@alchemy/smart-accounts 5.0.0-beta.23 → 5.0.0-beta.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
@@ -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";
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GASnB,MAAM,MAAM,CAAC;AACd,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAE9E,OAAO,EACL,yCAAyC,EACzC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqCzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAA4B,EAClE,MAAM,EACN,KAAK,EACL,cAAc,EACd,YAAY,EACZ,cAAc,EAAE,eAAe,EAC/B,IAAI,GAAG,EAAE,EACT,OAAO,EACP,WAAW,EAAE,YAAY,EACzB,qBAAqB,EAAE,sBAAsB,EAC7C,IAAI,GAC4B;IAChC,MAAM,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC;IAE/B,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;QACvC,SAAS,EAAE,KAAK,CAAC,IAAI;QACrB,IAAI;QACJ,iBAAiB,EAAE,CAAC,CAAC,cAAc;QACnC,iBAAiB,EAAE,CAAC,CAAC,eAAe;KACrC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,YAAY,EAAE,QAAQ,IAAI,uBAAuB,CAAC;IAEnE,MAAM,cAAc,G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,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAC7C,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC3B,MAAM,CAAC,KAAK,CAAC,uCAAuC,EAAE;gBACpD,SAAS,EAAE,KAAK,CAAC,IAAI;aACtB,CAAC,CAAC;YACH,MAAM,IAAI,iBAAiB,CACzB,iBAAiB,KAAK,CAAC,IAAI,gCAAgC,CAC5D,CAAC;QACJ,CAAC;QACD,IAAI,KAAK,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;YACpC,MAAM,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAC7D,MAAM,IAAI,iBAAiB,CACzB,qEAAqE,CACtE,CAAC;QACJ,CAAC;QACD,IACE,QAAQ,KAAK,uBAAuB;YACpC,KAAK,CAAC,OAAO,KAAK,cAAc,EAChC,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;YACtD,MAAM,IAAI,qBAAqB,EAAE,CAAC;QACpC,CAAC;QACD,aAAa,GAAG;YACd,iEAAiE;YACjE,+DAA+D;YAC/D,wCAAwC;YACxC,OAAO,EAAE,KAA0B;YACnC,OAAO,EAAE,cAAc,CAAC,UAAU;SACnC,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,sBAAsB,CAAC;QACxC,MAAM;QACN,KAAK;QACL,cAAc;QACd,cAAc;QACd,YAAY;QACZ,cAAc;QACd,aAAa;KACd,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,4EAA4E;KAC7E,CAAC;AACJ,CAAC","sourcesContent":["import {\n encodeFunctionData,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type PrivateKeyAccount,\n type Transport,\n} from \"viem\";\nimport {\n type ToSmartAccountParameters,\n entryPoint07Address,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport {\n getModularAccountV2AddressFromFactoryData,\n predictModularAccountV2Address,\n} from \"../predictAddress.js\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport { InvalidOwnerError } from \"../../errors/InvalidOwnerError.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from \"../utils/account.js\";\nimport { LOGGER } from \"../../logger.js\";\n\ntype Mode = \"default\" | \"7702\";\n\n// This may be extended in the future with additional MAv2-specific methods.\nexport type ModularAccountV2 = ModularAccountV2Base & {};\n\nexport type ToModularAccountV2Params<\n TMode extends Mode | undefined = Mode | undefined,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n accountAddress?: Address;\n mode?: TMode;\n} & (TMode extends \"7702\"\n ? {\n salt?: never;\n factory?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n factory?: Address;\n implementationAddress?: Address;\n } & (\n | {\n salt?: bigint;\n factoryData?: never;\n }\n | {\n salt?: never;\n factoryData?: Hex;\n }\n ));\n\n/**\n * Creates a MAv2 account.\n *\n * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.\n * @returns {Promise<ModularAccountV2>} A MAv2 account.\n */\nexport async function toModularAccountV2<TMode extends Mode = Mode>({\n client,\n owner,\n deferredAction,\n signerEntity,\n accountAddress: accountAddress_,\n salt = 0n,\n factory,\n factoryData: factoryData_,\n implementationAddress: implementationAddress_,\n mode,\n}: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2> {\n const is7702 = mode === \"7702\";\n\n LOGGER.debug(\"toModularAccountV2:start\", {\n ownerType: owner.type,\n mode,\n hasDeferredAction: !!deferredAction,\n hasAccountAddress: !!accountAddress_,\n });\n\n const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;\n\n const factoryAddress = factory ?? DefaultAddress.MAV2_FACTORY;\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702 ? DefaultAddress.SMAV2_7702 : DefaultAddress.SMAV2_BYTECODE);\n\n const getFactoryArgs = async () => {\n if (is7702) {\n // This is only for EP 0.8.0.\n // return {\n // factory: \"0x7702\",\n // factoryData: \"0x\",\n // } as const;\n return {\n factory: undefined,\n factoryData: undefined,\n } as const;\n }\n\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [owner.address, salt],\n }),\n };\n };\n\n const accountAddress =\n accountAddress_ ??\n (is7702\n ? owner.address\n : factoryData_\n ? await getModularAccountV2AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData: factoryData_,\n implementationAddress,\n entryPoint: {\n version: \"0.7\",\n address: entryPoint07Address,\n },\n })\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n type: \"SMA\",\n ownerAddress: owner.address,\n }));\n\n LOGGER.debug(\"toModularAccountV2:address-resolved\", {\n accountAddress,\n is7702,\n });\n\n let authorization: ToSmartAccountParameters[\"authorization\"];\n if (is7702) {\n LOGGER.debug(\"toModularAccountV2:7702-mode\");\n if (owner.type !== \"local\") {\n LOGGER.error(\"toModularAccountV2:invalid-owner-type\", {\n ownerType: owner.type,\n });\n throw new InvalidOwnerError(\n `Owner of type ${owner.type} is unsupported for 7702 mode.`,\n );\n }\n if (owner.signAuthorization == null) {\n LOGGER.error(\"toModularAccountV2:missing-signAuthorization\");\n throw new InvalidOwnerError(\n \"Owner must implement `signAuthorization` to be used with 7702 mode.\",\n );\n }\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n owner.address !== accountAddress\n ) {\n LOGGER.error(\"toModularAccountV2:entity-id-override\");\n throw new EntityIdOverrideError();\n }\n authorization = {\n // The current version of Viem has some pretty strict constraints\n // on a `PrivateKeyAccount`, but this seems safe as long as the\n // owner is able to `signAuthorization`.\n account: owner as PrivateKeyAccount,\n address: DefaultAddress.SMAV2_7702,\n };\n }\n\n const base = await toModularAccountV2Base({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity,\n deferredAction,\n authorization,\n });\n\n return {\n ...base,\n // This may be extended in the future with additional MAv2-specific methods.\n };\n}\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GASnB,MAAM,MAAM,CAAC;AACd,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAE9E,OAAO,EACL,yCAAyC,EACzC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqCzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAA4B,EAClE,MAAM,EACN,KAAK,EACL,cAAc,EACd,YAAY,EACZ,cAAc,EAAE,eAAe,EAC/B,IAAI,GAAG,EAAE,EACT,OAAO,EACP,WAAW,EAAE,YAAY,EACzB,qBAAqB,EAAE,sBAAsB,EAC7C,IAAI,GAC4B;IAChC,MAAM,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC;IAE/B,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;QACvC,SAAS,EAAE,KAAK,CAAC,IAAI;QACrB,IAA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Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type PrivateKeyAccount,\n type Transport,\n} from \"viem\";\nimport {\n type ToSmartAccountParameters,\n entryPoint07Address,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport {\n getModularAccountV2AddressFromFactoryData,\n predictModularAccountV2Address,\n} from \"../predictAddress.js\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport { InvalidOwnerError } from \"../../errors/InvalidOwnerError.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from \"../utils/account.js\";\nimport { LOGGER } from \"../../logger.js\";\n\ntype Mode = \"default\" | \"7702\";\n\n// This may be extended in the future with additional MAv2-specific methods.\nexport type ModularAccountV2 = ModularAccountV2Base & {};\n\nexport type ToModularAccountV2Params<\n TMode extends Mode | undefined = Mode | undefined,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n accountAddress?: Address;\n mode?: TMode;\n} & (TMode extends \"7702\"\n ? {\n salt?: never;\n factory?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n factory?: Address;\n implementationAddress?: Address;\n } & (\n | {\n salt?: bigint;\n factoryData?: never;\n }\n | {\n salt?: never;\n factoryData?: Hex;\n }\n ));\n\n/**\n * Creates a MAv2 account.\n *\n * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.\n * @returns {Promise<ModularAccountV2>} A MAv2 account.\n *\n * @example\n * ```ts\n * import { createPublicClient } from \"viem\";\n * import { createBundlerClient, createPaymasterClient } from \"viem/account-abstraction\";\n * import { sepolia } from \"viem/chains\";\n * import { generatePrivateKey, privateKeyToAccount } from \"viem/accounts\";\n * import { alchemyTransport } from \"@alchemy/common\";\n * import { estimateFeesPerGas } from \"@alchemy/aa-infra\";\n * import { toModularAccountV2 } from \"@alchemy/smart-accounts\";\n *\n * const transport = alchemyTransport({ apiKey: \"YOUR_API_KEY\" });\n *\n * // 1. Create a MAv2 smart account\n * const account = await toModularAccountV2({\n * client: createPublicClient({ chain: sepolia, transport }),\n * owner: privateKeyToAccount(generatePrivateKey()),\n * });\n *\n * // 2. Create a bundler client with the account\n * const bundlerClient = createBundlerClient({\n * account,\n * chain: sepolia,\n * transport,\n * userOperation: {\n * estimateFeesPerGas,\n * },\n * // Optional: sponsor gas with a paymaster\n * paymaster: createPaymasterClient({ transport }),\n * paymasterContext: { policyId: \"YOUR_POLICY_ID\" },\n * });\n *\n * // 3. Send a user operation\n * const hash = await bundlerClient.sendUserOperation({\n * calls: [{ to: \"0x...\", value: 0n, data: \"0x\" }],\n * });\n *\n * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });\n * ```\n */\nexport async function toModularAccountV2<TMode extends Mode = Mode>({\n client,\n owner,\n deferredAction,\n signerEntity,\n accountAddress: accountAddress_,\n salt = 0n,\n factory,\n factoryData: factoryData_,\n implementationAddress: implementationAddress_,\n mode,\n}: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2> {\n const is7702 = mode === \"7702\";\n\n LOGGER.debug(\"toModularAccountV2:start\", {\n ownerType: owner.type,\n mode,\n hasDeferredAction: !!deferredAction,\n hasAccountAddress: !!accountAddress_,\n });\n\n const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;\n\n const factoryAddress = factory ?? DefaultAddress.MAV2_FACTORY;\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702 ? DefaultAddress.SMAV2_7702 : DefaultAddress.SMAV2_BYTECODE);\n\n const getFactoryArgs = async () => {\n if (is7702) {\n // This is only for EP 0.8.0.\n // return {\n // factory: \"0x7702\",\n // factoryData: \"0x\",\n // } as const;\n return {\n factory: undefined,\n factoryData: undefined,\n } as const;\n }\n\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [owner.address, salt],\n }),\n };\n };\n\n const accountAddress =\n accountAddress_ ??\n (is7702\n ? owner.address\n : factoryData_\n ? await getModularAccountV2AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData: factoryData_,\n implementationAddress,\n entryPoint: {\n version: \"0.7\",\n address: entryPoint07Address,\n },\n })\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n type: \"SMA\",\n ownerAddress: owner.address,\n }));\n\n LOGGER.debug(\"toModularAccountV2:address-resolved\", {\n accountAddress,\n is7702,\n });\n\n let authorization: ToSmartAccountParameters[\"authorization\"];\n if (is7702) {\n LOGGER.debug(\"toModularAccountV2:7702-mode\");\n if (owner.type !== \"local\") {\n LOGGER.error(\"toModularAccountV2:invalid-owner-type\", {\n ownerType: owner.type,\n });\n throw new InvalidOwnerError(\n `Owner of type ${owner.type} is unsupported for 7702 mode.`,\n );\n }\n if (owner.signAuthorization == null) {\n LOGGER.error(\"toModularAccountV2:missing-signAuthorization\");\n throw new InvalidOwnerError(\n \"Owner must implement `signAuthorization` to be used with 7702 mode.\",\n );\n }\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n owner.address !== accountAddress\n ) {\n LOGGER.error(\"toModularAccountV2:entity-id-override\");\n throw new EntityIdOverrideError();\n }\n authorization = {\n // The current version of Viem has some pretty strict constraints\n // on a `PrivateKeyAccount`, but this seems safe as long as the\n // owner is able to `signAuthorization`.\n account: owner as PrivateKeyAccount,\n address: DefaultAddress.SMAV2_7702,\n };\n }\n\n const base = await toModularAccountV2Base({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity,\n deferredAction,\n authorization,\n });\n\n return {\n ...base,\n // This may be extended in the future with additional MAv2-specific methods.\n };\n}\n"]}
@@ -15,6 +15,8 @@ const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
15
15
  const ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
