@account-kit/smart-contracts 4.12.1-alpha.0 → 4.13.1-alpha.0
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/src/index.d.ts +5 -0
- package/dist/esm/src/index.js +2 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.d.ts +39 -0
- package/dist/esm/src/ma-v2/account/{semiModularAccountV2.js → common/modularAccountV2Base.js} +32 -61
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js.map +1 -0
- package/dist/esm/src/ma-v2/account/modularAccountV2.d.ts +16 -0
- package/dist/esm/src/ma-v2/account/modularAccountV2.js +113 -0
- package/dist/esm/src/ma-v2/account/modularAccountV2.js.map +1 -0
- package/dist/esm/src/ma-v2/account/nativeSMASigner.d.ts +1 -1
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js +1 -1
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js.map +1 -1
- package/dist/esm/src/ma-v2/actions/install-validation/installValidation.d.ts +11 -9
- package/dist/esm/src/ma-v2/actions/install-validation/installValidation.js +43 -23
- package/dist/esm/src/ma-v2/actions/install-validation/installValidation.js.map +1 -1
- package/dist/esm/src/ma-v2/client/client.d.ts +7 -6
- package/dist/esm/src/ma-v2/client/client.js +21 -18
- package/dist/esm/src/ma-v2/client/client.js.map +1 -1
- package/dist/esm/src/ma-v2/index.d.ts +0 -4
- package/dist/esm/src/ma-v2/index.js +0 -2
- package/dist/esm/src/ma-v2/index.js.map +1 -1
- package/dist/esm/src/ma-v2/modules/allowlist-module/module.d.ts +14 -0
- package/dist/esm/src/ma-v2/modules/allowlist-module/module.js +14 -0
- package/dist/esm/src/ma-v2/modules/allowlist-module/module.js.map +1 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.d.ts +1 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js +1 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js.map +1 -1
- package/dist/esm/src/ma-v2/modules/time-range-module/module.d.ts +10 -1
- package/dist/esm/src/ma-v2/modules/time-range-module/module.js +20 -0
- package/dist/esm/src/ma-v2/modules/time-range-module/module.js.map +1 -1
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts +40 -0
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts.map +1 -0
- package/dist/types/src/ma-v2/account/modularAccountV2.d.ts +17 -0
- package/dist/types/src/ma-v2/account/modularAccountV2.d.ts.map +1 -0
- package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts +1 -1
- package/dist/types/src/ma-v2/actions/install-validation/installValidation.d.ts +11 -9
- package/dist/types/src/ma-v2/actions/install-validation/installValidation.d.ts.map +1 -1
- package/dist/types/src/ma-v2/client/client.d.ts +7 -6
- package/dist/types/src/ma-v2/client/client.d.ts.map +1 -1
- package/dist/types/src/ma-v2/index.d.ts +0 -4
- package/dist/types/src/ma-v2/index.d.ts.map +1 -1
- package/dist/types/src/ma-v2/modules/allowlist-module/module.d.ts +14 -0
- package/dist/types/src/ma-v2/modules/allowlist-module/module.d.ts.map +1 -1
- package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts +1 -1
- package/dist/types/src/ma-v2/modules/time-range-module/module.d.ts +10 -1
- package/dist/types/src/ma-v2/modules/time-range-module/module.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +7 -0
- package/src/ma-v2/account/{semiModularAccountV2.ts → common/modularAccountV2Base.ts} +62 -105
- package/src/ma-v2/account/modularAccountV2.ts +193 -0
- package/src/ma-v2/account/nativeSMASigner.ts +1 -1
- package/src/ma-v2/actions/install-validation/installValidation.ts +75 -36
- package/src/ma-v2/client/client.ts +54 -34
- package/src/ma-v2/index.ts +0 -5
- package/src/ma-v2/modules/allowlist-module/module.ts +29 -0
- package/src/ma-v2/modules/single-signer-validation/signer.ts +1 -1
- package/src/ma-v2/modules/time-range-module/module.ts +34 -1
- package/dist/esm/src/ma-v2/account/semiModularAccountV2.d.ts +0 -41
- package/dist/esm/src/ma-v2/account/semiModularAccountV2.js.map +0 -1
- package/dist/types/src/ma-v2/account/semiModularAccountV2.d.ts +0 -42
- package/dist/types/src/ma-v2/account/semiModularAccountV2.d.ts.map +0 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EntryPointDef,
|
|
3
|
+
SmartAccountSigner,
|
|
4
|
+
ToSmartContractAccountParams,
|
|
5
|
+
} from "@aa-sdk/core";
|
|
6
|
+
import {
|
|
7
|
+
createBundlerClient,
|
|
8
|
+
getEntryPoint,
|
|
9
|
+
getAccountAddress,
|
|
10
|
+
EntityIdOverrideError,
|
|
11
|
+
InvalidModularAccountV2Mode,
|
|
12
|
+
} from "@aa-sdk/core";
|
|
13
|
+
import {
|
|
14
|
+
concatHex,
|
|
15
|
+
encodeFunctionData,
|
|
16
|
+
type Address,
|
|
17
|
+
type Chain,
|
|
18
|
+
type Hex,
|
|
19
|
+
type Transport,
|
|
20
|
+
} from "viem";
|
|
21
|
+
import { accountFactoryAbi } from "../abis/accountFactoryAbi.js";
|
|
22
|
+
import { getDefaultMAV2FactoryAddress } from "../utils.js";
|
|
23
|
+
import {
|
|
24
|
+
type SignerEntity,
|
|
25
|
+
type ModularAccountV2,
|
|
26
|
+
createMAv2Base,
|
|
27
|
+
} from "./common/modularAccountV2Base.js";
|
|
28
|
+
import { DEFAULT_OWNER_ENTITY_ID } from "../utils.js";
|
|
29
|
+
|
|
30
|
+
export type CreateModularAccountV2Params<
|
|
31
|
+
TTransport extends Transport = Transport,
|
|
32
|
+
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
33
|
+
> = (Pick<
|
|
34
|
+
ToSmartContractAccountParams<"ModularAccountV2", TTransport, Chain, "0.7.0">,
|
|
35
|
+
"transport" | "chain" | "accountAddress"
|
|
36
|
+
> & {
|
|
37
|
+
signer: TSigner;
|
|
38
|
+
entryPoint?: EntryPointDef<"0.7.0", Chain>;
|
|
39
|
+
signerEntity?: SignerEntity;
|
|
40
|
+
}) &
|
|
41
|
+
(
|
|
42
|
+
| {
|
|
43
|
+
mode?: "default";
|
|
44
|
+
salt?: bigint;
|
|
45
|
+
factoryAddress?: Address;
|
|
46
|
+
initCode?: Hex;
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
mode: "7702";
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export async function createModularAccountV2<
|
|
54
|
+
TTransport extends Transport = Transport,
|
|
55
|
+
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
56
|
+
>(
|
|
57
|
+
config: CreateModularAccountV2Params<TTransport, TSigner>
|
|
58
|
+
): Promise<ModularAccountV2<TSigner>>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Creates a ModularAccount V2 account, with the mode depending on the provided "mode" field.
|
|
62
|
+
* Possible modes include: "default", which is SMA Bytecode, and "7702", which is SMA 7702.
|
|
63
|
+
* Handles nonce generation, transaction encoding, and mode variant-specific behavior like initcode construction.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts twoslash
|
|
67
|
+
* import { createModularAccountV2 } from "@account-kit/smart-contracts";
|
|
68
|
+
* import { LocalAccountSigner } from "@aa-sdk/core";
|
|
69
|
+
* import { alchemy, sepolia } from "@account-kit/infra";
|
|
70
|
+
*
|
|
71
|
+
* const MNEMONIC = "...";
|
|
72
|
+
* const RPC_URL = "...";
|
|
73
|
+
*
|
|
74
|
+
* const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);
|
|
75
|
+
*
|
|
76
|
+
* const chain = sepolia;
|
|
77
|
+
*
|
|
78
|
+
* const transport = alchemy({ rpcUrl: RPC_URL });
|
|
79
|
+
*
|
|
80
|
+
*
|
|
81
|
+
* const modularAccountV2 = await createModularAccountV2({
|
|
82
|
+
* mode: "default", // or "7702"
|
|
83
|
+
* chain,
|
|
84
|
+
* signer,
|
|
85
|
+
* transport,
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @param {CreateModularAccountV2Params} config Configuration parameters for creating a Modular Account V2.
|
|
90
|
+
* @returns {Promise<ModularAccountV2>} A promise that resolves to an `ModularAccountV2` providing methods for nonce retrieval, transaction execution, and more.
|
|
91
|
+
*/
|
|
92
|
+
export async function createModularAccountV2(
|
|
93
|
+
config: CreateModularAccountV2Params
|
|
94
|
+
): Promise<ModularAccountV2> {
|
|
95
|
+
const {
|
|
96
|
+
transport,
|
|
97
|
+
chain,
|
|
98
|
+
signer,
|
|
99
|
+
accountAddress: _accountAddress,
|
|
100
|
+
entryPoint = getEntryPoint(chain, { version: "0.7.0" }),
|
|
101
|
+
signerEntity = {
|
|
102
|
+
isGlobalValidation: true,
|
|
103
|
+
entityId: DEFAULT_OWNER_ENTITY_ID,
|
|
104
|
+
},
|
|
105
|
+
signerEntity: { entityId = DEFAULT_OWNER_ENTITY_ID } = {},
|
|
106
|
+
} = config;
|
|
107
|
+
|
|
108
|
+
const client = createBundlerClient({
|
|
109
|
+
transport,
|
|
110
|
+
chain,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const accountFunctions = await (async () => {
|
|
114
|
+
switch (config.mode) {
|
|
115
|
+
case "7702": {
|
|
116
|
+
const getAccountInitCode = async (): Promise<Hex> => {
|
|
117
|
+
return "0x";
|
|
118
|
+
};
|
|
119
|
+
const signerAddress = await signer.getAddress();
|
|
120
|
+
const accountAddress = _accountAddress ?? signerAddress;
|
|
121
|
+
if (
|
|
122
|
+
entityId === DEFAULT_OWNER_ENTITY_ID &&
|
|
123
|
+
signerAddress !== accountAddress
|
|
124
|
+
) {
|
|
125
|
+
throw new EntityIdOverrideError();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const implementation: Address =
|
|
129
|
+
"0x69007702764179f14F51cdce752f4f775d74E139";
|
|
130
|
+
|
|
131
|
+
const getImplementationAddress = async () => implementation;
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
getAccountInitCode,
|
|
135
|
+
accountAddress,
|
|
136
|
+
getImplementationAddress,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
case "default":
|
|
140
|
+
case undefined: {
|
|
141
|
+
const {
|
|
142
|
+
salt = 0n,
|
|
143
|
+
factoryAddress = getDefaultMAV2FactoryAddress(chain),
|
|
144
|
+
initCode,
|
|
145
|
+
} = config;
|
|
146
|
+
|
|
147
|
+
const getAccountInitCode = async () => {
|
|
148
|
+
if (initCode) {
|
|
149
|
+
return initCode;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return concatHex([
|
|
153
|
+
factoryAddress,
|
|
154
|
+
encodeFunctionData({
|
|
155
|
+
abi: accountFactoryAbi,
|
|
156
|
+
functionName: "createSemiModularAccount",
|
|
157
|
+
args: [await signer.getAddress(), salt],
|
|
158
|
+
}),
|
|
159
|
+
]);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const accountAddress = await getAccountAddress({
|
|
163
|
+
client,
|
|
164
|
+
entryPoint,
|
|
165
|
+
accountAddress: _accountAddress,
|
|
166
|
+
getAccountInitCode,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
getAccountInitCode,
|
|
171
|
+
accountAddress,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
default:
|
|
175
|
+
assertNever(config);
|
|
176
|
+
}
|
|
177
|
+
})();
|
|
178
|
+
|
|
179
|
+
return createMAv2Base({
|
|
180
|
+
source: "ModularAccountV2",
|
|
181
|
+
transport,
|
|
182
|
+
chain,
|
|
183
|
+
signer,
|
|
184
|
+
entryPoint,
|
|
185
|
+
signerEntity,
|
|
186
|
+
...accountFunctions,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// If we add more valid modes, the switch case branch's mode will no longer be `never`, which will cause a compile time error here and ensure we handle the new type.
|
|
191
|
+
function assertNever(_valid: never): never {
|
|
192
|
+
throw new InvalidModularAccountV2Mode();
|
|
193
|
+
}
|
|
@@ -24,8 +24,8 @@ import {
|
|
|
24
24
|
serializeModuleEntity,
|
|
25
25
|
} from "../common/utils.js";
|
|
26
26
|
|
|
27
|
-
import { type
|
|
28
|
-
import { type
|
|
27
|
+
import { type ModularAccountV2Client } from "../../client/client.js";
|
|
28
|
+
import { type ModularAccountV2 } from "../../account/common/modularAccountV2Base.js";
|
|
29
29
|
import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js";
|
|
30
30
|
|
|
31
31
|
export type InstallValidationParams<
|
|
@@ -38,9 +38,9 @@ export type InstallValidationParams<
|
|
|
38
38
|
hookConfig: HookConfig;
|
|
39
39
|
initData: Hex;
|
|
40
40
|
}[];
|
|
41
|
-
account?:
|
|
41
|
+
account?: ModularAccountV2<TSigner> | undefined;
|
|
42
42
|
} & UserOperationOverridesParameter<
|
|
43
|
-
GetEntryPointFromAccount<
|
|
43
|
+
GetEntryPointFromAccount<ModularAccountV2<TSigner>>
|
|
44
44
|
>;
|
|
45
45
|
|
|
46
46
|
export type UninstallValidationParams<
|
|
@@ -50,9 +50,9 @@ export type UninstallValidationParams<
|
|
|
50
50
|
entityId: number;
|
|
51
51
|
uninstallData: Hex;
|
|
52
52
|
hookUninstallDatas: Hex[];
|
|
53
|
-
account?:
|
|
53
|
+
account?: ModularAccountV2<TSigner> | undefined;
|
|
54
54
|
} & UserOperationOverridesParameter<
|
|
55
|
-
GetEntryPointFromAccount<
|
|
55
|
+
GetEntryPointFromAccount<ModularAccountV2<TSigner>>
|
|
56
56
|
>;
|
|
57
57
|
|
|
58
58
|
export type InstallValidationActions<
|
|
@@ -61,9 +61,16 @@ export type InstallValidationActions<
|
|
|
61
61
|
installValidation: (
|
|
62
62
|
args: InstallValidationParams<TSigner>
|
|
63
63
|
) => Promise<SendUserOperationResult>;
|
|
64
|
+
encodeInstallValidation: (
|
|
65
|
+
// TODO: omit the user op sending related parameters from this type
|
|
66
|
+
args: InstallValidationParams<TSigner>
|
|
67
|
+
) => Promise<Hex>;
|
|
64
68
|
uninstallValidation: (
|
|
65
69
|
args: UninstallValidationParams<TSigner>
|
|
66
70
|
) => Promise<SendUserOperationResult>;
|
|
71
|
+
encodeUninstallValidation: (
|
|
72
|
+
args: UninstallValidationParams<TSigner>
|
|
73
|
+
) => Promise<Hex>;
|
|
67
74
|
};
|
|
68
75
|
|
|
69
76
|
/**
|
|
@@ -71,10 +78,10 @@ export type InstallValidationActions<
|
|
|
71
78
|
*
|
|
72
79
|
* @example
|
|
73
80
|
* ```ts
|
|
74
|
-
* import {
|
|
81
|
+
* import { createModularAccountV2Client, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from "@account-kit/smart-contracts";
|
|
75
82
|
* import { Address } from "viem";
|
|
76
83
|
*
|
|
77
|
-
* const client = (await
|
|
84
|
+
* const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);
|
|
78
85
|
* const sessionKeyAddress: Address = "0x1234";
|
|
79
86
|
* const sessionKeyEntityId: number = 1;
|
|
80
87
|
*
|
|
@@ -113,16 +120,15 @@ export type InstallValidationActions<
|
|
|
113
120
|
export const installValidationActions: <
|
|
114
121
|
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
115
122
|
>(
|
|
116
|
-
client:
|
|
117
|
-
) => InstallValidationActions<TSigner> = (client) =>
|
|
118
|
-
|
|
123
|
+
client: ModularAccountV2Client<TSigner>
|
|
124
|
+
) => InstallValidationActions<TSigner> = (client) => {
|
|
125
|
+
const encodeInstallValidation = async ({
|
|
119
126
|
validationConfig,
|
|
120
127
|
selectors,
|
|
121
128
|
installData,
|
|
122
129
|
hooks,
|
|
123
130
|
account = client.account,
|
|
124
|
-
|
|
125
|
-
}) => {
|
|
131
|
+
}: InstallValidationParams) => {
|
|
126
132
|
if (!account) {
|
|
127
133
|
throw new AccountNotFoundError();
|
|
128
134
|
}
|
|
@@ -143,9 +149,7 @@ export const installValidationActions: <
|
|
|
143
149
|
throw new EntityIdOverrideError();
|
|
144
150
|
}
|
|
145
151
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const callData = await encodeCallData(
|
|
152
|
+
return account.encodeCallData(
|
|
149
153
|
encodeFunctionData({
|
|
150
154
|
abi: semiModularAccountBytecodeAbi,
|
|
151
155
|
functionName: "installValidation",
|
|
@@ -159,22 +163,15 @@ export const installValidationActions: <
|
|
|
159
163
|
],
|
|
160
164
|
})
|
|
161
165
|
);
|
|
166
|
+
};
|
|
162
167
|
|
|
163
|
-
|
|
164
|
-
uo: callData,
|
|
165
|
-
account,
|
|
166
|
-
overrides,
|
|
167
|
-
});
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
uninstallValidation: async ({
|
|
168
|
+
const encodeUninstallValidation = async ({
|
|
171
169
|
moduleAddress,
|
|
172
170
|
entityId,
|
|
173
171
|
uninstallData,
|
|
174
172
|
hookUninstallDatas,
|
|
175
173
|
account = client.account,
|
|
176
|
-
|
|
177
|
-
}) => {
|
|
174
|
+
}: UninstallValidationParams) => {
|
|
178
175
|
if (!account) {
|
|
179
176
|
throw new AccountNotFoundError();
|
|
180
177
|
}
|
|
@@ -187,9 +184,7 @@ export const installValidationActions: <
|
|
|
187
184
|
);
|
|
188
185
|
}
|
|
189
186
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const callData = await encodeCallData(
|
|
187
|
+
return account.encodeCallData(
|
|
193
188
|
encodeFunctionData({
|
|
194
189
|
abi: semiModularAccountBytecodeAbi,
|
|
195
190
|
functionName: "uninstallValidation",
|
|
@@ -203,11 +198,55 @@ export const installValidationActions: <
|
|
|
203
198
|
],
|
|
204
199
|
})
|
|
205
200
|
);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
encodeInstallValidation,
|
|
205
|
+
encodeUninstallValidation,
|
|
206
|
+
installValidation: async ({
|
|
207
|
+
validationConfig,
|
|
208
|
+
selectors,
|
|
209
|
+
installData,
|
|
210
|
+
hooks,
|
|
211
|
+
account = client.account,
|
|
210
212
|
overrides,
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
|
|
213
|
+
}) => {
|
|
214
|
+
const callData = await encodeInstallValidation({
|
|
215
|
+
validationConfig,
|
|
216
|
+
selectors,
|
|
217
|
+
installData,
|
|
218
|
+
hooks,
|
|
219
|
+
account,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
return client.sendUserOperation({
|
|
223
|
+
uo: callData,
|
|
224
|
+
account,
|
|
225
|
+
overrides,
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
uninstallValidation: async ({
|
|
230
|
+
moduleAddress,
|
|
231
|
+
entityId,
|
|
232
|
+
uninstallData,
|
|
233
|
+
hookUninstallDatas,
|
|
234
|
+
account = client.account,
|
|
235
|
+
overrides,
|
|
236
|
+
}) => {
|
|
237
|
+
const callData = await encodeUninstallValidation({
|
|
238
|
+
moduleAddress,
|
|
239
|
+
entityId,
|
|
240
|
+
uninstallData,
|
|
241
|
+
hookUninstallDatas,
|
|
242
|
+
account,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
return client.sendUserOperation({
|
|
246
|
+
uo: callData,
|
|
247
|
+
account,
|
|
248
|
+
overrides,
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
};
|
|
@@ -4,42 +4,49 @@ import {
|
|
|
4
4
|
type SmartAccountClientConfig,
|
|
5
5
|
type NotType,
|
|
6
6
|
createSmartAccountClient,
|
|
7
|
+
default7702GasEstimator,
|
|
8
|
+
default7702UserOpSigner,
|
|
7
9
|
} from "@aa-sdk/core";
|
|
8
10
|
import { type Chain, type Transport } from "viem";
|
|
9
11
|
|
|
10
12
|
import {
|
|
11
|
-
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
createModularAccountV2,
|
|
14
|
+
type CreateModularAccountV2Params,
|
|
15
|
+
} from "../account/modularAccountV2.js";
|
|
16
|
+
|
|
15
17
|
import {
|
|
16
18
|
createAlchemySmartAccountClient,
|
|
17
19
|
isAlchemyTransport,
|
|
20
|
+
type AlchemySmartAccountClient,
|
|
18
21
|
type AlchemySmartAccountClientConfig,
|
|
19
22
|
type AlchemyTransport,
|
|
20
23
|
} from "@account-kit/infra";
|
|
21
24
|
import type { LightAccount } from "../../light-account/accounts/account.js";
|
|
22
|
-
|
|
25
|
+
|
|
26
|
+
import type { ModularAccountV2 } from "../account/common/modularAccountV2Base.js";
|
|
27
|
+
|
|
28
|
+
export type ModularAccountV2Client<
|
|
23
29
|
TSigner extends SmartAccountSigner = SmartAccountSigner,
|
|
24
30
|
TChain extends Chain = Chain,
|
|
25
31
|
TTransport extends Transport | AlchemyTransport = Transport
|
|
26
|
-
> = SmartAccountClient<TTransport, TChain,
|
|
32
|
+
> = SmartAccountClient<TTransport, TChain, ModularAccountV2<TSigner>>;
|
|
27
33
|
|
|
28
|
-
export type
|
|
34
|
+
export type CreateModularAccountV2ClientParams<
|
|
29
35
|
TTransport extends Transport = Transport,
|
|
30
36
|
TChain extends Chain = Chain,
|
|
31
37
|
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
32
|
-
> =
|
|
38
|
+
> = CreateModularAccountV2Params<TTransport, TSigner> &
|
|
33
39
|
Omit<
|
|
34
40
|
SmartAccountClientConfig<TTransport, TChain>,
|
|
35
41
|
"transport" | "account" | "chain"
|
|
36
42
|
>;
|
|
37
|
-
|
|
43
|
+
|
|
44
|
+
export type CreateModularAccountV2AlchemyClientParams<
|
|
38
45
|
TTransport extends Transport = Transport,
|
|
39
46
|
TChain extends Chain = Chain,
|
|
40
47
|
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
41
48
|
> = Omit<
|
|
42
|
-
|
|
49
|
+
CreateModularAccountV2ClientParams<TTransport, TChain, TSigner>,
|
|
43
50
|
"transport"
|
|
44
51
|
> &
|
|
45
52
|
Omit<
|
|
@@ -47,31 +54,34 @@ export type CreateSMAV2AlchemyAccountClientParams<
|
|
|
47
54
|
"account"
|
|
48
55
|
> & { paymasterAndData?: never; dummyPaymasterAndData?: never };
|
|
49
56
|
|
|
50
|
-
export function
|
|
57
|
+
export function createModularAccountV2Client<
|
|
51
58
|
TChain extends Chain = Chain,
|
|
52
59
|
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
53
60
|
>(
|
|
54
|
-
args:
|
|
55
|
-
|
|
61
|
+
args: CreateModularAccountV2AlchemyClientParams<
|
|
62
|
+
AlchemyTransport,
|
|
63
|
+
TChain,
|
|
64
|
+
TSigner
|
|
65
|
+
>
|
|
66
|
+
): Promise<ModularAccountV2Client<TSigner, TChain, AlchemyTransport>>;
|
|
56
67
|
|
|
57
|
-
export function
|
|
68
|
+
export function createModularAccountV2Client<
|
|
58
69
|
TTransport extends Transport = Transport,
|
|
59
70
|
TChain extends Chain = Chain,
|
|
60
71
|
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
61
72
|
>(
|
|
62
|
-
args:
|
|
73
|
+
args: CreateModularAccountV2ClientParams<TTransport, TChain, TSigner> &
|
|
63
74
|
NotType<TTransport, AlchemyTransport>
|
|
64
|
-
): Promise<
|
|
75
|
+
): Promise<ModularAccountV2Client<TSigner, TChain>>;
|
|
65
76
|
|
|
66
77
|
/**
|
|
67
|
-
* Creates a
|
|
78
|
+
* Creates a Modular Account V2 client using the provided configuration parameters.
|
|
68
79
|
*
|
|
69
80
|
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* import {
|
|
72
|
-
* import { createSMAV2AccountClient } from "@account-kit/smart-contracts";
|
|
81
|
+
* ```ts twoslash
|
|
82
|
+
* import { createModularAccountV2Client } from "@account-kit/smart-contracts";
|
|
73
83
|
* import { LocalAccountSigner } from "@aa-sdk/core";
|
|
74
|
-
* import { sepolia } from "@account-kit/infra";
|
|
84
|
+
* import { alchemy, sepolia } from "@account-kit/infra";
|
|
75
85
|
*
|
|
76
86
|
* const MNEMONIC = "...";
|
|
77
87
|
* const RPC_URL = "...";
|
|
@@ -80,11 +90,11 @@ export function createSMAV2AccountClient<
|
|
|
80
90
|
*
|
|
81
91
|
* const chain = sepolia;
|
|
82
92
|
*
|
|
83
|
-
* const transport =
|
|
93
|
+
* const transport = alchemy({ rpcUrl: RPC_URL });
|
|
84
94
|
*
|
|
85
95
|
* const policyId = "...";
|
|
86
96
|
*
|
|
87
|
-
* const
|
|
97
|
+
* const modularAccountV2Client = await createModularAccountV2Client({
|
|
88
98
|
* chain,
|
|
89
99
|
* signer,
|
|
90
100
|
* transport,
|
|
@@ -92,29 +102,39 @@ export function createSMAV2AccountClient<
|
|
|
92
102
|
* });
|
|
93
103
|
* ```
|
|
94
104
|
*
|
|
95
|
-
* @param {
|
|
105
|
+
* @param {CreateModularAccountV2ClientParams} config The configuration parameters required to create the Modular Account v2 account client
|
|
96
106
|
* @returns {Promise<SmartAccountClient>} A promise that resolves to a `SmartAccountClient` instance
|
|
97
107
|
*/
|
|
98
|
-
export async function
|
|
99
|
-
config:
|
|
100
|
-
|
|
108
|
+
export async function createModularAccountV2Client(
|
|
109
|
+
config:
|
|
110
|
+
| CreateModularAccountV2ClientParams
|
|
111
|
+
| CreateModularAccountV2AlchemyClientParams
|
|
112
|
+
): Promise<SmartAccountClient | AlchemySmartAccountClient> {
|
|
101
113
|
const { transport, chain } = config;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
|
|
115
|
+
const account = await createModularAccountV2(config);
|
|
116
|
+
|
|
117
|
+
const middlewareToAppend =
|
|
118
|
+
config.mode === "7702"
|
|
119
|
+
? {
|
|
120
|
+
gasEstimator: default7702GasEstimator(config.gasEstimator),
|
|
121
|
+
signUserOperation: default7702UserOpSigner(config.signUserOperation),
|
|
122
|
+
}
|
|
123
|
+
: {};
|
|
124
|
+
|
|
107
125
|
if (isAlchemyTransport(transport, chain)) {
|
|
108
126
|
return createAlchemySmartAccountClient({
|
|
109
127
|
...config,
|
|
110
128
|
transport,
|
|
111
129
|
chain,
|
|
112
|
-
account
|
|
130
|
+
account,
|
|
131
|
+
...middlewareToAppend,
|
|
113
132
|
});
|
|
114
133
|
}
|
|
115
134
|
|
|
116
135
|
return createSmartAccountClient({
|
|
117
136
|
...config,
|
|
118
|
-
account
|
|
137
|
+
account,
|
|
138
|
+
...middlewareToAppend,
|
|
119
139
|
});
|
|
120
140
|
}
|
package/src/ma-v2/index.ts
CHANGED
|
@@ -5,8 +5,6 @@ export { semiModularAccountBytecodeAbi } from "./abis/semiModularAccountBytecode
|
|
|
5
5
|
export { semiModularAccountStorageAbi } from "./abis/semiModularAccountStorageAbi.js";
|
|
6
6
|
|
|
7
7
|
export { nativeSMASigner } from "./account/nativeSMASigner.js";
|
|
8
|
-
export type * from "./account/semiModularAccountV2.js";
|
|
9
|
-
export { createSMAV2Account } from "./account/semiModularAccountV2.js";
|
|
10
8
|
|
|
11
9
|
export type {
|
|
12
10
|
ModuleEntity,
|
|
@@ -23,9 +21,6 @@ export {
|
|
|
23
21
|
export type * from "./actions/install-validation/installValidation.js";
|
|
24
22
|
export { installValidationActions } from "./actions/install-validation/installValidation.js";
|
|
25
23
|
|
|
26
|
-
export type * from "./client/client.js";
|
|
27
|
-
export { createSMAV2AccountClient } from "./client/client.js";
|
|
28
|
-
|
|
29
24
|
export {
|
|
30
25
|
getDefaultAllowlistModuleAddress,
|
|
31
26
|
getDefaultNativeTokenLimitModuleAddress,
|
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
import { encodeAbiParameters, type Address, type Hex } from "viem";
|
|
2
2
|
import { allowlistModuleAbi } from "./abis/allowlistModuleAbi.js";
|
|
3
|
+
import { HookType, type HookConfig } from "../../actions/common/types.js";
|
|
3
4
|
|
|
4
5
|
export const AllowlistModule = {
|
|
5
6
|
abi: allowlistModuleAbi,
|
|
7
|
+
buildHook: (
|
|
8
|
+
installArgs: {
|
|
9
|
+
entityId: number;
|
|
10
|
+
inputs: Array<{
|
|
11
|
+
target: Address;
|
|
12
|
+
hasSelectorAllowlist: boolean;
|
|
13
|
+
hasERC20SpendLimit: boolean;
|
|
14
|
+
erc20SpendLimit: bigint;
|
|
15
|
+
selectors: Array<Hex>;
|
|
16
|
+
}>;
|
|
17
|
+
},
|
|
18
|
+
address: Address
|
|
19
|
+
): {
|
|
20
|
+
hookConfig: HookConfig;
|
|
21
|
+
initData: Hex;
|
|
22
|
+
} => {
|
|
23
|
+
const installData = AllowlistModule.encodeOnInstallData(installArgs);
|
|
24
|
+
return {
|
|
25
|
+
hookConfig: {
|
|
26
|
+
address: address,
|
|
27
|
+
entityId: installArgs.entityId,
|
|
28
|
+
hookType: HookType.VALIDATION,
|
|
29
|
+
hasPreHooks: true,
|
|
30
|
+
hasPostHooks: false,
|
|
31
|
+
},
|
|
32
|
+
initData: installData,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
6
35
|
encodeOnInstallData: (args: {
|
|
7
36
|
entityId: number;
|
|
8
37
|
inputs: Array<{
|
|
@@ -24,7 +24,7 @@ import { packUOSignature, pack1271Signature } from "../../utils.js";
|
|
|
24
24
|
*
|
|
25
25
|
* const MNEMONIC = "...":
|
|
26
26
|
*
|
|
27
|
-
* const account =
|
|
27
|
+
* const account = createModularAccountV2({ config });
|
|
28
28
|
*
|
|
29
29
|
* const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);
|
|
30
30
|
*
|
|
@@ -1,9 +1,42 @@
|
|
|
1
|
-
import { encodeAbiParameters, type Hex } from "viem";
|
|
1
|
+
import { encodeAbiParameters, type Address, type Hex } from "viem";
|
|
2
2
|
|
|
3
3
|
import { timeRangeModuleAbi } from "./abis/timeRangeModuleAbi.js";
|
|
4
|
+
import { HookType, type HookConfig } from "../../actions/common/types.js";
|
|
4
5
|
|
|
5
6
|
export const TimeRangeModule = {
|
|
6
7
|
abi: timeRangeModuleAbi,
|
|
8
|
+
buildHook: (
|
|
9
|
+
installArgs: {
|
|
10
|
+
entityId: number;
|
|
11
|
+
validUntil: number;
|
|
12
|
+
validAfter: number;
|
|
13
|
+
},
|
|
14
|
+
address: Address
|
|
15
|
+
): { hookConfig: HookConfig; initData: Hex } => {
|
|
16
|
+
if (installArgs.validUntil > 2 ** 48 - 1) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"TimeRangeModule.buildHook: validUntil > type(uint48).max"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (installArgs.validAfter > 2 ** 48 - 1) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"TimeRangeModule.buildHook: validAfter > type(uint48).max"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const installData = TimeRangeModule.encodeOnInstallData(installArgs);
|
|
29
|
+
return {
|
|
30
|
+
hookConfig: {
|
|
31
|
+
address: address,
|
|
32
|
+
entityId: installArgs.entityId,
|
|
33
|
+
hookType: HookType.VALIDATION,
|
|
34
|
+
hasPreHooks: false,
|
|
35
|
+
hasPostHooks: false,
|
|
36
|
+
},
|
|
37
|
+
initData: installData,
|
|
38
|
+
};
|
|
39
|
+
},
|
|
7
40
|
encodeOnInstallData: (args: {
|
|
8
41
|
entityId: number;
|
|
9
42
|
validUntil: number;
|