@deserialize/multi-vm-wallet 1.2.1 → 1.2.3

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/IChainWallet.d.ts +5 -1
  2. package/dist/IChainWallet.js.map +1 -1
  3. package/dist/constant.d.ts +16 -0
  4. package/dist/constant.js +50 -20
  5. package/dist/constant.js.map +1 -1
  6. package/dist/evm/evm.d.ts +9 -1
  7. package/dist/evm/evm.js +43 -47
  8. package/dist/evm/evm.js.map +1 -1
  9. package/dist/evm/transaction.utils.d.ts +362 -0
  10. package/dist/evm/transaction.utils.js +669 -0
  11. package/dist/evm/transaction.utils.js.map +1 -0
  12. package/dist/evm/transactionParsing.d.ts +55 -0
  13. package/dist/evm/transactionParsing.js +414 -0
  14. package/dist/evm/transactionParsing.js.map +1 -0
  15. package/dist/evm/utils.d.ts +11 -9
  16. package/dist/evm/utils.js +42 -23
  17. package/dist/evm/utils.js.map +1 -1
  18. package/dist/helpers/index.d.ts +4 -0
  19. package/dist/helpers/index.js +13 -0
  20. package/dist/helpers/index.js.map +1 -0
  21. package/dist/svm/constant.d.ts +15 -0
  22. package/dist/svm/constant.js +25 -0
  23. package/dist/svm/constant.js.map +1 -0
  24. package/dist/svm/svm.d.ts +17 -5
  25. package/dist/svm/svm.js +29 -5
  26. package/dist/svm/svm.js.map +1 -1
  27. package/dist/svm/transactionParsing.d.ts +28 -0
  28. package/dist/svm/transactionParsing.js +207 -0
  29. package/dist/svm/transactionParsing.js.map +1 -0
  30. package/dist/svm/utils.d.ts +10 -5
  31. package/dist/svm/utils.js +103 -17
  32. package/dist/svm/utils.js.map +1 -1
  33. package/dist/test.d.ts +5 -1
  34. package/dist/test.js +54 -9
  35. package/dist/test.js.map +1 -1
  36. package/dist/types.d.ts +5 -1
  37. package/dist/types.js.map +1 -1
  38. package/package.json +7 -2
  39. package/utils/IChainWallet.ts +6 -4
  40. package/utils/constant.ts +55 -21
  41. package/utils/evm/evm.ts +63 -50
  42. package/utils/evm/transaction.utils.ts +824 -0
  43. package/utils/evm/transactionParsing.ts +613 -0
  44. package/utils/evm/utils.ts +50 -34
  45. package/utils/helpers/index.ts +11 -0
  46. package/utils/svm/constant.ts +29 -0
  47. package/utils/svm/svm.ts +44 -8
  48. package/utils/svm/transactionParsing.ts +294 -0
  49. package/utils/svm/utils.ts +151 -23
  50. package/utils/test.ts +70 -7
  51. package/utils/types.ts +6 -1