16
16
  const ACCOUNT_EXECUTE_SELECTOR = "0xb61d27f6";
17
17
  const ACCOUNT_EXECUTEBATCH_SELECTOR = "0x34fcd5be";
18
+ const ACCOUNT_PERFORM_CREATE_SELECTOR = "0x5998db5c";
19
+ const ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR = "0xf2680c0f";
18
20
  /**
19
21
  * A pseudo-enum for permission types.
20
22
  */
@@ -142,6 +144,12 @@ export class PermissionBuilder {
142
144
  * @returns {this} The permission builder instance.
143
145
  */
144
146
  addSelector({ selector }) {
147
+ if (selector === ACCOUNT_PERFORM_CREATE_SELECTOR) {
148
+ throw new SelectorNotAllowed("performCreate");
149
+ }
150
+ if (selector === ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR) {
151
+ throw new SelectorNotAllowed("executeWithRuntimeValidation");
152
+ }
145
153
  this.selectors.push(selector);
146
154
  return this;
147
155
  }
@@ -193,13 +201,19 @@ export class PermissionBuilder {
193
201
  if (permission.data.functions.length === 0) {
194
202
  throw new NoFunctionsProvidedError(permission);
195
203
  }
196
- // Explicitly disallow adding execute & executeBatch
204
+ // Explicitly disallow adding execute, executeBatch, performCreate, and executeWithRuntimeValidation
197
205
  if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {
198
206
  throw new SelectorNotAllowed("execute");
199
207
  }
200
208
  else if (permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)) {
201
209
  throw new SelectorNotAllowed("executeBatch");
202
210
  }
211
+ else if (permission.data.functions.includes(ACCOUNT_PERFORM_CREATE_SELECTOR)) {
212
+ throw new SelectorNotAllowed("performCreate");
213
+ }
214
+ else if (permission.data.functions.includes(ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR)) {
215
+ throw new SelectorNotAllowed("executeWithRuntimeValidation");
216
+ }
203
217
  this.selectors = [...this.selectors, ...permission.data.functions];
204
218
  }
