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

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.
@@ -8,6 +8,7 @@ export declare class InvalidEntityIdError extends BaseError {
8
8
  * Initializes a new instance of the error message with a default message indicating that the entity id is invalid because it's too large.
9
9
  *
10
10
  * @param {number} entityId the invalid entityId used
11
+ * @param {number | bigint} [maxAllowedInclusive] inclusive upper bound the entityId must not exceed. Defaults to `uint32.max`.
11
12
  */
12
- constructor(entityId: number);
13
+ constructor(entityId: number, maxAllowedInclusive?: number | bigint);
13
14
  }
@@ -1,4 +1,5 @@
1
1
  import { BaseError } from "@alchemy/common";
2
+ import { maxUint32 } from "viem";
2
3
  /**
3
4
  * Error class denoting that the provided entity id is invalid because it's too large.
4
5
  */
@@ -7,9 +8,10 @@ export class InvalidEntityIdError extends BaseError {
7
8
  * Initializes a new instance of the error message with a default message indicating that the entity id is invalid because it's too large.
8
9
  *
9
10
  * @param {number} entityId the invalid entityId used
11
+ * @param {number | bigint} [maxAllowedInclusive] inclusive upper bound the entityId must not exceed. Defaults to `uint32.max`.
10
12
  */
11
- constructor(entityId) {
12
- super(`Entity ID used is ${entityId}, but must be less than or equal to uint32.max`);
13
+ constructor(entityId, maxAllowedInclusive = maxUint32) {
14
+ super(`Entity ID used is ${entityId}, but must be less than or equal to ${maxAllowedInclusive}`);
13
15
  Object.defineProperty(this, "name", {
14
16
  enumerable: true,
15
17
  configurable: true,
@@ -1 +1 @@
1
- {"version":3,"file":"InvalidEntityIdError.js","sourceRoot":"","sources":["../../../src/errors/InvalidEntityIdError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAGjD;;;;OAIG;IACH,YAAY,QAAgB;QAC1B,KAAK,CACH,qBAAqB,QAAQ,gDAAgD,CAC9E,CAAC;QAVK;;;;mBAAO,sBAAsB;WAAC;IAWvC,CAAC;CACF","sourcesContent":["import { BaseError } from \"@alchemy/common\";\n\n/**\n * Error class denoting that the provided entity id is invalid because it's too large.\n */\nexport class InvalidEntityIdError extends BaseError {\n override name = \"InvalidEntityIdError\";\n\n /**\n * Initializes a new instance of the error message with a default message indicating that the entity id is invalid because it's too large.\n *\n * @param {number} entityId the invalid entityId used\n */\n constructor(entityId: number) {\n super(\n `Entity ID used is ${entityId}, but must be less than or equal to uint32.max`,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"InvalidEntityIdError.js","sourceRoot":"","sources":["../../../src/errors/InvalidEntityIdError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAGjD;;;;;OAKG;IACH,YACE,QAAgB,EAChB,sBAAuC,SAAS;QAEhD,KAAK,CACH,qBAAqB,QAAQ,uCAAuC,mBAAmB,EAAE,CAC1F,CAAC;QAdK;;;;mBAAO,sBAAsB;WAAC;IAevC,CAAC;CACF","sourcesContent":["import { BaseError } from \"@alchemy/common\";\nimport { maxUint32 } from \"viem\";\n\n/**\n * Error class denoting that the provided entity id is invalid because it's too large.\n */\nexport class InvalidEntityIdError extends BaseError {\n override name = \"InvalidEntityIdError\";\n\n /**\n * Initializes a new instance of the error message with a default message indicating that the entity id is invalid because it's too large.\n *\n * @param {number} entityId the invalid entityId used\n * @param {number | bigint} [maxAllowedInclusive] inclusive upper bound the entityId must not exceed. Defaults to `uint32.max`.\n */\n constructor(\n entityId: number,\n maxAllowedInclusive: number | bigint = maxUint32,\n ) {\n super(\n `Entity ID used is ${entityId}, but must be less than or equal to ${maxAllowedInclusive}`,\n );\n }\n}\n"]}
@@ -8,8 +8,12 @@ import { deferralActions, } from "./decorators/deferralActions.js";
8
8
  import { installValidationActions, } from "./decorators/installValidation.js";
9
9
  import { assertNever, AccountNotFoundError } from "@alchemy/common";
10
10
  import { AccountAddressAsTargetError, DeadlineOverLimitError, DuplicateTargetAddressError, ExpiredDeadlineError, MultipleGasLimitError, MultipleNativeTokenTransferError, NoFunctionsProvidedError, RootPermissionOnlyError, SelectorNotAllowed, ValidationConfigUnsetError, ZeroAddressError, } from "../errors/permissionBuilderErrors.js";
11
+ import { InvalidEntityIdError } from "../errors/InvalidEntityIdError.js";
11
12
  import { DefaultModuleAddress, isModularAccountV2 } from "./utils/account.js";
12
- // We use this to offset the ERC20 spend limit entityId
13
+ // Reserved offset for hooks that would otherwise collide on shared module storage
14
+ // (ERC20 spend limit vs PREVAL_ALLOWLIST on AllowlistModule; GAS_LIMIT vs
15
+ // NATIVE_TOKEN_TRANSFER on NativeTokenLimitModule). Any user-supplied entityId
16
+ // must be strictly less than this so the offset namespace stays disjoint.
13
17
  const HALF_UINT32 = 2147483647;
14
18
  const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
15
19
  const ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
@@ -150,6 +154,12 @@ export class PermissionBuilder {
150
154
  if (!account || !isModularAccountV2(account)) {
151
155
  throw new AccountNotFoundError();
152
156
  }
157
+ // EntityIds in [HALF_UINT32, uint32.max] overlap the offset namespace used by
158
+ // ERC20 spend-limit and GAS_LIMIT hooks, which would silently corrupt the
159
+ // shared module storage. Reject early.
160
+ if (entityId >= HALF_UINT32) {
161
+ throw new InvalidEntityIdError(entityId, HALF_UINT32 - 1);
162
+ }
153
163
  this.client = client;
154
164
  this.validationConfig = {
155
165
  moduleAddress: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,
@@ -428,16 +438,18 @@ export class PermissionBuilder {
428
438
  if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {
429
439
  throw new MultipleGasLimitError(permission);
430
440
  }
441
+ // Offset the entityId so GAS_LIMIT writes to a different slot than
442
+ // NATIVE_TOKEN_TRANSFER on the shared NativeTokenLimitModule.
431
443
  rawHooks[HookIdentifier.GAS_LIMIT] = {
432
444
  hookConfig: {
433
445
  address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,
434
- entityId,
446
+ entityId: entityId + HALF_UINT32,
435
447
  hookType: HookType.VALIDATION,
436
448
  hasPreHooks: true,
437
449
  hasPostHooks: false,
438
450
  },
439
451
  initData: {
440
- entityId,
452
+ entityId: entityId + HALF_UINT32,
441
453
  spendLimit: BigInt(permission.data.limit),
442
454
  },
443
455
  };
@@ -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,U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U;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\";\nconst ACCOUNT_INSTALL_VALIDATION_SELECTOR = \"0x1bbf564c\";\nconst ACCOUNT_UNINSTALL_VALIDATION_SELECTOR = \"0xb6b1ccfe\";\nconst ACCOUNT_INSTALL_EXECUTION_SELECTOR = \"0x1d37e7d6\";\nconst ACCOUNT_UNINSTALL_EXECUTION_SELECTOR = \"0x0b7cad71\";\nconst ACCOUNT_UPGRADE_TO_AND_CALL_SELECTOR = \"0x4f1ef286\";\n// Wrapped native functions that must not be added to a session key's selector allowlist.\nconst PRIVILEGED_SELECTORS: Record<string, string> = {\n [ACCOUNT_PERFORM_CREATE_SELECTOR]: \"performCreate\",\n [ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR]:\n \"executeWithRuntimeValidation\",\n [ACCOUNT_INSTALL_VALIDATION_SELECTOR]: \"installValidation\",\n [ACCOUNT_UNINSTALL_VALIDATION_SELECTOR]: \"uninstallValidation\",\n [ACCOUNT_INSTALL_EXECUTION_SELECTOR]: \"installExecution\",\n [ACCOUNT_UNINSTALL_EXECUTION_SELECTOR]: \"uninstallExecution\",\n [ACCOUNT_UPGRADE_TO_AND_CALL_SELECTOR]: \"upgradeToAndCall\",\n};\n\n// Auto-added by translatePermissions when a PREVAL_ALLOWLIST hook exists.\n// Blocked from manual addition to ensure they're only added with proper hook context.\nconst SYSTEM_MANAGED_SELECTORS: Record<string, string> = {\n [ACCOUNT_EXECUTE_SELECTOR]: \"execute\",\n [ACCOUNT_EXECUTEBATCH_SELECTOR]: \"executeBatch\",\n};\n\nfunction assertNotForbiddenSelector(selector: Hex): void {\n const normalized = selector.toLowerCase();\n const match =\n PRIVILEGED_SELECTORS[normalized] ?? SYSTEM_MANAGED_SELECTORS[normalized];\n if (match != null) {\n throw new SelectorNotAllowed(match);\n }\n}\n\nfunction assertNoForbiddenSelectors(selectors: Hex[]): void {\n for (const selector of selectors) {\n assertNotForbiddenSelector(selector);\n }\n}\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) {\n assertNoForbiddenSelectors(selectors);\n this.selectors = selectors;\n }\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 assertNotForbiddenSelector(selector);\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 assertNoForbiddenSelectors(permission.data.functions);\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":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C,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 { InvalidEntityIdError } from \"../errors/InvalidEntityIdError.js\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { DefaultModuleAddress, isModularAccountV2 } from \"./utils/account.js\";\n\n// Reserved offset for hooks that would otherwise collide on shared module storage\n// (ERC20 spend limit vs PREVAL_ALLOWLIST on AllowlistModule; GAS_LIMIT vs\n// NATIVE_TOKEN_TRANSFER on NativeTokenLimitModule). Any user-supplied entityId\n// must be strictly less than this so the offset namespace stays disjoint.\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\";\nconst ACCOUNT_INSTALL_VALIDATION_SELECTOR = \"0x1bbf564c\";\nconst ACCOUNT_UNINSTALL_VALIDATION_SELECTOR = \"0xb6b1ccfe\";\nconst ACCOUNT_INSTALL_EXECUTION_SELECTOR = \"0x1d37e7d6\";\nconst ACCOUNT_UNINSTALL_EXECUTION_SELECTOR = \"0x0b7cad71\";\nconst ACCOUNT_UPGRADE_TO_AND_CALL_SELECTOR = \"0x4f1ef286\";\n// Wrapped native functions that must not be added to a session key's selector allowlist.\nconst PRIVILEGED_SELECTORS: Record<string, string> = {\n [ACCOUNT_PERFORM_CREATE_SELECTOR]: \"performCreate\",\n [ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR]:\n \"executeWithRuntimeValidation\",\n [ACCOUNT_INSTALL_VALIDATION_SELECTOR]: \"installValidation\",\n [ACCOUNT_UNINSTALL_VALIDATION_SELECTOR]: \"uninstallValidation\",\n [ACCOUNT_INSTALL_EXECUTION_SELECTOR]: \"installExecution\",\n [ACCOUNT_UNINSTALL_EXECUTION_SELECTOR]: \"uninstallExecution\",\n [ACCOUNT_UPGRADE_TO_AND_CALL_SELECTOR]: \"upgradeToAndCall\",\n};\n\n// Auto-added by translatePermissions when a PREVAL_ALLOWLIST hook exists.\n// Blocked from manual addition to ensure they're only added with proper hook context.\nconst SYSTEM_MANAGED_SELECTORS: Record<string, string> = {\n [ACCOUNT_EXECUTE_SELECTOR]: \"execute\",\n [ACCOUNT_EXECUTEBATCH_SELECTOR]: \"executeBatch\",\n};\n\nfunction assertNotForbiddenSelector(selector: Hex): void {\n const normalized = selector.toLowerCase();\n const match =\n PRIVILEGED_SELECTORS[normalized] ?? SYSTEM_MANAGED_SELECTORS[normalized];\n if (match != null) {\n throw new SelectorNotAllowed(match);\n }\n}\n\nfunction assertNoForbiddenSelectors(selectors: Hex[]): void {\n for (const selector of selectors) {\n assertNotForbiddenSelector(selector);\n }\n}\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 // EntityIds in [HALF_UINT32, uint32.max] overlap the offset namespace used by\n // ERC20 spend-limit and GAS_LIMIT hooks, which would silently corrupt the\n // shared module storage. Reject early.\n if (entityId >= HALF_UINT32) {\n throw new InvalidEntityIdError(entityId, HALF_UINT32 - 1);\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) {\n assertNoForbiddenSelectors(selectors);\n this.selectors = selectors;\n }\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 assertNotForbiddenSelector(selector);\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 assertNoForbiddenSelectors(permission.data.functions);\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 // Offset the entityId so GAS_LIMIT writes to a different slot than\n // NATIVE_TOKEN_TRANSFER on the shared NativeTokenLimitModule.\n rawHooks[HookIdentifier.GAS_LIMIT] = {\n hookConfig: {\n address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,\n entityId: entityId + HALF_UINT32,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId: entityId + HALF_UINT32,\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.30";
1
+ export declare const VERSION = "5.0.0-beta.31";
@@ -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.30";
3
+ export const VERSION = "5.0.0-beta.31";
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.30\";\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.31\";\n"]}
@@ -8,7 +8,8 @@ export declare class InvalidEntityIdError extends BaseError {
8
8
  * Initializes a new instance of the error message with a default message indicating that the entity id is invalid because it's too large.
9
9
  *
10
10
  * @param {number} entityId the invalid entityId used
11
+ * @param {number | bigint} [maxAllowedInclusive] inclusive upper bound the entityId must not exceed. Defaults to `uint32.max`.
11
12
  */
12
- constructor(entityId: number);
13
+ constructor(entityId: number, maxAllowedInclusive?: number | bigint);
13
14
  }
14
15
  //# sourceMappingURL=InvalidEntityIdError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"InvalidEntityIdError.d.ts","sourceRoot":"","sources":["../../../src/errors/InvalidEntityIdError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IACxC,IAAI,SAA0B;IAEvC;;;;OAIG;gBACS,QAAQ,EAAE,MAAM;CAK7B"}
1
+ {"version":3,"file":"InvalidEntityIdError.d.ts","sourceRoot":"","sources":["../../../src/errors/InvalidEntityIdError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IACxC,IAAI,SAA0B;IAEvC;;;;;OAKG;gBAED,QAAQ,EAAE,MAAM,EAChB,mBAAmB,GAAE,MAAM,GAAG,MAAkB;CAMnD"}
@@ -1 +1 @@
1
- {"version":3,"file":"permissionBuilder.d.ts","sourceRoot":"","sources":["../../../src/ma-v2/permissionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAKd,OAAO,EAAY,KAAK,UAAU,EAAyB,MAAM,YAAY,CAAC;AAC9E,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAe3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAkD7D;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;CAajB,CAAC;AAGX,MAAM,MAAM,cA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qB;IAW7B,OAAO,CAAC,oBAAoB;IAkO5B,OAAO,CAAC,QAAQ;CAiCjB"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "5.0.0-beta.30";
1
+ export declare const VERSION = "5.0.0-beta.31";
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.31",
3
+ "version": "5.0.0-beta.32",
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.31",
42
+ "@alchemy/aa-infra": "5.0.0-beta.32",
43
43
  "typescript-template": "workspace:*",
44
44
  "viem": "^2.45.0"
45
45
  },
46
46
  "dependencies": {
47
- "@alchemy/common": "5.0.0-beta.31"
47
+ "@alchemy/common": "5.0.0-beta.32"
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": "1ad684c12e9a610b13b521a4831dc33948c4ef7b"
64
+ "gitHead": "be8a2500d58def53d0ad564248155aaa67f1e532"
65
65
  }
@@ -1,4 +1,5 @@
1
1
  import { BaseError } from "@alchemy/common";
2
+ import { maxUint32 } from "viem";
2
3
 
3
4
  /**
4
5
  * Error class denoting that the provided entity id is invalid because it's too large.
@@ -10,10 +11,14 @@ export class InvalidEntityIdError extends BaseError {
10
11
  * Initializes a new instance of the error message with a default message indicating that the entity id is invalid because it's too large.
11
12
  *
12
13
  * @param {number} entityId the invalid entityId used
14
+ * @param {number | bigint} [maxAllowedInclusive] inclusive upper bound the entityId must not exceed. Defaults to `uint32.max`.
13
15
  */
14
- constructor(entityId: number) {
16
+ constructor(
17
+ entityId: number,
18
+ maxAllowedInclusive: number | bigint = maxUint32,
19
+ ) {
15
20
  super(
16
- `Entity ID used is ${entityId}, but must be less than or equal to uint32.max`,
21
+ `Entity ID used is ${entityId}, but must be less than or equal to ${maxAllowedInclusive}`,
17
22
  );
18
23
  }
19
24
  }
@@ -35,10 +35,14 @@ import {
35
35
  ValidationConfigUnsetError,
36
36
  ZeroAddressError,
37
37
  } from "../errors/permissionBuilderErrors.js";
38
+ import { InvalidEntityIdError } from "../errors/InvalidEntityIdError.js";
38
39
  import type { SmartAccount } from "viem/account-abstraction";
39
40
  import { DefaultModuleAddress, isModularAccountV2 } from "./utils/account.js";
40
41
 
41
- // We use this to offset the ERC20 spend limit entityId
42
+ // Reserved offset for hooks that would otherwise collide on shared module storage
43
+ // (ERC20 spend limit vs PREVAL_ALLOWLIST on AllowlistModule; GAS_LIMIT vs
44
+ // NATIVE_TOKEN_TRANSFER on NativeTokenLimitModule). Any user-supplied entityId
45
+ // must be strictly less than this so the offset namespace stays disjoint.
42
46
  const HALF_UINT32 = 2147483647;
43
47
  const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
44
48
  const ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
@@ -304,6 +308,13 @@ export class PermissionBuilder {
304
308
  throw new AccountNotFoundError();
305
309
  }
306
310
 
311
+ // EntityIds in [HALF_UINT32, uint32.max] overlap the offset namespace used by
312
+ // ERC20 spend-limit and GAS_LIMIT hooks, which would silently corrupt the
313
+ // shared module storage. Reject early.
314
+ if (entityId >= HALF_UINT32) {
315
+ throw new InvalidEntityIdError(entityId, HALF_UINT32 - 1);
316
+ }
317
+
307
318
  this.client = client;
308
319
  this.validationConfig = {
309
320
  moduleAddress: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,
@@ -628,16 +639,18 @@ export class PermissionBuilder {
628
639
  if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {
629
640
  throw new MultipleGasLimitError(permission);
630
641
  }
642
+ // Offset the entityId so GAS_LIMIT writes to a different slot than
643
+ // NATIVE_TOKEN_TRANSFER on the shared NativeTokenLimitModule.
631
644
  rawHooks[HookIdentifier.GAS_LIMIT] = {
632
645
  hookConfig: {
633
646
  address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,
634
- entityId,
647
+ entityId: entityId + HALF_UINT32,
635
648
  hookType: HookType.VALIDATION,
636
649
  hasPreHooks: true,
637
650
  hasPostHooks: false,
638
651
  },
639
652
  initData: {
640
- entityId,
653
+ entityId: entityId + HALF_UINT32,
641
654
  spendLimit: BigInt(permission.data.limit),
642
655
  },
643
656
  };
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.31";
3
+ export const VERSION = "5.0.0-beta.32";