@alchemy/smart-accounts 0.0.0-alpha.5 → 0.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/esm/light-account/accounts/account.d.ts +2 -2
  2. package/dist/esm/light-account/accounts/account.js +4 -4
  3. package/dist/esm/light-account/accounts/account.js.map +1 -1
  4. package/dist/esm/light-account/accounts/base.d.ts +3 -3
  5. package/dist/esm/light-account/accounts/base.js.map +1 -1
  6. package/dist/esm/light-account/accounts/multi-owner-account.d.ts +2 -2
  7. package/dist/esm/light-account/accounts/multi-owner-account.js +3 -3
  8. package/dist/esm/light-account/accounts/multi-owner-account.js.map +1 -1
  9. package/dist/esm/ma-v1/accounts/base.d.ts +3 -3
  10. package/dist/esm/ma-v1/accounts/base.js.map +1 -1
  11. package/dist/esm/ma-v1/accounts/multi-owner-account.d.ts +2 -2
  12. package/dist/esm/ma-v1/accounts/multi-owner-account.js +3 -3
  13. package/dist/esm/ma-v1/accounts/multi-owner-account.js.map +1 -1
  14. package/dist/esm/ma-v2/accounts/account.d.ts +3 -3
  15. package/dist/esm/ma-v2/accounts/account.js +2 -2
  16. package/dist/esm/ma-v2/accounts/account.js.map +1 -1
  17. package/dist/esm/ma-v2/accounts/base.d.ts +3 -3
  18. package/dist/esm/ma-v2/accounts/base.js +6 -1
  19. package/dist/esm/ma-v2/accounts/base.js.map +1 -1
  20. package/dist/esm/types.d.ts +8 -1
  21. package/dist/esm/types.js.map +1 -1
  22. package/dist/types/light-account/accounts/account.d.ts +2 -2
  23. package/dist/types/light-account/accounts/account.d.ts.map +1 -1
  24. package/dist/types/light-account/accounts/base.d.ts +3 -3
  25. package/dist/types/light-account/accounts/base.d.ts.map +1 -1
  26. package/dist/types/light-account/accounts/multi-owner-account.d.ts +2 -2
  27. package/dist/types/light-account/accounts/multi-owner-account.d.ts.map +1 -1
  28. package/dist/types/ma-v1/accounts/base.d.ts +3 -3
  29. package/dist/types/ma-v1/accounts/base.d.ts.map +1 -1
  30. package/dist/types/ma-v1/accounts/multi-owner-account.d.ts +2 -2
  31. package/dist/types/ma-v1/accounts/multi-owner-account.d.ts.map +1 -1
  32. package/dist/types/ma-v2/accounts/account.d.ts +3 -3
  33. package/dist/types/ma-v2/accounts/account.d.ts.map +1 -1
  34. package/dist/types/ma-v2/accounts/base.d.ts +3 -3
  35. package/dist/types/ma-v2/accounts/base.d.ts.map +1 -1
  36. package/dist/types/types.d.ts +8 -1
  37. package/dist/types/types.d.ts.map +1 -1
  38. package/package.json +6 -5
  39. package/src/light-account/accounts/account.ts +5 -7
  40. package/src/light-account/accounts/base.ts +2 -2
  41. package/src/light-account/accounts/multi-owner-account.ts +4 -4
  42. package/src/ma-v1/accounts/base.ts +6 -3
  43. package/src/ma-v1/accounts/multi-owner-account.ts +4 -4
  44. package/src/ma-v2/accounts/account.ts +4 -4
  45. package/src/ma-v2/accounts/base.ts +12 -4
  46. package/src/types.ts +15 -1
@@ -10,7 +10,7 @@ export type ToLightAccountParams<TLightAccountVersion extends LightAccountVersio
10
10
  owner: JsonRpcAccount | LocalAccount;
11
11
  salt?: bigint;
12
12
  accountAddress?: Address;
13
- factoryAddress?: Address;
13
+ factory?: Address;
14
14
  factoryData?: Hex;
15
15
  version?: TLightAccountVersion;
16
16
  };
@@ -20,4 +20,4 @@ export type ToLightAccountParams<TLightAccountVersion extends LightAccountVersio
20
20
  * @param {ToLightAccountParams} param0 - The parameters for creating a light account.
21
21
  * @returns {Promise<LightAccount<TSigner, TLightAccountVersion>>} A light account.
22
22
  */
23
- export declare function toLightAccount<TLightAccountVersion extends LightAccountVersion<"LightAccount"> = LightAccountVersion<"LightAccount">>({ client, owner, salt: salt_, accountAddress: accountAddress_, version, factoryAddress, factoryData: factoryData_, }: ToLightAccountParams<TLightAccountVersion>): Promise<LightAccount<TLightAccountVersion>>;
23
+ export declare function toLightAccount<TLightAccountVersion extends LightAccountVersion<"LightAccount"> = LightAccountVersion<"LightAccount">>({ client, owner, salt: salt_, accountAddress: accountAddress_, version, factory, factoryData: factoryData_, }: ToLightAccountParams<TLightAccountVersion>): Promise<LightAccount<TLightAccountVersion>>;
@@ -17,7 +17,7 @@ import { LOGGER } from "../../logger.js";
17
17
  * @param {ToLightAccountParams} param0 - The parameters for creating a light account.
18
18
  * @returns {Promise<LightAccount<TSigner, TLightAccountVersion>>} A light account.
19
19
  */
