@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
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @alchemy/smart-accounts
2
2
 
3
+ **Beta** — This package replaces `@account-kit/smart-contracts`. This is a low-level package. Most users should use [`@alchemy/wallet-apis`](https://www.alchemy.com/docs/wallets/reference/wallet-apis) unless you need to use interface with Smart Accounts directly via viem.
4
+
3
5
  Viem-compatible smart account implementations for Alchemy's smart contract accounts. Supports LightAccount, Modular Account v1, and Modular Account v2 with EIP-7702.
4
6
 
5
7
  ## Installation
@@ -8,6 +10,49 @@ Viem-compatible smart account implementations for Alchemy's smart contract accou
8
10
  npm install @alchemy/smart-accounts @alchemy/common viem
9
11
  ```
10
12
 
13
+ ## Example Usage
14
+
15
+ ```ts
16
+ import { createPublicClient } from "viem";
17
+ import {
18
+ createBundlerClient,
19
+ createPaymasterClient,
20
+ } from "viem/account-abstraction";
21
+ import { sepolia } from "viem/chains";
22
+ import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
23
+ import { alchemyTransport } from "@alchemy/common";
24
+ import { estimateFeesPerGas } from "@alchemy/aa-infra";
25
+ import { toModularAccountV2 } from "@alchemy/smart-accounts";
26
+
27
+ const transport = alchemyTransport({ apiKey: "YOUR_API_KEY" });
28
+
29
+ // 1. Create a MAv2 smart account
30
+ const account = await toModularAccountV2({
31
+ client: createPublicClient({ chain: sepolia, transport }),
32
+ owner: privateKeyToAccount(generatePrivateKey()),
33
+ });
34
+
35
+ // 2. Create a bundler client with the account
36
+ const bundlerClient = createBundlerClient({
37
+ account,
38
+ chain: sepolia,
39
+ transport,
40
+ userOperation: {
41
+ estimateFeesPerGas,
42
+ },
43
+ // Optional: sponsor gas with a paymaster
44
+ paymaster: createPaymasterClient({ transport }),
45
+ paymasterContext: { policyId: "YOUR_POLICY_ID" },
46
+ });
47
+
48
+ // 3. Send a user operation
49
+ const hash = await bundlerClient.sendUserOperation({
50
+ calls: [{ to: "0x...", value: 0n, data: "0x" }],
51
+ });
52
+
53
+ const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
54
+ ```
55
+
11
56
  ## Key Exports
12
57
 
13
58
  ### LightAccount
@@ -15,12 +60,10 @@ npm install @alchemy/smart-accounts @alchemy/common viem
15
60
  - **`toLightAccount`** - Single-owner LightAccount
16
61
  - **`toMultiOwnerLightAccount`** - Multi-owner variant
17
62
  - **`predictLightAccountAddress`** / **`predictMultiOwnerLightAccountAddress`** - Counterfactual address prediction
18
- - **`singleOwnerLightAccountActions`** / **`multiOwnerLightAccountActions`** - Client decorators
19
63
 
20
64
  ### Modular Account v1 (ERC-6900)
21
65
 
22
66
  - **`toMultiOwnerModularAccountV1`** - Account constructor
23
- - **`multiOwnerModularAccountV1Actions`** - Client decorator
24
67
  - **`predictMultiOwnerModularAccountV1Address`** - Address prediction
25
68
 
26
69
  ### Modular Account v2
@@ -3,10 +3,6 @@ export type * from "./light-account/accounts/account.js";
3
3
  export { toLightAccount } from "./light-account/accounts/account.js";
4
4
  export type * from "./light-account/accounts/multi-owner-account.js";
5
5
  export { toMultiOwnerLightAccount } from "./light-account/accounts/multi-owner-account.js";
6
- export type * from "./light-account/decorators/singleOwner.js";
7
- export { singleOwnerLightAccountActions } from "./light-account/decorators/singleOwner.js";
8
- export type * from "./light-account/decorators/multiOwner.js";
9
- export { multiOwnerLightAccountActions } from "./light-account/decorators/multiOwner.js";
10
6
  export type * from "./light-account/predictAddress.js";
11
7
  export { predictLightAccountAddress, predictMultiOwnerLightAccountAddress, } from "./light-account/predictAddress.js";
12
8
  export { AccountVersionRegistry } from "./light-account/registry.js";
@@ -18,8 +14,6 @@ export type * from "./ma-v1/accounts/base.js";
18
14
  export { toModularAccountV1Base } from "./ma-v1/accounts/base.js";
19
15
  export type * from "./ma-v1/accounts/multi-owner-account.js";
20
16
  export { toMultiOwnerModularAccountV1 } from "./ma-v1/accounts/multi-owner-account.js";
21
- export type * from "./ma-v1/decorators/multiOwner.js";
22
- export { multiOwnerModularAccountV1Actions } from "./ma-v1/decorators/multiOwner.js";
23
17
  export type * from "./ma-v1/predictAddress.js";
24
18
  export { predictMultiOwnerModularAccountV1Address } from "./ma-v1/predictAddress.js";
25
19
  export { multiOwnerModularAccountStaticImpl } from "./ma-v1/mav1StaticImpl.js";
@@ -49,7 +43,7 @@ export type * from "./ma-v2/types.js";
49
43
  export type * from "./ma-v2/utils/account.js";
50
44
  export { DefaultAddress, DefaultModuleAddress, DEFAULT_OWNER_ENTITY_ID, EXECUTE_USER_OP_SELECTOR, getMAV2UpgradeToData, buildFullNonceKey, serializeModuleEntity, isModularAccountV2, } from "./ma-v2/utils/account.js";
51
45
  export type * from "./ma-v2/utils/deferredActions.js";
52
- export { parseDeferredAction, buildDeferredActionDigest, } from "./ma-v2/utils/deferredActions.js";
46
+ export { parseDeferredAction, encodeDeferredActionWithSignature, } from "./ma-v2/utils/deferredActions.js";
53
47
  export type * from "./ma-v2/utils/hooks.js";
54
48
  export { serializeValidationConfig, serializeHookConfig, } from "./ma-v2/utils/hooks.js";
55
49
  export type * from "./ma-v2/utils/signature.js";
package/dist/esm/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  export { toLightAccount } from "./light-account/accounts/account.js";
2
2
  export { toMultiOwnerLightAccount } from "./light-account/accounts/multi-owner-account.js";
3
- export { singleOwnerLightAccountActions } from "./light-account/decorators/singleOwner.js";
4
- export { multiOwnerLightAccountActions } from "./light-account/decorators/multiOwner.js";
5
3
  export { predictLightAccountAddress, predictMultiOwnerLightAccountAddress, } from "./light-account/predictAddress.js";
6
4
  export { AccountVersionRegistry } from "./light-account/registry.js";
7
5
  export { defaultLightAccountVersion, getLightAccountImplAddress, LightAccountUnsupported1271Factories, LightAccountUnsupported1271Impls, } from "./light-account/utils.js";
@@ -9,7 +7,6 @@ export { encodeCallsLA, decodeCallsLA, } from "./light-account/accounts/calldata
9
7
  export { lightAccountStaticImplV1_0_1, lightAccountStaticImplV1_0_2, lightAccountStaticImplV1_1_0, lightAccountStaticImplV2_0_0, multiOwnerLightAccountStaticImplV2_0_0, } from "./light-account/lightAccountStaticImpl.js";
10
8
  export { toModularAccountV1Base } from "./ma-v1/accounts/base.js";
11
9
  export { toMultiOwnerModularAccountV1 } from "./ma-v1/accounts/multi-owner-account.js";
12
- export { multiOwnerModularAccountV1Actions } from "./ma-v1/decorators/multiOwner.js";
13
10
  export { predictMultiOwnerModularAccountV1Address } from "./ma-v1/predictAddress.js";
14
11
  export { multiOwnerModularAccountStaticImpl } from "./ma-v1/mav1StaticImpl.js";
15
12
  export { DefaultMaV1Address, DefaultMaV1PluginAddress, } from "./ma-v1/account.js";
@@ -29,7 +26,7 @@ export { TimeRangeModule } from "./ma-v2/modules/time-range-module/module.js";
29
26
  export { PermissionBuilder, PermissionType, } from "./ma-v2/permissionBuilder.js";
30
27
  export { predictModularAccountV2Address } from "./ma-v2/predictAddress.js";
31
28
  export { DefaultAddress, DefaultModuleAddress, DEFAULT_OWNER_ENTITY_ID, EXECUTE_USER_OP_SELECTOR, getMAV2UpgradeToData, buildFullNonceKey, serializeModuleEntity, isModularAccountV2, } from "./ma-v2/utils/account.js";
32
- export { parseDeferredAction, buildDeferredActionDigest, } from "./ma-v2/utils/deferredActions.js";
29
+ export { parseDeferredAction, encodeDeferredActionWithSignature, } from "./ma-v2/utils/deferredActions.js";
33
30
  export { serializeValidationConfig, serializeHookConfig, } from "./ma-v2/utils/hooks.js";
34
31
  export { packUOSignature, pack1271Signature, toReplaySafeTypedData, } from "./ma-v2/utils/signature.js";
35
32
  // Errors
@@ -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,aAAa,EACb,aAAa,GACd,MAAM,2CAA2C,CAAC;AAEnD,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;AAE5B,OAAO,EACL,eAAe,EACf,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAI3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,O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AiB,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
+ {"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;AAG3F,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,aAAa,EACb,aAAa,GACd,MAAM,2CAA2C,CAAC;AAEnD,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,wCAAwC,EAAE,MAAM,2BAA2B,CAAC;AAErF,OAAO,EAAE,kCAAkC,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,eAAe,EACf,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAI3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EACL,eAAe,EACf,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAGxE,OAAO,EAAE,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AAoB,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\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/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 encodeDeferredActionWithSignature,\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"]}
@@ -15,7 +15,6 @@ export async function toLightAccountBase({ client, abi, accountAddress, owner, t
15
15
  const encodeUpgradeToAndCall = async ({ upgradeToAddress, upgradeToInitData, }) => {
16
16
  const expectedImplAddresses = Object.values(AccountVersionRegistry[type]).map((x) => x.accountImplementation);
17
17
  const getStorageAtAction = getAction(client, getStorageAt, "getStorageAt");
18
- // TODO(v5): This is a super fragile workflow, and we should consider not supporting this on the SmartAccount level in v5.
19
18
  const storage = await getStorageAtAction({
20
19
  address: accountAddress,
21
20
  slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/base.ts"],"names":[],"mapp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AAE,KAAK;wBACd,OAAO,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE;qBAC7B,CAAC,CAAC;oBACH,MAAM;gBACR,KAAK,QAAQ,CAAC;gBACd,KAAK,QAAQ;oBACX,MAAM,mBAAmB,GAAG,SAAS,CACnC,MAAM,EACN,aAAa,EACb,eAAe,CAChB,CAAC;oBAEF,SAAS,GAAG,MAAM,mBAAmB,CAAC;wBACpC,OAAO,EAAE,KAAK;wBACd,GAAG,yBAAyB,CAAC;4BAC3B,OAAO;4BACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;4BACrC,aAAa,EAAE;gCACb,GAAG,aAAa;gCAChB,MAAM,EAAE,cAAc;6BACvB;yBACF,CAAC;qBACH,CAAC,CAAC;oBACH,MAAM;gBACR;oBACE,MAAM,IAAI,SAAS,CAAC,mBAAmB,IAAI,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACzE,CAAC;YAED,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,IAAI;YACtB,sBAAsB,EAAE,GAAG,EAAE,CAAC,OAAO;YACrC,sBAAsB;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n concatHex,\n encodeFunctionData,\n fromHex,\n hashMessage,\n hashTypedData,\n trim,\n type Abi,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n getUserOperationHash,\n getUserOperationTypedData,\n toSmartAccount,\n type SmartAccountImplementation,\n} from \"viem/account-abstraction\";\nimport { getStorageAt, signMessage, signTypedData } from \"viem/actions\";\nimport type {\n EntryPointFromAccountRegistry,\n LightAccountType,\n LightAccountVersion,\n} from \"../registry.js\";\nimport { EIP1967_PROXY_IMPL_STORAGE_SLOT } from \"../utils.js\";\nimport { AccountVersionRegistry, isLightAccountVersion2 } from \"../registry.js\";\nimport {\n encodeCallsLA as encodeCalls,\n decodeCallsLA as decodeCalls,\n} from \"./calldataCodec.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport type {\n SignatureRequest,\n StaticSmartAccountImplementation,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { getAction } from \"viem/utils\";\n\nconst SignaturePrefix = {\n EOA: \"0x00\",\n CONTRACT: \"0x01\",\n CONTRACT_WITH_ADDR: \"0x02\",\n} as const;\n\nexport type BaseLightAccountImplementation<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountImplementation<\n EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>[\"abi\"],\n EntryPointFromAccountRegistry<\n TLightAccountType,\n TLightAccountVersion\n >[\"version\"],\n {\n getLightAccountVersion: () => TLightAccountVersion;\n smartAccountType: TLightAccountType;\n encodeUpgradeToAndCall: (params: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }) => Promise<Hex>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type LightAccountBase<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountWithDecodeCalls<\n BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>\n>;\n\nexport type ToLightAccountBaseParams<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n abi: Abi;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n type: TLightAccountType;\n version: TLightAccountVersion;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n};\n\nexport async function toLightAccountBase<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n>({\n client,\n abi,\n accountAddress,\n owner,\n type,\n version,\n getFactoryArgs,\n}: ToLightAccountBaseParams<\n TLightAccountType,\n TLightAccountVersion,\n TTransport\n>): Promise<LightAccountBase<TLightAccountType, TLightAccountVersion>> {\n const encodeUpgradeToAndCall = async ({\n upgradeToAddress,\n upgradeToInitData,\n }: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }): Promise<Hex> => {\n const expectedImplAddresses = (\n Object.values(\n AccountVersionRegistry[type],\n ) as StaticSmartAccountImplementation<false>[]\n ).map((x) => x.accountImplementation);\n\n const getStorageAtAction = getAction(client, getStorageAt, \"getStorageAt\");\n // TODO(v5): This is a super fragile workflow, and we should consider not supporting this on the SmartAccount level in v5.\n const storage = await getStorageAtAction({\n address: accountAddress,\n slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,\n });\n\n if (storage == null) {\n throw new BaseError(\n `Failed to get storage slot: ${EIP1967_PROXY_IMPL_STORAGE_SLOT}`,\n );\n }\n\n // Only upgrade undeployed accounts (storage 0) or deployed light accounts, else error.\n if (\n fromHex(storage, \"number\") !== 0 &&\n !expectedImplAddresses.some((x) => x === lowerAddress(trim(storage)))\n ) {\n throw new BaseError(\n `could not determine if smart account implementation is ${type} ${String(\n version,\n )}`,\n );\n }\n\n return encodeFunctionData({\n abi,\n functionName: \"upgradeToAndCall\",\n args: [upgradeToAddress, upgradeToInitData],\n });\n };\n\n const get1271Wrapper = (\n hashedMessage: Hex,\n version: string,\n ): TypedDataDefinition => {\n return {\n // EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\n // https://github.com/alchemyplatform/light-account/blob/main/src/LightAccount.sol#L236\n domain: {\n chainId: client.chain.id,\n name: type,\n verifyingContract: accountAddress,\n version,\n },\n types: {\n LightAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: hashedMessage,\n },\n primaryType: \"LightAccountMessage\",\n };\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const messageHash =\n params.type === \"eth_signTypedData_v4\"\n ? hashTypedData(params.data)\n : hashMessage(params.data);\n\n switch (version) {\n case \"v1.0.1\":\n return params;\n case \"v1.0.2\":\n throw new BaseError(\n `Version ${String(version)} of LightAccount doesn't support 1271`,\n );\n case \"v1.1.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"1\"),\n };\n case \"v2.0.0\":\n case \"v2.1.0\":\n case \"v2.2.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"2\"),\n };\n default:\n throw new BaseError(\n `Unknown version ${String(version)} of LightAccount`,\n );\n }\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return isLightAccountVersion2(\n version as LightAccountVersion<\"LightAccount\">,\n )\n ? concatHex([SignaturePrefix.EOA, signature])\n : signature;\n };\n\n const entryPoint = (\n AccountVersionRegistry[type][version] as StaticSmartAccountImplementation\n ).entryPoint;\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 return encodeCalls(calls);\n },\n\n async decodeCalls(data) {\n return decodeCalls(data, accountAddress);\n },\n\n async getStubSignature() {\n const signature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n return signature;\n case \"v2.0.0\":\n case \"v2.1.0\":\n case \"v2.2.0\":\n return concatHex([SignaturePrefix.EOA, signature]);\n default:\n throw new BaseError(`Unknown version ${type} of ${String(version)}`);\n }\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\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\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\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n let signature: Hex;\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n case \"v2.0.0\":\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(\n client,\n signMessage,\n \"signMessage\",\n );\n\n signature = await signMessageAction({\n account: owner,\n message: { raw: userOpHash },\n });\n break;\n case \"v2.1.0\":\n case \"v2.2.0\":\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n signature = await signTypedDataAction({\n account: owner,\n ...getUserOperationTypedData({\n chainId,\n entryPointAddress: entryPoint.address,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n }),\n });\n break;\n default:\n throw new BaseError(`Unknown version ${type} of ${String(version)}`);\n }\n\n return formatSignature(signature);\n },\n\n extend: {\n smartAccountType: type,\n getLightAccountVersion: () => version,\n encodeUpgradeToAndCall,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,aAAa,EACb,IAAI,GAUL,MAAM,MAAM,CAAC;AACd,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAMxE,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EACL,aAAa,IAAI,WAAW,EAC5B,aAAa,IAAI,WAAW,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,MAAM;IACX,QAAQ,EAAE,MAAM;IAChB,kBAAkB,EAAE,MAAM;CAClB,CAAC;AAmDX,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAKtC,EACA,MAAM,EACN,GAAG,EACH,cAAc,EACd,KAAK,EACL,IAAI,EACJ,OAAO,EACP,cAAc,GAKf;IACC,MAAM,sBAAsB,GAAG,KAAK,EAAE,EACpC,gBAAgB,EAChB,iBAAiB,GAIlB,EAAgB,EAAE;QACjB,MAAM,qBAAqB,GACzB,MAAM,CAAC,MAAM,CACX,sBAAsB,CAAC,IAAI,CAAC,CAE/B,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC;QAEtC,MAAM,kBAAkB,GA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M,iBAAiB,GAAG,SAAS,CACjC,MAAM,EACN,WAAW,EACX,aAAa,CACd,CAAC;oBAEF,SAAS,GAAG,MAAM,iBAAiB,CAAC;wBAClC,OAAO,EAAE,KAAK;wBACd,OAAO,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE;qBAC7B,CAAC,CAAC;oBACH,MAAM;gBACR,KAAK,QAAQ,CAAC;gBACd,KAAK,QAAQ;oBACX,MAAM,mBAAmB,GAAG,SAAS,CACnC,MAAM,EACN,aAAa,EACb,eAAe,CAChB,CAAC;oBAEF,SAAS,GAAG,MAAM,mBAAmB,CAAC;wBACpC,OAAO,EAAE,KAAK;wBACd,GAAG,yBAAyB,CAAC;4BAC3B,OAAO;4BACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;4BACrC,aAAa,EAAE;gCACb,GAAG,aAAa;gCAChB,MAAM,EAAE,cAAc;6BACvB;yBACF,CAAC;qBACH,CAAC,CAAC;oBACH,MAAM;gBACR;oBACE,MAAM,IAAI,SAAS,CAAC,mBAAmB,IAAI,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACzE,CAAC;YAED,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,IAAI;YACtB,sBAAsB,EAAE,GAAG,EAAE,CAAC,OAAO;YACrC,sBAAsB;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n concatHex,\n encodeFunctionData,\n fromHex,\n hashMessage,\n hashTypedData,\n trim,\n type Abi,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n getUserOperationHash,\n getUserOperationTypedData,\n toSmartAccount,\n type SmartAccountImplementation,\n} from \"viem/account-abstraction\";\nimport { getStorageAt, signMessage, signTypedData } from \"viem/actions\";\nimport type {\n EntryPointFromAccountRegistry,\n LightAccountType,\n LightAccountVersion,\n} from \"../registry.js\";\nimport { EIP1967_PROXY_IMPL_STORAGE_SLOT } from \"../utils.js\";\nimport { AccountVersionRegistry, isLightAccountVersion2 } from \"../registry.js\";\nimport {\n encodeCallsLA as encodeCalls,\n decodeCallsLA as decodeCalls,\n} from \"./calldataCodec.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport type {\n SignatureRequest,\n StaticSmartAccountImplementation,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { getAction } from \"viem/utils\";\n\nconst SignaturePrefix = {\n EOA: \"0x00\",\n CONTRACT: \"0x01\",\n CONTRACT_WITH_ADDR: \"0x02\",\n} as const;\n\nexport type BaseLightAccountImplementation<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountImplementation<\n EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>[\"abi\"],\n EntryPointFromAccountRegistry<\n TLightAccountType,\n TLightAccountVersion\n >[\"version\"],\n {\n getLightAccountVersion: () => TLightAccountVersion;\n smartAccountType: TLightAccountType;\n encodeUpgradeToAndCall: (params: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }) => Promise<Hex>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type LightAccountBase<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountWithDecodeCalls<\n BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>\n>;\n\nexport type ToLightAccountBaseParams<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n abi: Abi;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n type: TLightAccountType;\n version: TLightAccountVersion;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n};\n\nexport async function toLightAccountBase<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n>({\n client,\n abi,\n accountAddress,\n owner,\n type,\n version,\n getFactoryArgs,\n}: ToLightAccountBaseParams<\n TLightAccountType,\n TLightAccountVersion,\n TTransport\n>): Promise<LightAccountBase<TLightAccountType, TLightAccountVersion>> {\n const encodeUpgradeToAndCall = async ({\n upgradeToAddress,\n upgradeToInitData,\n }: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }): Promise<Hex> => {\n const expectedImplAddresses = (\n Object.values(\n AccountVersionRegistry[type],\n ) as StaticSmartAccountImplementation<false>[]\n ).map((x) => x.accountImplementation);\n\n const getStorageAtAction = getAction(client, getStorageAt, \"getStorageAt\");\n const storage = await getStorageAtAction({\n address: accountAddress,\n slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,\n });\n\n if (storage == null) {\n throw new BaseError(\n `Failed to get storage slot: ${EIP1967_PROXY_IMPL_STORAGE_SLOT}`,\n );\n }\n\n // Only upgrade undeployed accounts (storage 0) or deployed light accounts, else error.\n if (\n fromHex(storage, \"number\") !== 0 &&\n !expectedImplAddresses.some((x) => x === lowerAddress(trim(storage)))\n ) {\n throw new BaseError(\n `could not determine if smart account implementation is ${type} ${String(\n version,\n )}`,\n );\n }\n\n return encodeFunctionData({\n abi,\n functionName: \"upgradeToAndCall\",\n args: [upgradeToAddress, upgradeToInitData],\n });\n };\n\n const get1271Wrapper = (\n hashedMessage: Hex,\n version: string,\n ): TypedDataDefinition => {\n return {\n // EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\n // https://github.com/alchemyplatform/light-account/blob/main/src/LightAccount.sol#L236\n domain: {\n chainId: client.chain.id,\n name: type,\n verifyingContract: accountAddress,\n version,\n },\n types: {\n LightAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: hashedMessage,\n },\n primaryType: \"LightAccountMessage\",\n };\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const messageHash =\n params.type === \"eth_signTypedData_v4\"\n ? hashTypedData(params.data)\n : hashMessage(params.data);\n\n switch (version) {\n case \"v1.0.1\":\n return params;\n case \"v1.0.2\":\n throw new BaseError(\n `Version ${String(version)} of LightAccount doesn't support 1271`,\n );\n case \"v1.1.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"1\"),\n };\n case \"v2.0.0\":\n case \"v2.1.0\":\n case \"v2.2.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"2\"),\n };\n default:\n throw new BaseError(\n `Unknown version ${String(version)} of LightAccount`,\n );\n }\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return isLightAccountVersion2(\n version as LightAccountVersion<\"LightAccount\">,\n )\n ? concatHex([SignaturePrefix.EOA, signature])\n : signature;\n };\n\n const entryPoint = (\n AccountVersionRegistry[type][version] as StaticSmartAccountImplementation\n ).entryPoint;\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 return encodeCalls(calls);\n },\n\n async decodeCalls(data) {\n return decodeCalls(data, accountAddress);\n },\n\n async getStubSignature() {\n const signature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n return signature;\n case \"v2.0.0\":\n case \"v2.1.0\":\n case \"v2.2.0\":\n return concatHex([SignaturePrefix.EOA, signature]);\n default:\n throw new BaseError(`Unknown version ${type} of ${String(version)}`);\n }\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\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\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\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n let signature: Hex;\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n case \"v2.0.0\":\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(\n client,\n signMessage,\n \"signMessage\",\n );\n\n signature = await signMessageAction({\n account: owner,\n message: { raw: userOpHash },\n });\n break;\n case \"v2.1.0\":\n case \"v2.2.0\":\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n signature = await signTypedDataAction({\n account: owner,\n ...getUserOperationTypedData({\n chainId,\n entryPointAddress: entryPoint.address,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n }),\n });\n break;\n default:\n throw new BaseError(`Unknown version ${type} of ${String(version)}`);\n }\n\n return formatSignature(signature);\n },\n\n extend: {\n smartAccountType: type,\n getLightAccountVersion: () => version,\n encodeUpgradeToAndCall,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
@@ -11,9 +11,6 @@ import { BaseError } from "@alchemy/common";
11
11
  * @returns {Hex} The encoded calldata.
12
12
  */
13
13
  export function encodeCallsLA(calls) {
14
- if (!calls.length) {
15
- throw new BaseError("No calls to encode.");
16
- }
17
14
  if (calls.length === 1) {
18
15
  return encodeFunctionData({
19
16
  abi: LightAccountAbi_v1,
@@ -1 +1 @@
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;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,mHAAmH;AAEnH;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAsB;IAClD,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,kBAAkB;YACvB,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,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,MAAM,CACrD,CAAC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AAO,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
+ {"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;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,mHAAmH;AAEnH;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAsB;IAClD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,kBAAkB,CAAC;YACxB,GAAG,EAAE,kBAAkB;YACvB,YAAY,EAAE,SAAS;YACvB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC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E;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 === 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"]}
@@ -3,11 +3,6 @@ import { hexToNumber, trim } from "viem";
3
3
  import { getStorageAt } from "viem/actions";
4
4
  import { getAction } from "viem/utils";
5
5
  import { AccountVersionRegistry } from "./registry.js";
6
- // TODO(v5): The pattern of getDefaultXYZAddress(…) doesn’t really make sense as a standalone.
7
- // We built this expecting lots of diverging addresses per chain, but in practice we have none
8
- // (and we’ve turned down things that require this). Instead: we could build the
9
- // default-but-overridable behavior into the consuming functions themselves (i.e.
10
- // createLightAccount defaulting to a factory address, but make it overridable)
11
6
  /**
12
7
  * Get the default light account version for the given light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G,OAAO,CAAC,sBAAsB,EAAE,CAAC;IACjD,MAAM,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAEtC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAC3E,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAC/B,CAAC;IAEF,MAAM,kBAAkB,GAAG,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;IAE3E,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC;QACvC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,+BAA+B;KACtC,CAAC,CAAC;IAEH,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,SAAS,CACjB,+BAA+B,+BAA+B,EAAE,CACjE,CAAC;IACJ,CAAC;IAED,IACE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1B,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EACrE,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,0DAA0D,IAAI,IAAI,MAAM,CACtE,OAAO,CACR,EAAE,CACJ,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { BaseError, ChainNotFoundError, lowerAddress } from \"@alchemy/common\";\nimport { hexToNumber, trim, type Address } from \"viem\";\nimport { getStorageAt } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\nimport type { LightAccountBase } from \"./accounts/base.js\";\nimport type { LightAccountType, LightAccountVersion } from \"./registry.js\";\nimport { AccountVersionRegistry } from \"./registry.js\";\n\n// TODO(v5): The pattern of getDefaultXYZAddress(…) doesn’t really make sense as a standalone.\n// We built this expecting lots of diverging addresses per chain, but in practice we have none\n// (and we’ve turned down things that require this). Instead: we could build the\n// default-but-overridable behavior into the consuming functions themselves (i.e.\n// createLightAccount defaulting to a factory address, but make it overridable)\n\n/**\n * Get the default light account version for the given light account type\n *\n * @template {LightAccountType} TLightAccountType\n * @returns {LightAccountVersion<TLightAccountType>} the default version for the given light account type\n */\nexport const defaultLightAccountVersion = <\n TLightAccountType extends LightAccountType,\n>(): LightAccountVersion<TLightAccountType> => \"v2.0.0\";\n\n/**\n * Can be used to check if the account with one of the following implementation addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Impls = [\n AccountVersionRegistry.LightAccount[\"v1.0.1\"],\n AccountVersionRegistry.LightAccount[\"v1.0.2\"],\n];\n\n/**\n * Can be used to check if the account with one of the following factory addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Factories = new Set(\n LightAccountUnsupported1271Impls.map((x) => [x.factoryAddress]).flat(),\n);\n\nexport const EIP1967_PROXY_IMPL_STORAGE_SLOT =\n \"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc\";\n\n/**\n * Get the light account implementation address for the given light account\n *\n * @param {LightAccountBase} account - the light account to get the implementation address for\n * @returns {Promise<Address>} the light account implementation address for the given light account\n */\nexport async function getLightAccountImplAddress<\n TAccount extends LightAccountBase,\n>(account: TAccount): Promise<Address> {\n const client = account.client;\n const chain = client.chain;\n if (!chain) {\n throw new ChainNotFoundError();\n }\n const version = account.getLightAccountVersion();\n const type = account.smartAccountType;\n\n const expectedImplAddresses = Object.values(AccountVersionRegistry[type]).map(\n (x) => x.accountImplementation,\n );\n\n const getStorageAtAction = getAction(client, getStorageAt, \"getStorageAt\");\n\n const storage = await getStorageAtAction({\n address: account.address,\n slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,\n });\n\n if (storage == null) {\n throw new BaseError(\n `Failed to get storage slot: ${EIP1967_PROXY_IMPL_STORAGE_SLOT}`,\n );\n }\n\n if (\n hexToNumber(storage) !== 0 &&\n !expectedImplAddresses.some((x) => x === lowerAddress(trim(storage)))\n ) {\n throw new BaseError(\n `could not determine if smart account implementation is ${type} ${String(\n version,\n )}`,\n );\n }\n\n return trim(storage);\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/light-account/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAEE,EAAE,CAAC,QAAQ,CAAC;AAExD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC9C,sBAAsB,CAAC,YAAY,CAAC,QAAQ,CAAC;IAC7C,sBAAsB,CAAC,YAAY,CAAC,QAAQ,CAAC;CAC9C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,IAAI,GAAG,CACzD,gCAAgC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,EAAE,CACvE,CAAC;AAEF,MAAM,CAAC,MAAM,+BAA+B,GAC1C,oEAAoE,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAE9C,OAAiB;IACjB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;IACjD,MAAM,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAEtC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAC3E,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAC/B,CAAC;IAEF,MAAM,kBAAkB,GAAG,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;IAE3E,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC;QACvC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,+BAA+B;KACtC,CAAC,CAAC;IAEH,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,SAAS,CACjB,+BAA+B,+BAA+B,EAAE,CACjE,CAAC;IACJ,CAAC;IAED,IACE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1B,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EACrE,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,0DAA0D,IAAI,IAAI,MAAM,CACtE,OAAO,CACR,EAAE,CACJ,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { BaseError, ChainNotFoundError, lowerAddress } from \"@alchemy/common\";\nimport { hexToNumber, trim, type Address } from \"viem\";\nimport { getStorageAt } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\nimport type { LightAccountBase } from \"./accounts/base.js\";\nimport type { LightAccountType, LightAccountVersion } from \"./registry.js\";\nimport { AccountVersionRegistry } from \"./registry.js\";\n\n/**\n * Get the default light account version for the given light account type\n *\n * @template {LightAccountType} TLightAccountType\n * @returns {LightAccountVersion<TLightAccountType>} the default version for the given light account type\n */\nexport const defaultLightAccountVersion = <\n TLightAccountType extends LightAccountType,\n>(): LightAccountVersion<TLightAccountType> => \"v2.0.0\";\n\n/**\n * Can be used to check if the account with one of the following implementation addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Impls = [\n AccountVersionRegistry.LightAccount[\"v1.0.1\"],\n AccountVersionRegistry.LightAccount[\"v1.0.2\"],\n];\n\n/**\n * Can be used to check if the account with one of the following factory addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Factories = new Set(\n LightAccountUnsupported1271Impls.map((x) => [x.factoryAddress]).flat(),\n);\n\nexport const EIP1967_PROXY_IMPL_STORAGE_SLOT =\n \"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc\";\n\n/**\n * Get the light account implementation address for the given light account\n *\n * @param {LightAccountBase} account - the light account to get the implementation address for\n * @returns {Promise<Address>} the light account implementation address for the given light account\n */\nexport async function getLightAccountImplAddress<\n TAccount extends LightAccountBase,\n>(account: TAccount): Promise<Address> {\n const client = account.client;\n const chain = client.chain;\n if (!chain) {\n throw new ChainNotFoundError();\n }\n const version = account.getLightAccountVersion();\n const type = account.smartAccountType;\n\n const expectedImplAddresses = Object.values(AccountVersionRegistry[type]).map(\n (x) => x.accountImplementation,\n );\n\n const getStorageAtAction = getAction(client, getStorageAt, \"getStorageAt\");\n\n const storage = await getStorageAtAction({\n address: account.address,\n slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,\n });\n\n if (storage == null) {\n throw new BaseError(\n `Failed to get storage slot: ${EIP1967_PROXY_IMPL_STORAGE_SLOT}`,\n );\n }\n\n if (\n hexToNumber(storage) !== 0 &&\n !expectedImplAddresses.some((x) => x === lowerAddress(trim(storage)))\n ) {\n throw new BaseError(\n `could not determine if smart account implementation is ${type} ${String(\n version,\n )}`,\n );\n }\n\n return trim(storage);\n}\n"]}
@@ -71,7 +71,7 @@ export async function toModularAccountV1Base({ client, accountAddress, owner, ge
71
71
  const signTypedDataAction = getAction(client, signTypedData, "signTypedData");
72
72
  const { type, data } = await prepareSignature({
73
73
  type: "eth_signTypedData_v4",
74
- data: params, // TODO(v5): try harder to avoid this cast?
74
+ data: params,
75
75
  });
76
76
  return type === "personal_sign"
77
77
  ? signMessageAction({ account: owner, message: data })
@@ -1 +1 @@
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,CAC9B,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B,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"]}
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,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AC;YACH,OAAO,IAAI,KAAK,eAAe;gBAC7B,CAAC,CAAC,iBAAiB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBACtD,CAAC,CAAC,mBAAmB,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,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} 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,\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,6 +1,5 @@
1
1
  import { decodeFunctionData, encodeFunctionData, } from "viem";
2
2
  import { IStandardExecutorAbi } from "../abis/IStandardExecutor.js";
3
- import { BaseError } from "@alchemy/common";
4
3
  /**
5
4
  * Encodes an array of calls into ModularAccountV1 calldata for `execute` or `executeBatch`.
6
5
  * Used internally by the ModularAccountV1 SmartAccount implementation. Typically not needed
@@ -10,9 +9,6 @@ import { BaseError } from "@alchemy/common";
10
9
  * @returns {Hex} The encoded calldata.
11
10
  */
12
11
  export function encodeCallsMAv1(calls) {
13
- if (!calls.length) {
14
- throw new BaseError("No calls to encode.");
15
- }
16
12
  if (calls.length === 1) {
17
13
  return encodeFunctionData({
18
14
  abi: IStandardExecutorAbi,
@@ -1 +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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FunctionData,\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
+ {"version":3,"file":"calldataCodec.js","sourceRoot":"","sources":["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AC,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\";\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 === 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"]}
@@ -9,7 +9,5 @@ export type MultiOwnerModularAccountV1FactoryArgs = {
9
9
  };
10
10
  /**
11
11
  * Static implementation logic for ModularAccountV1.
12
- *
13
- * TODO(v5): update JSDoc format when doc-gen supports structs or records.
14
12
  */
15
13
  export declare const multiOwnerModularAccountStaticImpl: StaticSmartAccountImplementation<false, "0.6", MultiOwnerModularAccountV1FactoryArgs, typeof entryPoint06Abi, typeof UpgradeableModularAccountAbi, typeof MultiOwnerModularAccountFactoryAbi>;
@@ -7,8 +7,6 @@ import { DefaultMaV1Address } from "./account.js";
7
7
  import { predictMultiOwnerModularAccountV1Address } from "./predictAddress.js";
8
8
  /**
9
9
  * Static implementation logic for ModularAccountV1.
10
- *
11
- * TODO(v5): update JSDoc format when doc-gen supports structs or records.
12
10
  */
13
11
  export const multiOwnerModularAccountStaticImpl = {
14
12
  entryPoint: {
@@ -1 +1 @@
1
- {"version":3,"file":"mav1StaticImpl.js","sourceRoot":"","sources":["../../../src/ma-v1/mav1StaticImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,kBAAkB,EAAE,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,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;AAC/F,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,wCAAwC,EAAE,MAAM,qBAAqB,CAAC;AAO/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAO3C;IACF,UAAU,EAAE;QACV,GAAG,EAAE,eAAe;QACpB,OAAO,EAAE,mBAAmB;QAC5B,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE,4BAA4B;IACxC,UAAU,EAAE,kCAAkC;IAC9C,cAAc,EAAE,CAAC,WAAkD,EAAE,EAAE;QACrE,OAAO,kBAAkB,CAAC;YACxB,GAAG,EAAE,kCAAkC;YACvC,YAAY,EAAE,eAAe;YAC7B,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;IACD,qBAAqB,EAAE,YAAY,CACjC,kBAAkB,CAAC,sBAAsB,CAC1C;IACD,cAAc,EAAE,YAAY,CAAC,kBAAkB,CAAC,wBAAwB,CAAC;IACzE,qBAAqB,EAAE,CAAC,IAAI,EAAE,EAAE;QAC9B,OAAO,wCAAwC,CAAC;YAC9C,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,cAAc,EAAE,IAAI,CAAC,MAAM;YAC3B,cAAc,EAAE,kBAAkB,CAAC,wBAAwB;SAC5D,CAAC,CAAC;IACL,CAAC;CACF,CAAC","sourcesContent":["import { type Address, encodeFunctionData } from \"viem\";\nimport { entryPoint06Abi, entryPoint06Address } from \"viem/account-abstraction\";\nimport { lowerAddress } from \"@alchemy/common\";\nimport type { StaticSmartAccountImplementation } from \"../types\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"./abis/MultiOwnerModularAccountFactory.js\";\nimport { UpgradeableModularAccountAbi } from \"./abis/UpgradeableModularAccount.js\";\nimport { DefaultMaV1Address } from \"./account.js\";\nimport { predictMultiOwnerModularAccountV1Address } from \"./predictAddress.js\";\n\nexport type MultiOwnerModularAccountV1FactoryArgs = {\n owners: Address[];\n salt: bigint;\n};\n\n/**\n * Static implementation logic for ModularAccountV1.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const multiOwnerModularAccountStaticImpl: StaticSmartAccountImplementation<\n false,\n \"0.6\",\n MultiOwnerModularAccountV1FactoryArgs,\n typeof entryPoint06Abi,\n typeof UpgradeableModularAccountAbi,\n typeof MultiOwnerModularAccountFactoryAbi\n> = {\n entryPoint: {\n abi: entryPoint06Abi,\n address: entryPoint06Address,\n version: \"0.6\",\n },\n accountAbi: UpgradeableModularAccountAbi,\n factoryAbi: MultiOwnerModularAccountFactoryAbi,\n getFactoryData: (factoryArgs: MultiOwnerModularAccountV1FactoryArgs) => {\n return encodeFunctionData({\n abi: MultiOwnerModularAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [factoryArgs.salt, factoryArgs.owners],\n });\n },\n accountImplementation: lowerAddress(\n DefaultMaV1Address.IMPLEMENTATION_ADDRESS,\n ),\n factoryAddress: lowerAddress(DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY),\n predictAccountAddress: (args) => {\n return predictMultiOwnerModularAccountV1Address({\n salt: args.salt,\n ownerAddresses: args.owners,\n factoryAddress: DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n });\n },\n};\n"]}
1
+ {"version":3,"file":"mav1StaticImpl.js","sourceRoot":"","sources":["../../../src/ma-v1/mav1StaticImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,kBAAkB,EAAE,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,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;AAC/F,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,wCAAwC,EAAE,MAAM,qBAAqB,CAAC;AAO/E;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAO3C;IACF,UAAU,EAAE;QACV,GAAG,EAAE,eAAe;QACpB,OAAO,EAAE,mBAAmB;QAC5B,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE,4BAA4B;IACxC,UAAU,EAAE,kCAAkC;IAC9C,cAAc,EAAE,CAAC,WAAkD,EAAE,EAAE;QACrE,OAAO,kBAAkB,CAAC;YACxB,GAAG,EAAE,kCAAkC;YACvC,YAAY,EAAE,eAAe;YAC7B,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC;SAC7C,CAAC,CAAC;IACL,CAAC;IACD,qBAAqB,EAAE,YAAY,CACjC,kBAAkB,CAAC,sBAAsB,CAC1C;IACD,cAAc,EAAE,YAAY,CAAC,kBAAkB,CAAC,wBAAwB,CAAC;IACzE,qBAAqB,EAAE,CAAC,IAAI,EAAE,EAAE;QAC9B,OAAO,wCAAwC,CAAC;YAC9C,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,cAAc,EAAE,IAAI,CAAC,MAAM;YAC3B,cAAc,EAAE,kBAAkB,CAAC,wBAAwB;SAC5D,CAAC,CAAC;IACL,CAAC;CACF,CAAC","sourcesContent":["import { type Address, encodeFunctionData } from \"viem\";\nimport { entryPoint06Abi, entryPoint06Address } from \"viem/account-abstraction\";\nimport { lowerAddress } from \"@alchemy/common\";\nimport type { StaticSmartAccountImplementation } from \"../types\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"./abis/MultiOwnerModularAccountFactory.js\";\nimport { UpgradeableModularAccountAbi } from \"./abis/UpgradeableModularAccount.js\";\nimport { DefaultMaV1Address } from \"./account.js\";\nimport { predictMultiOwnerModularAccountV1Address } from \"./predictAddress.js\";\n\nexport type MultiOwnerModularAccountV1FactoryArgs = {\n owners: Address[];\n salt: bigint;\n};\n\n/**\n * Static implementation logic for ModularAccountV1.\n */\nexport const multiOwnerModularAccountStaticImpl: StaticSmartAccountImplementation<\n false,\n \"0.6\",\n MultiOwnerModularAccountV1FactoryArgs,\n typeof entryPoint06Abi,\n typeof UpgradeableModularAccountAbi,\n typeof MultiOwnerModularAccountFactoryAbi\n> = {\n entryPoint: {\n abi: entryPoint06Abi,\n address: entryPoint06Address,\n version: \"0.6\",\n },\n accountAbi: UpgradeableModularAccountAbi,\n factoryAbi: MultiOwnerModularAccountFactoryAbi,\n getFactoryData: (factoryArgs: MultiOwnerModularAccountV1FactoryArgs) => {\n return encodeFunctionData({\n abi: MultiOwnerModularAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [factoryArgs.salt, factoryArgs.owners],\n });\n },\n accountImplementation: lowerAddress(\n DefaultMaV1Address.IMPLEMENTATION_ADDRESS,\n ),\n factoryAddress: lowerAddress(DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY),\n predictAccountAddress: (args) => {\n return predictMultiOwnerModularAccountV1Address({\n salt: args.salt,\n ownerAddresses: args.owners,\n factoryAddress: DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n });\n },\n};\n"]}
@@ -30,6 +30,45 @@ export type ToModularAccountV2Params<TMode extends Mode | undefined = Mode | und
30
30
  *
31
31
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
32
32
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { createPublicClient } from "viem";
37
+ * import { createBundlerClient, createPaymasterClient } from "viem/account-abstraction";
38
+ * import { sepolia } from "viem/chains";
39
+ * import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
40
+ * import { alchemyTransport } from "@alchemy/common";
41
+ * import { estimateFeesPerGas } from "@alchemy/aa-infra";
42
+ * import { toModularAccountV2 } from "@alchemy/smart-accounts";
43
+ *
44
+ * const transport = alchemyTransport({ apiKey: "YOUR_API_KEY" });
45
+ *
46
+ * // 1. Create a MAv2 smart account
47
+ * const account = await toModularAccountV2({
48
+ * client: createPublicClient({ chain: sepolia, transport }),
49
+ * owner: privateKeyToAccount(generatePrivateKey()),
50
+ * });
51
+ *
52
+ * // 2. Create a bundler client with the account
53
+ * const bundlerClient = createBundlerClient({
54
+ * account,
55
+ * chain: sepolia,
56
+ * transport,
57
+ * userOperation: {
58
+ * estimateFeesPerGas,
59
+ * },
60
+ * // Optional: sponsor gas with a paymaster
61
+ * paymaster: createPaymasterClient({ transport }),
62
+ * paymasterContext: { policyId: "YOUR_POLICY_ID" },
63
+ * });
64
+ *
65
+ * // 3. Send a user operation
66
+ * const hash = await bundlerClient.sendUserOperation({
67
+ * calls: [{ to: "0x...", value: 0n, data: "0x" }],
68
+ * });
69
+ *
70
+ * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
71
+ * ```
33
72
  */
34
73
  export declare function toModularAccountV2<TMode extends Mode = Mode>({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt, factory, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2>;
35
74
  export {};
@@ -12,6 +12,45 @@ import { LOGGER } from "../../logger.js";
12
12
  *
13
13
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
14
14
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { createPublicClient } from "viem";
19
+ * import { createBundlerClient, createPaymasterClient } from "viem/account-abstraction";
20
+ * import { sepolia } from "viem/chains";
21
+ * import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
22
+ * import { alchemyTransport } from "@alchemy/common";
23
+ * import { estimateFeesPerGas } from "@alchemy/aa-infra";
24
+ * import { toModularAccountV2 } from "@alchemy/smart-accounts";
25
+ *
26
+ * const transport = alchemyTransport({ apiKey: "YOUR_API_KEY" });
27
+ *
28
+ * // 1. Create a MAv2 smart account
29
+ * const account = await toModularAccountV2({
30
+ * client: createPublicClient({ chain: sepolia, transport }),
31
+ * owner: privateKeyToAccount(generatePrivateKey()),
32
+ * });
33
+ *
34
+ * // 2. Create a bundler client with the account
35
+ * const bundlerClient = createBundlerClient({
36
+ * account,
37
+ * chain: sepolia,
38
+ * transport,
39
+ * userOperation: {
40
+ * estimateFeesPerGas,
41
+ * },
42
+ * // Optional: sponsor gas with a paymaster
43
+ * paymaster: createPaymasterClient({ transport }),
44
+ * paymasterContext: { policyId: "YOUR_POLICY_ID" },
45
+ * });
46
+ *
47
+ * // 3. Send a user operation
48
+ * const hash = await bundlerClient.sendUserOperation({
49
+ * calls: [{ to: "0x...", value: 0n, data: "0x" }],
50
+ * });
51
+ *
52
+ * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
53
+ * ```
15
54
  */
16
55
  export async function toModularAccountV2({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt = 0n, factory, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }) {
17
56
  const is7702 = mode === "7702";
@@ -109,7 +148,7 @@ export async function toModularAccountV2({ client, owner, deferredAction, signer
109
148
  });
110
149
  return {
111
150
  ...base,
112
- // TODO(v5): does this need to be extended w/ any more methods like LightAccount does?
151
+ // This may be extended in the future with additional MAv2-specific methods.
113
152
  };
114
153
  }
115
154
  //# sourceMappingURL=account.js.map