@deserialize/multi-vm-wallet 1.2.441 → 1.3.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 (98) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/SMART_WALLET_GUIDE.md +746 -0
  3. package/SMART_WALLET_IMPLEMENTATION.md +460 -0
  4. package/dist/IChainWallet.d.ts +3 -3
  5. package/dist/IChainWallet.js +5 -0
  6. package/dist/IChainWallet.js.map +1 -1
  7. package/dist/evm/SMART_WALLET_EXAMPLES.d.ts +20 -0
  8. package/dist/evm/SMART_WALLET_EXAMPLES.js +451 -0
  9. package/dist/evm/SMART_WALLET_EXAMPLES.js.map +1 -0
  10. package/dist/evm/aa-service/index.d.ts +16 -0
  11. package/dist/evm/aa-service/index.js +69 -0
  12. package/dist/evm/aa-service/index.js.map +1 -0
  13. package/dist/evm/aa-service/lib/account-adapter.d.ts +26 -0
  14. package/dist/evm/aa-service/lib/account-adapter.js +53 -0
  15. package/dist/evm/aa-service/lib/account-adapter.js.map +1 -0
  16. package/dist/evm/aa-service/lib/kernel-account.d.ts +91 -0
  17. package/dist/evm/aa-service/lib/kernel-account.js +251 -0
  18. package/dist/evm/aa-service/lib/kernel-account.js.map +1 -0
  19. package/dist/evm/aa-service/lib/kernel-modules.d.ts +240 -0
  20. package/dist/evm/aa-service/lib/kernel-modules.js +409 -0
  21. package/dist/evm/aa-service/lib/kernel-modules.js.map +1 -0
  22. package/dist/evm/aa-service/lib/session-keys.d.ts +170 -0
  23. package/dist/evm/aa-service/lib/session-keys.js +297 -0
  24. package/dist/evm/aa-service/lib/session-keys.js.map +1 -0
  25. package/dist/evm/aa-service/lib/type.d.ts +167 -0
  26. package/dist/evm/aa-service/lib/type.js +43 -0
  27. package/dist/evm/aa-service/lib/type.js.map +1 -0
  28. package/dist/evm/aa-service/services/account-abstraction.d.ts +614 -0
  29. package/dist/evm/aa-service/services/account-abstraction.js +754 -0
  30. package/dist/evm/aa-service/services/account-abstraction.js.map +1 -0
  31. package/dist/evm/aa-service/services/bundler.d.ts +29 -0
  32. package/dist/evm/aa-service/services/bundler.js +168 -0
  33. package/dist/evm/aa-service/services/bundler.js.map +1 -0
  34. package/dist/evm/evm.d.ts +67 -3
  35. package/dist/evm/evm.js +212 -7
  36. package/dist/evm/evm.js.map +1 -1
  37. package/dist/evm/index.d.ts +1 -0
  38. package/dist/evm/index.js +3 -0
  39. package/dist/evm/index.js.map +1 -1
  40. package/dist/evm/smartWallet.d.ts +265 -0
  41. package/dist/evm/smartWallet.js +675 -0
  42. package/dist/evm/smartWallet.js.map +1 -0
  43. package/dist/evm/smartWallet.types.d.ts +10 -0
  44. package/dist/evm/smartWallet.types.js +16 -0
  45. package/dist/evm/smartWallet.types.js.map +1 -0
  46. package/dist/evm/transaction.utils.d.ts +10 -10
  47. package/dist/evm/transaction.utils.js +12 -8
  48. package/dist/evm/transaction.utils.js.map +1 -1
  49. package/dist/evm/transactionParsing.js +77 -1
  50. package/dist/evm/transactionParsing.js.map +1 -1
  51. package/dist/helpers/index.d.ts +1 -0
  52. package/dist/helpers/index.js +15 -0
  53. package/dist/helpers/index.js.map +1 -1
  54. package/dist/helpers/routeScan.d.ts +191 -0
  55. package/dist/helpers/routeScan.js +114 -0
  56. package/dist/helpers/routeScan.js.map +1 -0
  57. package/dist/index.d.ts +0 -2
  58. package/dist/index.js +0 -2
  59. package/dist/index.js.map +1 -1
  60. package/dist/svm/svm.d.ts +4 -3
  61. package/dist/svm/svm.js +29 -18
  62. package/dist/svm/svm.js.map +1 -1
  63. package/dist/svm/transactionSender.js +2 -2
  64. package/dist/svm/transactionSender.js.map +1 -1
  65. package/dist/svm/utils.d.ts +4 -3
  66. package/dist/svm/utils.js +19 -6
  67. package/dist/svm/utils.js.map +1 -1
  68. package/dist/test.js +7 -0
  69. package/dist/test.js.map +1 -1
  70. package/dist/types.d.ts +19 -2
  71. package/dist/types.js.map +1 -1
  72. package/dist/vm.js +9 -7
  73. package/dist/vm.js.map +1 -1
  74. package/package.json +2 -2
  75. package/tsconfig.json +4 -3
  76. package/utils/IChainWallet.ts +3 -3
  77. package/utils/evm/SMART_WALLET_EXAMPLES.ts.bak +591 -0
  78. package/utils/evm/aa-service/index.ts +85 -0
  79. package/utils/evm/aa-service/lib/account-adapter.ts +60 -0
  80. package/utils/evm/aa-service/lib/kernel-account.ts +367 -0
  81. package/utils/evm/aa-service/lib/kernel-modules.ts +598 -0
  82. package/utils/evm/aa-service/lib/session-keys.ts +389 -0
  83. package/utils/evm/aa-service/lib/type.ts +236 -0
  84. package/utils/evm/aa-service/services/account-abstraction.ts +1015 -0
  85. package/utils/evm/aa-service/services/bundler.ts +217 -0
  86. package/utils/evm/evm.ts +268 -11
  87. package/utils/evm/index.ts +5 -1
  88. package/utils/evm/smartWallet.ts +797 -0
  89. package/utils/evm/smartWallet.types.ts +33 -0
  90. package/utils/evm/transaction.utils.ts +12 -10
  91. package/utils/evm/transactionParsing.ts +100 -14
  92. package/utils/helpers/index.ts +1 -0
  93. package/utils/helpers/routeScan.ts +397 -0
  94. package/utils/index.ts +0 -2
  95. package/utils/svm/svm.ts +50 -9
  96. package/utils/svm/utils.ts +52 -7
  97. package/utils/test.ts +7 -0
  98. package/utils/types.ts +24 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-adapter.js","sourceRoot":"","sources":["../../../../utils/evm/aa-service/lib/account-adapter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAgBH,kDAYC;AAQD,wDAkBC;AAnDD,kEAA+D;AAG/D;;;;;;;;;GASG;AACH,SAAgB,mBAAmB,CAC/B,OAAY,EACZ,KAAY;IAEZ,OAAO;QACH,GAAG,OAAO;QACV,KAAK;QACL,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI;YAC9B,OAAO,EAAE,yCAAmB;YAC5B,OAAO,EAAE,KAAK;SACjB;KACqB,CAAC;AAC/B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CAClC,iBAAsB,EACtB,aAAoC;IAEpC,wCAAwC;IACxC,MAAM,UAAU,GAAG,iBAAiB,CAAC,UAAU,IAAI,aAAa,CAAC,UAAU,IAAI;QAC3E,OAAO,EAAE,yCAAmB;QAC5B,OAAO,EAAE,KAAK;KACjB,CAAC;IAEF,OAAO;QACH,GAAG,iBAAiB;QACpB,KAAK,EAAE,aAAa,CAAC,KAAK;QAC1B,UAAU,EAAE;YACR,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,yCAAmB;YAClD,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,KAAK;SACvC;KACqB,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Kernel Account Factory
