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

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 (38) hide show
  1. package/dist/esm/index.d.ts +3 -0
  2. package/dist/esm/index.js +3 -0
  3. package/dist/esm/index.js.map +1 -1
  4. package/dist/esm/light-account/accounts/calldataCodec.d.ts +17 -0
  5. package/dist/esm/light-account/accounts/calldataCodec.js +20 -0
  6. package/dist/esm/light-account/accounts/calldataCodec.js.map +1 -1
  7. package/dist/esm/ma-v1/accounts/base.js +5 -49
  8. package/dist/esm/ma-v1/accounts/base.js.map +1 -1
  9. package/dist/esm/ma-v1/accounts/calldataCodec.d.ts +20 -0
  10. package/dist/esm/ma-v1/accounts/calldataCodec.js +73 -0
  11. package/dist/esm/ma-v1/accounts/calldataCodec.js.map +1 -0
  12. package/dist/esm/ma-v2/accounts/base.js +6 -53
  13. package/dist/esm/ma-v2/accounts/base.js.map +1 -1
  14. package/dist/esm/ma-v2/accounts/calldataCodec.d.ts +20 -0
  15. package/dist/esm/ma-v2/accounts/calldataCodec.js +81 -0
  16. package/dist/esm/ma-v2/accounts/calldataCodec.js.map +1 -0
  17. package/dist/esm/version.d.ts +1 -1
  18. package/dist/esm/version.js +1 -1
  19. package/dist/esm/version.js.map +1 -1
  20. package/dist/types/index.d.ts +3 -0
  21. package/dist/types/index.d.ts.map +1 -1
  22. package/dist/types/light-account/accounts/calldataCodec.d.ts +17 -0
  23. package/dist/types/light-account/accounts/calldataCodec.d.ts.map +1 -1
  24. package/dist/types/ma-v1/accounts/base.d.ts.map +1 -1
  25. package/dist/types/ma-v1/accounts/calldataCodec.d.ts +21 -0
  26. package/dist/types/ma-v1/accounts/calldataCodec.d.ts.map +1 -0
  27. package/dist/types/ma-v2/accounts/base.d.ts.map +1 -1
  28. package/dist/types/ma-v2/accounts/calldataCodec.d.ts +21 -0
  29. package/dist/types/ma-v2/accounts/calldataCodec.d.ts.map +1 -0
  30. package/dist/types/version.d.ts +1 -1
  31. package/package.json +4 -4
  32. package/src/index.ts +15 -0
  33. package/src/light-account/accounts/calldataCodec.ts +21 -0
  34. package/src/ma-v1/accounts/base.ts +3 -54
  35. package/src/ma-v1/accounts/calldataCodec.ts +85 -0
  36. package/src/ma-v2/accounts/base.ts +5 -67
  37. package/src/ma-v2/accounts/calldataCodec.ts +94 -0
  38. package/src/version.ts +1 -1
@@ -12,6 +12,7 @@ export { predictLightAccountAddress, predictMultiOwnerLightAccountAddress, } fro
12
12
  export { AccountVersionRegistry } from "./light-account/registry.js";
13
13
  export type * from "./light-account/registry.js";
14
14
  export { defaultLightAccountVersion, getLightAccountImplAddress, LightAccountUnsupported1271Factories, LightAccountUnsupported1271Impls, } from "./light-account/utils.js";
15
+ export { encodeCallsLA, decodeCallsLA, } from "./light-account/accounts/calldataCodec.js";
15
16
  export { lightAccountStaticImplV1_0_1, lightAccountStaticImplV1_0_2, lightAccountStaticImplV1_1_0, lightAccountStaticImplV2_0_0, multiOwnerLightAccountStaticImplV2_0_0, } from "./light-account/lightAccountStaticImpl.js";
16
17
  export type * from "./ma-v1/accounts/base.js";
17
18
  export { toModularAccountV1Base } from "./ma-v1/accounts/base.js";
@@ -23,10 +24,12 @@ export type * from "./ma-v1/predictAddress.js";
23
24
  export { predictMultiOwnerModularAccountV1Address } from "./ma-v1/predictAddress.js";
24
25
  export { multiOwnerModularAccountStaticImpl } from "./ma-v1/mav1StaticImpl.js";
25
26
  export { DefaultMaV1Address, DefaultMaV1PluginAddress, } from "./ma-v1/account.js";
27
+ export { encodeCallsMAv1, decodeCallsMAv1, } from "./ma-v1/accounts/calldataCodec.js";
26
28
  export type * from "./ma-v2/accounts/account.js";
27
29
  export { toModularAccountV2 } from "./ma-v2/accounts/account.js";
28
30
  export type * from "./ma-v2/accounts/base.js";
29
31
  export { toModularAccountV2Base } from "./ma-v2/accounts/base.js";
32
+ export { encodeCallsMAv2, decodeCallsMAv2, } from "./ma-v2/accounts/calldataCodec.js";
30
33
  export type * from "./ma-v2/decorators/deferralActions.js";
31
34
  export { deferralActions } from "./ma-v2/decorators/deferralActions.js";
32
35
  export type * from "./ma-v2/decorators/installValidation.js";
package/dist/esm/index.js CHANGED
@@ -5,6 +5,7 @@ export { multiOwnerLightAccountActions } from "./light-account/decorators/multiO
5
5
  export { predictLightAccountAddress, predictMultiOwnerLightAccountAddress, } from "./light-account/predictAddress.js";
6
6
  export { AccountVersionRegistry } from "./light-account/registry.js";
7
7
  export { defaultLightAccountVersion, getLightAccountImplAddress, LightAccountUnsupported1271Factories, LightAccountUnsupported1271Impls, } from "./light-account/utils.js";
8
+ export { encodeCallsLA, decodeCallsLA, } from "./light-account/accounts/calldataCodec.js";
8
9
  export { lightAccountStaticImplV1_0_1, lightAccountStaticImplV1_0_2, lightAccountStaticImplV1_1_0, lightAccountStaticImplV2_0_0, multiOwnerLightAccountStaticImplV2_0_0, } from "./light-account/lightAccountStaticImpl.js";
9
10
  export { toModularAccountV1Base } from "./ma-v1/accounts/base.js";
10
11
  export { toMultiOwnerModularAccountV1 } from "./ma-v1/accounts/multi-owner-account.js";
@@ -12,8 +13,10 @@ export { multiOwnerModularAccountV1Actions } from "./ma-v1/decorators/multiOwner
12
13
  export { predictMultiOwnerModularAccountV1Address } from "./ma-v1/predictAddress.js";
13
14
  export { multiOwnerModularAccountStaticImpl } from "./ma-v1/mav1StaticImpl.js";
14
15
  export { DefaultMaV1Address, DefaultMaV1PluginAddress, } from "./ma-v1/account.js";
16
+ export { encodeCallsMAv1, decodeCallsMAv1, } from "./ma-v1/accounts/calldataCodec.js";
15
17
  export { toModularAccountV2 } from "./ma-v2/accounts/account.js";
