@deserialize/multi-vm-wallet 1.0.2 → 1.0.4
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/IChainWallet.d.ts +17 -0
- package/dist/IChainWallet.js +23 -0
- package/dist/IChainWallet.js.map +1 -0
- package/dist/bip32.d.ts +11 -0
- package/dist/bip32.js +100 -0
- package/dist/bip32.js.map +1 -0
- package/dist/evm/evm.d.ts +56 -0
- package/dist/evm/evm.js +257 -0
- package/dist/evm/evm.js.map +1 -0
- package/dist/evm/index.d.ts +2 -0
- package/dist/evm/index.js +19 -0
- package/dist/evm/index.js.map +1 -0
- package/dist/evm/utils.d.ts +214 -0
- package/dist/evm/utils.js +538 -0
- package/dist/evm/utils.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/old.d.ts +0 -0
- package/dist/old.js +885 -0
- package/dist/old.js.map +1 -0
- package/dist/svm/index.d.ts +1 -0
- package/dist/svm/index.js +18 -0
- package/dist/svm/index.js.map +1 -0
- package/dist/svm/svm.d.ts +37 -0
- package/dist/svm/svm.js +181 -0
- package/dist/svm/svm.js.map +1 -0
- package/dist/svm/transactionSender.d.ts +8 -0
- package/dist/svm/transactionSender.js +88 -0
- package/dist/svm/transactionSender.js.map +1 -0
- package/dist/svm/utils.d.ts +85 -0
- package/dist/svm/utils.js +470 -0
- package/dist/svm/utils.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.js +42 -0
- package/dist/test.js.map +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/vm.d.ts +23 -0
- package/dist/vm.js +89 -0
- package/dist/vm.js.map +1 -0
- package/package.json +4 -1
- package/tsconfig.json +11 -111
- package/utils/evm/evm.ts +58 -3
- package/utils/old.ts +1005 -0
- package/utils/svm/svm.ts +29 -12
- package/utils/svm/transactionSender.ts +7 -2
- package/utils/svm/utils.ts +222 -29
- package/utils/test.ts +49 -0
- package/utils/vm.ts +50 -1
|
@@ -0,0 +1,214 @@
|
|
|
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, // Connected wallet (private key + provider)
|
|
114
|
+
transactionParams: TransactionParams, confirmations?: number, // Number of confirmations to wait for
|
|
115
|
+
timeout?: number) => Promise<TransactionResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Send native token (ETH, BNB, MATIC, etc.)
|
|
118
|
+
*/
|
|
119
|
+
export declare const sendNativeToken: (wallet: Wallet, to: string, amount: string | bigint, // Amount in wei
|
|
120
|
+
gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
|
|
121
|
+
/**
|
|
122
|
+
* Send ERC-20 token
|
|
123
|
+
*/
|
|
124
|
+
export declare const sendERC20Token: (wallet: Wallet, tokenAddress: string, to: string, amount: string | bigint, // Amount in token's smallest unit
|
|
125
|
+
gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
|
|
126
|
+
/**
|
|
127
|
+
* Execute any contract method
|
|
128
|
+
*/
|
|
129
|
+
export declare const executeContractMethod: (wallet: Wallet, contractAddress: string, abi: any[], methodName: string, methodParams?: any[], value?: string | bigint, // For payable methods
|
|
130
|
+
gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
|
|
131
|
+
/**
|
|
132
|
+
* Get current gas prices (both legacy and EIP-1559)
|
|
133
|
+
*/
|
|
134
|
+
export declare const getGasPrices: (provider: JsonRpcProvider) => Promise<{
|
|
135
|
+
gasPrice: bigint | null;
|
|
136
|
+
maxFeePerGas: bigint | null;
|
|
137
|
+
maxPriorityFeePerGas: bigint | null;
|
|
138
|
+
}>;
|
|
139
|
+
/**
|
|
140
|
+
* Estimate gas for a transaction
|
|
141
|
+
*/
|
|
142
|
+
export declare const estimateGas: (provider: JsonRpcProvider, transactionParams: TransactionParams) => Promise<bigint>;
|
|
143
|
+
/**
|
|
144
|
+
* Check ERC-20 token allowance
|
|
145
|
+
*/
|
|
146
|
+
export declare const checkAllowance: (tokenAddress: string, owner: string, spender: string, provider: JsonRpcProvider) => Promise<{
|
|
147
|
+
allowance: bigint;
|
|
148
|
+
formatted: string;
|
|
149
|
+
decimals: number;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Check if allowance is sufficient for a transaction
|
|
153
|
+
*/
|
|
154
|
+
export declare const isAllowanceSufficient: (tokenAddress: string, owner: string, spender: string, requiredAmount: string | bigint, provider: JsonRpcProvider) => Promise<boolean>;
|
|
155
|
+
/**
|
|
156
|
+
* Approve ERC-20 token spending
|
|
157
|
+
*/
|
|
158
|
+
export declare const approveToken: (wallet: Wallet, tokenAddress: string, spender: string, amount: string | bigint, // Amount to approve, use MaxUint256 for unlimited
|
|
159
|
+
gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
|
|
160
|
+
/**
|
|
161
|
+
* Approve unlimited token spending (MaxUint256)
|
|
162
|
+
*/
|
|
163
|
+
export declare const approveTokenUnlimited: (wallet: Wallet, tokenAddress: string, spender: string, gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
|
|
164
|
+
/**
|
|
165
|
+
* Check allowance and approve if necessary
|
|
166
|
+
*/
|
|
167
|
+
export declare const checkAndApprove: (wallet: Wallet, tokenAddress: string, spender: string, requiredAmount: string | bigint, approvalAmount?: string | bigint, // If not provided, will approve exactly the required amount
|
|
168
|
+
gasLimit?: string | bigint, confirmations?: number) => Promise<{
|
|
169
|
+
approvalNeeded: boolean;
|
|
170
|
+
currentAllowance: bigint;
|
|
171
|
+
approvalResult?: TransactionResult;
|
|
172
|
+
}>;
|
|
173
|
+
/**
|
|
174
|
+
* Reset token allowance to zero (security best practice before setting new allowance)
|
|
175
|
+
*/
|
|
176
|
+
export declare const resetAllowance: (wallet: Wallet, tokenAddress: string, spender: string, gasLimit?: string | bigint, confirmations?: number) => Promise<TransactionResult>;
|
|
177
|
+
/**
|
|
178
|
+
* Safe approve: Reset to zero first, then approve the desired amount
|
|
179
|
+
* (Some tokens like USDT require this)
|
|
180
|
+
*/
|
|
181
|
+
export declare const safeApprove: (wallet: Wallet, tokenAddress: string, spender: string, amount: string | bigint, gasLimit?: string | bigint, confirmations?: number) => Promise<{
|
|
182
|
+
resetResult: TransactionResult;
|
|
183
|
+
approveResult: TransactionResult;
|
|
184
|
+
}>;
|
|
185
|
+
export declare function getKyberSwapRoute(params: KyberSwapParams): Promise<KyberSwapResponse>;
|
|
186
|
+
export declare function buildKyberSwapTransaction(chainId: string, routeSummary: KyberRoute, sender: string, recipient: string, slippageTolerance?: number, deadline?: number, clientId?: string): Promise<KyberBuildResponse>;
|
|
187
|
+
export declare function performSwap(params: {
|
|
188
|
+
chainId: string;
|
|
189
|
+
tokenIn: string;
|
|
190
|
+
tokenOut: string;
|
|
191
|
+
amountIn: string;
|
|
192
|
+
sender: string;
|
|
193
|
+
recipient?: string;
|
|
194
|
+
slippageTolerance?: number;
|
|
195
|
+
deadline?: number;
|
|
196
|
+
feeAmount?: string;
|
|
197
|
+
feeReceiver?: string;
|
|
198
|
+
isInBps?: boolean;
|
|
199
|
+
chargeFeeBy?: 'currency_in' | 'currency_out';
|
|
200
|
+
clientId?: string;
|
|
201
|
+
}): Promise<TransactionParams>;
|
|
202
|
+
export declare function getKyberSupportedChains(): {
|
|
203
|
+
[key: string]: string;
|
|
204
|
+
};
|
|
205
|
+
export declare function isChainSupportedByKyber(chainId: string): boolean;
|
|
206
|
+
export declare function getNativeTokenAddress(): string;
|
|
207
|
+
export declare function formatAmountToWei(amount: string, decimals: number): string;
|
|
208
|
+
export declare function formatAmountFromWei(amountWei: string, decimals: number): string;
|
|
209
|
+
export declare function prepareSwapParams(tokenIn: string, tokenOut: string, amountIn: string, tokenInDecimals: number, isNativeIn?: boolean, isNativeOut?: boolean): {
|
|
210
|
+
tokenInAddress: string;
|
|
211
|
+
tokenOutAddress: string;
|
|
212
|
+
formattedAmountIn: string;
|
|
213
|
+
};
|
|
214
|
+
export {};
|