@deserialize/multi-vm-wallet 1.4.2 → 1.5.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 (186) hide show
  1. package/.claude/settings.local.json +7 -1
  2. package/BUILD_OPTIMIZATION_PLAN.md +640 -0
  3. package/BUILD_RESULTS.md +282 -0
  4. package/BUN_MIGRATION.md +415 -0
  5. package/CHANGELOG_SECURITY.md +573 -0
  6. package/IMPLEMENTATION_SUMMARY.md +494 -0
  7. package/SECURITY_AUDIT.md +1124 -0
  8. package/bun.lock +553 -0
  9. package/dist/IChainWallet.js +0 -5
  10. package/dist/bip32Old.js +0 -885
  11. package/dist/bip32Small.js +0 -79
  12. package/dist/bipTest.js +0 -362
  13. package/dist/constant.js +0 -17
  14. package/dist/english.js +0 -1
  15. package/dist/evm/aa-service/index.d.ts +0 -5
  16. package/dist/evm/aa-service/index.js +0 -14
  17. package/dist/evm/aa-service/lib/account-adapter.d.ts +0 -22
  18. package/dist/evm/aa-service/lib/account-adapter.js +0 -24
  19. package/dist/evm/aa-service/lib/kernel-account.d.ts +0 -30
  20. package/dist/evm/aa-service/lib/kernel-account.js +2 -67
  21. package/dist/evm/aa-service/lib/kernel-modules.d.ts +0 -177
  22. package/dist/evm/aa-service/lib/kernel-modules.js +4 -202
  23. package/dist/evm/aa-service/lib/session-keys.d.ts +0 -118
  24. package/dist/evm/aa-service/lib/session-keys.js +7 -151
  25. package/dist/evm/aa-service/lib/type.d.ts +0 -55
  26. package/dist/evm/aa-service/lib/type.js +0 -10
  27. package/dist/evm/aa-service/services/account-abstraction.d.ts +0 -426
  28. package/dist/evm/aa-service/services/account-abstraction.js +0 -461
  29. package/dist/evm/aa-service/services/bundler.d.ts +0 -6
  30. package/dist/evm/aa-service/services/bundler.js +0 -54
  31. package/dist/evm/evm.d.ts +9 -51
  32. package/dist/evm/evm.js +338 -76
  33. package/dist/evm/index.js +0 -3
  34. package/dist/evm/script.js +3 -17
  35. package/dist/evm/smartWallet.d.ts +0 -173
  36. package/dist/evm/smartWallet.js +0 -206
  37. package/dist/evm/smartWallet.types.d.ts +0 -6
  38. package/dist/evm/smartWallet.types.js +0 -8
  39. package/dist/evm/transaction.utils.d.ts +0 -242
  40. package/dist/evm/transaction.utils.js +4 -320
  41. package/dist/evm/transactionParsing.d.ts +0 -11
  42. package/dist/evm/transactionParsing.js +28 -147
  43. package/dist/evm/utils.d.ts +0 -46
  44. package/dist/evm/utils.js +1 -57
  45. package/dist/helpers/index.d.ts +0 -4
  46. package/dist/helpers/index.js +8 -44
  47. package/dist/helpers/routeScan.js +0 -1
  48. package/dist/index.js +0 -1
  49. package/dist/old.js +0 -884
  50. package/dist/price.js +0 -1
  51. package/dist/price.types.js +0 -2
  52. package/dist/rate-limiter.d.ts +28 -0
  53. package/dist/rate-limiter.js +95 -0
  54. package/dist/retry-logic.d.ts +14 -0
  55. package/dist/retry-logic.js +120 -0
  56. package/dist/savings/index.js +0 -1
  57. package/dist/savings/saving-manager.d.ts +10 -11
  58. package/dist/savings/saving-manager.js +79 -22
  59. package/dist/savings/savings-operations.d.ts +39 -0
  60. package/dist/savings/savings-operations.js +141 -0
  61. package/dist/savings/smart-savings.d.ts +0 -63
  62. package/dist/savings/smart-savings.js +0 -78
  63. package/dist/savings/types.d.ts +0 -69
  64. package/dist/savings/types.js +0 -7
  65. package/dist/savings/validation.d.ts +9 -0
  66. package/dist/savings/validation.js +85 -0
  67. package/dist/svm/constant.js +0 -1
  68. package/dist/svm/index.js +0 -1
  69. package/dist/svm/svm.d.ts +11 -1
  70. package/dist/svm/svm.js +267 -27
  71. package/dist/svm/transactionParsing.d.ts +0 -7
  72. package/dist/svm/transactionParsing.js +3 -41
  73. package/dist/svm/transactionSender.js +0 -9
  74. package/dist/svm/utils.d.ts +0 -12
  75. package/dist/svm/utils.js +9 -60
  76. package/dist/test.d.ts +0 -4
  77. package/dist/test.js +6 -98
  78. package/dist/transaction-utils.d.ts +38 -0
  79. package/dist/transaction-utils.js +168 -0
  80. package/dist/types.d.ts +36 -0
  81. package/dist/types.js +0 -1
  82. package/dist/utils.js +0 -1
  83. package/dist/vm-validation.d.ts +11 -0
  84. package/dist/vm-validation.js +151 -0
  85. package/dist/vm.d.ts +12 -2
  86. package/dist/vm.js +61 -16
  87. package/dist/walletBip32.js +15 -70
  88. package/package.json +9 -4
  89. package/test-discovery.ts +235 -0
  90. package/test-pocket-discovery.ts +84 -0
  91. package/tsconfig.json +18 -11
  92. package/tsconfig.prod.json +10 -0
  93. package/utils/evm/evm.ts +554 -8
  94. package/utils/rate-limiter.ts +179 -0
  95. package/utils/retry-logic.ts +271 -0
  96. package/utils/savings/EXAMPLES.md +883 -0
  97. package/utils/savings/SECURITY.md +731 -0
  98. package/utils/savings/saving-manager.ts +526 -16
  99. package/utils/savings/savings-operations.ts +509 -0
  100. package/utils/savings/validation.ts +187 -0
  101. package/utils/svm/svm.ts +476 -5
  102. package/utils/test.ts +2 -2
  103. package/utils/transaction-utils.ts +394 -0
  104. package/utils/types.ts +100 -0
  105. package/utils/vm-validation.ts +280 -0
  106. package/utils/vm.ts +197 -10
  107. package/utils/walletBip32.ts +39 -3
  108. package/dist/IChainWallet.js.map +0 -1
  109. package/dist/bip32.d.ts +0 -9
  110. package/dist/bip32.js +0 -172
  111. package/dist/bip32.js.map +0 -1
  112. package/dist/bip32Old.js.map +0 -1
  113. package/dist/bip32Small.js.map +0 -1
  114. package/dist/bipTest.js.map +0 -1
  115. package/dist/constant.js.map +0 -1
  116. package/dist/english.js.map +0 -1
  117. package/dist/evm/SMART_WALLET_EXAMPLES.d.ts +0 -20
  118. package/dist/evm/SMART_WALLET_EXAMPLES.js +0 -451
  119. package/dist/evm/SMART_WALLET_EXAMPLES.js.map +0 -1
  120. package/dist/evm/aa-service/index.js.map +0 -1
  121. package/dist/evm/aa-service/lib/account-adapter.js.map +0 -1
  122. package/dist/evm/aa-service/lib/kernel-account.js.map +0 -1
  123. package/dist/evm/aa-service/lib/kernel-modules.js.map +0 -1
  124. package/dist/evm/aa-service/lib/session-keys.js.map +0 -1
  125. package/dist/evm/aa-service/lib/type.js.map +0 -1
  126. package/dist/evm/aa-service/services/account-abstraction.js.map +0 -1
  127. package/dist/evm/aa-service/services/bundler.js.map +0 -1
  128. package/dist/evm/evm.js.map +0 -1
  129. package/dist/evm/index.js.map +0 -1
  130. package/dist/evm/script.js.map +0 -1
  131. package/dist/evm/smartWallet.js.map +0 -1
  132. package/dist/evm/smartWallet.types.js.map +0 -1
  133. package/dist/evm/transaction.utils.js.map +0 -1
  134. package/dist/evm/transactionParsing.js.map +0 -1
  135. package/dist/evm/utils.js.map +0 -1
  136. package/dist/helpers/index.js.map +0 -1
  137. package/dist/helpers/routeScan.js.map +0 -1
  138. package/dist/index.js.map +0 -1
  139. package/dist/old.js.map +0 -1
  140. package/dist/price.js.map +0 -1
  141. package/dist/price.types.js.map +0 -1
  142. package/dist/privacy/artifact-manager.d.ts +0 -117
  143. package/dist/privacy/artifact-manager.js +0 -251
  144. package/dist/privacy/artifact-manager.js.map +0 -1
  145. package/dist/privacy/broadcaster-client.d.ts +0 -166
  146. package/dist/privacy/broadcaster-client.js +0 -261
  147. package/dist/privacy/broadcaster-client.js.map +0 -1
  148. package/dist/privacy/index.d.ts +0 -34
  149. package/dist/privacy/index.js +0 -56
  150. package/dist/privacy/index.js.map +0 -1
  151. package/dist/privacy/network-config.d.ts +0 -57
  152. package/dist/privacy/network-config.js +0 -118
  153. package/dist/privacy/network-config.js.map +0 -1
  154. package/dist/privacy/poi-helper.d.ts +0 -161
  155. package/dist/privacy/poi-helper.js +0 -249
  156. package/dist/privacy/poi-helper.js.map +0 -1
  157. package/dist/privacy/railgun-engine.d.ts +0 -135
  158. package/dist/privacy/railgun-engine.js +0 -205
  159. package/dist/privacy/railgun-engine.js.map +0 -1
  160. package/dist/privacy/railgun-privacy-wallet.d.ts +0 -288
  161. package/dist/privacy/railgun-privacy-wallet.js +0 -539
  162. package/dist/privacy/railgun-privacy-wallet.js.map +0 -1
  163. package/dist/privacy/types.d.ts +0 -229
  164. package/dist/privacy/types.js +0 -26
  165. package/dist/privacy/types.js.map +0 -1
  166. package/dist/savings/index.js.map +0 -1
  167. package/dist/savings/saving-actions.d.ts +0 -0
  168. package/dist/savings/saving-actions.js +0 -78
  169. package/dist/savings/saving-actions.js.map +0 -1
  170. package/dist/savings/saving-manager.js.map +0 -1
  171. package/dist/savings/savings-manager.d.ts +0 -126
  172. package/dist/savings/savings-manager.js +0 -234
  173. package/dist/savings/savings-manager.js.map +0 -1
  174. package/dist/savings/smart-savings.js.map +0 -1
  175. package/dist/savings/types.js.map +0 -1
  176. package/dist/svm/constant.js.map +0 -1
  177. package/dist/svm/index.js.map +0 -1
  178. package/dist/svm/svm.js.map +0 -1
  179. package/dist/svm/transactionParsing.js.map +0 -1
  180. package/dist/svm/transactionSender.js.map +0 -1
  181. package/dist/svm/utils.js.map +0 -1
  182. package/dist/test.js.map +0 -1
  183. package/dist/types.js.map +0 -1
  184. package/dist/utils.js.map +0 -1
  185. package/dist/vm.js.map +0 -1
  186. package/dist/walletBip32.js.map +0 -1