3
+ *
4
+ * Modular factory for creating Kernel smart accounts with EIP-7702.
5
+ * Supports multiple bundlers, chains, and EntryPoint versions.
6
+ */
7
+ import { Chain, Hex, SignAuthorizationReturnType } from 'viem';
8
+ import { PrivateKeyAccount } from 'viem/accounts';
9
+ import { BundlerManager } from '../services/bundler';
10
+ import { BatchTransactionConfig, EntryPointVersion, KernelAccountConfig, KernelAccountInstance, KernelVersion, SingleTransactionConfig, Call } from './type';
11
+ export type { Call, KernelAccountInstance, EntryPointVersion, KernelVersion, KernelAccountConfig, BatchTransactionConfig, SingleTransactionConfig } from './type';
12
+ export declare function createKernel7702Account(config: KernelAccountConfig): Promise<KernelAccountInstance>;
13
+ export declare function createKernelAuthorization(config: {
14
+ owner: PrivateKeyAccount;
15
+ chain: Chain;
16
+ bundlerManager: BundlerManager;
17
+ kernelVersion?: KernelVersion;
18
+ }): Promise<SignAuthorizationReturnType | undefined>;
19
+ /**
20
+ * Send batch transaction (RECOMMENDED for smart accounts)
21
+ *
22
+ * Sends multiple calls in a single UserOperation, paying gas only once.
23
+ * This is one of the main benefits of smart accounts over EOAs.
24
+ *
25
+ * @example
26
+ * // Send ETH to 3 recipients in one transaction
27
+ * await sendBatchTransaction({
28
+ * kernelAccount: account,
29
+ * bundlerManager,
30
+ * calls: [
31
+ * { to: '0xRecipient1', value: parseEther('0.01') },
32
+ * { to: '0xRecipient2', value: parseEther('0.02') },
33
+ * { to: '0xRecipient3', value: parseEther('0.03') }
34
+ * ]
35
+ * });
36
+ */
37
+ export declare function sendBatchTransaction(config: BatchTransactionConfig): Promise<Hex>;
38
+ /**
39
+ * Send single transaction (convenience wrapper around sendBatchTransaction)
40
+ *
41
+ * For single operations, you can use this instead of sendBatchTransaction.
42
+ * Under the hood, it creates a batch with one call.
43
+ */
44
+ export declare function sendKernelTransaction(config: SingleTransactionConfig): Promise<Hex>;
45
+ export declare function waitForKernelReceipt(config: {
46
+ userOpHash: Hex;
47
+ chain: Chain;
48
+ bundlerManager: BundlerManager;
49
+ }): Promise<any>;
50
+ /**
51
+ * Configuration for sponsored batch transaction
52
+ */
53
+ export interface SponsoredBatchTransactionConfig {
54
+ ownerAuthorization: SignAuthorizationReturnType;
55
+ calls: Call[];
56
+ feePayerPrivateKey: Hex;
57
+ bundlerUrl: string;
58
+ paymasterUrl?: string;
59
+ chain: Chain;
60
+ entryPointVersion?: EntryPointVersion;
61
+ }
62
+ /**
63
+ * Send sponsored batch transaction using EIP-7702
64
+ *
65
+ * Allows a feePayer wallet to pay gas fees for another wallet's transaction.
66
+ * The transaction executes from the owner's address, but gas is paid by the feePayer.
67
+ *
68
+ * @param config - Sponsored transaction configuration
69
+ * @returns UserOperation hash and transaction hash
70
+ *
71
+ * @example
72
+ * // Owner creates authorization
73
+ * const authorization = await createKernelAuthorization({
74
+ * owner: ownerAccount,
75
+ * chain,
76
+ * bundlerManager
77
+ * });
78
+ *
79
+ * // FeePayer sends transaction
80
+ * const result = await sendSponsoredBatchTransaction({
81
+ * ownerAuthorization: authorization,
82
+ * calls: [{ to: recipient, value: parseEther('0.1') }],
83
+ * feePayerPrivateKey: sponsorPrivateKey,
84
+ * bundlerUrl,
85
+ * chain
86
+ * });
87
+ */
88
+ export declare function sendSponsoredBatchTransaction(config: SponsoredBatchTransactionConfig): Promise<{
89
+ userOpHash: Hex;
90
+ transactionHash?: string;
91
+ }>;
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ /**
3
+ * Kernel Account Factory
4
+ *
5
+ * Modular factory for creating Kernel smart accounts with EIP-7702.
6
+ * Supports multiple bundlers, chains, and EntryPoint versions.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createKernel7702Account = createKernel7702Account;
10
+ exports.createKernelAuthorization = createKernelAuthorization;
11
+ exports.sendBatchTransaction = sendBatchTransaction;
12
+ exports.sendKernelTransaction = sendKernelTransaction;
13
+ exports.waitForKernelReceipt = waitForKernelReceipt;
14
+ exports.sendSponsoredBatchTransaction = sendSponsoredBatchTransaction;
15
+ const viem_1 = require("viem");
16
+ const accounts_1 = require("viem/accounts");
17
+ const sdk_1 = require("@zerodev/sdk");
18
+ const constants_1 = require("@zerodev/sdk/constants");
19
+ const account_abstraction_1 = require("viem/account-abstraction");
20
+ const bundler_1 = require("../services/bundler");
21
+ // ============================================
22
+ // EntryPoint Mapping
23
+ // ============================================
24
+ const ENTRYPOINT_MAP = {
25
+ '0.6': account_abstraction_1.entryPoint07Address, // Fallback to 0.7 for 0.6 requests
26
+ '0.7': account_abstraction_1.entryPoint07Address
27
+ };
28
+ // ============================================
29
+ // Kernel Account Factory
30
+ // ============================================
31
+ async function createKernel7702Account(config) {
32
+ const { chain, owner, bundlerManager, entryPointVersion = '0.7', kernelVersion = '0.3.3' } = config;
33
+ // Create public client for standard RPC calls
34
+ // (Bundler clients don't support standard eth_* methods)
35
+ const publicClient = (0, viem_1.createPublicClient)({
36
+ chain,
37
+ transport: (0, viem_1.http)()
38
+ });
39
+ // Get EntryPoint address
40
+ const entryPointAddress = ENTRYPOINT_MAP[entryPointVersion];
41
+ if (!entryPointAddress) {
42
+ throw new Error(`Unsupported EntryPoint version: ${entryPointVersion}`);
43
+ }
44
+ // Create Kernel account with EIP-7702
45
+ // Use public client for account creation (needs eth_call, eth_getCode, etc.)
46
+ const kernelAccount = await (0, sdk_1.createKernelAccount)(publicClient, {
47
+ entryPoint: {
48
+ address: entryPointAddress,
49
+ version: entryPointVersion
50
+ },
51
+ kernelVersion: constants_1.KERNEL_V3_3,
52
+ eip7702Account: owner
53
+ });
54
+ return {
55
+ account: kernelAccount,
56
+ address: kernelAccount.address,
57
+ owner,
58
+ chain,
59
+ entryPoint: {
60
+ address: entryPointAddress,
61
+ version: entryPointVersion
62
+ }
63
+ };
64
+ }
65
+ // ============================================
66
+ // EIP-7702 Authorization Helper
67
+ // ============================================
68
+ async function createKernelAuthorization(config) {
69
+ const { owner, chain, bundlerManager, kernelVersion = '0.3.3' } = config;
70
+ const bundlerClient = bundlerManager.getClient(chain);
71
+ // Create public client for eth_getCode (bundler clients don't support it)
72
+ const publicClient = (0, viem_1.createPublicClient)({
73
+ chain,
74
+ transport: (0, viem_1.http)()
75
+ });
76
+ // Get Kernel implementation address
77
+ const delegateAddress = constants_1.KernelVersionToAddressesMap[constants_1.KERNEL_V3_3].accountImplementationAddress;
78
+ // Check if already delegated
79
+ const code = await publicClient.getCode({ address: owner.address });
80
+ const expectedCode = `0xef0100${delegateAddress.toLowerCase().substring(2)}`;
81
+ if (code === expectedCode) {
82
+ console.log('Already delegated to Kernel, no authorization needed');
83
+ return undefined;
84
+ }
85
+ // Create authorization
86
+ console.log('Creating EIP-7702 authorization for Kernel...');
87
+ // Get nonce for authorization
88
+ const nonce = await publicClient.getTransactionCount({
89
+ address: owner.address,
90
+ blockTag: 'pending'
91
+ });
92
+ // Sign authorization using the account's signAuthorization method
93
+ const authorization = await owner.signAuthorization({
94
+ contractAddress: delegateAddress,
95
+ chainId: chain.id,
96
+ nonce: nonce
97
+ });
98
+ return authorization;
99
+ }
100
+ // ============================================
101
+ // Transaction Helpers
102
+ // ============================================
103
+ /**
104
+ * Send batch transaction (RECOMMENDED for smart accounts)
105
+ *
106
+ * Sends multiple calls in a single UserOperation, paying gas only once.
107
+ * This is one of the main benefits of smart accounts over EOAs.
108
+ *
109
+ * @example
110
+ * // Send ETH to 3 recipients in one transaction
111
+ * await sendBatchTransaction({
112
+ * kernelAccount: account,
113
+ * bundlerManager,
114
+ * calls: [
115
+ * { to: '0xRecipient1', value: parseEther('0.01') },
116
+ * { to: '0xRecipient2', value: parseEther('0.02') },
117
+ * { to: '0xRecipient3', value: parseEther('0.03') }
118
+ * ]
119
+ * });
120
+ */
121
+ async function sendBatchTransaction(config) {
122
+ const { kernelAccount, bundlerManager, authorization, calls } = config;
123
+ if (calls.length === 0) {
124
+ throw new Error('Batch transaction must have at least one call');
125
+ }
126
+ const bundlerClient = bundlerManager.getClient(kernelAccount.chain);
127
+ // Normalize calls to ensure value and data are set
128
+ const normalizedCalls = calls.map(call => ({
129
+ to: call.to,
130
+ value: call.value ?? 0n,
131
+ data: call.data ?? '0x'
132
+ }));
133
+ const userOpHash = await bundlerClient.sendUserOperation({
134
+ account: kernelAccount.account,
135
+ authorization,
136
+ calls: normalizedCalls
137
+ });
138
+ return userOpHash;
139
+ }
140
+ /**
141
+ * Send single transaction (convenience wrapper around sendBatchTransaction)
142
+ *
143
+ * For single operations, you can use this instead of sendBatchTransaction.
144
+ * Under the hood, it creates a batch with one call.
145
+ */
146
+ async function sendKernelTransaction(config) {
147
+ const { kernelAccount, bundlerManager, authorization, to, value = 0n, data = '0x' } = config;
148
+ // Use batch transaction with single call
149
+ return sendBatchTransaction({
150
+ kernelAccount,
151
+ bundlerManager,
152
+ authorization,
153
+ calls: [{
154
+ to,
155
+ value,
156
+ data
157
+ }]
158
+ });
159
+ }
160
+ // ============================================
161
+ // Wait for Receipt Helper
162
+ // ============================================
163
+ async function waitForKernelReceipt(config) {
164
+ const { userOpHash, chain, bundlerManager } = config;
165
+ const bundlerClient = bundlerManager.getClient(chain);
166
+ const receipt = await bundlerClient.waitForUserOperationReceipt({
167
+ hash: userOpHash
168
+ });
169
+ return receipt;
170
+ }
171
+ /**
172
+ * Send sponsored batch transaction using EIP-7702
173
+ *
174
+ * Allows a feePayer wallet to pay gas fees for another wallet's transaction.
175
+ * The transaction executes from the owner's address, but gas is paid by the feePayer.
176
+ *
177
+ * @param config - Sponsored transaction configuration
178
+ * @returns UserOperation hash and transaction hash
179
+ *
180
+ * @example
181
+ * // Owner creates authorization
182
+ * const authorization = await createKernelAuthorization({
183
+ * owner: ownerAccount,
184
+ * chain,
185
+ * bundlerManager
186
+ * });
187
+ *
188
+ * // FeePayer sends transaction
189
+ * const result = await sendSponsoredBatchTransaction({
190
+ * ownerAuthorization: authorization,
191
+ * calls: [{ to: recipient, value: parseEther('0.1') }],
192
+ * feePayerPrivateKey: sponsorPrivateKey,
193
+ * bundlerUrl,
194
+ * chain
195
+ * });
196
+ */
197
+ async function sendSponsoredBatchTransaction(config) {
198
+ const { ownerAuthorization, calls, feePayerPrivateKey, bundlerUrl, paymasterUrl, chain, entryPointVersion = '0.7' } = config;
199
+ if (calls.length === 0) {
200
+ throw new Error('Sponsored transaction must have at least one call');
201
+ }
202
+ // Create feePayer account
203
+ const feePayerAccount = (0, accounts_1.privateKeyToAccount)(feePayerPrivateKey);
204
+ // Create bundler service for feePayer
205
+ const feePayerBundlerService = (0, bundler_1.createBundlerService)({
206
+ provider: "custom",
207
+ customUrl: bundlerUrl,
208
+ chain
209
+ });
210
+ // Get bundler client (uses feePayer account internally)
211
+ const bundlerClient = feePayerBundlerService.getClient(chain);
212
+ // Create kernel account for feePayer (needed for sendUserOperation)
213
+ const publicClient = (0, viem_1.createPublicClient)({
214
+ chain,
215
+ transport: (0, viem_1.http)(chain.rpcUrls.default.http[0])
216
+ });
217
+ const entryPointAddress = ENTRYPOINT_MAP[entryPointVersion];
218
+ if (!entryPointAddress) {
219
+ throw new Error(`Unsupported EntryPoint version: ${entryPointVersion}`);
220
+ }
221
+ const feePayerKernelAccount = await (0, sdk_1.createKernelAccount)(publicClient, {
222
+ entryPoint: {
223
+ address: entryPointAddress,
224
+ version: entryPointVersion
225
+ },
226
+ kernelVersion: constants_1.KERNEL_V3_3,
227
+ eip7702Account: feePayerAccount
228
+ });
229
+ // Normalize calls
230
+ const normalizedCalls = calls.map(call => ({
231
+ to: call.to,
232
+ value: call.value ?? 0n,
233
+ data: call.data ?? '0x'
234
+ }));
235
+ // Send UserOperation with owner's authorization
236
+ // The transaction executes from owner's address, but feePayer pays gas
237
+ const userOpHash = await bundlerClient.sendUserOperation({
238
+ account: feePayerKernelAccount,
239
+ authorization: ownerAuthorization,
240
+ calls: normalizedCalls
241
+ });
242
+ // Wait for receipt
243
+ const receipt = await bundlerClient.waitForUserOperationReceipt({
244
+ hash: userOpHash
245
+ });
246
+ return {
247
+ userOpHash: userOpHash,
248
+ transactionHash: receipt?.receipt?.transactionHash
249
+ };
250
+ }
251
+ //# sourceMappingURL=kernel-account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel-account.js","sourceRoot":"","sources":["../../../../utils/evm/aa-service/lib/kernel-account.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAoCH,0DAiDC;AAMD,8DA+CC;AAwBD,oDA4BC;AAQD,sDAqBC;AAMD,oDAcC;AA6CD,sEA6EC;AAvWD,+BAAmH;AACnH,4CAAuE;AACvE,sCAAmD;AACnD,sDAAkF;AAClF,kEAAoF;AACpF,iDAA2E;AAgB3E,+CAA+C;AAC/C,qBAAqB;AACrB,+CAA+C;AAE/C,MAAM,cAAc,GAAmC;IACnD,KAAK,EAAE,yCAAmB,EAAE,mCAAmC;IAC/D,KAAK,EAAE,yCAAmB;CAC7B,CAAC;AAEF,+CAA+C;AAC/C,yBAAyB;AACzB,+CAA+C;AAExC,KAAK,UAAU,uBAAuB,CACzC,MAA2B;IAE3B,MAAM,EACF,KAAK,EACL,KAAK,EACL,cAAc,EACd,iBAAiB,GAAG,KAAK,EACzB,aAAa,GAAG,OAAO,EAC1B,GAAG,MAAM,CAAC;IAEX,8CAA8C;IAC9C,yDAAyD;IACzD,MAAM,YAAY,GAAG,IAAA,yBAAkB,EAAC;QACpC,KAAK;QACL,SAAS,EAAE,IAAA,WAAI,G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AU,GAAG,MAAM,aAAa,CAAC,iBAAiB,CAAC;QACrD,OAAO,EAAE,qBAAqB;QAC9B,aAAa,EAAE,kBAAkB;QACjC,KAAK,EAAE,eAAe;KACzB,CAAC,CAAC;IAEH,mBAAmB;IACnB,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,2BAA2B,CAAC;QAC5D,IAAI,EAAE,UAAU;KACnB,CAAC,CAAC;IAEH,OAAO;QACH,UAAU,EAAE,UAAiB;QAC7B,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe;KACrD,CAAC;AACN,CAAC"}
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Kernel Module Management
3
+ *
4
+ * Handles installation and management of ERC-7579 modules for Kernel v3 accounts:
5
+ * - Validators: Session keys, multi-sig, passkeys
6
+ * - Executors: Additional execution logic
7
+ * - Hooks: Pre/post execution hooks
8
+ * - Fallbacks: Handle unknown function calls
9
+ *
10
+ * ERC-7579 Module Types:
11
+ * 1 = Validator
12
+ * 2 = Executor
13
+ * 3 = Fallback
14
+ * 4 = Hook
15
+ */
16
+ import { Hex } from 'viem';
17
+ import { KernelAccountInstance } from './kernel-account';
18
+ import { BundlerManager } from '../services/bundler';
19
+ export type ModuleType = 'validator' | 'executor' | 'fallback' | 'hook';
20
+ export declare const MODULE_TYPE_IDS: Record<ModuleType, number>;
21
+ export interface InstallModuleConfig {
22
+ account: KernelAccountInstance;
23
+ bundlerManager: BundlerManager;
24
+ moduleType: ModuleType;
25
+ moduleAddress: Hex;
26
+ initData?: Hex;
27
+ }
28
+ export interface UninstallModuleConfig {
29
+ account: KernelAccountInstance;
30
+ bundlerManager: BundlerManager;
31
+ moduleType: ModuleType;
32
+ moduleAddress: Hex;
33
+ deInitData?: Hex;
34
+ }
35
+ export interface ModuleStatus {
36
+ isInstalled: boolean;
37
+ moduleAddress: Hex;
38
+ moduleType: ModuleType;
39
+ }
40
+ /**
41
+ * Session key permissions for automated operations
42
+ *
43
+ * Example: Allow automated monthly transfers to a savings account
44
+ */
45
+ export interface SessionKeyPermission {
46
+ /** Target contract address (token, vault, etc.) */
47
+ target: Hex;
48
+ /** Maximum value per transaction (for ETH transfers) */
49
+ maxValuePerUse?: bigint;
50
+ /** Function selector to allow (e.g., transfer, approve) */
51
+ functionSelector?: Hex;
52
+ /** Maximum gas per transaction */
53
+ maxGasPerUse?: bigint;
54
+ /** Session expiry timestamp */
55
+ validUntil?: number;
56
+ /** Session start timestamp */
57
+ validAfter?: number;
58
+ /** Maximum number of uses */
59
+ maxUses?: number;
60
+ }
61
+ export interface CreateSessionKeyConfig {
62
+ account: KernelAccountInstance;
63
+ bundlerManager: BundlerManager;
64
+ sessionKeyAddress: Hex;
65
+ permissions: SessionKeyPermission[];
66
+ }
67
+ import { Call } from './kernel-account';
68
+ /**
69
+ * Prepare installModule call (for batching)
70
+ *
71
+ * Returns a Call object that can be batched with other operations.
72
+ * Use this when you want to install multiple modules in one transaction.
73
+ *
74
+ * @example
75
+ * // Batch install multiple modules
76
+ * const calls = [
77
+ * prepareInstallModule({ account, moduleType: 'validator', moduleAddress: '0x...' }),
78
+ * prepareInstallModule({ account, moduleType: 'hook', moduleAddress: '0x...' })
79
+ * ];
80
+ * await aaService.sendBatchTransaction({ account, calls });
81
+ */
82
+ export declare function prepareInstallModule(config: Omit<InstallModuleConfig, 'bundlerManager'>): Call;
83
+ /**
84
+ * Install a module on a Kernel account (execute immediately)
85
+ *
86
+ * This uses the ERC-7579 standard installModule function.
87
+ * For batching multiple modules, use prepareInstallModule instead.
88
+ *
89
+ * @example
90
+ * // Install a single module
91
+ * const userOpHash = await installModule({
92
+ * account,
93
+ * bundlerManager,
94
+ * moduleType: 'validator',
95
+ * moduleAddress: SESSION_KEY_VALIDATOR_ADDRESS,
96
+ * initData: encodedPermissions
97
+ * });
98
+ */
99
+ export declare function installModule(config: InstallModuleConfig): Promise<Hex>;
100
+ /**
101
+ * Prepare uninstallModule call (for batching)
102
+ *
103
+ * Returns a Call object that can be batched with other operations.
104
+ *
105
+ * @example
106
+ * // Batch uninstall multiple modules
107
+ * const calls = [
108
+ * prepareUninstallModule({ account, moduleType: 'validator', moduleAddress: '0x...' }),
109
+ * prepareUninstallModule({ account, moduleType: 'hook', moduleAddress: '0x...' })
110
+ * ];
111
+ * await aaService.sendBatchTransaction({ account, calls });
112
+ */
113
+ export declare function prepareUninstallModule(config: Omit<UninstallModuleConfig, 'bundlerManager'>): Call;
114
+ /**
115
+ * Uninstall a module from a Kernel account (execute immediately)
116
+ *
117
+ * For batching multiple uninstalls, use prepareUninstallModule instead.
118
+ *
119
+ * @example
120
+ * // Uninstall a single module
121
+ * const userOpHash = await uninstallModule({
122
+ * account,
123
+ * bundlerManager,
124
+ * moduleType: 'validator',
125
+ * moduleAddress: SESSION_KEY_VALIDATOR_ADDRESS
126
+ * });
127
+ */
128
+ export declare function uninstallModule(config: UninstallModuleConfig): Promise<Hex>;
129
+ /**
130
+ * Check if a module is installed on an account
131
+ *
132
+ * @example
133
+ * const isInstalled = await isModuleInstalled({
134
+ * account,
135
+ * bundlerManager,
136
+ * moduleType: 'validator',
137
+ * moduleAddress: SESSION_KEY_VALIDATOR_ADDRESS
138
+ * });
139
+ */
140
+ export declare function isModuleInstalled(config: Omit<InstallModuleConfig, 'initData'>): Promise<boolean>;
141
+ /**
142
+ * Prepare session key installation call (for batching)
143
+ *
144
+ * Returns a Call object that can be batched with other operations.
145
+ *
146
+ * @example
147
+ * // Batch install session key with other modules
148
+ * const calls = [
149
+ * prepareInstallSessionKey({ account, sessionKeyAddress, permissions }),
150
+ * prepareInstallModule({ account, moduleType: 'hook', moduleAddress: '0x...' })
151
+ * ];
152
+ * await aaService.sendBatchTransaction({ account, calls });
153
+ */
154
+ export declare function prepareInstallSessionKey(config: Omit<CreateSessionKeyConfig, 'bundlerManager'>): Call;
155
+ /**
156
+ * Create and install a session key validator (execute immediately)
157
+ *
158
+ * Session keys allow delegated access with specific permissions.
159
+ * Perfect for automated operations like recurring payments.
160
+ *
161
+ * For batching with other operations, use prepareInstallSessionKey instead.
162
+ *
163
+ * @example
164
+ * // Install session key for monthly savings automation
165
+ * const sessionKey = privateKeyToAccount('0x...');
166
+ *
167
+ * await createSessionKey({
168
+ * account,
169
+ * bundlerManager,
170
+ * sessionKeyAddress: sessionKey.address,
171
+ * permissions: [{
172
+ * target: USDC_ADDRESS,
173
+ * functionSelector: '0xa9059cbb', // transfer(address,uint256)
174
+ * maxValuePerUse: parseUnits('100', 6), // Max 100 USDC per tx
175
+ * validUntil: Date.now() + 30 * 24 * 60 * 60 * 1000, // 30 days
176
+ * maxUses: 1 // Once per month
177
+ * }]
178
+ * });
179
+ */
180
+ export declare function createSessionKey(config: CreateSessionKeyConfig): Promise<Hex>;
181
+ /**
182
+ * Prepare session key revocation call (for batching)
183
+ *
184
+ * Returns a Call object that can be batched with other operations.
185
+ *
186
+ * @example
187
+ * // Batch revoke multiple session keys
188
+ * const calls = [
189
+ * prepareRevokeSessionKey({ account, sessionKeyAddress: key1 }),
190
+ * prepareRevokeSessionKey({ account, sessionKeyAddress: key2 })
191
+ * ];
192
+ * await aaService.sendBatchTransaction({ account, calls });
193
+ */
194
+ export declare function prepareRevokeSessionKey(config: {
195
+ account: KernelAccountInstance;
196
+ sessionKeyAddress: Hex;
197
+ }): Call;
198
+ /**
199
+ * Revoke a session key (execute immediately)
200
+ *
201
+ * For batching with other operations, use prepareRevokeSessionKey instead.
202
+ */
203
+ export declare function revokeSessionKey(account: KernelAccountInstance, bundlerManager: BundlerManager, sessionKeyAddress: Hex): Promise<Hex>;
204
+ /**
205
+ * Prepare multi-sig validator installation call (for batching)
206
+ *
207
+ * Returns a Call object that can be batched with other operations.
208
+ *
209
+ * @example
210
+ * // Batch install multi-sig with session key
211
+ * const calls = [
212
+ * prepareInstallMultiSigValidator({ account, owners, threshold: 2 }),
213
+ * prepareInstallSessionKey({ account, sessionKeyAddress, permissions })
214
+ * ];
215
+ * await aaService.sendBatchTransaction({ account, calls });
216
+ */
217
+ export declare function prepareInstallMultiSigValidator(config: {
218
+ account: KernelAccountInstance;
219
+ owners: Hex[];
220
+ threshold: number;
221
+ }): Call;
222
+ /**
223
+ * Install a multi-signature validator (execute immediately)
224
+ *
225
+ * For batching with other operations, use prepareInstallMultiSigValidator instead.
226
+ *
227
+ * @example
228
+ * await installMultiSigValidator({
229
+ * account,
230
+ * bundlerManager,
231
+ * owners: [owner1, owner2, owner3],
232
+ * threshold: 2 // 2 of 3 signatures required
233
+ * });
234
+ */
235
+ export declare function installMultiSigValidator(config: {
236
+ account: KernelAccountInstance;
237
+ bundlerManager: BundlerManager;
238
+ owners: Hex[];
239
+ threshold: number;
240
+ }): Promise<Hex>;