205
219
  this.permissions.push(permission);
@@ -1 +1 @@
1
- {"version":3,"file":"permissionBuilder.js","sourceRoot":"","sources":["../../../src/ma-v2/permissionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,EACL,WAAW,GAMZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAA0C,MAAM,YAAY,CAAC;AAC9E,OAAO,EACL,eAAe,GAEhB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,wBAAwB,GAEzB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,gCAAgC,EAChC,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,EAClB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE9E,uDAAuD;AACvD,MAAM,WAAW,GAAG,UAAU,CAAC;AAC/B,MAAM,sBAAsB,GAAG,YAAY,CAAC;AAC5C,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAC7C,MAAM,wBAAwB,GAAG,YAAY,CAAC;AAC9C,MAAM,6BAA6B,GAAG,YAAY,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;IAC5C,oEAAoE;IACpE,sEAAsE;IAC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Content":["import {\n maxUint48,\n toHex,\n zeroAddress,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { NativeTokenLimitModule } from \"./modules/native-token-limit-module/module.js\";\nimport { SingleSignerValidationModule } from \"./modules/single-signer-validation/module.js\";\nimport { AllowlistModule } from \"./modules/allowlist-module/module.js\";\nimport { TimeRangeModule } from \"./modules/time-range-module/module.js\";\nimport { HookType, type HookConfig, type ValidationConfig } from \"./types.js\";\nimport {\n deferralActions,\n type DeferredActionTypedData,\n} from \"./decorators/deferralActions.js\";\nimport {\n installValidationActions,\n type InstallValidationParams,\n} from \"./decorators/installValidation.js\";\nimport { assertNever, AccountNotFoundError } from \"@alchemy/common\";\nimport {\n AccountAddressAsTargetError,\n DeadlineOverLimitError,\n DuplicateTargetAddressError,\n ExpiredDeadlineError,\n MultipleGasLimitError,\n MultipleNativeTokenTransferError,\n NoFunctionsProvidedError,\n RootPermissionOnlyError,\n SelectorNotAllowed,\n ValidationConfigUnsetError,\n ZeroAddressError,\n} from \"../errors/permissionBuilderErrors.js\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { DefaultModuleAddress, isModularAccountV2 } from \"./utils/account.js\";\n\n// We use this to offset the ERC20 spend limit entityId\nconst HALF_UINT32 = 2147483647;\nconst ERC20_APPROVE_SELECTOR = \"0x095ea7b3\";\nconst ERC20_TRANSFER_SELECTOR = \"0xa9059cbb\";\nconst ACCOUNT_EXECUTE_SELECTOR = \"0xb61d27f6\";\nconst ACCOUNT_EXECUTEBATCH_SELECTOR = \"0x34fcd5be\";\n\n/**\n * A pseudo-enum for permission types.\n */\nexport const PermissionType = {\n NATIVE_TOKEN_TRANSFER: \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER: \"erc20-token-transfer\",\n // ERC721_TOKEN_TRANSFER : \"erc721-token-transfer\", // Unimplemented\n // ERC1155_TOKEN_TRANSFER : \"erc1155-token-transfer\", // Unimplemented\n GAS_LIMIT: \"gas-limit\",\n // CALL_LIMIT : \"call-limit\", //Unimplemented\n // RATE_LIMIT : \"rate-limit\", //Unimplemented\n CONTRACT_ACCESS: \"contract-access\",\n ACCOUNT_FUNCTIONS: \"account-functions\",\n FUNCTIONS_ON_ALL_CONTRACTS: \"functions-on-all-contracts\",\n FUNCTIONS_ON_CONTRACT: \"functions-on-contract\",\n ROOT: \"root\",\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type PermissionType =\n (typeof PermissionType)[keyof typeof PermissionType];\n\n/**\n * A pseudo-enum for hook identifiers.\n */\nexport const HookIdentifier = {\n NATIVE_TOKEN_TRANSFER: \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER: \"erc20-token-transfer\",\n GAS_LIMIT: \"gas-limit\",\n PREVAL_ALLOWLIST: \"preval-allowlist\", // aggregate of CONTRACT_ACCESS, ACCOUNT_FUNCTIONS, FUNCTIONS_ON_ALL_CONTRACTS, FUNCTIONS_ON_CONTRACT\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type HookIdentifier =\n (typeof HookIdentifier)[keyof typeof HookIdentifier];\n\ntype PreExecutionHookConfig = {\n address: Address;\n entityId: number;\n hookType: typeof HookType.EXECUTION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype PreValidationHookConfig = {\n address: Address;\n entityId: number;\n hookType: typeof HookType.VALIDATION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.ERC20_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n [HookIdentifier.GAS_LIMIT]:\n | {\n hookConfig: PreValidationHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.PREVAL_ALLOWLIST]:\n | {\n hookConfig: PreValidationHookConfig;\n\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n};\n\ntype Key = {\n publicKey: Hex;\n type: \"secp256k1\" | \"contract\";\n};\n\nexport type Permission =\n | {\n // this permission allows transfer of native tokens from the account\n type: typeof PermissionType.NATIVE_TOKEN_TRANSFER;\n data: {\n allowance: Hex;\n };\n }\n | {\n // this permission allows transfer or approval of erc20 tokens from the account\n type: typeof PermissionType.ERC20_TOKEN_TRANSFER;\n data: {\n address: Address; // erc20 token contract address\n allowance: Hex;\n };\n }\n | {\n // this permissions allows the key to spend gas for UOs\n type: typeof PermissionType.GAS_LIMIT;\n data: {\n limit: Hex;\n };\n }\n | {\n // this permission grants access to all functions in a contract\n type: typeof PermissionType.CONTRACT_ACCESS;\n data: {\n address: Address;\n };\n }\n | {\n // this permission grants access to functions in the account\n type: typeof PermissionType.ACCOUNT_FUNCTIONS;\n data: {\n functions: Hex[]; // function signatures\n };\n }\n | {\n // this permission grants access to a function selector in any address or contract\n type: typeof PermissionType.FUNCTIONS_ON_ALL_CONTRACTS;\n data: {\n functions: Hex[]; // function signatures\n };\n }\n | {\n // this permission grants access to specified functions on a specific contract\n type: typeof PermissionType.FUNCTIONS_ON_CONTRACT;\n data: {\n address: Address;\n functions: Hex[];\n };\n }\n | {\n // this permission grants full access to everything\n type: typeof PermissionType.ROOT;\n data?: never;\n };\n\ntype Hook = {\n hookConfig: HookConfig;\n initData: Hex;\n};\n\n/**\n * A builder for constructing a Permission object.\n */\nexport class PermissionBuilder {\n private client: Client<Transport, Chain, SmartAccount>;\n private validationConfig: ValidationConfig = {\n moduleAddress: zeroAddress,\n entityId: 0, // uint32\n isGlobal: false,\n isSignatureValidation: false,\n isUserOpValidation: false,\n };\n private selectors: Hex[] = [];\n private installData: Hex = \"0x\";\n private permissions: Permission[] = [];\n private hooks: Hook[] = [];\n private nonce: bigint = 0n;\n private hasAssociatedExecHooks: boolean = false;\n private deadline: number = 0;\n\n /**\n * Creates a PermissionBuilder instance.\n *\n * @param {PermissionBuilderParams} params - The parameters for creating a PermissionBuilder instance.\n */\n constructor({\n client,\n key,\n entityId,\n nonce,\n selectors,\n hooks,\n deadline,\n }: {\n client: Client<Transport, Chain, SmartAccount>;\n key: Key;\n entityId: number;\n nonce: bigint;\n selectors?: Hex[];\n hooks?: Hook[];\n deadline?: number;\n }) {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n this.client = client;\n this.validationConfig = {\n moduleAddress: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n entityId,\n isUserOpValidation: true,\n isGlobal: false,\n isSignatureValidation: false,\n };\n this.installData = SingleSignerValidationModule.encodeOnInstallData({\n entityId: entityId,\n signer: key.publicKey,\n });\n this.nonce = nonce;\n if (selectors) this.selectors = selectors;\n if (hooks) this.hooks = hooks;\n if (deadline) this.deadline = deadline;\n }\n\n /**\n * Adds a selector to the permission builder.\n *\n * @param {Hex} selector - The selector to add.\n * @returns {this} The permission builder instance.\n */\n addSelector({ selector }: { selector: Hex }): this {\n this.selectors.push(selector);\n return this;\n }\n\n /**\n * Adds a permission to the permission builder.\n *\n * @param {Permission} permission - The permission to add.\n * @returns {this} The permission builder instance.\n */\n addPermission({ permission }: { permission: Permission }): this {\n // Check 1: If we're adding root, we can't have any other permissions\n if (permission.type === PermissionType.ROOT) {\n if (this.permissions.length !== 0) {\n throw new RootPermissionOnlyError(permission);\n }\n this.permissions.push(permission);\n // Set isGlobal to true\n this.validationConfig.isGlobal = true;\n return this;\n }\n\n // Check 2: If the permission is NOT ROOT (guaranteed), ensure there is no ROOT permission set\n // Will resolve to undefined if ROOT is not found\n // NOTE: Technically this could be replaced by checking permissions[0] since it should not be possible\n // to have >1 permission with root among them\n if (this.permissions.find((p) => p.type === PermissionType.ROOT)) {\n throw new RootPermissionOnlyError(permission);\n }\n\n // Check 3: If the permission is either CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT, ensure it doesn't collide with another like it.\n if (\n permission.type === PermissionType.CONTRACT_ACCESS ||\n permission.type === PermissionType.FUNCTIONS_ON_CONTRACT\n ) {\n // Check 3.1: address must not be the account address, or the user should use the ACCOUNT_FUNCTIONS permission\n if (permission.data.address === this.client.account.address) {\n throw new AccountAddressAsTargetError(permission);\n }\n\n // Check 3.2: there must not be an existing permission with this address as a target\n const targetAddress = permission.data.address;\n const existingPermissionWithSameAddress = this.permissions.find(\n (p) =>\n (p.type === PermissionType.CONTRACT_ACCESS &&\n \"address\" in p.data &&\n p.data.address === targetAddress) ||\n (p.type === PermissionType.FUNCTIONS_ON_CONTRACT &&\n \"address\" in p.data &&\n p.data.address === targetAddress),\n );\n\n if (existingPermissionWithSameAddress) {\n throw new DuplicateTargetAddressError(permission, targetAddress);\n }\n }\n\n // Check 4: If the permission is ACCOUNT_FUNCTIONS, add selectors\n if (permission.type === PermissionType.ACCOUNT_FUNCTIONS) {\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n // Explicitly disallow adding execute & executeBatch\n if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {\n throw new SelectorNotAllowed(\"execute\");\n } else if (\n permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)\n ) {\n throw new SelectorNotAllowed(\"executeBatch\");\n }\n this.selectors = [...this.selectors, ...permission.data.functions];\n }\n\n this.permissions.push(permission);\n return this;\n }\n\n /**\n * Adds multiple permissions to the permission builder.\n *\n * @param {Permission[]} permissions - The permissions to add.\n * @returns {this} The permission builder instance.\n */\n addPermissions({ permissions }: { permissions: Permission[] }): this {\n // We could validate each permission here, but for simplicity we'll just add them\n // A better approach would be to call addPermission for each one\n permissions.forEach((permission) => {\n this.addPermission({ permission });\n });\n return this;\n }\n\n /**\n * Compiles the deferred action typed data to sign.\n *\n * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionPayload: Hex}>} The deferred action typed data and the full pre-signature deferred action payload.\n */\n async compileDeferred(): Promise<{\n typedData: DeferredActionTypedData;\n fullPreSignatureDeferredActionPayload: Hex;\n }> {\n // Add time range module hook via expiry\n if (this.deadline !== 0) {\n if (this.deadline < Date.now() / 1000) {\n throw new ExpiredDeadlineError(this.deadline, Date.now() / 1000);\n }\n if (this.deadline > maxUint48) {\n throw new DeadlineOverLimitError(this.deadline);\n }\n\n this.hooks.push(\n TimeRangeModule.buildHook(\n {\n entityId: this.validationConfig.entityId,\n validUntil: this.deadline,\n validAfter: 0,\n },\n DefaultModuleAddress.TIME_RANGE,\n ),\n );\n }\n\n const installValidationCall = await this.compileRaw();\n\n const { typedData } = await deferralActions(\n this.client,\n ).createDeferredActionTypedDataObject({\n callData: installValidationCall,\n deadline: this.deadline,\n nonce: this.nonce,\n });\n\n const preSignaturePayload = deferralActions(\n this.client,\n ).buildPreSignatureDeferredActionPayload({ typedData });\n\n // Encode additional information to build the full pre-signature payload\n const fullPreSignatureDeferredActionPayload: `0x${string}` = `0x0${\n this.hasAssociatedExecHooks ? \"1\" : \"0\"\n }${toHex(this.nonce, {\n size: 32,\n }).slice(2)}${preSignaturePayload.slice(2)}`;\n\n return {\n typedData,\n fullPreSignatureDeferredActionPayload,\n };\n }\n\n /**\n * Compiles the raw install arguments for the installValidation function.\n *\n * @returns {Promise<Hex>} The raw install arguments.\n */\n async compileRaw(): Promise<Hex> {\n const account = this.client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n // Translate all permissions into raw hooks if >0\n if (this.permissions.length > 0) {\n const rawHooks = this.translatePermissions(\n this.validationConfig.entityId,\n );\n // Add the translated permissions as hooks\n this.addHooks(rawHooks);\n }\n this.validateConfiguration();\n\n return await installValidationActions(this.client).encodeInstallValidation({\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account,\n });\n }\n\n /**\n * Compiles the install arguments for the installValidation function.\n *\n * @returns {Promise<InstallValidationParams>} The install arguments.\n */\n async compileInstallArgs(): Promise<InstallValidationParams> {\n const account = this.client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n this.validateConfiguration();\n\n return {\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account,\n };\n }\n\n private validateConfiguration(): void {\n if (\n this.validationConfig.isGlobal === false &&\n this.selectors.length === 0\n ) {\n throw new ValidationConfigUnsetError();\n }\n }\n\n // Used to translate consolidated permissions into raw unencoded hooks\n // Note entityId will be a member object later\n private translatePermissions(entityId: number): RawHooks {\n const rawHooks: RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.ERC20_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.GAS_LIMIT]: undefined,\n [HookIdentifier.PREVAL_ALLOWLIST]: undefined,\n };\n\n this.permissions.forEach((permission) => {\n switch (permission.type) {\n case PermissionType.NATIVE_TOKEN_TRANSFER:\n // Should never be added twice, check is on addPermission(s) too\n if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] !== undefined) {\n throw new MultipleNativeTokenTransferError(permission);\n }\n rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] = {\n hookConfig: {\n address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,\n entityId,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.allowance),\n },\n };\n this.hasAssociatedExecHooks = true;\n break;\n case PermissionType.ERC20_TOKEN_TRANSFER:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId: entityId + HALF_UINT32,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId: entityId + HALF_UINT32,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: true,\n erc20SpendLimit: BigInt(permission.data.allowance),\n selectors: [],\n },\n ],\n },\n };\n this.hasAssociatedExecHooks = true;\n // Also allow `approve` and `transfer` for the erc20\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [ERC20_APPROVE_SELECTOR, ERC20_TRANSFER_SELECTOR], // approve, transfer\n },\n ],\n },\n };\n break;\n case PermissionType.GAS_LIMIT:\n // Should only ever be added once, check is also on addPermission(s)\n if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {\n throw new MultipleGasLimitError(permission);\n }\n rawHooks[HookIdentifier.GAS_LIMIT] = {\n hookConfig: {\n address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.limit),\n },\n };\n break;\n case PermissionType.CONTRACT_ACCESS:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [],\n },\n ],\n },\n };\n break;\n case PermissionType.ACCOUNT_FUNCTIONS:\n // This is handled in add permissions\n break;\n case PermissionType.FUNCTIONS_ON_ALL_CONTRACTS:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: zeroAddress,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.FUNCTIONS_ON_CONTRACT:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.ROOT:\n // Root permission handled in addPermission\n break;\n default:\n return assertNever(permission, \"Unexpected permission type\");\n }\n\n // isGlobal guaranteed to be false since it's only set with root permissions,\n // we must add access to execute & executeBatch if there's a preVal allowlist hook set.\n if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST] !== undefined) {\n const selectorsToAdd: `0x${string}`[] = [\n ACCOUNT_EXECUTE_SELECTOR,\n ACCOUNT_EXECUTEBATCH_SELECTOR,\n ]; // execute, executeBatch\n\n // Only add the selectors if they aren't already in this.selectors\n const newSelectors = selectorsToAdd.filter(\n (selector) => !this.selectors.includes(selector),\n );\n\n this.selectors = [...this.selectors, ...newSelectors];\n }\n });\n\n return rawHooks;\n }\n\n private addHooks(rawHooks: RawHooks) {\n const ntt = rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER];\n if (ntt) {\n this.hooks.push({\n hookConfig: ntt.hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(ntt.initData),\n });\n }\n\n const erc20 = rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER];\n if (erc20) {\n this.hooks.push({\n hookConfig: erc20.hookConfig,\n initData: AllowlistModule.encodeOnInstallData(erc20.initData),\n });\n }\n\n const gl = rawHooks[HookIdentifier.GAS_LIMIT];\n if (gl) {\n this.hooks.push({\n hookConfig: gl.hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(gl.initData),\n });\n }\n\n const allowlist = rawHooks[HookIdentifier.PREVAL_ALLOWLIST];\n if (allowlist) {\n this.hooks.push({\n hookConfig: allowlist.hookConfig,\n initData: AllowlistModule.encodeOnInstallData(allowlist.initData),\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"permissionBuilder.js","sourceRoot":"","sources":["../../../src/ma-v2/permissionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,EACL,WAAW,GAMZ,MAAM,MAAM,CAAC;AACd,OAAO,E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;gBACzB,QAAQ,EAAE,sBAAsB,CAAC,mBAAmB,CAAC,EAAE,CAAC,QAAQ,CAAC;aAClE,CAAC,CAAC;QACL,CAAC;QAED,MAAM,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QAC5D,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,SAAS,CAAC,UAAU;gBAChC,QAAQ,EAAE,eAAe,CAAC,mBAAmB,CAAC,SAAS,CAAC,QAAQ,CAAC;aAClE,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n maxUint48,\n toHex,\n zeroAddress,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { NativeTokenLimitModule } from \"./modules/native-token-limit-module/module.js\";\nimport { SingleSignerValidationModule } from \"./modules/single-signer-validation/module.js\";\nimport { AllowlistModule } from \"./modules/allowlist-module/module.js\";\nimport { TimeRangeModule } from \"./modules/time-range-module/module.js\";\nimport { HookType, type HookConfig, type ValidationConfig } from \"./types.js\";\nimport {\n deferralActions,\n type DeferredActionTypedData,\n} from \"./decorators/deferralActions.js\";\nimport {\n installValidationActions,\n type InstallValidationParams,\n} from \"./decorators/installValidation.js\";\nimport { assertNever, AccountNotFoundError } from \"@alchemy/common\";\nimport {\n AccountAddressAsTargetError,\n DeadlineOverLimitError,\n DuplicateTargetAddressError,\n ExpiredDeadlineError,\n MultipleGasLimitError,\n MultipleNativeTokenTransferError,\n NoFunctionsProvidedError,\n RootPermissionOnlyError,\n SelectorNotAllowed,\n ValidationConfigUnsetError,\n ZeroAddressError,\n} from \"../errors/permissionBuilderErrors.js\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { DefaultModuleAddress, isModularAccountV2 } from \"./utils/account.js\";\n\n// We use this to offset the ERC20 spend limit entityId\nconst HALF_UINT32 = 2147483647;\nconst ERC20_APPROVE_SELECTOR = \"0x095ea7b3\";\nconst ERC20_TRANSFER_SELECTOR = \"0xa9059cbb\";\nconst ACCOUNT_EXECUTE_SELECTOR = \"0xb61d27f6\";\nconst ACCOUNT_EXECUTEBATCH_SELECTOR = \"0x34fcd5be\";\nconst ACCOUNT_PERFORM_CREATE_SELECTOR = \"0x5998db5c\";\nconst ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR = \"0xf2680c0f\";\n\n/**\n * A pseudo-enum for permission types.\n */\nexport const PermissionType = {\n NATIVE_TOKEN_TRANSFER: \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER: \"erc20-token-transfer\",\n // ERC721_TOKEN_TRANSFER : \"erc721-token-transfer\", // Unimplemented\n // ERC1155_TOKEN_TRANSFER : \"erc1155-token-transfer\", // Unimplemented\n GAS_LIMIT: \"gas-limit\",\n // CALL_LIMIT : \"call-limit\", //Unimplemented\n // RATE_LIMIT : \"rate-limit\", //Unimplemented\n CONTRACT_ACCESS: \"contract-access\",\n ACCOUNT_FUNCTIONS: \"account-functions\",\n FUNCTIONS_ON_ALL_CONTRACTS: \"functions-on-all-contracts\",\n FUNCTIONS_ON_CONTRACT: \"functions-on-contract\",\n ROOT: \"root\",\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type PermissionType =\n (typeof PermissionType)[keyof typeof PermissionType];\n\n/**\n * A pseudo-enum for hook identifiers.\n */\nexport const HookIdentifier = {\n NATIVE_TOKEN_TRANSFER: \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER: \"erc20-token-transfer\",\n GAS_LIMIT: \"gas-limit\",\n PREVAL_ALLOWLIST: \"preval-allowlist\", // aggregate of CONTRACT_ACCESS, ACCOUNT_FUNCTIONS, FUNCTIONS_ON_ALL_CONTRACTS, FUNCTIONS_ON_CONTRACT\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type HookIdentifier =\n (typeof HookIdentifier)[keyof typeof HookIdentifier];\n\ntype PreExecutionHookConfig = {\n address: Address;\n entityId: number;\n hookType: typeof HookType.EXECUTION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype PreValidationHookConfig = {\n address: Address;\n entityId: number;\n hookType: typeof HookType.VALIDATION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.ERC20_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n [HookIdentifier.GAS_LIMIT]:\n | {\n hookConfig: PreValidationHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.PREVAL_ALLOWLIST]:\n | {\n hookConfig: PreValidationHookConfig;\n\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n};\n\ntype Key = {\n publicKey: Hex;\n type: \"secp256k1\" | \"contract\";\n};\n\nexport type Permission =\n | {\n // this permission allows transfer of native tokens from the account\n type: typeof PermissionType.NATIVE_TOKEN_TRANSFER;\n data: {\n allowance: Hex;\n };\n }\n | {\n // this permission allows transfer or approval of erc20 tokens from the account\n type: typeof PermissionType.ERC20_TOKEN_TRANSFER;\n data: {\n address: Address; // erc20 token contract address\n allowance: Hex;\n };\n }\n | {\n // this permissions allows the key to spend gas for UOs\n type: typeof PermissionType.GAS_LIMIT;\n data: {\n limit: Hex;\n };\n }\n | {\n // this permission grants access to all functions in a contract\n type: typeof PermissionType.CONTRACT_ACCESS;\n data: {\n address: Address;\n };\n }\n | {\n // this permission grants access to functions in the account\n type: typeof PermissionType.ACCOUNT_FUNCTIONS;\n data: {\n functions: Hex[]; // function signatures\n };\n }\n | {\n // this permission grants access to a function selector in any address or contract\n type: typeof PermissionType.FUNCTIONS_ON_ALL_CONTRACTS;\n data: {\n functions: Hex[]; // function signatures\n };\n }\n | {\n // this permission grants access to specified functions on a specific contract\n type: typeof PermissionType.FUNCTIONS_ON_CONTRACT;\n data: {\n address: Address;\n functions: Hex[];\n };\n }\n | {\n // this permission grants full access to everything\n type: typeof PermissionType.ROOT;\n data?: never;\n };\n\ntype Hook = {\n hookConfig: HookConfig;\n initData: Hex;\n};\n\n/**\n * A builder for constructing a Permission object.\n */\nexport class PermissionBuilder {\n private client: Client<Transport, Chain, SmartAccount>;\n private validationConfig: ValidationConfig = {\n moduleAddress: zeroAddress,\n entityId: 0, // uint32\n isGlobal: false,\n isSignatureValidation: false,\n isUserOpValidation: false,\n };\n private selectors: Hex[] = [];\n private installData: Hex = \"0x\";\n private permissions: Permission[] = [];\n private hooks: Hook[] = [];\n private nonce: bigint = 0n;\n private hasAssociatedExecHooks: boolean = false;\n private deadline: number = 0;\n\n /**\n * Creates a PermissionBuilder instance.\n *\n * @param {PermissionBuilderParams} params - The parameters for creating a PermissionBuilder instance.\n */\n constructor({\n client,\n key,\n entityId,\n nonce,\n selectors,\n hooks,\n deadline,\n }: {\n client: Client<Transport, Chain, SmartAccount>;\n key: Key;\n entityId: number;\n nonce: bigint;\n selectors?: Hex[];\n hooks?: Hook[];\n deadline?: number;\n }) {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n this.client = client;\n this.validationConfig = {\n moduleAddress: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n entityId,\n isUserOpValidation: true,\n isGlobal: false,\n isSignatureValidation: false,\n };\n this.installData = SingleSignerValidationModule.encodeOnInstallData({\n entityId: entityId,\n signer: key.publicKey,\n });\n this.nonce = nonce;\n if (selectors) this.selectors = selectors;\n if (hooks) this.hooks = hooks;\n if (deadline) this.deadline = deadline;\n }\n\n /**\n * Adds a selector to the permission builder.\n *\n * @param {Hex} selector - The selector to add.\n * @returns {this} The permission builder instance.\n */\n addSelector({ selector }: { selector: Hex }): this {\n if (selector === ACCOUNT_PERFORM_CREATE_SELECTOR) {\n throw new SelectorNotAllowed(\"performCreate\");\n }\n if (selector === ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR) {\n throw new SelectorNotAllowed(\"executeWithRuntimeValidation\");\n }\n this.selectors.push(selector);\n return this;\n }\n\n /**\n * Adds a permission to the permission builder.\n *\n * @param {Permission} permission - The permission to add.\n * @returns {this} The permission builder instance.\n */\n addPermission({ permission }: { permission: Permission }): this {\n // Check 1: If we're adding root, we can't have any other permissions\n if (permission.type === PermissionType.ROOT) {\n if (this.permissions.length !== 0) {\n throw new RootPermissionOnlyError(permission);\n }\n this.permissions.push(permission);\n // Set isGlobal to true\n this.validationConfig.isGlobal = true;\n return this;\n }\n\n // Check 2: If the permission is NOT ROOT (guaranteed), ensure there is no ROOT permission set\n // Will resolve to undefined if ROOT is not found\n // NOTE: Technically this could be replaced by checking permissions[0] since it should not be possible\n // to have >1 permission with root among them\n if (this.permissions.find((p) => p.type === PermissionType.ROOT)) {\n throw new RootPermissionOnlyError(permission);\n }\n\n // Check 3: If the permission is either CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT, ensure it doesn't collide with another like it.\n if (\n permission.type === PermissionType.CONTRACT_ACCESS ||\n permission.type === PermissionType.FUNCTIONS_ON_CONTRACT\n ) {\n // Check 3.1: address must not be the account address, or the user should use the ACCOUNT_FUNCTIONS permission\n if (permission.data.address === this.client.account.address) {\n throw new AccountAddressAsTargetError(permission);\n }\n\n // Check 3.2: there must not be an existing permission with this address as a target\n const targetAddress = permission.data.address;\n const existingPermissionWithSameAddress = this.permissions.find(\n (p) =>\n (p.type === PermissionType.CONTRACT_ACCESS &&\n \"address\" in p.data &&\n p.data.address === targetAddress) ||\n (p.type === PermissionType.FUNCTIONS_ON_CONTRACT &&\n \"address\" in p.data &&\n p.data.address === targetAddress),\n );\n\n if (existingPermissionWithSameAddress) {\n throw new DuplicateTargetAddressError(permission, targetAddress);\n }\n }\n\n // Check 4: If the permission is ACCOUNT_FUNCTIONS, add selectors\n if (permission.type === PermissionType.ACCOUNT_FUNCTIONS) {\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n // Explicitly disallow adding execute, executeBatch, performCreate, and executeWithRuntimeValidation\n if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {\n throw new SelectorNotAllowed(\"execute\");\n } else if (\n permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)\n ) {\n throw new SelectorNotAllowed(\"executeBatch\");\n } else if (\n permission.data.functions.includes(ACCOUNT_PERFORM_CREATE_SELECTOR)\n ) {\n throw new SelectorNotAllowed(\"performCreate\");\n } else if (\n permission.data.functions.includes(\n ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR,\n )\n ) {\n throw new SelectorNotAllowed(\"executeWithRuntimeValidation\");\n }\n this.selectors = [...this.selectors, ...permission.data.functions];\n }\n\n this.permissions.push(permission);\n return this;\n }\n\n /**\n * Adds multiple permissions to the permission builder.\n *\n * @param {Permission[]} permissions - The permissions to add.\n * @returns {this} The permission builder instance.\n */\n addPermissions({ permissions }: { permissions: Permission[] }): this {\n // We could validate each permission here, but for simplicity we'll just add them\n // A better approach would be to call addPermission for each one\n permissions.forEach((permission) => {\n this.addPermission({ permission });\n });\n return this;\n }\n\n /**\n * Compiles the deferred action typed data to sign.\n *\n * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionPayload: Hex}>} The deferred action typed data and the full pre-signature deferred action payload.\n */\n async compileDeferred(): Promise<{\n typedData: DeferredActionTypedData;\n fullPreSignatureDeferredActionPayload: Hex;\n }> {\n // Add time range module hook via expiry\n if (this.deadline !== 0) {\n if (this.deadline < Date.now() / 1000) {\n throw new ExpiredDeadlineError(this.deadline, Date.now() / 1000);\n }\n if (this.deadline > maxUint48) {\n throw new DeadlineOverLimitError(this.deadline);\n }\n\n this.hooks.push(\n TimeRangeModule.buildHook(\n {\n entityId: this.validationConfig.entityId,\n validUntil: this.deadline,\n validAfter: 0,\n },\n DefaultModuleAddress.TIME_RANGE,\n ),\n );\n }\n\n const installValidationCall = await this.compileRaw();\n\n const { typedData } = await deferralActions(\n this.client,\n ).createDeferredActionTypedDataObject({\n callData: installValidationCall,\n deadline: this.deadline,\n nonce: this.nonce,\n });\n\n const preSignaturePayload = deferralActions(\n this.client,\n ).buildPreSignatureDeferredActionPayload({ typedData });\n\n // Encode additional information to build the full pre-signature payload\n const fullPreSignatureDeferredActionPayload: `0x${string}` = `0x0${\n this.hasAssociatedExecHooks ? \"1\" : \"0\"\n }${toHex(this.nonce, {\n size: 32,\n }).slice(2)}${preSignaturePayload.slice(2)}`;\n\n return {\n typedData,\n fullPreSignatureDeferredActionPayload,\n };\n }\n\n /**\n * Compiles the raw install arguments for the installValidation function.\n *\n * @returns {Promise<Hex>} The raw install arguments.\n */\n async compileRaw(): Promise<Hex> {\n const account = this.client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n // Translate all permissions into raw hooks if >0\n if (this.permissions.length > 0) {\n const rawHooks = this.translatePermissions(\n this.validationConfig.entityId,\n );\n // Add the translated permissions as hooks\n this.addHooks(rawHooks);\n }\n this.validateConfiguration();\n\n return await installValidationActions(this.client).encodeInstallValidation({\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account,\n });\n }\n\n /**\n * Compiles the install arguments for the installValidation function.\n *\n * @returns {Promise<InstallValidationParams>} The install arguments.\n */\n async compileInstallArgs(): Promise<InstallValidationParams> {\n const account = this.client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n this.validateConfiguration();\n\n return {\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account,\n };\n }\n\n private validateConfiguration(): void {\n if (\n this.validationConfig.isGlobal === false &&\n this.selectors.length === 0\n ) {\n throw new ValidationConfigUnsetError();\n }\n }\n\n // Used to translate consolidated permissions into raw unencoded hooks\n // Note entityId will be a member object later\n private translatePermissions(entityId: number): RawHooks {\n const rawHooks: RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.ERC20_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.GAS_LIMIT]: undefined,\n [HookIdentifier.PREVAL_ALLOWLIST]: undefined,\n };\n\n this.permissions.forEach((permission) => {\n switch (permission.type) {\n case PermissionType.NATIVE_TOKEN_TRANSFER:\n // Should never be added twice, check is on addPermission(s) too\n if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] !== undefined) {\n throw new MultipleNativeTokenTransferError(permission);\n }\n rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] = {\n hookConfig: {\n address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,\n entityId,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.allowance),\n },\n };\n this.hasAssociatedExecHooks = true;\n break;\n case PermissionType.ERC20_TOKEN_TRANSFER:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId: entityId + HALF_UINT32,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId: entityId + HALF_UINT32,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: true,\n erc20SpendLimit: BigInt(permission.data.allowance),\n selectors: [],\n },\n ],\n },\n };\n this.hasAssociatedExecHooks = true;\n // Also allow `approve` and `transfer` for the erc20\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [ERC20_APPROVE_SELECTOR, ERC20_TRANSFER_SELECTOR], // approve, transfer\n },\n ],\n },\n };\n break;\n case PermissionType.GAS_LIMIT:\n // Should only ever be added once, check is also on addPermission(s)\n if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {\n throw new MultipleGasLimitError(permission);\n }\n rawHooks[HookIdentifier.GAS_LIMIT] = {\n hookConfig: {\n address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.limit),\n },\n };\n break;\n case PermissionType.CONTRACT_ACCESS:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [],\n },\n ],\n },\n };\n break;\n case PermissionType.ACCOUNT_FUNCTIONS:\n // This is handled in add permissions\n break;\n case PermissionType.FUNCTIONS_ON_ALL_CONTRACTS:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: zeroAddress,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.FUNCTIONS_ON_CONTRACT:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.ROOT:\n // Root permission handled in addPermission\n break;\n default:\n return assertNever(permission, \"Unexpected permission type\");\n }\n\n // isGlobal guaranteed to be false since it's only set with root permissions,\n // we must add access to execute & executeBatch if there's a preVal allowlist hook set.\n if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST] !== undefined) {\n const selectorsToAdd: `0x${string}`[] = [\n ACCOUNT_EXECUTE_SELECTOR,\n ACCOUNT_EXECUTEBATCH_SELECTOR,\n ]; // execute, executeBatch\n\n // Only add the selectors if they aren't already in this.selectors\n const newSelectors = selectorsToAdd.filter(\n (selector) => !this.selectors.includes(selector),\n );\n\n this.selectors = [...this.selectors, ...newSelectors];\n }\n });\n\n return rawHooks;\n }\n\n private addHooks(rawHooks: RawHooks) {\n const ntt = rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER];\n if (ntt) {\n this.hooks.push({\n hookConfig: ntt.hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(ntt.initData),\n });\n }\n\n const erc20 = rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER];\n if (erc20) {\n this.hooks.push({\n hookConfig: erc20.hookConfig,\n initData: AllowlistModule.encodeOnInstallData(erc20.initData),\n });\n }\n\n const gl = rawHooks[HookIdentifier.GAS_LIMIT];\n if (gl) {\n this.hooks.push({\n hookConfig: gl.hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(gl.initData),\n });\n }\n\n const allowlist = rawHooks[HookIdentifier.PREVAL_ALLOWLIST];\n if (allowlist) {\n this.hooks.push({\n hookConfig: allowlist.hookConfig,\n initData: AllowlistModule.encodeOnInstallData(allowlist.initData),\n });\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "5.0.0-beta.22";
1
+ export declare const VERSION = "5.0.0-beta.24";
@@ -1,4 +1,4 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "5.0.0-beta.22";
3
+ export const VERSION = "5.0.0-beta.24";
4
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"5.0.0-beta.22\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"5.0.0-beta.24\";\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 {};
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,cAAc,EACnB,KAAK,YAAY,EAEjB,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAKd,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAWhD,KAAK,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;AAG/B,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG,EAAE,CAAC;AAEzD,MAAM,MAAM,wBAAwB,CAClC,KAAK,SAAS,IAAI,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,IAC/C;IACF,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,cAAc,GAAG,YAAY,GAAG,SAAS,CAAC,CAAC;IAC5E,KAAK,EAAE,cAAc,GAAG,YAAY,CAAC;IACrC,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,GAAG,CAAC,KAAK,SAAS,MAAM,GACrB;IACE,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,qBAAqB,CAAC,EAAE,KAA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E,WAAW,EAAE,EAAE;QAAE,WAAW,EAAE,UAAU,EAAE,CAAA;KAAE,GAAG,IAAI;IASpE;;;;OAIG;IACG,eAAe,IAAI,OAAO,CAAC;QAC/B,SAAS,EAAE,uBAAuB,CAAC;QACnC,qCAAqC,EAAE,GAAG,CAAC;KAC5C,CAAC;IAiDF;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;IAyBhC;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAiB5D,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,oBAAoB;IAgO5B,OAAO,CAAC,QAAQ;CAiCjB"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "5.0.0-beta.22";
1
+ export declare const VERSION = "5.0.0-beta.24";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alchemy/smart-accounts",
3
- "version": "5.0.0-beta.23",
3
+ "version": "5.0.0-beta.25",
4
4
  "description": "This package contains all of the viem interfaces for Alchemy's Smart Contract Accounts",
5
5
  "author": "Alchemy",
6
6
  "license": "MIT",
@@ -39,12 +39,12 @@
39
39
  "test:run": "vitest run"
40
40
  },
41
41
  "devDependencies": {
42
- "@alchemy/aa-infra": "5.0.0-beta.23",
42
+ "@alchemy/aa-infra": "5.0.0-beta.25",
43
43
  "typescript-template": "workspace:*",
44
44
  "viem": "^2.45.0"
45
45
  },
46
46
  "dependencies": {
47
- "@alchemy/common": "5.0.0-beta.23"
47
+ "@alchemy/common": "5.0.0-beta.25"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "viem": "^2.45.0"
@@ -61,5 +61,5 @@
61
61
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
62
62
  },
63
63
  "homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
64
- "gitHead": "1354e8caf42c7f7bf389320f75f2920c6c00876b"
64
+ "gitHead": "0eb4e1f1d586317a5f2c189e2ddef139d7348412"
65
65
  }
@@ -65,6 +65,45 @@ export type ToModularAccountV2Params<
65
65
  *
66
66
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
67
67
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * import { createPublicClient } from "viem";
72
+ * import { createBundlerClient, createPaymasterClient } from "viem/account-abstraction";
73
+ * import { sepolia } from "viem/chains";
74
+ * import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
75
+ * import { alchemyTransport } from "@alchemy/common";
76
+ * import { estimateFeesPerGas } from "@alchemy/aa-infra";
77
+ * import { toModularAccountV2 } from "@alchemy/smart-accounts";
78
+ *
79
+ * const transport = alchemyTransport({ apiKey: "YOUR_API_KEY" });
80
+ *
81
+ * // 1. Create a MAv2 smart account
82
+ * const account = await toModularAccountV2({
83
+ * client: createPublicClient({ chain: sepolia, transport }),
84
+ * owner: privateKeyToAccount(generatePrivateKey()),
85
+ * });
86
+ *
87
+ * // 2. Create a bundler client with the account
88
+ * const bundlerClient = createBundlerClient({
89
+ * account,
90
+ * chain: sepolia,
91
+ * transport,
92
+ * userOperation: {
93
+ * estimateFeesPerGas,
94
+ * },
95
+ * // Optional: sponsor gas with a paymaster
96
+ * paymaster: createPaymasterClient({ transport }),
97
+ * paymasterContext: { policyId: "YOUR_POLICY_ID" },
98
+ * });
99
+ *
100
+ * // 3. Send a user operation
101
+ * const hash = await bundlerClient.sendUserOperation({
102
+ * calls: [{ to: "0x...", value: 0n, data: "0x" }],
103
+ * });
104
+ *
105
+ * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
106
+ * ```
68
107
  */
69
108
  export async function toModularAccountV2<TMode extends Mode = Mode>({
70
109
  client,
@@ -44,6 +44,8 @@ const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
44
44
  const ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
45
45
  const ACCOUNT_EXECUTE_SELECTOR = "0xb61d27f6";
46
46
  const ACCOUNT_EXECUTEBATCH_SELECTOR = "0x34fcd5be";
47
+ const ACCOUNT_PERFORM_CREATE_SELECTOR = "0x5998db5c";
48
+ const ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR = "0xf2680c0f";
47
49
 
48
50
  /**
49
51
  * A pseudo-enum for permission types.
@@ -289,6 +291,12 @@ export class PermissionBuilder {
289
291
  * @returns {this} The permission builder instance.
290
292
  */
291
293
  addSelector({ selector }: { selector: Hex }): this {
294
+ if (selector === ACCOUNT_PERFORM_CREATE_SELECTOR) {
295
+ throw new SelectorNotAllowed("performCreate");
296
+ }
297
+ if (selector === ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR) {
298
+ throw new SelectorNotAllowed("executeWithRuntimeValidation");
299
+ }
292
300
  this.selectors.push(selector);
293
301
  return this;
294
302
  }
@@ -351,13 +359,23 @@ export class PermissionBuilder {
351
359
  if (permission.data.functions.length === 0) {
352
360
  throw new NoFunctionsProvidedError(permission);
353
361
  }
354
- // Explicitly disallow adding execute & executeBatch
362
+ // Explicitly disallow adding execute, executeBatch, performCreate, and executeWithRuntimeValidation
355
363
  if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {
356
364
  throw new SelectorNotAllowed("execute");
357
365
  } else if (
358
366
  permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)
359
367
  ) {
360
368
  throw new SelectorNotAllowed("executeBatch");
369
+ } else if (
370
+ permission.data.functions.includes(ACCOUNT_PERFORM_CREATE_SELECTOR)
371
+ ) {
372
+ throw new SelectorNotAllowed("performCreate");
373
+ } else if (
374
+ permission.data.functions.includes(
375
+ ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR,
376
+ )
377
+ ) {
378
+ throw new SelectorNotAllowed("executeWithRuntimeValidation");
361
379
  }
362
380
  this.selectors = [...this.selectors, ...permission.data.functions];
363
381
  }
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "5.0.0-beta.23";
3
+ export const VERSION = "5.0.0-beta.25";