16
18
  export { toModularAccountV2Base } from "./ma-v2/accounts/base.js";
19
+ export { encodeCallsMAv2, decodeCallsMAv2, } from "./ma-v2/accounts/calldataCodec.js";
17
20
  export { deferralActions } from "./ma-v2/decorators/deferralActions.js";
18
21
  export { installValidationActions } from "./ma-v2/decorators/installValidation.js";
19
22
  export { semiModularAccountV2StaticImpl, semiModularAccount7702StaticImpl, } from "./ma-v2/mav2StaticImpl.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAGrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAO3F,OAAO,EAAE,8BAA8B,EAAE,MAAM,2CAA2C,CAAC;AAG3F,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAGzF,OAAO,EACL,0BAA0B,EAC1B,oCAAoC,GACrC,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,oCAAoC,EACpC,gCAAgC,GACjC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,2CAA2C,CAAC;AAInD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAGvF,OAAO,EAAE,iCAAiC,EAAE,MAAM,kCAAkC,CAAC;AAGrF,OAAO,EAAE,wCAAwC,EAAE,MAAM,2BAA2B,CAAC;AAErF,OAAO,EAAE,kCAAkC,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAGxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,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,EACtB,0BAA0B,EAC1B,gCAAgC,EAChC,gBAAgB,EAChB,qBAAqB,EACrB,8BAA8B,EAC9B,kBAAkB,GACnB,MAAM,qCAAqC,CAAC","sourcesContent":["export type * from \"./types.js\";\n\n// LightAccount\nexport type * from \"./light-account/accounts/account.js\";\nexport { toLightAccount } from \"./light-account/accounts/account.js\";\n\nexport type * from \"./light-account/accounts/multi-owner-account.js\";\nexport { toMultiOwnerLightAccount } from \"./light-account/accounts/multi-owner-account.js\";\n\n// TODO(v5): Something to consider for v5 - can we cut the exports for the account-specific actions\n// from the public interface, and just consume these internally with account + rely on the standard\n// bundlerClient actions for performing state writes (i.e. rotating owners)? I'm not sure it's useful\n// to consumers outside of attaching to instances of a client with the right action.\nexport type * from \"./light-account/decorators/singleOwner.js\";\nexport { singleOwnerLightAccountActions } from \"./light-account/decorators/singleOwner.js\";\n\nexport type * from \"./light-account/decorators/multiOwner.js\";\nexport { multiOwnerLightAccountActions } from \"./light-account/decorators/multiOwner.js\";\n\nexport type * from \"./light-account/predictAddress.js\";\nexport {\n predictLightAccountAddress,\n predictMultiOwnerLightAccountAddress,\n} from \"./light-account/predictAddress.js\";\n\nexport { AccountVersionRegistry } from \"./light-account/registry.js\";\nexport type * from \"./light-account/registry.js\";\nexport {\n defaultLightAccountVersion,\n getLightAccountImplAddress,\n LightAccountUnsupported1271Factories,\n LightAccountUnsupported1271Impls,\n} from \"./light-account/utils.js\";\n\nexport {\n lightAccountStaticImplV1_0_1,\n lightAccountStaticImplV1_0_2,\n lightAccountStaticImplV1_1_0,\n lightAccountStaticImplV2_0_0,\n multiOwnerLightAccountStaticImplV2_0_0,\n} from \"./light-account/lightAccountStaticImpl.js\";\n\n// ModularAccountV1\nexport type * from \"./ma-v1/accounts/base.js\";\nexport { toModularAccountV1Base } from \"./ma-v1/accounts/base.js\";\n\nexport type * from \"./ma-v1/accounts/multi-owner-account.js\";\nexport { toMultiOwnerModularAccountV1 } from \"./ma-v1/accounts/multi-owner-account.js\";\n\nexport type * from \"./ma-v1/decorators/multiOwner.js\";\nexport { multiOwnerModularAccountV1Actions } from \"./ma-v1/decorators/multiOwner.js\";\n\nexport type * from \"./ma-v1/predictAddress.js\";\nexport { predictMultiOwnerModularAccountV1Address } from \"./ma-v1/predictAddress.js\";\n\nexport { multiOwnerModularAccountStaticImpl } from \"./ma-v1/mav1StaticImpl.js\";\n\nexport {\n DefaultMaV1Address,\n DefaultMaV1PluginAddress,\n} from \"./ma-v1/account.js\";\n\n// ModularAccountV2\nexport type * from \"./ma-v2/accounts/account.js\";\nexport { toModularAccountV2 } from \"./ma-v2/accounts/account.js\";\n\nexport type * from \"./ma-v2/accounts/base.js\";\nexport { toModularAccountV2Base } from \"./ma-v2/accounts/base.js\";\n\nexport type * from \"./ma-v2/decorators/deferralActions.js\";\nexport { deferralActions } from \"./ma-v2/decorators/deferralActions.js\";\n\nexport type * from \"./ma-v2/decorators/installValidation.js\";\nexport { installValidationActions } from \"./ma-v2/decorators/installValidation.js\";\n\nexport {\n semiModularAccountV2StaticImpl,\n semiModularAccount7702StaticImpl,\n} from \"./ma-v2/mav2StaticImpl.js\";\nexport type * from \"./ma-v2/mav2StaticImpl.js\";\n\n// Modules\nexport { AllowlistModule } from \"./ma-v2/modules/allowlist-module/module.js\";\nexport { NativeTokenLimitModule } from \"./ma-v2/modules/native-token-limit-module/module.js\";\nexport { PaymasterGuardModule } from \"./ma-v2/modules/paymaster-guard-module/module.js\";\nexport { SingleSignerValidationModule } from \"./ma-v2/modules/single-signer-validation/module.js\";\nexport { TimeRangeModule } from \"./ma-v2/modules/time-range-module/module.js\";\n\nexport type * from \"./ma-v2/permissionBuilder.js\";\nexport {\n PermissionBuilder,\n PermissionType,\n} from \"./ma-v2/permissionBuilder.js\";\n\nexport type * from \"./ma-v2/predictAddress.js\";\nexport { predictModularAccountV2Address } from \"./ma-v2/predictAddress.js\";\n\nexport type * from \"./ma-v2/types.js\";\n\nexport type * from \"./ma-v2/utils/account.js\";\nexport {\n DefaultAddress,\n DefaultModuleAddress,\n DEFAULT_OWNER_ENTITY_ID,\n EXECUTE_USER_OP_SELECTOR,\n getMAV2UpgradeToData,\n buildFullNonceKey,\n serializeModuleEntity,\n isModularAccountV2,\n} from \"./ma-v2/utils/account.js\";\n\nexport type * from \"./ma-v2/utils/deferredActions.js\";\nexport {\n parseDeferredAction,\n buildDeferredActionDigest,\n} from \"./ma-v2/utils/deferredActions.js\";\n\nexport type * from \"./ma-v2/utils/hooks.js\";\nexport {\n serializeValidationConfig,\n serializeHookConfig,\n} from \"./ma-v2/utils/hooks.js\";\n\nexport type * from \"./ma-v2/utils/signature.js\";\nexport {\n packUOSignature,\n pack1271Signature,\n toReplaySafeTypedData,\n} from \"./ma-v2/utils/signature.js\";\n\n// Errors\nexport { EntityIdOverrideError } from \"./errors/EntityIdOverrideError.js\";\nexport { InvalidDeferredActionNonceError } from \"./errors/InvalidDeferredActionNonceError.js\";\nexport { InvalidEntityIdError } from \"./errors/InvalidEntityIdError.js\";\nexport { InvalidNonceKeyError } from \"./errors/InvalidNonceKeyError.js\";\nexport { InvalidOwnerError } from \"./errors/InvalidOwnerError.js\";\nexport {\n PermissionBuilderError,\n RootPermissionOnlyError,\n AccountAddressAsTargetError,\n DuplicateTargetAddressError,\n NoFunctionsProvidedError,\n ExpiredDeadlineError,\n DeadlineOverLimitError,\n ValidationConfigUnsetError,\n MultipleNativeTokenTransferError,\n ZeroAddressError,\n MultipleGasLimitError,\n UnsupportedPermissionTypeError,\n SelectorNotAllowed,\n} from \"./errors/permissionBuilderErrors.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAGrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAO3F,OAAO,EAAE,8BAA8B,EAAE,MAAM,2CAA2C,CAAC;AAG3F,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA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B,EAAE,MAAM,qDAAqD,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAG9E,OAAO,EACL,iBAAiB,EACjB,cAAc,GACf,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAK3E,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EACL,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,SAAS;AACT,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,gCAAgC,EAChC,gBAAgB,EAChB,qBAAqB,EACrB,8BAA8B,EAC9B,kBAAkB,GACnB,MAAM,qCAAqC,CAAC","sourcesContent":["export type * from \"./types.js\";\n\n// LightAccount\nexport type * from \"./light-account/accounts/account.js\";\nexport { toLightAccount } from \"./light-account/accounts/account.js\";\n\nexport type * from \"./light-account/accounts/multi-owner-account.js\";\nexport { toMultiOwnerLightAccount } from \"./light-account/accounts/multi-owner-account.js\";\n\n// TODO(v5): Something to consider for v5 - can we cut the exports for the account-specific actions\n// from the public interface, and just consume these internally with account + rely on the standard\n// bundlerClient actions for performing state writes (i.e. rotating owners)? I'm not sure it's useful\n// to consumers outside of attaching to instances of a client with the right action.\nexport type * from \"./light-account/decorators/singleOwner.js\";\nexport { singleOwnerLightAccountActions } from \"./light-account/decorators/singleOwner.js\";\n\nexport type * from \"./light-account/decorators/multiOwner.js\";\nexport { multiOwnerLightAccountActions } from \"./light-account/decorators/multiOwner.js\";\n\nexport type * from \"./light-account/predictAddress.js\";\nexport {\n predictLightAccountAddress,\n predictMultiOwnerLightAccountAddress,\n} from \"./light-account/predictAddress.js\";\n\nexport { AccountVersionRegistry } from \"./light-account/registry.js\";\nexport type * from \"./light-account/registry.js\";\nexport {\n defaultLightAccountVersion,\n getLightAccountImplAddress,\n LightAccountUnsupported1271Factories,\n LightAccountUnsupported1271Impls,\n} from \"./light-account/utils.js\";\n\nexport {\n encodeCallsLA,\n decodeCallsLA,\n} from \"./light-account/accounts/calldataCodec.js\";\n\nexport {\n lightAccountStaticImplV1_0_1,\n lightAccountStaticImplV1_0_2,\n lightAccountStaticImplV1_1_0,\n lightAccountStaticImplV2_0_0,\n multiOwnerLightAccountStaticImplV2_0_0,\n} from \"./light-account/lightAccountStaticImpl.js\";\n\n// ModularAccountV1\nexport type * from \"./ma-v1/accounts/base.js\";\nexport { toModularAccountV1Base } from \"./ma-v1/accounts/base.js\";\n\nexport type * from \"./ma-v1/accounts/multi-owner-account.js\";\nexport { toMultiOwnerModularAccountV1 } from \"./ma-v1/accounts/multi-owner-account.js\";\n\nexport type * from \"./ma-v1/decorators/multiOwner.js\";\nexport { multiOwnerModularAccountV1Actions } from \"./ma-v1/decorators/multiOwner.js\";\n\nexport type * from \"./ma-v1/predictAddress.js\";\nexport { predictMultiOwnerModularAccountV1Address } from \"./ma-v1/predictAddress.js\";\n\nexport { multiOwnerModularAccountStaticImpl } from \"./ma-v1/mav1StaticImpl.js\";\n\nexport {\n DefaultMaV1Address,\n DefaultMaV1PluginAddress,\n} from \"./ma-v1/account.js\";\n\nexport {\n encodeCallsMAv1,\n decodeCallsMAv1,\n} from \"./ma-v1/accounts/calldataCodec.js\";\n\n// ModularAccountV2\nexport type * from \"./ma-v2/accounts/account.js\";\nexport { toModularAccountV2 } from \"./ma-v2/accounts/account.js\";\n\nexport type * from \"./ma-v2/accounts/base.js\";\nexport { toModularAccountV2Base } from \"./ma-v2/accounts/base.js\";\n\nexport {\n encodeCallsMAv2,\n decodeCallsMAv2,\n} from \"./ma-v2/accounts/calldataCodec.js\";\n\nexport type * from \"./ma-v2/decorators/deferralActions.js\";\nexport { deferralActions } from \"./ma-v2/decorators/deferralActions.js\";\n\nexport type * from \"./ma-v2/decorators/installValidation.js\";\nexport { installValidationActions } from \"./ma-v2/decorators/installValidation.js\";\n\nexport {\n semiModularAccountV2StaticImpl,\n semiModularAccount7702StaticImpl,\n} from \"./ma-v2/mav2StaticImpl.js\";\nexport type * from \"./ma-v2/mav2StaticImpl.js\";\n\n// Modules\nexport { AllowlistModule } from \"./ma-v2/modules/allowlist-module/module.js\";\nexport { NativeTokenLimitModule } from \"./ma-v2/modules/native-token-limit-module/module.js\";\nexport { PaymasterGuardModule } from \"./ma-v2/modules/paymaster-guard-module/module.js\";\nexport { SingleSignerValidationModule } from \"./ma-v2/modules/single-signer-validation/module.js\";\nexport { TimeRangeModule } from \"./ma-v2/modules/time-range-module/module.js\";\n\nexport type * from \"./ma-v2/permissionBuilder.js\";\nexport {\n PermissionBuilder,\n PermissionType,\n} from \"./ma-v2/permissionBuilder.js\";\n\nexport type * from \"./ma-v2/predictAddress.js\";\nexport { predictModularAccountV2Address } from \"./ma-v2/predictAddress.js\";\n\nexport type * from \"./ma-v2/types.js\";\n\nexport type * from \"./ma-v2/utils/account.js\";\nexport {\n DefaultAddress,\n DefaultModuleAddress,\n DEFAULT_OWNER_ENTITY_ID,\n EXECUTE_USER_OP_SELECTOR,\n getMAV2UpgradeToData,\n buildFullNonceKey,\n serializeModuleEntity,\n isModularAccountV2,\n} from \"./ma-v2/utils/account.js\";\n\nexport type * from \"./ma-v2/utils/deferredActions.js\";\nexport {\n parseDeferredAction,\n buildDeferredActionDigest,\n} from \"./ma-v2/utils/deferredActions.js\";\n\nexport type * from \"./ma-v2/utils/hooks.js\";\nexport {\n serializeValidationConfig,\n serializeHookConfig,\n} from \"./ma-v2/utils/hooks.js\";\n\nexport type * from \"./ma-v2/utils/signature.js\";\nexport {\n packUOSignature,\n pack1271Signature,\n toReplaySafeTypedData,\n} from \"./ma-v2/utils/signature.js\";\n\n// Errors\nexport { EntityIdOverrideError } from \"./errors/EntityIdOverrideError.js\";\nexport { InvalidDeferredActionNonceError } from \"./errors/InvalidDeferredActionNonceError.js\";\nexport { InvalidEntityIdError } from \"./errors/InvalidEntityIdError.js\";\nexport { InvalidNonceKeyError } from \"./errors/InvalidNonceKeyError.js\";\nexport { InvalidOwnerError } from \"./errors/InvalidOwnerError.js\";\nexport {\n PermissionBuilderError,\n RootPermissionOnlyError,\n AccountAddressAsTargetError,\n DuplicateTargetAddressError,\n NoFunctionsProvidedError,\n ExpiredDeadlineError,\n DeadlineOverLimitError,\n ValidationConfigUnsetError,\n MultipleNativeTokenTransferError,\n ZeroAddressError,\n MultipleGasLimitError,\n UnsupportedPermissionTypeError,\n SelectorNotAllowed,\n} from \"./errors/permissionBuilderErrors.js\";\n"]}
