@account-kit/smart-contracts 4.64.0 → 4.65.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/account/common/modularAccountV2Base.js +52 -16
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js.map +1 -1
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/ma-v2/account/common/modularAccountV2Base.ts +57 -15
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createBundlerClient, getEntryPoint, InvalidDeferredActionNonce, InvalidEntityIdError, InvalidNonceKeyError, toSmartContractAccount, } from "@aa-sdk/core";
|
|
2
|
-
import { concatHex, encodeFunctionData, getContract, maxUint152, maxUint32, zeroAddress, } from "viem";
|
|
2
|
+
import { concatHex, encodeFunctionData, getContract, maxUint152, maxUint32, zeroAddress, isAddressEqual, } from "viem";
|
|
3
3
|
import { modularAccountAbi } from "../../abis/modularAccountAbi.js";
|
|
4
4
|
import { serializeModuleEntity } from "../../actions/common/utils.js";
|
|
5
5
|
import { singleSignerMessageSigner } from "../../modules/single-signer-validation/signer.js";
|
|
@@ -54,11 +54,13 @@ export async function createMAv2Base(config) {
|
|
|
54
54
|
throw new InvalidDeferredActionNonce();
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
const encodeExecute = async ({ target, data, value, }) => await encodeCallData(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const encodeExecute = async ({ target, data, value, }) => await encodeCallData(!isAddressEqual(target, accountAddress)
|
|
58
|
+
? encodeFunctionData({
|
|
59
|
+
abi: modularAccountAbi,
|
|
60
|
+
functionName: "execute",
|
|
61
|
+
args: [target, value ?? 0n, data],
|
|
62
|
+
})
|
|
63
|
+
: data);
|
|
62
64
|
const encodeBatchExecute = async (txs) => await encodeCallData(encodeFunctionData({
|
|
63
65
|
abi: modularAccountAbi,
|
|
64
66
|
functionName: "executeBatch",
|
|
@@ -94,7 +96,19 @@ export async function createMAv2Base(config) {
|
|
|
94
96
|
client,
|
|
95
97
|
});
|
|
96
98
|
const getExecutionData = async (selector) => {
|
|
97
|
-
|
|
99
|
+
// Start both promises in parallel
|
|
100
|
+
const deployStatusPromise = isAccountDeployed();
|
|
101
|
+
const executionDataPromise = accountContract.read
|
|
102
|
+
.getExecutionData([selector])
|
|
103
|
+
.catch((error) => {
|
|
104
|
+
// Store the original error for potential re-throwing
|
|
105
|
+
// If the account is not deployed, we will get an error here that we want to swallow.
|
|
106
|
+
// Otherwise, we will re-throw the error.
|
|
107
|
+
return { error };
|
|
108
|
+
});
|
|
109
|
+
// Check if account is deployed first
|
|
110
|
+
const deployStatus = await deployStatusPromise;
|
|
111
|
+
if (deployStatus === false) {
|
|
98
112
|
return {
|
|
99
113
|
module: zeroAddress,
|
|
100
114
|
skipRuntimeValidation: false,
|
|
@@ -102,10 +116,33 @@ export async function createMAv2Base(config) {
|
|
|
102
116
|
executionHooks: [],
|
|
103
117
|
};
|
|
104
118
|
}
|
|
105
|
-
|
|
119
|
+
// Only await execution data if account is deployed
|
|
120
|
+
const executionData = await executionDataPromise;
|
|
121
|
+
if ("error" in executionData) {
|
|
122
|
+
throw executionData.error;
|
|
123
|
+
}
|
|
124
|
+
return executionData;
|
|
106
125
|
};
|
|
107
126
|
const getValidationData = async (args) => {
|
|
108
|
-
|
|
127
|
+
const { validationModuleAddress, entityId } = args;
|
|
128
|
+
// Start both promises in parallel
|
|
129
|
+
const deployStatusPromise = isAccountDeployed();
|
|
130
|
+
const validationDataPromise = accountContract.read
|
|
131
|
+
.getValidationData([
|
|
132
|
+
serializeModuleEntity({
|
|
133
|
+
moduleAddress: validationModuleAddress ?? zeroAddress,
|
|
134
|
+
entityId: entityId ?? Number(maxUint32),
|
|
135
|
+
}),
|
|
136
|
+
])
|
|
137
|
+
.catch((error) => {
|
|
138
|
+
// Store the original error for potential re-throwing
|
|
139
|
+
// If the account is not deployed, we will get an error here that we want to swallow.
|
|
140
|
+
// Otherwise, we will re-throw the error.
|
|
141
|
+
return { error };
|
|
142
|
+
});
|
|
143
|
+
// Check if account is deployed first
|
|
144
|
+
const deployStatus = await deployStatusPromise;
|
|
145
|
+
if (deployStatus === false) {
|
|
109
146
|
return {
|
|
110
147
|
validationHooks: [],
|
|
111
148
|
executionHooks: [],
|
|
@@ -113,13 +150,12 @@ export async function createMAv2Base(config) {
|
|
|
113
150
|
validationFlags: 0,
|
|
114
151
|
};
|
|
115
152
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
]);
|
|
153
|
+
// Only await validation data if account is deployed
|
|
154
|
+
const validationData = await validationDataPromise;
|
|
155
|
+
if ("error" in validationData) {
|
|
156
|
+
throw validationData.error;
|
|
157
|
+
}
|
|
158
|
+
return validationData;
|
|
123
159
|
};
|
|
124
160
|
const encodeCallData = async (callData) => {
|
|
125
161
|
const validationData = await getValidationData({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modularAccountV2Base.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,GAMvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,GAKZ,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,qDAAqD,CAAC;AAC/F,OAAO,EAAE,uBAAuB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C,OAAO,SAAS,CAAC,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC;QAC/C,GAAG,qCAAqC;QACxC,SAAS;QACT,KAAK;QACL,UAAU;QACV,cAAc;QACd,aAAa;QACb,kBAAkB;QAClB,QAAQ;QACR,GAAG,CAAC,MAAM;YACR,CAAC,CAAC,QAAQ,KAAK,uBAAuB;gBACpC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,kBAAkB,CAAC;gBACpE,CAAC,CAAC,yBAAyB,CACvB,MAAM,EACN,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB;YACL,CAAC,CAAC,wBAAwB;YACtB,sFAAsF;YACtF,UAAW,EACX,KAAK,EACL,IAAI,EACJ,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB,CAAC;KACP,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,GAAG,WAAW;YACd,YAAY;YACZ,gBAAgB;YAChB,iBAAiB;YACjB,cAAc;SACa,CAAC,CAAC,gEAAgE;IACjG,CAAC;IAED,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,YAAY;QACZ,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;KACc,CAAC,CAAC,gEAAgE;AAClG,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAA6B;IAE7B,OAAO,OAAO,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC/C,CAAC","sourcesContent":["import {\n createBundlerClient,\n getEntryPoint,\n InvalidDeferredActionNonce,\n InvalidEntityIdError,\n InvalidNonceKeyError,\n toSmartContractAccount,\n type AccountOp,\n type SmartAccountSigner,\n type SmartContractAccount,\n type SmartContractAccountWithSigner,\n type ToSmartContractAccountParams,\n} from \"@aa-sdk/core\";\nimport {\n concatHex,\n encodeFunctionData,\n getContract,\n maxUint152,\n maxUint32,\n zeroAddress,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport type { ToWebAuthnAccountParameters } from \"viem/account-abstraction\";\nimport { modularAccountAbi } from \"../../abis/modularAccountAbi.js\";\nimport { serializeModuleEntity } from \"../../actions/common/utils.js\";\nimport { singleSignerMessageSigner } from \"../../modules/single-signer-validation/signer.js\";\nimport { webauthnSigningFunctions } from \"../../modules/webauthn-validation/signingMethods.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from \"../../utils.js\";\nimport { nativeSMASigner } from \"../nativeSMASigner.js\";\n\nexport const executeUserOpSelector: Hex = \"0x8DD7712F\";\n\nexport type ModularAccountsV2 = ModularAccountV2 | WebauthnModularAccountV2;\n\nexport type SignerEntity = {\n isGlobalValidation: boolean;\n entityId: number;\n};\n\nexport type ExecutionDataView = {\n module: Address;\n skipRuntimeValidation: boolean;\n allowGlobalValidation: boolean;\n executionHooks: readonly Hex[];\n};\n\nexport type ValidationDataView = {\n validationHooks: readonly Hex[];\n executionHooks: readonly Hex[];\n selectors: readonly Hex[];\n validationFlags: number;\n};\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type ModularAccountV2<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = SmartContractAccountWithSigner<\"ModularAccountV2\", TSigner, \"0.7.0\"> & {\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type WebauthnModularAccountV2 = SmartContractAccount<\n \"ModularAccountV2\",\n \"0.7.0\"\n> & {\n params: ToWebAuthnAccountParameters;\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type CreateMAV2BaseParams<\n TSigner extends SmartAccountSigner | undefined =\n | SmartAccountSigner\n | undefined,\n TTransport extends Transport = Transport,\n> = Omit<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n // Implements the following methods required by `toSmartContractAccount`, and passes through any other parameters.\n | \"encodeExecute\"\n | \"encodeBatchExecute\"\n | \"getNonce\"\n | \"signMessage\"\n | \"signTypedData\"\n | \"getDummySignature\"\n | \"prepareSign\"\n | \"formatSign\"\n> & {\n signer: TSigner;\n signerEntity?: SignerEntity;\n accountAddress: Address;\n deferredAction?: Hex;\n};\n\nexport type CreateWebauthnMAV2BaseParams = Omit<\n CreateMAV2BaseParams,\n \"signer\"\n> & {\n credential: ToWebAuthnAccountParameters[\"credential\"];\n getFn?: ToWebAuthnAccountParameters[\"getFn\"] | undefined;\n rpId?: ToWebAuthnAccountParameters[\"rpId\"] | undefined;\n};\n\nexport type CreateMAV2BaseReturnType<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = Promise<ModularAccountV2<TSigner>>;\n\n// function overload\nexport async function createMAv2Base(\n config: CreateWebauthnMAV2BaseParams,\n): Promise<WebauthnModularAccountV2>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(config: CreateMAV2BaseParams): CreateMAV2BaseReturnType<TSigner>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(\n config: CreateMAV2BaseParams<TSigner> | CreateWebauthnMAV2BaseParams,\n): Promise<WebauthnModularAccountV2 | ModularAccountV2<TSigner>> {\n let {\n transport,\n chain,\n entryPoint = getEntryPoint(chain, { version: \"0.7.0\" }),\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n signerEntity: {\n isGlobalValidation = true,\n entityId = DEFAULT_OWNER_ENTITY_ID,\n } = {},\n accountAddress,\n deferredAction,\n ...remainingToSmartContractAccountParams\n } = config;\n\n const signer = \"signer\" in config ? config.signer : undefined;\n const credential = \"credential\" in config ? config.credential : undefined;\n const getFn = \"getFn\" in config ? config.getFn : undefined;\n const rpId = \"rpId\" in config ? config.rpId : undefined;\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client,\n });\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce: bigint = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n // Set these values if the deferred action has not been consumed. We check this with the EP\n const nextNonceForDeferredAction: bigint =\n (await entryPointContract.read.getNonce([\n accountAddress,\n deferredActionNonce >> 64n,\n ])) as bigint;\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonce();\n }\n }\n\n const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({\n target,\n data,\n value,\n }) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [target, value ?? 0n, data],\n }),\n );\n\n const encodeBatchExecute: (txs: AccountOp[]) => Promise<Hex> = async (txs) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n txs.map((tx) => ({\n target: tx.target,\n data: tx.data,\n value: tx.value ?? 0n,\n })),\n ],\n }),\n );\n\n const isAccountDeployed: () => Promise<boolean> = async () =>\n !!(await client.getCode({ address: accountAddress }));\n\n const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey: bigint =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n return entryPointContract.read.getNonce([\n accountAddress,\n fullNonceKey,\n ]) as Promise<bigint>;\n };\n\n const accountContract = getContract({\n address: accountAddress,\n abi: modularAccountAbi,\n client,\n });\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return await accountContract.read.getExecutionData([selector]);\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n return await accountContract.read.getValidationData([\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ]);\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n hasAssociatedExecHooks = false; // set to falsy value once used\n return concatHex([executeUserOpSelector, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([executeUserOpSelector, callData]);\n }\n return callData;\n };\n\n const baseAccount = await toSmartContractAccount({\n ...remainingToSmartContractAccountParams,\n transport,\n chain,\n entryPoint,\n accountAddress,\n encodeExecute,\n encodeBatchExecute,\n getNonce,\n ...(signer\n ? entityId === DEFAULT_OWNER_ENTITY_ID\n ? nativeSMASigner(signer, chain, accountAddress, deferredActionData)\n : singleSignerMessageSigner(\n signer,\n chain,\n accountAddress,\n entityId,\n deferredActionData,\n )\n : webauthnSigningFunctions(\n // credential required for webauthn mode is checked at modularAccountV2 creation level\n credential!,\n getFn,\n rpId,\n chain,\n accountAddress,\n entityId,\n deferredActionData,\n )),\n });\n\n if (!signer) {\n return {\n ...baseAccount,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n } as WebauthnModularAccountV2; // TO DO: figure out when this breaks! we shouldn't have to cast\n }\n\n return {\n ...baseAccount,\n getSigner: () => signer,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n } as ModularAccountV2<TSigner>; // TO DO: figure out when this breaks! we shouldn't have to cast\n}\n\nexport function isModularAccountV2(\n account: SmartContractAccount,\n): account is ModularAccountV2 | WebauthnModularAccountV2 {\n return account.source === \"ModularAccountV2\";\n}\n"]}
|
|
1
|
+
{"version":3,"file":"modularAccountV2Base.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,GAMvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,EACX,cAAc,GAKf,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,qDAAqD,CAAC;AAC/F,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;A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AC,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,kBAAkB,CAAC;gBACpE,CAAC,CAAC,yBAAyB,CACvB,MAAM,EACN,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB;YACL,CAAC,CAAC,wBAAwB;YACtB,sFAAsF;YACtF,UAAW,EACX,KAAK,EACL,IAAI,EACJ,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB,CAAC;KACP,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,GAAG,WAAW;YACd,YAAY;YACZ,gBAAgB;YAChB,iBAAiB;YACjB,cAAc;SACa,CAAC,CAAC,gEAAgE;IACjG,CAAC;IAED,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,YAAY;QACZ,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;KACc,CAAC,CAAC,gEAAgE;AAClG,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAA6B;IAE7B,OAAO,OAAO,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC/C,CAAC","sourcesContent":["import {\n createBundlerClient,\n getEntryPoint,\n InvalidDeferredActionNonce,\n InvalidEntityIdError,\n InvalidNonceKeyError,\n toSmartContractAccount,\n type AccountOp,\n type SmartAccountSigner,\n type SmartContractAccount,\n type SmartContractAccountWithSigner,\n type ToSmartContractAccountParams,\n} from \"@aa-sdk/core\";\nimport {\n concatHex,\n encodeFunctionData,\n getContract,\n maxUint152,\n maxUint32,\n zeroAddress,\n isAddressEqual,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport type { ToWebAuthnAccountParameters } from \"viem/account-abstraction\";\nimport { modularAccountAbi } from \"../../abis/modularAccountAbi.js\";\nimport { serializeModuleEntity } from \"../../actions/common/utils.js\";\nimport { singleSignerMessageSigner } from \"../../modules/single-signer-validation/signer.js\";\nimport { webauthnSigningFunctions } from \"../../modules/webauthn-validation/signingMethods.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from \"../../utils.js\";\nimport { nativeSMASigner } from \"../nativeSMASigner.js\";\n\nexport const executeUserOpSelector: Hex = \"0x8DD7712F\";\n\nexport type ModularAccountsV2 = ModularAccountV2 | WebauthnModularAccountV2;\n\nexport type SignerEntity = {\n isGlobalValidation: boolean;\n entityId: number;\n};\n\nexport type ExecutionDataView = {\n module: Address;\n skipRuntimeValidation: boolean;\n allowGlobalValidation: boolean;\n executionHooks: readonly Hex[];\n};\n\nexport type ValidationDataView = {\n validationHooks: readonly Hex[];\n executionHooks: readonly Hex[];\n selectors: readonly Hex[];\n validationFlags: number;\n};\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type ModularAccountV2<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = SmartContractAccountWithSigner<\"ModularAccountV2\", TSigner, \"0.7.0\"> & {\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type WebauthnModularAccountV2 = SmartContractAccount<\n \"ModularAccountV2\",\n \"0.7.0\"\n> & {\n params: ToWebAuthnAccountParameters;\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type CreateMAV2BaseParams<\n TSigner extends SmartAccountSigner | undefined =\n | SmartAccountSigner\n | undefined,\n TTransport extends Transport = Transport,\n> = Omit<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n // Implements the following methods required by `toSmartContractAccount`, and passes through any other parameters.\n | \"encodeExecute\"\n | \"encodeBatchExecute\"\n | \"getNonce\"\n | \"signMessage\"\n | \"signTypedData\"\n | \"getDummySignature\"\n | \"prepareSign\"\n | \"formatSign\"\n> & {\n signer: TSigner;\n signerEntity?: SignerEntity;\n accountAddress: Address;\n deferredAction?: Hex;\n};\n\nexport type CreateWebauthnMAV2BaseParams = Omit<\n CreateMAV2BaseParams,\n \"signer\"\n> & {\n credential: ToWebAuthnAccountParameters[\"credential\"];\n getFn?: ToWebAuthnAccountParameters[\"getFn\"] | undefined;\n rpId?: ToWebAuthnAccountParameters[\"rpId\"] | undefined;\n};\n\nexport type CreateMAV2BaseReturnType<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = Promise<ModularAccountV2<TSigner>>;\n\n// function overload\nexport async function createMAv2Base(\n config: CreateWebauthnMAV2BaseParams,\n): Promise<WebauthnModularAccountV2>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(config: CreateMAV2BaseParams): CreateMAV2BaseReturnType<TSigner>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(\n config: CreateMAV2BaseParams<TSigner> | CreateWebauthnMAV2BaseParams,\n): Promise<WebauthnModularAccountV2 | ModularAccountV2<TSigner>> {\n let {\n transport,\n chain,\n entryPoint = getEntryPoint(chain, { version: \"0.7.0\" }),\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n signerEntity: {\n isGlobalValidation = true,\n entityId = DEFAULT_OWNER_ENTITY_ID,\n } = {},\n accountAddress,\n deferredAction,\n ...remainingToSmartContractAccountParams\n } = config;\n\n const signer = \"signer\" in config ? config.signer : undefined;\n const credential = \"credential\" in config ? config.credential : undefined;\n const getFn = \"getFn\" in config ? config.getFn : undefined;\n const rpId = \"rpId\" in config ? config.rpId : undefined;\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client,\n });\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce: bigint = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n // Set these values if the deferred action has not been consumed. We check this with the EP\n const nextNonceForDeferredAction: bigint =\n (await entryPointContract.read.getNonce([\n accountAddress,\n deferredActionNonce >> 64n,\n ])) as bigint;\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonce();\n }\n }\n\n const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({\n target,\n data,\n value,\n }) =>\n await encodeCallData(\n !isAddressEqual(target, accountAddress)\n ? encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [target, value ?? 0n, data],\n })\n : data, // If the target is the same as the account address, we don't need to wrap in a call to `execute`.\n );\n\n const encodeBatchExecute: (txs: AccountOp[]) => Promise<Hex> = async (txs) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n txs.map((tx) => ({\n target: tx.target,\n data: tx.data,\n value: tx.value ?? 0n,\n })),\n ],\n }),\n );\n\n const isAccountDeployed: () => Promise<boolean> = async () =>\n !!(await client.getCode({ address: accountAddress }));\n\n const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey: bigint =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n return entryPointContract.read.getNonce([\n accountAddress,\n fullNonceKey,\n ]) as Promise<bigint>;\n };\n\n const accountContract = getContract({\n address: accountAddress,\n abi: modularAccountAbi,\n client,\n });\n\n const getExecutionData = async (selector: Hex) => {\n // Start both promises in parallel\n const deployStatusPromise = isAccountDeployed();\n const executionDataPromise = accountContract.read\n .getExecutionData([selector])\n .catch((error) => {\n // Store the original error for potential re-throwing\n // If the account is not deployed, we will get an error here that we want to swallow.\n // Otherwise, we will re-throw the error.\n return { error };\n });\n\n // Check if account is deployed first\n const deployStatus = await deployStatusPromise;\n\n if (deployStatus === false) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n // Only await execution data if account is deployed\n const executionData = await executionDataPromise;\n if (\"error\" in executionData) {\n throw executionData.error;\n }\n return executionData;\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n const { validationModuleAddress, entityId } = args;\n\n // Start both promises in parallel\n const deployStatusPromise = isAccountDeployed();\n const validationDataPromise = accountContract.read\n .getValidationData([\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ])\n .catch((error) => {\n // Store the original error for potential re-throwing\n // If the account is not deployed, we will get an error here that we want to swallow.\n // Otherwise, we will re-throw the error.\n return { error };\n });\n\n // Check if account is deployed first\n const deployStatus = await deployStatusPromise;\n\n if (deployStatus === false) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n // Only await validation data if account is deployed\n const validationData = await validationDataPromise;\n if (\"error\" in validationData) {\n throw validationData.error;\n }\n return validationData;\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n hasAssociatedExecHooks = false; // set to falsy value once used\n return concatHex([executeUserOpSelector, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([executeUserOpSelector, callData]);\n }\n return callData;\n };\n\n const baseAccount = await toSmartContractAccount({\n ...remainingToSmartContractAccountParams,\n transport,\n chain,\n entryPoint,\n accountAddress,\n encodeExecute,\n encodeBatchExecute,\n getNonce,\n ...(signer\n ? entityId === DEFAULT_OWNER_ENTITY_ID\n ? nativeSMASigner(signer, chain, accountAddress, deferredActionData)\n : singleSignerMessageSigner(\n signer,\n chain,\n accountAddress,\n entityId,\n deferredActionData,\n )\n : webauthnSigningFunctions(\n // credential required for webauthn mode is checked at modularAccountV2 creation level\n credential!,\n getFn,\n rpId,\n chain,\n accountAddress,\n entityId,\n deferredActionData,\n )),\n });\n\n if (!signer) {\n return {\n ...baseAccount,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n } as WebauthnModularAccountV2; // TO DO: figure out when this breaks! we shouldn't have to cast\n }\n\n return {\n ...baseAccount,\n getSigner: () => signer,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n } as ModularAccountV2<TSigner>; // TO DO: figure out when this breaks! we shouldn't have to cast\n}\n\nexport function isModularAccountV2(\n account: SmartContractAccount,\n): account is ModularAccountV2 | WebauthnModularAccountV2 {\n return account.source === \"ModularAccountV2\";\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modularAccountV2Base.d.ts","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,8BAA8B,EACnC,KAAK,4BAA4B,EAClC,MAAM,cAAc,CAAC;AACtB,OAAO,
|
|
1
|
+
{"version":3,"file":"modularAccountV2Base.d.ts","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],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AAU,EAAE,2BAA2B,CAAC,YAAY,CAAC,CAAC;IACtD,KAAK,CAAC,EAAE,2BAA2B,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IACzD,IAAI,CAAC,EAAE,2BAA2B,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,wBAAwB,CAClC,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,IACrD,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAGvC,wBAAsB,cAAc,CAClC,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAErC,wBAAsB,cAAc,CAClC,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EACvD,MAAM,EAAE,oBAAoB,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;AA+QnE,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,IAAI,gBAAgB,GAAG,wBAAwB,CAExD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/smart-contracts",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.65.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.65.0",
|
|
56
56
|
"change-case": "^5.1.2",
|
|
57
57
|
"dedent": "^1.5.1",
|
|
58
58
|
"dotenv": "^16.3.1",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
71
71
|
},
|
|
72
72
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "5433a77a6f488b7ba30d2be844374d87d388dd7b",
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@aa-sdk/core": "^4.
|
|
76
|
-
"@account-kit/infra": "^4.
|
|
75
|
+
"@aa-sdk/core": "^4.65.0",
|
|
76
|
+
"@account-kit/infra": "^4.65.0",
|
|
77
77
|
"webauthn-p256": "^0.0.10"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
maxUint152,
|
|
19
19
|
maxUint32,
|
|
20
20
|
zeroAddress,
|
|
21
|
+
isAddressEqual,
|
|
21
22
|
type Address,
|
|
22
23
|
type Chain,
|
|
23
24
|
type Hex,
|
|
@@ -211,11 +212,13 @@ export async function createMAv2Base<
|
|
|
211
212
|
value,
|
|
212
213
|
}) =>
|
|
213
214
|
await encodeCallData(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
!isAddressEqual(target, accountAddress)
|
|
216
|
+
? encodeFunctionData({
|
|
217
|
+
abi: modularAccountAbi,
|
|
218
|
+
functionName: "execute",
|
|
219
|
+
args: [target, value ?? 0n, data],
|
|
220
|
+
})
|
|
221
|
+
: data, // If the target is the same as the account address, we don't need to wrap in a call to `execute`.
|
|
219
222
|
);
|
|
220
223
|
|
|
221
224
|
const encodeBatchExecute: (txs: AccountOp[]) => Promise<Hex> = async (txs) =>
|
|
@@ -265,7 +268,21 @@ export async function createMAv2Base<
|
|
|
265
268
|
});
|
|
266
269
|
|
|
267
270
|
const getExecutionData = async (selector: Hex) => {
|
|
268
|
-
|
|
271
|
+
// Start both promises in parallel
|
|
272
|
+
const deployStatusPromise = isAccountDeployed();
|
|
273
|
+
const executionDataPromise = accountContract.read
|
|
274
|
+
.getExecutionData([selector])
|
|
275
|
+
.catch((error) => {
|
|
276
|
+
// Store the original error for potential re-throwing
|
|
277
|
+
// If the account is not deployed, we will get an error here that we want to swallow.
|
|
278
|
+
// Otherwise, we will re-throw the error.
|
|
279
|
+
return { error };
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// Check if account is deployed first
|
|
283
|
+
const deployStatus = await deployStatusPromise;
|
|
284
|
+
|
|
285
|
+
if (deployStatus === false) {
|
|
269
286
|
return {
|
|
270
287
|
module: zeroAddress,
|
|
271
288
|
skipRuntimeValidation: false,
|
|
@@ -274,11 +291,37 @@ export async function createMAv2Base<
|
|
|
274
291
|
};
|
|
275
292
|
}
|
|
276
293
|
|
|
277
|
-
|
|
294
|
+
// Only await execution data if account is deployed
|
|
295
|
+
const executionData = await executionDataPromise;
|
|
296
|
+
if ("error" in executionData) {
|
|
297
|
+
throw executionData.error;
|
|
298
|
+
}
|
|
299
|
+
return executionData;
|
|
278
300
|
};
|
|
279
301
|
|
|
280
302
|
const getValidationData = async (args: ValidationDataParams) => {
|
|
281
|
-
|
|
303
|
+
const { validationModuleAddress, entityId } = args;
|
|
304
|
+
|
|
305
|
+
// Start both promises in parallel
|
|
306
|
+
const deployStatusPromise = isAccountDeployed();
|
|
307
|
+
const validationDataPromise = accountContract.read
|
|
308
|
+
.getValidationData([
|
|
309
|
+
serializeModuleEntity({
|
|
310
|
+
moduleAddress: validationModuleAddress ?? zeroAddress,
|
|
311
|
+
entityId: entityId ?? Number(maxUint32),
|
|
312
|
+
}),
|
|
313
|
+
])
|
|
314
|
+
.catch((error) => {
|
|
315
|
+
// Store the original error for potential re-throwing
|
|
316
|
+
// If the account is not deployed, we will get an error here that we want to swallow.
|
|
317
|
+
// Otherwise, we will re-throw the error.
|
|
318
|
+
return { error };
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// Check if account is deployed first
|
|
322
|
+
const deployStatus = await deployStatusPromise;
|
|
323
|
+
|
|
324
|
+
if (deployStatus === false) {
|
|
282
325
|
return {
|
|
283
326
|
validationHooks: [],
|
|
284
327
|
executionHooks: [],
|
|
@@ -287,13 +330,12 @@ export async function createMAv2Base<
|
|
|
287
330
|
};
|
|
288
331
|
}
|
|
289
332
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
]);
|
|
333
|
+
// Only await validation data if account is deployed
|
|
334
|
+
const validationData = await validationDataPromise;
|
|
335
|
+
if ("error" in validationData) {
|
|
336
|
+
throw validationData.error;
|
|
337
|
+
}
|
|
338
|
+
return validationData;
|
|
297
339
|
};
|
|
298
340
|
|
|
299
341
|
const encodeCallData = async (callData: Hex): Promise<Hex> => {
|