@deserialize/multi-vm-wallet 1.0.372 → 1.1.1

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 (79) hide show
  1. package/dist/bip32.d.ts +1 -3
  2. package/dist/bip32.js +103 -33
  3. package/dist/bip32.js.map +1 -1
  4. package/dist/bip32Old.d.ts +51 -0
  5. package/dist/bip32Old.js +856 -0
  6. package/dist/bip32Old.js.map +1 -0
  7. package/dist/{utils/bip32.d.ts → bip32Small.d.ts} +1 -3
  8. package/dist/bip32Small.js +115 -0
  9. package/dist/bip32Small.js.map +1 -0
  10. package/dist/bipTest.d.ts +0 -0
  11. package/dist/bipTest.js +363 -0
  12. package/dist/bipTest.js.map +1 -0
  13. package/dist/constant.d.ts +2 -0
  14. package/dist/constant.js +55 -0
  15. package/dist/constant.js.map +1 -0
  16. package/dist/evm/evm.d.ts +1 -0
  17. package/dist/evm/evm.js +1 -0
  18. package/dist/evm/evm.js.map +1 -1
  19. package/dist/evm/utils.d.ts +2 -1
  20. package/dist/evm/utils.js +24 -1
  21. package/dist/evm/utils.js.map +1 -1
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.js +2 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/svm/svm.d.ts +1 -0
  26. package/dist/svm/svm.js +12 -8
  27. package/dist/svm/svm.js.map +1 -1
  28. package/dist/svm/transactionSender.js +6 -2
  29. package/dist/svm/transactionSender.js.map +1 -1
  30. package/dist/svm/utils.d.ts +1 -0
  31. package/dist/svm/utils.js +25 -33
  32. package/dist/svm/utils.js.map +1 -1
  33. package/dist/test.d.ts +2 -0
  34. package/dist/test.js +42 -0
  35. package/dist/test.js.map +1 -0
  36. package/dist/types.d.ts +2 -0
  37. package/dist/types.js.map +1 -1
  38. package/dist/vm.d.ts +2 -1
  39. package/dist/vm.js +2 -2
  40. package/dist/vm.js.map +1 -1
  41. package/package.json +2 -5
  42. package/utils/bip32.ts +124 -35
  43. package/utils/bip32Old.ts +1004 -0
  44. package/utils/bip32Small.ts +91 -0
  45. package/utils/bipTest.ts +442 -0
  46. package/utils/constant.ts +55 -0
  47. package/utils/evm/evm.ts +4 -3
  48. package/utils/evm/utils.ts +29 -1
  49. package/utils/index.ts +3 -2
  50. package/utils/svm/svm.ts +14 -12
  51. package/utils/svm/transactionSender.ts +7 -2
  52. package/utils/svm/utils.ts +33 -33
  53. package/utils/test.ts +49 -0
  54. package/utils/types.ts +2 -0
  55. package/utils/vm.ts +4 -3
  56. package/dist/tsconfig.tsbuildinfo +0 -1
  57. package/dist/utils/IChainWallet.d.ts +0 -17
  58. package/dist/utils/IChainWallet.js +0 -22
  59. package/dist/utils/bip32.js +0 -99
  60. package/dist/utils/evm/evm.d.ts +0 -39
  61. package/dist/utils/evm/evm.js +0 -233
  62. package/dist/utils/evm/index.d.ts +0 -2
  63. package/dist/utils/evm/index.js +0 -18
  64. package/dist/utils/evm/utils.d.ts +0 -207
  65. package/dist/utils/evm/utils.js +0 -537
  66. package/dist/utils/index.d.ts +0 -7
  67. package/dist/utils/index.js +0 -23
  68. package/dist/utils/svm/index.d.ts +0 -1
  69. package/dist/utils/svm/index.js +0 -17
  70. package/dist/utils/svm/svm.d.ts +0 -36
  71. package/dist/utils/svm/svm.js +0 -166
  72. package/dist/utils/svm/transactionSender.d.ts +0 -8
  73. package/dist/utils/svm/transactionSender.js +0 -83
  74. package/dist/utils/svm/utils.d.ts +0 -85
  75. package/dist/utils/svm/utils.js +0 -304
  76. package/dist/utils/types.d.ts +0 -44
  77. package/dist/utils/types.js +0 -9
  78. package/dist/utils/vm.d.ts +0 -12
  79. package/dist/utils/vm.js +0 -48
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChainWallet = void 0;
4
- class ChainWallet {
5
- constructor(config, privateKey, index) {
6
- this.config = config;
7
- this.privateKey = privateKey;
8
- this.address = this.generateAddress(privateKey);
9
- this.index = index;
10
- }
11
- // abstract transferNFT(contractAddress: AddressType, tokenId: string, to: string): Promise<TransactionResult>;
12
- // abstract getTokenInfo(tokenAddress: string): Promise<TokenInfo>;
13
- // abstract getNFTInfo(contractAddress: string, tokenId: string): Promise<NFTInfo>;
14
- // abstract getTransactionHistory(): Promise<any[]>;
15
- getAddress() {
16
- return this.address;
17
- }
18
- getChainWalletConfig() {
19
- return this.config;
20
- }
21
- }
22
- exports.ChainWallet = ChainWallet;
@@ -1,99 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.GenerateNewMnemonic = GenerateNewMnemonic;
40
- exports.ValidateMnemonic = ValidateMnemonic;
41
- exports.GenerateSeed = GenerateSeed;
42
- exports.getSeedNode = getSeedNode;
43
- exports.EVMDeriveChildPrivateKey = EVMDeriveChildPrivateKey;
44
- exports.SVMDeriveChildPrivateKey = SVMDeriveChildPrivateKey;
45
- const bip39 = __importStar(require("bip39"));
46
- const bip32_1 = __importDefault(require("bip32"));
47
- const ecc = __importStar(require("tiny-secp256k1"));
48
- const ed25519 = __importStar(require("ed25519-hd-key"));
49
- const web3_js_1 = require("@solana/web3.js");
50
- const bip32 = (0, bip32_1.default)(ecc);
51
- // export function getPublicKeyFromSeed(seed: string, index: number) {
52
- // const node = getSeedNode(seed);
53
- // const { publicKey } = deriveChildPrivateKey(node, index);
54
- // return publicKey;
55
- // }
56
- // export function getPrivateKeyFromSeed(seed: string, index: number) {
57
- // const node = getSeedNode(seed);
58
- // const keyPair = deriveChildPrivateKey(node, index);
59
- // return keyPair.privateKey;
60
- // }
61
- function GenerateNewMnemonic() {
62
- const mnemonic = bip39.generateMnemonic();
63
- return mnemonic;
64
- }
65
- function ValidateMnemonic(mnemonic) {
66
- const isValid = bip39.validateMnemonic(mnemonic);
67
- if (!isValid) {
68
- throw new Error("Invalid mnemonic");
69
- }
70
- return isValid;
71
- }
72
- function GenerateSeed(_mnemonic) {
73
- const mnemonic = _mnemonic || bip39.generateMnemonic();
74
- const seed = bip39.mnemonicToSeedSync(mnemonic);
75
- const seedString = seed.toString("hex");
76
- return seedString;
77
- }
78
- function getSeedNode(seed) {
79
- const bip32 = (0, bip32_1.default)(ecc);
80
- const restoredSeedBuffer = Buffer.from(seed, "hex");
81
- const node = bip32.fromSeed(restoredSeedBuffer);
82
- return node;
83
- }
84
- //EVM
85
- function EVMDeriveChildPrivateKey(seed, index, derivationPath) {
86
- const node = getSeedNode(seed);
87
- const child = node.derivePath(`${derivationPath}${index}'`);
88
- const privateKey = child.privateKey.toString("hex");
89
- const publicKey = child.publicKey.toString("hex");
90
- return { privateKey, publicKey };
91
- }
92
- //SVM
93
- function SVMDeriveChildPrivateKey(seed, index, derivationPath) {
94
- const path = `${derivationPath}${index}'`;
95
- // Derive a seed from the given path
96
- const derivedSeed = ed25519.derivePath(path, seed).key;
97
- const derivedKeyPair = web3_js_1.Keypair.fromSeed(derivedSeed);
98
- return derivedKeyPair;
99
- }
@@ -1,39 +0,0 @@
1
- /**
2
- *
3
- * @param phrase this is the pass phrase for this vm
4
- * this is a class that will be responsible for creating several evm wallets code
5
- */
6
- import { ChainWallet } from "../IChainWallet";
7
- import { Balance, ChainWalletConfig, TokenInfo, TransactionResult } from "../types";
8
- import { VM } from "../vm";
9
- import { JsonRpcProvider, Wallet } from "ethers";
10
- export declare const createEvmVmPrivateKey: (phrase: string) => void;
11
- export declare class EVMVM extends VM<string, string, JsonRpcProvider> {
12
- derivationPath: string;
13
- constructor(seed: string);
14
- generatePrivateKey(index: number, seed?: string, mnemonic?: string, derivationPath?: string): {
15
- privateKey: string;
16
- index: number;
17
- };
18
- static fromMnemonic(seed: string): VM<string, string, JsonRpcProvider>;
19
- validateAddress(address: string): boolean;
20
- static getNativeBalance(address: string, connection: JsonRpcProvider): Promise<Balance>;
21
- static getTokenBalance(address: string, tokenAddress: string, connection: JsonRpcProvider): Promise<Balance>;
22
- }
23
- export declare class EVMChainWallet extends ChainWallet<string, string, JsonRpcProvider> {
24
- constructor(config: ChainWalletConfig, privateKey: string, index: number);
25
- getWallet(): Wallet;
26
- generateAddress(): string;
27
- getNativeBalance(): Promise<Balance>;
28
- getTokenBalance(tokenAddress: string): Promise<Balance>;
29
- transferNative(to: string, amount: number): Promise<TransactionResult>;
30
- transferToken(tokenAddress: TokenInfo, to: string, amount: number): Promise<TransactionResult>;
31
- swap(tokenAddress: TokenInfo, to: string, amount: number, slippage?: number): Promise<TransactionResult>;
32
- performCompleteSwap(tokenIn: TokenInfo, tokenOut: TokenInfo, amount: number, slippage?: number, recipient?: string, deadline?: number): Promise<TransactionResult>;
33
- getSwapQuote(tokenIn: TokenInfo, tokenOut: TokenInfo, amount: number): Promise<{
34
- amountOut: string;
35
- priceImpact: string;
36
- gasEstimate: string;
37
- route: string[];
38
- }>;
39
- }
@@ -1,233 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.EVMChainWallet = exports.EVMVM = exports.createEvmVmPrivateKey = void 0;
12
- const bip32_1 = require("../bip32");
13
- const IChainWallet_1 = require("../IChainWallet");
14
- const vm_1 = require("../vm");
15
- const ethers_1 = require("ethers");
16
- const bn_js_1 = __importDefault(require("bn.js"));
17
- const utils_1 = require("./utils");
18
- const createEvmVmPrivateKey = (phrase) => { };
19
- exports.createEvmVmPrivateKey = createEvmVmPrivateKey;
20
- class EVMVM extends vm_1.VM {
21
- constructor(seed) {
22
- super(seed, "EVM");
23
- this.derivationPath = "m/44'/60'/0'/0/"; // Default EVM derivation path
24
- }
25
- generatePrivateKey(index, seed, mnemonic, derivationPath = this.derivationPath) {
26
- let _seed;
27
- if (seed) {
28
- _seed = seed;
29
- }
30
- else if (mnemonic) {
31
- _seed = vm_1.VM.mnemonicToSeed(mnemonic);
32
- }
33
- else {
34
- _seed = this.seed;
35
- }
36
- const privateKey = (0, bip32_1.EVMDeriveChildPrivateKey)(_seed, index, derivationPath).privateKey;
37
- return { privateKey, index };
38
- }
39
- static fromMnemonic(seed) {
40
- return new EVMVM(seed);
41
- }
42
- validateAddress(address) {
43
- return ethers_1.ethers.isAddress(address);
44
- }
45
- static async getNativeBalance(address, connection) {
46
- // Implement native balance retrieval logic here
47
- return await (0, utils_1.getNativeBalance)(address, connection);
48
- }
49
- static async getTokenBalance(address, tokenAddress, connection) {
50
- // Implement token balance retrieval logic here
51
- return await (0, utils_1.getTokenBalance)(tokenAddress, address, connection);
52
- }
53
- }
54
- exports.EVMVM = EVMVM;
55
- class EVMChainWallet extends IChainWallet_1.ChainWallet {
56
- constructor(config, privateKey, index) {
57
- super(config, privateKey, index);
58
- const wallet = new ethers_1.Wallet(privateKey);
59
- this.address = wallet.address;
60
- this.privateKey = privateKey;
61
- this.connection = new ethers_1.JsonRpcProvider(config.rpcUrl);
62
- }
63
- getWallet() {
64
- return new ethers_1.Wallet(this.privateKey, this.connection);
65
- }
66
- generateAddress() {
67
- return this.address;
68
- }
69
- async getNativeBalance() {
70
- // Implement native balance retrieval logic here
71
- return await EVMVM.getNativeBalance(this.address, this.connection);
72
- }
73
- async getTokenBalance(tokenAddress) {
74
- // Implement token balance retrieval logic here
75
- return await EVMVM.getTokenBalance(this.address, tokenAddress, this.connection);
76
- }
77
- async transferNative(to, amount) {
78
- // Implement native transfer logic here
79
- const wallet = this.getWallet();
80
- return await (0, utils_1.sendNativeToken)(wallet, to, amount.toString(), undefined, this.config.confirmationNo || 5);
81
- }
82
- async transferToken(tokenAddress, to, amount) {
83
- // Implement token transfer logic here
84
- const wallet = this.getWallet();
85
- return await (0, utils_1.sendERC20Token)(wallet, tokenAddress.address, to, amount.toString(), undefined, this.config.confirmationNo || 5);
86
- }
87
- // Updated swap method signature to match base class so created another method to use it inside swap
88
- async swap(tokenAddress, to, amount, slippage = 50) {
89
- if (amount <= 0) {
90
- return {
91
- success: false,
92
- hash: "",
93
- error: "Amount must be greater than 0"
94
- };
95
- }
96
- const tokenOut = {
97
- address: to,
98
- name: '',
99
- symbol: '',
100
- decimals: 18
101
- };
102
- return await this.performCompleteSwap(tokenAddress, tokenOut, amount, slippage);
103
- }
104
- async performCompleteSwap(tokenIn, tokenOut, amount, slippage = 50, recipient, deadline) {
105
- try {
106
- const wallet = this.getWallet();
107
- const chainId = (await this.connection.getNetwork()).chainId.toString();
108
- console.log(` Starting swap on chain ${chainId}:`, {
109
- from: tokenIn.symbol || tokenIn.address,
110
- to: tokenOut.symbol || tokenOut.address,
111
- amount: amount,
112
- slippage: `${slippage / 100}%`
113
- });
114
- if (!(0, utils_1.isChainSupportedByKyber)(chainId)) {
115
- throw new Error(`Chain ${chainId} is not supported by KyberSwap`);
116
- }
117
- const isNativeIn = tokenIn.address === 'native' ||
118
- tokenIn.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
119
- const isNativeOut = tokenOut.address === 'native' ||
120
- tokenOut.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
121
- let tokenInDecimals = 18;
122
- if (!isNativeIn && tokenIn.decimals) {
123
- tokenInDecimals = tokenIn.decimals;
124
- }
125
- else if (!isNativeIn) {
126
- const tokenBalance = await this.getTokenBalance(tokenIn.address);
127
- tokenInDecimals = tokenBalance.decimal;
128
- }
129
- const { tokenInAddress, tokenOutAddress, formattedAmountIn } = (0, utils_1.prepareSwapParams)(tokenIn.address, tokenOut.address, amount.toString(), tokenInDecimals, isNativeIn, isNativeOut);
130
- console.log('Swap parameters:', {
131
- tokenInAddress,
132
- tokenOutAddress,
133
- formattedAmountIn,
134
- tokenInDecimals
135
- });
136
- if (isNativeIn) {
137
- const nativeBalance = await this.getNativeBalance();
138
- const requiredAmount = new bn_js_1.default(formattedAmountIn);
139
- if (nativeBalance.balance.lt(requiredAmount)) {
140
- throw new Error(`Insufficient native balance. Required: ${amount}, Available: ${nativeBalance.formatted}`);
141
- }
142
- }
143
- else {
144
- const tokenBalance = await this.getTokenBalance(tokenIn.address);
145
- const requiredAmount = new bn_js_1.default(formattedAmountIn);
146
- if (tokenBalance.balance.lt(requiredAmount)) {
147
- throw new Error(`Insufficient token balance. Required: ${amount}, Available: ${tokenBalance.formatted}`);
148
- }
149
- }
150
- const swapTx = await (0, utils_1.performSwap)({
151
- chainId,
152
- tokenIn: tokenInAddress,
153
- tokenOut: tokenOutAddress,
154
- amountIn: formattedAmountIn,
155
- sender: this.address,
156
- recipient: recipient || this.address,
157
- slippageTolerance: slippage,
158
- deadline: deadline ? Math.floor(Date.now() / 1000) + deadline : Math.floor(Date.now() / 1000) + 1200, // 20 minutes default
159
- clientId: 'EVMChainWallet'
160
- });
161
- console.log('Swap transaction prepared:', {
162
- to: swapTx.to,
163
- dataLength: swapTx.data?.length || 0,
164
- gasLimit: swapTx.gasLimit?.toString(),
165
- value: swapTx.value?.toString()
166
- });
167
- if (!isNativeIn) {
168
- console.log('Checking token approval...');
169
- const approvalResult = await (0, utils_1.checkAndApprove)(wallet, tokenIn.address, swapTx.to, formattedAmountIn, undefined, undefined, this.config.confirmationNo || 1);
170
- if (approvalResult.approvalNeeded && approvalResult.approvalResult) {
171
- if (!approvalResult.approvalResult.success) {
172
- throw new Error('Token approval failed');
173
- }
174
- console.log('Token approval successful');
175
- }
176
- else if (approvalResult.approvalNeeded) {
177
- throw new Error('Token approval was needed but failed');
178
- }
179
- else {
180
- console.log('Token approval not needed - sufficient allowance');
181
- }
182
- }
183
- const result = await (0, utils_1.signSendAndConfirm)(wallet, {
184
- to: swapTx.to,
185
- data: swapTx.data,
186
- value: swapTx.value || '0',
187
- gasLimit: swapTx.gasLimit
188
- }, this.config.confirmationNo || 1);
189
- if (result.success) {
190
- console.log(' Swap completed successfully:', {
191
- hash: result.hash,
192
- gasUsed: result.gasUsed?.toString(),
193
- blockNumber: result.blockNumber
194
- });
195
- }
196
- else {
197
- console.log(' Swap failed:', result);
198
- }
199
- return result;
200
- }
201
- catch (error) {
202
- console.error('Swap failed:', error);
203
- throw new Error(`Swap failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
204
- }
205
- }
206
- async getSwapQuote(tokenIn, tokenOut, amount) {
207
- try {
208
- const chainId = (await this.connection.getNetwork()).chainId.toString();
209
- if (!(0, utils_1.isChainSupportedByKyber)(chainId)) {
210
- throw new Error(`Chain ${chainId} is not supported by KyberSwap`);
211
- }
212
- const isNativeIn = tokenIn.address === 'native' ||
213
- tokenIn.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
214
- const isNativeOut = tokenOut.address === 'native' ||
215
- tokenOut.address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
216
- let tokenInDecimals = 18;
217
- if (!isNativeIn && tokenIn.decimals) {
218
- tokenInDecimals = tokenIn.decimals;
219
- }
220
- else if (!isNativeIn) {
221
- const tokenBalance = await this.getTokenBalance(tokenIn.address);
222
- tokenInDecimals = tokenBalance.decimal;
223
- }
224
- const { tokenInAddress, tokenOutAddress, formattedAmountIn } = (0, utils_1.prepareSwapParams)(tokenIn.address, tokenOut.address, amount.toString(), tokenInDecimals, isNativeIn, isNativeOut);
225
- throw new Error("Quote functionality requires direct API integration - use the swap method for full execution");
226
- }
227
- catch (error) {
228
- console.error('Error getting swap quote:', error);
229
- throw error;
230
- }
231
- }
232
- }
233
- exports.EVMChainWallet = EVMChainWallet;
@@ -1,2 +0,0 @@
1
- export * from "./evm";
2
- export * from "./utils";
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./evm"), exports);
18
- __exportStar(require("./utils"), exports);
@@ -1,207 +0,0 @@
1
- import { Balance } from '../types';
2
- import { JsonRpcProvider, Wallet, TransactionReceipt } from 'ethers';
3
- export interface TransactionParams {
4
- to: string;
5
- value?: string | bigint;
6
- data?: string;
7
- gasLimit?: string | bigint;
8
- gasPrice?: string | bigint;
9
- maxFeePerGas?: string | bigint;
10
- maxPriorityFeePerGas?: string | bigint;
11
- nonce?: number;
12
- }
13
- interface TransactionResult {
14
- hash: string;
15
- receipt: TransactionReceipt | null;
16
- success: boolean;
17
- gasUsed?: bigint;
18
- effectiveGasPrice?: bigint;
19
- blockNumber?: number;
20
- confirmations: number;
21
- }
22
- export interface SwapParams {
23
- tokenIn: string;
24
- tokenOut: string;
25
- amountIn: string;
26
- slippageTolerance?: number;
27
- recipient?: string;
28
- deadline?: number;
29
- feeAmount?: string;
30
- feeReceiver?: string;
31
- isInBps?: boolean;
32
- chargeFeeBy?: 'currency_in' | 'currency_out';
33
- }
34
- export interface KyberRoute {
35
- tokenIn: string;
36
- amountIn: string;
37
- tokenOut: string;
38
- amountOut: string;
39
- gas: string;
40
- gasPrice: string;
41
- gasUsd: number;
42
- amountOutUsd: string;
43
- receivedUsd: string;
44
- swaps: Array<{
45
- pool: string;
46
- tokenIn: string;
47
- tokenOut: string;
48
- swapAmount: string;
49
- amountOut: string;
50
- limitReturnAmount: string;
51
- maxPrice: string;
52
- exchange: string;
53
- poolLength: number;
54
- poolType: string;
55
- }>;
56
- tokens: {
57
- [address: string]: {
58
- address: string;
59
- symbol: string;
60
- name: string;
61
- decimals: number;
62
- price: number;
63
- };
64
- };
65
- }
66
- export interface KyberSwapResponse {
67
- code: number;
68
- message: string;
69
- data: {
70
- routeSummary: KyberRoute;
71
- routerAddress: string;
72
- };
73
- }
74
- export interface KyberBuildResponse {
75
- code: number;
76
- message: string;
77
- data: {
78
- amountIn: string;
79
- amountInUsd: string;
80
- amountOut: string;
81
- amountOutUsd: string;
82
- gas: string;
83
- gasUsd: string;
84
- outputChange: {
85
- amount: string;
86
- percent: number;
87
- level: number;
88
- };
89
- data: string;
90
- routerAddress: string;
91
- };
92
- }
93
- interface KyberSwapParams {
94
- chainId: string;
95
- tokenIn: string;
96
- tokenOut: string;
97
- amountIn: string;
98
- slippageTolerance?: number;
99
- recipient?: string;
100
- sender?: string;
101
- deadline?: number;
102
- feeAmount?: string;
103
- feeReceiver?: string;
104
- isInBps?: boolean;
105
- chargeFeeBy?: 'currency_in' | 'currency_out';
106
- clientId?: string;
107
- }
108
- export declare const getNativeBalance: (address: string, provider: JsonRpcProvider) => Promise<Balance>;
109
- export declare const getTokenBalance: (tokenAddress: string, walletAddress: string, provider: JsonRpcProvider) => Promise<Balance>;
110
- /**
111
- * Sign, send, and confirm any EVM transaction
112
- */
113
- export declare const signSendAndConfirm: (wallet: Wallet, transactionParams: TransactionParams, confirmations?: number, timeout?: number) => Promise<TransactionResult>;
114
- /**
115
- * Send native token (ETH, BNB, MATIC, etc.)
116
- */
117
- export declare const sendNativeToken: (wallet: Wallet, to: string, amount: string | bigint, gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
118
- /**
119
- * Send ERC-20 token
120
- */
121
- export declare const sendERC20Token: (wallet: Wallet, tokenAddress: string, to: string, amount: string | bigint, gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
122
- /**
123
- * Execute any contract method
124
- */
125
- export declare const executeContractMethod: (wallet: Wallet, contractAddress: string, abi: any[], methodName: string, methodParams?: any[], value?: string | bigint, gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
126
- /**
127
- * Get current gas prices (both legacy and EIP-1559)
128
- */
129
- export declare const getGasPrices: (provider: JsonRpcProvider) => Promise<{
130
- gasPrice: bigint;
131
- maxFeePerGas: bigint;
132
- maxPriorityFeePerGas: bigint;
133
- }>;
134
- /**
135
- * Estimate gas for a transaction
136
- */
137
- export declare const estimateGas: (provider: JsonRpcProvider, transactionParams: TransactionParams) => Promise<bigint>;
138
- /**
139
- * Check ERC-20 token allowance
140
- */
141
- export declare const checkAllowance: (tokenAddress: string, owner: string, spender: string, provider: JsonRpcProvider) => Promise<{
142
- allowance: bigint;
143
- formatted: string;
144
- decimals: number;
145
- }>;
146
- /**
147
- * Check if allowance is sufficient for a transaction
148
- */
149
- export declare const isAllowanceSufficient: (tokenAddress: string, owner: string, spender: string, requiredAmount: string | bigint, provider: JsonRpcProvider) => Promise<boolean>;
150
- /**
151
- * Approve ERC-20 token spending
152
- */
153
- export declare const approveToken: (wallet: Wallet, tokenAddress: string, spender: string, amount: string | bigint, gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
154
- /**
155
- * Approve unlimited token spending (MaxUint256)
156
- */
157
- export declare const approveTokenUnlimited: (wallet: Wallet, tokenAddress: string, spender: string, gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
158
- /**
159
- * Check allowance and approve if necessary
160
- */
161
- export declare const checkAndApprove: (wallet: Wallet, tokenAddress: string, spender: string, requiredAmount: string | bigint, approvalAmount?: string | bigint, gasLimit?: string | bigint, confirmations?: number) => Promise<{
162
- approvalNeeded: boolean;
163
- currentAllowance: bigint;
164
- approvalResult?: TransactionResult;
165
- }>;
166
- /**
167
- * Reset token allowance to zero (security best practice before setting new allowance)
168
- */
169
- export declare const resetAllowance: (wallet: Wallet, tokenAddress: string, spender: string, gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
170
- /**
171
- * Safe approve: Reset to zero first, then approve the desired amount
172
- * (Some tokens like USDT require this)
173
- */
174
- export declare const safeApprove: (wallet: Wallet, tokenAddress: string, spender: string, amount: string | bigint, gasLimit?: string | bigint, confirmations?: number) => Promise<{
175
- resetResult: TransactionResult;
176
- approveResult: TransactionResult;
177
- }>;
178
- export declare function getKyberSwapRoute(params: KyberSwapParams): Promise<KyberSwapResponse>;
179
- export declare function buildKyberSwapTransaction(chainId: string, routeSummary: KyberRoute, sender: string, recipient: string, slippageTolerance?: number, deadline?: number, clientId?: string): Promise<KyberBuildResponse>;
180
- export declare function performSwap(params: {
181
- chainId: string;
182
- tokenIn: string;
183
- tokenOut: string;
184
- amountIn: string;
185
- sender: string;
186
- recipient?: string;
187
- slippageTolerance?: number;
188
- deadline?: number;
189
- feeAmount?: string;
190
- feeReceiver?: string;
191
- isInBps?: boolean;
192
- chargeFeeBy?: 'currency_in' | 'currency_out';
193
- clientId?: string;
194
- }): Promise<TransactionParams>;
195
- export declare function getKyberSupportedChains(): {
196
- [key: string]: string;
197
- };
198
- export declare function isChainSupportedByKyber(chainId: string): boolean;
199
- export declare function getNativeTokenAddress(): string;
200
- export declare function formatAmountToWei(amount: string, decimals: number): string;
201
- export declare function formatAmountFromWei(amountWei: string, decimals: number): string;
202
- export declare function prepareSwapParams(tokenIn: string, tokenOut: string, amountIn: string, tokenInDecimals: number, isNativeIn?: boolean, isNativeOut?: boolean): {
203
- tokenInAddress: string;
204
- tokenOutAddress: string;
205
- formattedAmountIn: string;
206
- };
207
- export {};