Skip to content

Commit

Permalink
docs: update account kit documentation with up to date version of the…
Browse files Browse the repository at this point in the history
… sdk
  • Loading branch information
denniswon committed Apr 21, 2024
1 parent fd20bdc commit 0508011
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 202 deletions.
6 changes: 3 additions & 3 deletions packages/accounts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline

- **aa-ethers:** aa-ethers has had some functionality removed and apis changed

* inputs to the ProviderAdapter now require a SmartAccountClient
* with\* methods have been removed, middleware config now exists
- inputs to the ProviderAdapter now require a SmartAccountClient
- with\* methods have been removed, middleware config now exists
on the SmartAccountClient
* the Account Signer has been updated to take a SmartContractAccount
- the Account Signer has been updated to take a SmartContractAccount
as input

- all interfaces now use the new smart account
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/account/smartContractAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface AccountEntryPointRegistry<Name extends string = string>
"0.7.0": SmartContractAccount<Name, "0.7.0">;
}

//#region ToSmartContractAccountParams
export type ToSmartContractAccountParams<
Name extends string = string,
TTransport extends Transport = Transport,
Expand All @@ -135,6 +136,7 @@ export type ToSmartContractAccountParams<
signUserOperationHash?: (uoHash: Hex) => Promise<Hex>;
encodeUpgradeToAndCall?: (params: UpgradeToAndCallParams) => Promise<Hex>;
} & Omit<CustomSource, "signTransaction" | "address">;
//#endregion ToSmartContractAccountParams

export const parseFactoryAddressFromAccountInitCode = (
initCode: Hex
Expand Down Expand Up @@ -190,6 +192,7 @@ export const getAccountAddress = async ({
throw new GetCounterFactualAddressError();
};

//#region toSmartContractAccount
export async function toSmartContractAccount<
Name extends string = string,
TTransport extends Transport = Transport,
Expand All @@ -215,6 +218,7 @@ export async function toSmartContractAccount<
TChain,
TEntryPointVersion
>): Promise<SmartContractAccount<Name, TEntryPointVersion>>;
//#endregion toSmartContractAccount

export async function toSmartContractAccount({
transport,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type UpgradeToData = {
};
//#endregion UpgradeToData

//#region ClientMiddlewareConfig
export type ClientMiddlewareConfig<
TContext extends UserOperationContext | undefined =
| UserOperationContext
Expand All @@ -45,3 +46,4 @@ export type ClientMiddlewareConfig<
paymasterAndData: ClientMiddlewareFn<TContext>;
};
};
//#endregion ClientMiddlewareConfig
2 changes: 2 additions & 0 deletions packages/core/src/entrypoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface EntryPointRegistry<TChain extends Chain = Chain>
"0.7.0": SupportedEntryPoint<"0.7.0", TChain, typeof EntryPointAbi_v7>;
}

//#region EntryPointDef
export type EntryPointDef<
TEntryPointVersion extends EntryPointVersion,
TChain extends Chain = Chain,
Expand All @@ -81,6 +82,7 @@ export type EntryPointDef<
userOperation: UserOperationRequest<TEntryPointVersion>
) => Hex;
};
//#endregion EntryPointDef

export interface EntryPointDefRegistry<TChain extends Chain = Chain>
extends EntryPointRegistryBase<
Expand Down
28 changes: 18 additions & 10 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type UserOperationOverridesParameter<
? { overrides: UserOperationOverrides<TEntryPointVersion> }
: { overrides?: UserOperationOverrides<TEntryPointVersion> };

//#region UserOperationPaymasterOverrides
export type UserOperationPaymasterOverrides<
TEntryPointVersion extends EntryPointVersion
> = TEntryPointVersion extends "0.6.0"
Expand All @@ -79,14 +80,17 @@ export type UserOperationPaymasterOverrides<
// paymasterData overrides only allows '0x' for bypassing the paymaster middleware
// if set to '0x', all paymaster related fields are omitted from the user op request
paymasterData: EmptyHex;
paymasterVerificationGasLimit: NoUndefined<
UserOperationStruct<"0.7.0">["paymasterVerificationGasLimit"]
>;
paymasterPostOpGasLimit: NoUndefined<
UserOperationStruct<"0.7.0">["paymasterPostOpGasLimit"]
>;
paymasterVerificationGasLimit:
| NoUndefined<
UserOperationStruct<"0.7.0">["paymasterVerificationGasLimit"]
>
| Multiplier;
paymasterPostOpGasLimit:
| NoUndefined<UserOperationStruct<"0.7.0">["paymasterPostOpGasLimit"]>
| Multiplier;
}
: {};
//#endregion UserOperationOverridesParameter