@@ -1,3 +1,20 @@
1
1
  import { type Address, type Call, type Hex } from "viem";
2
+ /**
3
+ * Encodes an array of calls into LightAccount calldata for `execute` or `executeBatch`.
4
+ * Used internally by the LightAccount SmartAccount implementation. Typically not needed
5
+ * directly unless you have an advanced use case.
6
+ *
7
+ * @param {Call[]} calls The calls to encode.
8
+ * @returns {Hex} The encoded calldata.
9
+ */
2
10
  export declare function encodeCallsLA(calls: readonly Call[]): Hex;
11
+ /**
12
+ * Decodes LightAccount calldata back into an array of calls.
13
+ * Used internally by the LightAccount SmartAccount implementation. Typically not needed
14
+ * directly unless you have an advanced use case.
15
+ *
16
+ * @param {Hex} data The calldata to decode.
17
+ * @param {Address} accountAddress The account address, used as the `to` for unrecognized selectors.
18
+ * @returns {Call[]} The decoded calls.
19
+ */
3
20
  export declare function decodeCallsLA(data: Hex, accountAddress: Address): Call[];
@@ -2,7 +2,18 @@ import { decodeFunctionData, encodeFunctionData, } from "viem";
2
2
  import { LightAccountAbi_v1 } from "../abis/LightAccountAbi_v1.js";
