Skip to content

Commit

Permalink
feat: allow passing raw call data to sendUserOperation (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 committed Dec 1, 2023
1 parent 3f24fe0 commit 26b90b6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
8 changes: 6 additions & 2 deletions packages/accounts/src/kernel-zerodev/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { UserOperationCallData } from "@alchemy/aa-core";
import type { Hex } from "viem";

export interface KernelUserOperationCallData extends UserOperationCallData {
export type KernelUserOperationCallData = Exclude<
UserOperationCallData,
Hex
> & {
delegateCall?: boolean;
}
};

export type KernelBatchUserOperationCallData = KernelUserOperationCallData[];
2 changes: 2 additions & 0 deletions packages/core/src/provider/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ export class SmartAccountProvider<
nonce: this.account.getNonce(),
callData: Array.isArray(data)
? this.account.encodeBatchExecute(data)
: typeof data === "string"
? data
: this.account.encodeExecute(
data.target,
data.value ?? 0n,
Expand Down
20 changes: 11 additions & 9 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ export type PromiseOrValue<T> = T | Promise<T>;
export type BigNumberish = string | bigint | number;
export type BytesLike = Uint8Array | string;

export interface UserOperationCallData {
/* the target of the call */
target: Address;
/* the data passed to the target */
data: Hex;
/* the amount of native token to send to the target (default: 0) */
value?: bigint;
}
export type UserOperationCallData =
| {
/* the target of the call */
target: Address;
/* the data passed to the target */
data: Hex;
/* the amount of native token to send to the target (default: 0) */
value?: bigint;
}
| Hex;

export type BatchUserOperationCallData = UserOperationCallData[];
export type BatchUserOperationCallData = Exclude<UserOperationCallData, Hex>[];

export type UserOperationOverrides = Partial<
Pick<
Expand Down
2 changes: 1 addition & 1 deletion site/guides/send-user-operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Some other helpful viem methods include: [encodeFunctionData](https://viem.sh/do

## 4. Send The User Operation

Now we'll use the connected provider to send a user operation. We'll use the [sendUserOperation](/packages/aa-core/provider/waitForUserOperationTransaction.md) method on the provider.
Now we'll use the connected provider to send a user operation. We'll use the [sendUserOperation](/packages/aa-core/provider/sendUserOperation.md) method on the provider.

You can either send ETH to the smart account to pay for User Operation's gas, or you can connect your provider to an Alchemy Gas Manager using the [withAlchemyGasManager](/packages/aa-alchemy/provider/withAlchemyGasManager.md) method to sponsor the UO's gas. We'll use the latter approach below. You can go to the [Alchemy Dashboard](https://dashboard.alchemy.com/gas-manager) to get a Gas Manager policy ID.

Expand Down
4 changes: 3 additions & 1 deletion site/packages/aa-core/provider/sendUserOperation.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ A Promise containing the hash of the user operation and the request that was sen

## Parameters

### `UserOperationCallData | UserOperationCallData[]`
### `UserOperationCallData | UserOperationCallData[] | Hex`

`UserOperationCallData` is an object with the following properties:

- `target: Address` - the target of the call (equivalent to `to` in a transaction)
- `data: Hex` - can be either `0x` or a call data string
Expand Down

0 comments on commit 26b90b6

Please sign in to comment.