//#region UserOperationOverrides
export type UserOperationOverrides<
Expand Down Expand Up @@ -116,6 +120,14 @@ export type UserOperationOverrides<
* one user operation for your account in a bundle
*/
nonceKey: bigint;

/** The same state overrides for
* [`eth_call`](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-eth#eth-call) method.
* An address-to-state mapping, where each entry specifies some state to be ephemerally overridden
* prior to executing the call. State overrides allow you to customize the network state for
* the purpose of the simulation, so this feature is useful when you need to estimate gas
* for user operation scenarios under conditions that aren’t currently present on the live network.
*/
stateOverride: StateOverride;
} & UserOperationPaymasterOverrides<TEntryPointVersion>
>;
Expand Down Expand Up @@ -393,7 +405,3 @@ export type UserOperationStruct<TEntryPointVersion extends EntryPointVersion> =
? UserOperationStruct_v7
: never;
//#endregion UserOperationStruct

export type UserOperationStructUnion =
| UserOperationStruct_v6
| UserOperationStruct_v7;
2 changes: 1 addition & 1 deletion site/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default defineConfig({
items: [
{
text: "Migrating to 3.x.x",
link: "/migration-guide",
link: "/migration-guides/migrating-to-v3",
},
{
text: "Changelog",
Expand Down
6 changes: 6 additions & 0 deletions site/.vitepress/sidebar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export const sidebar: DefaultTheme.Sidebar = [
{ text: "Send UserOperations", link: "/send-uos" },
],
},
{
text: "Migration Guides",
collapsed: false,
base: "/migration-guides",
items: [{ text: "Migrating to v3.x.x", link: "/migrating-to-v3" }],
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ outline: deep
head:
- - meta
- property: og:title
content: Migration Guide
content: Migrating to aa-sdk v3
- - meta
- name: description
content: How to upgrade through breaking changes of aa-sdk.
content: How to upgrade through breaking changes of aa-sdk v3
- - meta
- property: og:description
content: How to upgrade through breaking changes of aa-sdk.
content: How to upgrade through breaking changes of aa-sdk v3.
- - meta
- name: twitter:title
content: Migration Guide
- - meta
- name: twitter:description
content: How to upgrade through breaking changes of aa-sdk
content: How to upgrade through breaking changes of aa-sdk v3.
---

# Migration Guide
Expand All @@ -24,8 +24,7 @@ Below are the steps to migrate your project from older versions of the `aa-sdk`

## Migrating to version 3.x.x

This version update brings a lot of breaking changes. As we began to support Modular Accounts and their interfaces, we realized
that the previous version of the SDK was not as flexible as it could have been to handle the modularity of the new account interfaces.
This version update brings a lot of breaking changes. As we began to support Modular Accounts and their interfaces, we realized that the previous version of the SDK was not as flexible as it could have been to handle the modularity of the new account interfaces.
To address this, version 3.x.x of the SDK switches to an approach more idiomatic to `viem`.

### Viem Version
Expand All @@ -34,8 +33,7 @@ We have updated our dependency to viem v2.x.x. This means you will need to updat

### Client: `SmartAccountProvider``SmartAccountClient`

The biggest change is that the `SmartAccountProvider` class has been removed and replaced with a `SmartAccountClient` type that extends
`viem`'s [`Client`](https://viem.sh/docs/clients/custom). To get started with the new clients, you can do the following:
The biggest change is that the `SmartAccountProvider` class has been removed and replaced with a `SmartAccountClient` type that extends `viem`'s [`Client`](https://viem.sh/docs/clients/custom). To get started with the new clients, you can do the following:

```ts
import { SmartAccountProvider } from "@alchemy/aa-core"; // [!code --]
Expand Down Expand Up @@ -81,7 +79,7 @@ const client = createSmartAccountClient({ // [!code ++]
### Client: signature changes on methods
To support [the various ways](/migration-guide#account-connecting-to-a-smart-account) of connecting to a smart account, the signatures of the methods on `SmartAccountClient` have changed. Almost all methods now have an optional param for `account` and have been converted into single argument functions that take an object with the their properties instead.
To support [the various ways](/migration-guides/migrating-to-v3#account-connecting-to-a-smart-account) of connecting to a smart account, the signatures of the methods on `SmartAccountClient` have changed. Almost all methods now have an optional param for `account` and have been converted into single argument functions that take an object with the their properties instead.
### Account: `BaseSmartContractAccount``SmartContractAccount`
Expand Down Expand Up @@ -113,8 +111,7 @@ const account = await createLightAccount({ // [!code ++]
### Account: Connecting to a Smart Account
In earlier versions, a provider could not be used with a smart account until it was connected to one using `.connect`. In version 3.x.x,
you have the option of keeping the two disconnected and passing the account to the client methods directly. You also have the option to hoist the account
In earlier versions, a provider could not be used with a smart account until it was connected to one using `.connect`. In version 3.x.x, you have the option of keeping the two disconnected and passing the account to the client methods directly. You also have the option to hoist the account
so that you don't have to pass the account to every method.
#### Option 1: Passing the Account to the Client Methods
Expand Down Expand Up @@ -206,8 +203,7 @@ const { hash } = await smartAccountClient.sendUserOperation({
### Account: Custom Accounts
In prior versions, using your own smart contract account implementations required that you extend `BaseSmartContractAccount`. In version 3.x.x, you can use the
`toSmartContractAccount` method which will allow you to use any account with `SmartAccountClient`. `toSmartContractAccount` has the form of:
In prior versions, using your own smart contract account implementations required that you extend `BaseSmartContractAccount`. In version 3.x.x, you can use the `toSmartContractAccount` method which will allow you to use any account with `SmartAccountClient`. `toSmartContractAccount` has the form of:
```ts
type toSmartContractAccount = <
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ head:

# estimateUserOperationGas

Calls `eth_estimateUserOperationGas` and returns the result
Calls `eth_estimateUserOperationGas` and returns the result.

## Usage

Expand All @@ -25,7 +25,8 @@ import { client } from "./client";

const estimates = await client.estimateUserOperationGas(
{
// ... user operation
// ... user operation request with account dummySignature,
// initCode, encoded user operation call data, sender address, etc.
},
"0xEntryPointAddress"
);
Expand All @@ -38,14 +39,19 @@ const estimates = await client.estimateUserOperationGas(

### `Promise<UserOperationEstimateGasResponse<EntryPointVersion>`

The result of the estimate including the `callGasLimit`, `verificationGasLimit`, `preVerificationGas`, and additionally, `paymasterVerificationGasLimit` for EntryPointVersion v0.7.0 user operations.
The result of the estimate including the `callGasLimit`, `verificationGasLimit`, `preVerificationGas`, and additionally, `paymasterVerificationGasLimit` for EntryPointVersion `v0.7.0` user operations.

## Parameters

### `request: UserOperationRequest<EntryPointVersion>`

The user operation to send
The user operation to estimate the gas for sending the user oepration.

### `entryPoint: Address`

The address of the entry point to send the user operation to

### `stateOverride?: StateOverride`

A type defining state overrides for [`eth_call`](https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-eth#eth-call) method. An optional address-to-state mapping, where each entry specifies some state to be ephemerally overridden prior to executing the call.
State overrides allow you to customize the network state for the purpose of the simulation, so this feature is useful when you need to estimate gas for user operation scenarios under conditions that aren’t currently present on the live network.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ head:

Builds an _unsigned_ `UserOperation` (UO) struct with all middleware of the `SmartAccountClient` run through the middleware pipeline.

The order of the middlewares is:

1. `dummyPaymasterDataMiddleware` -- populates a dummy paymaster data to use in estimation (default: "0x")
2. `feeDataGetter` -- sets maxfeePerGas and maxPriorityFeePerGas
3. `gasEstimator` -- calls eth_estimateUserOperationGas
4. `paymasterMiddleware` -- used to set paymasterAndData. (default: "0x")
5. `customMiddleware` -- allows you to override any of the results returned by previous middlewares
Learn more about [`ClientMiddleware`](/packages/aa-core/smart-account-client/middleware/index) to learn more about the internals of `SmartAccountClient` middleware pipeline that builds the user operation request given the user transaction call data and the operating account data.

## Usage

Expand Down Expand Up @@ -95,24 +89,4 @@ const uoHash = await smartAccountClient.sendRawUserOperation({

A `Promise` containing the _unsigned_ UO struct resulting from the middleware pipeline

## Parameters

### `SendUserOperationParameters<TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined>`

- `uo:` [`UserOperationCallData`](/resources/types#UserOperationCallData) | [`BatchUserOperationCallData`](/resources/types#BatchUserOperationCallData)

::: details UserOperationCallData
<<< @/../packages/core/src/types.ts#UserOperationCallData
:::

- `target: Address` - the target of the call (equivalent to `to` in a transaction)
- `data: Hex` - can be either `0x` or a call data string
- `value?: bigint` - optionally, set the value in wei you want to send to the target

- `overrides?:` [`UserOperationOverrides`](/resources/types#useroperationoverrides)

Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit`, `paymasterAndData`, or `nonceKey` for the user operation request. You can also specify a `stateOverride` to be passed into `eth_estimateUserOperationGas` during fee estimation.

- `account?: TAccount extends SmartContractAccount | undefined`

When using this action, if the `SmartContractAccount` has not been connected to the `SmartAccountClient` (e.g. `SmartAccountClient` not instantiated with your `SmartContractAccount` during [`createSmartAccountClient`](/packages/aa-core/smart-account-client/)). You can check if the account is connected to the client by checking the `account` field of `SmartAccountClient`. If the account is not connected, you can specify the `SmartContractAccount` instance to use for the function call.
<!--@include: ../../../../snippets/aa-core/send-uo-param.md-->
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Converts a traditional Ethereum transaction and builds an _unsigned_ `UserOperat

The order of the middlewares is:

1. `dummyPaymasterDataMiddleware` -- populates a dummy paymaster data to use in estimation (default: "0x")
2. `feeDataGetter` -- sets maxfeePerGas and maxPriorityFeePerGas
3. `gasEstimator` -- calls eth_estimateUserOperationGas
4. `paymasterMiddleware` -- used to set paymasterAndData. (default: "0x")
5. `customMiddleware` -- allows you to override any of the results returned by previous middlewares
1. `dummyPaymasterDataMiddleware` -- populates a dummy paymaster data to use in estimation (default: "0x")
2. `feeDataGetter` -- sets maxfeePerGas and maxPriorityFeePerGas
3. `gasEstimator` -- calls eth_estimateUserOperationGas
4. `paymasterMiddleware` -- used to set paymasterAndData. (default: "0x")
5. `customMiddleware` -- allows you to override any of the results returned by previous middlewares

Note that `to`, `data`, `value`, `maxFeePerGas`, `maxPriorityFeePerGas` fields of the transaction request type are considered and used to build the user operation from the transaction, while other fields are not used.

Expand Down Expand Up @@ -68,28 +68,4 @@ const uoHash = await smartAccountClient.sendRawUserOperation({ request, entryPoi

A `Promise` containing the _unsigned_ UO struct converted from the input transaction with all the middleware run on the resulting UO

## Parameters

### `args: SendTransactionParameters<TChain, TAccount, TChainOverride>`

::: details SendTransactionParameters

```ts
export type SendTransactionParameters<
TChain extends Chain | undefined = Chain | undefined,
TAccount extends Account | undefined = Account | undefined,
TChainOverride extends Chain | undefined = Chain | undefined,
///
derivedChain extends Chain | undefined = DeriveChain<TChain, TChainOverride>
> = UnionOmit<FormattedTransactionRequest<derivedChain>, "from"> &
GetAccountParameter<TAccount> &
GetChainParameter<TChain, TChainOverride>;
```

:::

The [`SendTransactionParameters`](https://github.com/wevm/viem/blob/6ef4ac131a878bf1dc4b335f5dc127e62618dda0/src/types/transaction.ts#L209) used as the parameter to the `WalletAction` [`sendTransaction`](https://viem.sh/docs/actions/wallet/sendTransaction) method representing a traditional ethereum transaction request.

- `overrides?:` [`UserOperationOverrides`](/resources/types#useroperationoverrides)

Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit`, `paymasterAndData`, or `nonceKey` for the user operation request
<!--@include: ../../../../snippets/aa-core/send-tx-param.md-->
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,7 @@ head:

# buildUserOperationFromTxs

Converts traditional Ethereum transactions in batch and builds an _unsigned_ `UserOperation` (UO) struct with all middleware of the `SmartAccountClient` run through the middleware pipeline.

The order of the middlewares is:

1. `dummyPaymasterDataMiddleware` -- populates a dummy paymaster data to use in estimation (default: "0x")
2. `feeDataGetter` -- sets maxfeePerGas and maxPriorityFeePerGas
3. `gasEstimator` -- calls eth_estimateUserOperationGas
4. `paymasterMiddleware` -- used to set paymasterAndData. (default: "0x")
5. `customMiddleware` -- allows you to override any of the results returned by previous middlewares

**NOTE**: Not all Smart Contract Accounts support batching. The `SmartContractAccount` implementation must implement the encodeBatchExecute method for the `SmartAccountClient` to execute the batched user operation successfully.

Note that `to`, `data`, `value`, `maxFeePerGas`, `maxPriorityFeePerGas` fields of the transaction request type are considered and used to build the user operation from the transaction, while other fields are not used.
Performs [`buildUserOperationFromTx`](./buildUserOperationFromTx.md) in batch and builds into a single, yet to be signed `UserOperation` (UO) struct. The output user operation struct will be filled with all gas fields (and paymaster data if a paymaster is used) based on the transactions data (`to`, `data`, `value`, `maxFeePerGas`, `maxPriorityFeePerGas`) computed using the configured [`ClientMiddlewares`](/packages/aa-core/smart-account-client/middleware/index) on the `SmartAccountClient`

## Usage

Expand Down
Loading

0 comments on commit 0508011

Please sign in to comment.