Skip to content

Commit

Permalink
feat: add a nonce key override to support parallel nonces
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 committed Feb 15, 2024
1 parent 6fd817f commit f3dd86d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 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
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type UserOperationOverrides = Partial<{
| UserOperationStruct["verificationGasLimit"]
| Percentage;
paymasterAndData: UserOperationStruct["paymasterAndData"];
nonceKey: bigint;
}>;

// represents the request as it needs to be formatted for RPC requests
Expand Down

0 comments on commit f3dd86d

Please sign in to comment.