@alchemy/smart-accounts 5.0.0-beta.3 → 5.0.0-beta.31

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.
Files changed (104) hide show
  1. package/README.md +45 -2
  2. package/dist/esm/index.d.ts +1 -7
  3. package/dist/esm/index.js +1 -4
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/esm/light-account/accounts/base.js +0 -1
  6. package/dist/esm/light-account/accounts/base.js.map +1 -1
  7. package/dist/esm/light-account/accounts/calldataCodec.js +0 -3
  8. package/dist/esm/light-account/accounts/calldataCodec.js.map +1 -1
  9. package/dist/esm/light-account/utils.js +0 -5
  10. package/dist/esm/light-account/utils.js.map +1 -1
  11. package/dist/esm/ma-v1/accounts/base.js +1 -1
  12. package/dist/esm/ma-v1/accounts/base.js.map +1 -1
  13. package/dist/esm/ma-v1/accounts/calldataCodec.js +0 -4
  14. package/dist/esm/ma-v1/accounts/calldataCodec.js.map +1 -1
  15. package/dist/esm/ma-v1/mav1StaticImpl.d.ts +0 -2
  16. package/dist/esm/ma-v1/mav1StaticImpl.js +0 -2
  17. package/dist/esm/ma-v1/mav1StaticImpl.js.map +1 -1
  18. package/dist/esm/ma-v2/accounts/account.d.ts +39 -0
  19. package/dist/esm/ma-v2/accounts/account.js +40 -1
  20. package/dist/esm/ma-v2/accounts/account.js.map +1 -1
  21. package/dist/esm/ma-v2/accounts/base.js +1 -1
  22. package/dist/esm/ma-v2/accounts/base.js.map +1 -1
  23. package/dist/esm/ma-v2/accounts/calldataCodec.js +0 -4
  24. package/dist/esm/ma-v2/accounts/calldataCodec.js.map +1 -1
  25. package/dist/esm/ma-v2/decorators/deferralActions.d.ts +3 -3
  26. package/dist/esm/ma-v2/decorators/deferralActions.js +3 -3
  27. package/dist/esm/ma-v2/decorators/deferralActions.js.map +1 -1
  28. package/dist/esm/ma-v2/decorators/installValidation.d.ts +8 -20
  29. package/dist/esm/ma-v2/decorators/installValidation.js +7 -58
  30. package/dist/esm/ma-v2/decorators/installValidation.js.map +1 -1
  31. package/dist/esm/ma-v2/mav2StaticImpl.d.ts +0 -4
  32. package/dist/esm/ma-v2/mav2StaticImpl.js +0 -4
  33. package/dist/esm/ma-v2/mav2StaticImpl.js.map +1 -1
  34. package/dist/esm/ma-v2/permissionBuilder.d.ts +2 -2
  35. package/dist/esm/ma-v2/permissionBuilder.js +46 -14
  36. package/dist/esm/ma-v2/permissionBuilder.js.map +1 -1
  37. package/dist/esm/ma-v2/utils/account.js +0 -2
  38. package/dist/esm/ma-v2/utils/account.js.map +1 -1
  39. package/dist/esm/ma-v2/utils/deferredActions.d.ts +6 -6
  40. package/dist/esm/ma-v2/utils/deferredActions.js +5 -5
  41. package/dist/esm/ma-v2/utils/deferredActions.js.map +1 -1
  42. package/dist/esm/version.d.ts +1 -1
  43. package/dist/esm/version.js +1 -1
  44. package/dist/esm/version.js.map +1 -1
  45. package/dist/types/index.d.ts +1 -7
  46. package/dist/types/index.d.ts.map +1 -1
  47. package/dist/types/light-account/accounts/base.d.ts.map +1 -1
  48. package/dist/types/light-account/accounts/calldataCodec.d.ts.map +1 -1
  49. package/dist/types/light-account/utils.d.ts.map +1 -1
  50. package/dist/types/ma-v1/accounts/calldataCodec.d.ts.map +1 -1
  51. package/dist/types/ma-v1/mav1StaticImpl.d.ts +0 -2
  52. package/dist/types/ma-v1/mav1StaticImpl.d.ts.map +1 -1
  53. package/dist/types/ma-v2/accounts/account.d.ts +39 -0
  54. package/dist/types/ma-v2/accounts/account.d.ts.map +1 -1
  55. package/dist/types/ma-v2/accounts/calldataCodec.d.ts.map +1 -1
  56. package/dist/types/ma-v2/decorators/deferralActions.d.ts +3 -3
  57. package/dist/types/ma-v2/decorators/deferralActions.d.ts.map +1 -1
  58. package/dist/types/ma-v2/decorators/installValidation.d.ts +8 -20
  59. package/dist/types/ma-v2/decorators/installValidation.d.ts.map +1 -1
  60. package/dist/types/ma-v2/mav2StaticImpl.d.ts +0 -4
  61. package/dist/types/ma-v2/mav2StaticImpl.d.ts.map +1 -1
  62. package/dist/types/ma-v2/permissionBuilder.d.ts +2 -2
  63. package/dist/types/ma-v2/permissionBuilder.d.ts.map +1 -1
  64. package/dist/types/ma-v2/utils/account.d.ts.map +1 -1
  65. package/dist/types/ma-v2/utils/deferredActions.d.ts +6 -6
  66. package/dist/types/ma-v2/utils/deferredActions.d.ts.map +1 -1
  67. package/dist/types/version.d.ts +1 -1
  68. package/dist/types/version.d.ts.map +1 -1
  69. package/package.json +6 -6
  70. package/src/index.ts +1 -14
  71. package/src/light-account/accounts/base.ts +0 -1
  72. package/src/light-account/accounts/calldataCodec.ts +0 -4
  73. package/src/light-account/utils.ts +0 -6
  74. package/src/ma-v1/accounts/base.ts +1 -1
  75. package/src/ma-v1/accounts/calldataCodec.ts +0 -5
  76. package/src/ma-v1/mav1StaticImpl.ts +0 -2
  77. package/src/ma-v2/accounts/account.ts +41 -2
  78. package/src/ma-v2/accounts/base.ts +1 -1
  79. package/src/ma-v2/accounts/calldataCodec.ts +0 -5
  80. package/src/ma-v2/decorators/deferralActions.ts +7 -7
  81. package/src/ma-v2/decorators/installValidation.ts +8 -83
  82. package/src/ma-v2/mav2StaticImpl.ts +0 -4
  83. package/src/ma-v2/permissionBuilder.ts +54 -17
  84. package/src/ma-v2/utils/account.ts +0 -2
  85. package/src/ma-v2/utils/deferredActions.ts +9 -9
  86. package/src/version.ts +1 -1
  87. package/dist/esm/light-account/decorators/multiOwner.d.ts +0 -17
  88. package/dist/esm/light-account/decorators/multiOwner.js +0 -39
  89. package/dist/esm/light-account/decorators/multiOwner.js.map +0 -1
  90. package/dist/esm/light-account/decorators/singleOwner.d.ts +0 -16
  91. package/dist/esm/light-account/decorators/singleOwner.js +0 -35
  92. package/dist/esm/light-account/decorators/singleOwner.js.map +0 -1
  93. package/dist/esm/ma-v1/decorators/multiOwner.d.ts +0 -17
  94. package/dist/esm/ma-v1/decorators/multiOwner.js +0 -39
  95. package/dist/esm/ma-v1/decorators/multiOwner.js.map +0 -1
  96. package/dist/types/light-account/decorators/multiOwner.d.ts +0 -18
  97. package/dist/types/light-account/decorators/multiOwner.d.ts.map +0 -1
  98. package/dist/types/light-account/decorators/singleOwner.d.ts +0 -17
  99. package/dist/types/light-account/decorators/singleOwner.d.ts.map +0 -1
  100. package/dist/types/ma-v1/decorators/multiOwner.d.ts +0 -18
  101. package/dist/types/ma-v1/decorators/multiOwner.d.ts.map +0 -1
  102. package/src/light-account/decorators/multiOwner.ts +0 -72
  103. package/src/light-account/decorators/singleOwner.ts +0 -63
  104. package/src/ma-v1/decorators/multiOwner.ts +0 -72
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GASnB,MAAM,MAAM,CAAC;AACd,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAE9E,OAAO,EACL,yCAAyC,EACzC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqCzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAA4B,EAClE,MAAM,EACN,KAAK,EACL,cAAc,EACd,YAAY,EACZ,cAAc,EAAE,eAAe,EAC/B,IAAI,GAAG,EAAE,EACT,OAAO,EACP,WAAW,EAAE,YAAY,EACzB,qBAAqB,EAAE,sBAAsB,EAC7C,IAAI,GAC4B;IAChC,MAAM,MAAM,GAAG,I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AAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,sFAAsF;KACvF,CAAC;AACJ,CAAC","sourcesContent":["import {\n encodeFunctionData,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type PrivateKeyAccount,\n type Transport,\n} from \"viem\";\nimport {\n type ToSmartAccountParameters,\n entryPoint07Address,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport {\n getModularAccountV2AddressFromFactoryData,\n predictModularAccountV2Address,\n} from \"../predictAddress.js\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport { InvalidOwnerError } from \"../../errors/InvalidOwnerError.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from \"../utils/account.js\";\nimport { LOGGER } from \"../../logger.js\";\n\ntype Mode = \"default\" | \"7702\";\n\n// TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\nexport type ModularAccountV2 = ModularAccountV2Base & {};\n\nexport type ToModularAccountV2Params<\n TMode extends Mode | undefined = Mode | undefined,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n accountAddress?: Address;\n mode?: TMode;\n} & (TMode extends \"7702\"\n ? {\n salt?: never;\n factory?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n factory?: Address;\n implementationAddress?: Address;\n } & (\n | {\n salt?: bigint;\n factoryData?: never;\n }\n | {\n salt?: never;\n factoryData?: Hex;\n }\n ));\n\n/**\n * Creates a MAv2 account.\n *\n * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.\n * @returns {Promise<ModularAccountV2>} A MAv2 account.\n */\nexport async function toModularAccountV2<TMode extends Mode = Mode>({\n client,\n owner,\n deferredAction,\n signerEntity,\n accountAddress: accountAddress_,\n salt = 0n,\n factory,\n factoryData: factoryData_,\n implementationAddress: implementationAddress_,\n mode,\n}: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2> {\n const is7702 = mode === \"7702\";\n\n LOGGER.debug(\"toModularAccountV2:start\", {\n ownerType: owner.type,\n mode,\n hasDeferredAction: !!deferredAction,\n hasAccountAddress: !!accountAddress_,\n });\n\n const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;\n\n const factoryAddress = factory ?? DefaultAddress.MAV2_FACTORY;\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702 ? DefaultAddress.SMAV2_7702 : DefaultAddress.SMAV2_BYTECODE);\n\n const getFactoryArgs = async () => {\n if (is7702) {\n // This is only for EP 0.8.0.\n // return {\n // factory: \"0x7702\",\n // factoryData: \"0x\",\n // } as const;\n return {\n factory: undefined,\n factoryData: undefined,\n } as const;\n }\n\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [owner.address, salt],\n }),\n };\n };\n\n const accountAddress =\n accountAddress_ ??\n (is7702\n ? owner.address\n : factoryData_\n ? await getModularAccountV2AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData: factoryData_,\n implementationAddress,\n entryPoint: {\n version: \"0.7\",\n address: entryPoint07Address,\n },\n })\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n type: \"SMA\",\n ownerAddress: owner.address,\n }));\n\n LOGGER.debug(\"toModularAccountV2:address-resolved\", {\n accountAddress,\n is7702,\n });\n\n let authorization: ToSmartAccountParameters[\"authorization\"];\n if (is7702) {\n LOGGER.debug(\"toModularAccountV2:7702-mode\");\n if (owner.type !== \"local\") {\n LOGGER.error(\"toModularAccountV2:invalid-owner-type\", {\n ownerType: owner.type,\n });\n throw new InvalidOwnerError(\n `Owner of type ${owner.type} is unsupported for 7702 mode.`,\n );\n }\n if (owner.signAuthorization == null) {\n LOGGER.error(\"toModularAccountV2:missing-signAuthorization\");\n throw new InvalidOwnerError(\n \"Owner must implement `signAuthorization` to be used with 7702 mode.\",\n );\n }\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n owner.address !== accountAddress\n ) {\n LOGGER.error(\"toModularAccountV2:entity-id-override\");\n throw new EntityIdOverrideError();\n }\n authorization = {\n // The current version of Viem has some pretty strict constraints\n // on a `PrivateKeyAccount`, but this seems safe as long as the\n // owner is able to `signAuthorization`.\n account: owner as PrivateKeyAccount,\n address: DefaultAddress.SMAV2_7702,\n };\n }\n\n const base = await toModularAccountV2Base({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity,\n deferredAction,\n authorization,\n });\n\n return {\n ...base,\n // TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\n };\n}\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GASnB,MAAM,MAAM,CAAC;AACd,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAE9E,OAAO,EACL,yCAAyC,EACzC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqCzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAA4B,E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EAAE,KAA0B;YACnC,OAAO,EAAE,cAAc,CAAC,UAAU;SACnC,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,sBAAsB,CAAC;QACxC,MAAM;QACN,KAAK;QACL,cAAc;QACd,cAAc;QACd,YAAY;QACZ,cAAc;QACd,aAAa;KACd,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,4EAA4E;KAC7E,CAAC;AACJ,CAAC","sourcesContent":["import {\n encodeFunctionData,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type PrivateKeyAccount,\n type Transport,\n} from \"viem\";\nimport {\n type ToSmartAccountParameters,\n entryPoint07Address,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport {\n getModularAccountV2AddressFromFactoryData,\n predictModularAccountV2Address,\n} from \"../predictAddress.js\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport { InvalidOwnerError } from \"../../errors/InvalidOwnerError.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from \"../utils/account.js\";\nimport { LOGGER } from \"../../logger.js\";\n\ntype Mode = \"default\" | \"7702\";\n\n// This may be extended in the future with additional MAv2-specific methods.\nexport type ModularAccountV2 = ModularAccountV2Base & {};\n\nexport type ToModularAccountV2Params<\n TMode extends Mode | undefined = Mode | undefined,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n accountAddress?: Address;\n mode?: TMode;\n} & (TMode extends \"7702\"\n ? {\n salt?: never;\n factory?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n factory?: Address;\n implementationAddress?: Address;\n } & (\n | {\n salt?: bigint;\n factoryData?: never;\n }\n | {\n salt?: never;\n factoryData?: Hex;\n }\n ));\n\n/**\n * Creates a MAv2 account.\n *\n * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.\n * @returns {Promise<ModularAccountV2>} A MAv2 account.\n *\n * @example\n * ```ts\n * import { createPublicClient } from \"viem\";\n * import { createBundlerClient, createPaymasterClient } from \"viem/account-abstraction\";\n * import { sepolia } from \"viem/chains\";\n * import { generatePrivateKey, privateKeyToAccount } from \"viem/accounts\";\n * import { alchemyTransport } from \"@alchemy/common\";\n * import { estimateFeesPerGas } from \"@alchemy/aa-infra\";\n * import { toModularAccountV2 } from \"@alchemy/smart-accounts\";\n *\n * const transport = alchemyTransport({ apiKey: \"YOUR_API_KEY\" });\n *\n * // 1. Create a MAv2 smart account\n * const account = await toModularAccountV2({\n * client: createPublicClient({ chain: sepolia, transport }),\n * owner: privateKeyToAccount(generatePrivateKey()),\n * });\n *\n * // 2. Create a bundler client with the account\n * const bundlerClient = createBundlerClient({\n * account,\n * chain: sepolia,\n * transport,\n * userOperation: {\n * estimateFeesPerGas,\n * },\n * // Optional: sponsor gas with a paymaster\n * paymaster: createPaymasterClient({ transport }),\n * paymasterContext: { policyId: \"YOUR_POLICY_ID\" },\n * });\n *\n * // 3. Send a user operation\n * const hash = await bundlerClient.sendUserOperation({\n * calls: [{ to: \"0x...\", value: 0n, data: \"0x\" }],\n * });\n *\n * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });\n * ```\n */\nexport async function toModularAccountV2<TMode extends Mode = Mode>({\n client,\n owner,\n deferredAction,\n signerEntity,\n accountAddress: accountAddress_,\n salt = 0n,\n factory,\n factoryData: factoryData_,\n implementationAddress: implementationAddress_,\n mode,\n}: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2> {\n const is7702 = mode === \"7702\";\n\n LOGGER.debug(\"toModularAccountV2:start\", {\n ownerType: owner.type,\n mode,\n hasDeferredAction: !!deferredAction,\n hasAccountAddress: !!accountAddress_,\n });\n\n const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;\n\n const factoryAddress = factory ?? DefaultAddress.MAV2_FACTORY;\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702 ? DefaultAddress.SMAV2_7702 : DefaultAddress.SMAV2_BYTECODE);\n\n const getFactoryArgs = async () => {\n if (is7702) {\n // This is only for EP 0.8.0.\n // return {\n // factory: \"0x7702\",\n // factoryData: \"0x\",\n // } as const;\n return {\n factory: undefined,\n factoryData: undefined,\n } as const;\n }\n\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [owner.address, salt],\n }),\n };\n };\n\n const accountAddress =\n accountAddress_ ??\n (is7702\n ? owner.address\n : factoryData_\n ? await getModularAccountV2AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData: factoryData_,\n implementationAddress,\n entryPoint: {\n version: \"0.7\",\n address: entryPoint07Address,\n },\n })\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n type: \"SMA\",\n ownerAddress: owner.address,\n }));\n\n LOGGER.debug(\"toModularAccountV2:address-resolved\", {\n accountAddress,\n is7702,\n });\n\n let authorization: ToSmartAccountParameters[\"authorization\"];\n if (is7702) {\n LOGGER.debug(\"toModularAccountV2:7702-mode\");\n if (owner.type !== \"local\") {\n LOGGER.error(\"toModularAccountV2:invalid-owner-type\", {\n ownerType: owner.type,\n });\n throw new InvalidOwnerError(\n `Owner of type ${owner.type} is unsupported for 7702 mode.`,\n );\n }\n if (owner.signAuthorization == null) {\n LOGGER.error(\"toModularAccountV2:missing-signAuthorization\");\n throw new InvalidOwnerError(\n \"Owner must implement `signAuthorization` to be used with 7702 mode.\",\n );\n }\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n owner.address !== accountAddress\n ) {\n LOGGER.error(\"toModularAccountV2:entity-id-override\");\n throw new EntityIdOverrideError();\n }\n authorization = {\n // The current version of Viem has some pretty strict constraints\n // on a `PrivateKeyAccount`, but this seems safe as long as the\n // owner is able to `signAuthorization`.\n account: owner as PrivateKeyAccount,\n address: DefaultAddress.SMAV2_7702,\n };\n }\n\n const base = await toModularAccountV2Base({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity,\n deferredAction,\n authorization,\n });\n\n return {\n ...base,\n // This may be extended in the future with additional MAv2-specific methods.\n };\n}\n"]}
@@ -229,7 +229,7 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
229
229
  td.domain.verifyingContract === accountAddress;
