@swapkit/helpers 1.0.0-rc.1 → 1.0.0-rc.100

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 (40) hide show
  1. package/dist/index.js +2452 -0
  2. package/dist/index.js.map +30 -0
  3. package/package.json +26 -36
  4. package/src/helpers/__tests__/asset.test.ts +149 -105
  5. package/src/helpers/__tests__/memo.test.ts +52 -40
  6. package/src/helpers/__tests__/others.test.ts +42 -37
  7. package/src/helpers/__tests__/validators.test.ts +24 -0
  8. package/src/helpers/asset.ts +139 -91
  9. package/src/helpers/derivationPath.ts +53 -0
  10. package/src/helpers/liquidity.ts +50 -43
  11. package/src/helpers/memo.ts +31 -28
  12. package/src/helpers/others.ts +35 -57
  13. package/src/helpers/validators.ts +15 -6
  14. package/src/helpers/web3wallets.ts +177 -0
  15. package/src/index.ts +14 -8
  16. package/src/modules/__tests__/assetValue.test.ts +420 -117
  17. package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
  18. package/src/modules/__tests__/swapKitNumber.test.ts +351 -149
  19. package/src/modules/assetValue.ts +243 -171
  20. package/src/modules/bigIntArithmetics.ts +313 -153
  21. package/src/modules/requestClient.ts +39 -0
  22. package/src/modules/swapKitError.ts +33 -5
  23. package/src/modules/swapKitNumber.ts +6 -3
  24. package/src/types/abis/erc20.ts +99 -0
  25. package/src/types/abis/mayaEvmVaults.ts +331 -0
  26. package/src/types/abis/tcEthVault.ts +496 -0
  27. package/src/types/chains.ts +220 -0
  28. package/src/types/commonTypes.ts +119 -0
  29. package/src/types/derivationPath.ts +56 -0
  30. package/src/types/errors/apiV1.ts +0 -0
  31. package/src/types/index.ts +10 -0
  32. package/src/types/network.ts +43 -0
  33. package/src/types/sdk.ts +44 -0
  34. package/src/types/tokens.ts +30 -0
  35. package/src/types/wallet.ts +47 -0
  36. package/LICENSE +0 -201
  37. package/dist/index.cjs +0 -1
  38. package/dist/index.d.ts +0 -333
  39. package/dist/index.es.js +0 -661
  40. package/src/helpers/number.ts +0 -40
@@ -1,4 +1,4 @@
1
- import { BigIntArithmetics } from './bigIntArithmetics.ts';
1
+ import { BigIntArithmetics, formatBigIntToSafeValue } from "./bigIntArithmetics.ts";
2
2
 
3
3
  export type SwapKitValueType = BigIntArithmetics | string | number;
4
4
 
@@ -7,7 +7,10 @@ export class SwapKitNumber extends BigIntArithmetics {
7
7
  return this.eqValue(value);
8
8
  }
9
9
 
10
- toString() {
11
- return this.value;
10
+ static fromBigInt(value: bigint, decimal?: number) {
11
+ return new SwapKitNumber({
12
+ decimal,
13
+ value: formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal }),
14
+ });
12
15
  }
13
16
  }
