@account-kit/smart-contracts 4.12.0 → 4.13.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.
Files changed (51) hide show
  1. package/dist/esm/src/index.d.ts +5 -0
  2. package/dist/esm/src/index.js +2 -0
  3. package/dist/esm/src/index.js.map +1 -1
  4. package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.d.ts +39 -0
  5. package/dist/esm/src/ma-v2/account/{semiModularAccountV2.js → common/modularAccountV2Base.js} +32 -61
  6. package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js.map +1 -0
  7. package/dist/esm/src/ma-v2/account/modularAccountV2.d.ts +16 -0
  8. package/dist/esm/src/ma-v2/account/modularAccountV2.js +113 -0
  9. package/dist/esm/src/ma-v2/account/modularAccountV2.js.map +1 -0
  10. package/dist/esm/src/ma-v2/account/nativeSMASigner.d.ts +1 -1
  11. package/dist/esm/src/ma-v2/account/nativeSMASigner.js +1 -1
  12. package/dist/esm/src/ma-v2/account/nativeSMASigner.js.map +1 -1
  13. package/dist/esm/src/ma-v2/actions/install-validation/installValidation.d.ts +11 -9
  14. package/dist/esm/src/ma-v2/actions/install-validation/installValidation.js +43 -23
  15. package/dist/esm/src/ma-v2/actions/install-validation/installValidation.js.map +1 -1
  16. package/dist/esm/src/ma-v2/client/client.d.ts +7 -6
  17. package/dist/esm/src/ma-v2/client/client.js +21 -18
  18. package/dist/esm/src/ma-v2/client/client.js.map +1 -1
  19. package/dist/esm/src/ma-v2/index.d.ts +0 -4
  20. package/dist/esm/src/ma-v2/index.js +0 -2
  21. package/dist/esm/src/ma-v2/index.js.map +1 -1
  22. package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.d.ts +1 -1
  23. package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js +1 -1
  24. package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js.map +1 -1
  25. package/dist/types/src/index.d.ts +5 -0
  26. package/dist/types/src/index.d.ts.map +1 -1
  27. package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts +40 -0
  28. package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts.map +1 -0
  29. package/dist/types/src/ma-v2/account/modularAccountV2.d.ts +17 -0
  30. package/dist/types/src/ma-v2/account/modularAccountV2.d.ts.map +1 -0
  31. package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts +1 -1
  32. package/dist/types/src/ma-v2/actions/install-validation/installValidation.d.ts +11 -9
  33. package/dist/types/src/ma-v2/actions/install-validation/installValidation.d.ts.map +1 -1
  34. package/dist/types/src/ma-v2/client/client.d.ts +7 -6
  35. package/dist/types/src/ma-v2/client/client.d.ts.map +1 -1
  36. package/dist/types/src/ma-v2/index.d.ts +0 -4
  37. package/dist/types/src/ma-v2/index.d.ts.map +1 -1
  38. package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts +1 -1
  39. package/package.json +6 -6
  40. package/src/index.ts +7 -0
  41. package/src/ma-v2/account/{semiModularAccountV2.ts → common/modularAccountV2Base.ts} +62 -105
  42. package/src/ma-v2/account/modularAccountV2.ts +193 -0
  43. package/src/ma-v2/account/nativeSMASigner.ts +1 -1
  44. package/src/ma-v2/actions/install-validation/installValidation.ts +75 -36
  45. package/src/ma-v2/client/client.ts +54 -34
  46. package/src/ma-v2/index.ts +0 -5
  47. package/src/ma-v2/modules/single-signer-validation/signer.ts +1 -1
  48. package/dist/esm/src/ma-v2/account/semiModularAccountV2.d.ts +0 -41
  49. package/dist/esm/src/ma-v2/account/semiModularAccountV2.js.map +0 -1
  50. package/dist/types/src/ma-v2/account/semiModularAccountV2.d.ts +0 -42
  51. package/dist/types/src/ma-v2/account/semiModularAccountV2.d.ts.map +0 -1
@@ -24,8 +24,8 @@ import {
24
24
  serializeModuleEntity,
25
25
  } from "../common/utils.js";
26
26
 