package/dist/evm/evm.js CHANGED
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
- /**
3
- *
4
- * @param phrase this is the pass phrase for this vm
5
- * this is a class that will be responsible for creating several evm wallets code
6
- */
7
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.EVMChainWallet = exports.EVMVM = void 0;
9
4
  const walletBip32_1 = require("../walletBip32");
10
5
  const IChainWallet_1 = require("../IChainWallet");
11
6
  const vm_1 = require("../vm");
7
+ const vm_validation_1 = require("../vm-validation");
12
8
  const ethers_1 = require("ethers");
13
9
  const utils_1 = require("./utils");
14
10
  const transactionParsing_1 = require("./transactionParsing");
@@ -17,21 +13,26 @@ const smartWallet_1 = require("./smartWallet");
17
13
  const price_1 = require("../price");
18
14
  const accounts_1 = require("viem/accounts");
19
15
  class EVMVM extends vm_1.VM {
20
- derivationPath = "m/44'/60'/0'/0/"; // Default EVM derivation path
16
+ derivationPath = "m/44'/60'/0'/0/";
21
17
  constructor(seed) {
22
18
  super(seed, "EVM");
23
19
  }
24
20
  getTokenInfo = utils_1.getTokenInfo;
25
21
  static getTokenInfo = utils_1.getTokenInfo;
26
22
  generatePrivateKey(index, seed, mnemonic, derivationPath = this.derivationPath) {
23
+ vm_validation_1.VMValidation.validateIndex(index, 'Wallet index');
24
+ vm_validation_1.VMValidation.validateDerivationPath(derivationPath + index + "'", 'EVM');
27
25
  let _seed;
28
26
  if (seed) {
27
+ vm_validation_1.VMValidation.validateSeed(seed);
29
28
  _seed = seed;
30
29
  }
31
30
  else if (mnemonic) {
31
+ vm_validation_1.VMValidation.validateMnemonic(mnemonic);
32
32
  _seed = vm_1.VM.mnemonicToSeed(mnemonic);
33
33
  }
34
34
  else {
35
+ this.checkNotDisposed();
35
36
  _seed = this.seed;
36
37
  }
37
38
  const privateKey = (0, walletBip32_1.EVMDeriveChildPrivateKey)(_seed, index, derivationPath).privateKey;
@@ -44,27 +45,352 @@ class EVMVM extends vm_1.VM {
44
45
  const seed = vm_1.VM.mnemonicToSeed(mnemonic);
45
46
  return new EVMVM(seed);
46
47
  }
47
- static validateAddress(address) {
48
- return ethers_1.ethers.isAddress(address);
48
+ static validateAddress(address, requireChecksum = false) {
49
+ if (!ethers_1.ethers.isAddress(address)) {
50
+ return false;
51
+ }
52
+ if (requireChecksum && address !== address.toLowerCase() && address !== address.toUpperCase()) {
53
+ try {
54
+ const checksummed = ethers_1.ethers.getAddress(address);
55
+ return checksummed === address;
56
+ }
57
+ catch {
58
+ return false;
59
+ }
60
+ }
61
+ return true;
62
+ }
63
+ static normalizeAddress(address) {
64
+ if (!this.validateAddress(address)) {
65
+ throw new Error(`Invalid Ethereum address: ${address}`);
66
+ }
67
+ return ethers_1.ethers.getAddress(address);
49
68
  }
50
69
  static async getNativeBalance(address, connection) {
51
- // Implement native balance retrieval logic here
52
70
  return await (0, utils_1.getNativeBalance)(address, connection);
53
71
  }
54
72
  static async getTokenBalance(address, tokenAddress, connection) {
55
- // Implement token balance retrieval logic here
56
73
  return await (0, utils_1.getTokenBalance)(tokenAddress, address, connection);
57
74
  }
58
75
  static convertFromEntropyToPrivateKey = (entropy) => {
59
76
  return (0, viem_1.toHex)(entropy);
60
77
  };
78
+ async discoverWallets(connection, options) {
79
+ const startTime = Date.now();
80
+ const checkInParallel = options?.checkInParallel ?? true;
81
+ const opts = {
82
+ startIndex: options?.startIndex ?? 0,
83
+ maxIndex: options?.maxIndex ?? 100,
84
+ gapLimit: options?.gapLimit ?? 20,
85
+ minBalance: options?.minBalance ?? 0n,
86
+ includeZeroBalance: options?.includeZeroBalance ?? false,
87
+ includePrivateKeys: options?.includePrivateKeys ?? false,
88
+ checkInParallel,
89
+ batchSize: options?.batchSize ?? 10,
90
+ checkDelay: options?.checkDelay ?? (checkInParallel ? 200 : 50),
91
+ onProgress: options?.onProgress ?? (() => { }),
92
+ onDiscovered: options?.onDiscovered ?? (() => { }),
93
+ };
94
+ const discovered = [];
95
+ let gapCounter = 0;
96
+ let highestIndex = opts.startIndex;
97
+ let stoppedByGapLimit = false;
98
+ const isViem = 'readContract' in connection;
99
+ if (opts.checkInParallel) {
100
+ for (let i = opts.startIndex; i <= opts.maxIndex; i += opts.batchSize) {
101
+ if (gapCounter >= opts.gapLimit) {
102
+ stoppedByGapLimit = true;
103
+ break;
104
+ }
105
+ const batchIndices = Array.from({ length: Math.min(opts.batchSize, opts.maxIndex - i + 1) }, (_, idx) => i + idx);
106
+ const batchResults = await Promise.all(batchIndices.map(index => this.checkWalletBalance(index, connection, isViem)));
107
+ for (let j = 0; j < batchResults.length; j++) {
108
+ const result = batchResults[j];
109
+ const index = batchIndices[j];
110
+ highestIndex = index;
111
+ if (result) {
112
+ const meetsMinBalance = result.nativeBalance.amount >= opts.minBalance;
113
+ if (meetsMinBalance || opts.includeZeroBalance) {
114
+ if (!opts.includePrivateKeys) {
115
+ delete result.privateKey;
116
+ }
117
+ discovered.push(result);
118
+ opts.onDiscovered(result);
119
+ if (meetsMinBalance) {
120
+ gapCounter = 0;
121
+ }
122
+ else {
123
+ gapCounter++;
124
+ }
125
+ }
126
+ else {
127
+ gapCounter++;
128
+ }
129
+ }
130
+ else {
131
+ gapCounter++;
132
+ }
133
+ opts.onProgress(index + 1 - opts.startIndex, opts.maxIndex - opts.startIndex + 1, discovered.length);
134
+ if (gapCounter >= opts.gapLimit) {
135
+ stoppedByGapLimit = true;
136
+ break;
137
+ }
138
+ }
139
+ if (i + opts.batchSize <= opts.maxIndex && !stoppedByGapLimit) {
140
+ await this.sleep(opts.checkDelay);
141
+ }
142
+ }
143
+ }
144
+ else {
145
+ for (let index = opts.startIndex; index <= opts.maxIndex; index++) {
146
+ if (gapCounter >= opts.gapLimit) {
147
+ stoppedByGapLimit = true;
148
+ break;
149
+ }
150
+ const result = await this.checkWalletBalance(index, connection, isViem);
151
+ highestIndex = index;
152
+ if (result) {
153
+ const meetsMinBalance = result.nativeBalance.amount >= opts.minBalance;
154
+ if (meetsMinBalance || opts.includeZeroBalance) {
155
+ if (!opts.includePrivateKeys) {
156
+ delete result.privateKey;
157
+ }
158
+ discovered.push(result);
159
+ opts.onDiscovered(result);
160
+ if (meetsMinBalance) {
161
+ gapCounter = 0;
162
+ }
163
+ else {
164
+ gapCounter++;
165
+ }
166
+ }
167
+ else {
168
+ gapCounter++;
169
+ }
170
+ }
171
+ else {
172
+ gapCounter++;
173
+ }
174
+ opts.onProgress(index + 1 - opts.startIndex, opts.maxIndex - opts.startIndex + 1, discovered.length);
175
+ if (index < opts.maxIndex && !stoppedByGapLimit) {
176
+ await this.sleep(opts.checkDelay);
177
+ }
178
+ }
179
+ }
180
+ const totalBalance = discovered.reduce((sum, wallet) => sum + wallet.nativeBalance.amount, 0n);
181
+ const duration = Date.now() - startTime;
182
+ return {
183
+ discovered,
184
+ scannedIndices: highestIndex - opts.startIndex + 1,
185
+ highestIndex,
186
+ totalBalance,
187
+ stoppedByGapLimit,
188
+ duration,
189
+ };
190
+ }
191
+ async checkWalletBalance(index, connection, isViem, maxRetries = 3) {
192
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
193
+ try {
194
+ const { privateKey } = this.generatePrivateKey(index);
195
+ const wallet = new ethers_1.ethers.Wallet(privateKey);
196
+ const address = wallet.address;
197
+ let balanceWei;
198
+ if (isViem) {
199
+ const viemConnection = connection;
200
+ balanceWei = await viemConnection.getBalance({ address: address });
201
+ }
202
+ else {
203
+ const ethersConnection = connection;
204
+ balanceWei = await ethersConnection.getBalance(address);
205
+ }
206
+ const formatted = Number(ethers_1.ethers.formatEther(balanceWei));
207
+ return {
208
+ index,
209
+ address,
210
+ derivationPath: `${this.derivationPath}${index}'`,
211
+ nativeBalance: {
212
+ amount: balanceWei,
213
+ formatted,
214
+ symbol: 'ETH',
215
+ },
216
+ privateKey,
217
+ };
218
+ }
219
+ catch (error) {
220
+ if (attempt === maxRetries - 1) {
221
+ console.warn(`Failed to check wallet at index ${index} after ${maxRetries} attempts:`, error);
222
+ return null;
223
+ }
224
+ const delay = Math.pow(2, attempt) * 1000;
225
+ await this.sleep(delay);
226
+ }
227
+ }
228
+ return null;
229
+ }
230
+ sleep(ms) {
231
+ return new Promise(resolve => setTimeout(resolve, ms));
232
+ }
233
+ async discoverPockets(connection, options) {
234
+ const startTime = Date.now();
235
+ const walletIndex = options?.walletIndex ?? 0;
236
+ const checkInParallel = options?.checkInParallel ?? true;
237
+ const opts = {
238
+ startIndex: options?.startIndex ?? 0,
239
+ maxIndex: options?.maxIndex ?? 100,
240
+ gapLimit: options?.gapLimit ?? 20,
241
+ minBalance: options?.minBalance ?? 0n,
242
+ includeZeroBalance: options?.includeZeroBalance ?? false,
243
+ includePrivateKeys: options?.includePrivateKeys ?? false,
244
+ checkInParallel,
245
+ batchSize: options?.batchSize ?? 10,
246
+ checkDelay: options?.checkDelay ?? (checkInParallel ? 200 : 50),
247
+ onProgress: options?.onProgress ?? (() => { }),
248
+ onDiscovered: options?.onDiscovered ?? (() => { }),
249
+ walletIndex,
250
+ };
251
+ const discovered = [];
252
+ let gapCounter = 0;
253
+ let highestIndex = opts.startIndex;
254
+ let stoppedByGapLimit = false;
255
+ const isViem = 'readContract' in connection;
256
+ if (opts.checkInParallel) {
257
+ for (let i = opts.startIndex; i <= opts.maxIndex; i += opts.batchSize) {
258
+ if (gapCounter >= opts.gapLimit) {
259
+ stoppedByGapLimit = true;
260
+ break;
261
+ }
262
+ const batchIndices = Array.from({ length: Math.min(opts.batchSize, opts.maxIndex - i + 1) }, (_, idx) => i + idx);
263
+ const batchResults = await Promise.all(batchIndices.map(index => this.checkPocketBalance(index, walletIndex, connection, isViem)));
264
+ for (let j = 0; j < batchResults.length; j++) {
265
+ const result = batchResults[j];
266
+ const index = batchIndices[j];
267
+ highestIndex = index;
268
+ if (result) {
269
+ const meetsMinBalance = result.nativeBalance.amount >= opts.minBalance;
270
+ if (meetsMinBalance || opts.includeZeroBalance) {
271
+ if (!opts.includePrivateKeys) {
272
+ delete result.privateKey;
273
+ }
274
+ discovered.push(result);
275
+ opts.onDiscovered(result);
276
+ if (meetsMinBalance) {
277
+ gapCounter = 0;
278
+ }
279
+ else {
280
+ gapCounter++;
281
+ }
282
+ }
283
+ else {
284
+ gapCounter++;
285
+ }
286
+ }
287
+ else {
288
+ gapCounter++;
289
+ }
290
+ opts.onProgress(index + 1 - opts.startIndex, opts.maxIndex - opts.startIndex + 1, discovered.length);
291
+ if (gapCounter >= opts.gapLimit) {
292
+ stoppedByGapLimit = true;
293
+ break;
294
+ }
295
+ }
296
+ if (i + opts.batchSize <= opts.maxIndex && !stoppedByGapLimit) {
297
+ await this.sleep(opts.checkDelay);
298
+ }
299
+ }
300
+ }
301
+ else {
302
+ for (let index = opts.startIndex; index <= opts.maxIndex; index++) {
303
+ if (gapCounter >= opts.gapLimit) {
304
+ stoppedByGapLimit = true;
305
+ break;
306
+ }
307
+ const result = await this.checkPocketBalance(index, walletIndex, connection, isViem);
308
+ highestIndex = index;
309
+ if (result) {
310
+ const meetsMinBalance = result.nativeBalance.amount >= opts.minBalance;
311
+ if (meetsMinBalance || opts.includeZeroBalance) {
312
+ if (!opts.includePrivateKeys) {
313
+ delete result.privateKey;
314
+ }
315
+ discovered.push(result);
316
+ opts.onDiscovered(result);
317
+ if (meetsMinBalance) {
318
+ gapCounter = 0;
319
+ }
320
+ else {
321
+ gapCounter++;
322
+ }
323
+ }
324
+ else {
325
+ gapCounter++;
326
+ }
327
+ }
328
+ else {
329
+ gapCounter++;
330
+ }
331
+ opts.onProgress(index + 1 - opts.startIndex, opts.maxIndex - opts.startIndex + 1, discovered.length);
332
+ if (index < opts.maxIndex && !stoppedByGapLimit) {
333
+ await this.sleep(opts.checkDelay);
334
+ }
335
+ }
336
+ }
337
+ const totalBalance = discovered.reduce((sum, wallet) => sum + wallet.nativeBalance.amount, 0n);
338
+ const duration = Date.now() - startTime;
339
+ return {
340
+ discovered,
341
+ scannedIndices: highestIndex - opts.startIndex + 1,
342
+ highestIndex,
343
+ totalBalance,
344
+ stoppedByGapLimit,
345
+ duration,
346
+ };
347
+ }
348
+ async checkPocketBalance(accountIndex, walletIndex, connection, isViem, maxRetries = 3) {
349
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
350
+ try {
351
+ const pocketIndex = accountIndex + 1;
352
+ const derivationPath = `m/44'/60'/${pocketIndex}'/0/${walletIndex}'`;
353
+ const { privateKey } = (0, walletBip32_1.EVMDeriveChildPrivateKey)(this.seed, walletIndex, `m/44'/60'/${pocketIndex}'/0/`);
354
+ const wallet = new ethers_1.ethers.Wallet(privateKey);
355
+ const address = wallet.address;
356
+ let balanceWei;
357
+ if (isViem) {
358
+ const viemConnection = connection;
359
+ balanceWei = await viemConnection.getBalance({ address: address });
360
+ }
361
+ else {
362
+ const ethersConnection = connection;
363
+ balanceWei = await ethersConnection.getBalance(address);
364
+ }
365
+ const formatted = Number(ethers_1.ethers.formatEther(balanceWei));
366
+ return {
367
+ index: accountIndex,
368
+ address,
369
+ derivationPath,
370
+ nativeBalance: {
371
+ amount: balanceWei,
372
+ formatted,
373
+ symbol: 'ETH',
374
+ },
375
+ privateKey,
376
+ };
377
+ }
378
+ catch (error) {
379
+ if (attempt === maxRetries - 1) {
380
+ console.warn(`Failed to check pocket at account ${accountIndex} after ${maxRetries} attempts:`, error);
381
+ return null;
382
+ }
383
+ const delay = Math.pow(2, attempt) * 1000;
384
+ await this.sleep(delay);
385
+ }
386
+ }
387
+ return null;
388
+ }
61
389
  }
