Skip to content

Commit

Permalink
feat: add a nonce key override to support parallel nonces (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 authored and denniswon committed Feb 20, 2024
1 parent e197ce3 commit cbe5e08
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/account/smartContractAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export type SmartContractAccount<
typedDataDefinition: TypedDataDefinition<typedData, primaryType>
) => Promise<Hex>;
encodeUpgradeToAndCall: (params: UpgradeToAndCallParams) => Promise<Hex>;
getNonce(): Promise<bigint>;
getNonce(nonceKey?: bigint): Promise<bigint>;
getInitCode: () => Promise<Hex>;
isAccountDeployed: () => Promise<boolean>;
getFactoryAddress: () => Address;
Expand Down Expand Up @@ -244,12 +244,12 @@ export async function toSmartContractAccount<
return initCode === "0x";
};

const getNonce = async () => {
const getNonce = async (nonceKey = 0n) => {
if (!(await isAccountDeployed())) {
return 0n;
}

return entryPointContract.read.getNonce([accountAddress_, BigInt(0)]);
return entryPointContract.read.getNonce([accountAddress_, nonceKey]);
};

const account = toAccount({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const buildUserOperation: <
uo: {
initCode: account.getInitCode(),
sender: account.address,
nonce: account.getNonce(),
nonce: account.getNonce(overrides?.nonceKey),
callData: Array.isArray(uo)
? account.encodeBatchExecute(uo)
: typeof uo === "string"
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export type UserOperationOverrides = Partial<{
| UserOperationStruct["verificationGasLimit"]
| Multiplier;
paymasterAndData: UserOperationStruct["paymasterAndData"];
/**
* This can be used to override the key used when calling `entryPoint.getNonce`
* It is useful when you want to use parallel nonces for user operations
*
* NOTE: not all bundlers fully support this feature and it could be that your bundler will still only include
* one user operation for your account in a bundle
*/
nonceKey: bigint;
}>;

// represents the request as it needs to be formatted for RPC requests
Expand Down
2 changes: 1 addition & 1 deletion site/packages/aa-accounts/light-account/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ A Promise containing a new `LightAccount`.

## Developer links

- [Light Account & Simple Account Deployment Addresses](/smart-accounts/accounts/deployment-addresses)
- [Light Account & Simple Account Deployment Addresses](/smart-accounts/light-account/#deployment-addresses)
- [Light Account Github Repo](https://github.com/alchemyplatform/light-account)
- [Quantstamp Audit Report](https://github.com/alchemyplatform/light-account/blob/main/Quantstamp-Audit.pdf)
2 changes: 1 addition & 1 deletion site/resources/terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ A service or application that manages the private key and signs `UserOperation`s

## Smart Account

A [smart account](https://accountkit.alchemy.com/smart-accounts/.html#what-s-a-smart-account) is an individual on-chain account located at a public address where an ERC-4337 smart contract account is deployed. This address is controlled by one or more owners of the smart contract account. The [aa-sdk](https://github.com/alchemyplatform/aa-sdk) supports different smart account implementations such as [Light Account](https://accountkit.alchemy.com/smart-accounts/light-account/.html), [Simple Account](https://github.com/eth-infinitism/account-abstraction/blob/develop/contracts/samples/SimpleAccount.sol) and [Modular Account](https://accountkit.alchemy.com/smart-accounts/modular-account/.html) (coming soon). You can also [add add your own account implementation in aa-sdk](https://accountkit.alchemy.com/smart-accounts/accounts/contributing.html).
A [smart account](https://accountkit.alchemy.com/smart-accounts/.html#what-s-a-smart-account) is an individual on-chain account located at a public address where an ERC-4337 smart contract account is deployed. This address is controlled by one or more owners of the smart contract account. The [aa-sdk](https://github.com/alchemyplatform/aa-sdk) supports different smart account implementations such as [Light Account](https://accountkit.alchemy.com/smart-accounts/light-account/.html), [Simple Account](https://github.com/eth-infinitism/account-abstraction/blob/develop/contracts/samples/SimpleAccount.sol) and [Modular Account](https://accountkit.alchemy.com/smart-accounts/modular-account/.html) (coming soon). You can also [add add your own account implementation in aa-sdk](https://accountkit.alchemy.com/smart-accounts/custom/contributing.html).

## `UserOperation`

Expand Down
2 changes: 1 addition & 1 deletion site/smart-accounts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Account Kit provides a default smart account called `LightAccount`.

[Light Account](/smart-accounts/light-account/) is a secure, audited, gas-optimized, ERC-4337 compatible smart account implementation. It comes equipped with features like owner transfers, [ERC-1271](https://eips.ethereum.org/EIPS/eip-1271) message signing, and batched transactions. It's also [open source](https://github.com/alchemyplatform/light-account)!

It is [deployed](/smart-accounts/accounts/deployment-addresses) on Ethereum, Optimism, Arbitrum, Polygon, Base, and the respective testnets.
It is [deployed](/smart-accounts/light-account/#deployment-addresses) on Ethereum, Optimism, Arbitrum, Polygon, Base, and the respective testnets.

## Use your own Account

Expand Down
10 changes: 4 additions & 6 deletions site/smart-accounts/light-account/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@ The following tables list the deployed factory and account implementation contra
| ---------------- | ------------------------------------------ | ------------------------------------------ |
| Eth Mainnet | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Eth Sepolia | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Eth Goerli | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Polygon Mainnet | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Polygon Mumbai | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Optimism | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Optimism Goerli | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Base | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Base Goerli | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Optimism Sepolia | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Arbitrum | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Arbitrum Goerli | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Arbitrum Sepolia | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Base | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |
| Base Sepolia | 0x00004EC70002a32400f8ae005A26081065620D20 | 0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba |

## Developer links

- [Light Account & Simple Account deployment addresses](/smart-accounts/accounts/deployment-addresses)
- [Light Account & Simple Account deployment addresses](/smart-accounts/light-account/#deployment-addresses)
- [Light Account Github repo](https://github.com/alchemyplatform/light-account)
- [Quantstamp audit report](https://github.com/alchemyplatform/light-account/blob/main/Quantstamp-Audit.pdf)

0 comments on commit cbe5e08

Please sign in to comment.