3
3
  import { BaseError } from "@alchemy/common";
4
4
  // Conveniently, all variants of LA up to v2.0.0 use the same function signatures for `execute` and `executeBatch`.
5
+ /**
6
+ * Encodes an array of calls into LightAccount calldata for `execute` or `executeBatch`.
7
+ * Used internally by the LightAccount SmartAccount implementation. Typically not needed
8
+ * directly unless you have an advanced use case.
9
+ *
10
+ * @param {Call[]} calls The calls to encode.
11
+ * @returns {Hex} The encoded calldata.
12
+ */
5
13
  export function encodeCallsLA(calls) {
14
+ if (!calls.length) {
15
+ throw new BaseError("No calls to encode.");
16
+ }
6
17
  if (calls.length === 1) {
7
18
  return encodeFunctionData({
8
19
  abi: LightAccountAbi_v1,
@@ -23,6 +34,15 @@ export function encodeCallsLA(calls) {
23
34
  args: hasValue ? [targets, values, datas] : [targets, datas],
24
35
  });
25
36
  }
37
+ /**
38
+ * Decodes LightAccount calldata back into an array of calls.
39
+ * Used internally by the LightAccount SmartAccount implementation. Typically not needed
40
+ * directly unless you have an advanced use case.
41
+ *
42
+ * @param {Hex} data The calldata to decode.
43
+ * @param {Address} accountAddress The account address, used as the `to` for unrecognized selectors.
44
+ * @returns {Call[]} The decoded calls.
45
+ */
26
46
  export function decodeCallsLA(data, accountAddress) {
27
47
  const decoded = decodeFunctionData({
28
48
  abi: LightAccountAbi_v1,
@@ -1 +1 @@
1
- {"version":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EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;gBACjC,EAAE;gBACF,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;gBACpB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC;aACnB,CAAC,CAAC,CAAC;QACN,CAAC;QAED,8BAA8B;QAC9B,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;QAEtC,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;YACpC,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YACjC,EAAE;YACF,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC;SACnB,CAAC,CAAC,CAAC;IACN,CAAC;IAED,oEAAoE;IACpE,OAAO;QACL;YACE,EAAE,EAAE,cAAc;YAClB,IAAI;SACL;KACF,CAAC;AACJ,CAAC;AAED,2DAA2D;AAC3D,SAAS,iBAAiB,CACxB,KAEoE;IAEpE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import {\n decodeFunctionData,\n encodeFunctionData,\n type Address,\n type Call,\n type Hex,\n} from \"viem\";\nimport { LightAccountAbi_v1 } from \"../abis/LightAccountAbi_v1.js\";\nimport { BaseError } from \"@alchemy/common\";\n\n// Conveniently, all variants of LA up to v2.0.0 use the same function signatures for `execute` and `executeBatch`.\n\nexport function encodeCallsLA(calls: readonly Call[]): Hex {\n if (calls.length === 1) {\n return encodeFunctionData({\n abi: LightAccountAbi_v1,\n functionName: \"execute\",\n args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? \"0x\"],\n });\n }\n\n const [targets, values, datas, hasValue] = calls.reduce(\n (accum, curr) => {\n accum[0].push(curr.to);\n accum[1].push(curr.value ?? 0n);\n accum[2].push(curr.data ?? \"0x\");\n accum[3] = accum[3] || (curr.value ?? 0n) !== 0n;\n return accum;\n },\n [[], [], [], false] as [Address[], bigint[], Hex[], boolean],\n );\n\n return encodeFunctionData({\n abi: LightAccountAbi_v1,\n functionName: \"executeBatch\",\n args: hasValue ? [targets, values, datas] : [targets, datas],\n });\n}\n\nexport function decodeCallsLA(data: Hex, accountAddress: Address): Call[] {\n const decoded = decodeFunctionData({\n abi: LightAccountAbi_v1,\n data,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n data: decoded.args[2],\n ...(decoded.args[1] !== undefined ? { value: decoded.args[1] } : {}),\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n // This function is overloaded - may or may not have an array for values.\n\n if (isThreeTupleArray(decoded.args)) {\n const [targets, values, datas] = decoded.args;\n\n if (targets.length !== values.length || targets.length !== datas.length) {\n throw new BaseError(\"Invalid arguments for executeBatch\");\n }\n\n return targets.map((to, index) => ({\n to,\n value: values[index],\n data: datas[index],\n }));\n }\n\n // Two tuple array (no values)\n const [targets, datas] = decoded.args;\n\n if (targets.length !== datas.length) {\n throw new BaseError(\"Invalid arguments for executeBatch\");\n }\n\n return targets.map((to, index) => ({\n to,\n data: datas[index],\n }));\n }\n\n // Otherwise, treat the call as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n}\n\n// Needed to narrow types for LAv1 `executeBatch` function.\nfunction isThreeTupleArray(\n input:\n | readonly [readonly Address[], readonly Hex[]]\n | readonly [readonly Address[], readonly bigint[], readonly Hex[]],\n): input is readonly [readonly Address[], readonly bigint[], readonly Hex[]] {\n return input.length === 3;\n}\n"]}
1
+ {"version":3,"file":"calldataCodec.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/calldataCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAInB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;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ACjC,EAAE;gBACF,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;gBACpB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC;aACnB,CAAC,CAAC,CAAC;QACN,CAAC;QAED,8BAA8B;QAC9B,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;QAEtC,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;YACpC,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YACjC,EAAE;YACF,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC;SACnB,CAAC,CAAC,CAAC;IACN,CAAC;IAED,oEAAoE;IACpE,OAAO;QACL;YACE,EAAE,EAAE,cAAc;YAClB,IAAI;SACL;KACF,CAAC;AACJ,CAAC;AAED,2DAA2D;AAC3D,SAAS,iBAAiB,CACxB,KAEoE;IAEpE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import {\n decodeFunctionData,\n encodeFunctionData,\n type Address,\n type Call,\n type Hex,\n} from \"viem\";\nimport { LightAccountAbi_v1 } from \"../abis/LightAccountAbi_v1.js\";\nimport { BaseError } from \"@alchemy/common\";\n\n// Conveniently, all variants of LA up to v2.0.0 use the same function signatures for `execute` and `executeBatch`.\n\n/**\n * Encodes an array of calls into LightAccount calldata for `execute` or `executeBatch`.\n * Used internally by the LightAccount 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 encodeCallsLA(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: LightAccountAbi_v1,\n functionName: \"execute\",\n args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? \"0x\"],\n });\n }\n\n const [targets, values, datas, hasValue] = calls.reduce(\n (accum, curr) => {\n accum[0].push(curr.to);\n accum[1].push(curr.value ?? 0n);\n accum[2].push(curr.data ?? \"0x\");\n accum[3] = accum[3] || (curr.value ?? 0n) !== 0n;\n return accum;\n },\n [[], [], [], false] as [Address[], bigint[], Hex[], boolean],\n );\n\n return encodeFunctionData({\n abi: LightAccountAbi_v1,\n functionName: \"executeBatch\",\n args: hasValue ? [targets, values, datas] : [targets, datas],\n });\n}\n\n/**\n * Decodes LightAccount calldata back into an array of calls.\n * Used internally by the LightAccount 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 decodeCallsLA(data: Hex, accountAddress: Address): Call[] {\n const decoded = decodeFunctionData({\n abi: LightAccountAbi_v1,\n data,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n data: decoded.args[2],\n ...(decoded.args[1] !== undefined ? { value: decoded.args[1] } : {}),\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n // This function is overloaded - may or may not have an array for values.\n\n if (isThreeTupleArray(decoded.args)) {\n const [targets, values, datas] = decoded.args;\n\n if (targets.length !== values.length || targets.length !== datas.length) {\n throw new BaseError(\"Invalid arguments for executeBatch\");\n }\n\n return targets.map((to, index) => ({\n to,\n value: values[index],\n data: datas[index],\n }));\n }\n\n // Two tuple array (no values)\n const [targets, datas] = decoded.args;\n\n if (targets.length !== datas.length) {\n throw new BaseError(\"Invalid arguments for executeBatch\");\n }\n\n return targets.map((to, index) => ({\n to,\n data: datas[index],\n }));\n }\n\n // Otherwise, treat the call as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n}\n\n// Needed to narrow types for LAv1 `executeBatch` function.\nfunction isThreeTupleArray(\n input:\n | readonly [readonly Address[], readonly Hex[]]\n | readonly [readonly Address[], readonly bigint[], readonly Hex[]],\n): input is readonly [readonly Address[], readonly bigint[], readonly Hex[]] {\n return input.length === 3;\n}\n"]}
@@ -1,9 +1,9 @@
1
- import { encodeFunctionData, } from "viem";
1
+ import {} from "viem";
2
2
  import { entryPoint06Abi, toSmartAccount, entryPoint06Address, getUserOperationHash, } from "viem/account-abstraction";
3
- import { IStandardExecutorAbi } from "../abis/IStandardExecutor.js";
4
3
  import { signMessage, signTypedData } from "viem/actions";
5
- import { decodeFunctionData, getAction, hashMessage, hashTypedData, isAddressEqual, } from "viem/utils";
4
+ import { getAction, hashMessage, hashTypedData, isAddressEqual, } from "viem/utils";
6
5
  import { BaseError } from "@alchemy/common";
6
+ import { encodeCallsMAv1, decodeCallsMAv1 } from "./calldataCodec.js";
7
7
  /**
8
8
  * Creates a ModularAccountV1Base instance.
9
9
  *
@@ -36,9 +36,6 @@ export async function toModularAccountV1Base({ client, accountAddress, owner, ge
36
36
  return accountAddress;
37
37
  },
38
38
  async encodeCalls(calls) {
39
- if (!calls.length) {
40
- throw new BaseError("No calls to encode.");
41
- }
42
39
  if (calls.length === 1) {
43
40
  const call = calls[0];
44
41
  // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.
@@ -48,53 +45,12 @@ export async function toModularAccountV1Base({ client, accountAddress, owner, ge
48
45
  }
49
46
  return call.data;
50
47
  }
51
- return encodeFunctionData({
52
- abi: IStandardExecutorAbi,
53
- functionName: "execute",
54
- args: [call.to, call.value ?? 0n, call.data ?? "0x"],
55
- });
56
48
  }
57
- return encodeFunctionData({
58
- abi: IStandardExecutorAbi,
59
- functionName: "executeBatch",
60
- args: [
61
- calls.map((call) => ({
62
- target: call.to,
63
- value: call.value ?? 0n,
64
- data: call.data ?? "0x",
65
- })),
66
- ],
67
- });
49
+ return encodeCallsMAv1(calls);
68
50
  },
69
51
  // Inverse of `encodeCalls`.
70
52
  async decodeCalls(data) {
71
- const decoded = decodeFunctionData({
72
- abi: IStandardExecutorAbi,
73
- data,
74
- });
75
- if (decoded.functionName === "execute") {
76
- return [
77
- {
78
- to: decoded.args[0],
79
- value: decoded.args[1],
80
- data: decoded.args[2],
81
- },
82
- ];
83
- }
84
- if (decoded.functionName === "executeBatch") {
85
- return decoded.args[0].map((call) => ({
86
- to: call.target,
87
- value: call.value,
88
- data: call.data,
89
- }));
90
- }
91
- // If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.
92
- return [
93
- {
94
- to: accountAddress,
95
- data,
96
- },
97
- ];
53
+ return decodeCallsMAv1(data, accountAddress);
98
54
  },
99
55
  async getStubSignature() {
100
56
  return "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v1/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,kBAAkB,GACnB,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EACf,cAAc,EAEd,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAgC5C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAE1C,EACA,MAAM,EACN,cAAc,EACd,KAAK,EACL,cAAc,EACd,aAAa,EACb,IAAI,GACqC;IACzC,MAAM,UAAU,GAAG;QACjB,GAAG,EAAE,eAAe;QACpB,OAAO,EAAE,mBAAmB;QAC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AAK,EAAE,CAAC,CAAC;QACvD,CAAC;QAED,KAAK,CAAC,iBAAiB,CAAC,UAAU;YAChC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,aAAa,EAAE,GAAG,UAAU,CAAC;YACnE,MAAM,UAAU,GAAG,oBAAoB,CAAC;gBACtC,OAAO;gBACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,aAAa,EAAE;oBACb,GAAG,aAAa;oBAChB,MAAM,EAAE,cAAc;iBACvB;aACF,CAAC,CAAC;YAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YACxE,OAAO,iBAAiB,CAAC;gBACvB,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE;oBACP,GAAG,EAAE,UAAU;iBAChB;aACF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,IAAI;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type Hash,\n type TypedDataDefinition,\n encodeFunctionData,\n} from \"viem\";\nimport {\n entryPoint06Abi,\n toSmartAccount,\n type SmartAccountImplementation,\n entryPoint06Address,\n getUserOperationHash,\n} from \"viem/account-abstraction\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { IStandardExecutorAbi } from \"../abis/IStandardExecutor.js\";\nimport { signMessage, signTypedData } from \"viem/actions\";\nimport {\n decodeFunctionData,\n getAction,\n hashMessage,\n hashTypedData,\n isAddressEqual,\n} from \"viem/utils\";\nimport { BaseError } from \"@alchemy/common\";\n\ntype MaV1AccountType = \"MultiOwnerModularAccountV1\"; // Currently no SDK v5 support for \"MultiSigModularAccountV1\".\n\nexport type BaseMaV1AccountImplementation = SmartAccountImplementation<\n typeof entryPoint06Abi,\n \"0.6\",\n {\n smartAccountType: MaV1AccountType;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type ModularAccountV1Base =\n SmartAccountWithDecodeCalls<BaseMaV1AccountImplementation>;\n\nexport type ToModularAccountV1BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n get712Wrapper: (msg: Hash) => Promise<TypedDataDefinition>;\n type: MaV1AccountType;\n};\n\n/**\n * Creates a ModularAccountV1Base instance.\n *\n * @param {ToModularAccountV1BaseParams<TTransport>} params The parameters for creating a ModularAccountV1Base instance\n * @returns {Promise<ModularAccountV1Base>} A promise that resolves to a ModularAccountV1Base instance\n */\nexport async function toModularAccountV1Base<\n TTransport extends Transport = Transport,\n>({\n client,\n accountAddress,\n owner,\n getFactoryArgs,\n get712Wrapper,\n type,\n}: ToModularAccountV1BaseParams<TTransport>): Promise<ModularAccountV1Base> {\n const entryPoint = {\n abi: entryPoint06Abi,\n address: entryPoint06Address,\n version: \"0.6\" as const,\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const data = await get712Wrapper(\n params.type === \"personal_sign\"\n ? hashMessage(params.data)\n : hashTypedData(params.data),\n );\n return {\n type: \"eth_signTypedData_v4\",\n data,\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return signature;\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (!calls.length) {\n throw new BaseError(\"No calls to encode.\");\n }\n\n if (calls.length === 1) {\n const call = calls[0];\n\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n if (isAddressEqual(call.to, accountAddress)) {\n if (call.data == null) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return call.data;\n }\n\n return encodeFunctionData({\n abi: IStandardExecutorAbi,\n functionName: \"execute\",\n args: [call.to, call.value ?? 0n, call.data ?? \"0x\"],\n });\n }\n\n return encodeFunctionData({\n abi: IStandardExecutorAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n value: call.value ?? 0n,\n data: call.data ?? \"0x\",\n })),\n ],\n });\n },\n\n // Inverse of `encodeCalls`.\n async decodeCalls(data) {\n const decoded = decodeFunctionData({\n abi: IStandardExecutorAbi,\n data,\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, we treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n },\n\n async getStubSignature() {\n return \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n },\n\n async signMessage({ message }) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n return type === \"personal_sign\"\n ? signMessageAction({ account: owner, message: data })\n : signTypedDataAction({ ...data, account: owner });\n },\n\n async signTypedData(params) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition, // TODO(v5): try harder to avoid this cast?\n });\n return type === \"personal_sign\"\n ? signMessageAction({ account: owner, message: data })\n : signTypedDataAction({ ...data, account: owner });\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n const userOpHash = getUserOperationHash({\n chainId,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n return signMessageAction({\n account: owner,\n message: {\n raw: userOpHash,\n },\n });\n },\n\n extend: {\n smartAccountType: type,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v1/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAUN,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EACf,cAAc,EAEd,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACL,SAAS,EACT,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAgCtE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAE1C,EACA,MAAM,EACN,cAAc,EACd,KAAK,EACL,cAAc,EACd,aAAa,EACb,IAAI,GACqC;IACzC,MAAM,UAAU,GAAG;QACjB,GAAG,EAAE,eAAe;QACpB,OAAO,EAAE,mBAAmB;QAC5B,OAAO,EAAE,KAAc;KACxB,CAAC;IAEF,MAAM,gBAAgB,GAAG,KAAK,EAC5B,MAAwB,EACG,EAAE;QAC7B,MAAM,IAAI,GAAG,MAAM,aAAa,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,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,aAAa,EAAE;oBACb,GAAG,aAAa;oBAChB,MAAM,EAAE,cAAc;iBACvB;aACF,CAAC,CAAC;YAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YACxE,OAAO,iBAAiB,CAAC;gBACvB,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE;oBACP,GAAG,EAAE,UAAU;iBAChB;aACF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,IAAI;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type Hash,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n entryPoint06Abi,\n toSmartAccount,\n type SmartAccountImplementation,\n entryPoint06Address,\n getUserOperationHash,\n} from \"viem/account-abstraction\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { signMessage, signTypedData } from \"viem/actions\";\nimport {\n getAction,\n hashMessage,\n hashTypedData,\n isAddressEqual,\n} from \"viem/utils\";\nimport { BaseError } from \"@alchemy/common\";\nimport { encodeCallsMAv1, decodeCallsMAv1 } from \"./calldataCodec.js\";\n\ntype MaV1AccountType = \"MultiOwnerModularAccountV1\"; // Currently no SDK v5 support for \"MultiSigModularAccountV1\".\n\nexport type BaseMaV1AccountImplementation = SmartAccountImplementation<\n typeof entryPoint06Abi,\n \"0.6\",\n {\n smartAccountType: MaV1AccountType;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type ModularAccountV1Base =\n SmartAccountWithDecodeCalls<BaseMaV1AccountImplementation>;\n\nexport type ToModularAccountV1BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n get712Wrapper: (msg: Hash) => Promise<TypedDataDefinition>;\n type: MaV1AccountType;\n};\n\n/**\n * Creates a ModularAccountV1Base instance.\n *\n * @param {ToModularAccountV1BaseParams<TTransport>} params The parameters for creating a ModularAccountV1Base instance\n * @returns {Promise<ModularAccountV1Base>} A promise that resolves to a ModularAccountV1Base instance\n */\nexport async function toModularAccountV1Base<\n TTransport extends Transport = Transport,\n>({\n client,\n accountAddress,\n owner,\n getFactoryArgs,\n get712Wrapper,\n type,\n}: ToModularAccountV1BaseParams<TTransport>): Promise<ModularAccountV1Base> {\n const entryPoint = {\n abi: entryPoint06Abi,\n address: entryPoint06Address,\n version: \"0.6\" as const,\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const data = await get712Wrapper(\n params.type === \"personal_sign\"\n ? hashMessage(params.data)\n : hashTypedData(params.data),\n );\n return {\n type: \"eth_signTypedData_v4\",\n data,\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return signature;\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\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 the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n if (isAddressEqual(call.to, accountAddress)) {\n if (call.data == null) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return call.data;\n }\n }\n\n return encodeCallsMAv1(calls);\n },\n\n // Inverse of `encodeCalls`.\n async decodeCalls(data) {\n return decodeCallsMAv1(data, accountAddress);\n },\n\n async getStubSignature() {\n return \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n },\n\n async signMessage({ message }) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n return type === \"personal_sign\"\n ? signMessageAction({ account: owner, message: data })\n : signTypedDataAction({ ...data, account: owner });\n },\n\n async signTypedData(params) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition, // TODO(v5): try harder to avoid this cast?\n });\n return type === \"personal_sign\"\n ? signMessageAction({ account: owner, message: data })\n : signTypedDataAction({ ...data, account: owner });\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n const userOpHash = getUserOperationHash({\n chainId,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n return signMessageAction({\n account: owner,\n message: {\n raw: userOpHash,\n },\n });\n },\n\n extend: {\n smartAccountType: type,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import { type Address, type Call, type Hex } from "viem";
2
+ /**
3
+ * Encodes an array of calls into ModularAccountV1 calldata for `execute` or `executeBatch`.
4
+ * Used internally by the ModularAccountV1 SmartAccount implementation. Typically not needed
5
+ * directly unless you have an advanced use case.
6
+ *
7
+ * @param {Call[]} calls The calls to encode.
8
+ * @returns {Hex} The encoded calldata.
9
+ */
10
+ export declare function encodeCallsMAv1(calls: readonly Call[]): Hex;
11
+ /**
12
+ * Decodes ModularAccountV1 calldata back into an array of calls.
13
+ * Used internally by the ModularAccountV1 SmartAccount implementation. Typically not needed
14
+ * directly unless you have an advanced use case.
15
+ *
16
+ * @param {Hex} data The calldata to decode.
17
+ * @param {Address} accountAddress The account address, used as the `to` for unrecognized selectors.
18
+ * @returns {Call[]} The decoded calls.
19
+ */
20
+ export declare function decodeCallsMAv1(data: Hex, accountAddress: Address): Call[];
@@ -0,0 +1,73 @@
1
+ import { decodeFunctionData, encodeFunctionData, } from "viem";
2
+ import { IStandardExecutorAbi } from "../abis/IStandardExecutor.js";
3
+ import { BaseError } from "@alchemy/common";
4
+ /**
5
+ * Encodes an array of calls into ModularAccountV1 calldata for `execute` or `executeBatch`.
6
+ * Used internally by the ModularAccountV1 SmartAccount implementation. Typically not needed
7
+ * directly unless you have an advanced use case.
8
+ *
9
+ * @param {Call[]} calls The calls to encode.
10
+ * @returns {Hex} The encoded calldata.
11
+ */
12
+ export function encodeCallsMAv1(calls) {
13
+ if (!calls.length) {
14
+ throw new BaseError("No calls to encode.");
15
+ }
16
+ if (calls.length === 1) {
17
+ return encodeFunctionData({
18
+ abi: IStandardExecutorAbi,
19
+ functionName: "execute",
20
+ args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? "0x"],
21
+ });
22
+ }
23
+ return encodeFunctionData({
24
+ abi: IStandardExecutorAbi,
25
+ functionName: "executeBatch",
26
+ args: [
27
+ calls.map((call) => ({
28
+ target: call.to,
29
+ value: call.value ?? 0n,
30
+ data: call.data ?? "0x",
31
+ })),
32
+ ],
33
+ });
34
+ }
35
+ /**
36
+ * Decodes ModularAccountV1 calldata back into an array of calls.
37
+ * Used internally by the ModularAccountV1 SmartAccount implementation. Typically not needed
38
+ * directly unless you have an advanced use case.
39
+ *
40
+ * @param {Hex} data The calldata to decode.
41
+ * @param {Address} accountAddress The account address, used as the `to` for unrecognized selectors.
42
+ * @returns {Call[]} The decoded calls.
43
+ */
44
+ export function decodeCallsMAv1(data, accountAddress) {
45
+ const decoded = decodeFunctionData({
46
+ abi: IStandardExecutorAbi,
47
+ data,
48
+ });
49
+ if (decoded.functionName === "execute") {
50
+ return [
51
+ {
52
+ to: decoded.args[0],
53
+ value: decoded.args[1],
54
+ data: decoded.args[2],
55
+ },
56
+ ];
57
+ }
58
+ if (decoded.functionName === "executeBatch") {
59
+ return decoded.args[0].map((call) => ({
60
+ to: call.target,
61
+ value: call.value,
62
+ data: call.data,
63
+ }));
64
+ }
65
+ // If the data is not for an `execute` or `executeBatch` call, treat it as a single call to the account itself.
66
+ return [
67
+ {
68
+ to: accountAddress,
69
+ data,
70
+ },
71
+ ];
72
+ }
73
+ //# sourceMappingURL=calldataCodec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calldataCodec.js","sourceRoot":"","sources":["../../../../src/ma-v1/accounts/calldataCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAInB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,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,oBAAoB;YACzB,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,oBAAoB;QACzB,YAAY,EAAE,cAAc;QAC5B,IAAI,EAAE;YACJ,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBACnB,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;gBACvB,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI;aACxB,CAAC,CAAC;SACJ;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,IAAS,EAAE,cAAuB;IAChE,MAAM,OAAO,GAAG,kBAAkB,CAAC;QACjC,GAAG,EAAE,oBAAoB;QACzB,IAAI;KACL,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO;YACL;gBACE,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;gBACnB,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;gBACtB,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;aACtB;SACF,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,YAAY,KAAK,cAAc,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACpC,EAAE,EAAE,IAAI,CAAC,MAAM;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,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 { IStandardExecutorAbi } from \"../abis/IStandardExecutor.js\";\nimport { BaseError } from \"@alchemy/common\";\n\n/**\n * Encodes an array of calls into ModularAccountV1 calldata for `execute` or `executeBatch`.\n * Used internally by the ModularAccountV1 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 encodeCallsMAv1(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: IStandardExecutorAbi,\n functionName: \"execute\",\n args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? \"0x\"],\n });\n }\n\n return encodeFunctionData({\n abi: IStandardExecutorAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n value: call.value ?? 0n,\n data: call.data ?? \"0x\",\n })),\n ],\n });\n}\n\n/**\n * Decodes ModularAccountV1 calldata back into an array of calls.\n * Used internally by the ModularAccountV1 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 decodeCallsMAv1(data: Hex, accountAddress: Address): Call[] {\n const decoded = decodeFunctionData({\n abi: IStandardExecutorAbi,\n data,\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,10 +1,10 @@
1
- import { concat, concatHex, encodeFunctionData, hashMessage, hashTypedData, maxUint32, maxUint152, zeroAddress, } from "viem";
1
+ import { concat, concatHex, hashMessage, hashTypedData, maxUint32, maxUint152, zeroAddress, } from "viem";
2
2
  import { entryPoint07Abi, entryPoint07Address, getUserOperationHash, toSmartAccount, } from "viem/account-abstraction";
3
3
  import { getCode, readContract, signMessage, signTypedData, } from "viem/actions";
4
4
  import { assertNever, BaseError } from "@alchemy/common";
5
5
  import { SignaturePrefix, } from "../types.js";
6
6
  import { modularAccountAbi } from "../abis/modularAccountAbi.js";
7
- import { decodeFunctionData, getAction, isAddressEqual, sliceHex, } from "viem/utils";
7
+ import { getAction, isAddressEqual } from "viem/utils";
8
8
  import { DEFAULT_OWNER_ENTITY_ID, DefaultModuleAddress, EXECUTE_USER_OP_SELECTOR, serializeModuleEntity, } from "../utils/account.js";
9
9
  import { parseDeferredAction } from "../utils/deferredActions.js";
10
10
  import { pack1271Signature, toReplaySafeTypedData, packUOSignature, } from "../utils/signature.js";
@@ -12,6 +12,7 @@ import { InvalidDeferredActionNonceError } from "../../errors/InvalidDeferredAct
12
12
  import { InvalidNonceKeyError } from "../../errors/InvalidNonceKeyError.js";
13
13
  import { InvalidEntityIdError } from "../../errors/InvalidEntityIdError.js";
14
14
  import { is7702Delegated } from "../../utils.js";
15
+ import { encodeCallsMAv2, decodeCallsMAv2 } from "./calldataCodec.js";
15
16
  /**
16
17
  * Creates a ModularAccountV2Base instance.
17
18
  *
@@ -191,64 +192,16 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
191
192
  const call = calls[0];
192
193
  if (isAddressEqual(call.to, accountAddress)) {
193
194
  // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.
194
- if (call.data === undefined) {
195
+ if (call.data == null) {
195
196
  throw new BaseError("Data is required for an account self-call.");
196
197
  }
197
198
  return encodeCallData(call.data);
198
199
  }
199
- return encodeCallData(encodeFunctionData({
200
- abi: modularAccountAbi,
201
- functionName: "execute",
202
- args: [call.to, call.value ?? 0n, call.data ?? "0x"],
203
- }));
204
200
  }
205
- return encodeCallData(encodeFunctionData({
206
- abi: modularAccountAbi,
207
- functionName: "executeBatch",
208
- args: [
209
- calls.map((call) => ({
210
- target: call.to,
211
- data: call.data ?? "0x",
212
- value: call.value ?? 0n,
213
- })),
214
- ],
215
- }));
201
+ return encodeCallData(encodeCallsMAv2(calls));
216
202
  },
217
203
  async decodeCalls(data) {
218
- // Inverse of `encodeCalls`.
219
- // Trim the EXECUTE_USER_OP_SELECTOR if it is present.
220
- const trimmedData = data
221
- .toLowerCase()
222
- .startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())
223
- ? sliceHex(data, 4)
224
- : data;
225
- const decoded = decodeFunctionData({
226
- abi: modularAccountAbi,
227
- data: trimmedData,
228
- });
229
- if (decoded.functionName === "execute") {
230
- return [
231
- {
232
- to: decoded.args[0],
233
- value: decoded.args[1],
234
- data: decoded.args[2],
235
- },
236
- ];
237
- }
238
- if (decoded.functionName === "executeBatch") {
239
- return decoded.args[0].map((call) => ({
240
- to: call.target,
241
- value: call.value,
242
- data: call.data,
243
- }));
244
- }
245
- // If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.
246
- return [
247
- {
248
- to: accountAddress,
249
- data,
250
- },
251
- ];
204
+ return decodeCallsMAv2(data, accountAddress);
252
205
  },
253
206
  async getStubSignature() {
254
207
  const sig = packUOSignature({
@@ -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,kBAAkB,EAClB,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,E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,CAAC,KAAK,CAAC,EAAE;gBACtC,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,aAAa,EAAE;oBACb,GAAG,EAAE;oBACL,MAAM,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 encodeFunctionData,\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 {\n decodeFunctionData,\n getAction,\n isAddressEqual,\n sliceHex,\n} 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\";\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 === undefined) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return encodeCallData(call.data);\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [call.to, call.value ?? 0n, call.data ?? \"0x\"],\n }),\n );\n }\n\n return encodeCallData(\n 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 async decodeCalls(data) {\n // Inverse of `encodeCalls`.\n // Trim the EXECUTE_USER_OP_SELECTOR if it is 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, we treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\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;AACzD,OAAO,EACL,eAAe,GAIhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EAAE,SAAS,EAAE,c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AExE,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, // 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"]}