20
- export async function toLightAccount({ client, owner, salt: salt_ = 0n, accountAddress: accountAddress_, version = defaultLightAccountVersion(), factoryAddress = AccountVersionRegistry.LightAccount[version].factoryAddress, factoryData: factoryData_, }) {
20
+ export async function toLightAccount({ client, owner, salt: salt_ = 0n, accountAddress: accountAddress_, version = defaultLightAccountVersion(), factory = AccountVersionRegistry.LightAccount[version].factoryAddress, factoryData: factoryData_, }) {
21
21
  LOGGER.debug("toLightAccount:start", {
22
22
  version,
23
23
  hasAccountAddress: !!accountAddress_,
@@ -26,12 +26,12 @@ export async function toLightAccount({ client, owner, salt: salt_ = 0n, accountA
26
26
  const factoryAbi = version === "v2.0.0"
27
27
  ? LightAccountFactoryAbi_v2
28
28
  : LightAccountFactoryAbi_v1;
29
- const salt = LightAccountUnsupported1271Factories.has(lowerAddress(factoryAddress))
29
+ const salt = LightAccountUnsupported1271Factories.has(lowerAddress(factory))
30
30
  ? 0n
31
31
  : salt_;
32
32
  const accountAddress = accountAddress_ ??
33
33
  predictLightAccountAddress({
34
- factoryAddress,
34
+ factoryAddress: factory,
35
35
  salt,
36
36
  ownerAddress: owner.address,
37
37
  version,
@@ -45,7 +45,7 @@ export async function toLightAccount({ client, owner, salt: salt_ = 0n, accountA
45
45
  args: [owner.address, salt],
46
46
  });
47
47
  return {
48
- factory: factoryAddress,
48
+ factory,
49
49
  factoryData,
50
50
  };
51
51
  };
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAQnB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,CAAC;YACF,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC;gBACrC,OAAO,EAAE,cAAc;gBACvB,GAAG,EAAE,UAAU;gBACf,YAAY,EAAE,OAAO;aACtB,CAAC,CAAC;YAEH,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;gBAClB,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;gBAC3D,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;YACtD,CAAC;YAED,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YACnD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,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 Transport,\n} from \"viem\";\nimport { readContract } from \"viem/actions\";\nimport { LightAccountAbi_v1 } from \"../abis/LightAccountAbi_v1.js\";\nimport { LightAccountAbi_v2 } from \"../abis/LightAccountAbi_v2.js\";\nimport { LightAccountFactoryAbi_v1 } from \"../abis/LightAccountFactoryAbi_v1.js\";\nimport { LightAccountFactoryAbi_v2 } from \"../abis/LightAccountFactoryAbi_v2.js\";\nimport { predictLightAccountAddress } from \"../predictAddress.js\";\nimport {\n type LightAccountVersion,\n AccountVersionRegistry,\n} from \"../registry.js\";\nimport {\n LightAccountUnsupported1271Factories,\n defaultLightAccountVersion,\n} from \"../utils.js\";\nimport { toLightAccountBase, type LightAccountBase } from \"./base.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport { getAction } from \"viem/utils\";\nimport { LOGGER } from \"../../logger.js\";\n\nexport type LightAccount<\n TLightAccountVersion extends\n LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">,\n> = LightAccountBase<\"LightAccount\", TLightAccountVersion> & {\n encodeTransferOwnership: (newOwner: Address) => Hex;\n getOwnerAddress: () => Promise<Address>;\n};\n\nexport type ToLightAccountParams<\n TLightAccountVersion extends\n LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n salt?: bigint;\n accountAddress?: Address;\n factoryAddress?: Address;\n factoryData?: Hex;\n version?: TLightAccountVersion;\n};\n\n/**\n * Creates a light account.\n *\n * @param {ToLightAccountParams} param0 - The parameters for creating a light account.\n * @returns {Promise<LightAccount<TSigner, TLightAccountVersion>>} A light account.\n */\nexport async function toLightAccount<\n TLightAccountVersion extends\n LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">,\n>({\n client,\n owner,\n salt: salt_ = 0n,\n accountAddress: accountAddress_,\n version = defaultLightAccountVersion() as TLightAccountVersion,\n factoryAddress = AccountVersionRegistry.LightAccount[version].factoryAddress,\n factoryData: factoryData_,\n}: ToLightAccountParams<TLightAccountVersion>): Promise<\n LightAccount<TLightAccountVersion>\n> {\n LOGGER.debug(\"toLightAccount:start\", {\n version,\n hasAccountAddress: !!accountAddress_,\n });\n\n const accountAbi =\n version === \"v2.0.0\" ? LightAccountAbi_v2 : LightAccountAbi_v1;\n const factoryAbi =\n version === \"v2.0.0\"\n ? LightAccountFactoryAbi_v2\n : LightAccountFactoryAbi_v1;\n\n const salt = LightAccountUnsupported1271Factories.has(\n lowerAddress(factoryAddress),\n )\n ? 0n\n : salt_;\n\n const accountAddress =\n accountAddress_ ??\n predictLightAccountAddress({\n factoryAddress,\n salt,\n ownerAddress: owner.address,\n version,\n });\n\n LOGGER.debug(\"toLightAccount:address-resolved\", { accountAddress });\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: factoryAbi,\n functionName: \"createAccount\",\n args: [owner.address, salt],\n });\n\n return {\n factory: factoryAddress,\n factoryData,\n };\n };\n\n const baseAccount = await toLightAccountBase({\n client,\n owner,\n abi: accountAbi,\n accountAddress,\n type: \"LightAccount\",\n version,\n getFactoryArgs,\n });\n\n return {\n ...baseAccount,\n\n encodeTransferOwnership: (newOwner: Address) => {\n return encodeFunctionData({\n abi: accountAbi,\n functionName: \"transferOwnership\",\n args: [newOwner],\n });\n },\n\n async getOwnerAddress(): Promise<Address> {\n LOGGER.debug(\"getOwnerAddress:start\", { accountAddress });\n const readContractAction = getAction(\n client,\n readContract,\n \"readContract\",\n );\n const owner = await readContractAction({\n address: accountAddress,\n abi: accountAbi,\n functionName: \"owner\",\n });\n\n if (owner == null) {\n LOGGER.error(\"getOwnerAddress:failed\", { accountAddress });\n throw new BaseError(\"could not get on-chain owner\");\n }\n\n LOGGER.debug(\"getOwnerAddress:success\", { owner });\n return owner;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAQnB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAEL,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,oCAAoC,EACpC,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAyB,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,MAAM,EAA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AAW;SACZ,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,kBAAkB,CAAC;QAC3C,MAAM;QACN,KAAK;QACL,GAAG,EAAE,UAAU;QACf,cAAc;QACd,IAAI,EAAE,cAAc;QACpB,OAAO;QACP,cAAc;KACf,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,WAAW;QAEd,uBAAuB,EAAE,CAAC,QAAiB,EAAE,EAAE;YAC7C,OAAO,kBAAkB,CAAC;gBACxB,GAAG,EAAE,UAAU;gBACf,YAAY,EAAE,mBAAmB;gBACjC,IAAI,EAAE,CAAC,QAAQ,CAAC;aACjB,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,eAAe;YACnB,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;YAC1D,MAAM,kBAAkB,GAAG,SAAS,CAClC,MAAM,EACN,YAAY,EACZ,cAAc,CACf,CAAC;YACF,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC;gBACrC,OAAO,EAAE,cAAc;gBACvB,GAAG,EAAE,UAAU;gBACf,YAAY,EAAE,OAAO;aACtB,CAAC,CAAC;YAEH,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;gBAClB,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;gBAC3D,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;YACtD,CAAC;YAED,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YACnD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,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 Transport,\n} from \"viem\";\nimport { readContract } from \"viem/actions\";\nimport { LightAccountAbi_v1 } from \"../abis/LightAccountAbi_v1.js\";\nimport { LightAccountAbi_v2 } from \"../abis/LightAccountAbi_v2.js\";\nimport { LightAccountFactoryAbi_v1 } from \"../abis/LightAccountFactoryAbi_v1.js\";\nimport { LightAccountFactoryAbi_v2 } from \"../abis/LightAccountFactoryAbi_v2.js\";\nimport { predictLightAccountAddress } from \"../predictAddress.js\";\nimport {\n type LightAccountVersion,\n AccountVersionRegistry,\n} from \"../registry.js\";\nimport {\n LightAccountUnsupported1271Factories,\n defaultLightAccountVersion,\n} from \"../utils.js\";\nimport { toLightAccountBase, type LightAccountBase } from \"./base.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport { getAction } from \"viem/utils\";\nimport { LOGGER } from \"../../logger.js\";\n\nexport type LightAccount<\n TLightAccountVersion extends\n LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">,\n> = LightAccountBase<\"LightAccount\", TLightAccountVersion> & {\n encodeTransferOwnership: (newOwner: Address) => Hex;\n getOwnerAddress: () => Promise<Address>;\n};\n\nexport type ToLightAccountParams<\n TLightAccountVersion extends\n LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n salt?: bigint;\n accountAddress?: Address;\n factory?: Address;\n factoryData?: Hex;\n version?: TLightAccountVersion;\n};\n\n/**\n * Creates a light account.\n *\n * @param {ToLightAccountParams} param0 - The parameters for creating a light account.\n * @returns {Promise<LightAccount<TSigner, TLightAccountVersion>>} A light account.\n */\nexport async function toLightAccount<\n TLightAccountVersion extends\n LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">,\n>({\n client,\n owner,\n salt: salt_ = 0n,\n accountAddress: accountAddress_,\n version = defaultLightAccountVersion() as TLightAccountVersion,\n factory = AccountVersionRegistry.LightAccount[version].factoryAddress,\n factoryData: factoryData_,\n}: ToLightAccountParams<TLightAccountVersion>): Promise<\n LightAccount<TLightAccountVersion>\n> {\n LOGGER.debug(\"toLightAccount:start\", {\n version,\n hasAccountAddress: !!accountAddress_,\n });\n\n const accountAbi =\n version === \"v2.0.0\" ? LightAccountAbi_v2 : LightAccountAbi_v1;\n const factoryAbi =\n version === \"v2.0.0\"\n ? LightAccountFactoryAbi_v2\n : LightAccountFactoryAbi_v1;\n\n const salt = LightAccountUnsupported1271Factories.has(lowerAddress(factory))\n ? 0n\n : salt_;\n\n const accountAddress =\n accountAddress_ ??\n predictLightAccountAddress({\n factoryAddress: factory,\n salt,\n ownerAddress: owner.address,\n version,\n });\n\n LOGGER.debug(\"toLightAccount:address-resolved\", { accountAddress });\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: factoryAbi,\n functionName: \"createAccount\",\n args: [owner.address, salt],\n });\n\n return {\n factory,\n factoryData,\n };\n };\n\n const baseAccount = await toLightAccountBase({\n client,\n owner,\n abi: accountAbi,\n accountAddress,\n type: \"LightAccount\",\n version,\n getFactoryArgs,\n });\n\n return {\n ...baseAccount,\n\n encodeTransferOwnership: (newOwner: Address) => {\n return encodeFunctionData({\n abi: accountAbi,\n functionName: \"transferOwnership\",\n args: [newOwner],\n });\n },\n\n async getOwnerAddress(): Promise<Address> {\n LOGGER.debug(\"getOwnerAddress:start\", { accountAddress });\n const readContractAction = getAction(\n client,\n readContract,\n \"readContract\",\n );\n const owner = await readContractAction({\n address: accountAddress,\n abi: accountAbi,\n functionName: \"owner\",\n });\n\n if (owner == null) {\n LOGGER.error(\"getOwnerAddress:failed\", { accountAddress });\n throw new BaseError(\"could not get on-chain owner\");\n }\n\n LOGGER.debug(\"getOwnerAddress:success\", { owner });\n return owner;\n },\n };\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { type Abi, type Address, type Chain, type Client, type Hex, type JsonRpcAccount, type LocalAccount, type Transport } from "viem";
2
- import { type SmartAccount, type SmartAccountImplementation } from "viem/account-abstraction";
2
+ import { type SmartAccountImplementation } from "viem/account-abstraction";
3
3
  import type { EntryPointFromAccountRegistry, LightAccountType, LightAccountVersion } from "../registry.js";
4
- import type { SignatureRequest } from "../../types.js";
4
+ import type { SignatureRequest, SmartAccountWithDecodeCalls } from "../../types.js";
5
5
  export type BaseLightAccountImplementation<TLightAccountType extends LightAccountType = LightAccountType, TLightAccountVersion extends LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>> = SmartAccountImplementation<EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>["abi"], EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>["version"], {
6
6
  getLightAccountVersion: () => TLightAccountVersion;
7
7
  smartAccountType: TLightAccountType;
@@ -12,7 +12,7 @@ export type BaseLightAccountImplementation<TLightAccountType extends LightAccoun
12
12
  prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;
13
13
  formatSignature: (signature: Hex) => Promise<Hex>;
14
14
  }, false>;
15
- export type LightAccountBase<TLightAccountType extends LightAccountType = LightAccountType, TLightAccountVersion extends LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>> = SmartAccount<BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>>;
15
+ export type LightAccountBase<TLightAccountType extends LightAccountType = LightAccountType, TLightAccountVersion extends LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>> = SmartAccountWithDecodeCalls<BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>>;
16
16
  export type ToLightAccountBaseParams<TLightAccountType extends LightAccountType, TLightAccountVersion extends LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>, TTransport extends Transport = Transport> = {
17
17
  client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;
18
18
  abi: Abi;
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,aAAa,EACb,IAAI,G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F,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n concat,\n concatHex,\n encodeFunctionData,\n fromHex,\n hashMessage,\n hashTypedData,\n trim,\n type Abi,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n getUserOperationHash,\n toSmartAccount,\n type SmartAccount,\n type SmartAccountImplementation,\n} from \"viem/account-abstraction\";\nimport { getStorageAt, signMessage, signTypedData } from \"viem/actions\";\nimport type {\n EntryPointFromAccountRegistry,\n LightAccountType,\n LightAccountVersion,\n} from \"../registry.js\";\nimport { EIP1967_PROXY_IMPL_STORAGE_SLOT } from \"../utils.js\";\nimport { AccountVersionRegistry } from \"../registry.js\";\nimport {\n encodeCallsLA as encodeCalls,\n decodeCallsLA as decodeCalls,\n} from \"./calldataCodec.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport type {\n SignatureRequest,\n StaticSmartAccountImplementation,\n} from \"../../types.js\";\nimport { getAction } from \"viem/utils\";\n\nconst SignaturePrefix = {\n EOA: \"0x00\",\n CONTRACT: \"0x01\",\n CONTRACT_WITH_ADDR: \"0x02\",\n} as const;\n\nexport type BaseLightAccountImplementation<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountImplementation<\n EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>[\"abi\"],\n EntryPointFromAccountRegistry<\n TLightAccountType,\n TLightAccountVersion\n >[\"version\"],\n {\n getLightAccountVersion: () => TLightAccountVersion;\n smartAccountType: TLightAccountType;\n encodeUpgradeToAndCall: (params: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }) => Promise<Hex>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type LightAccountBase<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccount<\n BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>\n>;\n\nexport type ToLightAccountBaseParams<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n abi: Abi;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n type: TLightAccountType;\n version: TLightAccountVersion;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n};\n\nexport async function toLightAccountBase<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n>({\n client,\n abi,\n accountAddress,\n owner,\n type,\n version,\n getFactoryArgs,\n}: ToLightAccountBaseParams<\n TLightAccountType,\n TLightAccountVersion,\n TTransport\n>): Promise<LightAccountBase<TLightAccountType, TLightAccountVersion>> {\n const encodeUpgradeToAndCall = async ({\n upgradeToAddress,\n upgradeToInitData,\n }: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }): Promise<Hex> => {\n const expectedImplAddresses = (\n Object.values(\n AccountVersionRegistry[type],\n ) as StaticSmartAccountImplementation<false>[]\n ).map((x) => x.accountImplementation);\n\n const getStorageAtAction = getAction(client, getStorageAt, \"getStorageAt\");\n // TODO(v5): This is a super fragile workflow, and we should consider not supporting this on the SmartAccount level in v5.\n const storage = await getStorageAtAction({\n address: accountAddress,\n slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,\n });\n\n if (storage == null) {\n throw new BaseError(\n `Failed to get storage slot: ${EIP1967_PROXY_IMPL_STORAGE_SLOT}`,\n );\n }\n\n // Only upgrade undeployed accounts (storage 0) or deployed light accounts, else error.\n if (\n fromHex(storage, \"number\") !== 0 &&\n !expectedImplAddresses.some((x) => x === lowerAddress(trim(storage)))\n ) {\n throw new BaseError(\n `could not determine if smart account implementation is ${type} ${String(\n version,\n )}`,\n );\n }\n\n return encodeFunctionData({\n abi,\n functionName: \"upgradeToAndCall\",\n args: [upgradeToAddress, upgradeToInitData],\n });\n };\n\n const get1271Wrapper = (\n hashedMessage: Hex,\n version: string,\n ): TypedDataDefinition => {\n return {\n // EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\n // https://github.com/alchemyplatform/light-account/blob/main/src/LightAccount.sol#L236\n domain: {\n chainId: client.chain.id,\n name: type,\n verifyingContract: accountAddress,\n version,\n },\n types: {\n LightAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: hashedMessage,\n },\n primaryType: \"LightAccountMessage\",\n };\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const messageHash =\n params.type === \"eth_signTypedData_v4\"\n ? hashTypedData(params.data)\n : hashMessage(params.data);\n\n switch (version) {\n case \"v1.0.1\":\n return params;\n case \"v1.0.2\":\n throw new BaseError(\n `Version ${String(version)} of LightAccount doesn't support 1271`,\n );\n case \"v1.1.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"1\"),\n };\n case \"v2.0.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"2\"),\n };\n default:\n throw new BaseError(\n `Unknown version ${String(version)} of LightAccount`,\n );\n }\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return version === \"v2.0.0\"\n ? concat([SignaturePrefix.EOA, signature])\n : signature;\n };\n\n const entryPoint = (\n AccountVersionRegistry[type][version] as StaticSmartAccountImplementation\n ).entryPoint;\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n return encodeCalls(calls);\n },\n\n async decodeCalls(data) {\n return decodeCalls(data, accountAddress);\n },\n\n async getStubSignature() {\n const signature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n return signature;\n case \"v2.0.0\":\n return concat([SignaturePrefix.EOA, signature]);\n default:\n throw new BaseError(`Unknown version ${type} of ${String(version)}`);\n }\n },\n\n async signMessage({ message }) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signTypedData(params) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n const userOpHash = getUserOperationHash({\n chainId,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const signature = await signMessageAction({\n account: owner,\n message: { raw: userOpHash },\n });\n\n return version === \"v2.0.0\"\n ? concatHex([SignaturePrefix.EOA, signature])\n : signature;\n },\n\n extend: {\n smartAccountType: type,\n getLightAccountVersion: () => version,\n encodeUpgradeToAndCall,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,aAAa,EACb,IAAI,GAUL,MAAM,MAAM,CAAC;AACd,OAAO,EACL,oBAAoB,EACpB,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAMxE,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EACL,aAAa,IAAI,WAAW,EAC5B,aAAa,IAAI,WAAW,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,MAAM;IACX,QAAQ,EAAE,MAAM;IAChB,kBAAkB,EAAE,MAAM;CAClB,CAAC;AAmDX,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAKtC,EACA,MAAM,EACN,GAAG,EACH,cAAc,EACd,KAAK,EACL,IAAI,EACJ,OAAO,EACP,cAAc,GAKf;IACC,MAAM,sBAAsB,GAAG,KAAK,EAAE,EACpC,gBAAgB,EAChB,iBAAiB,GAIlB,EAAgB,EAAE;QACjB,MAAM,qBAAqB,GACzB,MAAM,CAAC,MAAM,CACX,sBAAsB,CAAC,IAAI,CAAC,CAE/B,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC;QAEtC,MAAM,kBAAkB,GAAG,SAAS,C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SAAS,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;gBAC7C,CAAC,CAAC,SAAS,CAAC;QAChB,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,IAAI;YACtB,sBAAsB,EAAE,GAAG,EAAE,CAAC,OAAO;YACrC,sBAAsB;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n concat,\n concatHex,\n encodeFunctionData,\n fromHex,\n hashMessage,\n hashTypedData,\n trim,\n type Abi,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n getUserOperationHash,\n toSmartAccount,\n type SmartAccountImplementation,\n} from \"viem/account-abstraction\";\nimport { getStorageAt, signMessage, signTypedData } from \"viem/actions\";\nimport type {\n EntryPointFromAccountRegistry,\n LightAccountType,\n LightAccountVersion,\n} from \"../registry.js\";\nimport { EIP1967_PROXY_IMPL_STORAGE_SLOT } from \"../utils.js\";\nimport { AccountVersionRegistry } from \"../registry.js\";\nimport {\n encodeCallsLA as encodeCalls,\n decodeCallsLA as decodeCalls,\n} from \"./calldataCodec.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport type {\n SignatureRequest,\n StaticSmartAccountImplementation,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { getAction } from \"viem/utils\";\n\nconst SignaturePrefix = {\n EOA: \"0x00\",\n CONTRACT: \"0x01\",\n CONTRACT_WITH_ADDR: \"0x02\",\n} as const;\n\nexport type BaseLightAccountImplementation<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountImplementation<\n EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>[\"abi\"],\n EntryPointFromAccountRegistry<\n TLightAccountType,\n TLightAccountVersion\n >[\"version\"],\n {\n getLightAccountVersion: () => TLightAccountVersion;\n smartAccountType: TLightAccountType;\n encodeUpgradeToAndCall: (params: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }) => Promise<Hex>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type LightAccountBase<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountWithDecodeCalls<\n BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>\n>;\n\nexport type ToLightAccountBaseParams<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n abi: Abi;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n type: TLightAccountType;\n version: TLightAccountVersion;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n};\n\nexport async function toLightAccountBase<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n>({\n client,\n abi,\n accountAddress,\n owner,\n type,\n version,\n getFactoryArgs,\n}: ToLightAccountBaseParams<\n TLightAccountType,\n TLightAccountVersion,\n TTransport\n>): Promise<LightAccountBase<TLightAccountType, TLightAccountVersion>> {\n const encodeUpgradeToAndCall = async ({\n upgradeToAddress,\n upgradeToInitData,\n }: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }): Promise<Hex> => {\n const expectedImplAddresses = (\n Object.values(\n AccountVersionRegistry[type],\n ) as StaticSmartAccountImplementation<false>[]\n ).map((x) => x.accountImplementation);\n\n const getStorageAtAction = getAction(client, getStorageAt, \"getStorageAt\");\n // TODO(v5): This is a super fragile workflow, and we should consider not supporting this on the SmartAccount level in v5.\n const storage = await getStorageAtAction({\n address: accountAddress,\n slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,\n });\n\n if (storage == null) {\n throw new BaseError(\n `Failed to get storage slot: ${EIP1967_PROXY_IMPL_STORAGE_SLOT}`,\n );\n }\n\n // Only upgrade undeployed accounts (storage 0) or deployed light accounts, else error.\n if (\n fromHex(storage, \"number\") !== 0 &&\n !expectedImplAddresses.some((x) => x === lowerAddress(trim(storage)))\n ) {\n throw new BaseError(\n `could not determine if smart account implementation is ${type} ${String(\n version,\n )}`,\n );\n }\n\n return encodeFunctionData({\n abi,\n functionName: \"upgradeToAndCall\",\n args: [upgradeToAddress, upgradeToInitData],\n });\n };\n\n const get1271Wrapper = (\n hashedMessage: Hex,\n version: string,\n ): TypedDataDefinition => {\n return {\n // EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\n // https://github.com/alchemyplatform/light-account/blob/main/src/LightAccount.sol#L236\n domain: {\n chainId: client.chain.id,\n name: type,\n verifyingContract: accountAddress,\n version,\n },\n types: {\n LightAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: hashedMessage,\n },\n primaryType: \"LightAccountMessage\",\n };\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const messageHash =\n params.type === \"eth_signTypedData_v4\"\n ? hashTypedData(params.data)\n : hashMessage(params.data);\n\n switch (version) {\n case \"v1.0.1\":\n return params;\n case \"v1.0.2\":\n throw new BaseError(\n `Version ${String(version)} of LightAccount doesn't support 1271`,\n );\n case \"v1.1.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"1\"),\n };\n case \"v2.0.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"2\"),\n };\n default:\n throw new BaseError(\n `Unknown version ${String(version)} of LightAccount`,\n );\n }\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return version === \"v2.0.0\"\n ? concat([SignaturePrefix.EOA, signature])\n : signature;\n };\n\n const entryPoint = (\n AccountVersionRegistry[type][version] as StaticSmartAccountImplementation\n ).entryPoint;\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n return encodeCalls(calls);\n },\n\n async decodeCalls(data) {\n return decodeCalls(data, accountAddress);\n },\n\n async getStubSignature() {\n const signature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n return signature;\n case \"v2.0.0\":\n return concat([SignaturePrefix.EOA, signature]);\n default:\n throw new BaseError(`Unknown version ${type} of ${String(version)}`);\n }\n },\n\n async signMessage({ message }) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signTypedData(params) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n const userOpHash = getUserOperationHash({\n chainId,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const signature = await signMessageAction({\n account: owner,\n message: { raw: userOpHash },\n });\n\n return version === \"v2.0.0\"\n ? concatHex([SignaturePrefix.EOA, signature])\n : signature;\n },\n\n extend: {\n smartAccountType: type,\n getLightAccountVersion: () => version,\n encodeUpgradeToAndCall,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
@@ -11,7 +11,7 @@ export type ToMultiOwnerLightAccountParams = {
11
11
  }[]];
12
12
  salt?: bigint;
13
13
  accountAddress?: Address;
14
- factoryAddress?: Address;
14
+ factory?: Address;
15
15
  factoryData?: Hex;
16
16
  };
17
17
  /**
@@ -20,4 +20,4 @@ export type ToMultiOwnerLightAccountParams = {
20
20
  * @param {ToMultiOwnerLightAccountParams} param0 - The parameters for creating a multi-owner light account.
21
21
  * @returns {Promise<MultiOwnerLightAccount<TSigner>>} A multi-owner light account.
22
22
  */
23
- export declare function toMultiOwnerLightAccount({ client, salt, owners, accountAddress: accountAddress_, factoryAddress, factoryData: factoryData_, }: ToMultiOwnerLightAccountParams): Promise<MultiOwnerLightAccount>;
23
+ export declare function toMultiOwnerLightAccount({ client, salt, owners, accountAddress: accountAddress_, factory, factoryData: factoryData_, }: ToMultiOwnerLightAccountParams): Promise<MultiOwnerLightAccount>;
@@ -13,7 +13,7 @@ import { AccountVersionRegistry } from "../registry.js";
13
13
  * @param {ToMultiOwnerLightAccountParams} param0 - The parameters for creating a multi-owner light account.
14
14
  * @returns {Promise<MultiOwnerLightAccount<TSigner>>} A multi-owner light account.
15
15
  */
16
- export async function toMultiOwnerLightAccount({ client, salt = 0n, owners, accountAddress: accountAddress_, factoryAddress = AccountVersionRegistry.MultiOwnerLightAccount["v2.0.0"]
16
+ export async function toMultiOwnerLightAccount({ client, salt = 0n, owners, accountAddress: accountAddress_, factory = AccountVersionRegistry.MultiOwnerLightAccount["v2.0.0"]
17
17
  .factoryAddress, factoryData: factoryData_, }) {
18
18
  const signer = owners[0];
19
19
  const dedupedOwners = Array.from(new Set(owners.map((it) => lowerAddress(it.address))));
@@ -24,7 +24,7 @@ export async function toMultiOwnerLightAccount({ client, salt = 0n, owners, acco
24
24
  });
25
25
  const accountAddress = accountAddress_ ??
26
26
  predictMultiOwnerLightAccountAddress({
27
- factoryAddress,
27
+ factoryAddress: factory,
28
28
  salt,
29
29
  ownerAddresses: sortedOwners,
30
30
  });
@@ -36,7 +36,7 @@ export async function toMultiOwnerLightAccount({ client, salt = 0n, owners, acco
36
36
  args: [sortedOwners, salt],
37
37
  });
38
38
  return {
39
- factory: factoryAddress,
39
+ factory,
40
40
  factoryData,
41
41
  };
42
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"multi-owner-account.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/multi-owner-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,WAAW,GASZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAC;AAC/F,OAAO,EAAE,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAyB,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAsBxD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,EAC7C,MAAM,EACN,IAAI,GAAG,EAAE,EACT,MAAM,EACN,cAAc,EAAE,eAAe,EAC/B,cAAc,GAAG,sB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,wBAAwB;QAC9B,OAAO,EAAE,QAAQ;QACjB,cAAc;KACf,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,WAAW;QAEd,kBAAkB,EAAE,CAAC,WAAsB,EAAE,cAAyB,EAAE,EAAE;YACxE,OAAO,kBAAkB,CAAC;gBACxB,GAAG,EAAE,yBAAyB;gBAC9B,YAAY,EAAE,cAAc;gBAC5B,IAAI,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC;aACpC,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,iBAAiB;YACrB,MAAM,kBAAkB,GAAG,SAAS,CAClC,MAAM,EACN,YAAY,EACZ,cAAc,CACf,CAAC;YACF,MAAM,aAAa,GAAG,MAAM,kBAAkB,CAAC;gBAC7C,OAAO,EAAE,cAAc;gBACvB,GAAG,EAAE,yBAAyB;gBAC9B,YAAY,EAAE,QAAQ;aACvB,CAAC,CAAC;YAEH,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;gBAC1B,MAAM,IAAI,SAAS,CAAC,+BAA+B,CAAC,CAAC;YACvD,CAAC;YAED,IACE,CAAC,aAAa;iBACX,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;iBAC7B,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EACzC,CAAC;gBACD,MAAM,IAAI,SAAS,CACjB,qDAAqD,CACtD,CAAC;YACJ,CAAC;YAED,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n encodeFunctionData,\n hexToBigInt,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type OneOf,\n type Transport,\n} from \"viem\";\nimport { readContract } from \"viem/actions\";\nimport { MultiOwnerLightAccountAbi } from \"../abis/MultiOwnerLightAccountAbi.js\";\nimport { MultiOwnerLightAccountFactoryAbi } from \"../abis/MultiOwnerLightAccountFactoryAbi.js\";\nimport { predictMultiOwnerLightAccountAddress } from \"../predictAddress.js\";\nimport { toLightAccountBase, type LightAccountBase } from \"./base.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport { getAction } from \"viem/utils\";\nimport { AccountVersionRegistry } from \"../registry.js\";\n\nexport type MultiOwnerLightAccount = LightAccountBase<\n \"MultiOwnerLightAccount\",\n \"v2.0.0\"\n> & {\n encodeUpdateOwners: (\n ownersToAdd: Address[],\n ownersToRemove: Address[],\n ) => Hex;\n getOwnerAddresses: () => Promise<readonly Address[]>;\n};\n\nexport type ToMultiOwnerLightAccountParams = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{ address: Address }[]];\n salt?: bigint;\n accountAddress?: Address;\n factoryAddress?: Address;\n factoryData?: Hex;\n};\n\n/**\n * Creates a multi-owner light account.\n *\n * @param {ToMultiOwnerLightAccountParams} param0 - The parameters for creating a multi-owner light account.\n * @returns {Promise<MultiOwnerLightAccount<TSigner>>} A multi-owner light account.\n */\nexport async function toMultiOwnerLightAccount({\n client,\n salt = 0n,\n owners,\n accountAddress: accountAddress_,\n factoryAddress = AccountVersionRegistry.MultiOwnerLightAccount[\"v2.0.0\"]\n .factoryAddress,\n factoryData: factoryData_,\n}: ToMultiOwnerLightAccountParams): Promise<MultiOwnerLightAccount> {\n const signer = owners[0];\n\n const dedupedOwners = Array.from(\n new Set(owners.map((it) => lowerAddress(it.address))),\n );\n\n const sortedOwners = dedupedOwners.sort((a, b) => {\n const bigintA = hexToBigInt(a);\n const bigintB = hexToBigInt(b);\n return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;\n });\n\n const accountAddress =\n accountAddress_ ??\n predictMultiOwnerLightAccountAddress({\n factoryAddress,\n salt,\n ownerAddresses: sortedOwners,\n });\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: MultiOwnerLightAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [sortedOwners, salt],\n });\n\n return {\n factory: factoryAddress,\n factoryData,\n };\n };\n\n const baseAccount = await toLightAccountBase({\n client,\n owner: signer,\n abi: MultiOwnerLightAccountAbi,\n accountAddress,\n type: \"MultiOwnerLightAccount\",\n version: \"v2.0.0\",\n getFactoryArgs,\n });\n\n return {\n ...baseAccount,\n\n encodeUpdateOwners: (ownersToAdd: Address[], ownersToRemove: Address[]) => {\n return encodeFunctionData({\n abi: MultiOwnerLightAccountAbi,\n functionName: \"updateOwners\",\n args: [ownersToAdd, ownersToRemove],\n });\n },\n\n async getOwnerAddresses(): Promise<readonly Address[]> {\n const readContractAction = getAction(\n client,\n readContract,\n \"readContract\",\n );\n const ownersOnChain = await readContractAction({\n address: accountAddress,\n abi: MultiOwnerLightAccountAbi,\n functionName: \"owners\",\n });\n\n if (ownersOnChain == null) {\n throw new BaseError(\"could not get on-chain owners\");\n }\n\n if (\n !ownersOnChain\n .map((it) => lowerAddress(it))\n .includes(lowerAddress(signer.address))\n ) {\n throw new BaseError(\n \"on-chain owners does not include the current signer\",\n );\n }\n\n return ownersOnChain;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"multi-owner-account.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/multi-owner-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,WAAW,GASZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAC;AAC/F,OAAO,EAAE,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAyB,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,C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Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type OneOf,\n type Transport,\n} from \"viem\";\nimport { readContract } from \"viem/actions\";\nimport { MultiOwnerLightAccountAbi } from \"../abis/MultiOwnerLightAccountAbi.js\";\nimport { MultiOwnerLightAccountFactoryAbi } from \"../abis/MultiOwnerLightAccountFactoryAbi.js\";\nimport { predictMultiOwnerLightAccountAddress } from \"../predictAddress.js\";\nimport { toLightAccountBase, type LightAccountBase } from \"./base.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport { getAction } from \"viem/utils\";\nimport { AccountVersionRegistry } from \"../registry.js\";\n\nexport type MultiOwnerLightAccount = LightAccountBase<\n \"MultiOwnerLightAccount\",\n \"v2.0.0\"\n> & {\n encodeUpdateOwners: (\n ownersToAdd: Address[],\n ownersToRemove: Address[],\n ) => Hex;\n getOwnerAddresses: () => Promise<readonly Address[]>;\n};\n\nexport type ToMultiOwnerLightAccountParams = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{ address: Address }[]];\n salt?: bigint;\n accountAddress?: Address;\n factory?: Address;\n factoryData?: Hex;\n};\n\n/**\n * Creates a multi-owner light account.\n *\n * @param {ToMultiOwnerLightAccountParams} param0 - The parameters for creating a multi-owner light account.\n * @returns {Promise<MultiOwnerLightAccount<TSigner>>} A multi-owner light account.\n */\nexport async function toMultiOwnerLightAccount({\n client,\n salt = 0n,\n owners,\n accountAddress: accountAddress_,\n factory = AccountVersionRegistry.MultiOwnerLightAccount[\"v2.0.0\"]\n .factoryAddress,\n factoryData: factoryData_,\n}: ToMultiOwnerLightAccountParams): Promise<MultiOwnerLightAccount> {\n const signer = owners[0];\n\n const dedupedOwners = Array.from(\n new Set(owners.map((it) => lowerAddress(it.address))),\n );\n\n const sortedOwners = dedupedOwners.sort((a, b) => {\n const bigintA = hexToBigInt(a);\n const bigintB = hexToBigInt(b);\n return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;\n });\n\n const accountAddress =\n accountAddress_ ??\n predictMultiOwnerLightAccountAddress({\n factoryAddress: factory,\n salt,\n ownerAddresses: sortedOwners,\n });\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: MultiOwnerLightAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [sortedOwners, salt],\n });\n\n return {\n factory,\n factoryData,\n };\n };\n\n const baseAccount = await toLightAccountBase({\n client,\n owner: signer,\n abi: MultiOwnerLightAccountAbi,\n accountAddress,\n type: \"MultiOwnerLightAccount\",\n version: \"v2.0.0\",\n getFactoryArgs,\n });\n\n return {\n ...baseAccount,\n\n encodeUpdateOwners: (ownersToAdd: Address[], ownersToRemove: Address[]) => {\n return encodeFunctionData({\n abi: MultiOwnerLightAccountAbi,\n functionName: \"updateOwners\",\n args: [ownersToAdd, ownersToRemove],\n });\n },\n\n async getOwnerAddresses(): Promise<readonly Address[]> {\n const readContractAction = getAction(\n client,\n readContract,\n \"readContract\",\n );\n const ownersOnChain = await readContractAction({\n address: accountAddress,\n abi: MultiOwnerLightAccountAbi,\n functionName: \"owners\",\n });\n\n if (ownersOnChain == null) {\n throw new BaseError(\"could not get on-chain owners\");\n }\n\n if (\n !ownersOnChain\n .map((it) => lowerAddress(it))\n .includes(lowerAddress(signer.address))\n ) {\n throw new BaseError(\n \"on-chain owners does not include the current signer\",\n );\n }\n\n return ownersOnChain;\n },\n };\n}\n"]}
@@ -1,13 +1,13 @@
1
1
  import { type Address, type Chain, type Client, type Hex, type JsonRpcAccount, type LocalAccount, type Transport, type Hash, type TypedDataDefinition } from "viem";
2
- import { entryPoint06Abi, type SmartAccount, type SmartAccountImplementation } from "viem/account-abstraction";
3
- import type { SignatureRequest } from "../../types.js";
2
+ import { entryPoint06Abi, type SmartAccountImplementation } from "viem/account-abstraction";
3
+ import type { SignatureRequest, SmartAccountWithDecodeCalls } from "../../types.js";
4
4
  type MaV1AccountType = "MultiOwnerModularAccountV1";
5
5
  export type BaseMaV1AccountImplementation = SmartAccountImplementation<typeof entryPoint06Abi, "0.6", {
6
6
  smartAccountType: MaV1AccountType;
7
7
  prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;
8
8
  formatSignature: (signature: Hex) => Promise<Hex>;
9
9
  }, false>;
10
- export type ModularAccountV1Base = SmartAccount<BaseMaV1AccountImplementation>;
10
+ export type ModularAccountV1Base = SmartAccountWithDecodeCalls<BaseMaV1AccountImplementation>;
11
11
  export type ToModularAccountV1BaseParams<TTransport extends Transport = Transport> = {
12
12
  client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;
13
13
  accountAddress: Address;
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v1/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,kBAAkB,GACnB,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EACf,cAAc,EAGd,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA+B5C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAE1C,EACA,MAAM,EACN,cAAc,EACd,KAAK,EACL,cAAc,EACd,aAAa,EACb,IAAI,GACqC;IACzC,MAAM,UAAU,GAAG;QACjB,GAAG,EAAE,eAAe;QACpB,OAAO,EAAE,mBAAmB;QAC5B,OAAO,EAAE,KAAc;KACxB,CAAC;IAEF,MAAM,gBAAgB,GAAG,KAAK,EAC5B,MAAwB,EACG,EAAE;QAC7B,MAAM,IAAI,GAAG,M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K,CAAC,EAAE,EAAE,GAAG,aAAa,EAAE,GAAG,UAAU,CAAC;YACnE,MAAM,UAAU,GAAG,oBAAoB,CAAC;gBACtC,OAAO;gBACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,aAAa,EAAE;oBACb,GAAG,aAAa;oBAChB,MAAM,EAAE,cAAc;iBACvB;aACF,CAAC,CAAC;YAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YACxE,OAAO,iBAAiB,CAAC;gBACvB,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE;oBACP,GAAG,EAAE,UAAU;iBAChB;aACF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,IAAI;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type Hash,\n type TypedDataDefinition,\n encodeFunctionData,\n} from \"viem\";\nimport {\n entryPoint06Abi,\n toSmartAccount,\n type SmartAccount,\n type SmartAccountImplementation,\n entryPoint06Address,\n getUserOperationHash,\n} from \"viem/account-abstraction\";\nimport type { SignatureRequest } from \"../../types.js\";\nimport { IStandardExecutorAbi } from \"../abis/IStandardExecutor.js\";\nimport { signMessage, signTypedData } from \"viem/actions\";\nimport {\n decodeFunctionData,\n getAction,\n hashMessage,\n hashTypedData,\n isAddressEqual,\n} from \"viem/utils\";\nimport { BaseError } from \"@alchemy/common\";\n\ntype MaV1AccountType = \"MultiOwnerModularAccountV1\"; // Currently no SDK v5 support for \"MultiSigModularAccountV1\".\n\nexport type BaseMaV1AccountImplementation = SmartAccountImplementation<\n typeof entryPoint06Abi,\n \"0.6\",\n {\n smartAccountType: MaV1AccountType;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type ModularAccountV1Base = SmartAccount<BaseMaV1AccountImplementation>;\n\nexport type ToModularAccountV1BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n get712Wrapper: (msg: Hash) => Promise<TypedDataDefinition>;\n type: MaV1AccountType;\n};\n\n/**\n * Creates a ModularAccountV1Base instance.\n *\n * @param {ToModularAccountV1BaseParams<TTransport>} params The parameters for creating a ModularAccountV1Base instance\n * @returns {Promise<ModularAccountV1Base>} A promise that resolves to a ModularAccountV1Base instance\n */\nexport async function toModularAccountV1Base<\n TTransport extends Transport = Transport,\n>({\n client,\n accountAddress,\n owner,\n getFactoryArgs,\n get712Wrapper,\n type,\n}: ToModularAccountV1BaseParams<TTransport>): Promise<ModularAccountV1Base> {\n const entryPoint = {\n abi: entryPoint06Abi,\n address: entryPoint06Address,\n version: \"0.6\" as const,\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const data = await get712Wrapper(\n params.type === \"personal_sign\"\n ? hashMessage(params.data)\n : hashTypedData(params.data),\n );\n return {\n type: \"eth_signTypedData_v4\",\n data,\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return signature;\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (!calls.length) {\n throw new BaseError(\"No calls to encode.\");\n }\n\n if (calls.length === 1) {\n const call = calls[0];\n\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n if (isAddressEqual(call.to, accountAddress)) {\n if (call.data == null) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return call.data;\n }\n\n return encodeFunctionData({\n abi: IStandardExecutorAbi,\n functionName: \"execute\",\n args: [call.to, call.value ?? 0n, call.data ?? \"0x\"],\n });\n }\n\n return encodeFunctionData({\n abi: IStandardExecutorAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n value: call.value ?? 0n,\n data: call.data ?? \"0x\",\n })),\n ],\n });\n },\n\n // Inverse of `encodeCalls`.\n async decodeCalls(data) {\n const decoded = decodeFunctionData({\n abi: IStandardExecutorAbi,\n data,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n },\n\n async getStubSignature() {\n return \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n },\n\n async signMessage({ message }) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n return type === \"personal_sign\"\n ? signMessageAction({ account: owner, message: data })\n : signTypedDataAction({ ...data, account: owner });\n },\n\n async signTypedData(params) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition, // TODO(v5): try harder to avoid this cast?\n });\n return type === \"personal_sign\"\n ? signMessageAction({ account: owner, message: data })\n : signTypedDataAction({ ...data, account: owner });\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n const userOpHash = getUserOperationHash({\n chainId,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n return signMessageAction({\n account: owner,\n message: {\n raw: userOpHash,\n },\n });\n },\n\n extend: {\n smartAccountType: type,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v1/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,kBAAkB,GACnB,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EACf,cAAc,EAEd,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAgC5C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAE1C,EACA,MAAM,EACN,cAAc,EACd,KAAK,EACL,cAAc,EACd,aAAa,EACb,IAAI,GACqC;IACzC,MAAM,UAAU,GAAG;QACjB,GAAG,EAAE,eAAe;QACpB,OAAO,EAAE,mBAAmB;QAC5B,OAAO,EAAE,KAAc;KACxB,CAAC;IAEF,MAAM,gBAAgB,GAAG,KAAK,EAC5B,MAAwB,EACG,EAAE;QAC7B,MAAM,IAAI,GAAG,MAAM,aAAa,CAC9B,MAAM,CAAC,IAAI,KAAK,eAAe;YAC7B,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;YAC1B,CAAC,CAAC,aAAa,CAAC,MAAM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,OAAO;gBACrC,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,aAAa,EAAE;oBACb,GAAG,aAAa;oBAChB,MAAM,EAAE,cAAc;iBACvB;aACF,CAAC,CAAC;YAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YACxE,OAAO,iBAAiB,CAAC;gBACvB,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE;oBACP,GAAG,EAAE,UAAU;iBAChB;aACF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,IAAI;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type Hash,\n type TypedDataDefinition,\n encodeFunctionData,\n} from \"viem\";\nimport {\n entryPoint06Abi,\n toSmartAccount,\n type SmartAccountImplementation,\n entryPoint06Address,\n getUserOperationHash,\n} from \"viem/account-abstraction\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { IStandardExecutorAbi } from \"../abis/IStandardExecutor.js\";\nimport { signMessage, signTypedData } from \"viem/actions\";\nimport {\n decodeFunctionData,\n getAction,\n hashMessage,\n hashTypedData,\n isAddressEqual,\n} from \"viem/utils\";\nimport { BaseError } from \"@alchemy/common\";\n\ntype MaV1AccountType = \"MultiOwnerModularAccountV1\"; // Currently no SDK v5 support for \"MultiSigModularAccountV1\".\n\nexport type BaseMaV1AccountImplementation = SmartAccountImplementation<\n typeof entryPoint06Abi,\n \"0.6\",\n {\n smartAccountType: MaV1AccountType;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type ModularAccountV1Base =\n SmartAccountWithDecodeCalls<BaseMaV1AccountImplementation>;\n\nexport type ToModularAccountV1BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n get712Wrapper: (msg: Hash) => Promise<TypedDataDefinition>;\n type: MaV1AccountType;\n};\n\n/**\n * Creates a ModularAccountV1Base instance.\n *\n * @param {ToModularAccountV1BaseParams<TTransport>} params The parameters for creating a ModularAccountV1Base instance\n * @returns {Promise<ModularAccountV1Base>} A promise that resolves to a ModularAccountV1Base instance\n */\nexport async function toModularAccountV1Base<\n TTransport extends Transport = Transport,\n>({\n client,\n accountAddress,\n owner,\n getFactoryArgs,\n get712Wrapper,\n type,\n}: ToModularAccountV1BaseParams<TTransport>): Promise<ModularAccountV1Base> {\n const entryPoint = {\n abi: entryPoint06Abi,\n address: entryPoint06Address,\n version: \"0.6\" as const,\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const data = await get712Wrapper(\n params.type === \"personal_sign\"\n ? hashMessage(params.data)\n : hashTypedData(params.data),\n );\n return {\n type: \"eth_signTypedData_v4\",\n data,\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return signature;\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (!calls.length) {\n throw new BaseError(\"No calls to encode.\");\n }\n\n if (calls.length === 1) {\n const call = calls[0];\n\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n if (isAddressEqual(call.to, accountAddress)) {\n if (call.data == null) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return call.data;\n }\n\n return encodeFunctionData({\n abi: IStandardExecutorAbi,\n functionName: \"execute\",\n args: [call.to, call.value ?? 0n, call.data ?? \"0x\"],\n });\n }\n\n return encodeFunctionData({\n abi: IStandardExecutorAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n value: call.value ?? 0n,\n data: call.data ?? \"0x\",\n })),\n ],\n });\n },\n\n // Inverse of `encodeCalls`.\n async decodeCalls(data) {\n const decoded = decodeFunctionData({\n abi: IStandardExecutorAbi,\n data,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n },\n\n async getStubSignature() {\n return \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n },\n\n async signMessage({ message }) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n return type === \"personal_sign\"\n ? signMessageAction({ account: owner, message: data })\n : signTypedDataAction({ ...data, account: owner });\n },\n\n async signTypedData(params) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition, // TODO(v5): try harder to avoid this cast?\n });\n return type === \"personal_sign\"\n ? signMessageAction({ account: owner, message: data })\n : signTypedDataAction({ ...data, account: owner });\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n const userOpHash = getUserOperationHash({\n chainId,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n return signMessageAction({\n account: owner,\n message: {\n raw: userOpHash,\n },\n });\n },\n\n extend: {\n smartAccountType: type,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
@@ -11,7 +11,7 @@ export type ToMultiOwnerModularAccountV1Params = {
11
11
  }[]];
12
12
  salt?: bigint;
13
13
  accountAddress?: Address;
14
- factoryAddress?: Address;
14
+ factory?: Address;
15
15
  factoryData?: Hex;
16
16
  };
17
17
  /**
@@ -20,4 +20,4 @@ export type ToMultiOwnerModularAccountV1Params = {
20
20
  * @param {ToMultiOwnerModularAccountV1Params} param0 - The parameters for creating a multi-owner MAv1 account.
21
21
  * @returns {Promise<MultiOwnerModularAccountV1<TSigner>>} A multi-owner MAv1 account.
22
22
  */
23
- export declare function toMultiOwnerModularAccountV1({ client, salt, owners, accountAddress: accountAddress_, factoryAddress, factoryData: factoryData_, }: ToMultiOwnerModularAccountV1Params): Promise<MultiOwnerModularAccountV1>;
23
+ export declare function toMultiOwnerModularAccountV1({ client, salt, owners, accountAddress: accountAddress_, factory, factoryData: factoryData_, }: ToMultiOwnerModularAccountV1Params): Promise<MultiOwnerModularAccountV1>;
@@ -14,7 +14,7 @@ import { MultiOwnerPluginAbi } from "../abis/MultiOwnerPlugin.js";
14
14
  * @param {ToMultiOwnerModularAccountV1Params} param0 - The parameters for creating a multi-owner MAv1 account.
15
15
  * @returns {Promise<MultiOwnerModularAccountV1<TSigner>>} A multi-owner MAv1 account.
16
16
  */
17
- export async function toMultiOwnerModularAccountV1({ client, salt = 0n, owners, accountAddress: accountAddress_, factoryAddress = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY, factoryData: factoryData_, }) {
17
+ export async function toMultiOwnerModularAccountV1({ client, salt = 0n, owners, accountAddress: accountAddress_, factory = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY, factoryData: factoryData_, }) {
18
18
  const signer = owners[0];
19
19
  const dedupedOwners = Array.from(new Set(owners.map((it) => lowerAddress(it.address))));
20
20
  const sortedOwners = dedupedOwners.sort((a, b) => {
@@ -24,7 +24,7 @@ export async function toMultiOwnerModularAccountV1({ client, salt = 0n, owners,
24
24
  });
25
25
  const accountAddress = accountAddress_ ??
26
26
  predictMultiOwnerModularAccountV1Address({
27
- factoryAddress,
27
+ factoryAddress: factory,
28
28
  salt,
29
29
  ownerAddresses: sortedOwners,
30
30
  });
@@ -36,7 +36,7 @@ export async function toMultiOwnerModularAccountV1({ client, salt = 0n, owners,
36
36
  args: [salt, sortedOwners],
37
37
  });
38
38
  return {
39
- factory: factoryAddress,
39
+ factory,
40
40
  factoryData,
41
41
  };
42
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"multi-owner-account.js","sourceRoot":"","sources":["../../../../src/ma-v1/accounts/multi-owner-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EASX,kBAAkB,GAGnB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,kCAAkC,EAAE,MAAM,4CAA4C,CAAC;AAChG,OAAO,EAAE,wCAAwC,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,oCAAoC,EAAE,MAAM,8CAA8C,CAAC;AACpG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAmBlE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,EACjD,MAAM,EACN,IAAI,GAAG,EAAE,EACT,MAAM,EACN,cAAc,EAAE,eAAe,EAC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AAI,EAAE,CAAC,cAAc,CAAC;aACvB,CAAC,CAAC;YAEH,IACE,CAAC,aAAa;iBACX,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;iBAC7B,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EACzC,CAAC;gBACD,MAAM,IAAI,SAAS,CACjB,qDAAqD,CACtD,CAAC;YACJ,CAAC;YAED,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n hexToBigInt,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type OneOf,\n type Transport,\n encodeFunctionData,\n type Hash,\n type TypedDataDefinition,\n} from \"viem\";\nimport { toModularAccountV1Base, type ModularAccountV1Base } from \"./base.js\";\nimport { lowerAddress, BaseError } from \"@alchemy/common\";\nimport { DefaultMaV1Address, DefaultMaV1PluginAddress } from \"../account.js\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"../abis/MultiOwnerModularAccountFactory.js\";\nimport { predictMultiOwnerModularAccountV1Address } from \"../predictAddress.js\";\nimport { MultiOwnerPluginExecutionFunctionAbi } from \"../abis/MultiOwnerPluginExecutionFunction.js\";\nimport { readContract } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\nimport { MultiOwnerPluginAbi } from \"../abis/MultiOwnerPlugin.js\";\n\nexport type MultiOwnerModularAccountV1 = ModularAccountV1Base & {\n encodeUpdateOwners: (\n ownersToAdd: Address[],\n ownersToRemove: Address[],\n ) => Hex;\n getOwnerAddresses: () => Promise<readonly Address[]>;\n};\n\nexport type ToMultiOwnerModularAccountV1Params = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{ address: Address }[]];\n salt?: bigint;\n accountAddress?: Address;\n factoryAddress?: Address;\n factoryData?: Hex;\n};\n\n/**\n * Creates a multi-owner MAv1 account.\n *\n * @param {ToMultiOwnerModularAccountV1Params} param0 - The parameters for creating a multi-owner MAv1 account.\n * @returns {Promise<MultiOwnerModularAccountV1<TSigner>>} A multi-owner MAv1 account.\n */\nexport async function toMultiOwnerModularAccountV1({\n client,\n salt = 0n,\n owners,\n accountAddress: accountAddress_,\n factoryAddress = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n factoryData: factoryData_,\n}: ToMultiOwnerModularAccountV1Params): Promise<MultiOwnerModularAccountV1> {\n const signer = owners[0];\n\n const dedupedOwners = Array.from(\n new Set(owners.map((it) => lowerAddress(it.address))),\n );\n\n const sortedOwners = dedupedOwners.sort((a, b) => {\n const bigintA = hexToBigInt(a);\n const bigintB = hexToBigInt(b);\n return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;\n });\n\n const accountAddress =\n accountAddress_ ??\n predictMultiOwnerModularAccountV1Address({\n factoryAddress,\n salt,\n ownerAddresses: sortedOwners,\n });\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: MultiOwnerModularAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [salt, sortedOwners],\n });\n\n return {\n factory: factoryAddress,\n factoryData,\n };\n };\n\n const get712Wrapper = async (msg: Hash): Promise<TypedDataDefinition> => {\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n const [, name, version, chainId, verifyingContract, salt] =\n await readContractAction({\n abi: MultiOwnerPluginAbi,\n address: DefaultMaV1PluginAddress.MULTI_OWNER,\n functionName: \"eip712Domain\",\n account: accountAddress,\n });\n\n return {\n domain: {\n chainId: Number(chainId),\n name,\n salt,\n verifyingContract,\n version,\n },\n types: {\n AlchemyModularAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: msg,\n },\n primaryType: \"AlchemyModularAccountMessage\",\n };\n };\n\n const baseAccount = await toModularAccountV1Base({\n client,\n owner: signer,\n accountAddress,\n getFactoryArgs,\n type: \"MultiOwnerModularAccountV1\",\n get712Wrapper,\n });\n\n return {\n ...baseAccount,\n\n encodeUpdateOwners: (ownersToAdd: Address[], ownersToRemove: Address[]) => {\n return encodeFunctionData({\n abi: MultiOwnerPluginExecutionFunctionAbi,\n functionName: \"updateOwners\",\n args: [ownersToAdd, ownersToRemove],\n });\n },\n\n async getOwnerAddresses(): Promise<readonly Address[]> {\n const readContractAction = getAction(\n client,\n readContract,\n \"readContract\",\n );\n const ownersOnChain = await readContractAction({\n address: DefaultMaV1PluginAddress.MULTI_OWNER,\n abi: MultiOwnerPluginAbi,\n functionName: \"ownersOf\",\n args: [accountAddress],\n });\n\n if (\n !ownersOnChain\n .map((it) => lowerAddress(it))\n .includes(lowerAddress(signer.address))\n ) {\n throw new BaseError(\n \"on-chain owners does not include the current signer\",\n );\n }\n\n return ownersOnChain;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"multi-owner-account.js","sourceRoot":"","sources":["../../../../src/ma-v1/accounts/multi-owner-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EASX,kBAAkB,GAGnB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,kCAAkC,EAAE,MAAM,4CAA4C,CAAC;AAChG,OAAO,EAAE,wCAAwC,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,oCAAoC,EAAE,MAAM,8CAA8C,CAAC;AACpG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAmBlE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,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C,WAAW;gBAC7C,GAAG,EAAE,mBAAmB;gBACxB,YAAY,EAAE,UAAU;gBACxB,IAAI,EAAE,CAAC,cAAc,CAAC;aACvB,CAAC,CAAC;YAEH,IACE,CAAC,aAAa;iBACX,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;iBAC7B,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EACzC,CAAC;gBACD,MAAM,IAAI,SAAS,CACjB,qDAAqD,CACtD,CAAC;YACJ,CAAC;YAED,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n hexToBigInt,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type OneOf,\n type Transport,\n encodeFunctionData,\n type Hash,\n type TypedDataDefinition,\n} from \"viem\";\nimport { toModularAccountV1Base, type ModularAccountV1Base } from \"./base.js\";\nimport { lowerAddress, BaseError } from \"@alchemy/common\";\nimport { DefaultMaV1Address, DefaultMaV1PluginAddress } from \"../account.js\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"../abis/MultiOwnerModularAccountFactory.js\";\nimport { predictMultiOwnerModularAccountV1Address } from \"../predictAddress.js\";\nimport { MultiOwnerPluginExecutionFunctionAbi } from \"../abis/MultiOwnerPluginExecutionFunction.js\";\nimport { readContract } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\nimport { MultiOwnerPluginAbi } from \"../abis/MultiOwnerPlugin.js\";\n\nexport type MultiOwnerModularAccountV1 = ModularAccountV1Base & {\n encodeUpdateOwners: (\n ownersToAdd: Address[],\n ownersToRemove: Address[],\n ) => Hex;\n getOwnerAddresses: () => Promise<readonly Address[]>;\n};\n\nexport type ToMultiOwnerModularAccountV1Params = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{ address: Address }[]];\n salt?: bigint;\n accountAddress?: Address;\n factory?: Address;\n factoryData?: Hex;\n};\n\n/**\n * Creates a multi-owner MAv1 account.\n *\n * @param {ToMultiOwnerModularAccountV1Params} param0 - The parameters for creating a multi-owner MAv1 account.\n * @returns {Promise<MultiOwnerModularAccountV1<TSigner>>} A multi-owner MAv1 account.\n */\nexport async function toMultiOwnerModularAccountV1({\n client,\n salt = 0n,\n owners,\n accountAddress: accountAddress_,\n factory = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n factoryData: factoryData_,\n}: ToMultiOwnerModularAccountV1Params): Promise<MultiOwnerModularAccountV1> {\n const signer = owners[0];\n\n const dedupedOwners = Array.from(\n new Set(owners.map((it) => lowerAddress(it.address))),\n );\n\n const sortedOwners = dedupedOwners.sort((a, b) => {\n const bigintA = hexToBigInt(a);\n const bigintB = hexToBigInt(b);\n return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;\n });\n\n const accountAddress =\n accountAddress_ ??\n predictMultiOwnerModularAccountV1Address({\n factoryAddress: factory,\n salt,\n ownerAddresses: sortedOwners,\n });\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: MultiOwnerModularAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [salt, sortedOwners],\n });\n\n return {\n factory,\n factoryData,\n };\n };\n\n const get712Wrapper = async (msg: Hash): Promise<TypedDataDefinition> => {\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n const [, name, version, chainId, verifyingContract, salt] =\n await readContractAction({\n abi: MultiOwnerPluginAbi,\n address: DefaultMaV1PluginAddress.MULTI_OWNER,\n functionName: \"eip712Domain\",\n account: accountAddress,\n });\n\n return {\n domain: {\n chainId: Number(chainId),\n name,\n salt,\n verifyingContract,\n version,\n },\n types: {\n AlchemyModularAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: msg,\n },\n primaryType: \"AlchemyModularAccountMessage\",\n };\n };\n\n const baseAccount = await toModularAccountV1Base({\n client,\n owner: signer,\n accountAddress,\n getFactoryArgs,\n type: \"MultiOwnerModularAccountV1\",\n get712Wrapper,\n });\n\n return {\n ...baseAccount,\n\n encodeUpdateOwners: (ownersToAdd: Address[], ownersToRemove: Address[]) => {\n return encodeFunctionData({\n abi: MultiOwnerPluginExecutionFunctionAbi,\n functionName: \"updateOwners\",\n args: [ownersToAdd, ownersToRemove],\n });\n },\n\n async getOwnerAddresses(): Promise<readonly Address[]> {\n const readContractAction = getAction(\n client,\n readContract,\n \"readContract\",\n );\n const ownersOnChain = await readContractAction({\n address: DefaultMaV1PluginAddress.MULTI_OWNER,\n abi: MultiOwnerPluginAbi,\n functionName: \"ownersOf\",\n args: [accountAddress],\n });\n\n if (\n !ownersOnChain\n .map((it) => lowerAddress(it))\n .includes(lowerAddress(signer.address))\n ) {\n throw new BaseError(\n \"on-chain owners does not include the current signer\",\n );\n }\n\n return ownersOnChain;\n },\n };\n}\n"]}
@@ -13,12 +13,12 @@ export type ToModularAccountV2Params<TMode extends Mode | undefined = Mode | und
13
13
  mode?: TMode;
14
14
  } & (TMode extends "7702" ? {
15
15
  salt?: never;
16
- factoryAddress?: never;
16
+ factory?: never;
17
17
  factoryData?: never;
18
18
  implementationAddress?: never;
19
19
  } : {
20
20
  salt?: bigint;
21
- factoryAddress?: Address;
21
+ factory?: Address;
22
22
  factoryData?: Hex;
23
23
  implementationAddress?: Address;
24
24
  });
@@ -28,5 +28,5 @@ export type ToModularAccountV2Params<TMode extends Mode | undefined = Mode | und
28
28
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
29
29
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
30
30
  */
31
- export declare function toModularAccountV2<TMode extends Mode = Mode>({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt, factoryAddress: factoryAddress_, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2>;
31
+ 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>;
32
32
  export {};
@@ -14,7 +14,7 @@ import { LOGGER } from "../../logger.js";
14
14
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
15
15
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
16
16
  */
17
- export async function toModularAccountV2({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt = 0n, factoryAddress: factoryAddress_, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }) {
17
+ export async function toModularAccountV2({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt = 0n, factory, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }) {
18
18
  const is7702 = mode === "7702";
19
19
  LOGGER.debug("toModularAccountV2:start", {
20
20
  ownerType: owner.type,
@@ -23,7 +23,7 @@ export async function toModularAccountV2({ client, owner, deferredAction, signer
23
23
  hasAccountAddress: !!accountAddress_,
24
24
  });
25
25
  const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;
26
- const factoryAddress = factoryAddress_ ??
26
+ const factoryAddress = factory ??
27
27
  (owner.type === "webAuthn"
28
28
  ? DefaultAddress.MAV2_FACTORY_WEBAUTHN
29
29
  : DefaultAddress.MAV2_FACTORY);
@@ -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;AAKd,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,k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ACJ,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 type {\n WebAuthnAccount,\n ToSmartAccountParameters,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport { predictModularAccountV2Address } from \"../predictAddress.js\";\nimport { parsePublicKey } from \"webauthn-p256\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { webAuthnFactoryAbi } from \"../abis/webAuthnFactoryAbi.js\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport { InvalidOwnerError } from \"../../errors/InvalidOwnerError.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from \"../utils/account.js\";\nimport { LOGGER } from \"../../logger.js\";\n\ntype Mode = \"default\" | \"7702\";\n\n// TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\nexport type ModularAccountV2 = ModularAccountV2Base & {};\n\nexport type ToModularAccountV2Params<\n TMode extends Mode | undefined = Mode | undefined,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount | WebAuthnAccount;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n accountAddress?: Address;\n mode?: TMode;\n} & (TMode extends \"7702\"\n ? {\n salt?: never;\n factoryAddress?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n salt?: bigint;\n factoryAddress?: Address;\n factoryData?: Hex;\n implementationAddress?: Address;\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 factoryAddress: factoryAddress_,\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 =\n factoryAddress_ ??\n (owner.type === \"webAuthn\"\n ? DefaultAddress.MAV2_FACTORY_WEBAUTHN\n : DefaultAddress.MAV2_FACTORY);\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702\n ? DefaultAddress.SMAV2_7702\n : owner.type === \"webAuthn\"\n ? DefaultAddress.MAV2\n : 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 if (owner.type === \"webAuthn\") {\n const { x, y } = parsePublicKey(owner.publicKey);\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: webAuthnFactoryAbi,\n functionName: \"createWebAuthnAccount\",\n args: [x, y, salt, entityId],\n }),\n };\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 (mode === \"7702\" && owner.type === \"local\"\n ? owner.address\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n ...(owner.type === \"webAuthn\"\n ? {\n type: \"WebAuthn\",\n ownerPublicKey: owner.publicKey,\n entityId,\n }\n : {\n type: \"SMA\", // `MA` is never used here since we only support deploying SMA & WebAuthn accounts.\n ownerAddress: owner.address,\n entityId,\n }),\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 // TODO(v5): Ensure this works w/ our signer types.\n if (owner.type !== \"local\") {\n LOGGER.error(\"toModularAccountV2:invalid-owner-type\", {\n ownerType: owner.type,\n });\n throw new InvalidOwnerError(\n `Owner of type ${owner.type} is unsupported for 7702 mode.`,\n );\n }\n if (owner.signAuthorization == null) {\n LOGGER.error(\"toModularAccountV2:missing-signAuthorization\");\n throw new InvalidOwnerError(\n \"Owner must implement `signAuthorization` to be used with 7702 mode.\",\n );\n }\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n owner.address !== accountAddress\n ) {\n LOGGER.error(\"toModularAccountV2:entity-id-override\");\n throw new EntityIdOverrideError();\n }\n authorization = {\n // The current version of Viem has some pretty strict constraints\n // on a `PrivateKeyAccount`, but this seems safe as long as the\n // owner is able to `signAuthorization`.\n account: owner as PrivateKeyAccount,\n address: DefaultAddress.SMAV2_7702,\n };\n }\n\n const base = await toModularAccountV2Base({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity,\n deferredAction,\n authorization,\n });\n\n return {\n ...base,\n // TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\n };\n}\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GASnB,MAAM,MAAM,CAAC;AAKd,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAA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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 type {\n WebAuthnAccount,\n ToSmartAccountParameters,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport { predictModularAccountV2Address } from \"../predictAddress.js\";\nimport { parsePublicKey } from \"webauthn-p256\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { webAuthnFactoryAbi } from \"../abis/webAuthnFactoryAbi.js\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport { InvalidOwnerError } from \"../../errors/InvalidOwnerError.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from \"../utils/account.js\";\nimport { LOGGER } from \"../../logger.js\";\n\ntype Mode = \"default\" | \"7702\";\n\n// TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\nexport type ModularAccountV2 = ModularAccountV2Base & {};\n\nexport type ToModularAccountV2Params<\n TMode extends Mode | undefined = Mode | undefined,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount | WebAuthnAccount;\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 salt?: bigint;\n factory?: Address;\n factoryData?: Hex;\n implementationAddress?: Address;\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 =\n factory ??\n (owner.type === \"webAuthn\"\n ? DefaultAddress.MAV2_FACTORY_WEBAUTHN\n : DefaultAddress.MAV2_FACTORY);\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702\n ? DefaultAddress.SMAV2_7702\n : owner.type === \"webAuthn\"\n ? DefaultAddress.MAV2\n : 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 if (owner.type === \"webAuthn\") {\n const { x, y } = parsePublicKey(owner.publicKey);\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: webAuthnFactoryAbi,\n functionName: \"createWebAuthnAccount\",\n args: [x, y, salt, entityId],\n }),\n };\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 (mode === \"7702\" && owner.type === \"local\"\n ? owner.address\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n ...(owner.type === \"webAuthn\"\n ? {\n type: \"WebAuthn\",\n ownerPublicKey: owner.publicKey,\n entityId,\n }\n : {\n type: \"SMA\", // `MA` is never used here since we only support deploying SMA & WebAuthn accounts.\n ownerAddress: owner.address,\n entityId,\n }),\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 // TODO(v5): Ensure this works w/ our signer types.\n if (owner.type !== \"local\") {\n LOGGER.error(\"toModularAccountV2:invalid-owner-type\", {\n ownerType: owner.type,\n });\n throw new InvalidOwnerError(\n `Owner of type ${owner.type} is unsupported for 7702 mode.`,\n );\n }\n if (owner.signAuthorization == null) {\n LOGGER.error(\"toModularAccountV2:missing-signAuthorization\");\n throw new InvalidOwnerError(\n \"Owner must implement `signAuthorization` to be used with 7702 mode.\",\n );\n }\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n owner.address !== accountAddress\n ) {\n LOGGER.error(\"toModularAccountV2:entity-id-override\");\n throw new EntityIdOverrideError();\n }\n authorization = {\n // The current version of Viem has some pretty strict constraints\n // on a `PrivateKeyAccount`, but this seems safe as long as the\n // owner is able to `signAuthorization`.\n account: owner as PrivateKeyAccount,\n address: DefaultAddress.SMAV2_7702,\n };\n }\n\n const base = await toModularAccountV2Base({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity,\n deferredAction,\n authorization,\n });\n\n return {\n ...base,\n // TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\n };\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { type Address, type Hex, type Chain, type Client, type JsonRpcAccount, type LocalAccount, type Transport } from "viem";
2
- import { entryPoint07Abi, type SmartAccountImplementation, type SmartAccount, type WebAuthnAccount, type ToSmartAccountParameters } from "viem/account-abstraction";
2
+ import { entryPoint07Abi, type SmartAccountImplementation, type WebAuthnAccount, type ToSmartAccountParameters } from "viem/account-abstraction";
3
3
  import { type ExecutionDataView, type SignerEntity, type ValidationDataView } from "../types.js";
4
- import type { SignatureRequest } from "../../types.js";
4
+ import type { SignatureRequest, SmartAccountWithDecodeCalls } from "../../types.js";
5
5
  export type ValidationDataParams = {
6
6
  validationModuleAddress: Address;
7
7
  entityId?: never;
@@ -18,7 +18,7 @@ export type BaseModularAccountV2Implementation = SmartAccountImplementation<type
18
18
  prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;
19
19
  formatSignature: (signature: Hex) => Promise<Hex>;
20
20
  }, boolean>;
21
- export type ModularAccountV2Base = SmartAccount<BaseModularAccountV2Implementation>;
21
+ export type ModularAccountV2Base = SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;
22
22
  export type ToModularAccountV2BaseParams<TTransport extends Transport = Transport> = {
23
23
  client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;
24
24
  owner: JsonRpcAccount | LocalAccount | WebAuthnAccount;
@@ -31,10 +31,15 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
31
31
  if (entityId > Number(maxUint32)) {
32
32
  throw new InvalidEntityIdError(entityId);
33
33
  }
34
+ let isDeployed = false;
34
35
  const isAccountDeployed = async () => {
36
+ if (isDeployed) {
37
+ return true;
38
+ }
35
39
  const action = getAction(client, getCode, "getCode");
36
40
  const code = await action({ address: accountAddress });
37
- return code != null && code !== "0x";
41
+ isDeployed = !!code;
42
+ return isDeployed;
38
43
  };
39
44
  // These default values signal that we should not use the set deferred action nonce
40
45
  let nonce;