62
390
  exports.EVMVM = EVMVM;
63
391
  class EVMChainWallet extends IChainWallet_1.ChainWallet {
64
392
  wallet;
65
393
  smartWallet;
66
- // private savingsManager?: SavingsManager
67
- // private smartSavingsManager?: SmartSavingsManager
68
394
  constructor(config, privateKey, index) {
69
395
  privateKey = privateKey.startsWith('0x') ? privateKey : `0x${privateKey}`;
70
396
  super(config, privateKey, index);
@@ -81,33 +407,15 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
81
407
  this.address = account.address;
82
408
  this.privateKey = privateKey;
83
409
  }
84
- // ============================================
85
- // Smart Wallet Extension Methods
86
- // ============================================
87
- /**
88
- * Check if Account Abstraction is supported on this chain
89
- * @returns true if aaSupport is enabled in config
90
- */
91
410
  isAASupportedByChain() {
92
411
  return this.config.aaSupport?.enabled === true;
93
412
  }
94
413
  convertFromEntropyToPrivateKey = (entropy) => {
95
414
  return (0, viem_1.toHex)(entropy);
96
415
  };
97
- /**
98
- * Check if smart wallet is initialized and ready for AA operations
99
- * @returns true if extend() has been called and smart wallet exists
100
- */
101
416
  isSmartWalletInitialized() {
102
417
  return !!this.smartWallet;
103
418
  }
104
- // createSavingsManager(mnemonic: string, index: number = 0, chain: ChainWalletConfig) {
105
- // return new SavingsManager(mnemonic, index, (chain))
106
- // }
107
- /**
108
- * Validate that AA is available for sponsored transactions
109
- * @throws Error with helpful message if AA is not available
110
- */
111
419
  validateAAAvailability() {
112
420
  if (!this.isSmartWalletInitialized()) {
113
421
  if (this.isAASupportedByChain()) {
@@ -123,26 +431,8 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
123
431
  }
124
432
  }
125
433
  }
126
- /**
127
- * Extend wallet with smart wallet capabilities
128
- * Enables Account Abstraction (EIP-4337) and EIP-7702 features
129
- *
130
- * @param options - Smart wallet configuration (optional if bundlerUrl is in config)
131
- * @returns EVMSmartWallet instance
132
- *
133
- * @example
134
- * // Using bundlerUrl from chainConfig
135
- * const smartWallet = await evmWallet.extend();
136
- *
137
- * @example
138
- * // Or provide bundlerUrl directly
139
- * const smartWallet = await evmWallet.extend({
140
- * bundlerUrl: 'https://api.pimlico.io/v2/...'
141
- * });
142
- */
143
434
  async extend(options = {}) {
144
435
  if (!this.smartWallet) {
145
- // Merge options with aaSupport config (options take priority)
146
436
  const mergedOptions = {
147
437
  ...options,
148
438
  aaConfig: this.config.aaSupport,
@@ -150,14 +440,12 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
150
440
  paymasterUrl: options.paymasterUrl || this.config.aaSupport?.paymasterUrl,
151
441
  entryPointVersion: options.entryPointVersion || this.config.aaSupport?.entryPoints?.[0]?.version
152
442
  };
153
- // Validate bundlerUrl is available
154
443
  if (!mergedOptions.bundlerUrl) {
155
444
  throw new Error('bundlerUrl is required to enable smart wallet features.\n' +
156
445
  'Provide it via:\n' +
157
446
  '1. extend({ bundlerUrl: "..." }), OR\n' +
158
447
  '2. Configure aaSupport in your chain config');
159
448
  }
160
- // Create viem chain object from config
161
449
  const chain = {
162
450
  id: this.config.chainId,
163
451
  name: this.config.name,
@@ -180,34 +468,18 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
180
468
  testnet: this.config.testnet || false
181
469
  };
182
470
  this.smartWallet = new smartWallet_1.EVMSmartWallet(this.privateKey, chain, mergedOptions);
183
- // Auto-initialize if option is set (default: true)
184
471
  if (options.autoInitialize !== false) {
185
472
  await this.smartWallet.initialize();
186
473
  }
187
474
  }
188
475
  return this.smartWallet;
189
476
  }
190
- /**
191
- * Check if smart wallet is enabled
192
- *
193
- * @returns true if extend() has been called
194
- */
195
477
  hasSmartWallet() {
196
478
  return !!this.smartWallet;
197
479
  }
198
- /**
199
- * Get smart wallet instance
200
- *
201
- * @returns EVMSmartWallet instance or undefined
202
- */
203
480
  getSmartWallet() {
204
481
  return this.smartWallet;
205
482
  }
206
- /**
207
- * Get smart wallet address (if initialized)
208
- *
209
- * @returns Smart wallet address or undefined
210
- */
211
483
  getSmartWalletAddress() {
212
484
  if (!this.smartWallet) {
213
485
  return undefined;
@@ -219,9 +491,6 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
219
491
  return undefined;
220
492
  }
221
493
  }
222
- // ============================================
223
- // Existing Wallet Methods
224
- // ============================================
225
494
  getWallet() {
226
495
  return this.wallet;
227
496
  }
@@ -229,22 +498,18 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
229
498
  return this.address;
230
499
  }