@@ -0,0 +1,99 @@
1
+ export const erc20ABI = [
2
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
3
+ {
4
+ anonymous: false,
5
+ inputs: [
6
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
7
+ { indexed: true, internalType: "address", name: "spender", type: "address" },
8
+ { indexed: false, internalType: "uint256", name: "value", type: "uint256" },
9
+ ],
10
+ name: "Approval",
11
+ type: "event",
12
+ },
13
+ {
14
+ anonymous: false,
15
+ inputs: [
16
+ { indexed: true, internalType: "address", name: "from", type: "address" },
17
+ { indexed: true, internalType: "address", name: "to", type: "address" },
18
+ { indexed: false, internalType: "uint256", name: "value", type: "uint256" },
19
+ ],
20
+ name: "Transfer",
21
+ type: "event",
22
+ },
23
+ {
24
+ inputs: [
25
+ { internalType: "address", name: "", type: "address" },
26
+ { internalType: "address", name: "", type: "address" },
27
+ ],
28
+ name: "allowance",
29
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
30
+ stateMutability: "view",
31
+ type: "function",
32
+ },
33
+ {
34
+ inputs: [
35
+ { internalType: "address", name: "spender", type: "address" },
36
+ { internalType: "uint256", name: "value", type: "uint256" },
37
+ ],
38
+ name: "approve",
39
+ outputs: [{ internalType: "bool", name: "success", type: "bool" }],
40
+ stateMutability: "nonpayable",
41
+ type: "function",
42
+ },
43
+ {
44
+ inputs: [{ internalType: "address", name: "", type: "address" }],
45
+ name: "balanceOf",
46
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
47
+ stateMutability: "view",
48
+ type: "function",
49
+ },
50
+ {
51
+ inputs: [],
52
+ name: "decimals",
53
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
54
+ stateMutability: "view",
55
+ type: "function",
56
+ },
57
+ {
58
+ inputs: [],
59
+ name: "name",
60
+ outputs: [{ internalType: "string", name: "", type: "string" }],
61
+ stateMutability: "view",
62
+ type: "function",
63
+ },
64
+ {
65
+ inputs: [],
66
+ name: "symbol",
67
+ outputs: [{ internalType: "string", name: "", type: "string" }],
68
+ stateMutability: "view",
69
+ type: "function",
70
+ },
71
+ {
72
+ inputs: [],
73
+ name: "totalSupply",
74
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
75
+ stateMutability: "view",
76
+ type: "function",
77
+ },
78
+ {
79
+ inputs: [
80
+ { internalType: "address", name: "to", type: "address" },
81
+ { internalType: "uint256", name: "value", type: "uint256" },
82
+ ],
83
+ name: "transfer",
84
+ outputs: [{ internalType: "bool", name: "success", type: "bool" }],
85
+ stateMutability: "nonpayable",
86
+ type: "function",
87
+ },
88
+ {
89
+ inputs: [
90
+ { internalType: "address", name: "from", type: "address" },
91
+ { internalType: "address", name: "to", type: "address" },
92
+ { internalType: "uint256", name: "value", type: "uint256" },
93
+ ],
94
+ name: "transferFrom",
95
+ outputs: [{ internalType: "bool", name: "success", type: "bool" }],
96
+ stateMutability: "nonpayable",
97
+ type: "function",
98
+ },
99
+ ];
@@ -0,0 +1,331 @@
1
+ export const MayaEthereumVaultAbi = [
2
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
3
+ {
4
+ anonymous: false,
5
+ inputs: [
6
+ { indexed: true, internalType: "address", name: "to", type: "address" },
7
+ { indexed: true, internalType: "address", name: "asset", type: "address" },
8
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
9
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
10
+ ],
11
+ name: "Deposit",
12
+ type: "event",
13
+ },
14
+ {
15
+ anonymous: false,
16
+ inputs: [
17
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
18
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
19
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
20
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
21
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
22
+ ],
23
+ name: "TransferAllowance",
24
+ type: "event",
25
+ },
26
+ {
27
+ anonymous: false,
28
+ inputs: [
29
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
30
+ { indexed: true, internalType: "address", name: "to", type: "address" },
31
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
32
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
33
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
34
+ ],
35
+ name: "TransferOut",
36
+ type: "event",
37
+ },
38
+ {
39
+ anonymous: false,
40
+ inputs: [
41
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
42
+ { indexed: false, internalType: "address", name: "target", type: "address" },
43
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
44
+ { indexed: false, internalType: "address", name: "finalAsset", type: "address" },
45
+ { indexed: false, internalType: "address", name: "to", type: "address" },
46
+ { indexed: false, internalType: "uint256", name: "amountOutMin", type: "uint256" },
47
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
48
+ ],
49
+ name: "TransferOutAndCall",
50
+ type: "event",
51
+ },
52
+ {
53
+ anonymous: false,
54
+ inputs: [
55
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
56
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
57
+ {
58
+ components: [
59
+ { internalType: "address", name: "asset", type: "address" },
60
+ { internalType: "uint256", name: "amount", type: "uint256" },
61
+ ],
62
+ indexed: false,
63
+ internalType: "struct MAYAChain_Router.Coin[]",
64
+ name: "coins",
65
+ type: "tuple[]",
66
+ },
67
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
68
+ ],
69
+ name: "VaultTransfer",
70
+ type: "event",
71
+ },
72
+ {
73
+ inputs: [
74
+ { internalType: "address payable", name: "vault", type: "address" },
75
+ { internalType: "address", name: "asset", type: "address" },
76
+ { internalType: "uint256", name: "amount", type: "uint256" },
77
+ { internalType: "string", name: "memo", type: "string" },
78
+ ],
79
+ name: "deposit",
80
+ outputs: [],
81
+ stateMutability: "payable",
82
+ type: "function",
83
+ },
84
+ {
85
+ inputs: [
86
+ { internalType: "address payable", name: "vault", type: "address" },
87
+ { internalType: "address", name: "asset", type: "address" },
88
+ { internalType: "uint256", name: "amount", type: "uint256" },
89
+ { internalType: "string", name: "memo", type: "string" },
90
+ { internalType: "uint256", name: "expiration", type: "uint256" },
91
+ ],
92
+ name: "depositWithExpiry",
93
+ outputs: [],
94
+ stateMutability: "payable",
95
+ type: "function",
96
+ },
97
+ {
98
+ inputs: [
99
+ { internalType: "address", name: "router", type: "address" },
100
+ { internalType: "address payable", name: "asgard", type: "address" },
101
+ {
102
+ components: [
103
+ { internalType: "address", name: "asset", type: "address" },
104
+ { internalType: "uint256", name: "amount", type: "uint256" },
105
+ ],
106
+ internalType: "struct MAYAChain_Router.Coin[]",
107
+ name: "coins",
108
+ type: "tuple[]",
109
+ },
110
+ { internalType: "string", name: "memo", type: "string" },
111
+ ],
112
+ name: "returnVaultAssets",
113
+ outputs: [],
114
+ stateMutability: "payable",
115
+ type: "function",
116
+ },
117
+ {
118
+ inputs: [
119
+ { internalType: "address", name: "router", type: "address" },
120
+ { internalType: "address", name: "newVault", type: "address" },
121
+ { internalType: "address", name: "asset", type: "address" },
122
+ { internalType: "uint256", name: "amount", type: "uint256" },
123
+ { internalType: "string", name: "memo", type: "string" },
124
+ ],
125
+ name: "transferAllowance",
126
+ outputs: [],
127
+ stateMutability: "nonpayable",
128
+ type: "function",
129
+ },
130
+ {
131
+ inputs: [
132
+ { internalType: "address payable", name: "to", type: "address" },
133
+ { internalType: "address", name: "asset", type: "address" },
134
+ { internalType: "uint256", name: "amount", type: "uint256" },
135
+ { internalType: "string", name: "memo", type: "string" },
136
+ ],
137
+ name: "transferOut",
138
+ outputs: [],
139
+ stateMutability: "payable",
140
+ type: "function",
141
+ },
142
+ {
143
+ inputs: [
144
+ { internalType: "address payable", name: "target", type: "address" },
145
+ { internalType: "address", name: "finalToken", type: "address" },
146
+ { internalType: "address", name: "to", type: "address" },
147
+ { internalType: "uint256", name: "amountOutMin", type: "uint256" },
148
+ { internalType: "string", name: "memo", type: "string" },
149
+ ],
150
+ name: "transferOutAndCall",
151
+ outputs: [],
152
+ stateMutability: "payable",
153
+ type: "function",
154
+ },
155
+ {
156
+ inputs: [
157
+ { internalType: "address", name: "vault", type: "address" },
158
+ { internalType: "address", name: "token", type: "address" },
159
+ ],
160
+ name: "vaultAllowance",
161
+ outputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
162
+ stateMutability: "view",
163
+ type: "function",
164
+ },
165
+ ];
166
+
167
+ export const MayaArbitrumVaultAbi = [
168
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
169
+ {
170
+ anonymous: false,
171
+ inputs: [
172
+ { indexed: true, internalType: "address", name: "to", type: "address" },
173
+ { indexed: true, internalType: "address", name: "asset", type: "address" },
174
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
175
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
176
+ ],
177
+ name: "Deposit",
178
+ type: "event",
179
+ },
180
+ {
181
+ anonymous: false,
182
+ inputs: [
183
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
184
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
185
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
186
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
187
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
188
+ ],
189
+ name: "TransferAllowance",
190
+ type: "event",
191
+ },
192
+ {
193
+ anonymous: false,
194
+ inputs: [
195
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
196
+ { indexed: true, internalType: "address", name: "to", type: "address" },
197
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
198
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
199
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
200
+ ],
201
+ name: "TransferOut",
202
+ type: "event",
203
+ },
204
+ {
205
+ anonymous: false,
206
+ inputs: [
207
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
208
+ { indexed: false, internalType: "address", name: "target", type: "address" },
209
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
210
+ { indexed: false, internalType: "address", name: "finalAsset", type: "address" },
211
+ { indexed: false, internalType: "address", name: "to", type: "address" },
212
+ { indexed: false, internalType: "uint256", name: "amountOutMin", type: "uint256" },
213
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
214
+ ],
215
+ name: "TransferOutAndCall",
216
+ type: "event",
217
+ },
218
+ {
219
+ anonymous: false,
220
+ inputs: [
221
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
222
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
223
+ {
224
+ components: [
225
+ { internalType: "address", name: "asset", type: "address" },
226
+ { internalType: "uint256", name: "amount", type: "uint256" },
227
+ ],
228
+ indexed: false,
229
+ internalType: "struct ArbRouter.Coin[]",
230
+ name: "coins",
231
+ type: "tuple[]",
232
+ },
233
+ { indexed: false, internalType: "string", name: "memo", type: "string" },
234
+ ],
235
+ name: "VaultTransfer",
236
+ type: "event",
237
+ },
238
+ {
239
+ inputs: [
240
+ { internalType: "address payable", name: "vault", type: "address" },
241
+ { internalType: "address", name: "asset", type: "address" },
242
+ { internalType: "uint256", name: "amount", type: "uint256" },
243
+ { internalType: "string", name: "memo", type: "string" },
244
+ ],
245
+ name: "deposit",
246
+ outputs: [],
247
+ stateMutability: "payable",
248
+ type: "function",
249
+ },
250
+ {
251
+ inputs: [
252
+ { internalType: "address payable", name: "vault", type: "address" },
253
+ { internalType: "address", name: "asset", type: "address" },
254
+ { internalType: "uint256", name: "amount", type: "uint256" },
255
+ { internalType: "string", name: "memo", type: "string" },
256
+ { internalType: "uint256", name: "expiration", type: "uint256" },
257
+ ],
258
+ name: "depositWithExpiry",
259
+ outputs: [],
260
+ stateMutability: "payable",
261
+ type: "function",
262
+ },
263
+ {
264
+ inputs: [
265
+ { internalType: "address", name: "router", type: "address" },
266
+ { internalType: "address payable", name: "asgard", type: "address" },
267
+ {
268
+ components: [
269
+ { internalType: "address", name: "asset", type: "address" },
270
+ { internalType: "uint256", name: "amount", type: "uint256" },
271
+ ],
272
+ internalType: "struct ArbRouter.Coin[]",
273
+ name: "coins",
274
+ type: "tuple[]",
275
+ },
276
+ { internalType: "string", name: "memo", type: "string" },
277
+ ],
278
+ name: "returnVaultAssets",
279
+ outputs: [],
280
+ stateMutability: "payable",
281
+ type: "function",
282
+ },
283
+ {
284
+ inputs: [
285
+ { internalType: "address", name: "router", type: "address" },
286
+ { internalType: "address", name: "newVault", type: "address" },
287
+ { internalType: "address", name: "asset", type: "address" },
288
+ { internalType: "uint256", name: "amount", type: "uint256" },
289
+ { internalType: "string", name: "memo", type: "string" },
290
+ ],
291
+ name: "transferAllowance",
292
+ outputs: [],
293
+ stateMutability: "nonpayable",
294
+ type: "function",
295
+ },
296
+ {
297
+ inputs: [
298
+ { internalType: "address payable", name: "to", type: "address" },
299
+ { internalType: "address", name: "asset", type: "address" },
300
+ { internalType: "uint256", name: "amount", type: "uint256" },
301
+ { internalType: "string", name: "memo", type: "string" },
302
+ ],
303
+ name: "transferOut",
304
+ outputs: [],
305
+ stateMutability: "payable",
306
+ type: "function",
307
+ },
308
+ {
309
+ inputs: [
310
+ { internalType: "address payable", name: "target", type: "address" },
311
+ { internalType: "address", name: "finalToken", type: "address" },
312
+ { internalType: "address", name: "to", type: "address" },
313
+ { internalType: "uint256", name: "amountOutMin", type: "uint256" },
314
+ { internalType: "string", name: "memo", type: "string" },
315
+ ],
316
+ name: "transferOutAndCall",
317
+ outputs: [],
318
+ stateMutability: "payable",
319
+ type: "function",
320
+ },
321
+ {
322
+ inputs: [
323
+ { internalType: "address", name: "vault", type: "address" },
324
+ { internalType: "address", name: "token", type: "address" },
325
+ ],
326
+ name: "vaultAllowance",
327
+ outputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
328
+ stateMutability: "view",
329
+ type: "function",
330
+ },
331
+ ];