@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
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
lightAccountStaticImplV1_0_2,
|
|
6
6
|
lightAccountStaticImplV1_1_0,
|
|
7
7
|
lightAccountStaticImplV2_0_0,
|
|
8
|
+
lightAccountStaticImplV2_1_0,
|
|
9
|
+
lightAccountStaticImplV2_2_0,
|
|
8
10
|
multiOwnerLightAccountStaticImplV2_0_0,
|
|
9
11
|
} from "./lightAccountStaticImpl.js";
|
|
10
12
|
import type { StaticSmartAccountImplementation } from "../types.js";
|
|
@@ -20,6 +22,8 @@ export const AccountVersionRegistry = {
|
|
|
20
22
|
"v1.0.2": lightAccountStaticImplV1_0_2,
|
|
21
23
|
"v1.1.0": lightAccountStaticImplV1_1_0,
|
|
22
24
|
"v2.0.0": lightAccountStaticImplV2_0_0,
|
|
25
|
+
"v2.1.0": lightAccountStaticImplV2_1_0,
|
|
26
|
+
"v2.2.0": lightAccountStaticImplV2_2_0,
|
|
23
27
|
},
|
|
24
28
|
MultiOwnerLightAccount: {
|
|
25
29
|
"v2.0.0": multiOwnerLightAccountStaticImplV2_0_0,
|
|
@@ -34,8 +38,50 @@ export type LightAccountType = Extract<
|
|
|
34
38
|
export type LightAccountVersion<TAccountType extends LightAccountType> =
|
|
35
39
|
keyof (typeof AccountVersionRegistry)[TAccountType];
|
|
36
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Light Account v1 versions
|
|
43
|
+
*/
|
|
44
|
+
export const LightAccountV1Versions = [
|
|
45
|
+
"v1.0.1",
|
|
46
|
+
"v1.0.2",
|
|
47
|
+
"v1.1.0",
|
|
48
|
+
] as const satisfies LightAccountVersion<"LightAccount">[];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Light Account v2 versions
|
|
52
|
+
*/
|
|
53
|
+
export const LightAccountV2Versions = [
|
|
54
|
+
"v2.0.0",
|
|
55
|
+
"v2.1.0",
|
|
56
|
+
"v2.2.0",
|
|
57
|
+
] as const satisfies LightAccountVersion<"LightAccount">[];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Type guard to check if a version is a Light Account v1 version
|
|
61
|
+
*
|
|
62
|
+
* @param {LightAccountVersion<"LightAccount">} version - The version to check.
|
|
63
|
+
* @returns {boolean} True if the version is a v1 version.
|
|
64
|
+
*/
|
|
65
|
+
export const isLightAccountVersion1 = (
|
|
66
|
+
version: LightAccountVersion<"LightAccount">,
|
|
67
|
+
): version is (typeof LightAccountV1Versions)[number] =>
|
|
68
|
+
(LightAccountV1Versions as readonly string[]).includes(version);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Type guard to check if a version is a Light Account v2 version
|
|
72
|
+
*
|
|
73
|
+
* @param {LightAccountVersion<"LightAccount">} version - The version to check.
|
|
74
|
+
* @returns {boolean} True if the version is a v2 version.
|
|
75
|
+
*/
|
|
76
|
+
export const isLightAccountVersion2 = (
|
|
77
|
+
version: LightAccountVersion<"LightAccount">,
|
|
78
|
+
): version is (typeof LightAccountV2Versions)[number] =>
|
|
79
|
+
(LightAccountV2Versions as readonly string[]).includes(version);
|
|
80
|
+
|
|
37
81
|
export type GetLightAccountType<TAccount extends LightAccountBase> =
|
|
38
|
-
TAccount["
|
|
82
|
+
TAccount["smartAccountType"] extends LightAccountType
|
|
83
|
+
? TAccount["smartAccountType"]
|
|
84
|
+
: never;
|
|
39
85
|
|
|
40
86
|
export type LightAccountAbi<
|
|
41
87
|
TAccountType extends LightAccountType,
|
|
@@ -61,7 +61,7 @@ export async function getLightAccountImplAddress<
|
|
|
61
61
|
throw new ChainNotFoundError();
|
|
62
62
|
}
|
|
63
63
|
const version = account.getLightAccountVersion();
|
|
64
|
-
const type = account.
|
|
64
|
+
const type = account.smartAccountType;
|
|
65
65
|
|
|
66
66
|
const expectedImplAddresses = Object.values(AccountVersionRegistry[type]).map(
|
|
67
67
|
(x) => x.accountImplementation,
|
|
@@ -13,12 +13,14 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
entryPoint06Abi,
|
|
15
15
|
toSmartAccount,
|
|
16
|
-
type SmartAccount,
|
|
17
16
|
type SmartAccountImplementation,
|
|
18
17
|
entryPoint06Address,
|
|
19
18
|
getUserOperationHash,
|
|
20
19
|
} from "viem/account-abstraction";
|
|
21
|
-
import type {
|
|
20
|
+
import type {
|
|
21
|
+
SignatureRequest,
|
|
22
|
+
SmartAccountWithDecodeCalls,
|
|
23
|
+
} from "../../types.js";
|
|
22
24
|
import { IStandardExecutorAbi } from "../abis/IStandardExecutor.js";
|
|
23
25
|
import { signMessage, signTypedData } from "viem/actions";
|
|
24
26
|
import {
|
|
@@ -36,14 +38,15 @@ export type BaseMaV1AccountImplementation = SmartAccountImplementation<
|
|
|
36
38
|
typeof entryPoint06Abi,
|
|
37
39
|
"0.6",
|
|
38
40
|
{
|
|
39
|
-
|
|
41
|
+
smartAccountType: MaV1AccountType;
|
|
40
42
|
prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;
|
|
41
43
|
formatSignature: (signature: Hex) => Promise<Hex>;
|
|
42
44
|
},
|
|
43
45
|
false
|
|
44
46
|
>;
|
|
45
47
|
|
|
46
|
-
export type ModularAccountV1Base =
|
|
48
|
+
export type ModularAccountV1Base =
|
|
49
|
+
SmartAccountWithDecodeCalls<BaseMaV1AccountImplementation>;
|
|
47
50
|
|
|
48
51
|
export type ToModularAccountV1BaseParams<
|
|
49
52
|
TTransport extends Transport = Transport,
|
|
@@ -237,7 +240,7 @@ export async function toModularAccountV1Base<
|
|
|
237
240
|
},
|
|
238
241
|
|
|
239
242
|
extend: {
|
|
240
|
-
|
|
243
|
+
smartAccountType: type,
|
|
241
244
|
prepareSignature,
|
|
242
245
|
formatSignature,
|
|
243
246
|
},
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
|
+
encodeFunctionData,
|
|
2
3
|
hexToBigInt,
|
|
3
4
|
type Address,
|
|
4
5
|
type Chain,
|
|
5
6
|
type Client,
|
|
7
|
+
type Hash,
|
|
6
8
|
type Hex,
|
|
7
9
|
type JsonRpcAccount,
|
|
8
10
|
type LocalAccount,
|
|
9
11
|
type OneOf,
|
|
10
12
|
type Transport,
|
|
11
|
-
encodeFunctionData,
|
|
12
|
-
type Hash,
|
|
13
13
|
type TypedDataDefinition,
|
|
14
14
|
} from "viem";
|
|
15
15
|
import { toModularAccountV1Base, type ModularAccountV1Base } from "./base.js";
|
|
16
16
|
import { lowerAddress, BaseError } from "@alchemy/common";
|
|
17
17
|
import { DefaultMaV1Address, DefaultMaV1PluginAddress } from "../account.js";
|
|
18
18
|
import { MultiOwnerModularAccountFactoryAbi } from "../abis/MultiOwnerModularAccountFactory.js";
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
getMultiOwnerModularAccountV1AddressFromFactoryData,
|
|
21
|
+
predictMultiOwnerModularAccountV1Address,
|
|
22
|
+
} from "../predictAddress.js";
|
|
20
23
|
import { MultiOwnerPluginExecutionFunctionAbi } from "../abis/MultiOwnerPluginExecutionFunction.js";
|
|
21
24
|
import { readContract } from "viem/actions";
|
|
22
25
|
import { getAction } from "viem/utils";
|
|
23
26
|
import { MultiOwnerPluginAbi } from "../abis/MultiOwnerPlugin.js";
|
|
27
|
+
import { entryPoint06Address } from "viem/account-abstraction";
|
|
24
28
|
|
|
25
29
|
export type MultiOwnerModularAccountV1 = ModularAccountV1Base & {
|
|
26
30
|
encodeUpdateOwners: (
|
|
@@ -33,10 +37,12 @@ export type MultiOwnerModularAccountV1 = ModularAccountV1Base & {
|
|
|
33
37
|
export type ToMultiOwnerModularAccountV1Params = {
|
|
34
38
|
client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;
|
|
35
39
|
owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{ address: Address }[]];
|
|
36
|
-
salt?: bigint;
|
|
37
40
|
accountAddress?: Address;
|
|
38
|
-
|
|
39
|
-
}
|
|
41
|
+
factory?: Address;
|
|
42
|
+
} & (
|
|
43
|
+
| { salt?: bigint; factoryData?: never }
|
|
44
|
+
| { salt?: never; factoryData?: Hex }
|
|
45
|
+
);
|
|
40
46
|
|
|
41
47
|
/**
|
|
42
48
|
* Creates a multi-owner MAv1 account.
|
|
@@ -49,7 +55,8 @@ export async function toMultiOwnerModularAccountV1({
|
|
|
49
55
|
salt = 0n,
|
|
50
56
|
owners,
|
|
51
57
|
accountAddress: accountAddress_,
|
|
52
|
-
|
|
58
|
+
factory = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,
|
|
59
|
+
factoryData: factoryData_,
|
|
53
60
|
}: ToMultiOwnerModularAccountV1Params): Promise<MultiOwnerModularAccountV1> {
|
|
54
61
|
const signer = owners[0];
|
|
55
62
|
|
|
@@ -65,21 +72,33 @@ export async function toMultiOwnerModularAccountV1({
|
|
|
65
72
|
|
|
66
73
|
const accountAddress =
|
|
67
74
|
accountAddress_ ??
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
(factoryData_
|
|
76
|
+
? await getMultiOwnerModularAccountV1AddressFromFactoryData({
|
|
77
|
+
client,
|
|
78
|
+
factoryAddress: factory,
|
|
79
|
+
factoryData: factoryData_,
|
|
80
|
+
entryPoint: {
|
|
81
|
+
version: "0.6",
|
|
82
|
+
address: entryPoint06Address,
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
: predictMultiOwnerModularAccountV1Address({
|
|
86
|
+
factoryAddress: factory,
|
|
87
|
+
salt,
|
|
88
|
+
ownerAddresses: sortedOwners,
|
|
89
|
+
}));
|
|
73
90
|
|
|
74
91
|
const getFactoryArgs = async () => {
|
|
75
|
-
const factoryData =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
const factoryData =
|
|
93
|
+
factoryData_ ??
|
|
94
|
+
encodeFunctionData({
|
|
95
|
+
abi: MultiOwnerModularAccountFactoryAbi,
|
|
96
|
+
functionName: "createAccount",
|
|
97
|
+
args: [salt, sortedOwners],
|
|
98
|
+
});
|
|
80
99
|
|
|
81
100
|
return {
|
|
82
|
-
factory
|
|
101
|
+
factory,
|
|
83
102
|
factoryData,
|
|
84
103
|
};
|
|
85
104
|
};
|
|
@@ -21,7 +21,10 @@ export type MultiOwnerModularAccountV1Actions<
|
|
|
21
21
|
function isMultiOwnerModularAccountV1(
|
|
22
22
|
account: SmartAccount,
|
|
23
23
|
): account is MultiOwnerModularAccountV1 {
|
|
24
|
-
return
|
|
24
|
+
return (
|
|
25
|
+
"smartAccountType" in account &&
|
|
26
|
+
account.smartAccountType === "MultiOwnerModularAccountV1"
|
|
27
|
+
);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
/**
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Address,
|
|
3
|
-
|
|
3
|
+
type Client,
|
|
4
|
+
concatHex,
|
|
5
|
+
decodeFunctionData,
|
|
4
6
|
encodeAbiParameters,
|
|
7
|
+
getContractAddress,
|
|
8
|
+
isAddressEqual,
|
|
5
9
|
keccak256,
|
|
6
|
-
concatHex,
|
|
7
10
|
type Hex,
|
|
8
11
|
} from "viem";
|
|
12
|
+
import type { EntryPointVersion } from "viem/account-abstraction";
|
|
9
13
|
import { DefaultMaV1Address } from "./account.js";
|
|
14
|
+
import { MultiOwnerModularAccountFactoryAbi } from "./abis/MultiOwnerModularAccountFactory.js";
|
|
10
15
|
import { BaseError } from "@alchemy/common";
|
|
16
|
+
import { getSenderFromFactoryData } from "../utils.js";
|
|
11
17
|
|
|
12
18
|
export type PredictMultiOwnerModularAccountV1AddressParams = {
|
|
13
19
|
salt: bigint;
|
|
@@ -83,3 +89,54 @@ function getERC1967ProxyInitCodeHash(implementationAddress: Address): Hex {
|
|
|
83
89
|
|
|
84
90
|
return keccak256(concatHex([ERC1967_PROXY_BYTECODE, constructorArgs]));
|
|
85
91
|
}
|
|
92
|
+
|
|
93
|
+
export type GetMultiOwnerModularAccountV1AddressFromFactoryDataParams = {
|
|
94
|
+
client: Client;
|
|
95
|
+
factoryAddress: Address;
|
|
96
|
+
factoryData: Hex;
|
|
97
|
+
entryPoint: {
|
|
98
|
+
version: EntryPointVersion;
|
|
99
|
+
address: Address;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Gets the multi-owner modular account v1 address from factory data.
|
|
105
|
+
* If the factory is a known default, decodes the args and predicts without RPC.
|
|
106
|
+
* Otherwise falls back to calling the entry point's getSenderAddress.
|
|
107
|
+
*
|
|
108
|
+
* @param {GetMultiOwnerModularAccountV1AddressFromFactoryDataParams} params - The parameters
|
|
109
|
+
* @returns {Promise<Address>} The account address
|
|
110
|
+
*/
|
|
111
|
+
export async function getMultiOwnerModularAccountV1AddressFromFactoryData({
|
|
112
|
+
client,
|
|
113
|
+
factoryAddress,
|
|
114
|
+
factoryData,
|
|
115
|
+
entryPoint,
|
|
116
|
+
}: GetMultiOwnerModularAccountV1AddressFromFactoryDataParams): Promise<Address> {
|
|
117
|
+
if (
|
|
118
|
+
isAddressEqual(factoryAddress, DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY)
|
|
119
|
+
) {
|
|
120
|
+
try {
|
|
121
|
+
const decoded = decodeFunctionData({
|
|
122
|
+
abi: MultiOwnerModularAccountFactoryAbi,
|
|
123
|
+
data: factoryData,
|
|
124
|
+
});
|
|
125
|
+
if (decoded.functionName === "createAccount") {
|
|
126
|
+
const [decodedSalt, decodedOwners] = decoded.args;
|
|
127
|
+
return predictMultiOwnerModularAccountV1Address({
|
|
128
|
+
factoryAddress,
|
|
129
|
+
salt: decodedSalt,
|
|
130
|
+
ownerAddresses: [...decodedOwners],
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
} catch {
|
|
134
|
+
// Decode failed, fall through to RPC
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return getSenderFromFactoryData(client, {
|
|
138
|
+
factory: factoryAddress,
|
|
139
|
+
factoryData,
|
|
140
|
+
entryPoint,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
@@ -9,16 +9,17 @@ import {
|
|
|
9
9
|
type PrivateKeyAccount,
|
|
10
10
|
type Transport,
|
|
11
11
|
} from "viem";
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
import {
|
|
13
|
+
type ToSmartAccountParameters,
|
|
14
|
+
entryPoint07Address,
|
|
15
15
|
} from "viem/account-abstraction";
|
|
16
16
|
import { toModularAccountV2Base, type ModularAccountV2Base } from "./base.js";
|
|
17
17
|
import type { SignerEntity } from "../types.js";
|
|
18
|
-
import {
|
|
19
|
-
|
|
18
|
+
import {
|
|
19
|
+
getModularAccountV2AddressFromFactoryData,
|
|
20
|
+
predictModularAccountV2Address,
|
|
21
|
+
} from "../predictAddress.js";
|
|
20
22
|
import { accountFactoryAbi } from "../abis/accountFactoryAbi.js";
|
|
21
|
-
import { webAuthnFactoryAbi } from "../abis/webAuthnFactoryAbi.js";
|
|
22
23
|
import { EntityIdOverrideError } from "../../errors/EntityIdOverrideError.js";
|
|
23
24
|
import { InvalidOwnerError } from "../../errors/InvalidOwnerError.js";
|
|
24
25
|
import { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from "../utils/account.js";
|
|
@@ -33,7 +34,7 @@ export type ToModularAccountV2Params<
|
|
|
33
34
|
TMode extends Mode | undefined = Mode | undefined,
|
|
34
35
|
> = {
|
|
35
36
|
client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;
|
|
36
|
-
owner: JsonRpcAccount | LocalAccount
|
|
37
|
+
owner: JsonRpcAccount | LocalAccount;
|
|
37
38
|
deferredAction?: Hex;
|
|
38
39
|
signerEntity?: SignerEntity;
|
|
39
40
|
accountAddress?: Address;
|
|
@@ -41,16 +42,23 @@ export type ToModularAccountV2Params<
|
|
|
41
42
|
} & (TMode extends "7702"
|
|
42
43
|
? {
|
|
43
44
|
salt?: never;
|
|
44
|
-
|
|
45
|
+
factory?: never;
|
|
45
46
|
factoryData?: never;
|
|
46
47
|
implementationAddress?: never;
|
|
47
48
|
}
|
|
48
49
|
: {
|
|
49
|
-
|
|
50
|
-
factoryAddress?: Address;
|
|
51
|
-
factoryData?: Hex;
|
|
50
|
+
factory?: Address;
|
|
52
51
|
implementationAddress?: Address;
|
|
53
|
-
}
|
|
52
|
+
} & (
|
|
53
|
+
| {
|
|
54
|
+
salt?: bigint;
|
|
55
|
+
factoryData?: never;
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
salt?: never;
|
|
59
|
+
factoryData?: Hex;
|
|
60
|
+
}
|
|
61
|
+
));
|
|
54
62
|
|
|
55
63
|
/**
|
|
56
64
|
* Creates a MAv2 account.
|
|
@@ -65,7 +73,7 @@ export async function toModularAccountV2<TMode extends Mode = Mode>({
|
|
|
65
73
|
signerEntity,
|
|
66
74
|
accountAddress: accountAddress_,
|
|
67
75
|
salt = 0n,
|
|
68
|
-
|
|
76
|
+
factory,
|
|
69
77
|
factoryData: factoryData_,
|
|
70
78
|
implementationAddress: implementationAddress_,
|
|
71
79
|
mode,
|
|
@@ -81,19 +89,11 @@ export async function toModularAccountV2<TMode extends Mode = Mode>({
|
|
|
81
89
|
|
|
82
90
|
const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;
|
|
83
91
|
|
|
84
|
-
const factoryAddress =
|
|
85
|
-
factoryAddress_ ??
|
|
86
|
-
(owner.type === "webAuthn"
|
|
87
|
-
? DefaultAddress.MAV2_FACTORY_WEBAUTHN
|
|
88
|
-
: DefaultAddress.MAV2_FACTORY);
|
|
92
|
+
const factoryAddress = factory ?? DefaultAddress.MAV2_FACTORY;
|
|
89
93
|
|
|
90
94
|
const implementationAddress =
|
|
91
95
|
implementationAddress_ ??
|
|
92
|
-
(is7702
|
|
93
|
-
? DefaultAddress.SMAV2_7702
|
|
94
|
-
: owner.type === "webAuthn"
|
|
95
|
-
? DefaultAddress.MAV2
|
|
96
|
-
: DefaultAddress.SMAV2_BYTECODE);
|
|
96
|
+
(is7702 ? DefaultAddress.SMAV2_7702 : DefaultAddress.SMAV2_BYTECODE);
|
|
97
97
|
|
|
98
98
|
const getFactoryArgs = async () => {
|
|
99
99
|
if (is7702) {
|
|
@@ -108,20 +108,6 @@ export async function toModularAccountV2<TMode extends Mode = Mode>({
|
|
|
108
108
|
} as const;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
if (owner.type === "webAuthn") {
|
|
112
|
-
const { x, y } = parsePublicKey(owner.publicKey);
|
|
113
|
-
return {
|
|
114
|
-
factory: factoryAddress,
|
|
115
|
-
factoryData:
|
|
116
|
-
factoryData_ ??
|
|
117
|
-
encodeFunctionData({
|
|
118
|
-
abi: webAuthnFactoryAbi,
|
|
119
|
-
functionName: "createWebAuthnAccount",
|
|
120
|
-
args: [x, y, salt, entityId],
|
|
121
|
-
}),
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
111
|
return {
|
|
126
112
|
factory: factoryAddress,
|
|
127
113
|
factoryData:
|
|
@@ -136,24 +122,26 @@ export async function toModularAccountV2<TMode extends Mode = Mode>({
|
|
|
136
122
|
|
|
137
123
|
const accountAddress =
|
|
138
124
|
accountAddress_ ??
|
|
139
|
-
(
|
|
125
|
+
(is7702
|
|
140
126
|
? owner.address
|
|
141
|
-
:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
127
|
+
: factoryData_
|
|
128
|
+
? await getModularAccountV2AddressFromFactoryData({
|
|
129
|
+
client,
|
|
130
|
+
factoryAddress,
|
|
131
|
+
factoryData: factoryData_,
|
|
132
|
+
implementationAddress,
|
|
133
|
+
entryPoint: {
|
|
134
|
+
version: "0.7",
|
|
135
|
+
address: entryPoint07Address,
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
: predictModularAccountV2Address({
|
|
139
|
+
factoryAddress,
|
|
140
|
+
implementationAddress,
|
|
141
|
+
salt,
|
|
142
|
+
type: "SMA",
|
|
143
|
+
ownerAddress: owner.address,
|
|
144
|
+
}));
|
|
157
145
|
|
|
158
146
|
LOGGER.debug("toModularAccountV2:address-resolved", {
|
|
159
147
|
accountAddress,
|
|
@@ -163,7 +151,6 @@ export async function toModularAccountV2<TMode extends Mode = Mode>({
|
|
|
163
151
|
let authorization: ToSmartAccountParameters["authorization"];
|
|
164
152
|
if (is7702) {
|
|
165
153
|
LOGGER.debug("toModularAccountV2:7702-mode");
|
|
166
|
-
// TODO(v5): Ensure this works w/ our signer types.
|
|
167
154
|
if (owner.type !== "local") {
|
|
168
155
|
LOGGER.error("toModularAccountV2:invalid-owner-type", {
|
|
169
156
|
ownerType: owner.type,
|