Skip to content

Commit

Permalink
docs: updating to entrypoint v.7 overview
Browse files Browse the repository at this point in the history
  • Loading branch information
denniswon committed Apr 19, 2024
1 parent b94825c commit a0a181d
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 26 deletions.
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/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
20 changes: 10 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 @@ -393,7 +397,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
12 changes: 12 additions & 0 deletions site/.vitepress/sidebar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ export const sidebar: DefaultTheme.Sidebar = [
{ text: "Send UserOperations", link: "/send-uos" },
],
},
{
text: "Migration Guides",
collapsed: false,
base: "/migration-guides",
items: [
{ text: "Introduction", link: "/migrating-to-v3" },
{
text: "Entrypoint v0.7.0",
link: "/entrypoint-v7",
},
],
},
],
},
{
Expand Down
190 changes: 190 additions & 0 deletions site/migration-guides/entrypoint-v7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
---
outline: deep
head:
- - meta
- property: og:title
content: Migration Guide
- - meta
- name: description
content: How to update from Entrypoint v0.6 to v0.7.
- - meta
- property: og:description
content: How to update from Entrypoint v0.6 to v0.7.
- - meta
- name: twitter:title
content: Migration Guide
- - meta
- name: twitter:description
content: How to update from Entrypoint v0.6 to v0.7.
---

# Entrypoint v0.7 Update Guide

## Entrypoint v0.7: A Milestone in Account Abstraction

[Version 0.7](https://github.com/eth-infinitism/account-abstraction/releases/tag/v0.7.0), the latest advancement, brings significant updates and optimizations driven by community feedback and evolving needs:

- Optimized Gas Management: Making transactions more cost-effective.
- Advanced Security: Introducing stringent security measures for better account and transaction protection.
- Enhanced Developer Tools: Offering improved resources for creating AA-enabled dApps.

## What’s New in Entrypoint v0.7

Entrypoint v0.7 introduces several key features and improvements to streamline Account Abstraction further:

- Optimized Data Structures: Refining transactional data structures for enhanced performance and reduced gas costs.
- Simulation Functions and Deployment Overhaul: Version 0.7 removes on-chain simulation functions, directing them off-chain for bundlers, optimizing contract efficiency.
- delegateAndRevert() Helper: This addition aids networks without state overrides, ensuring reliable validation and gas estimation.
- ERC-165 “supportsInterface”: Enhancing interoperability.
- Token Paymaster Template: Illustrating how to implement paymasters that can sponsor transaction fees.
- Penalty for Unused Gas: Introducing a charge on unused gas limits to encourage efficient gas usage.
- Streamlined Post-Operation Calls: Simplifying the transaction process by removing redundant postOp calls.
- Gas Limit Specifications: Providing clearer guidelines for gas estimation and enhancing security.
- Structural Adjustments: Separating off-chain and on-chain UserOperation representations for better efficiency and clarity.

With upgrade made for `aa-sdk` version `v3.8.4`, `aa-sdk` now supports both EntryPoint v0.6.0 and the latest v.0.7.0 contract for compatible smart accounts.

Below are the steps to update your project from using Entrypoint v0.6.0 to v0.7.0 of the `aa-sdk`.

::: tip Note
This migration guide assumes you are already on `aa-sdk` version `^3.x.x`. If you are looking to upgrade from the older versions of `aa-sdk`, you can follow the [Migration Guide](./migrating-to-v3.md) to first upgrade `aa-sdk` version to `^3.x.x`.
:::

Upgrading to the latest version `v3.8.4` of `aa-sdk` does **not** involve breaking changes if you continue to stay on using Entrypoint v0.6.0 for your smart accounts. If you are looking to update to using Entrypoint v0.7.0, you can simply do so by specifying in the optional entrypoint version parameter to the version `0.7.0` when instantiating your `SmartContractAccount`. For the initial launch of Entrypoint v0.7 support in `aa-sdk`, the default Entrypoint version will remain as `v0.6.0`, but note that this default version value will be changed to the latest version in the future versions of `aa-sdk`.

### Account Support

Because [Entrypoint](https://eips.ethereum.org/EIPS/eip-4337#definitions) is a singleton contract, where there is only one implementation and one instance exists on each chain, you first need to make sure the smart account and the bundler you are using is updated with a certain Entrypoint version.

From version `^3.8.4`, `aa-sdk` lets you easily configure which Entrypoint version compatible Smart Account to use. `aa-sdk` supports 4 types of accounts natively, and the below table details which EntryPoints each account is valid for.

| Account | EntryPoint v0.7 | EntryPoint v0.6 |
| :---------------------------- | :-------------- | :-------------- |
| SimpleAccount |||
| LightAccount v1 (_< v.2.0.0_) |||
| LightAccount v2 (_>= v2.0.0_) |||
| MultiOwnerLightAccount |||
| MultiOwnerModularAccount |||
| MultisigModularAccount |||

### `SmartContractAccount`: optional `entryPoint` parameter for [`toSmartContractAccount`](/packages/aa-core/accounts/)

The only change that needs to be made to update to using Entrypoint v.7 is to specify the optional `entryPoint` parameter of the [`ToSmartContractAccountParams`](/resources/types#ToSmartContractAccountParams) used for the [`toSmartContractAccount`](/packages/aa-core/accounts/) function when instantiating a `SmartContractAccount`. Based on the `entryPoint` parameter, which is of type [`EntryPointDef`](/resources/types#EntryPointDef) of the specific `EntryPointVersion`, the output `SmartContractAccount` will be strongly-typed with the structure compatible to perform the desired `EntryPointVersion` user operations. Using `SimpleAccount` as an example, you will have to make the following changes:

```ts
import { createSimpleAccount } from "@alchemy/aa-core";
import { getEntryPoint, LocalAccountSigner, type Hex } from "@alchemy/aa-core";
import { sepolia } from "@alchemy/aa-core";

const chain = sepolia;

const account = await createSimpleAccount({
transport: http("RPC_URL"),
signer,
chain,
entryPoint: getEntryPoint(chain, { version: "0.7.0" }), // [!code ++]
});
```

### [`BundlerClient`](/resources/types#BundlerClient)

The `BundlerClient` will be compatible with both Entrypoint v0.6 and v0.7 operations, and the connected bundler is expected to determine the comaptible `EntryPoint` contract version based on the `entryPointAddress` parameter through the bundler RPC requests.

### [`SmartAccountClient`](/resources/types#SmartAccountClient): `EntryPointVersion` inferred from the connected Smart Account

As mentioned above, `Clients` support multiple `Entrypoint` contract versions depending on the `entryPointAddress` used when calling the RPC methods. As `SmartAccountClient` is an extension to `BundlerClient`, it is compatible with both `Entrypoint` version v0.6 and v0.7. When the `Account` is connected to the `Client` to perform [`SmartAccountClientActions`](/resources/types#smartaccountclientaction) on the connected `Account`, then the `SmartAccountClient` will be strongly-typed with the `EntryPointVersion` type inferred from the Account.

#### Using Entrypoint v0.7 Smart Account with `SmartAccountClient`

```ts
import {
createBundlerClient,
createSmartAccountClientFromExisting,
createSimpleAccount,
getEntryPoint,
LocalAccountSigner,
type Hex,
} from "@alchemy/aa-core";
import { sepolia } from "@alchemy/aa-core";
import { http, custom } from "viem";

const chain = sepolia;

const client = createBundlerClient({
chain,
transport: http("JSON_RPC_URL"),
});

// [!code focus:99]
const account_v7 = await createSimpleAccount({
signer,
transport: custom(client),
chain,
entryPoint: getEntryPoint(chain, { version: "0.7.0" }), // required for Entrypoint v0.7 [!code ++]
});

const smartAccountClient = createSmartAccountClientFromExisting({
client,
});

const uoStruct_v7: UserOperationStruct<"0.7.0"> =
await smartAccountClient.buildUserOperation({
uo: {
target: "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
data: "0x",
value: 10n,
},
account: account_v7,
});

// uoStruct_v7: UserOperationStruct<"0.7.0"> = {
// sender: string;
// nonce: BigNumberish;
// initCode: BytesLike | "0x"; [!code --]
// factory?: string; [!code ++]
// factoryData?: BytesLike; [!code ++]
// callData: BytesLike;
// callGasLimit?: BigNumberish;
// verificationGasLimit?: BigNumberish;
// preVerificationGas?: BigNumberish;
// maxFeePerGas?: BigNumberish;
// maxPriorityFeePerGas?: BigNumberish;
// paymasterAndData: BytesLike | "0x"; [!code --]
// paymaster?: string; [!code ++]
// paymasterVerificationGasLimit?: BigNumberish; [!code ++]
// paymasterPostOpGasLimit?: BigNumberish; [!code ++]
// paymasterData?: BytesLike; [!code ++]
// signature: BytesLike;
// }
```

### [`UserOperationOverrides`](/resources/types#useroperationoverrides)

Similar to the updated `UserOperation` type from `Entrypoint` v0.6 to v0.7, `UserOperationOverrides` types are different from the two version operations.

#### `paymasterAndData` field replaced with `paymaster` address and the `paymasterData` separated in addition to the 2 added `paymaster` operation gas limit fields

```ts
export type UserOperationOverrides<'0.7.0'> = {
...
paymasterAndData?: EmptyHex; // [!code --]
paymaster?: string; // [!code ++]
paymasterData?: EmptyHex; // [!code ++]
paymasterVerificationGasLimit?: BigNumberish | Multiplier; // [!code ++]
paymasterPostOpGasLimit?: BigNumberish | Multiplier; // [!code ++]
}
```
##### `stateOverride` field added to `UserOperationOverrides` for validating and estimating gas for transactions
The state overrides during transaction calls (e.g., [`eth_call`](https://docs.alchemy.com/reference/eth-call) and [`eth_estimateGas`](https://docs.alchemy.com/reference/eth-estimategas)) allow for more flexible testing and gas estimation. However, not all networks support this feature. For networks lacking state overrides, `Entrypoint` v0.7 introduced the `delegateAndRevert()` function to be used as a workaround. It aids in validating and estimating gas for transactions by simulating conditions without permanently changing the on-chain state.
```ts
export type UserOperationOverrides<'0.7.0'> = {
...
stateOverride?: StateOverride; // [!code ++]
...
};
```

Learn how to estimate `UserOperation` gas when using `Entrypoint` v0.7 smart accounts by referring to the guide [`How to estimate gas when using Entrypoint v0.7`](/using-smart-accounts/entrypoint-v7-how-to-estimate-gas).
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
Empty file added site/resources/errors.md
Empty file.
Loading

0 comments on commit a0a181d

Please sign in to comment.