@alchemy/smart-accounts 0.0.0-alpha.2 → 0.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/light-account/accounts/account.d.ts +9 -4
- package/dist/esm/light-account/accounts/account.js +29 -18
- package/dist/esm/light-account/accounts/account.js.map +1 -1
- package/dist/esm/light-account/accounts/base.d.ts +4 -4
- package/dist/esm/light-account/accounts/base.js +51 -24
- package/dist/esm/light-account/accounts/base.js.map +1 -1
- package/dist/esm/light-account/accounts/multi-owner-account.d.ts +9 -4
- package/dist/esm/light-account/accounts/multi-owner-account.js +23 -14
- package/dist/esm/light-account/accounts/multi-owner-account.js.map +1 -1
- package/dist/esm/light-account/decorators/multiOwner.js +2 -1
- package/dist/esm/light-account/decorators/multiOwner.js.map +1 -1
- package/dist/esm/light-account/decorators/singleOwner.js +1 -1
- package/dist/esm/light-account/decorators/singleOwner.js.map +1 -1
- package/dist/esm/light-account/lightAccountStaticImpl.d.ts +3 -1
- package/dist/esm/light-account/lightAccountStaticImpl.js +57 -7
- package/dist/esm/light-account/lightAccountStaticImpl.js.map +1 -1
- package/dist/esm/light-account/predictAddress.d.ts +40 -2
- package/dist/esm/light-account/predictAddress.js +83 -3
- package/dist/esm/light-account/predictAddress.js.map +1 -1
- package/dist/esm/light-account/registry.d.ts +3411 -1
- package/dist/esm/light-account/registry.js +33 -1
- package/dist/esm/light-account/registry.js.map +1 -1
- package/dist/esm/light-account/utils.js +1 -1
- package/dist/esm/light-account/utils.js.map +1 -1
- package/dist/esm/ma-v1/accounts/base.d.ts +4 -4
- package/dist/esm/ma-v1/accounts/base.js +1 -1
- package/dist/esm/ma-v1/accounts/base.js.map +1 -1
- package/dist/esm/ma-v1/accounts/multi-owner-account.d.ts +9 -4
- package/dist/esm/ma-v1/accounts/multi-owner-account.js +26 -14
- package/dist/esm/ma-v1/accounts/multi-owner-account.js.map +1 -1
- package/dist/esm/ma-v1/decorators/multiOwner.js +2 -1
- package/dist/esm/ma-v1/decorators/multiOwner.js.map +1 -1
- package/dist/esm/ma-v1/predictAddress.d.ts +20 -1
- package/dist/esm/ma-v1/predictAddress.js +37 -1
- package/dist/esm/ma-v1/predictAddress.js.map +1 -1
- package/dist/esm/ma-v2/accounts/account.d.ts +10 -7
- package/dist/esm/ma-v2/accounts/account.js +24 -43
- package/dist/esm/ma-v2/accounts/account.js.map +1 -1
- package/dist/esm/ma-v2/accounts/base.d.ts +5 -5
- package/dist/esm/ma-v2/accounts/base.js +18 -60
- package/dist/esm/ma-v2/accounts/base.js.map +1 -1
- package/dist/esm/ma-v2/mav2StaticImpl.d.ts +1 -15
- package/dist/esm/ma-v2/mav2StaticImpl.js +0 -33
- package/dist/esm/ma-v2/mav2StaticImpl.js.map +1 -1
- package/dist/esm/ma-v2/predictAddress.d.ts +22 -6
- package/dist/esm/ma-v2/predictAddress.js +46 -12
- package/dist/esm/ma-v2/predictAddress.js.map +1 -1
- package/dist/esm/ma-v2/utils/account.d.ts +0 -3
- package/dist/esm/ma-v2/utils/account.js +2 -4
- package/dist/esm/ma-v2/utils/account.js.map +1 -1
- package/dist/esm/ma-v2/utils/signature.d.ts +1 -12
- package/dist/esm/ma-v2/utils/signature.js +1 -34
- package/dist/esm/ma-v2/utils/signature.js.map +1 -1
- package/dist/esm/types.d.ts +8 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +32 -2
- package/dist/esm/utils.js +75 -5
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/index.d.ts +4 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/light-account/accounts/account.d.ts +9 -4
- package/dist/types/light-account/accounts/account.d.ts.map +1 -1
- package/dist/types/light-account/accounts/base.d.ts +4 -4
- package/dist/types/light-account/accounts/base.d.ts.map +1 -1
- package/dist/types/light-account/accounts/multi-owner-account.d.ts +9 -4
- package/dist/types/light-account/accounts/multi-owner-account.d.ts.map +1 -1
- package/dist/types/light-account/decorators/multiOwner.d.ts.map +1 -1
- package/dist/types/light-account/decorators/singleOwner.d.ts.map +1 -1
- package/dist/types/light-account/lightAccountStaticImpl.d.ts +3 -1
- package/dist/types/light-account/lightAccountStaticImpl.d.ts.map +1 -1
- package/dist/types/light-account/predictAddress.d.ts +40 -2
- package/dist/types/light-account/predictAddress.d.ts.map +1 -1
- package/dist/types/light-account/registry.d.ts +3411 -1
- package/dist/types/light-account/registry.d.ts.map +1 -1
- package/dist/types/ma-v1/accounts/base.d.ts +4 -4
- package/dist/types/ma-v1/accounts/base.d.ts.map +1 -1
- package/dist/types/ma-v1/accounts/multi-owner-account.d.ts +9 -4
- package/dist/types/ma-v1/accounts/multi-owner-account.d.ts.map +1 -1
- package/dist/types/ma-v1/decorators/multiOwner.d.ts.map +1 -1
- package/dist/types/ma-v1/predictAddress.d.ts +20 -1
- package/dist/types/ma-v1/predictAddress.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/account.d.ts +10 -7
- package/dist/types/ma-v2/accounts/account.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/base.d.ts +5 -5
- package/dist/types/ma-v2/accounts/base.d.ts.map +1 -1
- package/dist/types/ma-v2/mav2StaticImpl.d.ts +1 -15
- package/dist/types/ma-v2/mav2StaticImpl.d.ts.map +1 -1
- package/dist/types/ma-v2/predictAddress.d.ts +22 -6
- package/dist/types/ma-v2/predictAddress.d.ts.map +1 -1
- package/dist/types/ma-v2/utils/account.d.ts +0 -3
- package/dist/types/ma-v2/utils/account.d.ts.map +1 -1
- package/dist/types/ma-v2/utils/signature.d.ts +1 -12
- package/dist/types/ma-v2/utils/signature.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +32 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +5 -6
- package/src/index.ts +4 -3
- package/src/light-account/accounts/account.ts +42 -26
- package/src/light-account/accounts/base.ts +66 -27
- package/src/light-account/accounts/multi-owner-account.ts +33 -16
- package/src/light-account/decorators/multiOwner.ts +4 -1
- package/src/light-account/decorators/singleOwner.ts +3 -1
- package/src/light-account/lightAccountStaticImpl.ts +84 -11
- package/src/light-account/predictAddress.ts +124 -3
- package/src/light-account/registry.ts +47 -1
- package/src/light-account/utils.ts +1 -1
- package/src/ma-v1/accounts/base.ts +8 -5
- package/src/ma-v1/accounts/multi-owner-account.ts +37 -18
- package/src/ma-v1/decorators/multiOwner.ts +4 -1
- package/src/ma-v1/predictAddress.ts +59 -2
- package/src/ma-v2/accounts/account.ts +42 -55
- package/src/ma-v2/accounts/base.ts +24 -88
- package/src/ma-v2/mav2StaticImpl.ts +1 -52
- package/src/ma-v2/predictAddress.ts +68 -30
- package/src/ma-v2/utils/account.ts +4 -4
- package/src/ma-v2/utils/signature.ts +2 -51
- package/src/types.ts +15 -1
- package/src/utils.ts +119 -6
- package/src/version.ts +1 -1
- package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -330
- package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js +0 -260
- package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js.map +0 -1
- package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -287
- package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js +0 -374
- package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js.map +0 -1
- package/dist/esm/ma-v2/modules/webauthn-validation/module.d.ts +0 -11
- package/dist/esm/ma-v2/modules/webauthn-validation/module.js +0 -16
- package/dist/esm/ma-v2/modules/webauthn-validation/module.js.map +0 -1
- package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -331
- package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts.map +0 -1
- package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -288
- package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts.map +0 -1
- package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts +0 -12
- package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts.map +0 -1
- package/src/ma-v2/abis/webAuthnFactoryAbi.ts +0 -259
- package/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.ts +0 -373
- package/src/ma-v2/modules/webauthn-validation/module.ts +0 -28
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lightAccountStaticImplV1_0_1, lightAccountStaticImplV1_0_2, lightAccountStaticImplV1_1_0, lightAccountStaticImplV2_0_0, multiOwnerLightAccountStaticImplV2_0_0, } from "./lightAccountStaticImpl.js";
|
|
1
|
+
import { lightAccountStaticImplV1_0_1, lightAccountStaticImplV1_0_2, lightAccountStaticImplV1_1_0, lightAccountStaticImplV2_0_0, lightAccountStaticImplV2_1_0, lightAccountStaticImplV2_2_0, multiOwnerLightAccountStaticImplV2_0_0, } from "./lightAccountStaticImpl.js";
|
|
2
2
|
/**
|
|
3
3
|
* Account version registry interface that defines the light account versions
|
|
4
4
|
* and the version definition for each light account type
|
|
@@ -10,9 +10,41 @@ export const AccountVersionRegistry = {
|
|
|
10
10
|
"v1.0.2": lightAccountStaticImplV1_0_2,
|
|
11
11
|
"v1.1.0": lightAccountStaticImplV1_1_0,
|
|
12
12
|
"v2.0.0": lightAccountStaticImplV2_0_0,
|
|
13
|
+
"v2.1.0": lightAccountStaticImplV2_1_0,
|
|
14
|
+
"v2.2.0": lightAccountStaticImplV2_2_0,
|
|
13
15
|
},
|
|
14
16
|
MultiOwnerLightAccount: {
|
|
15
17
|
"v2.0.0": multiOwnerLightAccountStaticImplV2_0_0,
|
|
16
18
|
},
|
|
17
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Light Account v1 versions
|
|
22
|
+
*/
|
|
23
|
+
export const LightAccountV1Versions = [
|
|
24
|
+
"v1.0.1",
|
|
25
|
+
"v1.0.2",
|
|
26
|
+
"v1.1.0",
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Light Account v2 versions
|
|
30
|
+
*/
|
|
31
|
+
export const LightAccountV2Versions = [
|
|
32
|
+
"v2.0.0",
|
|
33
|
+
"v2.1.0",
|
|
34
|
+
"v2.2.0",
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* Type guard to check if a version is a Light Account v1 version
|
|
38
|
+
*
|
|
39
|
+
* @param {LightAccountVersion<"LightAccount">} version - The version to check.
|
|
40
|
+
* @returns {boolean} True if the version is a v1 version.
|
|
41
|
+
*/
|
|
42
|
+
export const isLightAccountVersion1 = (version) => LightAccountV1Versions.includes(version);
|
|
43
|
+
/**
|
|
44
|
+
* Type guard to check if a version is a Light Account v2 version
|
|
45
|
+
*
|
|
46
|
+
* @param {LightAccountVersion<"LightAccount">} version - The version to check.
|
|
47
|
+
* @returns {boolean} True if the version is a v2 version.
|
|
48
|
+
*/
|
|
49
|
+
export const isLightAccountVersion2 = (version) => LightAccountV2Versions.includes(version);
|
|
18
50
|
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/light-account/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,6BAA6B,CAAC;AAGrC;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,YAAY,EAAE;QACZ,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;KACvC;IACD,sBAAsB,EAAE;QACtB,QAAQ,EAAE,sCAAsC;KACjD;CACyE,CAAC","sourcesContent":["import type { Abi, Address } from \"viem\";\nimport type { LightAccountBase } from \"./accounts/base.js\";\nimport {\n lightAccountStaticImplV1_0_1,\n lightAccountStaticImplV1_0_2,\n lightAccountStaticImplV1_1_0,\n lightAccountStaticImplV2_0_0,\n multiOwnerLightAccountStaticImplV2_0_0,\n} from \"./lightAccountStaticImpl.js\";\nimport type { StaticSmartAccountImplementation } from \"../types.js\";\n\n/**\n * Account version registry interface that defines the light account versions\n * and the version definition for each light account type\n *\n */\nexport const AccountVersionRegistry = {\n LightAccount: {\n \"v1.0.1\": lightAccountStaticImplV1_0_1,\n \"v1.0.2\": lightAccountStaticImplV1_0_2,\n \"v1.1.0\": lightAccountStaticImplV1_1_0,\n \"v2.0.0\": lightAccountStaticImplV2_0_0,\n },\n MultiOwnerLightAccount: {\n \"v2.0.0\": multiOwnerLightAccountStaticImplV2_0_0,\n },\n} satisfies Record<string, Record<string, StaticSmartAccountImplementation>>;\n\nexport type LightAccountType = Extract<\n keyof typeof AccountVersionRegistry,\n \"LightAccount\" | \"MultiOwnerLightAccount\"\n>;\n\nexport type LightAccountVersion<TAccountType extends LightAccountType> =\n keyof (typeof AccountVersionRegistry)[TAccountType];\n\nexport type GetLightAccountType<TAccount extends LightAccountBase> =\n TAccount[\"
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/light-account/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,6BAA6B,CAAC;AAGrC;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,YAAY,EAAE;QACZ,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;KACvC;IACD,sBAAsB,EAAE;QACtB,QAAQ,EAAE,sCAAsC;KACjD;CACyE,CAAC;AAU7E;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,QAAQ;IACR,QAAQ;IACR,QAAQ;CACgD,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,QAAQ;IACR,QAAQ;IACR,QAAQ;CACgD,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,OAA4C,EACQ,EAAE,CACrD,sBAA4C,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAElE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,OAA4C,EACQ,EAAE,CACrD,sBAA4C,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import type { Abi, Address } from \"viem\";\nimport type { LightAccountBase } from \"./accounts/base.js\";\nimport {\n lightAccountStaticImplV1_0_1,\n lightAccountStaticImplV1_0_2,\n lightAccountStaticImplV1_1_0,\n lightAccountStaticImplV2_0_0,\n lightAccountStaticImplV2_1_0,\n lightAccountStaticImplV2_2_0,\n multiOwnerLightAccountStaticImplV2_0_0,\n} from \"./lightAccountStaticImpl.js\";\nimport type { StaticSmartAccountImplementation } from \"../types.js\";\n\n/**\n * Account version registry interface that defines the light account versions\n * and the version definition for each light account type\n *\n */\nexport const AccountVersionRegistry = {\n LightAccount: {\n \"v1.0.1\": lightAccountStaticImplV1_0_1,\n \"v1.0.2\": lightAccountStaticImplV1_0_2,\n \"v1.1.0\": lightAccountStaticImplV1_1_0,\n \"v2.0.0\": lightAccountStaticImplV2_0_0,\n \"v2.1.0\": lightAccountStaticImplV2_1_0,\n \"v2.2.0\": lightAccountStaticImplV2_2_0,\n },\n MultiOwnerLightAccount: {\n \"v2.0.0\": multiOwnerLightAccountStaticImplV2_0_0,\n },\n} satisfies Record<string, Record<string, StaticSmartAccountImplementation>>;\n\nexport type LightAccountType = Extract<\n keyof typeof AccountVersionRegistry,\n \"LightAccount\" | \"MultiOwnerLightAccount\"\n>;\n\nexport type LightAccountVersion<TAccountType extends LightAccountType> =\n keyof (typeof AccountVersionRegistry)[TAccountType];\n\n/**\n * Light Account v1 versions\n */\nexport const LightAccountV1Versions = [\n \"v1.0.1\",\n \"v1.0.2\",\n \"v1.1.0\",\n] as const satisfies LightAccountVersion<\"LightAccount\">[];\n\n/**\n * Light Account v2 versions\n */\nexport const LightAccountV2Versions = [\n \"v2.0.0\",\n \"v2.1.0\",\n \"v2.2.0\",\n] as const satisfies LightAccountVersion<\"LightAccount\">[];\n\n/**\n * Type guard to check if a version is a Light Account v1 version\n *\n * @param {LightAccountVersion<\"LightAccount\">} version - The version to check.\n * @returns {boolean} True if the version is a v1 version.\n */\nexport const isLightAccountVersion1 = (\n version: LightAccountVersion<\"LightAccount\">,\n): version is (typeof LightAccountV1Versions)[number] =>\n (LightAccountV1Versions as readonly string[]).includes(version);\n\n/**\n * Type guard to check if a version is a Light Account v2 version\n *\n * @param {LightAccountVersion<\"LightAccount\">} version - The version to check.\n * @returns {boolean} True if the version is a v2 version.\n */\nexport const isLightAccountVersion2 = (\n version: LightAccountVersion<\"LightAccount\">,\n): version is (typeof LightAccountV2Versions)[number] =>\n (LightAccountV2Versions as readonly string[]).includes(version);\n\nexport type GetLightAccountType<TAccount extends LightAccountBase> =\n TAccount[\"smartAccountType\"] extends LightAccountType\n ? TAccount[\"smartAccountType\"]\n : never;\n\nexport type LightAccountAbi<\n TAccountType extends LightAccountType,\n TAccountVersion extends LightAccountVersion<TAccountType>,\n> = TAccountVersion extends keyof (typeof AccountVersionRegistry)[TAccountType]\n ? (typeof AccountVersionRegistry)[TAccountType][TAccountVersion] extends StaticSmartAccountImplementation\n ? (typeof AccountVersionRegistry)[TAccountType][TAccountVersion][\"accountAbi\"]\n : never\n : never;\n\n/**\n * Infers the EntryPoint details as a type, given the account type and version.\n */\nexport type EntryPointFromAccountRegistry<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> =\n (typeof AccountVersionRegistry)[TLightAccountType][TLightAccountVersion] extends StaticSmartAccountImplementation<\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n infer _7702,\n infer entryPointVersion,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n infer _factoryArgs,\n infer entryPointAbi extends Abi\n >\n ? (typeof AccountVersionRegistry)[TLightAccountType][TLightAccountVersion][\"entryPoint\"] extends {\n readonly version: entryPointVersion;\n readonly address: Address;\n readonly abi: entryPointAbi;\n }\n ? (typeof AccountVersionRegistry)[TLightAccountType][TLightAccountVersion][\"entryPoint\"]\n : never\n : never;\n"]}
|
|
@@ -46,7 +46,7 @@ export async function getLightAccountImplAddress(account) {
|
|
|
46
46
|
throw new ChainNotFoundError();
|
|
47
47
|
}
|
|
48
48
|
const version = account.getLightAccountVersion();
|
|
49
|
-
const type = account.
|
|
49
|
+
const type = account.smartAccountType;
|
|
50
50
|
const expectedImplAddresses = Object.values(AccountVersionRegistry[type]).map((x) => x.accountImplementation);
|
|
51
51
|
const getStorageAtAction = getAction(client, getStorageAt, "getStorageAt");
|
|
52
52
|
const storage = await getStorageAtAction({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/light-account/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,sBAAsB,EAAE,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E,cAAc,CAAC,CAAC;IAE3E,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC;QACvC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,+BAA+B;KACtC,CAAC,CAAC;IAEH,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,SAAS,CACjB,+BAA+B,+BAA+B,EAAE,CACjE,CAAC;IACJ,CAAC;IAED,IACE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1B,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EACrE,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,0DAA0D,IAAI,IAAI,MAAM,CACtE,OAAO,CACR,EAAE,CACJ,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { BaseError, ChainNotFoundError, lowerAddress } from \"@alchemy/common\";\nimport { hexToNumber, trim, type Address } from \"viem\";\nimport { getStorageAt } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\nimport type { LightAccountBase } from \"./accounts/base.js\";\nimport type { LightAccountType, LightAccountVersion } from \"./registry.js\";\nimport { AccountVersionRegistry } from \"./registry.js\";\n\n// TODO(v5): The pattern of getDefaultXYZAddress(…) doesn’t really make sense as a standalone.\n// We built this expecting lots of diverging addresses per chain, but in practice we have none\n// (and we’ve turned down things that require this). Instead: we could build the\n// default-but-overridable behavior into the consuming functions themselves (i.e.\n// createLightAccount defaulting to a factory address, but make it overridable)\n\n/**\n * Get the default light account version for the given light account type\n *\n * @template {LightAccountType} TLightAccountType\n * @returns {LightAccountVersion<TLightAccountType>} the default version for the given light account type\n */\nexport const defaultLightAccountVersion = <\n TLightAccountType extends LightAccountType,\n>(): LightAccountVersion<TLightAccountType> => \"v2.0.0\";\n\n/**\n * Can be used to check if the account with one of the following implementation addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Impls = [\n AccountVersionRegistry.LightAccount[\"v1.0.1\"],\n AccountVersionRegistry.LightAccount[\"v1.0.2\"],\n];\n\n/**\n * Can be used to check if the account with one of the following factory addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Factories = new Set(\n LightAccountUnsupported1271Impls.map((x) => [x.factoryAddress]).flat(),\n);\n\nexport const EIP1967_PROXY_IMPL_STORAGE_SLOT =\n \"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc\";\n\n/**\n * Get the light account implementation address for the given light account\n *\n * @param {LightAccountBase} account - the light account to get the implementation address for\n * @returns {Promise<Address>} the light account implementation address for the given light account\n */\nexport async function getLightAccountImplAddress<\n TAccount extends LightAccountBase,\n>(account: TAccount): Promise<Address> {\n const client = account.client;\n const chain = client.chain;\n if (!chain) {\n throw new ChainNotFoundError();\n }\n const version = account.getLightAccountVersion();\n const type = account.smartAccountType;\n\n const expectedImplAddresses = Object.values(AccountVersionRegistry[type]).map(\n (x) => x.accountImplementation,\n );\n\n const getStorageAtAction = getAction(client, getStorageAt, \"getStorageAt\");\n\n const storage = await getStorageAtAction({\n address: account.address,\n slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,\n });\n\n if (storage == null) {\n throw new BaseError(\n `Failed to get storage slot: ${EIP1967_PROXY_IMPL_STORAGE_SLOT}`,\n );\n }\n\n if (\n hexToNumber(storage) !== 0 &&\n !expectedImplAddresses.some((x) => x === lowerAddress(trim(storage)))\n ) {\n throw new BaseError(\n `could not determine if smart account implementation is ${type} ${String(\n version,\n )}`,\n );\n }\n\n return trim(storage);\n}\n"]}
|
|
@@ -1,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
|
|
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 =
|
|
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;A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H,OAAO,IAAI,KAAK,eAAe;gBAC7B,CAAC,CAAC,iBAAiB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBACtD,CAAC,CAAC,mBAAmB,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QACvD,CAAC;QAED,KAAK,CAAC,iBAAiB,CAAC,UAAU;YAChC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,aAAa,EAAE,GAAG,UAAU,CAAC;YACnE,MAAM,UAAU,GAAG,oBAAoB,CAAC;gBACtC,OAAO;gBACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,aAAa,EAAE;oBACb,GAAG,aAAa;oBAChB,MAAM,EAAE,cAAc;iBACvB;aACF,CAAC,CAAC;YAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YACxE,OAAO,iBAAiB,CAAC;gBACvB,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE;oBACP,GAAG,EAAE,UAAU;iBAChB;aACF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE;YACN,MAAM,EAAE,IAAI;YACZ,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 source: 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 source: 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,GA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B,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QACvD,CAAC;QAED,KAAK,CAAC,iBAAiB,CAAC,UAAU;YAChC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,aAAa,EAAE,GAAG,UAAU,CAAC;YACnE,MAAM,UAAU,GAAG,oBAAoB,CAAC;gBACtC,OAAO;gBACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,iBAAiB,EAAE,UAAU,CAAC,OAAO;gBACrC,aAAa,EAAE;oBACb,GAAG,aAAa;oBAChB,MAAM,EAAE,cAAc;iBACvB;aACF,CAAC,CAAC;YAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YACxE,OAAO,iBAAiB,CAAC;gBACvB,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE;oBACP,GAAG,EAAE,UAAU;iBAChB;aACF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,IAAI;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type Hash,\n type TypedDataDefinition,\n 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"]}
|
|
@@ -9,14 +9,19 @@ export type ToMultiOwnerModularAccountV1Params = {
|
|
|
9
9
|
owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{
|
|
10
10
|
address: Address;
|
|
11
11
|
}[]];
|
|
12
|
-
salt?: bigint;
|
|
13
12
|
accountAddress?: Address;
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
factory?: Address;
|
|
14
|
+
} & ({
|
|
15
|
+
salt?: bigint;
|
|
16
|
+
factoryData?: never;
|
|
17
|
+
} | {
|
|
18
|
+
salt?: never;
|
|
19
|
+
factoryData?: Hex;
|
|
20
|
+
});
|
|
16
21
|
/**
|
|
17
22
|
* Creates a multi-owner MAv1 account.
|
|
18
23
|
*
|
|
19
24
|
* @param {ToMultiOwnerModularAccountV1Params} param0 - The parameters for creating a multi-owner MAv1 account.
|
|
20
25
|
* @returns {Promise<MultiOwnerModularAccountV1<TSigner>>} A multi-owner MAv1 account.
|
|
21
26
|
*/
|
|
22
|
-
export declare function toMultiOwnerModularAccountV1({ client, salt, owners, accountAddress: accountAddress_,
|
|
27
|
+
export declare function toMultiOwnerModularAccountV1({ client, salt, owners, accountAddress: accountAddress_, factory, factoryData: factoryData_, }: ToMultiOwnerModularAccountV1Params): Promise<MultiOwnerModularAccountV1>;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { encodeFunctionData, hexToBigInt, } from "viem";
|
|
2
2
|
import { toModularAccountV1Base } from "./base.js";
|
|
3
3
|
import { lowerAddress, BaseError } from "@alchemy/common";
|
|
4
4
|
import { DefaultMaV1Address, DefaultMaV1PluginAddress } from "../account.js";
|
|
5
5
|
import { MultiOwnerModularAccountFactoryAbi } from "../abis/MultiOwnerModularAccountFactory.js";
|
|
6
|
-
import { predictMultiOwnerModularAccountV1Address } from "../predictAddress.js";
|
|
6
|
+
import { getMultiOwnerModularAccountV1AddressFromFactoryData, predictMultiOwnerModularAccountV1Address, } from "../predictAddress.js";
|
|
7
7
|
import { MultiOwnerPluginExecutionFunctionAbi } from "../abis/MultiOwnerPluginExecutionFunction.js";
|
|
8
8
|
import { readContract } from "viem/actions";
|
|
9
9
|
import { getAction } from "viem/utils";
|
|
10
10
|
import { MultiOwnerPluginAbi } from "../abis/MultiOwnerPlugin.js";
|
|
11
|
+
import { entryPoint06Address } from "viem/account-abstraction";
|
|
11
12
|
/**
|
|
12
13
|
* Creates a multi-owner MAv1 account.
|
|
13
14
|
*
|
|
14
15
|
* @param {ToMultiOwnerModularAccountV1Params} param0 - The parameters for creating a multi-owner MAv1 account.
|
|
15
16
|
* @returns {Promise<MultiOwnerModularAccountV1<TSigner>>} A multi-owner MAv1 account.
|
|
16
17
|
*/
|
|
17
|
-
export async function toMultiOwnerModularAccountV1({ client, salt = 0n, owners, accountAddress: accountAddress_,
|
|
18
|
+
export async function toMultiOwnerModularAccountV1({ client, salt = 0n, owners, accountAddress: accountAddress_, factory = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY, factoryData: factoryData_, }) {
|
|
18
19
|
const signer = owners[0];
|
|
19
20
|
const dedupedOwners = Array.from(new Set(owners.map((it) => lowerAddress(it.address))));
|
|
20
21
|
const sortedOwners = dedupedOwners.sort((a, b) => {
|
|
@@ -23,19 +24,30 @@ export async function toMultiOwnerModularAccountV1({ client, salt = 0n, owners,
|
|
|
23
24
|
return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;
|
|
24
25
|
});
|
|
25
26
|
const accountAddress = accountAddress_ ??
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
(factoryData_
|
|
28
|
+
? await getMultiOwnerModularAccountV1AddressFromFactoryData({
|
|
29
|
+
client,
|
|
30
|
+
factoryAddress: factory,
|
|
31
|
+
factoryData: factoryData_,
|
|
32
|
+
entryPoint: {
|
|
33
|
+
version: "0.6",
|
|
34
|
+
address: entryPoint06Address,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
: predictMultiOwnerModularAccountV1Address({
|
|
38
|
+
factoryAddress: factory,
|
|
39
|
+
salt,
|
|
40
|
+
ownerAddresses: sortedOwners,
|
|
41
|
+
}));
|
|
31
42
|
const getFactoryArgs = async () => {
|
|
32
|
-
const factoryData =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
const factoryData = factoryData_ ??
|
|
44
|
+
encodeFunctionData({
|
|
45
|
+
abi: MultiOwnerModularAccountFactoryAbi,
|
|
46
|
+
functionName: "createAccount",
|
|
47
|
+
args: [salt, sortedOwners],
|
|
48
|
+
});
|
|
37
49
|
return {
|
|
38
|
-
factory
|
|
50
|
+
factory,
|
|
39
51
|
factoryData,
|
|
40
52
|
};
|
|
41
53
|
};
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"multi-owner-account.js","sourceRoot":"","sources":["../../../../src/ma-v1/accounts/multi-owner-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,WAAW,GAWZ,MAAM,MAAM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AAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n encodeFunctionData,\n hexToBigInt,\n type Address,\n type Chain,\n type Client,\n type Hash,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type OneOf,\n type Transport,\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 {\n getMultiOwnerModularAccountV1AddressFromFactoryData,\n predictMultiOwnerModularAccountV1Address,\n} 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\";\nimport { entryPoint06Address } from \"viem/account-abstraction\";\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 accountAddress?: Address;\n factory?: Address;\n} & (\n | { salt?: bigint; factoryData?: never }\n | { salt?: never; 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 (factoryData_\n ? await getMultiOwnerModularAccountV1AddressFromFactoryData({\n client,\n factoryAddress: factory,\n factoryData: factoryData_,\n entryPoint: {\n version: \"0.6\",\n address: entryPoint06Address,\n },\n })\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"]}
|
|
@@ -2,7 +2,8 @@ import { sendUserOperation } from "viem/account-abstraction";
|
|
|
2
2
|
import { getAction } from "viem/utils";
|
|
3
3
|
import { AccountNotFoundError } from "@alchemy/common";
|
|
4
4
|
function isMultiOwnerModularAccountV1(account) {
|
|
5
|
-
return "
|
|
5
|
+
return ("smartAccountType" in account &&
|
|
6
|
+
account.smartAccountType === "MultiOwnerModularAccountV1");
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* Generates client actions for a multi-owner MAv1 account, including the ability to update owners.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiOwner.js","sourceRoot":"","sources":["../../../../src/ma-v1/decorators/multiOwner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAqB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAgBvD,SAAS,4BAA4B,CACnC,OAAqB;IAErB,OAAO,
|
|
1
|
+
{"version":3,"file":"multiOwner.js","sourceRoot":"","sources":["../../../../src/ma-v1/decorators/multiOwner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAqB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAgBvD,SAAS,4BAA4B,CACnC,OAAqB;IAErB,OAAO,CACL,kBAAkB,IAAI,OAAO;QAC7B,OAAO,CAAC,gBAAgB,KAAK,4BAA4B,CAC1D,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAK/C,MAA4C;IAI5C,OAAO;QACL,yFAAyF;QACzF,uFAAuF;QACvF,6EAA6E;QAC7E,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAC3B,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;YAEvE,IAAI,CAAC,OAAO,IAAI,CAAC,4BAA4B,CAAC,OAAO,CAAC,EAAE,CAAC;gBACvD,MAAM,IAAI,oBAAoB,EAAE,CAAC;YACnC,CAAC;YAED,MAAM,IAAI,GAAG,OAAO,CAAC,kBAAkB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;YAErE,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;YACzE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC;gBAC1B,KAAK,EAAE;oBACL;wBACE,EAAE,EAAE,OAAO,CAAC,OAAO;wBACnB,IAAI;qBACL;iBACF;gBACD,OAAO;aACR,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Address, Chain, Client, Hex, IsUndefined, Transport } from \"viem\";\nimport { sendUserOperation, type SmartAccount } from \"viem/account-abstraction\";\nimport { getAction } from \"viem/utils\";\nimport type { GetAccountParameter } from \"../../types.js\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport type { MultiOwnerModularAccountV1 } from \"../accounts/multi-owner-account.js\";\n\nexport type MultiOwnerModularAccountV1Actions<\n TAccount extends MultiOwnerModularAccountV1 | undefined =\n | MultiOwnerModularAccountV1\n | undefined,\n> = {\n updateOwners: (\n args: {\n ownersToAdd: Address[];\n ownersToRemove: Address[];\n } & GetAccountParameter<TAccount, MultiOwnerModularAccountV1>,\n ) => Promise<Hex>;\n};\n\nfunction isMultiOwnerModularAccountV1(\n account: SmartAccount,\n): account is MultiOwnerModularAccountV1 {\n return (\n \"smartAccountType\" in account &&\n account.smartAccountType === \"MultiOwnerModularAccountV1\"\n );\n}\n\n/**\n * Generates client actions for a multi-owner MAv1 account, including the ability to update owners.\n *\n * @param {Client<TTransport, TChain, TAccount>} client The client instance used to interact with the account\n * @returns {MultiOwnerLightAccountActions<TAccount>} An object containing the client actions specifically for a multi-owner modular account\n */\nexport function multiOwnerModularAccountV1Actions<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): MultiOwnerModularAccountV1Actions<\n IsUndefined<TAccount> extends true ? undefined : MultiOwnerModularAccountV1\n> {\n return {\n // TODO(v5): Another pattern I think we should consider deprecating for v5 - actions that\n // implicitly do a sendUserOperation internally. These are non-composable with batching\n // and have a number of other issues that are solved with viem writeContract.\n updateOwners: async (args) => {\n const { ownersToAdd, ownersToRemove, account = client.account } = args;\n\n if (!account || !isMultiOwnerModularAccountV1(account)) {\n throw new AccountNotFoundError();\n }\n\n const data = account.encodeUpdateOwners(ownersToAdd, ownersToRemove);\n\n const action = getAction(client, sendUserOperation, \"sendUserOperation\");\n const result = await action({\n calls: [\n {\n to: account.address,\n data,\n },\n ],\n account,\n });\n\n return result;\n },\n };\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type Address } from "viem";
|
|
1
|
+
import { type Address, type Client, type Hex } from "viem";
|
|
2
|
+
import type { EntryPointVersion } from "viem/account-abstraction";
|
|
2
3
|
export type PredictMultiOwnerModularAccountV1AddressParams = {
|
|
3
4
|
salt: bigint;
|
|
4
5
|
ownerAddresses: Address[];
|
|
@@ -26,3 +27,21 @@ export type PredictMultiOwnerModularAccountV1AddressParams = {
|
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
29
|
export declare const predictMultiOwnerModularAccountV1Address: ({ salt, ownerAddresses, factoryAddress, }: PredictMultiOwnerModularAccountV1AddressParams) => Address;
|
|
30
|
+
export type GetMultiOwnerModularAccountV1AddressFromFactoryDataParams = {
|
|
31
|
+
client: Client;
|
|
32
|
+
factoryAddress: Address;
|
|
33
|
+
factoryData: Hex;
|
|
34
|
+
entryPoint: {
|
|
35
|
+
version: EntryPointVersion;
|
|
36
|
+
address: Address;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Gets the multi-owner modular account v1 address from factory data.
|
|
41
|
+
* If the factory is a known default, decodes the args and predicts without RPC.
|
|
42
|
+
* Otherwise falls back to calling the entry point's getSenderAddress.
|
|
43
|
+
*
|
|
44
|
+
* @param {GetMultiOwnerModularAccountV1AddressFromFactoryDataParams} params - The parameters
|
|
45
|
+
* @returns {Promise<Address>} The account address
|
|
46
|
+
*/
|
|
47
|
+
export declare function getMultiOwnerModularAccountV1AddressFromFactoryData({ client, factoryAddress, factoryData, entryPoint, }: GetMultiOwnerModularAccountV1AddressFromFactoryDataParams): Promise<Address>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { concatHex, decodeFunctionData, encodeAbiParameters, getContractAddress, isAddressEqual, keccak256, } from "viem";
|
|
2
2
|
import { DefaultMaV1Address } from "./account.js";
|
|
3
|
+
import { MultiOwnerModularAccountFactoryAbi } from "./abis/MultiOwnerModularAccountFactory.js";
|
|
3
4
|
import { BaseError } from "@alchemy/common";
|
|
5
|
+
import { getSenderFromFactoryData } from "../utils.js";
|
|
4
6
|
/**
|
|
5
7
|
* Predicts the address of a MultiOwnerModularAccountV1 smart account before deployment.
|
|
6
8
|
*
|
|
@@ -48,4 +50,38 @@ function getERC1967ProxyInitCodeHash(implementationAddress) {
|
|
|
48
50
|
const constructorArgs = encodeAbiParameters([{ type: "address" }, { type: "bytes" }], [implementationAddress, "0x"]);
|
|
49
51
|
return keccak256(concatHex([ERC1967_PROXY_BYTECODE, constructorArgs]));
|
|
50
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the multi-owner modular account v1 address from factory data.
|
|
55
|
+
* If the factory is a known default, decodes the args and predicts without RPC.
|
|
56
|
+
* Otherwise falls back to calling the entry point's getSenderAddress.
|
|
57
|
+
*
|
|
58
|
+
* @param {GetMultiOwnerModularAccountV1AddressFromFactoryDataParams} params - The parameters
|
|
59
|
+
* @returns {Promise<Address>} The account address
|
|
60
|
+
*/
|
|
61
|
+
export async function getMultiOwnerModularAccountV1AddressFromFactoryData({ client, factoryAddress, factoryData, entryPoint, }) {
|
|
62
|
+
if (isAddressEqual(factoryAddress, DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY)) {
|
|
63
|
+
try {
|
|
64
|
+
const decoded = decodeFunctionData({
|
|
65
|
+
abi: MultiOwnerModularAccountFactoryAbi,
|
|
66
|
+
data: factoryData,
|
|
67
|
+
});
|
|
68
|
+
if (decoded.functionName === "createAccount") {
|
|
69
|
+
const [decodedSalt, decodedOwners] = decoded.args;
|
|
70
|
+
return predictMultiOwnerModularAccountV1Address({
|
|
71
|
+
factoryAddress,
|
|
72
|
+
salt: decodedSalt,
|
|
73
|
+
ownerAddresses: [...decodedOwners],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Decode failed, fall through to RPC
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return getSenderFromFactoryData(client, {
|
|
82
|
+
factory: factoryAddress,
|
|
83
|
+
factoryData,
|
|
84
|
+
entryPoint,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
51
87
|
//# sourceMappingURL=predictAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predictAddress.js","sourceRoot":"","sources":["../../../src/ma-v1/predictAddress.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"predictAddress.js","sourceRoot":"","sources":["../../../src/ma-v1/predictAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,SAAS,GAEV,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AASvD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,EACvD,IAAI,EACJ,cAAc,EACd,cAAc,GAAG,kBAAkB,CAAC,wBAAwB,GACb,EAAW,EAAE;IAC5D,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,cAAc,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAE3D,MAAM,YAAY,GAAG,2BAA2B,CAC9C,kBAAkB,CAAC,sBAAsB,CAC1C,CAAC;IAEF,OAAO,kBAAkB,CAAC;QACxB,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,YAAY;QAClB,YAAY,EAAE,YAAY;KAC3B,CAAC,CAAC;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d,IAAI,EAAE,WAAW;oBACjB,cAAc,EAAE,CAAC,GAAG,aAAa,CAAC;iBACnC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,qCAAqC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,wBAAwB,CAAC,MAAM,EAAE;QACtC,OAAO,EAAE,cAAc;QACvB,WAAW;QACX,UAAU;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Client,\n concatHex,\n decodeFunctionData,\n encodeAbiParameters,\n getContractAddress,\n isAddressEqual,\n keccak256,\n type Hex,\n} from \"viem\";\nimport type { EntryPointVersion } from \"viem/account-abstraction\";\nimport { DefaultMaV1Address } from \"./account.js\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"./abis/MultiOwnerModularAccountFactory.js\";\nimport { BaseError } from \"@alchemy/common\";\nimport { getSenderFromFactoryData } from \"../utils.js\";\n\nexport type PredictMultiOwnerModularAccountV1AddressParams = {\n salt: bigint;\n /* Owner addresses must be already deduped, sorted in ascending order, and have the signer address included. */\n ownerAddresses: Address[];\n factoryAddress?: Address;\n};\n\n/**\n * Predicts the address of a MultiOwnerModularAccountV1 smart account before deployment.\n *\n * This function uses CREATE2 to deterministically compute the account address based on the factory address,\n * salt, and owner addresses. The predicted address will match the actual deployed address if the same\n * parameters are used during deployment.\n *\n * @param {PredictMultiOwnerModularAccountV1AddressParams} params The parameters for predicting the account address\n * @param {bigint} params.salt A unique value used to generate different account addresses for the same set of owners\n * @param {Address[]} params.ownerAddresses Array of owner addresses that will control the account. Must be deduplicated, sorted in ascending order, and include the signer address. Cannot be empty and must contain at most 100 addresses.\n * @param {Address} [params.factoryAddress] The factory contract address that will deploy the account. Defaults to the standard MultiOwnerModularAccountV1 factory address.\n * @returns {Address} The predicted address where the account will be deployed\n *\n * @example\n * ```ts\n * const predictedAddress = predictMultiOwnerModularAccountV1Address({\n * salt: 0n,\n * ownerAddresses: [\"0x1234...\", \"0x5678...\"]\n * });\n * ```\n */\nexport const predictMultiOwnerModularAccountV1Address = ({\n salt,\n ownerAddresses,\n factoryAddress = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n}: PredictMultiOwnerModularAccountV1AddressParams): Address => {\n if (ownerAddresses.length === 0) {\n throw new BaseError(\"Owners array cannot be empty\");\n }\n if (ownerAddresses.length > 100) {\n throw new Error(\"Maximum 100 owners on creation\");\n }\n\n const combinedSalt = getCombinedSalt(salt, ownerAddresses);\n\n const initCodeHash = getERC1967ProxyInitCodeHash(\n DefaultMaV1Address.IMPLEMENTATION_ADDRESS,\n );\n\n return getContractAddress({\n from: factoryAddress,\n opcode: \"CREATE2\",\n salt: combinedSalt,\n bytecodeHash: initCodeHash,\n });\n};\n\nfunction getCombinedSalt(salt: bigint, owners: Address[]): Hex {\n const encodedOwners = encodeAbiParameters([{ type: \"address[]\" }], [owners]);\n const saltAndOwners = encodeAbiParameters(\n [{ type: \"uint256\" }, { type: \"bytes\" }],\n [salt, encodedOwners],\n );\n return keccak256(saltAndOwners);\n}\n\nfunction getERC1967ProxyInitCodeHash(implementationAddress: Address): Hex {\n const ERC1967_PROXY_BYTECODE =\n \"0x60406080815261042c908138038061001681610218565b93843982019181818403126102135780516001600160a01b038116808203610213576020838101516001600160401b0394919391858211610213570186601f820112156102135780519061007161006c83610253565b610218565b918083528583019886828401011161021357888661008f930161026e565b813b156101b9577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b031916841790556000927fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8480a28051158015906101b2575b61010b575b855160e790816103458239f35b855194606086019081118682101761019e578697849283926101889952602788527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c87890152660819985a5b195960ca1b8a8901525190845af4913d15610194573d9061017a61006c83610253565b91825281943d92013e610291565b508038808080806100fe565b5060609250610291565b634e487b7160e01b84526041600452602484fd5b50826100f9565b855162461bcd60e51b815260048101859052602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761023d57604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161023d57601f01601f191660200190565b60005b8381106102815750506000910152565b8181015183820152602001610271565b919290156102f357508151156102a5575090565b3b156102ae5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156103065750805190602001fd5b6044604051809262461bcd60e51b825260206004830152610336815180928160248601526020868601910161026e565b601f01601f19168101030190fdfe60806040523615605f5773ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f35b3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f3fea26469706673582212208f3104255ee3c201238ea03e118ee6ec0a2cff51cbfbdc3af1727982a5a959a564736f6c63430008160033\" as const;\n\n const constructorArgs = encodeAbiParameters(\n [{ type: \"address\" }, { type: \"bytes\" }],\n [implementationAddress, \"0x\"],\n );\n\n return keccak256(concatHex([ERC1967_PROXY_BYTECODE, constructorArgs]));\n}\n\nexport type GetMultiOwnerModularAccountV1AddressFromFactoryDataParams = {\n client: Client;\n factoryAddress: Address;\n factoryData: Hex;\n entryPoint: {\n version: EntryPointVersion;\n address: Address;\n };\n};\n\n/**\n * Gets the multi-owner modular account v1 address from factory data.\n * If the factory is a known default, decodes the args and predicts without RPC.\n * Otherwise falls back to calling the entry point's getSenderAddress.\n *\n * @param {GetMultiOwnerModularAccountV1AddressFromFactoryDataParams} params - The parameters\n * @returns {Promise<Address>} The account address\n */\nexport async function getMultiOwnerModularAccountV1AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData,\n entryPoint,\n}: GetMultiOwnerModularAccountV1AddressFromFactoryDataParams): Promise<Address> {\n if (\n isAddressEqual(factoryAddress, DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY)\n ) {\n try {\n const decoded = decodeFunctionData({\n abi: MultiOwnerModularAccountFactoryAbi,\n data: factoryData,\n });\n if (decoded.functionName === \"createAccount\") {\n const [decodedSalt, decodedOwners] = decoded.args;\n return predictMultiOwnerModularAccountV1Address({\n factoryAddress,\n salt: decodedSalt,\n ownerAddresses: [...decodedOwners],\n });\n }\n } catch {\n // Decode failed, fall through to RPC\n }\n }\n return getSenderFromFactoryData(client, {\n factory: factoryAddress,\n factoryData,\n entryPoint,\n });\n}\n"]}
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
import { type Address, type Chain, type Client, type Hex, type JsonRpcAccount, type LocalAccount, type Transport } from "viem";
|
|
2
|
-
import type { WebAuthnAccount } from "viem/account-abstraction";
|
|
3
2
|
import { type ModularAccountV2Base } from "./base.js";
|
|
4
3
|
import type { SignerEntity } from "../types.js";
|
|
5
4
|
type Mode = "default" | "7702";
|
|
6
5
|
export type ModularAccountV2 = ModularAccountV2Base & {};
|
|
7
6
|
export type ToModularAccountV2Params<TMode extends Mode | undefined = Mode | undefined> = {
|
|
8
7
|
client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;
|
|
9
|
-
owner: JsonRpcAccount | LocalAccount
|
|
8
|
+
owner: JsonRpcAccount | LocalAccount;
|
|
10
9
|
deferredAction?: Hex;
|
|
11
10
|
signerEntity?: SignerEntity;
|
|
12
11
|
accountAddress?: Address;
|
|
13
12
|
mode?: TMode;
|
|
14
13
|
} & (TMode extends "7702" ? {
|
|
15
14
|
salt?: never;
|
|
16
|
-
|
|
15
|
+
factory?: never;
|
|
17
16
|
factoryData?: never;
|
|
18
17
|
implementationAddress?: never;
|
|
19
18
|
} : {
|
|
19
|
+
factory?: Address;
|
|
20
|
+
implementationAddress?: Address;
|
|
21
|
+
} & ({
|
|
20
22
|
salt?: bigint;
|
|
21
|
-
|
|
23
|
+
factoryData?: never;
|
|
24
|
+
} | {
|
|
25
|
+
salt?: never;
|
|
22
26
|
factoryData?: Hex;
|
|
23
|
-
|
|
24
|
-
});
|
|
27
|
+
}));
|
|
25
28
|
/**
|
|
26
29
|
* Creates a MAv2 account.
|
|
27
30
|
*
|
|
28
31
|
* @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
|
|
29
32
|
* @returns {Promise<ModularAccountV2>} A MAv2 account.
|
|
30
33
|
*/
|
|
31
|
-
export declare function toModularAccountV2<TMode extends Mode = Mode>({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt,
|
|
34
|
+
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
35
|
export {};
|