@@ -0,0 +1,55 @@
1
+ import { type PublicClient, type Address } from 'viem';
2
+ import { TransactionType } from '../constant';
3
+ export interface EVMTransactionHistoryItem {
4
+ hash: string;
5
+ timestamp: number | null;
6
+ status: 'success' | 'failed' | 'pending';
7
+ fee: string;
8
+ type: TransactionType;
9
+ from: string;
10
+ to: string | null;
11
+ blockNumber: bigint;
12
+ gasUsed: bigint;
13
+ gasPrice: string;
14
+ value: string;
15
+ method?: string;
16
+ tokenTransfers?: TokenTransfer[];
17
+ nftTransfers?: NFTTransfer[];
18
+ }
19
+ export interface TokenTransfer {
20
+ type: 'ERC20';
21
+ from: string;
22
+ to: string;
23
+ amount: string;
24
+ tokenAddress: string;
25
+ tokenSymbol?: string;
26
+ tokenDecimals?: number;
27
+ }
28
+ export interface NFTTransfer {
29
+ type: 'ERC721' | 'ERC1155';
30
+ from: string;
31
+ to: string;
32
+ tokenId: string;
33
+ amount?: string;
34
+ tokenAddress: string;
35
+ collectionName?: string;
36
+ }
37
+ export interface TransactionHistoryOptions {
38
+ startBlock?: bigint;
39
+ endBlock?: bigint;
40
+ includeTokenTransfers?: boolean;
41
+ includeNFTTransfers?: boolean;
42
+ }
43
+ /**
44
+ * Fetches and parses transaction history for an EVM wallet address
45
+ * @param client - Viem public client
46
+ * @param walletAddress - Ethereum address
47
+ * @param options - Optional parameters for filtering and features
48
+ * @returns Array of parsed transaction history items
49
+ */
50
+ export declare function getEVMTransactionHistory(client: PublicClient, walletAddress: Address, options?: TransactionHistoryOptions): Promise<EVMTransactionHistoryItem[]>;
51
+ /**
52
+ * Alternative function that uses Etherscan-like API
53
+ * This is the recommended approach for production use
54
+ */
55
+ export declare function getEVMTransactionHistoryWithAPI(client: PublicClient, walletAddress: Address, apiEndpoint: string, apiKey: string, options?: TransactionHistoryOptions): Promise<EVMTransactionHistoryItem[]>;
@@ -0,0 +1,414 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEVMTransactionHistory = getEVMTransactionHistory;
4
+ exports.getEVMTransactionHistoryWithAPI = getEVMTransactionHistoryWithAPI;
5
+ const viem_1 = require("viem");
6
+ const constant_1 = require("../constant");
7
+ // ERC20 Transfer event signature
8
+ const ERC20_TRANSFER_EVENT = (0, viem_1.parseAbi)([
9
+ 'event Transfer(address indexed from, address indexed to, uint256 value)'
10
+ ]);
11
+ // ERC721 Transfer event signature
12
+ const ERC721_TRANSFER_EVENT = (0, viem_1.parseAbi)([
13
+ 'event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)'
14
+ ]);
15
+ // ERC1155 TransferSingle event signature
16
+ const ERC1155_TRANSFER_SINGLE_EVENT = (0, viem_1.parseAbi)([
17
+ 'event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value)'
18
+ ]);
19
+ // ERC1155 TransferBatch event signature
20
+ const ERC1155_TRANSFER_BATCH_EVENT = (0, viem_1.parseAbi)([
21
+ 'event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values)'
22
+ ]);
23
+ /**
24
+ * Fetches and parses transaction history for an EVM wallet address
25
+ * @param client - Viem public client
26
+ * @param walletAddress - Ethereum address
27
+ * @param options - Optional parameters for filtering and features
28
+ * @returns Array of parsed transaction history items
29
+ */
30
+ async function getEVMTransactionHistory(client, walletAddress, options = {}) {
31
+ const { startBlock = 0n, endBlock, includeTokenTransfers = true, includeNFTTransfers = true, } = options;
32
+ try {
33
+ const currentBlock = await client.getBlockNumber();
34
+ const toBlock = endBlock || currentBlock;
35
+ // For wallet UI, we typically want recent transactions
36
+ // Start scanning from current block backwards
37
+ const scanStartBlock = startBlock > 0n ? startBlock : (currentBlock > 5000n ? currentBlock - 5000n : 0n);
38
+ console.log(`Fetching recent transactions from block ${scanStartBlock} to ${toBlock}`);
39
+ // Get transaction hashes for the address (max 15 transactions)
40
+ const txHashes = await getRecentTransactionHashes(client, walletAddress, scanStartBlock, toBlock, 15 // max transactions to fetch
41
+ );
42
+ console.log(`Found ${txHashes.length} unique transactions`);
43
+ // Fetch full transaction details in batches
44
+ const transactions = await fetchTransactionsInBatches(client, txHashes, 10);
45
+ // Parse each transaction
46
+ const history = [];
47
+ for (const { tx, receipt, block } of transactions) {
48
+ if (!tx || !receipt)
49
+ continue;
50
+ const parsed = await parseEVMTransaction(client, tx, receipt, block?.timestamp || null, walletAddress, includeTokenTransfers, includeNFTTransfers);
51
+ history.push(parsed);
52
+ }
53
+ // Sort by block number (newest first)
54
+ history.sort((a, b) => Number(b.blockNumber - a.blockNumber));
55
+ return history;
56
+ }
57
+ catch (error) {
58
+ console.error('Error fetching EVM transaction history:', error);
59
+ throw error;
60
+ }
61
+ }
62
+ /**
63
+ * Gets recent transaction hashes by scanning blocks backwards
64
+ * Uses batched parallel requests for better performance
65
+ */
66
+ async function getRecentTransactionHashes(client, address, startBlock, endBlock, maxTransactions = 15, batchSize = 9) {
67
+ const txHashes = [];
68
+ const seenHashes = new Map();
69
+ const addressLower = address.toLowerCase();
70
+ let currentBlock = endBlock;
71
+ let blocksScanned = 0n;
72
+ console.log(`Scanning blocks backwards from ${endBlock}...`);
73
+ // Iterate backwards in batches
74
+ while (currentBlock >= startBlock && txHashes.length < maxTransactions) {
75
+ // Create batch of block numbers to fetch
76
+ const blockNumbers = [];
77
+ for (let i = 0; i < batchSize && currentBlock >= startBlock; i++) {
78
+ blockNumbers.push(currentBlock);
79
+ currentBlock--;
80
+ }
81
+ try {
82
+ // Fetch all blocks in parallel
83
+ const blocks = await Promise.all(blockNumbers.map(blockNumber => client.getBlock({
84
+ blockNumber,
85
+ includeTransactions: true,
86
+ }).catch(error => {
87
+ console.error(`Error fetching block ${blockNumber}:`, error);
88
+ return null;
89
+ })));
90
+ blocks.length;
91
+ console.log('blocks.length: ', blocks.length);
92
+ // Process blocks in order (newest to oldest)
93
+ for (const block of blocks) {
94
+ if (!block || !block.transactions)
95
+ continue;
96
+ for (let i = 0; i < block.transactions.length && txHashes.length < maxTransactions; i++) {
97
+ const tx = block.transactions[i];
98
+ if (typeof tx === 'object') {
99
+ // Check if wallet is sender or receiver
100
+ const isSender = tx.from.toLowerCase() === addressLower;
101
+ const isReceiver = tx.to?.toLowerCase() === addressLower;
102
+ if ((isSender || isReceiver) && !seenHashes.has(tx.hash)) {
103
+ seenHashes.set(tx.hash, true);
104
+ txHashes.push(tx.hash);
105
+ }
106
+ }
107
+ else {
108
+ console.log("Transaction is not an object: ", tx);
109
+ }
110
+ }
111
+ // Early exit if we found enough transactions
112
+ if (txHashes.length >= maxTransactions)
113
+ break;
114
+ }
115
+ blocksScanned += BigInt(blockNumbers.length);
116
+ // Log progress
117
+ if (blocksScanned % 50n === 0n || blocksScanned < 50n) {
118
+ console.log(`Scanned ${blocksScanned} blocks, found ${txHashes.length} transactions`);
119
+ }
120
+ }
121
+ catch (error) {
122
+ console.error(`Error fetching block batch:`, error);
123
+ continue;
124
+ }
125
+ }
126
+ console.log(`Found ${txHashes.length} transactions after scanning ${blocksScanned} blocks`);
127
+ return txHashes;
128
+ }
129
+ /**
130
+ * Alternative function that uses Etherscan-like API
131
+ * This is the recommended approach for production use
132
+ */
133
+ async function getEVMTransactionHistoryWithAPI(client, walletAddress, apiEndpoint, apiKey, options = {}) {
134
+ const { includeTokenTransfers = true, includeNFTTransfers = true } = options;
135
+ try {
136
+ // Fetch normal transactions
137
+ const normalTxResponse = await fetch(`${apiEndpoint}?module=account&action=txlist&address=${walletAddress}&startblock=0&endblock=99999999&sort=desc&apikey=${apiKey}`);
138
+ const normalTxData = await normalTxResponse.json();
139
+ const history = [];
140
+ if (normalTxData.status === '1' && normalTxData.result) {
141
+ for (const tx of normalTxData.result.slice(0, 50)) { // Limit to 50 most recent
142
+ const receipt = await client.getTransactionReceipt({ hash: tx.hash });
143
+ const parsed = await parseEVMTransaction(client, {
144
+ hash: tx.hash,
145
+ from: tx.from,
146
+ to: tx.to,
147
+ value: BigInt(tx.value),
148
+ blockNumber: BigInt(tx.blockNumber),
149
+ input: tx.input,
150
+ nonce: parseInt(tx.nonce),
151
+ gas: BigInt(tx.gas),
152
+ gasPrice: tx.gasPrice ? BigInt(tx.gasPrice) : undefined,
153
+ }, receipt, BigInt(tx.timeStamp), walletAddress, includeTokenTransfers, includeNFTTransfers);
154
+ history.push(parsed);
155
+ }
156
+ }
157
+ return history;
158
+ }
159
+ catch (error) {
160
+ console.error('Error fetching EVM transaction history with API:', error);
161
+ throw error;
162
+ }
163
+ }
164
+ /**
165
+ * Fetches transaction hashes for an address by iterating through blocks
166
+ * Efficient for recent transactions (last 10-15 txs)
167
+ */
168
+ async function getTransactionHashesByAddress(client, address, startBlock, endBlock, direction, maxTransactions = 15) {
169
+ const txHashes = [];
170
+ const addressLower = address.toLowerCase();
171
+ let currentBlock = endBlock;
172
+ console.log(`Scanning blocks backwards from ${endBlock} to ${startBlock}...`);
173
+ // Iterate backwards from most recent block
174
+ while (currentBlock >= startBlock && txHashes.length < maxTransactions) {
175
+ try {
176
+ const block = await client.getBlock({
177
+ blockNumber: currentBlock,
178
+ includeTransactions: true,
179
+ });
180
+ if (block.transactions) {
181
+ for (const tx of block.transactions) {
182
+ // Check if transaction matches the direction filter
183
+ if (typeof tx === 'object') {
184
+ const matchesDirection = (direction === 'from' && tx.from.toLowerCase() === addressLower) ||
185
+ (direction === 'to' && tx.to?.toLowerCase() === addressLower) ||
186
+ (direction === 'from' && tx.from.toLowerCase() === addressLower) ||
187
+ (direction === 'to' && tx.to?.toLowerCase() === addressLower);
188
+ if (matchesDirection) {
189
+ txHashes.push(tx.hash);
190
+ // Stop if we've found enough transactions
191
+ if (txHashes.length >= maxTransactions) {
192
+ break;
193
+ }
194
+ }
195
+ }
196
+ }
197
+ }
198
+ currentBlock--;
199
+ // Log progress every 100 blocks
200
+ if ((endBlock - currentBlock) % 100n === 0n) {
201
+ console.log(`Scanned ${endBlock - currentBlock} blocks, found ${txHashes.length} transactions`);
202
+ }
203
+ }
204
+ catch (error) {
205
+ console.error(`Error fetching block ${currentBlock}:`, error);
206
+ currentBlock--;
207
+ continue;
208
+ }
209
+ }
210
+ console.log(`Found ${txHashes.length} transactions after scanning ${endBlock - currentBlock} blocks`);
211
+ return txHashes;
212
+ }
213
+ /**
214
+ * Fetches full transaction details in batches
215
+ */
216
+ async function fetchTransactionsInBatches(client, hashes, batchSize) {
217
+ const results = [];
218
+ for (let i = 0; i < hashes.length; i += batchSize) {
219
+ const batch = hashes.slice(i, i + batchSize);
220
+ const batchResults = await Promise.all(batch.map(async (hash) => {
221
+ try {
222
+ const [tx, receipt] = await Promise.all([
223
+ client.getTransaction({ hash }),
224
+ client.getTransactionReceipt({ hash }),
225
+ ]);
226
+ let block = null;
227
+ if (tx?.blockNumber) {
228
+ block = await client.getBlock({ blockNumber: tx.blockNumber });
229
+ }
230
+ return { tx, receipt, block };
231
+ }
232
+ catch (error) {
233
+ console.error(`Error fetching transaction ${hash}:`, error);
234
+ return { tx: null, receipt: null, block: null };
235
+ }
236
+ }));
237
+ results.push(...batchResults);
238
+ // Small delay to avoid rate limiting
239
+ if (i + batchSize < hashes.length) {
240
+ await new Promise(resolve => setTimeout(resolve, 100));
241
+ }
242
+ }
243
+ return results;
244
+ }
245
+ /**
246
+ * Parses a single EVM transaction
247
+ */
248
+ async function parseEVMTransaction(client, tx, receipt, timestamp, walletAddress, includeTokenTransfers, includeNFTTransfers) {
249
+ const gasUsed = receipt.gasUsed;
250
+ const effectiveGasPrice = receipt.effectiveGasPrice || tx.gasPrice || 0n;
251
+ const fee = (0, viem_1.formatEther)(gasUsed * effectiveGasPrice);
252
+ const gasPrice = (0, viem_1.formatUnits)(effectiveGasPrice, 9); // gwei
253
+ // Determine transaction type
254
+ const type = determineTransactionType(tx, receipt);
255
+ // Extract method signature
256
+ const method = tx.input && tx.input.length >= 10
257
+ ? tx.input.slice(0, 10)
258
+ : undefined;
259
+ // Parse token transfers from logs
260
+ let tokenTransfers = [];
261
+ let nftTransfers = [];
262
+ if (includeTokenTransfers || includeNFTTransfers) {
263
+ const transfers = await parseTransferLogs(client, receipt.logs, walletAddress, includeTokenTransfers, includeNFTTransfers);
264
+ tokenTransfers = transfers.tokens;
265
+ nftTransfers = transfers.nfts;
266
+ }
267
+ return {
268
+ hash: tx.hash,
269
+ timestamp: timestamp ? Number(timestamp) : null,
270
+ blockNumber: tx.blockNumber || 0n,
271
+ status: receipt.status === 'success' ? 'success' : 'failed',
272
+ fee,
273
+ gasUsed,
274
+ gasPrice,
275
+ type,
276
+ from: tx.from,
277
+ to: tx.to || null,
278
+ value: (0, viem_1.formatEther)(tx.value || 0n),
279
+ method,
280
+ tokenTransfers: tokenTransfers.length > 0 ? tokenTransfers : undefined,
281
+ nftTransfers: nftTransfers.length > 0 ? nftTransfers : undefined,
282
+ };
283
+ }
284
+ /**
285
+ * Determines the transaction type
286
+ */
287
+ function determineTransactionType(tx, receipt) {
288
+ // Contract creation
289
+ if (!tx.to)
290
+ return constant_1.TRANSACTION_TYPE.CONTRACT_CREATION;
291
+ // Check if it's a token/NFT transfer based on method signature
292
+ const methodSig = tx.input?.slice(0, 10);
293
+ if (methodSig === '0xa9059cbb')
294
+ return constant_1.TRANSACTION_TYPE.TOKEN_TRANSFER; // ERC20 transfer
295
+ if (methodSig === '0x23b872dd')
296
+ return constant_1.TRANSACTION_TYPE.TOKEN_TRANSFER; // ERC20 transferFrom
297
+ if (methodSig === '0x42842e0e')
298
+ return constant_1.TRANSACTION_TYPE.NFT_TRANSFER; // ERC721 safeTransferFrom
299
+ if (methodSig === '0xf242432a')
300
+ return constant_1.TRANSACTION_TYPE.NFT_TRANSFER; // ERC1155 safeTransferFrom
301
+ // Check value
302
+ if (tx.value && tx.value > 0n)
303
+ return constant_1.TRANSACTION_TYPE.NATIVE_TRANSFER;
304
+ // Check logs for common patterns
305
+ if (receipt.logs.some(log => log.topics[0]?.includes('Swap')))
306
+ return constant_1.TRANSACTION_TYPE.SWAP;
307
+ if (receipt.logs.some(log => log.topics[0]?.includes('Deposit')))
308
+ return constant_1.TRANSACTION_TYPE.DEPOSIT;
309
+ if (receipt.logs.some(log => log.topics[0]?.includes('Withdraw')))
310
+ return constant_1.TRANSACTION_TYPE.WITHDRAWAL;
311
+ return constant_1.TRANSACTION_TYPE.CONTRACT_INTERACTION;
312
+ }
313
+ /**
314
+ * Parses transfer events from transaction logs
315
+ */
316
+ async function parseTransferLogs(client, logs, walletAddress, includeTokenTransfers, includeNFTTransfers) {
317
+ const tokens = [];
318
+ const nfts = [];
319
+ for (const log of logs) {
320
+ try {
321
+ // Try ERC20 Transfer
322
+ if (includeTokenTransfers && log.topics.length === 3) {
323
+ try {
324
+ const decoded = (0, viem_1.decodeEventLog)({
325
+ abi: ERC20_TRANSFER_EVENT,
326
+ data: log.data,
327
+ topics: log.topics,
328
+ });
329
+ if (decoded.eventName === 'Transfer') {
330
+ const { from, to, value } = decoded.args;
331
+ // Only include if wallet is involved
332
+ if (from.toLowerCase() === walletAddress.toLowerCase() ||
333
+ to.toLowerCase() === walletAddress.toLowerCase()) {
334
+ // Try to get token info (this might fail for non-standard tokens)
335
+ let decimals = 18;
336
+ try {
337
+ decimals = await client.readContract({
338
+ address: log.address,
339
+ abi: (0, viem_1.parseAbi)(['function decimals() view returns (uint8)']),
340
+ functionName: 'decimals',
341
+ });
342
+ }
343
+ catch { }
344
+ tokens.push({
345
+ type: 'ERC20',
346
+ from,
347
+ to,
348
+ amount: (0, viem_1.formatUnits)(value, decimals),
349
+ tokenAddress: log.address,
350
+ tokenDecimals: decimals,
351
+ });
352
+ }
353
+ }
354
+ }
355
+ catch { }
356
+ }
357
+ // Try ERC721 Transfer (has indexed tokenId)
358
+ if (includeNFTTransfers && log.topics.length === 4) {
359
+ try {
360
+ const decoded = (0, viem_1.decodeEventLog)({
361
+ abi: ERC721_TRANSFER_EVENT,
362
+ data: log.data,
363
+ topics: log.topics,
364
+ });
365
+ if (decoded.eventName === 'Transfer') {
366
+ const { from, to, tokenId } = decoded.args;
367
+ if (from.toLowerCase() === walletAddress.toLowerCase() ||
368
+ to.toLowerCase() === walletAddress.toLowerCase()) {
369
+ nfts.push({
370
+ type: 'ERC721',
371
+ from,
372
+ to,
373
+ tokenId: tokenId.toString(),
374
+ tokenAddress: log.address,
375
+ });
376
+ }
377
+ }
378
+ }
379
+ catch { }
380
+ }
381
+ // Try ERC1155 TransferSingle
382
+ if (includeNFTTransfers) {
383
+ try {
384
+ const decoded = (0, viem_1.decodeEventLog)({
385
+ abi: ERC1155_TRANSFER_SINGLE_EVENT,
386
+ data: log.data,
387
+ topics: log.topics,
388
+ });
389
+ if (decoded.eventName === 'TransferSingle') {
390
+ const { from, to, id, value } = decoded.args;
391
+ if (from.toLowerCase() === walletAddress.toLowerCase() ||
392
+ to.toLowerCase() === walletAddress.toLowerCase()) {
393
+ nfts.push({
394
+ type: 'ERC1155',
395
+ from,
396
+ to,
397
+ tokenId: id.toString(),
398
+ amount: value.toString(),
399
+ tokenAddress: log.address,
400
+ });
401
+ }
402
+ }
403
+ }
404
+ catch { }
405
+ }
406
+ }
407
+ catch (error) {
408
+ // Skip logs that don't match our patterns
409
+ continue;
410
+ }
411
+ }
412
+ return { tokens, nfts };
413
+ }
414
+ //# sourceMappingURL=transactionParsing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactionParsing.js","sourceRoot":"","sources":["../../utils/evm/transactionParsing.ts"],"names":[],"mappings":";;AAyFA,4DA+DC;AA4FD,0EAmDC;AAvSD,+BAYc;AACd,0CAAgE;AAiDhE,iCAAiC;AACjC,MAAM,oBAAoB,GAAG,IAAA,eAAQ,EAAC;IAClC,yEAAyE;CAC5E,CAAC,CAA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AC;oBACL,CAAC;gBACL,CAAC;gBAAC,MAAM,CAAC,CAAC,CAAC;YACf,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,0CAA0C;YAC1C,SAAS;QACb,CAAC;IACL,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC"}
@@ -1,5 +1,6 @@
1
- import { Balance, TokenInfo } from '../types';
1
+ import { Balance, ChainWalletConfig, UserTokenBalance, TokenInfo } from '../types';
2
2
  import { JsonRpcProvider, Wallet, TransactionReceipt } from 'ethers';