27
- import { type SMAV2AccountClient } from "../../client/client.js";
28
- import { type MAV2Account } from "../../account/semiModularAccountV2.js";
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?: MAV2Account<TSigner> | undefined;
41
+ account?: ModularAccountV2<TSigner> | undefined;
42
42
  } & UserOperationOverridesParameter<
43
- GetEntryPointFromAccount<MAV2Account<TSigner>>
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?: MAV2Account<TSigner> | undefined;
53
+ account?: ModularAccountV2<TSigner> | undefined;
54
54
  } & UserOperationOverridesParameter<
55
- GetEntryPointFromAccount<MAV2Account<TSigner>>
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 { createSMAV2AccountClient, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from "@account-kit/smart-contracts";
81
+ * import { createModularAccountV2Client, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from "@account-kit/smart-contracts";
75
82
  * import { Address } from "viem";
76
83
  *
77
- * const client = (await createSMAV2AccountClient({ ... })).extend(installValidationActions);
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: SMAV2AccountClient<TSigner>
117
- ) => InstallValidationActions<TSigner> = (client) => ({
118
- installValidation: async ({
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
- overrides,
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
- const { encodeCallData } = account;
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
- return client.sendUserOperation({
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
- overrides,
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
- const { encodeCallData } = account;
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
- return client.sendUserOperation({
208
- uo: callData,
209
- account,
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
- createSMAV2Account,
12
- type CreateSMAV2AccountParams,
13
- type MAV2Account,
14
- } from "../account/semiModularAccountV2.js";
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
- export type SMAV2AccountClient<
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, MAV2Account<TSigner>>;
32
+ > = SmartAccountClient<TTransport, TChain, ModularAccountV2<TSigner>>;
27
33
 
28
- export type CreateSMAV2AccountClientParams<
34
+ export type CreateModularAccountV2ClientParams<
29
35
  TTransport extends Transport = Transport,
30
36
  TChain extends Chain = Chain,
31
37
  TSigner extends SmartAccountSigner = SmartAccountSigner
32
- > = CreateSMAV2AccountParams<TTransport, TSigner> &
38
+ > = CreateModularAccountV2Params<TTransport, TSigner> &
33
39
  Omit<
34
40
  SmartAccountClientConfig<TTransport, TChain>,
35
41
  "transport" | "account" | "chain"
36
42
  >;
37
- export type CreateSMAV2AlchemyAccountClientParams<
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
- CreateSMAV2AccountClientParams<TTransport, TChain, TSigner>,
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 createSMAV2AccountClient<
57
+ export function createModularAccountV2Client<
51
58
  TChain extends Chain = Chain,
52
59
  TSigner extends SmartAccountSigner = SmartAccountSigner
53
60
  >(
54
- args: CreateSMAV2AlchemyAccountClientParams<AlchemyTransport, TChain, TSigner>
55
- ): Promise<SMAV2AccountClient<TSigner, TChain, AlchemyTransport>>;
61
+ args: CreateModularAccountV2AlchemyClientParams<
62
+ AlchemyTransport,
63
+ TChain,
64
+ TSigner
65
+ >
66
+ ): Promise<ModularAccountV2Client<TSigner, TChain, AlchemyTransport>>;
56
67
 
57
- export function createSMAV2AccountClient<
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: CreateSMAV2AccountClientParams<TTransport, TChain, TSigner> &
73
+ args: CreateModularAccountV2ClientParams<TTransport, TChain, TSigner> &
63
74
  NotType<TTransport, AlchemyTransport>
64
- ): Promise<SMAV2AccountClient<TSigner, TChain>>;
75
+ ): Promise<ModularAccountV2Client<TSigner, TChain>>;
65
76
 
66
77
  /**
67
- * Creates a SMAv2 account client using the provided configuration parameters.
78
+ * Creates a Modular Account V2 client using the provided configuration parameters.
68
79
  *
69
80
  * @example
70
- * ```ts
71
- * import { http } from "viem";
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 = http(RPC_URL);
93
+ * const transport = alchemy({ rpcUrl: RPC_URL });
84
94
  *
85
95
  * const policyId = "...";
86
96
  *
87
- * const SMAV2SignerAccountClient = await createSMAV2AccountClient({
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 {CreateSMAV2AccountClientParams} config The configuration parameters required to create the MAv2 account client
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 createSMAV2AccountClient(
99
- config: CreateSMAV2AccountClientParams
100
- ): Promise<SmartAccountClient> {
108
+ export async function createModularAccountV2Client(
109
+ config:
110
+ | CreateModularAccountV2ClientParams
111
+ | CreateModularAccountV2AlchemyClientParams
112
+ ): Promise<SmartAccountClient | AlchemySmartAccountClient> {
101
113
  const { transport, chain } = config;
102
- const smaV2Account = await createSMAV2Account({
103
- ...config,
104
- transport,
105
- chain,
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: smaV2Account,
130
+ account,
131
+ ...middlewareToAppend,
113
132
  });
114
133
  }
115
134
 
116
135
  return createSmartAccountClient({
117
136
  ...config,
118
- account: smaV2Account,
137
+ account,
138
+ ...middlewareToAppend,
119
139
  });
120
140
  }
@@ -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,
@@ -24,7 +24,7 @@ import { packUOSignature, pack1271Signature } from "../../utils.js";
24
24
  *
25
25
  * const MNEMONIC = "...":
26
26
  *
27
- * const account = createSMAV2Account({ config });
27
+ * const account = createModularAccountV2({ config });
28
28
  *
29
29
  * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);
30
30
  *
@@ -1,41 +0,0 @@
1
- import type { EntryPointDef, SmartAccountSigner, SmartContractAccountWithSigner, ToSmartContractAccountParams } from "@aa-sdk/core";
2
- import { type Address, type Chain, type Hex, type Transport } from "viem";
3
- export type SignerEntity = {
4
- isGlobalValidation: boolean;
5
- entityId: number;
6
- };
7
- export type ExecutionDataView = {
8
- module: Address;
9
- skipRuntimeValidation: boolean;
10
- allowGlobalValidation: boolean;
11
- executionHooks: readonly Hex[];
12
- };
13
- export type ValidationDataView = {
14
- validationHooks: readonly Hex[];
15
- executionHooks: readonly Hex[];
16
- selectors: readonly Hex[];
17
- validationFlags: number;
18
- };
19
- export type ValidationDataParams = {
20
- validationModuleAddress: Address;
21
- entityId?: never;
22
- } | {
23
- validationModuleAddress?: never;
24
- entityId: number;
25
- };
26
- export type MAV2Account<TSigner extends SmartAccountSigner = SmartAccountSigner> = SmartContractAccountWithSigner<"MAV2Account", TSigner, "0.7.0"> & {
27
- signerEntity: SignerEntity;
28
- getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;
29
- getValidationData: (args: ValidationDataParams) => Promise<ValidationDataView>;
30
- encodeCallData: (callData: Hex) => Promise<Hex>;
31
- };
32
- export type CreateSMAV2AccountParams<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner> = Pick<ToSmartContractAccountParams<"MAV2Account", TTransport, Chain, "0.7.0">, "transport" | "chain" | "accountAddress"> & {
33
- signer: TSigner;
34
- salt?: bigint;
35
- factoryAddress?: Address;
36
- initCode?: Hex;
37
- initialOwner?: Address;
38
- entryPoint?: EntryPointDef<"0.7.0", Chain>;
39
- signerEntity?: SignerEntity;
40
- };
41
- export declare function createSMAV2Account<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner>(config: CreateSMAV2AccountParams<TTransport, TSigner>): Promise<MAV2Account<TSigner>>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"semiModularAccountV2.js","sourceRoot":"","sources":["../../../../../src/ma-v2/account/semiModularAccountV2.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,SAAS,EACT,UAAU,EACV,WAAW,GAKZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,MAAM,qBAAqB,GAAQ,YAAY,CAAC;AAiEhD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAgC;IAEhC,MAAM,EACJ,SAAS,EACT,KAAK,EACL,MAAM,EACN,IAAI,GAAG,EAAE,EACT,cAAc,GA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AAE,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC;aACxC,CAAC;SACH,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,KAAK,EAAE,QAAa,EAAgB,EAAE;QAC3D,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC;YAC7C,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;SAC3B,CAAC,CAAC;QAEH,OAAO,cAAc,CAAC,cAAc,CAAC,MAAM;YACzC,CAAC,CAAC,SAAS,CAAC,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;YAC9C,CAAC,CAAC,QAAQ,CAAC;IACf,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,WAAW;QACd,eAAe;QACf,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,YAAY;QACZ,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;KACf,CAAC;AACJ,CAAC","sourcesContent":["import type {\n EntryPointDef,\n SmartAccountSigner,\n AccountOp,\n SmartContractAccountWithSigner,\n ToSmartContractAccountParams,\n} from \"@aa-sdk/core\";\nimport {\n createBundlerClient,\n getEntryPoint,\n toSmartContractAccount,\n InvalidEntityIdError,\n InvalidNonceKeyError,\n getAccountAddress,\n} from \"@aa-sdk/core\";\nimport {\n concatHex,\n encodeFunctionData,\n getContract,\n maxUint32,\n maxUint152,\n zeroAddress,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport {\n getDefaultMAV2FactoryAddress,\n DEFAULT_OWNER_ENTITY_ID,\n} from \"../utils.js\";\nimport { singleSignerMessageSigner } from \"../modules/single-signer-validation/signer.js\";\nimport { nativeSMASigner } from \"./nativeSMASigner.js\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport { serializeModuleEntity } from \"../actions/common/utils.js\";\n\nconst executeUserOpSelector: Hex = \"0x8DD7712F\";\n\nexport type SignerEntity = {\n isGlobalValidation: boolean;\n entityId: number;\n};\n\nexport type ExecutionDataView = {\n module: Address;\n skipRuntimeValidation: boolean;\n allowGlobalValidation: boolean;\n executionHooks: readonly Hex[];\n};\n\nexport type ValidationDataView = {\n validationHooks: readonly Hex[];\n executionHooks: readonly Hex[];\n selectors: readonly Hex[];\n validationFlags: number;\n};\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type MAV2Account<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> = SmartContractAccountWithSigner<\"MAV2Account\", TSigner, \"0.7.0\"> & {\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type CreateSMAV2AccountParams<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> = Pick<\n ToSmartContractAccountParams<\"MAV2Account\", TTransport, Chain, \"0.7.0\">,\n \"transport\" | \"chain\" | \"accountAddress\"\n> & {\n signer: TSigner;\n salt?: bigint;\n factoryAddress?: Address;\n initCode?: Hex;\n initialOwner?: Address;\n entryPoint?: EntryPointDef<\"0.7.0\", Chain>;\n signerEntity?: SignerEntity;\n};\n\nexport async function createSMAV2Account<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner\n>(\n config: CreateSMAV2AccountParams<TTransport, TSigner>\n): Promise<MAV2Account<TSigner>>;\n\n/**\n * Creates an SMAV2 account using defined parameters including chain, signer, salt, factory address, and more.\n * Handles account initialization code, nonce generation, transaction encoding, and more to construct a modular account with optional validation hooks.\n *\n * @param {CreateSMAV2AccountParams} config Configuration parameters for creating an SMAV2 account. Includes chain details, signer, salt, factory address, and more.\n * @returns {Promise<MAV2Account>} A promise that resolves to an `MAV2Account` providing methods for nonce retrieval, transaction execution, and more.\n */\nexport async function createSMAV2Account(\n config: CreateSMAV2AccountParams\n): Promise<MAV2Account> {\n const {\n transport,\n chain,\n signer,\n salt = 0n,\n factoryAddress = getDefaultMAV2FactoryAddress(chain),\n initCode,\n initialOwner,\n accountAddress,\n entryPoint = getEntryPoint(chain, { version: \"0.7.0\" }),\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n signerEntity: {\n isGlobalValidation = true,\n entityId = DEFAULT_OWNER_ENTITY_ID,\n } = {},\n } = config;\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const getAccountInitCode = async () => {\n if (initCode) {\n return initCode;\n }\n\n // If an initial owner is not provided, use the signer's address\n const ownerAddress = initialOwner ?? (await signer.getAddress());\n\n return concatHex([\n factoryAddress,\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [ownerAddress, salt],\n }),\n ]);\n };\n\n const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({\n target,\n data,\n value,\n }) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [target, value ?? 0n, data],\n })\n );\n\n const encodeBatchExecute: (txs: AccountOp[]) => Promise<Hex> = async (txs) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n txs.map((tx) => ({\n target: tx.target,\n data: tx.data,\n value: tx.value ?? 0n,\n })),\n ],\n })\n );\n\n const _accountAddress = await getAccountAddress({\n client,\n entryPoint,\n accountAddress,\n getAccountInitCode,\n });\n\n const baseAccount = await toSmartContractAccount({\n transport,\n chain,\n entryPoint,\n accountAddress: _accountAddress,\n source: `MAV2Account`,\n encodeExecute,\n encodeBatchExecute,\n getAccountInitCode,\n ...(entityId === DEFAULT_OWNER_ENTITY_ID\n ? nativeSMASigner(signer, chain, _accountAddress)\n : singleSignerMessageSigner(signer, chain, _accountAddress, entityId)),\n });\n\n // TODO: add deferred action flag\n const getAccountNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client,\n });\n\n const fullNonceKey: bigint =\n (nonceKey << 40n) +\n BigInt(entityId << 8) +\n (isGlobalValidation ? 1n : 0n);\n\n return entryPointContract.read.getNonce([\n _accountAddress,\n fullNonceKey,\n ]) as Promise<bigint>;\n };\n\n const accountContract = getContract({\n address: _accountAddress,\n abi: modularAccountAbi,\n client,\n });\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await baseAccount.isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return await accountContract.read.getExecutionData([selector]);\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await baseAccount.isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n return await accountContract.read.getValidationData([\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ]);\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n\n return validationData.executionHooks.length\n ? concatHex([executeUserOpSelector, callData])\n : callData;\n };\n\n return {\n ...baseAccount,\n getAccountNonce,\n getSigner: () => signer,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n };\n}\n"]}
@@ -1,42 +0,0 @@
1
- import type { EntryPointDef, SmartAccountSigner, SmartContractAccountWithSigner, ToSmartContractAccountParams } from "@aa-sdk/core";
2
- import { type Address, type Chain, type Hex, type Transport } from "viem";
3
- export type SignerEntity = {
4
- isGlobalValidation: boolean;
5
- entityId: number;
6
- };
7
- export type ExecutionDataView = {
8
- module: Address;
9
- skipRuntimeValidation: boolean;
10
- allowGlobalValidation: boolean;
11
- executionHooks: readonly Hex[];
12
- };
13
- export type ValidationDataView = {
14
- validationHooks: readonly Hex[];
15
- executionHooks: readonly Hex[];
16
- selectors: readonly Hex[];
17
- validationFlags: number;
18
- };
19
- export type ValidationDataParams = {
20
- validationModuleAddress: Address;
21
- entityId?: never;
22
- } | {
23
- validationModuleAddress?: never;
24
- entityId: number;
25
- };
26
- export type MAV2Account<TSigner extends SmartAccountSigner = SmartAccountSigner> = SmartContractAccountWithSigner<"MAV2Account", TSigner, "0.7.0"> & {
27
- signerEntity: SignerEntity;
28
- getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;
29
- getValidationData: (args: ValidationDataParams) => Promise<ValidationDataView>;
30
- encodeCallData: (callData: Hex) => Promise<Hex>;
31
- };
32
- export type CreateSMAV2AccountParams<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner> = Pick<ToSmartContractAccountParams<"MAV2Account", TTransport, Chain, "0.7.0">, "transport" | "chain" | "accountAddress"> & {
33
- signer: TSigner;
34
- salt?: bigint;
35
- factoryAddress?: Address;
36
- initCode?: Hex;
37
- initialOwner?: Address;
38
- entryPoint?: EntryPointDef<"0.7.0", Chain>;
39
- signerEntity?: SignerEntity;
40
- };
41
- export declare function createSMAV2Account<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner>(config: CreateSMAV2AccountParams<TTransport, TSigner>): Promise<MAV2Account<TSigner>>;
42
- //# sourceMappingURL=semiModularAccountV2.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"semiModularAccountV2.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/account/semiModularAccountV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAElB,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAStB,OAAO,EAOL,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