231
500
  async getNativeBalance() {
232
- // Implement native balance retrieval logic here
233
501
  return await EVMVM.getNativeBalance(this.address, this.connection);
234
502
  }
235
503
  async getTokenBalance(tokenAddress) {
236
- // Implement token balance retrieval logic here
237
504
  return await EVMVM.getTokenBalance(this.address, tokenAddress, this.connection);
238
505
  }
239
506
  async getTokenInfo(tokenAddress) {
240
507
  return await EVMVM.getTokenInfo(tokenAddress, this.connection);
241
508
  }
242
509
  async discoverToken() {
243
- // Implement token discovery logic here
244
510
  return await (0, utils_1.discoverTokens)(this.address, this.config);
245
511
  }
246
512
  async discoverNFT() {
247
- // Implement NFT discovery logic here
248
513
  return await (0, utils_1.discoverNFTs)(this.address, this.config);
249
514
  }
250
515
  async transferNative(to, amount) {
@@ -276,11 +541,9 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
276
541
  }
277
542
  return result.data;
278
543
  }
279
- // Updated swap method signature to match base class so created another method to use it inside swap
280
544
  async swap(tokenAddress, to, amount, slippage = 50) {
281
545
  throw new Error("Not Implemented");
282
546
  }
283
- // Helper method for EVMChainWallet class
284
547
  fail(message) {
285
548
  return {
286
549
  success: false,
@@ -305,4 +568,3 @@ class EVMChainWallet extends IChainWallet_1.ChainWallet {
305
568
  }
306
569
  }
307
570
  exports.EVMChainWallet = EVMChainWallet;
308
- //# sourceMappingURL=evm.js.map
package/dist/evm/index.js CHANGED
@@ -17,6 +17,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./evm"), exports);
18
18
  __exportStar(require("./utils"), exports);
19
19
  __exportStar(require("./smartWallet"), exports);
20
- // Note: AA service types are re-exported through smartWallet.types.ts
21
- // Direct AA service exports would cause duplicate export errors
22
- //# sourceMappingURL=index.js.map
@@ -2,12 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.quickSwapSetup = exports.quote = void 0;
4
4
  const ethers_1 = require("ethers");
5
- // Simplified ABI for Uniswap V3 Router
6
5
  const ROUTER_ABI = [
7
6
  'function exactInputSingle((address tokenIn, address tokenIn, uint24 fee, address recipient, uint256 deadline, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96)) external payable returns (uint256 amountOut)',
8
7
  'function exactOutputSingle((address tokenIn, address tokenIn, uint24 fee, address recipient, uint256 deadline, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96)) external payable returns (uint256 amountIn)'
9
8
  ];
10
- // ERC20 ABI (simplified)
11
9
  const ERC20_ABI = [
12
10
  'function approve(address spender, uint256 amount) external returns (bool)',
13
11
  'function allowance(address owner, address spender) external view returns (uint256)',
@@ -42,18 +40,13 @@ const quote = async (quoterAddress, rpc, tokenIn, tokenOut, amountIn, fee, sqrtP
42
40
  };
43
41
  exports.quote = quote;
44
42
  const quickSwapSetup = async (params) => {
45
- const { privateKey, tokenIn, tokenOut, amountIn, tokenInDecimal, adminAddress, routerAddress, rpcUrl, minAmountOut, feeTier = 100 // 0.01% fee tier
46
- } = params;
43
+ const { privateKey, tokenIn, tokenOut, amountIn, tokenInDecimal, adminAddress, routerAddress, rpcUrl, minAmountOut, feeTier = 100 } = params;
47
44
  try {
48
- // Setup provider and wallet
49
45
  const provider = new ethers_1.ethers.JsonRpcProvider(rpcUrl);
50
46
  const wallet = new ethers_1.ethers.Wallet(privateKey, provider);
51
- // Create contract instances
52
47
  const router = new ethers_1.ethers.Contract(routerAddress, ROUTER_ABI, wallet);
53
48
  const tokenInContract = new ethers_1.ethers.Contract(tokenIn, ERC20_ABI, wallet);
54
- // Convert amount to wei
55
- const amountInWei = ethers_1.ethers.parseUnits(amountIn, tokenInDecimal); // Assuming 18 decimals
56
- // Check and approve token allowance
49
+ const amountInWei = ethers_1.ethers.parseUnits(amountIn, tokenInDecimal);
57
50
  const allowance = await tokenInContract.allowance(wallet.address, routerAddress);
58
51
  if (allowance < amountInWei) {
59
52
  console.log('Approving tokens...');
@@ -61,18 +54,14 @@ const quickSwapSetup = async (params) => {
61
54
  await approveTx.wait();
62
55
  console.log('Approval confirmed');
63
56
  }
64
- // Calculate amount with fee (0.01% to admin)
65
- const feeAmount = amountInWei * BigInt(1) / BigInt(10000); // 0.01%
57
+ const feeAmount = amountInWei * BigInt(1) / BigInt(10000);
66
58
  const amountAfterFee = amountInWei - feeAmount;
67
- // Transfer fee to admin
68
59
  if (feeAmount > 0) {
69
60
  console.log(`Transferring ${ethers_1.ethers.formatUnits(feeAmount, tokenIn)} fee to admin`);
70
61
  const feeTransferTx = await tokenInContract.transfer(adminAddress, feeAmount);
71
62
  await feeTransferTx.wait();
72
63
  }
73
- // Set deadline (10 minutes from now)
74
64
  const deadline = Math.floor(Date.now() / 1000) + 600;
75
- // Prepare swap parameters
76
65
  const swapParams = {
77
66
  tokenIn: tokenIn,
78
67
  tokenOut: tokenOut,
@@ -84,12 +73,10 @@ const quickSwapSetup = async (params) => {
84
73
  sqrtPriceLimitX96: 0
85
74
  };
86
75
  console.log('Executing swap...');
87
- // Execute swap
88
76
  const swapTx = await router.exactInputSingle(swapParams);
89
77
  const receipt = await swapTx.wait();
90
78
  console.log('Swap successful!');
91
79
  console.log('Transaction hash:', receipt.hash);
92
- // Check final balances
93
80
  const tokenOutContract = new ethers_1.ethers.Contract(tokenOut, ERC20_ABI, wallet);
94
81
  const finalBalance = await tokenOutContract.balanceOf(wallet.address);
95
82
  console.log(`Final ${tokenOut} balance:`, ethers_1.ethers.formatUnits(finalBalance, 18));
@@ -108,4 +95,3 @@ const quickSwapSetup = async (params) => {
108
95
  }
109
96
  };
110
97
  exports.quickSwapSetup = quickSwapSetup;
111
- //# sourceMappingURL=script.js.map