@account-kit/smart-contracts 4.66.3 → 4.66.4

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.
@@ -1,4 +1,4 @@
1
- import { createBundlerClient, getEntryPoint, InvalidDeferredActionNonce, InvalidEntityIdError, InvalidNonceKeyError, toSmartContractAccount, } from "@aa-sdk/core";
1
+ import { BaseError, createBundlerClient, getEntryPoint, InvalidDeferredActionNonce, InvalidEntityIdError, InvalidNonceKeyError, toSmartContractAccount, } from "@aa-sdk/core";
2
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";
@@ -72,7 +72,24 @@ export async function createMAv2Base(config) {
72
72
  })),
73
73
  ],
74
74
  }));
75
- const isAccountDeployed = async () => !!(await client.getCode({ address: accountAddress }));
75
+ const isAccountDeployed = async () => {
76
+ const code = (await client.getCode({ address: accountAddress }))?.toLowerCase();
77
+ const is7702Delegated = code?.startsWith("0xef0100");
78
+ if (!is7702Delegated) {
79
+ return !!code;
80
+ }
81
+ if (!config.getImplementationAddress) {
82
+ // Edge case where account is already delegated to a 3rd party
83
+ // implementation, but the MAv2 client is initialized using its
84
+ // address without specifying 7702 mode.
85
+ throw new BaseError("Account is an already-delegated 7702 account, but client is missing implementation address. Be sure to initialize the client in 7702 mode.");
86
+ }
87
+ const expectedCode = concatHex([
88
+ "0xef0100",
89
+ await config.getImplementationAddress(),
90
+ ]).toLowerCase();
91
+ return code === expectedCode;
92
+ };
76
93
  const getNonce = async (nonceKey = 0n) => {
77
94
  if (nonce) {
78
95
  const tempNonce = nonce;
@@ -1 +1 @@
1
- {"version":3,"file":"modularAccountV2Base.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAA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undlerClient,\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
+ {"version":3,"file":"modularAccountV2Base.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,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;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,qBAAqB,GAAQ,YAAY,CAAC;AAsGvD,MAAM,CAAC,KAAK,UAAU,cAAc,CAGlC,MAAoE;IAEpE,IAAI,EACF,SAAS,EACT,KAAK,EACL,UAAU,GAAG,aAAa,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EACvD,YAAY,GAAG;QACb,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,uBAAuB;KAClC,EACD,YAAY,EAAE,EACZ,kBAAkB,GAAG,IAAI,EACzB,QAAQ,GAAG,uBAAuB,GACnC,GAAG,EAAE,EACN,cAAc,EACd,cAAc,EACd,GAAG,qCAAqC,EACzC,GAAG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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 BaseError,\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 const code = (\n await client.getCode({ address: accountAddress })\n )?.toLowerCase();\n const is7702Delegated = code?.startsWith(\"0xef0100\");\n\n if (!is7702Delegated) {\n return !!code;\n }\n\n if (!config.getImplementationAddress) {\n // Edge case where account is already delegated to a 3rd party\n // implementation, but the MAv2 client is initialized using its\n // address without specifying 7702 mode.\n throw new BaseError(\n \"Account is an already-delegated 7702 account, but client is missing implementation address. Be sure to initialize the client in 7702 mode.\",\n );\n }\n\n const expectedCode = concatHex([\n \"0xef0100\",\n await config.getImplementationAddress(),\n ]).toLowerCase();\n return code === expectedCode;\n };\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,EAQL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,GAAG,EACR,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAQ5E,eAAO,MAAM,qBAAqB,EAAE,GAAkB,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG,wBAAwB,CAAC;AAE5E,MAAM,MAAM,YAAY,GAAG;IACzB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,cAAc,EAAE,SAAS,GAAG,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe,EAAE,SAAS,GAAG,EAAE,CAAC;IAChC,cAAc,EAAE,SAAS,GAAG,EAAE,CAAC;IAC/B,SAAS,EAAE,SAAS,GAAG,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC5B;IACE,uBAAuB,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,GACD;IACE,uBAAuB,CAAC,EAAE,KAAK,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEN,MAAM,MAAM,gBAAgB,CAC1B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,GAAG,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,oBAAoB,EACpB,QAAQ,CACT,GAAG;IACF,UAAU,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"}
1
+ {"version":3,"file":"modularAccountV2Base.d.ts","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,8BAA8B,EACnC,KAAK,4BAA4B,EAClC,MAAM,cAAc,CAAC;AACtB,OAAO,EAQL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,GAAG,EACR,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAQ5E,eAAO,MAAM,qBAAqB,EAAE,GAAkB,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG,wBAAwB,CAAC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CAAC;AAErC,wBAAsB,cAAc,CAClC,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EACvD,MAAM,EAAE,oBAAoB,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;AAsSnE,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.66.3",
3
+ "version": "4.66.4",
4
4
  "description": "aa-sdk compatible interfaces for Alchemy Smart Accounts",
5
5
  "author": "Alchemy",
6
6
  "license": "MIT",
@@ -51,7 +51,7 @@
51
51
  "test:run": "vitest run"
52
52
  },
53
53
  "devDependencies": {
54
- "@account-kit/plugingen": "^4.66.3",
54
+ "@account-kit/plugingen": "^4.66.4",
55
55
  "change-case": "^5.1.2",
56
56
  "dedent": "^1.5.1",
57
57
  "dotenv": "^16.3.1",
@@ -69,10 +69,10 @@
69
69
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
70
70
  },
71
71
  "homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
72
- "gitHead": "33b7e38e6f83cc7a5bae3976b6c8a54b15f6cd4e",
72
+ "gitHead": "058d16b7492048f8f0f24b02445269ad07ae8e4e",
73
73
  "dependencies": {
74
- "@aa-sdk/core": "^4.66.3",
75
- "@account-kit/infra": "^4.66.3",
74
+ "@aa-sdk/core": "^4.66.4",
75
+ "@account-kit/infra": "^4.66.4",
76
76
  "webauthn-p256": "^0.0.10"
77
77
  },
78
78
  "peerDependencies": {
@@ -1,4 +1,5 @@
1
1
  import {
2
+ BaseError,
2
3
  createBundlerClient,
3
4
  getEntryPoint,
4
5
  InvalidDeferredActionNonce,
@@ -236,8 +237,31 @@ export async function createMAv2Base<
236
237
  }),
237
238
  );
238
239
 
239
- const isAccountDeployed: () => Promise<boolean> = async () =>
240
- !!(await client.getCode({ address: accountAddress }));
240
+ const isAccountDeployed: () => Promise<boolean> = async () => {
241
+ const code = (
242
+ await client.getCode({ address: accountAddress })
243
+ )?.toLowerCase();
244
+ const is7702Delegated = code?.startsWith("0xef0100");
245
+
246
+ if (!is7702Delegated) {
247
+ return !!code;
248
+ }
249
+
250
+ if (!config.getImplementationAddress) {
251
+ // Edge case where account is already delegated to a 3rd party
252
+ // implementation, but the MAv2 client is initialized using its
253
+ // address without specifying 7702 mode.
254
+ throw new BaseError(
255
+ "Account is an already-delegated 7702 account, but client is missing implementation address. Be sure to initialize the client in 7702 mode.",
256
+ );
257
+ }
258
+
259
+ const expectedCode = concatHex([
260
+ "0xef0100",
261
+ await config.getImplementationAddress(),
262
+ ]).toLowerCase();
263
+ return code === expectedCode;
264
+ };
241
265
 
242
266
  const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {
243
267
  if (nonce) {