3
+ import BigNumber from 'bignumber.js';
3
4
  export interface TransactionParams {
4
5
  to: string;
5
6
  value?: string | bigint;
@@ -186,6 +187,15 @@ export declare const safeApprove: (wallet: Wallet, tokenAddress: string, spender
186
187
  resetResult: TransactionResult;
187
188
  approveResult: TransactionResult;
188
189
  }>;
190
+ export declare const discoverTokens: (wallet: string, chain: ChainWalletConfig) => Promise<UserTokenBalance<string>[]>;
191
+ export declare function calcGasTotal(gasLimit?: string, gasPrice?: string): string;
192
+ export declare function toPrecisionWithoutTrailingZeros(n: number, precision: number): string;
193
+ /**
194
+ * @param {number|string|BigNumber} value
195
+ * @param {number=} decimals
196
+ * @returns {BigNumber}
197
+ */
198
+ export declare function calcTokenAmount(value: number | string | BigNumber, decimals?: number): BigNumber;
189
199
  export declare function getKyberSwapRoute(params: KyberSwapParams): Promise<KyberSwapResponse>;
190
200
  export declare function buildKyberSwapTransaction(chainId: string, routeSummary: KyberRoute, sender: string, recipient: string, slippageTolerance?: number, deadline?: number, clientId?: string): Promise<KyberBuildResponse>;
191
201
  export declare function performSwap(params: {
@@ -216,13 +226,5 @@ export declare function prepareSwapParams(tokenIn: string, tokenOut: string, amo
216
226
  tokenOutAddress: string;
217
227
  formattedAmountIn: string;
218
228
  };
219
- /**
220
- * Normalize token address for Debonk
221
- * Converts 'native' or variations to the standard 0xEeeee... address
222
- */
223
- /**
224
- * Convert slippage from basis points to percentage for Debonk
225
- * Input: 50 (0.5% in bps) -> Output: 0.5 (percentage)
226
- */
227
229
  export declare function convertSlippageForDebonk(slippageBps: number): number;
228
230
  export {};
package/dist/evm/utils.js CHANGED
@@ -3,7 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.safeApprove = exports.resetAllowance = exports.checkAndApprove = exports.approveTokenUnlimited = exports.approveToken = exports.isAllowanceSufficient = exports.checkAllowance = exports.estimateGas = exports.getGasPrices = exports.executeContractMethod = exports.sendERC20Token = exports.sendNativeToken = exports.signSendAndConfirm = exports.getTokenBalance = exports.getTokenInfo = exports.getNativeBalance = exports.DESERIALIZED_SUPPORTED_CHAINS = void 0;
6
+ exports.discoverTokens = exports.safeApprove = exports.resetAllowance = exports.checkAndApprove = exports.approveTokenUnlimited = exports.approveToken = exports.isAllowanceSufficient = exports.checkAllowance = exports.estimateGas = exports.getGasPrices = exports.executeContractMethod = exports.sendERC20Token = exports.sendNativeToken = exports.signSendAndConfirm = exports.getTokenBalance = exports.getTokenInfo = exports.getNativeBalance = exports.DESERIALIZED_SUPPORTED_CHAINS = void 0;
7
+ exports.calcGasTotal = calcGasTotal;
8
+ exports.toPrecisionWithoutTrailingZeros = toPrecisionWithoutTrailingZeros;
9
+ exports.calcTokenAmount = calcTokenAmount;
7
10
  exports.getKyberSwapRoute = getKyberSwapRoute;
8
11
  exports.buildKyberSwapTransaction = buildKyberSwapTransaction;
9
12
  exports.performSwap = performSwap;
@@ -17,6 +20,8 @@ exports.prepareSwapParams = prepareSwapParams;
17
20
  exports.convertSlippageForDebonk = convertSlippageForDebonk;
18
21
  const ethers_1 = require("ethers");
19
22
  const bn_js_1 = __importDefault(require("bn.js"));
23
+ const helpers_1 = require("../helpers");
24
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
20
25
  const KYBER_BASE_URL = 'https://aggregator-api.kyberswap.com';
21
26
  const KYBER_SUPPORTED_CHAINS = {
22
27
  '1': 'ethereum',
@@ -46,9 +51,10 @@ const ERC20_ABI = [
46
51
  ];
47
52
  const getNativeBalance = async (address, provider) => {
48
53
  const balance = await provider.getBalance(address);
54
+ const final = ethers_1.ethers.formatEther(balance);
49
55
  return {
50
56
  balance: new bn_js_1.default(balance),
51
- formatted: Number(balance / 10n ** 18n),
57
+ formatted: Number(final),
52
58
  decimal: 18
53
59
  };
54
60
  };
@@ -393,6 +399,38 @@ const safeApprove = async (wallet, tokenAddress, spender, amount, gasLimit, conf
393
399
  }
394
400
  };
395
401
  exports.safeApprove = safeApprove;
402
+ const discoverTokens = async (wallet, chain) => {
403
+ const balances = await helpers_1.HelperAPI.getUserToken(wallet, chain.vmType ?? "EVM", chain.chainId);
404
+ const formatBalances = balances.data.map((token) => {
405
+ return {
406
+ address: token.contractAddress,
407
+ name: token.name,
408
+ symbol: token.symbol,
409
+ decimals: token.decimals,
410
+ balance: token.balance,
411
+ owner: wallet
412
+ };
413
+ });
414
+ return formatBalances;
415
+ };
416
+ exports.discoverTokens = discoverTokens;
417
+ function calcGasTotal(gasLimit = '0', gasPrice = '0') {
418
+ return new bn_js_1.default(gasLimit, 16).mul(new bn_js_1.default(gasPrice, 16)).toString();
419
+ }
420
+ function toPrecisionWithoutTrailingZeros(n, precision) {
421
+ return new bignumber_js_1.default(n)
422
+ .toPrecision(precision)
423
+ .replace(/(\.[0-9]*[1-9])0*|(\.0*)/u, '$1');
424
+ }
425
+ /**
426
+ * @param {number|string|BigNumber} value
427
+ * @param {number=} decimals
428
+ * @returns {BigNumber}
429
+ */
430
+ function calcTokenAmount(value, decimals) {
431
+ const divisor = new bignumber_js_1.default(10).pow(decimals ?? 0);
432
+ return new bignumber_js_1.default(String(value)).div(divisor);
433
+ }
396
434
  //swaps
397
435
  //kyber swap here
398
436
  //docs -. https://docs.kyberswap.com/kyberswap-solutions/kyberswap-aggregator/developer-guides/execute-a-swap-with-the-aggregator-api
@@ -569,14 +607,10 @@ function getNativeTokenAddress() {
569
607
  return '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
570
608
  }
571
609
  function formatAmountToWei(amount, decimals) {
572
- const amountBN = new bn_js_1.default(amount);
573
- const multiplier = new bn_js_1.default(10).pow(new bn_js_1.default(decimals));
574
- return amountBN.mul(multiplier).toString();
610
+ return (0, ethers_1.parseUnits)(amount, decimals).toString();
575
611
  }
576
612
  function formatAmountFromWei(amountWei, decimals) {
577
- const amountBN = new bn_js_1.default(amountWei);
578
- const divisor = new bn_js_1.default(10).pow(new bn_js_1.default(decimals));
579
- return amountBN.div(divisor).toString();
613
+ return (0, ethers_1.formatUnits)(amountWei, decimals);
580
614
  }
581
615
  function prepareSwapParams(tokenIn, tokenOut, amountIn, tokenInDecimals, isNativeIn = false, isNativeOut = false) {
582
616
  const tokenInAddress = isNativeIn ? getNativeTokenAddress() : tokenIn;
@@ -590,21 +624,6 @@ function prepareSwapParams(tokenIn, tokenOut, amountIn, tokenInDecimals, isNativ
590
624
  formattedAmountIn
591
625
  };
592
626
  }
593
- /**
594
- * Normalize token address for Debonk
595
- * Converts 'native' or variations to the standard 0xEeeee... address
596
- */
597
- // export function normalizeTokenAddressForDebonk(tokenAddress: string): string {
598
- // if (tokenAddress === 'native' ||
599
- // tokenAddress.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
600
- // return getNativeTokenAddress();
601
- // }
602
- // return tokenAddress;
603
- // }
604
- /**
605
- * Convert slippage from basis points to percentage for Debonk
606
- * Input: 50 (0.5% in bps) -> Output: 0.5 (percentage)
607
- */
608
627
  function convertSlippageForDebonk(slippageBps) {
609
628
  return slippageBps / 100;
610
629
  }