230
230
  const { data } = await prepareSignature({
231
231
  type: "eth_signTypedData_v4",
232
- data: td, // TODO(v5): Try harder to satisfy this w/o casting.
232
+ data: td,
233
233
  });
234
234
  const action = getAction(client, signTypedData, "signTypedData");
235
235
  const signature = await action({
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EACN,SAAS,EACT,WAAW,EACX,aAAa,EAEb,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EAEf,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EACL,eAAe,GAIhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CA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BACtC,mBAAmB;aACpB,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,kBAAkB;gBAClC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;gBAClD,CAAC,CAAC,eAAe,CAAC;YAEpB,kBAAkB,GAAG,SAAS,CAAC,CAAC,kBAAkB;YAClD,sBAAsB,GAAG,KAAK,CAAC,CAAC,+BAA+B;YAE/D,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,kBAA2B;YAC7C,YAAY,EAAE;gBACZ,QAAQ;gBACR,kBAAkB;aACnB;YACD,cAAc;YACd,gBAAgB;YAChB,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Chain,\n type Client,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n concat,\n concatHex,\n hashMessage,\n hashTypedData,\n type TypedDataDefinition,\n maxUint32,\n maxUint152,\n zeroAddress,\n} from \"viem\";\nimport {\n entryPoint07Abi,\n type SmartAccountImplementation,\n entryPoint07Address,\n getUserOperationHash,\n toSmartAccount,\n type ToSmartAccountParameters,\n} from \"viem/account-abstraction\";\nimport {\n getCode,\n readContract,\n signMessage,\n signTypedData,\n} from \"viem/actions\";\nimport { assertNever, BaseError } from \"@alchemy/common\";\nimport {\n SignaturePrefix,\n type ExecutionDataView,\n type SignerEntity,\n type ValidationDataView,\n} from \"../types.js\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { getAction, isAddressEqual } from \"viem/utils\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n DefaultModuleAddress,\n EXECUTE_USER_OP_SELECTOR,\n serializeModuleEntity,\n} from \"../utils/account.js\";\nimport { parseDeferredAction } from \"../utils/deferredActions.js\";\nimport {\n pack1271Signature,\n toReplaySafeTypedData,\n packUOSignature,\n} from \"../utils/signature.js\";\nimport { InvalidDeferredActionNonceError } from \"../../errors/InvalidDeferredActionNonceError.js\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { InvalidEntityIdError } from \"../../errors/InvalidEntityIdError.js\";\nimport { is7702Delegated } from \"../../utils.js\";\nimport { encodeCallsMAv2, decodeCallsMAv2 } from \"./calldataCodec.js\";\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type BaseModularAccountV2Implementation = SmartAccountImplementation<\n typeof entryPoint07Abi,\n \"0.7\",\n {\n smartAccountType: \"ModularAccountV2\";\n signerEntity: SignerEntity;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n boolean\n>;\n\nexport type ModularAccountV2Base =\n SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;\n\nexport type ToModularAccountV2BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n accountAddress: Address;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n signerEntity?: SignerEntity;\n deferredAction?: Hex;\n authorization?: ToSmartAccountParameters[\"authorization\"];\n};\n\n/**\n * Creates a ModularAccountV2Base instance.\n *\n * @param {ToModularAccountV2BaseParams<TTransport>} params - The parameters for creating a ModularAccountV2Base instance.\n * @returns {Promise<ModularAccountV2Base>} A promise that resolves to a ModularAccountV2Base instance.\n */\nexport async function toModularAccountV2Base<\n TTransport extends Transport = Transport,\n>({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n deferredAction,\n authorization,\n}: ToModularAccountV2BaseParams<TTransport>): Promise<ModularAccountV2Base> {\n let { isGlobalValidation, entityId } = signerEntity;\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address as Address,\n version: \"0.7\" as const,\n };\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n let isDeployed = false;\n\n const isAccountDeployed: () => Promise<boolean> = async () => {\n if (isDeployed) {\n return true;\n }\n const action = getAction(client, getCode, \"getCode\");\n const code = await action({ address: accountAddress });\n isDeployed = authorization\n ? is7702Delegated(authorization.address, code)\n : !!code;\n return isDeployed;\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 = 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 const readContractAction = getAction(client, readContract, \"readContract\");\n\n // Set these values if the deferred action has not been consumed. We check this with the EP.\n const nextNonceForDeferredAction: bigint = await readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, deferredActionNonce >> 64n],\n });\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 InvalidDeferredActionNonceError();\n }\n }\n\n const getNonce = async (\n params?: { key?: bigint | undefined } | undefined,\n ): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n const nonceKey = params?.key ?? 0n;\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n return readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, fullNonceKey],\n });\n };\n\n const accountContract = {\n address: accountAddress,\n abi: modularAccountAbi,\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 readContract(client, {\n ...accountContract,\n functionName: \"getExecutionData\",\n args: [selector],\n });\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 const readContractAction = getAction(client, readContract, \"readContract\");\n return readContractAction({\n ...accountContract,\n functionName: \"getValidationData\",\n args: [\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\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 return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n return callData;\n };\n\n const prepareSignature = async (\n request: SignatureRequest,\n ): Promise<Extract<SignatureRequest, { type: \"eth_signTypedData_v4\" }>> => {\n const isDeferredAction =\n request.type === \"eth_signTypedData_v4\" &&\n request.data?.primaryType === \"DeferredAction\" &&\n request.data?.domain?.verifyingContract === accountAddress;\n\n if (isDeferredAction && entityId === DEFAULT_OWNER_ENTITY_ID) {\n return request;\n }\n\n const hash =\n request.type === \"personal_sign\"\n ? hashMessage(request.data)\n : request.type === \"eth_signTypedData_v4\"\n ? hashTypedData(request.data)\n : assertNever(request, \"Unexpected signature request type\");\n\n return {\n type: \"eth_signTypedData_v4\",\n data: toReplaySafeTypedData({\n chainId: client.chain.id,\n hash,\n ...(entityId === DEFAULT_OWNER_ENTITY_ID\n ? { address: accountAddress }\n : {\n address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }),\n }),\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return pack1271Signature({\n entityId,\n validationSignaturePrefix: SignaturePrefix.EOA,\n validationSignature: signature,\n });\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n getNonce,\n authorization,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length === 1) {\n const call = calls[0];\n\n if (isAddressEqual(call.to, accountAddress)) {\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n\n if (call.data == null) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return encodeCallData(call.data);\n }\n }\n\n return encodeCallData(encodeCallsMAv2(calls));\n },\n\n async decodeCalls(data) {\n return decodeCallsMAv2(data, accountAddress);\n },\n\n async getStubSignature() {\n const sig = packUOSignature({\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n async signMessage({ message }) {\n const { data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return formatSignature(signature);\n },\n\n async signTypedData(td) {\n const isDeferredAction =\n td.primaryType === \"DeferredAction\" &&\n td.domain &&\n typeof td.domain === \"object\" &&\n \"verifyingContract\" in td.domain &&\n td.domain.verifyingContract === accountAddress;\n\n const { data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: td as TypedDataDefinition, // TODO(v5): Try harder to satisfy this w/o casting.\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return isDeferredAction\n ? concat([SignaturePrefix.EOA, signature])\n : formatSignature(signature);\n },\n\n async signUserOperation(uo) {\n const hash = getUserOperationHash({\n chainId: uo.chainId ?? client.chain.id,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...uo,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const validationSignature = await signMessageAction({\n account: owner,\n message: { raw: hash },\n });\n\n const packedSignature = packUOSignature({\n validationSignature,\n });\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, packedSignature])\n : packedSignature;\n\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n\n return signature;\n },\n\n extend: {\n smartAccountType: \"ModularAccountV2\" as const,\n signerEntity: {\n entityId,\n isGlobalValidation,\n },\n encodeCallData,\n getExecutionData,\n getValidationData,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EACN,SAAS,EACT,WAAW,EACX,aAAa,EAEb,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EAEf,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;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,EAAE,cAAc;iBACvB;aACF,CAAC,CAAC;YAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YAExE,MAAM,mBAAmB,GAAG,MAAM,iBAAiB,CAAC;gBAClD,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;aACvB,CAAC,CAAC;YAEH,MAAM,eAAe,GAAG,eAAe,CAAC;gBACtC,mBAAmB;aACpB,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,kBAAkB;gBAClC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;gBAClD,CAAC,CAAC,eAAe,CAAC;YAEpB,kBAAkB,GAAG,SAAS,CAAC,CAAC,kBAAkB;YAClD,sBAAsB,GAAG,KAAK,CAAC,CAAC,+BAA+B;YAE/D,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,kBAA2B;YAC7C,YAAY,EAAE;gBACZ,QAAQ;gBACR,kBAAkB;aACnB;YACD,cAAc;YACd,gBAAgB;YAChB,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Chain,\n type Client,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n concat,\n concatHex,\n hashMessage,\n hashTypedData,\n type TypedDataDefinition,\n maxUint32,\n maxUint152,\n zeroAddress,\n} from \"viem\";\nimport {\n entryPoint07Abi,\n type SmartAccountImplementation,\n entryPoint07Address,\n getUserOperationHash,\n toSmartAccount,\n type ToSmartAccountParameters,\n} from \"viem/account-abstraction\";\nimport {\n getCode,\n readContract,\n signMessage,\n signTypedData,\n} from \"viem/actions\";\nimport { assertNever, BaseError } from \"@alchemy/common\";\nimport {\n SignaturePrefix,\n type ExecutionDataView,\n type SignerEntity,\n type ValidationDataView,\n} from \"../types.js\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { getAction, isAddressEqual } from \"viem/utils\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n DefaultModuleAddress,\n EXECUTE_USER_OP_SELECTOR,\n serializeModuleEntity,\n} from \"../utils/account.js\";\nimport { parseDeferredAction } from \"../utils/deferredActions.js\";\nimport {\n pack1271Signature,\n toReplaySafeTypedData,\n packUOSignature,\n} from \"../utils/signature.js\";\nimport { InvalidDeferredActionNonceError } from \"../../errors/InvalidDeferredActionNonceError.js\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { InvalidEntityIdError } from \"../../errors/InvalidEntityIdError.js\";\nimport { is7702Delegated } from \"../../utils.js\";\nimport { encodeCallsMAv2, decodeCallsMAv2 } from \"./calldataCodec.js\";\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type BaseModularAccountV2Implementation = SmartAccountImplementation<\n typeof entryPoint07Abi,\n \"0.7\",\n {\n smartAccountType: \"ModularAccountV2\";\n signerEntity: SignerEntity;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n boolean\n>;\n\nexport type ModularAccountV2Base =\n SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;\n\nexport type ToModularAccountV2BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n accountAddress: Address;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n signerEntity?: SignerEntity;\n deferredAction?: Hex;\n authorization?: ToSmartAccountParameters[\"authorization\"];\n};\n\n/**\n * Creates a ModularAccountV2Base instance.\n *\n * @param {ToModularAccountV2BaseParams<TTransport>} params - The parameters for creating a ModularAccountV2Base instance.\n * @returns {Promise<ModularAccountV2Base>} A promise that resolves to a ModularAccountV2Base instance.\n */\nexport async function toModularAccountV2Base<\n TTransport extends Transport = Transport,\n>({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n deferredAction,\n authorization,\n}: ToModularAccountV2BaseParams<TTransport>): Promise<ModularAccountV2Base> {\n let { isGlobalValidation, entityId } = signerEntity;\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address as Address,\n version: \"0.7\" as const,\n };\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n let isDeployed = false;\n\n const isAccountDeployed: () => Promise<boolean> = async () => {\n if (isDeployed) {\n return true;\n }\n const action = getAction(client, getCode, \"getCode\");\n const code = await action({ address: accountAddress });\n isDeployed = authorization\n ? is7702Delegated(authorization.address, code)\n : !!code;\n return isDeployed;\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 = 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 const readContractAction = getAction(client, readContract, \"readContract\");\n\n // Set these values if the deferred action has not been consumed. We check this with the EP.\n const nextNonceForDeferredAction: bigint = await readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, deferredActionNonce >> 64n],\n });\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 InvalidDeferredActionNonceError();\n }\n }\n\n const getNonce = async (\n params?: { key?: bigint | undefined } | undefined,\n ): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n const nonceKey = params?.key ?? 0n;\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n return readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, fullNonceKey],\n });\n };\n\n const accountContract = {\n address: accountAddress,\n abi: modularAccountAbi,\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 readContract(client, {\n ...accountContract,\n functionName: \"getExecutionData\",\n args: [selector],\n });\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 const readContractAction = getAction(client, readContract, \"readContract\");\n return readContractAction({\n ...accountContract,\n functionName: \"getValidationData\",\n args: [\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\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 return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n return callData;\n };\n\n const prepareSignature = async (\n request: SignatureRequest,\n ): Promise<Extract<SignatureRequest, { type: \"eth_signTypedData_v4\" }>> => {\n const isDeferredAction =\n request.type === \"eth_signTypedData_v4\" &&\n request.data?.primaryType === \"DeferredAction\" &&\n request.data?.domain?.verifyingContract === accountAddress;\n\n if (isDeferredAction && entityId === DEFAULT_OWNER_ENTITY_ID) {\n return request;\n }\n\n const hash =\n request.type === \"personal_sign\"\n ? hashMessage(request.data)\n : request.type === \"eth_signTypedData_v4\"\n ? hashTypedData(request.data)\n : assertNever(request, \"Unexpected signature request type\");\n\n return {\n type: \"eth_signTypedData_v4\",\n data: toReplaySafeTypedData({\n chainId: client.chain.id,\n hash,\n ...(entityId === DEFAULT_OWNER_ENTITY_ID\n ? { address: accountAddress }\n : {\n address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }),\n }),\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return pack1271Signature({\n entityId,\n validationSignaturePrefix: SignaturePrefix.EOA,\n validationSignature: signature,\n });\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n getNonce,\n authorization,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length === 1) {\n const call = calls[0];\n\n if (isAddressEqual(call.to, accountAddress)) {\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n\n if (call.data == null) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return encodeCallData(call.data);\n }\n }\n\n return encodeCallData(encodeCallsMAv2(calls));\n },\n\n async decodeCalls(data) {\n return decodeCallsMAv2(data, accountAddress);\n },\n\n async getStubSignature() {\n const sig = packUOSignature({\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n async signMessage({ message }) {\n const { data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return formatSignature(signature);\n },\n\n async signTypedData(td) {\n const isDeferredAction =\n td.primaryType === \"DeferredAction\" &&\n td.domain &&\n typeof td.domain === \"object\" &&\n \"verifyingContract\" in td.domain &&\n td.domain.verifyingContract === accountAddress;\n\n const { data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: td as TypedDataDefinition,\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return isDeferredAction\n ? concat([SignaturePrefix.EOA, signature])\n : formatSignature(signature);\n },\n\n async signUserOperation(uo) {\n const hash = getUserOperationHash({\n chainId: uo.chainId ?? client.chain.id,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...uo,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const validationSignature = await signMessageAction({\n account: owner,\n message: { raw: hash },\n });\n\n const packedSignature = packUOSignature({\n validationSignature,\n });\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, packedSignature])\n : packedSignature;\n\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n\n return signature;\n },\n\n extend: {\n smartAccountType: \"ModularAccountV2\" as const,\n signerEntity: {\n entityId,\n isGlobalValidation,\n },\n encodeCallData,\n getExecutionData,\n getValidationData,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
@@ -2,7 +2,6 @@ import { decodeFunctionData, encodeFunctionData, } from "viem";
2
2
  import { sliceHex } from "viem/utils";
3
3
  import { modularAccountAbi } from "../abis/modularAccountAbi.js";
4
4
  import { EXECUTE_USER_OP_SELECTOR } from "../utils/account.js";
5
- import { BaseError } from "@alchemy/common";
6
5
  /**
7
6
  * Encodes an array of calls into ModularAccountV2 calldata for `execute` or `executeBatch`.
8
7
  * Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed
@@ -12,9 +11,6 @@ import { BaseError } from "@alchemy/common";
12
11
  * @returns {Hex} The encoded calldata.
13
12
  */
14
13
  export function encodeCallsMAv2(calls) {
15
- if (!calls.length) {
16
- throw new BaseError("No calls to encode.");
17
- }
18
14
  if (calls.length === 1) {
19
15
  return encodeFunctionData({
20
16
  abi: modularAccountAbi,
@@ -1 +1 @@
1
- {"version":3,"file":"calldataCodec.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/calldataCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAInB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,KAAsB;IACpD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,kBAAkB,CAAC;YACxB,GAAG,EAAE,iBAAiB;YACtB,YAAY,EAAE,SAAS;YACvB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC;SACjE,CAAC,CAAC;IACL,CAAC;IAED,OA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,IAAI;SAChB,CAAC,CAAC,CAAC;IACN,CAAC;IAED,+GAA+G;IAC/G,OAAO;QACL;YACE,EAAE,EAAE,cAAc;YAClB,IAAI;SACL;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n decodeFunctionData,\n encodeFunctionData,\n type Address,\n type Call,\n type Hex,\n} from \"viem\";\nimport { sliceHex } from \"viem/utils\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport { EXECUTE_USER_OP_SELECTOR } from \"../utils/account.js\";\nimport { BaseError } from \"@alchemy/common\";\n\n/**\n * Encodes an array of calls into ModularAccountV2 calldata for `execute` or `executeBatch`.\n * Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed\n * directly unless you have an advanced use case.\n *\n * @param {Call[]} calls The calls to encode.\n * @returns {Hex} The encoded calldata.\n */\nexport function encodeCallsMAv2(calls: readonly Call[]): Hex {\n if (!calls.length) {\n throw new BaseError(\"No calls to encode.\");\n }\n\n if (calls.length === 1) {\n return encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? \"0x\"],\n });\n }\n\n return encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n data: call.data ?? \"0x\",\n value: call.value ?? 0n,\n })),\n ],\n });\n}\n\n/**\n * Decodes ModularAccountV2 calldata back into an array of calls. Strips the `EXECUTE_USER_OP_SELECTOR` prefix if present.\n * Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed\n * directly unless you have an advanced use case.\n *\n * @param {Hex} data The calldata to decode.\n * @param {Address} accountAddress The account address, used as the `to` for unrecognized selectors.\n * @returns {Call[]} The decoded calls.\n */\nexport function decodeCallsMAv2(data: Hex, accountAddress: Address): Call[] {\n // Strip the EXECUTE_USER_OP_SELECTOR prefix if present.\n const trimmedData = data\n .toLowerCase()\n .startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())\n ? sliceHex(data, 4)\n : data;\n\n const decoded = decodeFunctionData({\n abi: modularAccountAbi,\n data: trimmedData,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n}\n"]}
1
+ {"version":3,"file":"calldataCodec.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/calldataCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAInB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,KAAsB;IACpD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,kBAAkB,CAAC;YACxB,GAAG,EAAE,iBAAiB;YACtB,YAAY,EAAE,SAAS;YACvB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC;SACjE,CAAC,CAAC;IACL,CAAC;IAED,OAAO,kBAAkB,CAAC;QACxB,GAAG,EAAE,iBAAiB;QACtB,YAAY,EAAE,cAAc;QAC5B,IAAI,EAAE;YACJ,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACnB,MAAM,EAAE,IAAI,CAAC,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Call,\n type Hex,\n} from \"viem\";\nimport { sliceHex } from \"viem/utils\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport { EXECUTE_USER_OP_SELECTOR } from \"../utils/account.js\";\n\n/**\n * Encodes an array of calls into ModularAccountV2 calldata for `execute` or `executeBatch`.\n * Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed\n * directly unless you have an advanced use case.\n *\n * @param {Call[]} calls The calls to encode.\n * @returns {Hex} The encoded calldata.\n */\nexport function encodeCallsMAv2(calls: readonly Call[]): Hex {\n if (calls.length === 1) {\n return encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? \"0x\"],\n });\n }\n\n return encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n data: call.data ?? \"0x\",\n value: call.value ?? 0n,\n })),\n ],\n });\n}\n\n/**\n * Decodes ModularAccountV2 calldata back into an array of calls. Strips the `EXECUTE_USER_OP_SELECTOR` prefix if present.\n * Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed\n * directly unless you have an advanced use case.\n *\n * @param {Hex} data The calldata to decode.\n * @param {Address} accountAddress The account address, used as the `to` for unrecognized selectors.\n * @returns {Call[]} The decoded calls.\n */\nexport function decodeCallsMAv2(data: Hex, accountAddress: Address): Call[] {\n // Strip the EXECUTE_USER_OP_SELECTOR prefix if present.\n const trimmedData = data\n .toLowerCase()\n .startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())\n ? sliceHex(data, 4)\n : data;\n\n const decoded = decodeFunctionData({\n abi: modularAccountAbi,\n data: trimmedData,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n}\n"]}
@@ -25,7 +25,7 @@ export type CreateDeferredActionTypedDataParams = {
25
25
  deadline: number;
26
26
  nonce: bigint;
27
27
  };
28
- export type BuildPreSignatureDeferredActionDigestParams = {
28
+ export type BuildPreSignatureDeferredActionPayloadParams = {
29
29
  typedData: DeferredActionTypedData;
30
30
  };
31
31
  export type EntityIdAndNonceParams = {
@@ -36,7 +36,7 @@ export type EntityIdAndNonceParams = {
36
36
  };
37
37
  export type DeferralActions = {
38
38
  createDeferredActionTypedDataObject: (args: CreateDeferredActionTypedDataParams) => Promise<DeferredActionReturnData>;
39
- buildPreSignatureDeferredActionDigest: (args: BuildPreSignatureDeferredActionDigestParams) => Hex;
39
+ buildPreSignatureDeferredActionPayload: (args: BuildPreSignatureDeferredActionPayloadParams) => Hex;
40
40
  getEntityIdAndNonce: (args: EntityIdAndNonceParams) => Promise<{
41
41
  nonce: bigint;
42
42
  entityId: number;
@@ -46,6 +46,6 @@ export type DeferralActions = {
46
46
  * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
47
47
  *
48
48
  * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
49
- * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
49
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildPreSignatureDeferredActionPayload`, and `buildUserOperationWithDeferredAction`.
50
50
  */
51
51
  export declare const deferralActions: <TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends SmartAccount = SmartAccount>(client: Client<TTransport, TChain, TAccount>) => DeferralActions;
@@ -10,7 +10,7 @@ export const ENTITY_ID_AND_NONCE_READER_BYTECODE = "0x60806040523480156100105760
10
10
  * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
11
11
  *
12
12
  * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
13
- * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
13
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildPreSignatureDeferredActionPayload`, and `buildUserOperationWithDeferredAction`.
14
14
  */
15
15
  export const deferralActions = (client) => {
16
16
  const createDeferredActionTypedDataObject = async ({ callData, deadline, nonce, }) => {
@@ -40,7 +40,7 @@ export const deferralActions = (client) => {
40
40
  },
41
41
  };
42
42
  };
43
- const buildPreSignatureDeferredActionDigest = ({ typedData, }) => {
43
+ const buildPreSignatureDeferredActionPayload = ({ typedData, }) => {
44
44
  const account = client.account;
45
45
  if (!account || !isModularAccountV2(account)) {
46
46
  throw new AccountNotFoundError();
@@ -93,7 +93,7 @@ export const deferralActions = (client) => {
93
93
  };
94
94
  return {
95
95
  createDeferredActionTypedDataObject,
96
- buildPreSignatureDeferredActionDigest,
96
+ buildPreSignatureDeferredActionPayload,
97
97
  getEntityIdAndNonce,
98
98
  };
99
99
  };
@@ -1 +1 @@
1
- {"version":3,"file":"deferralActions.js","sourceRoot":"","sources":["../../../../src/ma-v2/decorators/deferralActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAKT,YAAY,EACZ,IAAI,EACJ,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,KAAK,GAEN,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,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AC,UAAU,CAAC,OAAO;gBAC1B,iBAAiB,CAAC;oBAChB,QAAQ;oBACR,QAAQ;oBACR,kBAAkB;oBAClB,gBAAgB;iBACjB,CAAC;aACH;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC/C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC;YACnB,QAAQ,EAAE,WAAW,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;SACjD,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,mCAAmC;QACnC,qCAAqC;QACrC,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n concatHex,\n type Hex,\n type Client,\n type Chain,\n type Transport,\n encodePacked,\n size,\n toHex,\n maxUint152,\n encodeDeployData,\n hexToNumber,\n isHex,\n type TypedDataDefinition,\n} from \"viem\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { entityIdAndNonceReaderAbi } from \"../abis/entityIdAndNonceReader.js\";\nimport { getAction } from \"viem/utils\";\nimport { call } from \"viem/actions\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { buildFullNonceKey, isModularAccountV2 } from \"../utils/account.js\";\nimport { AccountNotFoundError, BaseError } from \"@alchemy/common\";\n\nexport const ENTITY_ID_AND_NONCE_READER_BYTECODE =\n \"0x608060405234801561001057600080fd5b506040516104f13803806104f183398101604081905261002f916101e5565b60006008826001600160c01b0316901c90506000808263ffffffff1611610057576001610059565b815b90506001600160a01b0385163b15610133575b60006001600160a01b03861663d31b575b6bffffffff0000000000000000604085901b166040516001600160e01b031960e084901b1681526001600160401b03199091166004820152602401600060405180830381865afa1580156100d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100fd91908101906103c6565b805190915060ff161580156101155750606081015151155b156101205750610133565b8161012a816104a4565b9250505061006c565b604051631aab3f0d60e11b81526001600160a01b03868116600483015264ffffffff01600160c01b038516600884901b64ffffffff0016176024830152600091908616906335567e1a90604401602060405180830381865afa15801561019d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c191906104d7565b90508060005260206000f35b6001600160a01b03811681146101e257600080fd5b50565b6000806000606084860312156101fa57600080fd5b8351610205816101cd565b6020850151909350610216816101cd565b60408501519092506001600160c01b038116811461023357600080fd5b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156102765761027661023e565b60405290565b604051601f8201601f191681016001600160401b03811182821017156102a4576102a461023e565b604052919050565b60006001600160401b038211156102c5576102c561023e565b5060051b60200190565b600082601f8301126102e057600080fd5b81516102f36102ee826102ac565b61027c565b8082825260208201915060208360051b86010192508583111561031557600080fd5b602085015b8381101561034857805166ffffffffffffff198116811461033a57600080fd5b83526020928301920161031a565b5095945050505050565b600082601f83011261036357600080fd5b81516103716102ee826102ac565b8082825260208201915060208360051b86010192508583111561039357600080fd5b602085015b838110156103485780516001600160e01b0319811681146103b857600080fd5b835260209283019201610398565b6000602082840312156103d857600080fd5b81516001600160401b038111156103ee57600080fd5b82016080818503121561040057600080fd5b610408610254565b815160ff8116811461041957600080fd5b815260208201516001600160401b0381111561043457600080fd5b610440868285016102cf565b60208301525060408201516001600160401b0381111561045f57600080fd5b61046b868285016102cf565b60408301525060608201516001600160401b0381111561048a57600080fd5b61049686828501610352565b606083015250949350505050565b600063ffffffff821663ffffffff81036104ce57634e487b7160e01b600052601160045260246000fd5b60010192915050565b6000602082840312156104e957600080fd5b505191905056fe\";\n\nexport type DeferredActionTypedData = TypedDataDefinition<\n {\n DeferredAction: [\n { name: \"nonce\"; type: \"uint256\" },\n { name: \"deadline\"; type: \"uint48\" },\n { name: \"call\"; type: \"bytes\" },\n ];\n },\n \"DeferredAction\"\n>;\n\nexport type DeferredActionReturnData = {\n typedData: DeferredActionTypedData;\n};\n\nexport type CreateDeferredActionTypedDataParams = {\n callData: Hex;\n deadline: number;\n nonce: bigint;\n};\n\nexport type BuildPreSignatureDeferredActionDigestParams = {\n typedData: DeferredActionTypedData;\n};\n\nexport type EntityIdAndNonceParams = {\n entityId?: number;\n nonceKey?: bigint;\n isGlobalValidation: boolean;\n isDeferredAction?: boolean;\n};\n\nexport type DeferralActions = {\n createDeferredActionTypedDataObject: (\n args: CreateDeferredActionTypedDataParams,\n ) => Promise<DeferredActionReturnData>;\n buildPreSignatureDeferredActionDigest: (\n args: BuildPreSignatureDeferredActionDigestParams,\n ) => Hex;\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 TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartAccount = SmartAccount,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): DeferralActions => {\n const createDeferredActionTypedDataObject = async ({\n callData,\n deadline,\n nonce,\n }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n return {\n typedData: {\n domain: {\n chainId: client.chain.id,\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: nonce,\n deadline: deadline,\n call: callData,\n },\n },\n };\n };\n\n const buildPreSignatureDeferredActionDigest = ({\n typedData,\n }: BuildPreSignatureDeferredActionDigestParams): Hex => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n const signerEntity = account.signerEntity;\n const validationLocator =\n (BigInt(signerEntity.entityId) << 8n) |\n (signerEntity.isGlobalValidation ? 1n : 0n);\n\n const encodedCallData = encodePacked(\n [\"uint168\", \"uint48\", \"bytes\"],\n [validationLocator, typedData.message.deadline, typedData.message.call],\n );\n\n const encodedDataLength = size(encodedCallData);\n const encodedData = concatHex([\n toHex(encodedDataLength, { size: 4 }),\n encodedCallData,\n ]);\n return encodedData;\n };\n\n const getEntityIdAndNonce = async ({\n entityId = 1,\n nonceKey = 0n,\n isGlobalValidation,\n isDeferredAction = true,\n }: EntityIdAndNonceParams) => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const bytecode = encodeDeployData({\n abi: entityIdAndNonceReaderAbi,\n bytecode: ENTITY_ID_AND_NONCE_READER_BYTECODE,\n args: [\n account.address,\n account.entryPoint.address,\n buildFullNonceKey({\n nonceKey,\n entityId,\n isGlobalValidation,\n isDeferredAction,\n }),\n ],\n });\n\n const action = getAction(client, call, \"call\");\n const { data } = await action({ data: bytecode });\n if (!data) {\n throw new BaseError(\"No data returned from contract call\");\n }\n if (!isHex(data)) {\n throw new BaseError(\"Expected hex data 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 buildPreSignatureDeferredActionDigest,\n getEntityIdAndNonce,\n };\n};\n"]}
1
+ {"version":3,"file":"deferralActions.js","sourceRoot":"","sources":["../../../../src/ma-v2/decorators/deferralActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAKT,YAAY,EACZ,IAAI,EACJ,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,KAAK,GAEN,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,CAAC,MAAM,mCAAmC,GAC9C,s+EAAs+E,CAAC;AA8Cz+E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAK7B,MAA4C,EAC3B,EAAE;IACnB,MAAM,mCAAmC,GAAG,KAAK,EAAE,EACjD,QAAQ,EACR,QAAQ,EACR,KAAK,GAC+B,EAAqC,EAAE;QAC3E,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED,OAAO;YACL,SAAS,EAAE;gBACT,MAAM,EAAE;oBACN,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE;oBACxB,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;iBAC1C;gBACD,KAAK,EAAE;oBACL,cAAc,EAAE;wBAC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AC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;SACjD,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,mCAAmC;QACnC,sCAAsC;QACtC,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n concatHex,\n type Hex,\n type Client,\n type Chain,\n type Transport,\n encodePacked,\n size,\n toHex,\n maxUint152,\n encodeDeployData,\n hexToNumber,\n isHex,\n type TypedDataDefinition,\n} from \"viem\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { entityIdAndNonceReaderAbi } from \"../abis/entityIdAndNonceReader.js\";\nimport { getAction } from \"viem/utils\";\nimport { call } from \"viem/actions\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { buildFullNonceKey, isModularAccountV2 } from \"../utils/account.js\";\nimport { AccountNotFoundError, BaseError } from \"@alchemy/common\";\n\nexport const ENTITY_ID_AND_NONCE_READER_BYTECODE =\n \"0x608060405234801561001057600080fd5b506040516104f13803806104f183398101604081905261002f916101e5565b60006008826001600160c01b0316901c90506000808263ffffffff1611610057576001610059565b815b90506001600160a01b0385163b15610133575b60006001600160a01b03861663d31b575b6bffffffff0000000000000000604085901b166040516001600160e01b031960e084901b1681526001600160401b03199091166004820152602401600060405180830381865afa1580156100d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100fd91908101906103c6565b805190915060ff161580156101155750606081015151155b156101205750610133565b8161012a816104a4565b9250505061006c565b604051631aab3f0d60e11b81526001600160a01b03868116600483015264ffffffff01600160c01b038516600884901b64ffffffff0016176024830152600091908616906335567e1a90604401602060405180830381865afa15801561019d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c191906104d7565b90508060005260206000f35b6001600160a01b03811681146101e257600080fd5b50565b6000806000606084860312156101fa57600080fd5b8351610205816101cd565b6020850151909350610216816101cd565b60408501519092506001600160c01b038116811461023357600080fd5b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156102765761027661023e565b60405290565b604051601f8201601f191681016001600160401b03811182821017156102a4576102a461023e565b604052919050565b60006001600160401b038211156102c5576102c561023e565b5060051b60200190565b600082601f8301126102e057600080fd5b81516102f36102ee826102ac565b61027c565b8082825260208201915060208360051b86010192508583111561031557600080fd5b602085015b8381101561034857805166ffffffffffffff198116811461033a57600080fd5b83526020928301920161031a565b5095945050505050565b600082601f83011261036357600080fd5b81516103716102ee826102ac565b8082825260208201915060208360051b86010192508583111561039357600080fd5b602085015b838110156103485780516001600160e01b0319811681146103b857600080fd5b835260209283019201610398565b6000602082840312156103d857600080fd5b81516001600160401b038111156103ee57600080fd5b82016080818503121561040057600080fd5b610408610254565b815160ff8116811461041957600080fd5b815260208201516001600160401b0381111561043457600080fd5b610440868285016102cf565b60208301525060408201516001600160401b0381111561045f57600080fd5b61046b868285016102cf565b60408301525060608201516001600160401b0381111561048a57600080fd5b61049686828501610352565b606083015250949350505050565b600063ffffffff821663ffffffff81036104ce57634e487b7160e01b600052601160045260246000fd5b60010192915050565b6000602082840312156104e957600080fd5b505191905056fe\";\n\nexport type DeferredActionTypedData = TypedDataDefinition<\n {\n DeferredAction: [\n { name: \"nonce\"; type: \"uint256\" },\n { name: \"deadline\"; type: \"uint48\" },\n { name: \"call\"; type: \"bytes\" },\n ];\n },\n \"DeferredAction\"\n>;\n\nexport type DeferredActionReturnData = {\n typedData: DeferredActionTypedData;\n};\n\nexport type CreateDeferredActionTypedDataParams = {\n callData: Hex;\n deadline: number;\n nonce: bigint;\n};\n\nexport type BuildPreSignatureDeferredActionPayloadParams = {\n typedData: DeferredActionTypedData;\n};\n\nexport type EntityIdAndNonceParams = {\n entityId?: number;\n nonceKey?: bigint;\n isGlobalValidation: boolean;\n isDeferredAction?: boolean;\n};\n\nexport type DeferralActions = {\n createDeferredActionTypedDataObject: (\n args: CreateDeferredActionTypedDataParams,\n ) => Promise<DeferredActionReturnData>;\n buildPreSignatureDeferredActionPayload: (\n args: BuildPreSignatureDeferredActionPayloadParams,\n ) => Hex;\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`, `buildPreSignatureDeferredActionPayload`, and `buildUserOperationWithDeferredAction`.\n */\nexport const deferralActions = <\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartAccount = SmartAccount,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): DeferralActions => {\n const createDeferredActionTypedDataObject = async ({\n callData,\n deadline,\n nonce,\n }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n return {\n typedData: {\n domain: {\n chainId: client.chain.id,\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: nonce,\n deadline: deadline,\n call: callData,\n },\n },\n };\n };\n\n const buildPreSignatureDeferredActionPayload = ({\n typedData,\n }: BuildPreSignatureDeferredActionPayloadParams): Hex => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n const signerEntity = account.signerEntity;\n const validationLocator =\n (BigInt(signerEntity.entityId) << 8n) |\n (signerEntity.isGlobalValidation ? 1n : 0n);\n\n const encodedCallData = encodePacked(\n [\"uint168\", \"uint48\", \"bytes\"],\n [validationLocator, typedData.message.deadline, typedData.message.call],\n );\n\n const encodedDataLength = size(encodedCallData);\n const encodedData = concatHex([\n toHex(encodedDataLength, { size: 4 }),\n encodedCallData,\n ]);\n return encodedData;\n };\n\n const getEntityIdAndNonce = async ({\n entityId = 1,\n nonceKey = 0n,\n isGlobalValidation,\n isDeferredAction = true,\n }: EntityIdAndNonceParams) => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const bytecode = encodeDeployData({\n abi: entityIdAndNonceReaderAbi,\n bytecode: ENTITY_ID_AND_NONCE_READER_BYTECODE,\n args: [\n account.address,\n account.entryPoint.address,\n buildFullNonceKey({\n nonceKey,\n entityId,\n isGlobalValidation,\n isDeferredAction,\n }),\n ],\n });\n\n const action = getAction(client, call, \"call\");\n const { data } = await action({ data: bytecode });\n if (!data) {\n throw new BaseError(\"No data returned from contract call\");\n }\n if (!isHex(data)) {\n throw new BaseError(\"Expected hex data 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 buildPreSignatureDeferredActionPayload,\n getEntityIdAndNonce,\n };\n};\n"]}
@@ -2,7 +2,7 @@ import { type Address, type Client, type Hex, type IsUndefined, type Chain, type
2
2
  import type { HookConfig, ValidationConfig } from "../types.js";
3
3
  import type { ModularAccountV2 } from "../accounts/account.js";
4
4
  import type { GetAccountParameter } from "../../types.js";
5
- import { type SmartAccount } from "viem/account-abstraction";
5
+ import type { SmartAccount } from "viem/account-abstraction";
6
6
  export type InstallValidationParams<TAccount extends SmartAccount | undefined = SmartAccount | undefined> = {
7
7
  validationConfig: ValidationConfig;
8
8
  selectors: Hex[];
@@ -20,27 +20,23 @@ export type UninstallValidationParams<TAccount extends SmartAccount | undefined
20
20
  } & GetAccountParameter<TAccount, ModularAccountV2>;
21
21
  export type InstallValidationActions<TAccount extends SmartAccount | undefined = SmartAccount | undefined> = {
22
22
  encodeInstallValidation: (args: InstallValidationParams<TAccount>) => Promise<Hex>;
23
- installValidation: (args: InstallValidationParams<TAccount>) => Promise<Hex>;
24
23
  encodeUninstallValidation: (args: UninstallValidationParams<TAccount>) => Promise<Hex>;
25
- uninstallValidation: (args: UninstallValidationParams<TAccount>) => Promise<Hex>;
26
24
  };
27
25
  /**
28
- * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
26
+ * Provides validation installation and uninstallation encoding functionalities for a MA v2 client.
29
27
  *
30
28
  * @example
31
29
  * ```ts
32
- * import { createModularAccountV2Client, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from "@alchemy/smart-accounts";
30
+ * import { installValidationActions, SingleSignerValidationModule } from "@alchemy/smart-accounts";
33
31
  * import { Address } from "viem";
34
32
  *
35
33
  * const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);
36
34
  * const sessionKeyAddress: Address = "0x1234";
37
35
  * const sessionKeyEntityId: number = 1;
38
36
  *
39
- * await client.installValidation({
37
+ * const callData = await client.encodeInstallValidation({
40
38
  * validationConfig: {
41
- * moduleAddress: getDefaultSingleSignerValidationModuleAddress(
42
- * client.chain
43
- * ),
39
+ * moduleAddress: getDefaultSingleSignerValidationModuleAddress(client.chain),
44
40
  * entityId: sessionKeyEntityId,
45
41
  * isGlobal: true,
46
42
  * isSignatureValidation: false,
@@ -54,18 +50,10 @@ export type InstallValidationActions<TAccount extends SmartAccount | undefined =
54
50
  * hooks: [],
55
51
  * });
56
52
  *
57
- * await client.uninstallValidation({
58
- * moduleAddress: sessionKeyAddress,
59
- * entityId: sessionKeyEntityId,
60
- * uninstallData: SingleSignerValidationModule.encodeOnUninstallData({
61
- * entityId: sessionKeyEntityId,
62
- * }),
63
- * hookUninstallDatas: [],
64
- * });
65
- *
53
+ * await client.sendUserOperation({ callData, account });
66
54
  * ```
67
55
  *
68
- * @param {object} client - The client instance which provides account and sendUserOperation functionality.
69
- * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.
56
+ * @param {object} client - The client instance which provides account functionality.
57
+ * @returns {object} - An object containing `encodeInstallValidation` and `encodeUninstallValidation`.
70
58
  */
71
59
  export declare function installValidationActions<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends SmartAccount | undefined = SmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>): InstallValidationActions<IsUndefined<TAccount> extends true ? undefined : ModularAccountV2>;
@@ -1,29 +1,24 @@
1
1
  import { zeroAddress, concatHex, encodeFunctionData, } from "viem";
2
2
  import { semiModularAccountBytecodeAbi } from "../abis/semiModularAccountBytecodeAbi.js";
3
- import { sendUserOperation } from "viem/account-abstraction";
4
- import { getAction } from "viem/utils";
5
3
  import { AccountNotFoundError } from "@alchemy/common";
6
4
  import { EntityIdOverrideError } from "../../errors/EntityIdOverrideError.js";
7
5
  import { serializeHookConfig, serializeValidationConfig, } from "../utils/hooks.js";
8
6
  import { DEFAULT_OWNER_ENTITY_ID, isModularAccountV2, serializeModuleEntity, } from "../utils/account.js";
9
- // TODO(v5): update jsdoc
10
7
  /**
11
- * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
8
+ * Provides validation installation and uninstallation encoding functionalities for a MA v2 client.
12
9
  *
13
10
  * @example
14
11
  * ```ts
15
- * import { createModularAccountV2Client, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from "@alchemy/smart-accounts";
12
+ * import { installValidationActions, SingleSignerValidationModule } from "@alchemy/smart-accounts";
16
13
  * import { Address } from "viem";
17
14
  *
18
15
  * const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);
19
16
  * const sessionKeyAddress: Address = "0x1234";
20
17
  * const sessionKeyEntityId: number = 1;
21
18
  *
22
- * await client.installValidation({
19
+ * const callData = await client.encodeInstallValidation({
23
20
  * validationConfig: {
24
- * moduleAddress: getDefaultSingleSignerValidationModuleAddress(
25
- * client.chain
26
- * ),
21
+ * moduleAddress: getDefaultSingleSignerValidationModuleAddress(client.chain),
27
22
  * entityId: sessionKeyEntityId,
28
23
  * isGlobal: true,
29
24
  * isSignatureValidation: false,
@@ -37,19 +32,11 @@ import { DEFAULT_OWNER_ENTITY_ID, isModularAccountV2, serializeModuleEntity, } f
37
32
  * hooks: [],
38
33
  * });
39
34
  *
40
- * await client.uninstallValidation({
41
- * moduleAddress: sessionKeyAddress,
42
- * entityId: sessionKeyEntityId,
43
- * uninstallData: SingleSignerValidationModule.encodeOnUninstallData({
44
- * entityId: sessionKeyEntityId,
45
- * }),
46
- * hookUninstallDatas: [],
47
- * });
48
- *
35
+ * await client.sendUserOperation({ callData, account });
49
36
  * ```
50
37
  *
51
- * @param {object} client - The client instance which provides account and sendUserOperation functionality.
52
- * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.
38
+ * @param {object} client - The client instance which provides account functionality.
39
+ * @returns {object} - An object containing `encodeInstallValidation` and `encodeUninstallValidation`.
53
40
  */
54
41
  export function installValidationActions(client) {
55
42
  const encodeInstallValidation = async (args) => {
@@ -94,44 +81,6 @@ export function installValidationActions(client) {
94
81
  return {
95
82
  encodeInstallValidation,
96
83
  encodeUninstallValidation,
97
- installValidation: async (args) => {
98
- const { validationConfig, selectors, installData, hooks, account = client.account, } = args;
99
- if (!account || !isModularAccountV2(account)) {
100
- throw new AccountNotFoundError();
101
- }
102
- const callData = await encodeInstallValidation({
103
- validationConfig,
104
- selectors,
105
- installData,
106
- hooks,
107
- account,
108
- });
109
- const action = getAction(client, sendUserOperation, "sendUserOperation");
110
- const result = await action({
111
- callData,
112
- account,
113
- });
114
- return result;
115
- },
116
- uninstallValidation: async (args) => {
117
- const { moduleAddress, entityId, uninstallData, hookUninstallDatas, account = client.account, } = args;
118
- if (!account || !isModularAccountV2(account)) {
119
- throw new AccountNotFoundError();
120
- }
121
- const callData = await encodeUninstallValidation({
122
- moduleAddress,
123
- entityId,
124
- uninstallData,
125
- hookUninstallDatas,
126
- account,
127
- });
128
- const action = getAction(client, sendUserOperation, "sendUserOperation");
129
- const result = await action({
130
- callData,
131
- account,
132
- });
133
- return result;
134
- },
135
84
  };
136
85
  }
137
86
  //# sourceMappingURL=installValidation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"installValidation.js","sourceRoot":"","sources":["../../../../src/ma-v2/decorators/installValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,kBAAkB,GACnB,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAqB,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAsC7B,yBAAyB;AACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,wBAAwB,CAKtC,MAA4C;IAI5C,MAAM,uBAAuB,GAAG,KAAK,EACnC,IAEC,EACD,EAAE;QACF,MAAM,EACJ,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,KAAK,EACL,OAAO,GAAG,MAAM,CAAC,OAAO,GACzB,GAAG,IAAI,CAAC;QAET,IAAI,CAAC,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED,4GAA4G;QAC5G,IACE,gBAAgB,CAAC,QAAQ,KAAK,uBAAuB;YACrD,gBAAgB,CAAC,aAAa,KAAK,WAAW,EAC9C,CAAC;YACD,MAAM,IAAI,qBAAqB,EAAE,CAAC;QACpC,CAAC;QAED,O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AM,IAAI,oBAAoB,EAAE,CAAC;YACnC,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,uBAAuB,CAAC;gBAC7C,gBAAgB;gBAChB,SAAS;gBACT,WAAW;gBACX,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;YACzE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC;gBAC1B,QAAQ;gBACR,OAAO;aACR,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,mBAAmB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAClC,MAAM,EACJ,aAAa,EACb,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,OAAO,GAAG,MAAM,CAAC,OAAO,GACzB,GAAG,IAAI,CAAC;YAET,IAAI,CAAC,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC7C,MAAM,IAAI,oBAAoB,EAAE,CAAC;YACnC,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,yBAAyB,CAAC;gBAC/C,aAAa;gBACb,QAAQ;gBACR,aAAa;gBACb,kBAAkB;gBAClB,OAAO;aACR,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;YACzE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC;gBAC1B,QAAQ;gBACR,OAAO;aACR,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Address,\n type Client,\n type Hex,\n type IsUndefined,\n type Chain,\n type Transport,\n zeroAddress,\n concatHex,\n encodeFunctionData,\n} from \"viem\";\nimport type { HookConfig, ValidationConfig } from \"../types.js\";\nimport type { ModularAccountV2 } from \"../accounts/account.js\";\nimport type { GetAccountParameter } from \"../../types.js\";\nimport { semiModularAccountBytecodeAbi } from \"../abis/semiModularAccountBytecodeAbi.js\";\nimport { type SmartAccount, sendUserOperation } from \"viem/account-abstraction\";\nimport { getAction } from \"viem/utils\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport {\n serializeHookConfig,\n serializeValidationConfig,\n} from \"../utils/hooks.js\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n isModularAccountV2,\n serializeModuleEntity,\n} from \"../utils/account.js\";\n\nexport type InstallValidationParams<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n validationConfig: ValidationConfig;\n selectors: Hex[];\n installData: Hex;\n hooks: {\n hookConfig: HookConfig;\n initData: Hex;\n }[];\n} & GetAccountParameter<TAccount, ModularAccountV2>;\n\nexport type UninstallValidationParams<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n moduleAddress: Address;\n entityId: number;\n uninstallData: Hex;\n hookUninstallDatas: Hex[];\n} & GetAccountParameter<TAccount, ModularAccountV2>;\n\nexport type InstallValidationActions<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n encodeInstallValidation: (\n args: InstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n installValidation: (args: InstallValidationParams<TAccount>) => Promise<Hex>;\n encodeUninstallValidation: (\n args: UninstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n uninstallValidation: (\n args: UninstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n};\n\n// TODO(v5): update jsdoc\n/**\n * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.\n *\n * @example\n * ```ts\n * import { createModularAccountV2Client, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from \"@alchemy/smart-accounts\";\n * import { Address } from \"viem\";\n *\n * const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);\n * const sessionKeyAddress: Address = \"0x1234\";\n * const sessionKeyEntityId: number = 1;\n *\n * await client.installValidation({\n * validationConfig: {\n * moduleAddress: getDefaultSingleSignerValidationModuleAddress(\n * client.chain\n * ),\n * entityId: sessionKeyEntityId,\n * isGlobal: true,\n * isSignatureValidation: false,\n * isUserOpValidation: true,\n * },\n * selectors: [],\n * installData: SingleSignerValidationModule.encodeOnInstallData({\n * entityId: sessionKeyEntityId,\n * signer: sessionKeyAddress,\n * }),\n * hooks: [],\n * });\n *\n * await client.uninstallValidation({\n * moduleAddress: sessionKeyAddress,\n * entityId: sessionKeyEntityId,\n * uninstallData: SingleSignerValidationModule.encodeOnUninstallData({\n * entityId: sessionKeyEntityId,\n * }),\n * hookUninstallDatas: [],\n * });\n *\n * ```\n *\n * @param {object} client - The client instance which provides account and sendUserOperation functionality.\n * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.\n */\nexport function installValidationActions<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): InstallValidationActions<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n> {\n const encodeInstallValidation = async (\n args: InstallValidationParams<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n >,\n ) => {\n const {\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n // An entityId of zero is only allowed if we're installing or uninstalling hooks on the fallback validation.\n if (\n validationConfig.entityId === DEFAULT_OWNER_ENTITY_ID &&\n validationConfig.moduleAddress !== zeroAddress\n ) {\n throw new EntityIdOverrideError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"installValidation\",\n args: [\n serializeValidationConfig(validationConfig),\n selectors,\n installData,\n hooks.map((hook: { hookConfig: HookConfig; initData: Hex }) =>\n concatHex([serializeHookConfig(hook.hookConfig), hook.initData]),\n ),\n ],\n }),\n );\n };\n\n const encodeUninstallValidation = async (\n args: UninstallValidationParams<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n >,\n ) => {\n const {\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"uninstallValidation\",\n args: [\n serializeModuleEntity({\n moduleAddress,\n entityId,\n }),\n uninstallData,\n hookUninstallDatas,\n ],\n }),\n );\n };\n\n return {\n encodeInstallValidation,\n encodeUninstallValidation,\n installValidation: async (args) => {\n const {\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n const callData = await encodeInstallValidation({\n validationConfig,\n selectors,\n installData,\n hooks,\n account,\n });\n\n const action = getAction(client, sendUserOperation, \"sendUserOperation\");\n const result = await action({\n callData,\n account,\n });\n\n return result;\n },\n\n uninstallValidation: async (args) => {\n const {\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n const callData = await encodeUninstallValidation({\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account,\n });\n\n const action = getAction(client, sendUserOperation, \"sendUserOperation\");\n const result = await action({\n callData,\n account,\n });\n\n return result;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"installValidation.js","sourceRoot":"","sources":["../../../../src/ma-v2/decorators/installValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,kBAAkB,GACnB,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAEzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,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ACJ,aAAa,EACb,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,OAAO,GAAG,MAAM,CAAC,OAAO,GACzB,GAAG,IAAI,CAAC;QAET,IAAI,CAAC,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED,OAAO,OAAO,CAAC,cAAc,CAC3B,kBAAkB,CAAC;YACjB,GAAG,EAAE,6BAA6B;YAClC,YAAY,EAAE,qBAAqB;YACnC,IAAI,EAAE;gBACJ,qBAAqB,CAAC;oBACpB,aAAa;oBACb,QAAQ;iBACT,CAAC;gBACF,aAAa;gBACb,kBAAkB;aACnB;SACF,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,uBAAuB;QACvB,yBAAyB;KAC1B,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Address,\n type Client,\n type Hex,\n type IsUndefined,\n type Chain,\n type Transport,\n zeroAddress,\n concatHex,\n encodeFunctionData,\n} from \"viem\";\nimport type { HookConfig, ValidationConfig } from \"../types.js\";\nimport type { ModularAccountV2 } from \"../accounts/account.js\";\nimport type { GetAccountParameter } from \"../../types.js\";\nimport { semiModularAccountBytecodeAbi } from \"../abis/semiModularAccountBytecodeAbi.js\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport {\n serializeHookConfig,\n serializeValidationConfig,\n} from \"../utils/hooks.js\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n isModularAccountV2,\n serializeModuleEntity,\n} from \"../utils/account.js\";\n\nexport type InstallValidationParams<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n validationConfig: ValidationConfig;\n selectors: Hex[];\n installData: Hex;\n hooks: {\n hookConfig: HookConfig;\n initData: Hex;\n }[];\n} & GetAccountParameter<TAccount, ModularAccountV2>;\n\nexport type UninstallValidationParams<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n moduleAddress: Address;\n entityId: number;\n uninstallData: Hex;\n hookUninstallDatas: Hex[];\n} & GetAccountParameter<TAccount, ModularAccountV2>;\n\nexport type InstallValidationActions<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n encodeInstallValidation: (\n args: InstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n encodeUninstallValidation: (\n args: UninstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n};\n\n/**\n * Provides validation installation and uninstallation encoding functionalities for a MA v2 client.\n *\n * @example\n * ```ts\n * import { installValidationActions, SingleSignerValidationModule } from \"@alchemy/smart-accounts\";\n * import { Address } from \"viem\";\n *\n * const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);\n * const sessionKeyAddress: Address = \"0x1234\";\n * const sessionKeyEntityId: number = 1;\n *\n * const callData = await client.encodeInstallValidation({\n * validationConfig: {\n * moduleAddress: getDefaultSingleSignerValidationModuleAddress(client.chain),\n * entityId: sessionKeyEntityId,\n * isGlobal: true,\n * isSignatureValidation: false,\n * isUserOpValidation: true,\n * },\n * selectors: [],\n * installData: SingleSignerValidationModule.encodeOnInstallData({\n * entityId: sessionKeyEntityId,\n * signer: sessionKeyAddress,\n * }),\n * hooks: [],\n * });\n *\n * await client.sendUserOperation({ callData, account });\n * ```\n *\n * @param {object} client - The client instance which provides account functionality.\n * @returns {object} - An object containing `encodeInstallValidation` and `encodeUninstallValidation`.\n */\nexport function installValidationActions<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): InstallValidationActions<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n> {\n const encodeInstallValidation = async (\n args: InstallValidationParams<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n >,\n ) => {\n const {\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n // An entityId of zero is only allowed if we're installing or uninstalling hooks on the fallback validation.\n if (\n validationConfig.entityId === DEFAULT_OWNER_ENTITY_ID &&\n validationConfig.moduleAddress !== zeroAddress\n ) {\n throw new EntityIdOverrideError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"installValidation\",\n args: [\n serializeValidationConfig(validationConfig),\n selectors,\n installData,\n hooks.map((hook: { hookConfig: HookConfig; initData: Hex }) =>\n concatHex([serializeHookConfig(hook.hookConfig), hook.initData]),\n ),\n ],\n }),\n );\n };\n\n const encodeUninstallValidation = async (\n args: UninstallValidationParams<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n >,\n ) => {\n const {\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"uninstallValidation\",\n args: [\n serializeModuleEntity({\n moduleAddress,\n entityId,\n }),\n uninstallData,\n hookUninstallDatas,\n ],\n }),\n );\n };\n\n return {\n encodeInstallValidation,\n encodeUninstallValidation,\n };\n}\n"]}
@@ -10,14 +10,10 @@ export type SemiModularAccountV2FactoryArgs = {
10
10
  export type SemiModularAccountV2StaticImpl = StaticSmartAccountImplementation<false, "0.7", SemiModularAccountV2FactoryArgs, typeof entryPoint07Abi, typeof semiModularAccountBytecodeAbi, typeof accountFactoryAbi>;
11
11
  /**
12
12
  * Static implementation logic for SemiModularAccountV2.
13
- *
14
- * TODO(v5): update JSDoc format when doc-gen supports structs or records.
15
13
  */
16
14
  export declare const semiModularAccountV2StaticImpl: SemiModularAccountV2StaticImpl;
17
15
  export type SemiModularAccount7702StaticImpl = StaticSmartAccountImplementation<true, "0.7", SemiModularAccountV2FactoryArgs, typeof entryPoint07Abi, typeof semiModularAccountBytecodeAbi, typeof accountFactoryAbi>;
18
16
  /**
19
17
  * Static implementation logic for SemiModularAccount7702.
20
- *
21
- * TODO(v5): update JSDoc format when doc-gen supports structs or records.
22
18
  */
23
19
  export declare const semiModularAccount7702StaticImpl: SemiModularAccount7702StaticImpl;
@@ -18,8 +18,6 @@ const semiModularAccountBase = {
18
18
  };
19
19
  /**
20
20
  * Static implementation logic for SemiModularAccountV2.
21
- *
22
- * TODO(v5): update JSDoc format when doc-gen supports structs or records.
23
21
  */
24
22
  export const semiModularAccountV2StaticImpl = {
25
23
  ...semiModularAccountBase,
@@ -45,8 +43,6 @@ export const semiModularAccountV2StaticImpl = {
45
43
  };
46
44
  /**
47
45
  * Static implementation logic for SemiModularAccount7702.
48
- *
49
- * TODO(v5): update JSDoc format when doc-gen supports structs or records.
50
46
  */
51
47
  export const semiModularAccount7702StaticImpl = {
52
48
  ...semiModularAccountBase,
@@ -1 +1 @@
1
- {"version":3,"file":"mav2StaticImpl.js","sourceRoot":"","sources":["../../../src/ma-v2/mav2StaticImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAgBrE,gFAAgF;AAChF,MAAM,UAAU,GAAG;IACjB,GAAG,EAAE,eAAe;IACpB,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,KAAK;CACN,CAAC;AAEX,sEAAsE;AACtE,MAAM,sBAAsB,GAAG;IAC7B,UAAU;IACV,UAAU,EAAE,6BAA6B;CACQ,CAAC;AAEpD;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAmC;IAC5E,GAAG,sBAAsB;IACzB,qBAAqB,EAAE,YAAY,CAAC,kBAAkB,CAAC,cAAc,CAAC;IACtE,cAAc,EAAE,YAAY,CAAC,kBAAkB,CAAC,YAAY,CAAC;IAC7D,UAAU,EAAE,iBAAiB;IAC7B,cAAc,EAAE,CAAC,IAAqC,EAAE,EAAE;QACxD,OAAO,kBAAkB,CAAC;YACxB,GAAG,EAAE,iBAAiB;YACtB,YAAY,EAAE,0BAA0B;YACxC,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC;SAC9B,CAAC,CAAC;IACL,CAAC;IACD,qBAAqB,EAAE,CAAC,IAAqC,EAAE,EAAE;QAC/D,OAAO,8BAA8B,CAAC;YACpC,cAAc,EAAE,kBAAkB,CAAC,YAAY;YAC/C,qBAAqB,EAAE,kBAAkB,CAAC,cAAc;YACxD,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,KAAK;SACzB,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAWF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAC3C;IACE,GAAG,sBAAsB;IACzB,iBAAiB,EAAE,YAAY,CAAC,kBAAkB,CAAC,UAAU,CAAC;CAC/D,CAAC","sourcesContent":["import { encodeFunctionData, type Address } from \"viem\";\nimport { entryPoint07Abi, entryPoint07Address } from \"viem/account-abstraction\";\nimport { lowerAddress } from \"@alchemy/common\";\nimport type { StaticSmartAccountImplementation } from \"../types.js\";\nimport { semiModularAccountBytecodeAbi } from \"./abis/semiModularAccountBytecodeAbi.js\";\nimport { accountFactoryAbi } from \"./abis/accountFactoryAbi.js\";\nimport { DefaultAddress as DefaultMAV2Address } from \"./utils/account.js\";\nimport { predictModularAccountV2Address } from \"./predictAddress.js\";\n\nexport type SemiModularAccountV2FactoryArgs = {\n owner: Address;\n salt: bigint;\n};\n\nexport type SemiModularAccountV2StaticImpl = StaticSmartAccountImplementation<\n false,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n// Shared entryPoint configuration across all modular account v2 implementations\nconst entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address,\n version: \"0.7\",\n} as const;\n\n// Shared base for semi-modular account implementations (SMA and 7702)\nconst semiModularAccountBase = {\n entryPoint,\n accountAbi: semiModularAccountBytecodeAbi,\n} satisfies Partial<SemiModularAccountV2StaticImpl>;\n\n/**\n * Static implementation logic for SemiModularAccountV2.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const semiModularAccountV2StaticImpl: SemiModularAccountV2StaticImpl = {\n ...semiModularAccountBase,\n accountImplementation: lowerAddress(DefaultMAV2Address.SMAV2_BYTECODE),\n factoryAddress: lowerAddress(DefaultMAV2Address.MAV2_FACTORY),\n factoryAbi: accountFactoryAbi,\n getFactoryData: (args: SemiModularAccountV2FactoryArgs) => {\n return encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [args.owner, args.salt],\n });\n },\n predictAccountAddress: (args: SemiModularAccountV2FactoryArgs) => {\n return predictModularAccountV2Address({\n factoryAddress: DefaultMAV2Address.MAV2_FACTORY,\n implementationAddress: DefaultMAV2Address.SMAV2_BYTECODE,\n type: \"SMA\",\n salt: args.salt,\n ownerAddress: args.owner,\n });\n },\n};\n\nexport type SemiModularAccount7702StaticImpl = StaticSmartAccountImplementation<\n true,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n/**\n * Static implementation logic for SemiModularAccount7702.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const semiModularAccount7702StaticImpl: SemiModularAccount7702StaticImpl =\n {\n ...semiModularAccountBase,\n delegationAddress: lowerAddress(DefaultMAV2Address.SMAV2_7702),\n };\n"]}
1
+ {"version":3,"file":"mav2StaticImpl.js","sourceRoot":"","sources":["../../../src/ma-v2/mav2StaticImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAgBrE,gFAAgF;AAChF,MAAM,UAAU,GAAG;IACjB,GAAG,EAAE,eAAe;IACpB,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,KAAK;CACN,CAAC;AAEX,sEAAsE;AACtE,MAAM,sBAAsB,GAAG;IAC7B,UAAU;IACV,UAAU,EAAE,6BAA6B;CACQ,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAmC;IAC5E,GAAG,sBAAsB;IACzB,qBAAqB,EAAE,YAAY,CAAC,kBAAkB,CAAC,cAAc,CAAC;IACtE,cAAc,EAAE,YAAY,CAAC,kBAAkB,CAAC,YAAY,CAAC;IAC7D,UAAU,EAAE,iBAAiB;IAC7B,cAAc,EAAE,CAAC,IAAqC,EAAE,EAAE;QACxD,OAAO,kBAAkB,CAAC;YACxB,GAAG,EAAE,iBAAiB;YACtB,YAAY,EAAE,0BAA0B;YACxC,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC;SAC9B,CAAC,CAAC;IACL,CAAC;IACD,qBAAqB,EAAE,CAAC,IAAqC,EAAE,EAAE;QAC/D,OAAO,8BAA8B,CAAC;YACpC,cAAc,EAAE,kBAAkB,CAAC,YAAY;YAC/C,qBAAqB,EAAE,kBAAkB,CAAC,cAAc;YACxD,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,KAAK;SACzB,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAWF;;GAEG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAC3C;IACE,GAAG,sBAAsB;IACzB,iBAAiB,EAAE,YAAY,CAAC,kBAAkB,CAAC,UAAU,CAAC;CAC/D,CAAC","sourcesContent":["import { encodeFunctionData, type Address } from \"viem\";\nimport { entryPoint07Abi, entryPoint07Address } from \"viem/account-abstraction\";\nimport { lowerAddress } from \"@alchemy/common\";\nimport type { StaticSmartAccountImplementation } from \"../types.js\";\nimport { semiModularAccountBytecodeAbi } from \"./abis/semiModularAccountBytecodeAbi.js\";\nimport { accountFactoryAbi } from \"./abis/accountFactoryAbi.js\";\nimport { DefaultAddress as DefaultMAV2Address } from \"./utils/account.js\";\nimport { predictModularAccountV2Address } from \"./predictAddress.js\";\n\nexport type SemiModularAccountV2FactoryArgs = {\n owner: Address;\n salt: bigint;\n};\n\nexport type SemiModularAccountV2StaticImpl = StaticSmartAccountImplementation<\n false,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n// Shared entryPoint configuration across all modular account v2 implementations\nconst entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address,\n version: \"0.7\",\n} as const;\n\n// Shared base for semi-modular account implementations (SMA and 7702)\nconst semiModularAccountBase = {\n entryPoint,\n accountAbi: semiModularAccountBytecodeAbi,\n} satisfies Partial<SemiModularAccountV2StaticImpl>;\n\n/**\n * Static implementation logic for SemiModularAccountV2.\n */\nexport const semiModularAccountV2StaticImpl: SemiModularAccountV2StaticImpl = {\n ...semiModularAccountBase,\n accountImplementation: lowerAddress(DefaultMAV2Address.SMAV2_BYTECODE),\n factoryAddress: lowerAddress(DefaultMAV2Address.MAV2_FACTORY),\n factoryAbi: accountFactoryAbi,\n getFactoryData: (args: SemiModularAccountV2FactoryArgs) => {\n return encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [args.owner, args.salt],\n });\n },\n predictAccountAddress: (args: SemiModularAccountV2FactoryArgs) => {\n return predictModularAccountV2Address({\n factoryAddress: DefaultMAV2Address.MAV2_FACTORY,\n implementationAddress: DefaultMAV2Address.SMAV2_BYTECODE,\n type: \"SMA\",\n salt: args.salt,\n ownerAddress: args.owner,\n });\n },\n};\n\nexport type SemiModularAccount7702StaticImpl = StaticSmartAccountImplementation<\n true,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n/**\n * Static implementation logic for SemiModularAccount7702.\n */\nexport const semiModularAccount7702StaticImpl: SemiModularAccount7702StaticImpl =\n {\n ...semiModularAccountBase,\n delegationAddress: lowerAddress(DefaultMAV2Address.SMAV2_7702),\n };\n"]}
@@ -133,11 +133,11 @@ export declare class PermissionBuilder {
133
133
  /**
134
134
  * Compiles the deferred action typed data to sign.
135
135
  *
136
- * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionDigest: Hex}>} The deferred action typed data and the full pre-signature deferred action digest.
136
+ * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionPayload: Hex}>} The deferred action typed data and the full pre-signature deferred action payload.
137
137
  */
138
138
  compileDeferred(): Promise<{
139
139
  typedData: DeferredActionTypedData;
140
- fullPreSignatureDeferredActionDigest: Hex;
140
+ fullPreSignatureDeferredActionPayload: Hex;
141
141
  }>;
142
142
  /**
143
143
  * Compiles the raw install arguments for the installValidation function.