@account-kit/smart-contracts 4.20.1 → 4.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/src/ma-v2/abis/entityIdAndNonceReader.d.ts +9 -0
- package/dist/esm/src/ma-v2/abis/entityIdAndNonceReader.js +24 -0
- package/dist/esm/src/ma-v2/abis/entityIdAndNonceReader.js.map +1 -0
- package/dist/esm/src/ma-v2/actions/{DeferralActions.d.ts → deferralActions.d.ts} +9 -0
- package/dist/esm/src/ma-v2/actions/{DeferralActions.js → deferralActions.js} +48 -9
- package/dist/esm/src/ma-v2/actions/deferralActions.js.map +1 -0
- package/dist/esm/src/ma-v2/index.d.ts +1 -0
- package/dist/esm/src/ma-v2/index.js +1 -0
- package/dist/esm/src/ma-v2/index.js.map +1 -1
- package/dist/esm/src/ma-v2/utils.d.ts +9 -0
- package/dist/esm/src/ma-v2/utils.js +7 -0
- package/dist/esm/src/ma-v2/utils.js.map +1 -1
- package/dist/types/src/ma-v2/abis/entityIdAndNonceReader.d.ts +10 -0
- package/dist/types/src/ma-v2/abis/entityIdAndNonceReader.d.ts.map +1 -0
- package/dist/types/src/ma-v2/actions/{DeferralActions.d.ts → deferralActions.d.ts} +10 -1
- package/dist/types/src/ma-v2/actions/{DeferralActions.d.ts.map → deferralActions.d.ts.map} +1 -1
- package/dist/types/src/ma-v2/index.d.ts +1 -0
- package/dist/types/src/ma-v2/index.d.ts.map +1 -1
- package/dist/types/src/ma-v2/utils.d.ts +9 -0
- package/dist/types/src/ma-v2/utils.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/ma-v2/abis/entityIdAndNonceReader.ts +23 -0
- package/src/ma-v2/actions/{DeferralActions.ts → deferralActions.ts} +67 -8
- package/src/ma-v2/index.ts +1 -0
- package/src/ma-v2/utils.ts +25 -0
- package/dist/esm/src/ma-v2/actions/DeferralActions.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const entityIdAndNonceReaderAbi = [
|
|
2
|
+
{
|
|
3
|
+
type: "constructor",
|
|
4
|
+
inputs: [
|
|
5
|
+
{
|
|
6
|
+
name: "account",
|
|
7
|
+
type: "address",
|
|
8
|
+
internalType: "contract IModularAccountView",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: "ep",
|
|
12
|
+
type: "address",
|
|
13
|
+
internalType: "contract IEntryPoint",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "nonce",
|
|
17
|
+
type: "uint192",
|
|
18
|
+
internalType: "uint192",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
stateMutability: "nonpayable",
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
//# sourceMappingURL=entityIdAndNonceReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityIdAndNonceReader.js","sourceRoot":"","sources":["../../../../../src/ma-v2/abis/entityIdAndNonceReader.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC;QACE,IAAI,EAAE,aAAa;QACnB,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,SAAS;gBACf,YAAY,EAAE,8BAA8B;aAC7C;YACD;gBACE,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,SAAS;gBACf,YAAY,EAAE,sBAAsB;aACrC;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;gBACf,YAAY,EAAE,SAAS;aACxB;SACF;QACD,eAAe,EAAE,YAAY;KAC9B;CACF,CAAC","sourcesContent":["export const entityIdAndNonceReaderAbi = [\n {\n type: \"constructor\",\n inputs: [\n {\n name: \"account\",\n type: \"address\",\n internalType: \"contract IModularAccountView\",\n },\n {\n name: \"ep\",\n type: \"address\",\n internalType: \"contract IEntryPoint\",\n },\n {\n name: \"nonce\",\n type: \"uint192\",\n internalType: \"uint192\",\n },\n ],\n stateMutability: \"nonpayable\",\n },\n];\n"]}
|
|
@@ -49,10 +49,19 @@ export type BuildUserOperationWithDeferredActionParams = {
|
|
|
49
49
|
signaturePrepend: Hex;
|
|
50
50
|
nonceOverride: bigint;
|
|
51
51
|
};
|
|
52
|
+
export type EntityIdAndNonceParams = {
|
|
53
|
+
entityId: number;
|
|
54
|
+
nonceKey: bigint;
|
|
55
|
+
isGlobalValidation: boolean;
|
|
56
|
+
};
|
|
52
57
|
export type DeferralActions = {
|
|
53
58
|
createDeferredActionTypedDataObject: (args: CreateDeferredActionTypedDataParams) => Promise<DeferredActionReturnData>;
|
|
54
59
|
buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;
|
|
55
60
|
buildUserOperationWithDeferredAction: (args: BuildUserOperationWithDeferredActionParams) => Promise<UserOperationRequest_v7>;
|
|
61
|
+
getEntityIdAndNonce: (args: EntityIdAndNonceParams) => Promise<{
|
|
62
|
+
nonce: bigint;
|
|
63
|
+
entityId: number;
|
|
64
|
+
}>;
|
|
56
65
|
};
|
|
57
66
|
/**
|
|
58
67
|
* Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AccountNotFoundError, InvalidNonceKeyError, EntryPointNotFoundError, } from "@aa-sdk/core";
|
|
2
|
-
import { concatHex, maxUint152, getContract, encodePacked, size, toHex, } from "viem";
|
|
2
|
+
import { concatHex, maxUint152, getContract, encodePacked, size, toHex, encodeDeployData, hexToNumber, } from "viem";
|
|
3
|
+
import { entityIdAndNonceReaderBytecode, buildFullNonceKey } from "../utils.js";
|
|
4
|
+
import { entityIdAndNonceReaderAbi } from "../abis/entityIdAndNonceReader.js";
|
|
3
5
|
/**
|
|
4
6
|
* Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
|
|
5
7
|
*
|
|
@@ -7,13 +9,12 @@ import { concatHex, maxUint152, getContract, encodePacked, size, toHex, } from "
|
|
|
7
9
|
* @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
|
|
8
10
|
*/
|
|
9
11
|
export const deferralActions = (client) => {
|
|
10
|
-
const createDeferredActionTypedDataObject = async ({ callData, deadline, entityId, isGlobalValidation, nonceKeyOverride, }) => {
|
|
12
|
+
const createDeferredActionTypedDataObject = async ({ callData, deadline, entityId, isGlobalValidation, nonceKeyOverride = 0n, }) => {
|
|
11
13
|
if (!client.account) {
|
|
12
14
|
throw new AccountNotFoundError();
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
throw new InvalidNonceKeyError(baseNonceKey);
|
|
16
|
+
if (nonceKeyOverride > maxUint152) {
|
|
17
|
+
throw new InvalidNonceKeyError(nonceKeyOverride);
|
|
17
18
|
}
|
|
18
19
|
const entryPoint = client.account.getEntryPoint();
|
|
19
20
|
if (entryPoint === undefined) {
|
|
@@ -26,9 +27,12 @@ export const deferralActions = (client) => {
|
|
|
26
27
|
});
|
|
27
28
|
// 2 = deferred action flags 0b10
|
|
28
29
|
// 1 = isGlobal validation flag 0b01
|
|
29
|
-
const fullNonceKey = (
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const fullNonceKey = buildFullNonceKey({
|
|
31
|
+
nonceKey: nonceKeyOverride,
|
|
32
|
+
entityId,
|
|
33
|
+
isGlobalValidation,
|
|
34
|
+
isDeferredAction: true,
|
|
35
|
+
});
|
|
32
36
|
const nonceOverride = (await entryPointContract.read.getNonce([
|
|
33
37
|
client.account.address,
|
|
34
38
|
fullNonceKey,
|
|
@@ -113,10 +117,45 @@ export const deferralActions = (client) => {
|
|
|
113
117
|
client.account.getDummySignature = previousDummySigGetter;
|
|
114
118
|
return unsignedUo;
|
|
115
119
|
};
|
|
120
|
+
const getEntityIdAndNonce = async ({ entityId, nonceKey, isGlobalValidation, }) => {
|
|
121
|
+
if (!client.account) {
|
|
122
|
+
throw new AccountNotFoundError();
|
|
123
|
+
}
|
|
124
|
+
if (nonceKey > maxUint152) {
|
|
125
|
+
throw new InvalidNonceKeyError(nonceKey);
|
|
126
|
+
}
|
|
127
|
+
const entryPoint = client.account.getEntryPoint();
|
|
128
|
+
if (entryPoint === undefined) {
|
|
129
|
+
throw new EntryPointNotFoundError(client.chain, "0.7.0");
|
|
130
|
+
}
|
|
131
|
+
const bytecode = encodeDeployData({
|
|
132
|
+
abi: entityIdAndNonceReaderAbi,
|
|
133
|
+
bytecode: entityIdAndNonceReaderBytecode,
|
|
134
|
+
args: [
|
|
135
|
+
client.account.address,
|
|
136
|
+
entryPoint.address,
|
|
137
|
+
buildFullNonceKey({
|
|
138
|
+
nonceKey,
|
|
139
|
+
entityId,
|
|
140
|
+
isGlobalValidation,
|
|
141
|
+
isDeferredAction: true,
|
|
142
|
+
}),
|
|
143
|
+
],
|
|
144
|
+
});
|
|
145
|
+
const { data } = await client.call({ data: bytecode });
|
|
146
|
+
if (!data) {
|
|
147
|
+
throw new Error("No data returned from contract call");
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
nonce: BigInt(data),
|
|
151
|
+
entityId: hexToNumber(`0x${data.slice(40, 48)}`),
|
|
152
|
+
};
|
|
153
|
+
};
|
|
116
154
|
return {
|
|
117
155
|
createDeferredActionTypedDataObject,
|
|
118
156
|
buildDeferredActionDigest,
|
|
119
157
|
buildUserOperationWithDeferredAction,
|
|
158
|
+
getEntityIdAndNonce,
|
|
120
159
|
};
|
|
121
160
|
};
|
|
122
|
-
//# sourceMappingURL=
|
|
161
|
+
//# sourceMappingURL=deferralActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferralActions.js","sourceRoot":"","sources":["../../../../../src/ma-v2/actions/deferralActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,GAIxB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EACZ,IAA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serOperationCallData,\n type BatchUserOperationCallData,\n type UserOperationRequest_v7,\n} from \"@aa-sdk/core\";\nimport {\n type Address,\n type Hex,\n concatHex,\n maxUint152,\n getContract,\n encodePacked,\n size,\n toHex,\n encodeDeployData,\n hexToNumber,\n} from \"viem\";\nimport { entityIdAndNonceReaderBytecode, buildFullNonceKey } from \"../utils.js\";\nimport { entityIdAndNonceReaderAbi } from \"../abis/entityIdAndNonceReader.js\";\nimport type { ModularAccountV2Client } from \"../client/client.js\";\n\nexport type DeferredActionTypedData = {\n domain: {\n chainId: number;\n verifyingContract: Address;\n };\n types: {\n DeferredAction: [\n { name: \"nonce\"; type: \"uint256\" },\n { name: \"deadline\"; type: \"uint48\" },\n { name: \"call\"; type: \"bytes\" }\n ];\n };\n primaryType: \"DeferredAction\";\n message: {\n nonce: bigint;\n deadline: number;\n call: Hex;\n };\n};\n\nexport type DeferredActionReturnData = {\n typedData: DeferredActionTypedData;\n nonceOverride: bigint;\n};\n\nexport type CreateDeferredActionTypedDataParams = {\n callData: Hex;\n deadline: number;\n entityId: number;\n isGlobalValidation: boolean;\n nonceKeyOverride?: bigint;\n};\n\nexport type BuildDeferredActionDigestParams = {\n typedData: DeferredActionTypedData;\n sig: Hex;\n};\n\nexport type BuildUserOperationWithDeferredActionParams = {\n uo: UserOperationCallData | BatchUserOperationCallData;\n signaturePrepend: Hex;\n nonceOverride: bigint;\n};\n\nexport type EntityIdAndNonceParams = {\n entityId: number;\n nonceKey: bigint;\n isGlobalValidation: boolean;\n};\n\nexport type DeferralActions = {\n createDeferredActionTypedDataObject: (\n args: CreateDeferredActionTypedDataParams\n ) => Promise<DeferredActionReturnData>;\n buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;\n buildUserOperationWithDeferredAction: (\n args: BuildUserOperationWithDeferredActionParams\n ) => Promise<UserOperationRequest_v7>;\n getEntityIdAndNonce: (\n args: EntityIdAndNonceParams\n ) => Promise<{ nonce: bigint; entityId: number }>;\n};\n\n/**\n * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.\n *\n * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.\n * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.\n */\nexport const deferralActions: (\n client: ModularAccountV2Client\n) => DeferralActions = (client: ModularAccountV2Client): DeferralActions => {\n const createDeferredActionTypedDataObject = async ({\n callData,\n deadline,\n entityId,\n isGlobalValidation,\n nonceKeyOverride = 0n,\n }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n if (nonceKeyOverride > maxUint152) {\n throw new InvalidNonceKeyError(nonceKeyOverride);\n }\n\n const entryPoint = client.account.getEntryPoint();\n if (entryPoint === undefined) {\n throw new EntryPointNotFoundError(client.chain, \"0.7.0\");\n }\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client: client,\n });\n\n // 2 = deferred action flags 0b10\n // 1 = isGlobal validation flag 0b01\n const fullNonceKey: bigint = buildFullNonceKey({\n nonceKey: nonceKeyOverride,\n entityId,\n isGlobalValidation,\n isDeferredAction: true,\n });\n\n const nonceOverride = (await entryPointContract.read.getNonce([\n client.account.address,\n fullNonceKey,\n ])) as bigint;\n\n return {\n typedData: {\n domain: {\n chainId: await client.getChainId(),\n verifyingContract: client.account.address,\n },\n types: {\n DeferredAction: [\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint48\" },\n { name: \"call\", type: \"bytes\" },\n ],\n },\n primaryType: \"DeferredAction\",\n message: {\n nonce: nonceOverride,\n deadline: deadline,\n call: callData,\n },\n },\n nonceOverride: nonceOverride,\n };\n };\n\n /**\n * Creates the digest which must be prepended to the userOp signature.\n *\n * Assumption: The client this extends is used to sign the typed data.\n *\n * @param {object} args The argument object containing the following:\n * @param {DeferredActionTypedData} args.typedData The typed data object for the deferred action\n * @param {Hex} args.sig The signature to include in the digest\n * @returns {Hex} The encoded digest to be prepended to the userOp signature\n */\n const buildDeferredActionDigest = ({\n typedData,\n sig,\n }: BuildDeferredActionDigestParams): Hex => {\n const signerEntity = client.account.signerEntity;\n const validationLocator =\n (BigInt(signerEntity.entityId) << 8n) |\n (signerEntity.isGlobalValidation ? 1n : 0n);\n\n let encodedData = encodePacked(\n [\"uint168\", \"uint48\", \"bytes\"],\n [validationLocator, typedData.message.deadline, typedData.message.call]\n );\n\n const encodedDataLength = size(encodedData);\n const sigLength = size(sig);\n\n encodedData = concatHex([\n toHex(encodedDataLength, { size: 4 }),\n encodedData,\n toHex(sigLength, { size: 4 }),\n sig,\n ]);\n\n return encodedData;\n };\n\n /**\n * Builds a user operation with a deferred action by wrapping buildUserOperation() with a dummy signature override.\n *\n * @param {object} args The argument object containing the following:\n * @param {UserOperationCallData | BatchUserOperationCallData} args.uo The user operation call data to build\n * @param {Hex} args.signaturePrepend The signature data to prepend to the dummy signature\n * @param {bigint} args.nonceOverride The nonce to override in the user operation, generally given from the typed data builder\n * @returns {Promise<UserOperationRequest_v7>} The unsigned user operation request with the deferred action\n */\n const buildUserOperationWithDeferredAction = async ({\n uo,\n signaturePrepend,\n nonceOverride,\n }: BuildUserOperationWithDeferredActionParams): Promise<UserOperationRequest_v7> => {\n // Check if client.account is defined\n if (client.account === undefined) {\n throw new AccountNotFoundError();\n }\n\n // Pre-fetch the dummy sig so we can override `client.account.getDummySignature()`\n const dummySig = await client.account.getDummySignature();\n\n // Cache the previous dummy signature getter\n const previousDummySigGetter = client.account.getDummySignature;\n\n // Override client.account.getDummySignature() so `client.buildUserOperation()` uses the prepended hex and the dummy signature during gas estimation\n client.account.getDummySignature = () => {\n return concatHex([signaturePrepend, dummySig as Hex]);\n };\n\n const unsignedUo = (await client.buildUserOperation({\n uo: uo,\n overrides: {\n nonce: nonceOverride,\n },\n })) as UserOperationRequest_v7;\n\n // Restore the dummy signature getter\n client.account.getDummySignature = previousDummySigGetter;\n\n return unsignedUo;\n };\n\n const getEntityIdAndNonce = async ({\n entityId,\n nonceKey,\n isGlobalValidation,\n }: EntityIdAndNonceParams) => {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const entryPoint = client.account.getEntryPoint();\n if (entryPoint === undefined) {\n throw new EntryPointNotFoundError(client.chain, \"0.7.0\");\n }\n\n const bytecode = encodeDeployData({\n abi: entityIdAndNonceReaderAbi,\n bytecode: entityIdAndNonceReaderBytecode,\n args: [\n client.account.address,\n entryPoint.address,\n buildFullNonceKey({\n nonceKey,\n entityId,\n isGlobalValidation,\n isDeferredAction: true,\n }),\n ],\n });\n\n const { data } = await client.call({ data: bytecode });\n if (!data) {\n throw new Error(\"No data returned from contract call\");\n }\n\n return {\n nonce: BigInt(data),\n entityId: hexToNumber(`0x${data.slice(40, 48)}`),\n };\n };\n\n return {\n createDeferredActionTypedDataObject,\n buildDeferredActionDigest,\n buildUserOperationWithDeferredAction,\n getEntityIdAndNonce,\n };\n};\n"]}
|
|
@@ -9,6 +9,7 @@ export { serializeValidationConfig, serializeHookConfig, serializeModuleEntity,
|
|
|
9
9
|
export type * from "./actions/install-validation/installValidation.js";
|
|
10
10
|
export { installValidationActions } from "./actions/install-validation/installValidation.js";
|
|
11
11
|
export { getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddress, getDefaultPaymasterGuardModuleAddress, getDefaultSingleSignerValidationModuleAddress, getDefaultTimeRangeModuleAddress, getDefaultWebauthnValidationModuleAddress, } from "./modules/utils.js";
|
|
12
|
+
export { buildFullNonceKey } from "./utils.js";
|
|
12
13
|
export { allowlistModuleAbi } from "./modules/allowlist-module/abis/allowlistModuleAbi.js";
|
|
13
14
|
export { AllowlistModule } from "./modules/allowlist-module/module.js";
|
|
14
15
|
export { nativeTokenLimitModuleAbi } from "./modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js";
|
|
@@ -8,6 +8,7 @@ export { HookType } from "./actions/common/types.js";
|
|
|
8
8
|
export { serializeValidationConfig, serializeHookConfig, serializeModuleEntity, } from "./actions/common/utils.js";
|
|
9
9
|
export { installValidationActions } from "./actions/install-validation/installValidation.js";
|
|
10
10
|
export { getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddress, getDefaultPaymasterGuardModuleAddress, getDefaultSingleSignerValidationModuleAddress, getDefaultTimeRangeModuleAddress, getDefaultWebauthnValidationModuleAddress, } from "./modules/utils.js";
|
|
11
|
+
export { buildFullNonceKey } from "./utils.js";
|
|
11
12
|
export { allowlistModuleAbi } from "./modules/allowlist-module/abis/allowlistModuleAbi.js";
|
|
12
13
|
export { AllowlistModule } from "./modules/allowlist-module/module.js";
|
|
13
14
|
export { nativeTokenLimitModuleAbi } from "./modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ma-v2/index.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAQ/D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAE7F,OAAO,EACL,gCAAgC,EAChC,uCAAuC,EACvC,qCAAqC,EACrC,6CAA6C,EAC7C,gCAAgC,EAChC,yCAAyC,GAC1C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uDAAuD,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uEAAuE,CAAC;AAClH,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kEAAkE,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,+BAA+B,EAAE,MAAM,4EAA4E,CAAC;AAC7H,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,MAAM,wDAAwD,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,MAAM,6DAA6D,CAAC","sourcesContent":["// ma v2 exports\nexport { accountFactoryAbi } from \"./abis/accountFactoryAbi.js\";\nexport { modularAccountAbi } from \"./abis/modularAccountAbi.js\";\nexport { semiModularAccountBytecodeAbi } from \"./abis/semiModularAccountBytecodeAbi.js\";\nexport { semiModularAccountStorageAbi } from \"./abis/semiModularAccountStorageAbi.js\";\n\nexport { nativeSMASigner } from \"./account/nativeSMASigner.js\";\n\nexport type {\n ModuleEntity,\n ValidationConfig,\n HookConfig,\n ValidationData,\n} from \"./actions/common/types.js\";\nexport { HookType } from \"./actions/common/types.js\";\nexport {\n serializeValidationConfig,\n serializeHookConfig,\n serializeModuleEntity,\n} from \"./actions/common/utils.js\";\nexport type * from \"./actions/install-validation/installValidation.js\";\nexport { installValidationActions } from \"./actions/install-validation/installValidation.js\";\n\nexport {\n getDefaultAllowlistModuleAddress,\n getDefaultNativeTokenLimitModuleAddress,\n getDefaultPaymasterGuardModuleAddress,\n getDefaultSingleSignerValidationModuleAddress,\n getDefaultTimeRangeModuleAddress,\n getDefaultWebauthnValidationModuleAddress,\n} from \"./modules/utils.js\";\nexport { allowlistModuleAbi } from \"./modules/allowlist-module/abis/allowlistModuleAbi.js\";\nexport { AllowlistModule } from \"./modules/allowlist-module/module.js\";\nexport { nativeTokenLimitModuleAbi } from \"./modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js\";\nexport { NativeTokenLimitModule } from \"./modules/native-token-limit-module/module.js\";\nexport { paymasterGuardModuleAbi } from \"./modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.js\";\nexport { PaymasterGuardModule } from \"./modules/paymaster-guard-module/module.js\";\nexport { singleSignerValidationModuleAbi } from \"./modules/single-signer-validation/abis/singleSignerValidationModuleAbi.js\";\nexport { SingleSignerValidationModule } from \"./modules/single-signer-validation/module.js\";\nexport { timeRangeModuleAbi } from \"./modules/time-range-module/abis/timeRangeModuleAbi.js\";\nexport { TimeRangeModule } from \"./modules/time-range-module/module.js\";\nexport { webauthnValidationModuleAbi } from \"./modules/webauthn-validation/abis/webauthnValidationAbi.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ma-v2/index.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAQ/D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAE7F,OAAO,EACL,gCAAgC,EAChC,uCAAuC,EACvC,qCAAqC,EACrC,6CAA6C,EAC7C,gCAAgC,EAChC,yCAAyC,GAC1C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uDAAuD,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uEAAuE,CAAC;AAClH,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kEAAkE,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,+BAA+B,EAAE,MAAM,4EAA4E,CAAC;AAC7H,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,MAAM,wDAAwD,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,MAAM,6DAA6D,CAAC","sourcesContent":["// ma v2 exports\nexport { accountFactoryAbi } from \"./abis/accountFactoryAbi.js\";\nexport { modularAccountAbi } from \"./abis/modularAccountAbi.js\";\nexport { semiModularAccountBytecodeAbi } from \"./abis/semiModularAccountBytecodeAbi.js\";\nexport { semiModularAccountStorageAbi } from \"./abis/semiModularAccountStorageAbi.js\";\n\nexport { nativeSMASigner } from \"./account/nativeSMASigner.js\";\n\nexport type {\n ModuleEntity,\n ValidationConfig,\n HookConfig,\n ValidationData,\n} from \"./actions/common/types.js\";\nexport { HookType } from \"./actions/common/types.js\";\nexport {\n serializeValidationConfig,\n serializeHookConfig,\n serializeModuleEntity,\n} from \"./actions/common/utils.js\";\nexport type * from \"./actions/install-validation/installValidation.js\";\nexport { installValidationActions } from \"./actions/install-validation/installValidation.js\";\n\nexport {\n getDefaultAllowlistModuleAddress,\n getDefaultNativeTokenLimitModuleAddress,\n getDefaultPaymasterGuardModuleAddress,\n getDefaultSingleSignerValidationModuleAddress,\n getDefaultTimeRangeModuleAddress,\n getDefaultWebauthnValidationModuleAddress,\n} from \"./modules/utils.js\";\nexport { buildFullNonceKey } from \"./utils.js\";\nexport { allowlistModuleAbi } from \"./modules/allowlist-module/abis/allowlistModuleAbi.js\";\nexport { AllowlistModule } from \"./modules/allowlist-module/module.js\";\nexport { nativeTokenLimitModuleAbi } from \"./modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js\";\nexport { NativeTokenLimitModule } from \"./modules/native-token-limit-module/module.js\";\nexport { paymasterGuardModuleAbi } from \"./modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.js\";\nexport { PaymasterGuardModule } from \"./modules/paymaster-guard-module/module.js\";\nexport { singleSignerValidationModuleAbi } from \"./modules/single-signer-validation/abis/singleSignerValidationModuleAbi.js\";\nexport { SingleSignerValidationModule } from \"./modules/single-signer-validation/module.js\";\nexport { timeRangeModuleAbi } from \"./modules/time-range-module/abis/timeRangeModuleAbi.js\";\nexport { TimeRangeModule } from \"./modules/time-range-module/module.js\";\nexport { webauthnValidationModuleAbi } from \"./modules/webauthn-validation/abis/webauthnValidationAbi.js\";\n"]}
|
|
@@ -36,3 +36,12 @@ export type GetMAV2UpgradeToData<TSigner extends SmartAccountSigner = SmartAccou
|
|
|
36
36
|
export declare function getMAV2UpgradeToData<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TSigner extends SmartAccountSigner = SmartAccountSigner, TAccount extends SmartContractAccountWithSigner<string, TSigner> | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined>(client: SmartAccountClient<TTransport, TChain, TAccount>, args: GetMAV2UpgradeToData<TSigner, TAccount>): Promise<UpgradeToData & {
|
|
37
37
|
createModularAccountV2FromExisting: () => Promise<ModularAccountV2<TSigner>>;
|
|
38
38
|
}>;
|
|
39
|
+
export declare const entityIdAndNonceReaderBytecode = "0x608060405234801561001057600080fd5b506040516104f13803806104f183398101604081905261002f916101e5565b60006008826001600160c01b0316901c90506000808263ffffffff1611610057576001610059565b815b90506001600160a01b0385163b15610133575b60006001600160a01b03861663d31b575b6bffffffff0000000000000000604085901b166040516001600160e01b031960e084901b1681526001600160401b03199091166004820152602401600060405180830381865afa1580156100d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100fd91908101906103c6565b805190915060ff161580156101155750606081015151155b156101205750610133565b8161012a816104a4565b9250505061006c565b604051631aab3f0d60e11b81526001600160a01b03868116600483015264ffffffff01600160c01b038516600884901b64ffffffff0016176024830152600091908616906335567e1a90604401602060405180830381865afa15801561019d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c191906104d7565b90508060005260206000f35b6001600160a01b03811681146101e257600080fd5b50565b6000806000606084860312156101fa57600080fd5b8351610205816101cd565b6020850151909350610216816101cd565b60408501519092506001600160c01b038116811461023357600080fd5b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156102765761027661023e565b60405290565b604051601f8201601f191681016001600160401b03811182821017156102a4576102a461023e565b604052919050565b60006001600160401b038211156102c5576102c561023e565b5060051b60200190565b600082601f8301126102e057600080fd5b81516102f36102ee826102ac565b61027c565b8082825260208201915060208360051b86010192508583111561031557600080fd5b602085015b8381101561034857805166ffffffffffffff198116811461033a57600080fd5b83526020928301920161031a565b5095945050505050565b600082601f83011261036357600080fd5b81516103716102ee826102ac565b8082825260208201915060208360051b86010192508583111561039357600080fd5b602085015b838110156103485780516001600160e01b0319811681146103b857600080fd5b835260209283019201610398565b6000602082840312156103d857600080fd5b81516001600160401b038111156103ee57600080fd5b82016080818503121561040057600080fd5b610408610254565b815160ff8116811461041957600080fd5b815260208201516001600160401b0381111561043457600080fd5b610440868285016102cf565b60208301525060408201516001600160401b0381111561045f57600080fd5b61046b868285016102cf565b60408301525060608201516001600160401b0381111561048a57600080fd5b61049686828501610352565b606083015250949350505050565b600063ffffffff821663ffffffff81036104ce57634e487b7160e01b600052601160045260246000fd5b60010192915050565b6000602082840312156104e957600080fd5b505191905056fe";
|
|
40
|
+
export type BuildNonceParams = {
|
|
41
|
+
nonceKey?: bigint;
|
|
42
|
+
entityId?: number;
|
|
43
|
+
isGlobalValidation?: boolean;
|
|
44
|
+
isDeferredAction?: boolean;
|
|
45
|
+
isDirectCallValidation?: boolean;
|
|
46
|
+
};
|
|
47
|
+
export declare const buildFullNonceKey: ({ nonceKey, entityId, isGlobalValidation, isDeferredAction, }: BuildNonceParams) => bigint;
|
|
@@ -148,4 +148,11 @@ export async function getMAV2UpgradeToData(client, args) {
|
|
|
148
148
|
}),
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
+
export const entityIdAndNonceReaderBytecode = "0x608060405234801561001057600080fd5b506040516104f13803806104f183398101604081905261002f916101e5565b60006008826001600160c01b0316901c90506000808263ffffffff1611610057576001610059565b815b90506001600160a01b0385163b15610133575b60006001600160a01b03861663d31b575b6bffffffff0000000000000000604085901b166040516001600160e01b031960e084901b1681526001600160401b03199091166004820152602401600060405180830381865afa1580156100d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100fd91908101906103c6565b805190915060ff161580156101155750606081015151155b156101205750610133565b8161012a816104a4565b9250505061006c565b604051631aab3f0d60e11b81526001600160a01b03868116600483015264ffffffff01600160c01b038516600884901b64ffffffff0016176024830152600091908616906335567e1a90604401602060405180830381865afa15801561019d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c191906104d7565b90508060005260206000f35b6001600160a01b03811681146101e257600080fd5b50565b6000806000606084860312156101fa57600080fd5b8351610205816101cd565b6020850151909350610216816101cd565b60408501519092506001600160c01b038116811461023357600080fd5b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156102765761027661023e565b60405290565b604051601f8201601f191681016001600160401b03811182821017156102a4576102a461023e565b604052919050565b60006001600160401b038211156102c5576102c561023e565b5060051b60200190565b600082601f8301126102e057600080fd5b81516102f36102ee826102ac565b61027c565b8082825260208201915060208360051b86010192508583111561031557600080fd5b602085015b8381101561034857805166ffffffffffffff198116811461033a57600080fd5b83526020928301920161031a565b5095945050505050565b600082601f83011261036357600080fd5b81516103716102ee826102ac565b8082825260208201915060208360051b86010192508583111561039357600080fd5b602085015b838110156103485780516001600160e01b0319811681146103b857600080fd5b835260209283019201610398565b6000602082840312156103d857600080fd5b81516001600160401b038111156103ee57600080fd5b82016080818503121561040057600080fd5b610408610254565b815160ff8116811461041957600080fd5b815260208201516001600160401b0381111561043457600080fd5b610440868285016102cf565b60208301525060408201516001600160401b0381111561045f57600080fd5b61046b868285016102cf565b60408301525060608201516001600160401b0381111561048a57600080fd5b61049686828501610352565b606083015250949350505050565b600063ffffffff821663ffffffff81036104ce57634e487b7160e01b600052601160045260246000fd5b60010192915050565b6000602082840312156104e957600080fd5b505191905056fe";
|
|
152
|
+
export const buildFullNonceKey = ({ nonceKey = 0n, entityId = 0, isGlobalValidation = true, isDeferredAction = false, }) => {
|
|
153
|
+
return ((nonceKey << 40n) +
|
|
154
|
+
BigInt(entityId << 8) +
|
|
155
|
+
(isDeferredAction ? 2n : 0n) +
|
|
156
|
+
(isGlobalValidation ? 1n : 0n));
|
|
157
|
+
};
|
|
151
158
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/ma-v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,kBAAkB,GAKnB,MAAM,MAAM,CAAC;AACd,OAAO,EACL,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,WAAW,EACX,OAAO,EACP,QAAQ,EACR,eAAe,EACf,OAAO,EACP,WAAW,EACX,OAAO,GACR,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAyB,MAAM,0CAA0C,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E5E,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,MAAM,QAAQ,GAAG,kBAAkB,CAAC;QAClC,GAAG,EAAE,4BAA4B;QACjC,YAAY,EAAE,YAAY;QAC1B,IAAI,EAAE,CAAC,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC,UAAU,EAAE,CAAC;KAC/C,CAAC,CAAC;IAEH,OAAO;QACL,WAAW,EAAE,6BAA6B,CAAC,KAAK,CAAC;QACjD,kBAAkB,EAAE,QAAQ;QAC5B,kCAAkC,EAAE,KAAK,IAAI,EAAE,CAC7C,sBAAsB,CAAC;YACrB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;YACnC,KAAK,EAAE,KAAc;YACrB,MAAM,EAAE,OAAO,CAAC,SAAS,EAAE;YAC3B,cAAc,EAAE,OAAO,CAAC,OAAO;SAChC,CAAC;KACL,CAAC;AACJ,CAAC","sourcesContent":["import {\n concat,\n toHex,\n custom,\n encodeFunctionData,\n type Hex,\n type Chain,\n type Address,\n type Transport,\n} from \"viem\";\nimport {\n arbitrum,\n arbitrumSepolia,\n base,\n baseSepolia,\n mainnet,\n optimism,\n optimismSepolia,\n polygon,\n polygonAmoy,\n sepolia,\n} from \"@account-kit/infra\";\nimport { createModularAccountV2 } from \"./account/modularAccountV2.js\";\nimport { type ModularAccountV2 } from \"./account/common/modularAccountV2Base.js\";\nimport { semiModularAccountStorageAbi } from \"./abis/semiModularAccountStorageAbi.js\";\nimport {\n AccountNotFoundError,\n ChainNotFoundError,\n type GetAccountParameter,\n type SmartAccountClient,\n type SmartAccountSigner,\n type SmartContractAccountWithSigner,\n type UpgradeToData,\n} from \"@aa-sdk/core\";\n\nexport const DEFAULT_OWNER_ENTITY_ID = 0;\n\nexport type PackUOSignatureParams = {\n // orderedHookData: HookData[];\n validationSignature: Hex;\n};\n\n// TODO: direct call validation 1271\nexport type Pack1271SignatureParams = {\n validationSignature: Hex;\n entityId: number;\n};\n\n// Signature packing utility for user operations\nexport const packUOSignature = ({\n // orderedHookData, TODO: integrate in next iteration of MAv2 sdk\n validationSignature,\n}: PackUOSignatureParams): Hex => {\n return concat([\"0xFF\", \"0x00\", validationSignature]);\n};\n\n// Signature packing utility for 1271 signatures\nexport const pack1271Signature = ({\n validationSignature,\n entityId,\n}: Pack1271SignatureParams): Hex => {\n return concat([\n \"0x00\",\n toHex(entityId, { size: 4 }),\n \"0xFF\",\n \"0x00\", // EOA type signature\n validationSignature,\n ]);\n};\n\nexport const getDefaultMAV2FactoryAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x00000000000017c61b5bEe81050EC8eFc9c6fecd\";\n }\n};\n\nexport const getDefaultSMAV2BytecodeAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x000000000000c5A9089039570Dd36455b5C07383\";\n }\n};\n\nexport const getDefaultSMAV2StorageAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x0000000000006E2f9d80CaEc0Da6500f005EB25A\";\n }\n};\n\nexport const getDefaultSMAV27702Address = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x69007702764179f14F51cdce752f4f775d74E139\";\n }\n};\n\nexport const getDefaultMAV2Address = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x00000000000002377B26b1EdA7b0BC371C60DD4f\";\n }\n};\n\nexport type GetMAV2UpgradeToData<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TAccount extends\n | SmartContractAccountWithSigner<string, TSigner>\n | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined\n> = GetAccountParameter<TAccount>;\n\n/**\n * Retrieves the data necessary to upgrade to a Modular Account V2 (MA v2).\n * Note that the upgrade will be to the Semi Modular Account Storage variant\n *\n * @example\n * ```ts\n * import { createLightAccountClient, getMAV2UpgradeToData } from \"@account-kit/smart-contracts\";\n *\n * const client = createLightAccountClient({});\n * const upgradeData = await getMAV2UpgradeToData(client, {});\n * ```\n *\n * @param {SmartAccountClient<TTransport, TChain, TAccount>} client The smart account client\n * @param {GetMAV2UpgradeToData<TSigner, TAccount>} args The arguments required for the upgrade\n * @returns {Promise<UpgradeToData & { createModularAccountV2FromExisting: () => Promise<ModularAccountV2<TSigner>>}>} A promise that resolves to upgrade data augmented with a function to create a Modular Account V2\n */\nexport async function getMAV2UpgradeToData<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TAccount extends\n | SmartContractAccountWithSigner<string, TSigner>\n | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined\n>(\n client: SmartAccountClient<TTransport, TChain, TAccount>,\n args: GetMAV2UpgradeToData<TSigner, TAccount>\n): Promise<\n UpgradeToData & {\n createModularAccountV2FromExisting: () => Promise<\n ModularAccountV2<TSigner>\n >;\n }\n> {\n const { account: account_ = client.account } = args;\n\n if (!account_) {\n throw new AccountNotFoundError();\n }\n const account = account_ as SmartContractAccountWithSigner<string, TSigner>;\n\n const chain = client.chain;\n if (!chain) {\n throw new ChainNotFoundError();\n }\n\n const initData = encodeFunctionData({\n abi: semiModularAccountStorageAbi,\n functionName: \"initialize\",\n args: [await account.getSigner().getAddress()],\n });\n\n return {\n implAddress: getDefaultSMAV2StorageAddress(chain),\n initializationData: initData,\n createModularAccountV2FromExisting: async () =>\n createModularAccountV2({\n transport: custom(client.transport),\n chain: chain as Chain,\n signer: account.getSigner(),\n accountAddress: account.address,\n }),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/ma-v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,kBAAkB,GAKnB,MAAM,MAAM,CAAC;AACd,OAAO,EACL,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,WAAW,EACX,OAAO,EACP,QAAQ,EACR,eAAe,EACf,OAAO,EACP,WAAW,EACX,OAAO,GACR,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAyB,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AACtF,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GAMnB,MAAM,cAAc,CAAC;AAEtB,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAazC,gDAAgD;AAChD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC;AAC9B,iEAAiE;AACjE,mBAAmB,GACG,EAAO,EAAE;IAC/B,OAAO,MAAM,CAAC,CAAC,MAAM,EAAE,MA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H,OAAO;QACL,WAAW,EAAE,6BAA6B,CAAC,KAAK,CAAC;QACjD,kBAAkB,EAAE,QAAQ;QAC5B,kCAAkC,EAAE,KAAK,IAAI,EAAE,CAC7C,sBAAsB,CAAC;YACrB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;YACnC,KAAK,EAAE,KAAc;YACrB,MAAM,EAAE,OAAO,CAAC,SAAS,EAAE;YAC3B,cAAc,EAAE,OAAO,CAAC,OAAO;SAChC,CAAC;KACL,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,8BAA8B,GACzC,s+EAAs+E,CAAC;AAUz+E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,QAAQ,GAAG,EAAE,EACb,QAAQ,GAAG,CAAC,EACZ,kBAAkB,GAAG,IAAI,EACzB,gBAAgB,GAAG,KAAK,GACP,EAAU,EAAE;IAC7B,OAAO,CACL,CAAC,QAAQ,IAAI,GAAG,CAAC;QACjB,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;QACrB,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5B,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC/B,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n concat,\n toHex,\n custom,\n encodeFunctionData,\n type Hex,\n type Chain,\n type Address,\n type Transport,\n} from \"viem\";\nimport {\n arbitrum,\n arbitrumSepolia,\n base,\n baseSepolia,\n mainnet,\n optimism,\n optimismSepolia,\n polygon,\n polygonAmoy,\n sepolia,\n} from \"@account-kit/infra\";\nimport { createModularAccountV2 } from \"./account/modularAccountV2.js\";\nimport { type ModularAccountV2 } from \"./account/common/modularAccountV2Base.js\";\nimport { semiModularAccountStorageAbi } from \"./abis/semiModularAccountStorageAbi.js\";\nimport {\n AccountNotFoundError,\n ChainNotFoundError,\n type GetAccountParameter,\n type SmartAccountClient,\n type SmartAccountSigner,\n type SmartContractAccountWithSigner,\n type UpgradeToData,\n} from \"@aa-sdk/core\";\n\nexport const DEFAULT_OWNER_ENTITY_ID = 0;\n\nexport type PackUOSignatureParams = {\n // orderedHookData: HookData[];\n validationSignature: Hex;\n};\n\n// TODO: direct call validation 1271\nexport type Pack1271SignatureParams = {\n validationSignature: Hex;\n entityId: number;\n};\n\n// Signature packing utility for user operations\nexport const packUOSignature = ({\n // orderedHookData, TODO: integrate in next iteration of MAv2 sdk\n validationSignature,\n}: PackUOSignatureParams): Hex => {\n return concat([\"0xFF\", \"0x00\", validationSignature]);\n};\n\n// Signature packing utility for 1271 signatures\nexport const pack1271Signature = ({\n validationSignature,\n entityId,\n}: Pack1271SignatureParams): Hex => {\n return concat([\n \"0x00\",\n toHex(entityId, { size: 4 }),\n \"0xFF\",\n \"0x00\", // EOA type signature\n validationSignature,\n ]);\n};\n\nexport const getDefaultMAV2FactoryAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x00000000000017c61b5bEe81050EC8eFc9c6fecd\";\n }\n};\n\nexport const getDefaultSMAV2BytecodeAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x000000000000c5A9089039570Dd36455b5C07383\";\n }\n};\n\nexport const getDefaultSMAV2StorageAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x0000000000006E2f9d80CaEc0Da6500f005EB25A\";\n }\n};\n\nexport const getDefaultSMAV27702Address = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x69007702764179f14F51cdce752f4f775d74E139\";\n }\n};\n\nexport const getDefaultMAV2Address = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.id:\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x00000000000002377B26b1EdA7b0BC371C60DD4f\";\n }\n};\n\nexport type GetMAV2UpgradeToData<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TAccount extends\n | SmartContractAccountWithSigner<string, TSigner>\n | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined\n> = GetAccountParameter<TAccount>;\n\n/**\n * Retrieves the data necessary to upgrade to a Modular Account V2 (MA v2).\n * Note that the upgrade will be to the Semi Modular Account Storage variant\n *\n * @example\n * ```ts\n * import { createLightAccountClient, getMAV2UpgradeToData } from \"@account-kit/smart-contracts\";\n *\n * const client = createLightAccountClient({});\n * const upgradeData = await getMAV2UpgradeToData(client, {});\n * ```\n *\n * @param {SmartAccountClient<TTransport, TChain, TAccount>} client The smart account client\n * @param {GetMAV2UpgradeToData<TSigner, TAccount>} args The arguments required for the upgrade\n * @returns {Promise<UpgradeToData & { createModularAccountV2FromExisting: () => Promise<ModularAccountV2<TSigner>>}>} A promise that resolves to upgrade data augmented with a function to create a Modular Account V2\n */\nexport async function getMAV2UpgradeToData<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TAccount extends\n | SmartContractAccountWithSigner<string, TSigner>\n | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined\n>(\n client: SmartAccountClient<TTransport, TChain, TAccount>,\n args: GetMAV2UpgradeToData<TSigner, TAccount>\n): Promise<\n UpgradeToData & {\n createModularAccountV2FromExisting: () => Promise<\n ModularAccountV2<TSigner>\n >;\n }\n> {\n const { account: account_ = client.account } = args;\n\n if (!account_) {\n throw new AccountNotFoundError();\n }\n const account = account_ as SmartContractAccountWithSigner<string, TSigner>;\n\n const chain = client.chain;\n if (!chain) {\n throw new ChainNotFoundError();\n }\n\n const initData = encodeFunctionData({\n abi: semiModularAccountStorageAbi,\n functionName: \"initialize\",\n args: [await account.getSigner().getAddress()],\n });\n\n return {\n implAddress: getDefaultSMAV2StorageAddress(chain),\n initializationData: initData,\n createModularAccountV2FromExisting: async () =>\n createModularAccountV2({\n transport: custom(client.transport),\n chain: chain as Chain,\n signer: account.getSigner(),\n accountAddress: account.address,\n }),\n };\n}\n\nexport const entityIdAndNonceReaderBytecode =\n \"0x608060405234801561001057600080fd5b506040516104f13803806104f183398101604081905261002f916101e5565b60006008826001600160c01b0316901c90506000808263ffffffff1611610057576001610059565b815b90506001600160a01b0385163b15610133575b60006001600160a01b03861663d31b575b6bffffffff0000000000000000604085901b166040516001600160e01b031960e084901b1681526001600160401b03199091166004820152602401600060405180830381865afa1580156100d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100fd91908101906103c6565b805190915060ff161580156101155750606081015151155b156101205750610133565b8161012a816104a4565b9250505061006c565b604051631aab3f0d60e11b81526001600160a01b03868116600483015264ffffffff01600160c01b038516600884901b64ffffffff0016176024830152600091908616906335567e1a90604401602060405180830381865afa15801561019d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c191906104d7565b90508060005260206000f35b6001600160a01b03811681146101e257600080fd5b50565b6000806000606084860312156101fa57600080fd5b8351610205816101cd565b6020850151909350610216816101cd565b60408501519092506001600160c01b038116811461023357600080fd5b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156102765761027661023e565b60405290565b604051601f8201601f191681016001600160401b03811182821017156102a4576102a461023e565b604052919050565b60006001600160401b038211156102c5576102c561023e565b5060051b60200190565b600082601f8301126102e057600080fd5b81516102f36102ee826102ac565b61027c565b8082825260208201915060208360051b86010192508583111561031557600080fd5b602085015b8381101561034857805166ffffffffffffff198116811461033a57600080fd5b83526020928301920161031a565b5095945050505050565b600082601f83011261036357600080fd5b81516103716102ee826102ac565b8082825260208201915060208360051b86010192508583111561039357600080fd5b602085015b838110156103485780516001600160e01b0319811681146103b857600080fd5b835260209283019201610398565b6000602082840312156103d857600080fd5b81516001600160401b038111156103ee57600080fd5b82016080818503121561040057600080fd5b610408610254565b815160ff8116811461041957600080fd5b815260208201516001600160401b0381111561043457600080fd5b610440868285016102cf565b60208301525060408201516001600160401b0381111561045f57600080fd5b61046b868285016102cf565b60408301525060608201516001600160401b0381111561048a57600080fd5b61049686828501610352565b606083015250949350505050565b600063ffffffff821663ffffffff81036104ce57634e487b7160e01b600052601160045260246000fd5b60010192915050565b6000602082840312156104e957600080fd5b505191905056fe\";\n\nexport type BuildNonceParams = {\n nonceKey?: bigint;\n entityId?: number;\n isGlobalValidation?: boolean;\n isDeferredAction?: boolean;\n isDirectCallValidation?: boolean;\n};\n\nexport const buildFullNonceKey = ({\n nonceKey = 0n,\n entityId = 0,\n isGlobalValidation = true,\n isDeferredAction = false,\n}: BuildNonceParams): bigint => {\n return (\n (nonceKey << 40n) +\n BigInt(entityId << 8) +\n (isDeferredAction ? 2n : 0n) +\n (isGlobalValidation ? 1n : 0n)\n );\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityIdAndNonceReader.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/abis/entityIdAndNonceReader.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB;;;;;;;;GAsBrC,CAAC"}
|
|
@@ -49,10 +49,19 @@ export type BuildUserOperationWithDeferredActionParams = {
|
|
|
49
49
|
signaturePrepend: Hex;
|
|
50
50
|
nonceOverride: bigint;
|
|
51
51
|
};
|
|
52
|
+
export type EntityIdAndNonceParams = {
|
|
53
|
+
entityId: number;
|
|
54
|
+
nonceKey: bigint;
|
|
55
|
+
isGlobalValidation: boolean;
|
|
56
|
+
};
|
|
52
57
|
export type DeferralActions = {
|
|
53
58
|
createDeferredActionTypedDataObject: (args: CreateDeferredActionTypedDataParams) => Promise<DeferredActionReturnData>;
|
|
54
59
|
buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;
|
|
55
60
|
buildUserOperationWithDeferredAction: (args: BuildUserOperationWithDeferredActionParams) => Promise<UserOperationRequest_v7>;
|
|
61
|
+
getEntityIdAndNonce: (args: EntityIdAndNonceParams) => Promise<{
|
|
62
|
+
nonce: bigint;
|
|
63
|
+
entityId: number;
|
|
64
|
+
}>;
|
|
56
65
|
};
|
|
57
66
|
/**
|
|
58
67
|
* Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
|
|
@@ -61,4 +70,4 @@ export type DeferralActions = {
|
|
|
61
70
|
* @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
|
|
62
71
|
*/
|
|
63
72
|
export declare const deferralActions: (client: ModularAccountV2Client) => DeferralActions;
|
|
64
|
-
//# sourceMappingURL=
|
|
73
|
+
//# sourceMappingURL=deferralActions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"deferralActions.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/actions/deferralActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC7B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,EAAE,GAAG,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,mCAAmC,EAAE,CACnC,IAAI,EAAE,mCAAmC,KACtC,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACvC,yBAAyB,EAAE,CAAC,IAAI,EAAE,+BAA+B,KAAK,GAAG,CAAC;IAC1E,oCAAoC,EAAE,CACpC,IAAI,EAAE,0CAA0C,KAC7C,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtC,mBAAmB,EAAE,CACnB,IAAI,EAAE,sBAAsB,KACzB,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,CAC5B,MAAM,EAAE,sBAAsB,KAC3B,eAmMJ,CAAC"}
|
|
@@ -9,6 +9,7 @@ export { serializeValidationConfig, serializeHookConfig, serializeModuleEntity,
|
|
|
9
9
|
export type * from "./actions/install-validation/installValidation.js";
|
|
10
10
|
export { installValidationActions } from "./actions/install-validation/installValidation.js";
|
|
11
11
|
export { getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddress, getDefaultPaymasterGuardModuleAddress, getDefaultSingleSignerValidationModuleAddress, getDefaultTimeRangeModuleAddress, getDefaultWebauthnValidationModuleAddress, } from "./modules/utils.js";
|
|
12
|
+
export { buildFullNonceKey } from "./utils.js";
|
|
12
13
|
export { allowlistModuleAbi } from "./modules/allowlist-module/abis/allowlistModuleAbi.js";
|
|
13
14
|
export { AllowlistModule } from "./modules/allowlist-module/module.js";
|
|
14
15
|
export { nativeTokenLimitModuleAbi } from "./modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,cAAc,GACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AACnC,mBAAmB,mDAAmD,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAE7F,OAAO,EACL,gCAAgC,EAChC,uCAAuC,EACvC,qCAAqC,EACrC,6CAA6C,EAC7C,gCAAgC,EAChC,yCAAyC,GAC1C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,uDAAuD,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uEAAuE,CAAC;AAClH,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kEAAkE,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,+BAA+B,EAAE,MAAM,4EAA4E,CAAC;AAC7H,OAAO,EAAE,4BAA4B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OAAO,EAAE,uBAAuB,EAAE,MAAM,kEAAkE,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,+BAA+B,EAAE,MAAM,4EAA4E,CAAC;AAC7H,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,MAAM,wDAAwD,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,MAAM,6DAA6D,CAAC"}
|
|
@@ -36,4 +36,13 @@ export type GetMAV2UpgradeToData<TSigner extends SmartAccountSigner = SmartAccou
|
|
|
36
36
|
export declare function getMAV2UpgradeToData<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TSigner extends SmartAccountSigner = SmartAccountSigner, TAccount extends SmartContractAccountWithSigner<string, TSigner> | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined>(client: SmartAccountClient<TTransport, TChain, TAccount>, args: GetMAV2UpgradeToData<TSigner, TAccount>): Promise<UpgradeToData & {
|
|
37
37
|
createModularAccountV2FromExisting: () => Promise<ModularAccountV2<TSigner>>;
|
|
38
38
|
}>;
|
|
39
|
+
export declare const entityIdAndNonceReaderBytecode = "0x608060405234801561001057600080fd5b506040516104f13803806104f183398101604081905261002f916101e5565b60006008826001600160c01b0316901c90506000808263ffffffff1611610057576001610059565b815b90506001600160a01b0385163b15610133575b60006001600160a01b03861663d31b575b6bffffffff0000000000000000604085901b166040516001600160e01b031960e084901b1681526001600160401b03199091166004820152602401600060405180830381865afa1580156100d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100fd91908101906103c6565b805190915060ff161580156101155750606081015151155b156101205750610133565b8161012a816104a4565b9250505061006c565b604051631aab3f0d60e11b81526001600160a01b03868116600483015264ffffffff01600160c01b038516600884901b64ffffffff0016176024830152600091908616906335567e1a90604401602060405180830381865afa15801561019d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c191906104d7565b90508060005260206000f35b6001600160a01b03811681146101e257600080fd5b50565b6000806000606084860312156101fa57600080fd5b8351610205816101cd565b6020850151909350610216816101cd565b60408501519092506001600160c01b038116811461023357600080fd5b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156102765761027661023e565b60405290565b604051601f8201601f191681016001600160401b03811182821017156102a4576102a461023e565b604052919050565b60006001600160401b038211156102c5576102c561023e565b5060051b60200190565b600082601f8301126102e057600080fd5b81516102f36102ee826102ac565b61027c565b8082825260208201915060208360051b86010192508583111561031557600080fd5b602085015b8381101561034857805166ffffffffffffff198116811461033a57600080fd5b83526020928301920161031a565b5095945050505050565b600082601f83011261036357600080fd5b81516103716102ee826102ac565b8082825260208201915060208360051b86010192508583111561039357600080fd5b602085015b838110156103485780516001600160e01b0319811681146103b857600080fd5b835260209283019201610398565b6000602082840312156103d857600080fd5b81516001600160401b038111156103ee57600080fd5b82016080818503121561040057600080fd5b610408610254565b815160ff8116811461041957600080fd5b815260208201516001600160401b0381111561043457600080fd5b610440868285016102cf565b60208301525060408201516001600160401b0381111561045f57600080fd5b61046b868285016102cf565b60408301525060608201516001600160401b0381111561048a57600080fd5b61049686828501610352565b606083015250949350505050565b600063ffffffff821663ffffffff81036104ce57634e487b7160e01b600052601160045260246000fd5b60010192915050565b6000602082840312156104e957600080fd5b505191905056fe";
|
|
40
|
+
export type BuildNonceParams = {
|
|
41
|
+
nonceKey?: bigint;
|
|
42
|
+
entityId?: number;
|
|
43
|
+
isGlobalValidation?: boolean;
|
|
44
|
+
isDeferredAction?: boolean;
|
|
45
|
+
isDirectCallValidation?: boolean;
|
|
46
|
+
};
|
|
47
|
+
export declare const buildFullNonceKey: ({ nonceKey, entityId, isGlobalValidation, isDeferredAction, }: BuildNonceParams) => bigint;
|
|
39
48
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version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CAAC;AAEz+E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,iBAAiB,kEAK3B,gBAAgB,KAAG,MAOrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/smart-contracts",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.22.0",
|
|
4
4
|
"description": "aa-sdk compatible interfaces for Alchemy Smart Accounts",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"test:run": "vitest run"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@account-kit/plugingen": "^4.
|
|
55
|
+
"@account-kit/plugingen": "^4.22.0",
|
|
56
56
|
"change-case": "^5.1.2",
|
|
57
57
|
"dedent": "^1.5.1",
|
|
58
58
|
"dotenv": "^16.3.1",
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
73
73
|
},
|
|
74
74
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "07a9e38db91c0a8937f3e2f28e25c95605e31698",
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@aa-sdk/core": "^4.
|
|
78
|
-
"@account-kit/infra": "^4.
|
|
77
|
+
"@aa-sdk/core": "^4.22.0",
|
|
78
|
+
"@account-kit/infra": "^4.22.0"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"viem": "^2.22.6"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const entityIdAndNonceReaderAbi = [
|
|
2
|
+
{
|
|
3
|
+
type: "constructor",
|
|
4
|
+
inputs: [
|
|
5
|
+
{
|
|
6
|
+
name: "account",
|
|
7
|
+
type: "address",
|
|
8
|
+
internalType: "contract IModularAccountView",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: "ep",
|
|
12
|
+
type: "address",
|
|
13
|
+
internalType: "contract IEntryPoint",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "nonce",
|
|
17
|
+
type: "uint192",
|
|
18
|
+
internalType: "uint192",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
stateMutability: "nonpayable",
|
|
22
|
+
},
|
|
23
|
+
];
|
|
@@ -15,7 +15,11 @@ import {
|
|
|
15
15
|
encodePacked,
|
|
16
16
|
size,
|
|
17
17
|
toHex,
|
|
18
|
+
encodeDeployData,
|
|
19
|
+
hexToNumber,
|
|
18
20
|
} from "viem";
|
|
21
|
+
import { entityIdAndNonceReaderBytecode, buildFullNonceKey } from "../utils.js";
|
|
22
|
+
import { entityIdAndNonceReaderAbi } from "../abis/entityIdAndNonceReader.js";
|
|
19
23
|
import type { ModularAccountV2Client } from "../client/client.js";
|
|
20
24
|
|
|
21
25
|
export type DeferredActionTypedData = {
|
|
@@ -62,6 +66,12 @@ export type BuildUserOperationWithDeferredActionParams = {
|
|
|
62
66
|
nonceOverride: bigint;
|
|
63
67
|
};
|
|
64
68
|
|
|
69
|
+
export type EntityIdAndNonceParams = {
|
|
70
|
+
entityId: number;
|
|
71
|
+
nonceKey: bigint;
|
|
72
|
+
isGlobalValidation: boolean;
|
|
73
|
+
};
|
|
74
|
+
|
|
65
75
|
export type DeferralActions = {
|
|
66
76
|
createDeferredActionTypedDataObject: (
|
|
67
77
|
args: CreateDeferredActionTypedDataParams
|
|
@@ -70,6 +80,9 @@ export type DeferralActions = {
|
|
|
70
80
|
buildUserOperationWithDeferredAction: (
|
|
71
81
|
args: BuildUserOperationWithDeferredActionParams
|
|
72
82
|
) => Promise<UserOperationRequest_v7>;
|
|
83
|
+
getEntityIdAndNonce: (
|
|
84
|
+
args: EntityIdAndNonceParams
|
|
85
|
+
) => Promise<{ nonce: bigint; entityId: number }>;
|
|
73
86
|
};
|
|
74
87
|
|
|
75
88
|
/**
|
|
@@ -86,15 +99,14 @@ export const deferralActions: (
|
|
|
86
99
|
deadline,
|
|
87
100
|
entityId,
|
|
88
101
|
isGlobalValidation,
|
|
89
|
-
nonceKeyOverride,
|
|
102
|
+
nonceKeyOverride = 0n,
|
|
90
103
|
}: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {
|
|
91
104
|
if (!client.account) {
|
|
92
105
|
throw new AccountNotFoundError();
|
|
93
106
|
}
|
|
94
107
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
throw new InvalidNonceKeyError(baseNonceKey);
|
|
108
|
+
if (nonceKeyOverride > maxUint152) {
|
|
109
|
+
throw new InvalidNonceKeyError(nonceKeyOverride);
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
const entryPoint = client.account.getEntryPoint();
|
|
@@ -110,10 +122,12 @@ export const deferralActions: (
|
|
|
110
122
|
|
|
111
123
|
// 2 = deferred action flags 0b10
|
|
112
124
|
// 1 = isGlobal validation flag 0b01
|
|
113
|
-
const fullNonceKey: bigint =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
const fullNonceKey: bigint = buildFullNonceKey({
|
|
126
|
+
nonceKey: nonceKeyOverride,
|
|
127
|
+
entityId,
|
|
128
|
+
isGlobalValidation,
|
|
129
|
+
isDeferredAction: true,
|
|
130
|
+
});
|
|
117
131
|
|
|
118
132
|
const nonceOverride = (await entryPointContract.read.getNonce([
|
|
119
133
|
client.account.address,
|
|
@@ -224,9 +238,54 @@ export const deferralActions: (
|
|
|
224
238
|
return unsignedUo;
|
|
225
239
|
};
|
|
226
240
|
|
|
241
|
+
const getEntityIdAndNonce = async ({
|
|
242
|
+
entityId,
|
|
243
|
+
nonceKey,
|
|
244
|
+
isGlobalValidation,
|
|
245
|
+
}: EntityIdAndNonceParams) => {
|
|
246
|
+
if (!client.account) {
|
|
247
|
+
throw new AccountNotFoundError();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (nonceKey > maxUint152) {
|
|
251
|
+
throw new InvalidNonceKeyError(nonceKey);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const entryPoint = client.account.getEntryPoint();
|
|
255
|
+
if (entryPoint === undefined) {
|
|
256
|
+
throw new EntryPointNotFoundError(client.chain, "0.7.0");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const bytecode = encodeDeployData({
|
|
260
|
+
abi: entityIdAndNonceReaderAbi,
|
|
261
|
+
bytecode: entityIdAndNonceReaderBytecode,
|
|
262
|
+
args: [
|
|
263
|
+
client.account.address,
|
|
264
|
+
entryPoint.address,
|
|
265
|
+
buildFullNonceKey({
|
|
266
|
+
nonceKey,
|
|
267
|
+
entityId,
|
|
268
|
+
isGlobalValidation,
|
|
269
|
+
isDeferredAction: true,
|
|
270
|
+
}),
|
|
271
|
+
],
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const { data } = await client.call({ data: bytecode });
|
|
275
|
+
if (!data) {
|
|
276
|
+
throw new Error("No data returned from contract call");
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
nonce: BigInt(data),
|
|
281
|
+
entityId: hexToNumber(`0x${data.slice(40, 48)}`),
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
|
|
227
285
|
return {
|
|
228
286
|
createDeferredActionTypedDataObject,
|
|
229
287
|
buildDeferredActionDigest,
|
|
230
288
|
buildUserOperationWithDeferredAction,
|
|
289
|
+
getEntityIdAndNonce,
|
|
231
290
|
};
|
|
232
291
|
};
|
package/src/ma-v2/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export {
|
|
|
29
29
|
getDefaultTimeRangeModuleAddress,
|
|
30
30
|
getDefaultWebauthnValidationModuleAddress,
|
|
31
31
|
} from "./modules/utils.js";
|
|
32
|
+
export { buildFullNonceKey } from "./utils.js";
|
|
32
33
|
export { allowlistModuleAbi } from "./modules/allowlist-module/abis/allowlistModuleAbi.js";
|
|
33
34
|
export { AllowlistModule } from "./modules/allowlist-module/module.js";
|
|
34
35
|
export { nativeTokenLimitModuleAbi } from "./modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js";
|
package/src/ma-v2/utils.ts
CHANGED
|
@@ -228,3 +228,28 @@ export async function getMAV2UpgradeToData<
|
|
|
228
228
|
}),
|
|
229
229
|
};
|
|
230
230
|
}
|
|
231
|
+
|
|
232
|
+
export const entityIdAndNonceReaderBytecode =
|
|
233
|
+
"0x608060405234801561001057600080fd5b506040516104f13803806104f183398101604081905261002f916101e5565b60006008826001600160c01b0316901c90506000808263ffffffff1611610057576001610059565b815b90506001600160a01b0385163b15610133575b60006001600160a01b03861663d31b575b6bffffffff0000000000000000604085901b166040516001600160e01b031960e084901b1681526001600160401b03199091166004820152602401600060405180830381865afa1580156100d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100fd91908101906103c6565b805190915060ff161580156101155750606081015151155b156101205750610133565b8161012a816104a4565b9250505061006c565b604051631aab3f0d60e11b81526001600160a01b03868116600483015264ffffffff01600160c01b038516600884901b64ffffffff0016176024830152600091908616906335567e1a90604401602060405180830381865afa15801561019d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c191906104d7565b90508060005260206000f35b6001600160a01b03811681146101e257600080fd5b50565b6000806000606084860312156101fa57600080fd5b8351610205816101cd565b6020850151909350610216816101cd565b60408501519092506001600160c01b038116811461023357600080fd5b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156102765761027661023e565b60405290565b604051601f8201601f191681016001600160401b03811182821017156102a4576102a461023e565b604052919050565b60006001600160401b038211156102c5576102c561023e565b5060051b60200190565b600082601f8301126102e057600080fd5b81516102f36102ee826102ac565b61027c565b8082825260208201915060208360051b86010192508583111561031557600080fd5b602085015b8381101561034857805166ffffffffffffff198116811461033a57600080fd5b83526020928301920161031a565b5095945050505050565b600082601f83011261036357600080fd5b81516103716102ee826102ac565b8082825260208201915060208360051b86010192508583111561039357600080fd5b602085015b838110156103485780516001600160e01b0319811681146103b857600080fd5b835260209283019201610398565b6000602082840312156103d857600080fd5b81516001600160401b038111156103ee57600080fd5b82016080818503121561040057600080fd5b610408610254565b815160ff8116811461041957600080fd5b815260208201516001600160401b0381111561043457600080fd5b610440868285016102cf565b60208301525060408201516001600160401b0381111561045f57600080fd5b61046b868285016102cf565b60408301525060608201516001600160401b0381111561048a57600080fd5b61049686828501610352565b606083015250949350505050565b600063ffffffff821663ffffffff81036104ce57634e487b7160e01b600052601160045260246000fd5b60010192915050565b6000602082840312156104e957600080fd5b505191905056fe";
|
|
234
|
+
|
|
235
|
+
export type BuildNonceParams = {
|
|
236
|
+
nonceKey?: bigint;
|
|
237
|
+
entityId?: number;
|
|
238
|
+
isGlobalValidation?: boolean;
|
|
239
|
+
isDeferredAction?: boolean;
|
|
240
|
+
isDirectCallValidation?: boolean;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
export const buildFullNonceKey = ({
|
|
244
|
+
nonceKey = 0n,
|
|
245
|
+
entityId = 0,
|
|
246
|
+
isGlobalValidation = true,
|
|
247
|
+
isDeferredAction = false,
|
|
248
|
+
}: BuildNonceParams): bigint => {
|
|
249
|
+
return (
|
|
250
|
+
(nonceKey << 40n) +
|
|
251
|
+
BigInt(entityId << 8) +
|
|
252
|
+
(isDeferredAction ? 2n : 0n) +
|
|
253
|
+
(isGlobalValidation ? 1n : 0n)
|
|
254
|
+
);
|
|
255
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeferralActions.js","sourceRoot":"","sources":["../../../../../src/ma-v2/actions/DeferralActions.ts"],"names":[],"mappings":"A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F,OAAO;QACL,mCAAmC;QACnC,yBAAyB;QACzB,oCAAoC;KACrC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n AccountNotFoundError,\n InvalidNonceKeyError,\n EntryPointNotFoundError,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type UserOperationRequest_v7,\n} from \"@aa-sdk/core\";\nimport {\n type Address,\n type Hex,\n concatHex,\n maxUint152,\n getContract,\n encodePacked,\n size,\n toHex,\n} from \"viem\";\nimport type { ModularAccountV2Client } from \"../client/client.js\";\n\nexport type DeferredActionTypedData = {\n domain: {\n chainId: number;\n verifyingContract: Address;\n };\n types: {\n DeferredAction: [\n { name: \"nonce\"; type: \"uint256\" },\n { name: \"deadline\"; type: \"uint48\" },\n { name: \"call\"; type: \"bytes\" }\n ];\n };\n primaryType: \"DeferredAction\";\n message: {\n nonce: bigint;\n deadline: number;\n call: Hex;\n };\n};\n\nexport type DeferredActionReturnData = {\n typedData: DeferredActionTypedData;\n nonceOverride: bigint;\n};\n\nexport type CreateDeferredActionTypedDataParams = {\n callData: Hex;\n deadline: number;\n entityId: number;\n isGlobalValidation: boolean;\n nonceKeyOverride?: bigint;\n};\n\nexport type BuildDeferredActionDigestParams = {\n typedData: DeferredActionTypedData;\n sig: Hex;\n};\n\nexport type BuildUserOperationWithDeferredActionParams = {\n uo: UserOperationCallData | BatchUserOperationCallData;\n signaturePrepend: Hex;\n nonceOverride: bigint;\n};\n\nexport type DeferralActions = {\n createDeferredActionTypedDataObject: (\n args: CreateDeferredActionTypedDataParams\n ) => Promise<DeferredActionReturnData>;\n buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;\n buildUserOperationWithDeferredAction: (\n args: BuildUserOperationWithDeferredActionParams\n ) => Promise<UserOperationRequest_v7>;\n};\n\n/**\n * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.\n *\n * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.\n * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.\n */\nexport const deferralActions: (\n client: ModularAccountV2Client\n) => DeferralActions = (client: ModularAccountV2Client): DeferralActions => {\n const createDeferredActionTypedDataObject = async ({\n callData,\n deadline,\n entityId,\n isGlobalValidation,\n nonceKeyOverride,\n }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n const baseNonceKey = nonceKeyOverride || 0n;\n if (baseNonceKey > maxUint152) {\n throw new InvalidNonceKeyError(baseNonceKey);\n }\n\n const entryPoint = client.account.getEntryPoint();\n if (entryPoint === undefined) {\n throw new EntryPointNotFoundError(client.chain, \"0.7.0\");\n }\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client: client,\n });\n\n // 2 = deferred action flags 0b10\n // 1 = isGlobal validation flag 0b01\n const fullNonceKey: bigint =\n ((baseNonceKey << 40n) + (BigInt(entityId) << 8n)) |\n 2n |\n (isGlobalValidation ? 1n : 0n);\n\n const nonceOverride = (await entryPointContract.read.getNonce([\n client.account.address,\n fullNonceKey,\n ])) as bigint;\n\n return {\n typedData: {\n domain: {\n chainId: await client.getChainId(),\n verifyingContract: client.account.address,\n },\n types: {\n DeferredAction: [\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint48\" },\n { name: \"call\", type: \"bytes\" },\n ],\n },\n primaryType: \"DeferredAction\",\n message: {\n nonce: nonceOverride,\n deadline: deadline,\n call: callData,\n },\n },\n nonceOverride: nonceOverride,\n };\n };\n\n /**\n * Creates the digest which must be prepended to the userOp signature.\n *\n * Assumption: The client this extends is used to sign the typed data.\n *\n * @param {object} args The argument object containing the following:\n * @param {DeferredActionTypedData} args.typedData The typed data object for the deferred action\n * @param {Hex} args.sig The signature to include in the digest\n * @returns {Hex} The encoded digest to be prepended to the userOp signature\n */\n const buildDeferredActionDigest = ({\n typedData,\n sig,\n }: BuildDeferredActionDigestParams): Hex => {\n const signerEntity = client.account.signerEntity;\n const validationLocator =\n (BigInt(signerEntity.entityId) << 8n) |\n (signerEntity.isGlobalValidation ? 1n : 0n);\n\n let encodedData = encodePacked(\n [\"uint168\", \"uint48\", \"bytes\"],\n [validationLocator, typedData.message.deadline, typedData.message.call]\n );\n\n const encodedDataLength = size(encodedData);\n const sigLength = size(sig);\n\n encodedData = concatHex([\n toHex(encodedDataLength, { size: 4 }),\n encodedData,\n toHex(sigLength, { size: 4 }),\n sig,\n ]);\n\n return encodedData;\n };\n\n /**\n * Builds a user operation with a deferred action by wrapping buildUserOperation() with a dummy signature override.\n *\n * @param {object} args The argument object containing the following:\n * @param {UserOperationCallData | BatchUserOperationCallData} args.uo The user operation call data to build\n * @param {Hex} args.signaturePrepend The signature data to prepend to the dummy signature\n * @param {bigint} args.nonceOverride The nonce to override in the user operation, generally given from the typed data builder\n * @returns {Promise<UserOperationRequest_v7>} The unsigned user operation request with the deferred action\n */\n const buildUserOperationWithDeferredAction = async ({\n uo,\n signaturePrepend,\n nonceOverride,\n }: BuildUserOperationWithDeferredActionParams): Promise<UserOperationRequest_v7> => {\n // Check if client.account is defined\n if (client.account === undefined) {\n throw new AccountNotFoundError();\n }\n\n // Pre-fetch the dummy sig so we can override `client.account.getDummySignature()`\n const dummySig = await client.account.getDummySignature();\n\n // Cache the previous dummy signature getter\n const previousDummySigGetter = client.account.getDummySignature;\n\n // Override client.account.getDummySignature() so `client.buildUserOperation()` uses the prepended hex and the dummy signature during gas estimation\n client.account.getDummySignature = () => {\n return concatHex([signaturePrepend, dummySig as Hex]);\n };\n\n const unsignedUo = (await client.buildUserOperation({\n uo: uo,\n overrides: {\n nonce: nonceOverride,\n },\n })) as UserOperationRequest_v7;\n\n // Restore the dummy signature getter\n client.account.getDummySignature = previousDummySigGetter;\n\n return unsignedUo;\n };\n\n return {\n createDeferredActionTypedDataObject,\n buildDeferredActionDigest,\n buildUserOperationWithDeferredAction,\n };\n};\n"]}
|