@deserialize/multi-vm-wallet 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bip32Old.d.ts +0 -51
- package/dist/bip32Old.js +876 -845
- package/dist/bip32Old.js.map +1 -1
- package/dist/bip32Small.d.ts +0 -9
- package/dist/bip32Small.js +78 -113
- package/dist/bip32Small.js.map +1 -1
- package/dist/constant.d.ts +16 -0
- package/dist/constant.js +19 -3
- package/dist/constant.js.map +1 -1
- package/dist/english.d.ts +1 -0
- package/dist/english.js +2052 -0
- package/dist/english.js.map +1 -0
- package/dist/evm/evm.d.ts +6 -1
- package/dist/evm/evm.js +36 -45
- package/dist/evm/evm.js.map +1 -1
- package/dist/evm/transactionParsing.d.ts +3687 -0
- package/dist/evm/transactionParsing.js +441 -0
- package/dist/evm/transactionParsing.js.map +1 -0
- package/dist/evm/utils.d.ts +2 -9
- package/dist/evm/utils.js +19 -22
- package/dist/evm/utils.js.map +1 -1
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +13 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/svm/constant.d.ts +15 -0
- package/dist/svm/constant.js +25 -0
- package/dist/svm/constant.js.map +1 -0
- package/dist/svm/svm.d.ts +5 -2
- package/dist/svm/svm.js +10 -0
- package/dist/svm/svm.js.map +1 -1
- package/dist/svm/transactionParsing.d.ts +28 -0
- package/dist/svm/transactionParsing.js +207 -0
- package/dist/svm/transactionParsing.js.map +1 -0
- package/dist/svm/utils.d.ts +4 -3
- package/dist/svm/utils.js +83 -10
- package/dist/svm/utils.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +47 -9
- package/dist/test.js.map +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.js.map +1 -1
- package/dist/walletBip32.js +1 -1
- package/dist/walletBip32.js.map +1 -1
- package/package.json +4 -2
- package/utils/IChainWallet.ts +1 -1
- package/utils/bip32Old.ts +988 -988
- package/utils/bip32Small.ts +78 -78
- package/utils/constant.ts +22 -4
- package/utils/english.ts +2048 -0
- package/utils/evm/evm.ts +54 -48
- package/utils/evm/transactionParsing.ts +639 -0
- package/utils/evm/utils.ts +29 -33
- package/utils/helpers/index.ts +11 -0
- package/utils/svm/constant.ts +29 -0
- package/utils/svm/svm.ts +14 -2
- package/utils/svm/transactionParsing.ts +294 -0
- package/utils/svm/utils.ts +105 -14
- package/utils/test.ts +56 -6
- package/utils/types.ts +6 -1
- package/utils/walletBip32.ts +1 -1
package/utils/evm/evm.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { EVMDeriveChildPrivateKey } from "../walletBip32";
|
|
8
8
|
import { ChainWallet } from "../IChainWallet";
|
|
9
|
-
import { Balance, ChainWalletConfig, NFTInfo, TokenInfo, TransactionResult } from "../types";
|
|
9
|
+
import { Balance, ChainWalletConfig, NFTInfo, UserTokenBalance, TokenInfo, TransactionResult } from "../types";
|
|
10
10
|
import { VM } from "../vm";
|
|
11
11
|
import { ethers, JsonRpcProvider, Wallet, formatUnits } from "ethers";
|
|
12
12
|
import BN from "bn.js";
|
|
@@ -29,8 +29,11 @@ import {
|
|
|
29
29
|
approveToken,
|
|
30
30
|
executeContractMethod,
|
|
31
31
|
getTokenInfo,
|
|
32
|
-
DESERIALIZED_SUPPORTED_CHAINS
|
|
32
|
+
DESERIALIZED_SUPPORTED_CHAINS,
|
|
33
|
+
discoverTokens
|
|
33
34
|
} from "./utils";
|
|
35
|
+
import { EVMTransactionHistoryItem, getEVMTransactionHistory } from "./transactionParsing";
|
|
36
|
+
import { createPublicClient, Hex, http, PublicClient } from "viem";
|
|
34
37
|
|
|
35
38
|
interface DebonkQuoteResponse {
|
|
36
39
|
tokenA: string;
|
|
@@ -110,12 +113,45 @@ export class EVMVM extends VM<string, string, JsonRpcProvider> {
|
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider> {
|
|
116
|
+
client: PublicClient
|
|
113
117
|
constructor(config: ChainWalletConfig, privateKey: string, index: number) {
|
|
114
118
|
super(config, privateKey, index);
|
|
115
119
|
const wallet = new Wallet(privateKey);
|
|
116
120
|
this.address = wallet.address;
|
|
117
121
|
this.privateKey = privateKey;
|
|
118
122
|
this.connection = new JsonRpcProvider(config.rpcUrl)
|
|
123
|
+
|
|
124
|
+
//client for viem
|
|
125
|
+
this.client = createPublicClient(
|
|
126
|
+
{
|
|
127
|
+
chain: {
|
|
128
|
+
rpcUrls: {
|
|
129
|
+
default: {
|
|
130
|
+
http: [config.rpcUrl]
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
id: config.chainId,
|
|
134
|
+
name: config.name,
|
|
135
|
+
nativeCurrency: {
|
|
136
|
+
name: config.nativeToken.name,
|
|
137
|
+
symbol: config.nativeToken.symbol,
|
|
138
|
+
decimals: config.nativeToken.decimals
|
|
139
|
+
},
|
|
140
|
+
blockExplorers: {
|
|
141
|
+
default: {
|
|
142
|
+
name: config.name + " Explorer",
|
|
143
|
+
url: config.explorerUrl,
|
|
144
|
+
apiUrl: config.explorerUrl
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
},
|
|
148
|
+
testnet: config.testnet || false
|
|
149
|
+
|
|
150
|
+
},
|
|
151
|
+
transport: http(config.rpcUrl)
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
)
|
|
119
155
|
}
|
|
120
156
|
|
|
121
157
|
getWallet(): Wallet {
|
|
@@ -136,6 +172,11 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
136
172
|
return await EVMVM.getTokenBalance(this.address, tokenAddress, this.connection!)
|
|
137
173
|
}
|
|
138
174
|
|
|
175
|
+
async discoverToken(): Promise<UserTokenBalance<string>[]> {
|
|
176
|
+
// Implement token discovery logic here
|
|
177
|
+
return await discoverTokens(this.address, this.config)
|
|
178
|
+
}
|
|
179
|
+
|
|
139
180
|
async transferNative(to: string, amount: number): Promise<TransactionResult> {
|
|
140
181
|
// Implement native transfer logic here
|
|
141
182
|
const wallet = this.getWallet()
|
|
@@ -148,6 +189,11 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
148
189
|
return await sendERC20Token(wallet, tokenAddress.address, to, amount.toString(), undefined, this.config.confirmationNo || 5)
|
|
149
190
|
}
|
|
150
191
|
|
|
192
|
+
async getTransactionHistory(): Promise<EVMTransactionHistoryItem[]> {
|
|
193
|
+
const wallet = this.getWallet();
|
|
194
|
+
return await getEVMTransactionHistory(this.client, wallet.address as Hex);
|
|
195
|
+
}
|
|
196
|
+
|
|
151
197
|
// Updated swap method signature to match base class so created another method to use it inside swap
|
|
152
198
|
async swap(
|
|
153
199
|
tokenAddress: TokenInfo,
|
|
@@ -222,20 +268,12 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
222
268
|
|
|
223
269
|
// Convert amount to wei (multiply by 10^18 for 18 decimal tokens)
|
|
224
270
|
const amountInWei = (amount * Math.pow(10, tokenIn.decimals || 18)).toString();
|
|
225
|
-
|
|
271
|
+
|
|
226
272
|
// Convert slippage from bps to percentage (e.g., 50 bps -> 0.5%)
|
|
227
273
|
const slippagePercentage = slippage / 100;
|
|
228
274
|
|
|
229
|
-
console.log("Debonk API swap params:", {
|
|
230
|
-
tokenA: tokenInAddress,
|
|
231
|
-
tokenB: tokenOutAddress,
|
|
232
|
-
amountIn: amount,
|
|
233
|
-
amountInWei: amountInWei,
|
|
234
|
-
slippage: slippagePercentage,
|
|
235
|
-
});
|
|
236
275
|
|
|
237
276
|
// Step 1: Get quote from API
|
|
238
|
-
console.log("Getting quote from Debonk API...");
|
|
239
277
|
|
|
240
278
|
const quotePayload = {
|
|
241
279
|
tokenA: tokenInAddress,
|
|
@@ -244,7 +282,6 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
244
282
|
dexId: "ZERO_G"
|
|
245
283
|
};
|
|
246
284
|
|
|
247
|
-
console.log("Quote request payload:", quotePayload);
|
|
248
285
|
|
|
249
286
|
const quoteResponse = await fetch(`${BASE_URL}/quote`, {
|
|
250
287
|
method: 'POST',
|
|
@@ -261,7 +298,6 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
261
298
|
}
|
|
262
299
|
|
|
263
300
|
const quote: DebonkQuoteResponse = await quoteResponse.json();
|
|
264
|
-
console.log("Quote received:", JSON.stringify(quote, null, 2));
|
|
265
301
|
|
|
266
302
|
// Step 2: Fix the quote dexId for swap API (it expects "ALL")
|
|
267
303
|
const modifiedQuote = {
|
|
@@ -269,22 +305,16 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
269
305
|
dexId: "ALL" // Change from "ZERO_G" to "ALL" as required by swap API
|
|
270
306
|
};
|
|
271
307
|
|
|
272
|
-
console.log("Modified quote for swap API:", JSON.stringify(modifiedQuote, null, 2));
|
|
273
|
-
|
|
274
308
|
// Step 3: Get wallet address
|
|
275
309
|
const walletAddress = await this.getWallet().getAddress();
|
|
276
|
-
console.log("Wallet address:", walletAddress);
|
|
277
|
-
|
|
278
|
-
// Step 4: Call swap API with modified quote
|
|
279
|
-
console.log("Calling swap API...");
|
|
280
310
|
|
|
281
311
|
const swapPayload = {
|
|
282
312
|
publicKey: walletAddress,
|
|
283
313
|
slippage: slippagePercentage,
|
|
284
314
|
quote: modifiedQuote
|
|
315
|
+
|
|
285
316
|
};
|
|
286
317
|
|
|
287
|
-
console.log("Swap request payload:", JSON.stringify(swapPayload, null, 2));
|
|
288
318
|
|
|
289
319
|
const swapResponse = await fetch(`${BASE_URL}/swap`, {
|
|
290
320
|
method: 'POST',
|
|
@@ -301,17 +331,14 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
301
331
|
}
|
|
302
332
|
|
|
303
333
|
const swapData: DebonkSwapResponse = await swapResponse.json();
|
|
304
|
-
console.log("Swap API response:", JSON.stringify(swapData, null, 2));
|
|
305
334
|
|
|
306
335
|
const wallet = this.getWallet();
|
|
307
336
|
let lastTxHash = '';
|
|
308
337
|
|
|
309
338
|
// Step 5: Execute each transaction sequentially
|
|
310
|
-
console.log(`Executing ${swapData.transactions.length} transactions...`);
|
|
311
339
|
|
|
312
340
|
for (let i = 0; i < swapData.transactions.length; i++) {
|
|
313
341
|
const transaction = swapData.transactions[i];
|
|
314
|
-
console.log(`Executing transaction ${i + 1} of ${swapData.transactions.length}`);
|
|
315
342
|
|
|
316
343
|
// Prepare transaction object
|
|
317
344
|
const txRequest = {
|
|
@@ -321,8 +348,6 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
321
348
|
// gasPrice: 70000000000,
|
|
322
349
|
// gasLimit: 70000, // Increase significantly
|
|
323
350
|
};
|
|
324
|
-
console.log("Prepared transaction request:", txRequest);
|
|
325
|
-
console.log(`Transaction ${i + 1} request:`, txRequest);
|
|
326
351
|
|
|
327
352
|
try {
|
|
328
353
|
const txResponse = await wallet.sendTransaction(txRequest);
|
|
@@ -338,11 +363,6 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
338
363
|
const txHash = receipt.hash || txResponse.hash;
|
|
339
364
|
lastTxHash = txHash;
|
|
340
365
|
|
|
341
|
-
console.log(`Transaction ${i + 1} confirmed:`, {
|
|
342
|
-
hash: txHash,
|
|
343
|
-
blockNumber: receipt.blockNumber,
|
|
344
|
-
gasUsed: receipt.gasUsed?.toString()
|
|
345
|
-
});
|
|
346
366
|
|
|
347
367
|
} catch (txError: any) {
|
|
348
368
|
console.error(`Transaction ${i + 1} failed:`, txError);
|
|
@@ -350,7 +370,7 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
350
370
|
}
|
|
351
371
|
}
|
|
352
372
|
|
|
353
|
-
|
|
373
|
+
|
|
354
374
|
|
|
355
375
|
return {
|
|
356
376
|
success: true,
|
|
@@ -411,12 +431,7 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
411
431
|
isNativeOut
|
|
412
432
|
);
|
|
413
433
|
|
|
414
|
-
|
|
415
|
-
tokenInAddress,
|
|
416
|
-
tokenOutAddress,
|
|
417
|
-
formattedAmountIn,
|
|
418
|
-
tokenInDecimals
|
|
419
|
-
});
|
|
434
|
+
|
|
420
435
|
|
|
421
436
|
if (isNativeIn) {
|
|
422
437
|
const nativeBalance = await this.getNativeBalance();
|
|
@@ -452,7 +467,7 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
452
467
|
});
|
|
453
468
|
|
|
454
469
|
if (!isNativeIn) {
|
|
455
|
-
|
|
470
|
+
|
|
456
471
|
const approvalResult = await checkAndApprove(
|
|
457
472
|
wallet,
|
|
458
473
|
tokenIn.address,
|
|
@@ -486,20 +501,11 @@ export class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider>
|
|
|
486
501
|
this.config.confirmationNo || 1,
|
|
487
502
|
);
|
|
488
503
|
|
|
489
|
-
if (result.success) {
|
|
490
|
-
console.log(' Kyber swap completed successfully:', {
|
|
491
|
-
hash: result.hash,
|
|
492
|
-
gasUsed: result.gasUsed?.toString(),
|
|
493
|
-
blockNumber: result.blockNumber
|
|
494
|
-
});
|
|
495
|
-
} else {
|
|
496
|
-
console.log(' Kyber swap failed:', result);
|
|
497
|
-
}
|
|
498
504
|
|
|
499
505
|
return result;
|
|
500
506
|
|
|
501
507
|
} catch (error) {
|
|
502
|
-
|
|
508
|
+
|
|
503
509
|
throw new Error(`Kyber swap failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
504
510
|
}
|
|
505
511
|
}
|