@swapkit/helpers 1.0.0-rc.10 → 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 +24 -37
  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 +130 -94
  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 +30 -13
  13. package/src/helpers/validators.ts +15 -6
  14. package/src/helpers/web3wallets.ts +177 -0
  15. package/src/index.ts +14 -9
  16. package/src/modules/__tests__/assetValue.test.ts +414 -117
  17. package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
  18. package/src/modules/__tests__/swapKitNumber.test.ts +306 -183
  19. package/src/modules/assetValue.ts +218 -152
  20. package/src/modules/bigIntArithmetics.ts +214 -165
  21. package/src/modules/requestClient.ts +39 -0
  22. package/src/modules/swapKitError.ts +33 -5
  23. package/src/modules/swapKitNumber.ts +8 -1
  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 -355
  39. package/dist/index.es.js +0 -1064
  40. package/src/helpers/request.ts +0 -16
package/dist/index.js ADDED
@@ -0,0 +1,2452 @@
1
+ var __require = ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/types/abis/erc20.ts
10
+ var erc20ABI = [
11
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
12
+ {
13
+ anonymous: false,
14
+ inputs: [
15
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
16
+ { indexed: true, internalType: "address", name: "spender", type: "address" },
17
+ { indexed: false, internalType: "uint256", name: "value", type: "uint256" }
18
+ ],
19
+ name: "Approval",
20
+ type: "event"
21
+ },
22
+ {
23
+ anonymous: false,
24
+ inputs: [
25
+ { indexed: true, internalType: "address", name: "from", type: "address" },
26
+ { indexed: true, internalType: "address", name: "to", type: "address" },
27
+ { indexed: false, internalType: "uint256", name: "value", type: "uint256" }
28
+ ],
29
+ name: "Transfer",
30
+ type: "event"
31
+ },
32
+ {
33
+ inputs: [
34
+ { internalType: "address", name: "", type: "address" },
35
+ { internalType: "address", name: "", type: "address" }
36
+ ],
37
+ name: "allowance",
38
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
39
+ stateMutability: "view",
40
+ type: "function"
41
+ },
42
+ {
43
+ inputs: [
44
+ { internalType: "address", name: "spender", type: "address" },
45
+ { internalType: "uint256", name: "value", type: "uint256" }
46
+ ],
47
+ name: "approve",
48
+ outputs: [{ internalType: "bool", name: "success", type: "bool" }],
49
+ stateMutability: "nonpayable",
50
+ type: "function"
51
+ },
52
+ {
53
+ inputs: [{ internalType: "address", name: "", type: "address" }],
54
+ name: "balanceOf",
55
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
56
+ stateMutability: "view",
57
+ type: "function"
58
+ },
59
+ {
60
+ inputs: [],
61
+ name: "decimals",
62
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
63
+ stateMutability: "view",
64
+ type: "function"
65
+ },
66
+ {
67
+ inputs: [],
68
+ name: "name",
69
+ outputs: [{ internalType: "string", name: "", type: "string" }],
70
+ stateMutability: "view",
71
+ type: "function"
72
+ },
73
+ {
74
+ inputs: [],
75
+ name: "symbol",
76
+ outputs: [{ internalType: "string", name: "", type: "string" }],
77
+ stateMutability: "view",
78
+ type: "function"
79
+ },
80
+ {
81
+ inputs: [],
82
+ name: "totalSupply",
83
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
84
+ stateMutability: "view",
85
+ type: "function"
86
+ },
87
+ {
88
+ inputs: [
89
+ { internalType: "address", name: "to", type: "address" },
90
+ { internalType: "uint256", name: "value", type: "uint256" }
91
+ ],
92
+ name: "transfer",
93
+ outputs: [{ internalType: "bool", name: "success", type: "bool" }],
94
+ stateMutability: "nonpayable",
95
+ type: "function"
96
+ },
97
+ {
98
+ inputs: [
99
+ { internalType: "address", name: "from", type: "address" },
100
+ { internalType: "address", name: "to", type: "address" },
101
+ { internalType: "uint256", name: "value", type: "uint256" }
102
+ ],
103
+ name: "transferFrom",
104
+ outputs: [{ internalType: "bool", name: "success", type: "bool" }],
105
+ stateMutability: "nonpayable",
106
+ type: "function"
107
+ }
108
+ ];
109
+ // src/types/abis/mayaEvmVaults.ts
110
+ var MayaEthereumVaultAbi = [
111
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
112
+ {
113
+ anonymous: false,
114
+ inputs: [
115
+ { indexed: true, internalType: "address", name: "to", type: "address" },
116
+ { indexed: true, internalType: "address", name: "asset", type: "address" },
117
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
118
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
119
+ ],
120
+ name: "Deposit",
121
+ type: "event"
122
+ },
123
+ {
124
+ anonymous: false,
125
+ inputs: [
126
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
127
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
128
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
129
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
130
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
131
+ ],
132
+ name: "TransferAllowance",
133
+ type: "event"
134
+ },
135
+ {
136
+ anonymous: false,
137
+ inputs: [
138
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
139
+ { indexed: true, internalType: "address", name: "to", type: "address" },
140
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
141
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
142
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
143
+ ],
144
+ name: "TransferOut",
145
+ type: "event"
146
+ },
147
+ {
148
+ anonymous: false,
149
+ inputs: [
150
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
151
+ { indexed: false, internalType: "address", name: "target", type: "address" },
152
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
153
+ { indexed: false, internalType: "address", name: "finalAsset", type: "address" },
154
+ { indexed: false, internalType: "address", name: "to", type: "address" },
155
+ { indexed: false, internalType: "uint256", name: "amountOutMin", type: "uint256" },
156
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
157
+ ],
158
+ name: "TransferOutAndCall",
159
+ type: "event"
160
+ },
161
+ {
162
+ anonymous: false,
163
+ inputs: [
164
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
165
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
166
+ {
167
+ components: [
168
+ { internalType: "address", name: "asset", type: "address" },
169
+ { internalType: "uint256", name: "amount", type: "uint256" }
170
+ ],
171
+ indexed: false,
172
+ internalType: "struct MAYAChain_Router.Coin[]",
173
+ name: "coins",
174
+ type: "tuple[]"
175
+ },
176
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
177
+ ],
178
+ name: "VaultTransfer",
179
+ type: "event"
180
+ },
181
+ {
182
+ inputs: [
183
+ { internalType: "address payable", name: "vault", type: "address" },
184
+ { internalType: "address", name: "asset", type: "address" },
185
+ { internalType: "uint256", name: "amount", type: "uint256" },
186
+ { internalType: "string", name: "memo", type: "string" }
187
+ ],
188
+ name: "deposit",
189
+ outputs: [],
190
+ stateMutability: "payable",
191
+ type: "function"
192
+ },
193
+ {
194
+ inputs: [
195
+ { internalType: "address payable", name: "vault", type: "address" },
196
+ { internalType: "address", name: "asset", type: "address" },
197
+ { internalType: "uint256", name: "amount", type: "uint256" },
198
+ { internalType: "string", name: "memo", type: "string" },
199
+ { internalType: "uint256", name: "expiration", type: "uint256" }
200
+ ],
201
+ name: "depositWithExpiry",
202
+ outputs: [],
203
+ stateMutability: "payable",
204
+ type: "function"
205
+ },
206
+ {
207
+ inputs: [
208
+ { internalType: "address", name: "router", type: "address" },
209
+ { internalType: "address payable", name: "asgard", type: "address" },
210
+ {
211
+ components: [
212
+ { internalType: "address", name: "asset", type: "address" },
213
+ { internalType: "uint256", name: "amount", type: "uint256" }
214
+ ],
215
+ internalType: "struct MAYAChain_Router.Coin[]",
216
+ name: "coins",
217
+ type: "tuple[]"
218
+ },
219
+ { internalType: "string", name: "memo", type: "string" }
220
+ ],
221
+ name: "returnVaultAssets",
222
+ outputs: [],
223
+ stateMutability: "payable",
224
+ type: "function"
225
+ },
226
+ {
227
+ inputs: [
228
+ { internalType: "address", name: "router", type: "address" },
229
+ { internalType: "address", name: "newVault", type: "address" },
230
+ { internalType: "address", name: "asset", type: "address" },
231
+ { internalType: "uint256", name: "amount", type: "uint256" },
232
+ { internalType: "string", name: "memo", type: "string" }
233
+ ],
234
+ name: "transferAllowance",
235
+ outputs: [],
236
+ stateMutability: "nonpayable",
237
+ type: "function"
238
+ },
239
+ {
240
+ inputs: [
241
+ { internalType: "address payable", name: "to", type: "address" },
242
+ { internalType: "address", name: "asset", type: "address" },
243
+ { internalType: "uint256", name: "amount", type: "uint256" },
244
+ { internalType: "string", name: "memo", type: "string" }
245
+ ],
246
+ name: "transferOut",
247
+ outputs: [],
248
+ stateMutability: "payable",
249
+ type: "function"
250
+ },
251
+ {
252
+ inputs: [
253
+ { internalType: "address payable", name: "target", type: "address" },
254
+ { internalType: "address", name: "finalToken", type: "address" },
255
+ { internalType: "address", name: "to", type: "address" },
256
+ { internalType: "uint256", name: "amountOutMin", type: "uint256" },
257
+ { internalType: "string", name: "memo", type: "string" }
258
+ ],
259
+ name: "transferOutAndCall",
260
+ outputs: [],
261
+ stateMutability: "payable",
262
+ type: "function"
263
+ },
264
+ {
265
+ inputs: [
266
+ { internalType: "address", name: "vault", type: "address" },
267
+ { internalType: "address", name: "token", type: "address" }
268
+ ],
269
+ name: "vaultAllowance",
270
+ outputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
271
+ stateMutability: "view",
272
+ type: "function"
273
+ }
274
+ ];
275
+ var MayaArbitrumVaultAbi = [
276
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
277
+ {
278
+ anonymous: false,
279
+ inputs: [
280
+ { indexed: true, internalType: "address", name: "to", type: "address" },
281
+ { indexed: true, internalType: "address", name: "asset", type: "address" },
282
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
283
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
284
+ ],
285
+ name: "Deposit",
286
+ type: "event"
287
+ },
288
+ {
289
+ anonymous: false,
290
+ inputs: [
291
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
292
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
293
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
294
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
295
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
296
+ ],
297
+ name: "TransferAllowance",
298
+ type: "event"
299
+ },
300
+ {
301
+ anonymous: false,
302
+ inputs: [
303
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
304
+ { indexed: true, internalType: "address", name: "to", type: "address" },
305
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
306
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
307
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
308
+ ],
309
+ name: "TransferOut",
310
+ type: "event"
311
+ },
312
+ {
313
+ anonymous: false,
314
+ inputs: [
315
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
316
+ { indexed: false, internalType: "address", name: "target", type: "address" },
317
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
318
+ { indexed: false, internalType: "address", name: "finalAsset", type: "address" },
319
+ { indexed: false, internalType: "address", name: "to", type: "address" },
320
+ { indexed: false, internalType: "uint256", name: "amountOutMin", type: "uint256" },
321
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
322
+ ],
323
+ name: "TransferOutAndCall",
324
+ type: "event"
325
+ },
326
+ {
327
+ anonymous: false,
328
+ inputs: [
329
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
330
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
331
+ {
332
+ components: [
333
+ { internalType: "address", name: "asset", type: "address" },
334
+ { internalType: "uint256", name: "amount", type: "uint256" }
335
+ ],
336
+ indexed: false,
337
+ internalType: "struct ArbRouter.Coin[]",
338
+ name: "coins",
339
+ type: "tuple[]"
340
+ },
341
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
342
+ ],
343
+ name: "VaultTransfer",
344
+ type: "event"
345
+ },
346
+ {
347
+ inputs: [
348
+ { internalType: "address payable", name: "vault", type: "address" },
349
+ { internalType: "address", name: "asset", type: "address" },
350
+ { internalType: "uint256", name: "amount", type: "uint256" },
351
+ { internalType: "string", name: "memo", type: "string" }
352
+ ],
353
+ name: "deposit",
354
+ outputs: [],
355
+ stateMutability: "payable",
356
+ type: "function"
357
+ },
358
+ {
359
+ inputs: [
360
+ { internalType: "address payable", name: "vault", type: "address" },
361
+ { internalType: "address", name: "asset", type: "address" },
362
+ { internalType: "uint256", name: "amount", type: "uint256" },
363
+ { internalType: "string", name: "memo", type: "string" },
364
+ { internalType: "uint256", name: "expiration", type: "uint256" }
365
+ ],
366
+ name: "depositWithExpiry",
367
+ outputs: [],
368
+ stateMutability: "payable",
369
+ type: "function"
370
+ },
371
+ {
372
+ inputs: [
373
+ { internalType: "address", name: "router", type: "address" },
374
+ { internalType: "address payable", name: "asgard", type: "address" },
375
+ {
376
+ components: [
377
+ { internalType: "address", name: "asset", type: "address" },
378
+ { internalType: "uint256", name: "amount", type: "uint256" }
379
+ ],
380
+ internalType: "struct ArbRouter.Coin[]",
381
+ name: "coins",
382
+ type: "tuple[]"
383
+ },
384
+ { internalType: "string", name: "memo", type: "string" }
385
+ ],
386
+ name: "returnVaultAssets",
387
+ outputs: [],
388
+ stateMutability: "payable",
389
+ type: "function"
390
+ },
391
+ {
392
+ inputs: [
393
+ { internalType: "address", name: "router", type: "address" },
394
+ { internalType: "address", name: "newVault", type: "address" },
395
+ { internalType: "address", name: "asset", type: "address" },
396
+ { internalType: "uint256", name: "amount", type: "uint256" },
397
+ { internalType: "string", name: "memo", type: "string" }
398
+ ],
399
+ name: "transferAllowance",
400
+ outputs: [],
401
+ stateMutability: "nonpayable",
402
+ type: "function"
403
+ },
404
+ {
405
+ inputs: [
406
+ { internalType: "address payable", name: "to", type: "address" },
407
+ { internalType: "address", name: "asset", type: "address" },
408
+ { internalType: "uint256", name: "amount", type: "uint256" },
409
+ { internalType: "string", name: "memo", type: "string" }
410
+ ],
411
+ name: "transferOut",
412
+ outputs: [],
413
+ stateMutability: "payable",
414
+ type: "function"
415
+ },
416
+ {
417
+ inputs: [
418
+ { internalType: "address payable", name: "target", type: "address" },
419
+ { internalType: "address", name: "finalToken", type: "address" },
420
+ { internalType: "address", name: "to", type: "address" },
421
+ { internalType: "uint256", name: "amountOutMin", type: "uint256" },
422
+ { internalType: "string", name: "memo", type: "string" }
423
+ ],
424
+ name: "transferOutAndCall",
425
+ outputs: [],
426
+ stateMutability: "payable",
427
+ type: "function"
428
+ },
429
+ {
430
+ inputs: [
431
+ { internalType: "address", name: "vault", type: "address" },
432
+ { internalType: "address", name: "token", type: "address" }
433
+ ],
434
+ name: "vaultAllowance",
435
+ outputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
436
+ stateMutability: "view",
437
+ type: "function"
438
+ }
439
+ ];
440
+ // src/types/abis/tcEthVault.ts
441
+ var TCEthereumVaultAbi = [
442
+ {
443
+ inputs: [{ internalType: "address", name: "rune", type: "address" }],
444
+ stateMutability: "nonpayable",
445
+ type: "constructor"
446
+ },
447
+ {
448
+ anonymous: false,
449
+ inputs: [
450
+ { indexed: true, internalType: "address", name: "to", type: "address" },
451
+ { indexed: true, internalType: "address", name: "asset", type: "address" },
452
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
453
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
454
+ ],
455
+ name: "Deposit",
456
+ type: "event"
457
+ },
458
+ {
459
+ anonymous: false,
460
+ inputs: [
461
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
462
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
463
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
464
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
465
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
466
+ ],
467
+ name: "TransferAllowance",
468
+ type: "event"
469
+ },
470
+ {
471
+ anonymous: false,
472
+ inputs: [
473
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
474
+ { indexed: true, internalType: "address", name: "to", type: "address" },
475
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
476
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
477
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
478
+ ],
479
+ name: "TransferOut",
480
+ type: "event"
481
+ },
482
+ {
483
+ anonymous: false,
484
+ inputs: [
485
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
486
+ { indexed: false, internalType: "address", name: "target", type: "address" },
487
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
488
+ { indexed: false, internalType: "address", name: "finalAsset", type: "address" },
489
+ { indexed: false, internalType: "address", name: "to", type: "address" },
490
+ { indexed: false, internalType: "uint256", name: "amountOutMin", type: "uint256" },
491
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
492
+ ],
493
+ name: "TransferOutAndCall",
494
+ type: "event"
495
+ },
496
+ {
497
+ anonymous: false,
498
+ inputs: [
499
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
500
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
501
+ {
502
+ components: [
503
+ { internalType: "address", name: "asset", type: "address" },
504
+ { internalType: "uint256", name: "amount", type: "uint256" }
505
+ ],
506
+ indexed: false,
507
+ internalType: "struct THORChain_Router.Coin[]",
508
+ name: "coins",
509
+ type: "tuple[]"
510
+ },
511
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
512
+ ],
513
+ name: "VaultTransfer",
514
+ type: "event"
515
+ },
516
+ {
517
+ inputs: [],
518
+ name: "RUNE",
519
+ outputs: [{ internalType: "address", name: "", type: "address" }],
520
+ stateMutability: "view",
521
+ type: "function"
522
+ },
523
+ {
524
+ inputs: [
525
+ { internalType: "address payable", name: "vault", type: "address" },
526
+ { internalType: "address", name: "asset", type: "address" },
527
+ { internalType: "uint256", name: "amount", type: "uint256" },
528
+ { internalType: "string", name: "memo", type: "string" }
529
+ ],
530
+ name: "deposit",
531
+ outputs: [],
532
+ stateMutability: "payable",
533
+ type: "function"
534
+ },
535
+ {
536
+ inputs: [
537
+ { internalType: "address payable", name: "vault", type: "address" },
538
+ { internalType: "address", name: "asset", type: "address" },
539
+ { internalType: "uint256", name: "amount", type: "uint256" },
540
+ { internalType: "string", name: "memo", type: "string" },
541
+ { internalType: "uint256", name: "expiration", type: "uint256" }
542
+ ],
543
+ name: "depositWithExpiry",
544
+ outputs: [],
545
+ stateMutability: "payable",
546
+ type: "function"
547
+ },
548
+ {
549
+ inputs: [
550
+ { internalType: "address", name: "router", type: "address" },
551
+ { internalType: "address payable", name: "asgard", type: "address" },
552
+ {
553
+ components: [
554
+ { internalType: "address", name: "asset", type: "address" },
555
+ { internalType: "uint256", name: "amount", type: "uint256" }
556
+ ],
557
+ internalType: "struct THORChain_Router.Coin[]",
558
+ name: "coins",
559
+ type: "tuple[]"
560
+ },
561
+ { internalType: "string", name: "memo", type: "string" }
562
+ ],
563
+ name: "returnVaultAssets",
564
+ outputs: [],
565
+ stateMutability: "payable",
566
+ type: "function"
567
+ },
568
+ {
569
+ inputs: [
570
+ { internalType: "address", name: "router", type: "address" },
571
+ { internalType: "address", name: "newVault", type: "address" },
572
+ { internalType: "address", name: "asset", type: "address" },
573
+ { internalType: "uint256", name: "amount", type: "uint256" },
574
+ { internalType: "string", name: "memo", type: "string" }
575
+ ],
576
+ name: "transferAllowance",
577
+ outputs: [],
578
+ stateMutability: "nonpayable",
579
+ type: "function"
580
+ },
581
+ {
582
+ inputs: [
583
+ { internalType: "address payable", name: "to", type: "address" },
584
+ { internalType: "address", name: "asset", type: "address" },
585
+ { internalType: "uint256", name: "amount", type: "uint256" },
586
+ { internalType: "string", name: "memo", type: "string" }
587
+ ],
588
+ name: "transferOut",
589
+ outputs: [],
590
+ stateMutability: "payable",
591
+ type: "function"
592
+ },
593
+ {
594
+ inputs: [
595
+ { internalType: "address payable", name: "aggregator", type: "address" },
596
+ { internalType: "address", name: "finalToken", type: "address" },
597
+ { internalType: "address", name: "to", type: "address" },
598
+ { internalType: "uint256", name: "amountOutMin", type: "uint256" },
599
+ { internalType: "string", name: "memo", type: "string" }
600
+ ],
601
+ name: "transferOutAndCall",
602
+ outputs: [],
603
+ stateMutability: "payable",
604
+ type: "function"
605
+ },
606
+ {
607
+ inputs: [
608
+ { internalType: "address", name: "vault", type: "address" },
609
+ { internalType: "address", name: "token", type: "address" }
610
+ ],
611
+ name: "vaultAllowance",
612
+ outputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
613
+ stateMutability: "view",
614
+ type: "function"
615
+ }
616
+ ];
617
+ var TCAvalancheDepositABI = [
618
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
619
+ {
620
+ anonymous: false,
621
+ inputs: [
622
+ { indexed: true, internalType: "address", name: "to", type: "address" },
623
+ { indexed: true, internalType: "address", name: "asset", type: "address" },
624
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
625
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
626
+ ],
627
+ name: "Deposit",
628
+ type: "event"
629
+ },
630
+ {
631
+ anonymous: false,
632
+ inputs: [
633
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
634
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
635
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
636
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
637
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
638
+ ],
639
+ name: "TransferAllowance",
640
+ type: "event"
641
+ },
642
+ {
643
+ anonymous: false,
644
+ inputs: [
645
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
646
+ { indexed: true, internalType: "address", name: "to", type: "address" },
647
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
648
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
649
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
650
+ ],
651
+ name: "TransferOut",
652
+ type: "event"
653
+ },
654
+ {
655
+ anonymous: false,
656
+ inputs: [
657
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
658
+ { indexed: false, internalType: "address", name: "target", type: "address" },
659
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
660
+ { indexed: false, internalType: "address", name: "finalAsset", type: "address" },
661
+ { indexed: false, internalType: "address", name: "to", type: "address" },
662
+ { indexed: false, internalType: "uint256", name: "amountOutMin", type: "uint256" },
663
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
664
+ ],
665
+ name: "TransferOutAndCall",
666
+ type: "event"
667
+ },
668
+ {
669
+ anonymous: false,
670
+ inputs: [
671
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
672
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
673
+ {
674
+ components: [
675
+ { internalType: "address", name: "asset", type: "address" },
676
+ { internalType: "uint256", name: "amount", type: "uint256" }
677
+ ],
678
+ indexed: false,
679
+ internalType: "struct AvaxRouter.Coin[]",
680
+ name: "coins",
681
+ type: "tuple[]"
682
+ },
683
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
684
+ ],
685
+ name: "VaultTransfer",
686
+ type: "event"
687
+ },
688
+ {
689
+ inputs: [
690
+ { internalType: "address payable", name: "vault", type: "address" },
691
+ { internalType: "address", name: "asset", type: "address" },
692
+ { internalType: "uint256", name: "amount", type: "uint256" },
693
+ { internalType: "string", name: "memo", type: "string" }
694
+ ],
695
+ name: "deposit",
696
+ outputs: [],
697
+ stateMutability: "payable",
698
+ type: "function"
699
+ },
700
+ {
701
+ inputs: [
702
+ { internalType: "address payable", name: "vault", type: "address" },
703
+ { internalType: "address", name: "asset", type: "address" },
704
+ { internalType: "uint256", name: "amount", type: "uint256" },
705
+ { internalType: "string", name: "memo", type: "string" },
706
+ { internalType: "uint256", name: "expiration", type: "uint256" }
707
+ ],
708
+ name: "depositWithExpiry",
709
+ outputs: [],
710
+ stateMutability: "payable",
711
+ type: "function"
712
+ },
713
+ {
714
+ inputs: [
715
+ { internalType: "address", name: "router", type: "address" },
716
+ { internalType: "address payable", name: "asgard", type: "address" },
717
+ {
718
+ components: [
719
+ { internalType: "address", name: "asset", type: "address" },
720
+ { internalType: "uint256", name: "amount", type: "uint256" }
721
+ ],
722
+ internalType: "struct AvaxRouter.Coin[]",
723
+ name: "coins",
724
+ type: "tuple[]"
725
+ },
726
+ { internalType: "string", name: "memo", type: "string" }
727
+ ],
728
+ name: "returnVaultAssets",
729
+ outputs: [],
730
+ stateMutability: "payable",
731
+ type: "function"
732
+ },
733
+ {
734
+ inputs: [
735
+ { internalType: "address", name: "router", type: "address" },
736
+ { internalType: "address", name: "newVault", type: "address" },
737
+ { internalType: "address", name: "asset", type: "address" },
738
+ { internalType: "uint256", name: "amount", type: "uint256" },
739
+ { internalType: "string", name: "memo", type: "string" }
740
+ ],
741
+ name: "transferAllowance",
742
+ outputs: [],
743
+ stateMutability: "nonpayable",
744
+ type: "function"
745
+ },
746
+ {
747
+ inputs: [
748
+ { internalType: "address payable", name: "to", type: "address" },
749
+ { internalType: "address", name: "asset", type: "address" },
750
+ { internalType: "uint256", name: "amount", type: "uint256" },
751
+ { internalType: "string", name: "memo", type: "string" }
752
+ ],
753
+ name: "transferOut",
754
+ outputs: [],
755
+ stateMutability: "payable",
756
+ type: "function"
757
+ },
758
+ {
759
+ inputs: [
760
+ { internalType: "address payable", name: "target", type: "address" },
761
+ { internalType: "address", name: "finalToken", type: "address" },
762
+ { internalType: "address", name: "to", type: "address" },
763
+ { internalType: "uint256", name: "amountOutMin", type: "uint256" },
764
+ { internalType: "string", name: "memo", type: "string" }
765
+ ],
766
+ name: "transferOutAndCall",
767
+ outputs: [],
768
+ stateMutability: "payable",
769
+ type: "function"
770
+ },
771
+ {
772
+ inputs: [
773
+ { internalType: "address", name: "vault", type: "address" },
774
+ { internalType: "address", name: "token", type: "address" }
775
+ ],
776
+ name: "vaultAllowance",
777
+ outputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
778
+ stateMutability: "view",
779
+ type: "function"
780
+ }
781
+ ];
782
+ var TCBscDepositABI = [
783
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
784
+ {
785
+ anonymous: false,
786
+ inputs: [
787
+ { indexed: true, internalType: "address", name: "to", type: "address" },
788
+ { indexed: true, internalType: "address", name: "asset", type: "address" },
789
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
790
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
791
+ ],
792
+ name: "Deposit",
793
+ type: "event"
794
+ },
795
+ {
796
+ anonymous: false,
797
+ inputs: [
798
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
799
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
800
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
801
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
802
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
803
+ ],
804
+ name: "TransferAllowance",
805
+ type: "event"
806
+ },
807
+ {
808
+ anonymous: false,
809
+ inputs: [
810
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
811
+ { indexed: true, internalType: "address", name: "to", type: "address" },
812
+ { indexed: false, internalType: "address", name: "asset", type: "address" },
813
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
814
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
815
+ ],
816
+ name: "TransferOut",
817
+ type: "event"
818
+ },
819
+ {
820
+ anonymous: false,
821
+ inputs: [
822
+ { indexed: true, internalType: "address", name: "vault", type: "address" },
823
+ { indexed: false, internalType: "address", name: "target", type: "address" },
824
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
825
+ { indexed: false, internalType: "address", name: "finalAsset", type: "address" },
826
+ { indexed: false, internalType: "address", name: "to", type: "address" },
827
+ { indexed: false, internalType: "uint256", name: "amountOutMin", type: "uint256" },
828
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
829
+ ],
830
+ name: "TransferOutAndCall",
831
+ type: "event"
832
+ },
833
+ {
834
+ anonymous: false,
835
+ inputs: [
836
+ { indexed: true, internalType: "address", name: "oldVault", type: "address" },
837
+ { indexed: true, internalType: "address", name: "newVault", type: "address" },
838
+ {
839
+ components: [
840
+ { internalType: "address", name: "asset", type: "address" },
841
+ { internalType: "uint256", name: "amount", type: "uint256" }
842
+ ],
843
+ indexed: false,
844
+ internalType: "struct THORChain_Router.Coin[]",
845
+ name: "coins",
846
+ type: "tuple[]"
847
+ },
848
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
849
+ ],
850
+ name: "VaultTransfer",
851
+ type: "event"
852
+ },
853
+ {
854
+ inputs: [
855
+ { internalType: "address payable", name: "vault", type: "address" },
856
+ { internalType: "address", name: "asset", type: "address" },
857
+ { internalType: "uint256", name: "amount", type: "uint256" },
858
+ { internalType: "string", name: "memo", type: "string" },
859
+ { internalType: "uint256", name: "expiration", type: "uint256" }
860
+ ],
861
+ name: "depositWithExpiry",
862
+ outputs: [],
863
+ stateMutability: "payable",
864
+ type: "function"
865
+ },
866
+ {
867
+ inputs: [
868
+ { internalType: "address", name: "router", type: "address" },
869
+ { internalType: "address payable", name: "asgard", type: "address" },
870
+ {
871
+ components: [
872
+ { internalType: "address", name: "asset", type: "address" },
873
+ { internalType: "uint256", name: "amount", type: "uint256" }
874
+ ],
875
+ internalType: "struct THORChain_Router.Coin[]",
876
+ name: "coins",
877
+ type: "tuple[]"
878
+ },
879
+ { internalType: "string", name: "memo", type: "string" }
880
+ ],
881
+ name: "returnVaultAssets",
882
+ outputs: [],
883
+ stateMutability: "payable",
884
+ type: "function"
885
+ },
886
+ {
887
+ inputs: [
888
+ { internalType: "address", name: "router", type: "address" },
889
+ { internalType: "address", name: "newVault", type: "address" },
890
+ { internalType: "address", name: "asset", type: "address" },
891
+ { internalType: "uint256", name: "amount", type: "uint256" },
892
+ { internalType: "string", name: "memo", type: "string" }
893
+ ],
894
+ name: "transferAllowance",
895
+ outputs: [],
896
+ stateMutability: "nonpayable",
897
+ type: "function"
898
+ },
899
+ {
900
+ inputs: [
901
+ { internalType: "address payable", name: "to", type: "address" },
902
+ { internalType: "address", name: "asset", type: "address" },
903
+ { internalType: "uint256", name: "amount", type: "uint256" },
904
+ { internalType: "string", name: "memo", type: "string" }
905
+ ],
906
+ name: "transferOut",
907
+ outputs: [],
908
+ stateMutability: "payable",
909
+ type: "function"
910
+ },
911
+ {
912
+ inputs: [
913
+ { internalType: "address payable", name: "target", type: "address" },
914
+ { internalType: "address", name: "finalToken", type: "address" },
915
+ { internalType: "address", name: "to", type: "address" },
916
+ { internalType: "uint256", name: "amountOutMin", type: "uint256" },
917
+ { internalType: "string", name: "memo", type: "string" }
918
+ ],
919
+ name: "transferOutAndCall",
920
+ outputs: [],
921
+ stateMutability: "payable",
922
+ type: "function"
923
+ },
924
+ {
925
+ inputs: [
926
+ { internalType: "address", name: "vault", type: "address" },
927
+ { internalType: "address", name: "token", type: "address" }
928
+ ],
929
+ name: "vaultAllowance",
930
+ outputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
931
+ stateMutability: "view",
932
+ type: "function"
933
+ }
934
+ ];
935
+ // src/types/network.ts
936
+ var RPCUrl;
937
+ (function(RPCUrl2) {
938
+ RPCUrl2["Arbitrum"] = "https://arb1.arbitrum.io/rpc";
939
+ RPCUrl2["Avalanche"] = "https://node-router.thorswap.net/avalanche-c";
940
+ RPCUrl2["Binance"] = "";
941
+ RPCUrl2["BinanceSmartChain"] = "https://bsc-dataseed.binance.org";
942
+ RPCUrl2["Bitcoin"] = "https://node-router.thorswap.net/bitcoin";
943
+ RPCUrl2["BitcoinCash"] = "https://node-router.thorswap.net/bitcoin-cash";
944
+ RPCUrl2["Chainflip"] = "wss://mainnet-archive.chainflip.io";
945
+ RPCUrl2["Cosmos"] = "https://node-router.thorswap.net/cosmos/rpc";
946
+ RPCUrl2["Dash"] = "https://node-router.thorswap.net/dash";
947
+ RPCUrl2["Dogecoin"] = "https://node-router.thorswap.net/dogecoin";
948
+ RPCUrl2["Ethereum"] = "https://node-router.thorswap.net/ethereum";
949
+ RPCUrl2["Kujira"] = "https://rpc-kujira.synergynodes.com/";
950
+ RPCUrl2["Litecoin"] = "https://node-router.thorswap.net/litecoin";
951
+ RPCUrl2["Maya"] = "https://tendermint.mayachain.info";
952
+ RPCUrl2["MayaStagenet"] = "https://stagenet.tendermint.mayachain.info";
953
+ RPCUrl2["Optimism"] = "https://mainnet.optimism.io";
954
+ RPCUrl2["Polkadot"] = "wss://rpc.polkadot.io";
955
+ RPCUrl2["Polygon"] = "https://polygon-rpc.com";
956
+ RPCUrl2["THORChain"] = "https://rpc.thorswap.net";
957
+ RPCUrl2["THORChainStagenet"] = "https://stagenet-rpc.ninerealms.com";
958
+ })(RPCUrl || (RPCUrl = {}));
959
+ var ExplorerUrl;
960
+ (function(ExplorerUrl2) {
961
+ ExplorerUrl2["Arbitrum"] = "https://arbiscan.io";
962
+ ExplorerUrl2["Avalanche"] = "https://snowtrace.io";
963
+ ExplorerUrl2["Binance"] = "https://explorer.binance.org";
964
+ ExplorerUrl2["BinanceSmartChain"] = "https://bscscan.com";
965
+ ExplorerUrl2["Bitcoin"] = "https://blockchair.com/bitcoin";
966
+ ExplorerUrl2["BitcoinCash"] = "https://www.blockchair.com/bitcoin-cash";
967
+ ExplorerUrl2["Chainflip"] = "https://explorer.polkascan.io/polkadot";
968
+ ExplorerUrl2["Cosmos"] = "https://www.mintscan.io/cosmos";
969
+ ExplorerUrl2["Dash"] = "https://blockchair.com/dash";
970
+ ExplorerUrl2["Dogecoin"] = "https://blockchair.com/dogecoin";
971
+ ExplorerUrl2["Ethereum"] = "https://etherscan.io";
972
+ ExplorerUrl2["Kujira"] = "https://finder.kujira.network/kaiyo-1";
973
+ ExplorerUrl2["Litecoin"] = "https://blockchair.com/litecoin";
974
+ ExplorerUrl2["Maya"] = "https://www.mayascan.org";
975
+ ExplorerUrl2["Optimism"] = "https://optimistic.etherscan.io";
976
+ ExplorerUrl2["Polkadot"] = "https://polkadot.subscan.io/";
977
+ ExplorerUrl2["Polygon"] = "https://polygonscan.com";
978
+ ExplorerUrl2["THORChain"] = "https://runescan.io";
979
+ })(ExplorerUrl || (ExplorerUrl = {}));
980
+
981
+ // src/types/chains.ts
982
+ var Chain;
983
+ (function(Chain2) {
984
+ Chain2["Arbitrum"] = "ARB";
985
+ Chain2["Avalanche"] = "AVAX";
986
+ Chain2["Binance"] = "BNB";
987
+ Chain2["BinanceSmartChain"] = "BSC";
988
+ Chain2["Bitcoin"] = "BTC";
989
+ Chain2["BitcoinCash"] = "BCH";
990
+ Chain2["Cosmos"] = "GAIA";
991
+ Chain2["Dash"] = "DASH";
992
+ Chain2["Dogecoin"] = "DOGE";
993
+ Chain2["Ethereum"] = "ETH";
994
+ Chain2["Kujira"] = "KUJI";
995
+ Chain2["Litecoin"] = "LTC";
996
+ Chain2["Maya"] = "MAYA";
997
+ Chain2["Optimism"] = "OP";
998
+ Chain2["Polkadot"] = "DOT";
999
+ Chain2["Chainflip"] = "FLIP";
1000
+ Chain2["Polygon"] = "MATIC";
1001
+ Chain2["THORChain"] = "THOR";
1002
+ })(Chain || (Chain = {}));
1003
+ var ChainId;
1004
+ (function(ChainId2) {
1005
+ ChainId2["Arbitrum"] = "42161";
1006
+ ChainId2["ArbitrumHex"] = "0xa4b1";
1007
+ ChainId2["Avalanche"] = "43114";
1008
+ ChainId2["AvalancheHex"] = "0xa86a";
1009
+ ChainId2["Binance"] = "Binance-Chain-Tigris";
1010
+ ChainId2["BinanceSmartChain"] = "56";
1011
+ ChainId2["BinanceSmartChainHex"] = "0x38";
1012
+ ChainId2["Bitcoin"] = "bitcoin";
1013
+ ChainId2["BitcoinCash"] = "bitcoincash";
1014
+ ChainId2["Chainflip"] = "chainflip";
1015
+ ChainId2["Cosmos"] = "cosmoshub-4";
1016
+ ChainId2["Dash"] = "dash";
1017
+ ChainId2["Dogecoin"] = "dogecoin";
1018
+ ChainId2["Kujira"] = "kaiyo-1";
1019
+ ChainId2["Ethereum"] = "1";
1020
+ ChainId2["EthereumHex"] = "0x1";
1021
+ ChainId2["Litecoin"] = "litecoin";
1022
+ ChainId2["Maya"] = "mayachain-mainnet-v1";
1023
+ ChainId2["MayaStagenet"] = "mayachain-stagenet-v1";
1024
+ ChainId2["Optimism"] = "10";
1025
+ ChainId2["OptimismHex"] = "0xa";
1026
+ ChainId2["Polkadot"] = "polkadot";
1027
+ ChainId2["Polygon"] = "137";
1028
+ ChainId2["PolygonHex"] = "0x89";
1029
+ ChainId2["THORChain"] = "thorchain-mainnet-v1";
1030
+ ChainId2["THORChainStagenet"] = "thorchain-stagenet-v2";
1031
+ })(ChainId || (ChainId = {}));
1032
+ var ChainIdToChain = {
1033
+ [ChainId.ArbitrumHex]: Chain.Arbitrum,
1034
+ [ChainId.Arbitrum]: Chain.Arbitrum,
1035
+ [ChainId.AvalancheHex]: Chain.Avalanche,
1036
+ [ChainId.Avalanche]: Chain.Avalanche,
1037
+ [ChainId.BinanceSmartChainHex]: Chain.BinanceSmartChain,
1038
+ [ChainId.BinanceSmartChain]: Chain.BinanceSmartChain,
1039
+ [ChainId.Binance]: Chain.Binance,
1040
+ [ChainId.BitcoinCash]: Chain.BitcoinCash,
1041
+ [ChainId.Bitcoin]: Chain.Bitcoin,
1042
+ [ChainId.Chainflip]: Chain.Chainflip,
1043
+ [ChainId.Cosmos]: Chain.Cosmos,
1044
+ [ChainId.Dash]: Chain.Dash,
1045
+ [ChainId.Dogecoin]: Chain.Dogecoin,
1046
+ [ChainId.EthereumHex]: Chain.Ethereum,
1047
+ [ChainId.Kujira]: Chain.Kujira,
1048
+ [ChainId.Ethereum]: Chain.Ethereum,
1049
+ [ChainId.Litecoin]: Chain.Litecoin,
1050
+ [ChainId.MayaStagenet]: Chain.Maya,
1051
+ [ChainId.Maya]: Chain.Maya,
1052
+ [ChainId.OptimismHex]: Chain.Optimism,
1053
+ [ChainId.Optimism]: Chain.Optimism,
1054
+ [ChainId.Polkadot]: Chain.Polkadot,
1055
+ [ChainId.PolygonHex]: Chain.Polygon,
1056
+ [ChainId.Polygon]: Chain.Polygon,
1057
+ [ChainId.THORChainStagenet]: Chain.THORChain,
1058
+ [ChainId.THORChain]: Chain.THORChain
1059
+ };
1060
+ var chainNames = Object.keys(Chain);
1061
+ var chains = Object.values(Chain);
1062
+ var BaseDecimal;
1063
+ (function(BaseDecimal2) {
1064
+ BaseDecimal2[BaseDecimal2["ARB"] = 18] = "ARB";
1065
+ BaseDecimal2[BaseDecimal2["AVAX"] = 18] = "AVAX";
1066
+ BaseDecimal2[BaseDecimal2["BCH"] = 8] = "BCH";
1067
+ BaseDecimal2[BaseDecimal2["BNB"] = 8] = "BNB";
1068
+ BaseDecimal2[BaseDecimal2["BSC"] = 18] = "BSC";
1069
+ BaseDecimal2[BaseDecimal2["BTC"] = 8] = "BTC";
1070
+ BaseDecimal2[BaseDecimal2["DASH"] = 8] = "DASH";
1071
+ BaseDecimal2[BaseDecimal2["DOGE"] = 8] = "DOGE";
1072
+ BaseDecimal2[BaseDecimal2["DOT"] = 10] = "DOT";
1073
+ BaseDecimal2[BaseDecimal2["ETH"] = 18] = "ETH";
1074
+ BaseDecimal2[BaseDecimal2["FLIP"] = 18] = "FLIP";
1075
+ BaseDecimal2[BaseDecimal2["GAIA"] = 6] = "GAIA";
1076
+ BaseDecimal2[BaseDecimal2["KUJI"] = 6] = "KUJI";
1077
+ BaseDecimal2[BaseDecimal2["LTC"] = 8] = "LTC";
1078
+ BaseDecimal2[BaseDecimal2["MATIC"] = 18] = "MATIC";
1079
+ BaseDecimal2[BaseDecimal2["MAYA"] = 10] = "MAYA";
1080
+ BaseDecimal2[BaseDecimal2["OP"] = 18] = "OP";
1081
+ BaseDecimal2[BaseDecimal2["THOR"] = 8] = "THOR";
1082
+ BaseDecimal2[BaseDecimal2["ZEC"] = 8] = "ZEC";
1083
+ })(BaseDecimal || (BaseDecimal = {}));
1084
+ var SubstrateChains = [Chain.Polkadot, Chain.Chainflip];
1085
+ var EVMChains = [
1086
+ Chain.Ethereum,
1087
+ Chain.Avalanche,
1088
+ Chain.BinanceSmartChain,
1089
+ Chain.Arbitrum,
1090
+ Chain.Optimism,
1091
+ Chain.Polygon
1092
+ ];
1093
+ var UTXOChains = [
1094
+ Chain.Bitcoin,
1095
+ Chain.BitcoinCash,
1096
+ Chain.Dash,
1097
+ Chain.Dogecoin,
1098
+ Chain.Litecoin
1099
+ ];
1100
+ var CosmosChains = [
1101
+ Chain.Cosmos,
1102
+ Chain.THORChain,
1103
+ Chain.Binance,
1104
+ Chain.Maya,
1105
+ Chain.Kujira
1106
+ ];
1107
+ var TCSupportedChains = [
1108
+ Chain.Avalanche,
1109
+ Chain.Binance,
1110
+ Chain.BinanceSmartChain,
1111
+ Chain.Bitcoin,
1112
+ Chain.BitcoinCash,
1113
+ Chain.Cosmos,
1114
+ Chain.Dogecoin,
1115
+ Chain.Ethereum,
1116
+ Chain.Litecoin,
1117
+ Chain.THORChain
1118
+ ];
1119
+ var MAYASupportedChains = [
1120
+ Chain.Arbitrum,
1121
+ Chain.Dash,
1122
+ Chain.Ethereum,
1123
+ Chain.Kujira,
1124
+ Chain.Maya,
1125
+ Chain.THORChain
1126
+ ];
1127
+ var ChainToChainName = chains.reduce((acc, chain) => {
1128
+ const chainName = chainNames.find((key) => Chain[key] === chain);
1129
+ if (chainName)
1130
+ acc[chain] = chainName;
1131
+ return acc;
1132
+ }, {});
1133
+ var ChainToChainId = chains.reduce((acc, chain) => {
1134
+ acc[chain] = ChainId[ChainToChainName[chain]];
1135
+ return acc;
1136
+ }, {});
1137
+ var ChainToRPC = chains.reduce((acc, chain) => {
1138
+ acc[chain] = RPCUrl[ChainToChainName[chain]];
1139
+ return acc;
1140
+ }, {});
1141
+ var ChainToHexChainId = chains.reduce((acc, chain) => {
1142
+ const chainString = `${ChainToChainName[chain]}Hex`;
1143
+ acc[chain] = ChainId[chainString];
1144
+ return acc;
1145
+ }, {});
1146
+ var ChainToExplorerUrl = chains.reduce((acc, chain) => {
1147
+ acc[chain] = ExplorerUrl[ChainToChainName[chain]];
1148
+ return acc;
1149
+ }, {});
1150
+ // src/types/commonTypes.ts
1151
+ var QuoteMode;
1152
+ (function(QuoteMode2) {
1153
+ QuoteMode2["TC_SUPPORTED_TO_TC_SUPPORTED"] = "TC-TC";
1154
+ QuoteMode2["TC_SUPPORTED_TO_ETH"] = "TC-ERC20";
1155
+ QuoteMode2["TC_SUPPORTED_TO_AVAX"] = "TC-ARC20";
1156
+ QuoteMode2["TC_SUPPORTED_TO_BSC"] = "TC-BEP20";
1157
+ QuoteMode2["ETH_TO_TC_SUPPORTED"] = "ERC20-TC";
1158
+ QuoteMode2["ETH_TO_ETH"] = "ERC20-ERC20";
1159
+ QuoteMode2["ETH_TO_AVAX"] = "ERC20-ARC20";
1160
+ QuoteMode2["ETH_TO_BSC"] = "ERC20-BEP20";
1161
+ QuoteMode2["AVAX_TO_TC_SUPPORTED"] = "ARC20-TC";
1162
+ QuoteMode2["AVAX_TO_ETH"] = "ARC20-ERC20";
1163
+ QuoteMode2["AVAX_TO_AVAX"] = "ARC20-ARC20";
1164
+ QuoteMode2["AVAX_TO_BSC"] = "ARC20-BEP20";
1165
+ QuoteMode2["BSC_TO_TC_SUPPORTED"] = "BEP20-TC";
1166
+ QuoteMode2["BSC_TO_ETH"] = "BEP20-ERC20";
1167
+ QuoteMode2["BSC_TO_AVAX"] = "BEP20-ARC20";
1168
+ QuoteMode2["BSC_TO_BSC"] = "BEP20-BEP20";
1169
+ })(QuoteMode || (QuoteMode = {}));
1170
+ var AGG_SWAP = [QuoteMode.ETH_TO_ETH, QuoteMode.AVAX_TO_AVAX, QuoteMode.BSC_TO_BSC];
1171
+ var SWAP_IN = [
1172
+ QuoteMode.ETH_TO_TC_SUPPORTED,
1173
+ QuoteMode.ETH_TO_AVAX,
1174
+ QuoteMode.ETH_TO_BSC,
1175
+ QuoteMode.AVAX_TO_TC_SUPPORTED,
1176
+ QuoteMode.AVAX_TO_ETH,
1177
+ QuoteMode.AVAX_TO_BSC,
1178
+ QuoteMode.BSC_TO_TC_SUPPORTED,
1179
+ QuoteMode.BSC_TO_ETH,
1180
+ QuoteMode.BSC_TO_AVAX
1181
+ ];
1182
+ var SWAP_OUT = [
1183
+ QuoteMode.TC_SUPPORTED_TO_TC_SUPPORTED,
1184
+ QuoteMode.TC_SUPPORTED_TO_ETH,
1185
+ QuoteMode.TC_SUPPORTED_TO_AVAX,
1186
+ QuoteMode.TC_SUPPORTED_TO_BSC
1187
+ ];
1188
+ // src/types/derivationPath.ts
1189
+ var ContractAddress;
1190
+ (function(ContractAddress2) {
1191
+ ContractAddress2["ARB"] = "0x0000000000000000000000000000000000000000";
1192
+ ContractAddress2["AVAX"] = "0x0000000000000000000000000000000000000000";
1193
+ ContractAddress2["ETH"] = "0x0000000000000000000000000000000000000000";
1194
+ ContractAddress2["BSC"] = "0x0000000000000000000000000000000000000000";
1195
+ ContractAddress2["MATIC"] = "0x0000000000000000000000000000000000001010";
1196
+ ContractAddress2["OP"] = "0x4200000000000000000000000000000000000042";
1197
+ })(ContractAddress || (ContractAddress = {}));
1198
+ var DerivationPath;
1199
+ (function(DerivationPath2) {
1200
+ DerivationPath2["ARB"] = "m/44'/60'/0'/0";
1201
+ DerivationPath2["AVAX"] = "m/44'/60'/0'/0";
1202
+ DerivationPath2["BCH"] = "m/44'/145'/0'/0";
1203
+ DerivationPath2["BNB"] = "m/44'/714'/0'/0";
1204
+ DerivationPath2["BSC"] = "m/44'/60'/0'/0";
1205
+ DerivationPath2["BTC"] = "m/84'/0'/0'/0";
1206
+ DerivationPath2["DASH"] = "m/44'/5'/0'/0";
1207
+ DerivationPath2["DOGE"] = "m/44'/3'/0'/0";
1208
+ DerivationPath2["DOT"] = "////";
1209
+ DerivationPath2["ETH"] = "m/44'/60'/0'/0";
1210
+ DerivationPath2["FLIP"] = "////";
1211
+ DerivationPath2["GAIA"] = "m/44'/118'/0'/0";
1212
+ DerivationPath2["KUJI"] = "m/44'/118'/0'/0";
1213
+ DerivationPath2["LTC"] = "m/84'/2'/0'/0";
1214
+ DerivationPath2["MATIC"] = "m/44'/60'/0'/0";
1215
+ DerivationPath2["MAYA"] = "m/44'/931'/0'/0";
1216
+ DerivationPath2["OP"] = "m/44'/60'/0'/0";
1217
+ DerivationPath2["THOR"] = "m/44'/931'/0'/0";
1218
+ })(DerivationPath || (DerivationPath = {}));
1219
+ var NetworkDerivationPath = {
1220
+ ARB: [44, 60, 0, 0, 0],
1221
+ AVAX: [44, 60, 0, 0, 0],
1222
+ BCH: [44, 145, 0, 0, 0],
1223
+ BNB: [44, 714, 0, 0, 0],
1224
+ BSC: [44, 60, 0, 0, 0],
1225
+ BTC: [84, 0, 0, 0, 0],
1226
+ DASH: [44, 5, 0, 0, 0],
1227
+ DOGE: [44, 3, 0, 0, 0],
1228
+ ETH: [44, 60, 0, 0, 0],
1229
+ GAIA: [44, 118, 0, 0, 0],
1230
+ KUJI: [44, 118, 0, 0, 0],
1231
+ LTC: [84, 2, 0, 0, 0],
1232
+ MATIC: [44, 60, 0, 0, 0],
1233
+ MAYA: [44, 931, 0, 0, 0],
1234
+ OP: [44, 60, 0, 0, 0],
1235
+ THOR: [44, 931, 0, 0, 0],
1236
+ DOT: [0, 0, 0, 0, 0],
1237
+ FLIP: [0, 0, 0, 0, 0]
1238
+ };
1239
+ // src/types/wallet.ts
1240
+ var WalletOption;
1241
+ (function(WalletOption2) {
1242
+ WalletOption2["KEYSTORE"] = "KEYSTORE";
1243
+ WalletOption2["KEEPKEY"] = "KEEPKEY";
1244
+ WalletOption2["XDEFI"] = "XDEFI";
1245
+ WalletOption2["METAMASK"] = "METAMASK";
1246
+ WalletOption2["COINBASE_WEB"] = "COINBASE_WEB";
1247
+ WalletOption2["COINBASE_MOBILE"] = "COINBASE_MOBILE";
1248
+ WalletOption2["TREZOR"] = "TREZOR";
1249
+ WalletOption2["TRUSTWALLET_WEB"] = "TRUSTWALLET_WEB";
1250
+ WalletOption2["LEDGER"] = "LEDGER";
1251
+ WalletOption2["KEPLR"] = "KEPLR";
1252
+ WalletOption2["OKX"] = "OKX";
1253
+ WalletOption2["OKX_MOBILE"] = "OKX_MOBILE";
1254
+ WalletOption2["BRAVE"] = "BRAVE";
1255
+ WalletOption2["WALLETCONNECT"] = "WALLETCONNECT";
1256
+ })(WalletOption || (WalletOption = {}));
1257
+ var LedgerErrorCode;
1258
+ (function(LedgerErrorCode2) {
1259
+ LedgerErrorCode2[LedgerErrorCode2["NoError"] = 36864] = "NoError";
1260
+ LedgerErrorCode2[LedgerErrorCode2["LockedDevice"] = 21781] = "LockedDevice";
1261
+ LedgerErrorCode2[LedgerErrorCode2["TC_NotFound"] = 65535] = "TC_NotFound";
1262
+ })(LedgerErrorCode || (LedgerErrorCode = {}));
1263
+ // src/types/sdk.ts
1264
+ var FeeOption;
1265
+ (function(FeeOption2) {
1266
+ FeeOption2["Average"] = "average";
1267
+ FeeOption2["Fast"] = "fast";
1268
+ FeeOption2["Fastest"] = "fastest";
1269
+ })(FeeOption || (FeeOption = {}));
1270
+ var ApproveMode;
1271
+ (function(ApproveMode2) {
1272
+ ApproveMode2["Approve"] = "approve";
1273
+ ApproveMode2["CheckOnly"] = "checkOnly";
1274
+ })(ApproveMode || (ApproveMode = {}));
1275
+ var MemoType;
1276
+ (function(MemoType2) {
1277
+ MemoType2["BOND"] = "BOND";
1278
+ MemoType2["DEPOSIT"] = "+";
1279
+ MemoType2["LEAVE"] = "LEAVE";
1280
+ MemoType2["THORNAME_REGISTER"] = "~";
1281
+ MemoType2["UNBOND"] = "UNBOND";
1282
+ MemoType2["WITHDRAW"] = "-";
1283
+ MemoType2["OPEN_LOAN"] = "$+";
1284
+ MemoType2["CLOSE_LOAN"] = "$-";
1285
+ })(MemoType || (MemoType = {}));
1286
+ // src/modules/requestClient.ts
1287
+ import ky from "ky";
1288
+ function setRequestClientConfig({ apiKey, ...config }) {
1289
+ kyClient = ky.create({
1290
+ ...config,
1291
+ headers: { ...defaultRequestHeaders, ...config.headers, "x-api-key": apiKey }
1292
+ });
1293
+ }
1294
+ var getKyClient = function() {
1295
+ if (kyClient)
1296
+ return kyClient;
1297
+ kyClient = ky.create({ headers: defaultRequestHeaders });
1298
+ return kyClient;
1299
+ };
1300
+ var kyClient;
1301
+ var defaultRequestHeaders = typeof window !== "undefined" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" };
1302
+ var getTypedBaseRequestClient = (kyClient2) => ({
1303
+ get: (url, options) => kyClient2.get(url, options).json(),
1304
+ post: (url, options) => kyClient2.post(url, options).json()
1305
+ });
1306
+ var RequestClient = {
1307
+ ...getTypedBaseRequestClient(getKyClient()),
1308
+ extend: (options) => {
1309
+ const extendedClient = getKyClient().extend(options);
1310
+ return {
1311
+ ...getTypedBaseRequestClient(extendedClient),
1312
+ extend: RequestClient.extend
1313
+ };
1314
+ }
1315
+ };
1316
+
1317
+ // src/helpers/asset.ts
1318
+ async function findAssetBy(params) {
1319
+ const tokenPackages = await import("@swapkit/tokens");
1320
+ for (const tokenList of Object.values(tokenPackages)) {
1321
+ for (const { identifier, chain: tokenChain, ...rest } of tokenList.tokens) {
1322
+ if ("identifier" in params && identifier === params.identifier) {
1323
+ return identifier;
1324
+ }
1325
+ if ("address" in rest && "chain" in params && tokenChain === params.chain && rest.address.toLowerCase() === params.contract.toLowerCase())
1326
+ return identifier;
1327
+ }
1328
+ }
1329
+ return;
1330
+ }
1331
+ var getDecimalMethodHex = "0x313ce567";
1332
+ var getContractDecimals = async ({ chain, to }) => {
1333
+ try {
1334
+ const { result } = await RequestClient.post(ChainToRPC[chain], {
1335
+ headers: {
1336
+ accept: "*/*",
1337
+ "content-type": "application/json",
1338
+ "cache-control": "no-cache"
1339
+ },
1340
+ body: JSON.stringify({
1341
+ id: 44,
1342
+ jsonrpc: "2.0",
1343
+ method: "eth_call",
1344
+ params: [{ to: to.toLowerCase(), data: getDecimalMethodHex }, "latest"]
1345
+ })
1346
+ });
1347
+ return Number.parseInt(BigInt(result || BaseDecimal[chain]).toString());
1348
+ } catch (error) {
1349
+ console.error(error);
1350
+ return BaseDecimal[chain];
1351
+ }
1352
+ };
1353
+ var getETHAssetDecimal = (symbol) => {
1354
+ if (symbol === Chain.Ethereum)
1355
+ return BaseDecimal.ETH;
1356
+ const splitSymbol = symbol.split("-");
1357
+ const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
1358
+ return address?.startsWith("0x") ? getContractDecimals({ chain: Chain.Ethereum, to: address }) : BaseDecimal.ETH;
1359
+ };
1360
+ var getAVAXAssetDecimal = (symbol) => {
1361
+ const splitSymbol = symbol.split("-");
1362
+ const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
1363
+ return address?.startsWith("0x") ? getContractDecimals({ chain: Chain.Avalanche, to: address.toLowerCase() }) : BaseDecimal.AVAX;
1364
+ };
1365
+ var getBSCAssetDecimal = (symbol) => {
1366
+ if (symbol === Chain.BinanceSmartChain)
1367
+ return BaseDecimal.BSC;
1368
+ return BaseDecimal.BSC;
1369
+ };
1370
+ var getDecimal = ({ chain, symbol }) => {
1371
+ switch (chain) {
1372
+ case Chain.Ethereum:
1373
+ return getETHAssetDecimal(symbol);
1374
+ case Chain.Avalanche:
1375
+ return getAVAXAssetDecimal(symbol);
1376
+ case Chain.BinanceSmartChain:
1377
+ return getBSCAssetDecimal(symbol);
1378
+ default:
1379
+ return BaseDecimal[chain];
1380
+ }
1381
+ };
1382
+ var isGasAsset = ({ chain, symbol }) => {
1383
+ switch (chain) {
1384
+ case Chain.Arbitrum:
1385
+ case Chain.Optimism:
1386
+ return symbol === "ETH";
1387
+ case Chain.Maya:
1388
+ return symbol === "CACAO";
1389
+ case Chain.Kujira:
1390
+ return symbol === "KUJI";
1391
+ case Chain.Cosmos:
1392
+ return symbol === "ATOM";
1393
+ case Chain.Polygon:
1394
+ return symbol === "MATIC";
1395
+ case Chain.BinanceSmartChain:
1396
+ return symbol === "BNB";
1397
+ case Chain.THORChain:
1398
+ return symbol === "RUNE";
1399
+ default:
1400
+ return symbol === chain;
1401
+ }
1402
+ };
1403
+ var getCommonAssetInfo = (assetString) => {
1404
+ switch (assetString) {
1405
+ case `${Chain.Ethereum}.THOR`:
1406
+ return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
1407
+ case `${Chain.Ethereum}.vTHOR`:
1408
+ return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
1409
+ case Chain.Arbitrum:
1410
+ return { identifier: `${Chain.Arbitrum}.ETH`, decimal: BaseDecimal[assetString] };
1411
+ case Chain.Optimism:
1412
+ return { identifier: `${Chain.Optimism}.ETH`, decimal: BaseDecimal[assetString] };
1413
+ case Chain.Cosmos:
1414
+ return { identifier: "GAIA.ATOM", decimal: BaseDecimal[assetString] };
1415
+ case Chain.THORChain:
1416
+ return { identifier: "THOR.RUNE", decimal: BaseDecimal[assetString] };
1417
+ case Chain.BinanceSmartChain:
1418
+ return { identifier: "BSC.BNB", decimal: BaseDecimal[assetString] };
1419
+ case Chain.Maya:
1420
+ return { identifier: "MAYA.CACAO", decimal: BaseDecimal.MAYA };
1421
+ case `${Chain.Maya}.MAYA`:
1422
+ return { identifier: "MAYA.MAYA", decimal: 4 };
1423
+ case `${Chain.Kujira}.USK`:
1424
+ return { identifier: `${Chain.Kujira}.USK`, decimal: 6 };
1425
+ default:
1426
+ return { identifier: `${assetString}.${assetString}`, decimal: BaseDecimal[assetString] };
1427
+ }
1428
+ };
1429
+ var getAssetType = ({ chain, symbol }) => {
1430
+ if (symbol.includes("/"))
1431
+ return "Synth";
1432
+ switch (chain) {
1433
+ case Chain.Cosmos:
1434
+ return symbol === "ATOM" ? "Native" : Chain.Cosmos;
1435
+ case Chain.Kujira:
1436
+ return symbol === Chain.Kujira ? "Native" : Chain.Kujira;
1437
+ case Chain.Binance:
1438
+ return symbol === Chain.Binance ? "Native" : "BEP2";
1439
+ case Chain.BinanceSmartChain:
1440
+ return symbol === Chain.Binance ? "Native" : "BEP20";
1441
+ case Chain.Ethereum:
1442
+ return symbol === Chain.Ethereum ? "Native" : "ERC20";
1443
+ case Chain.Avalanche:
1444
+ return symbol === Chain.Avalanche ? "Native" : Chain.Avalanche;
1445
+ case Chain.Polygon:
1446
+ return symbol === Chain.Polygon ? "Native" : "POLYGON";
1447
+ case Chain.Arbitrum:
1448
+ return [Chain.Ethereum, Chain.Arbitrum].includes(symbol) ? "Native" : "ARBITRUM";
1449
+ case Chain.Optimism:
1450
+ return [Chain.Ethereum, Chain.Optimism].includes(symbol) ? "Native" : "OPTIMISM";
1451
+ default:
1452
+ return "Native";
1453
+ }
1454
+ };
1455
+ var assetFromString = (assetString) => {
1456
+ const [chain, ...symbolArray] = assetString.split(".");
1457
+ const synth = assetString.includes("/");
1458
+ const symbol = symbolArray.join(".");
1459
+ const splitSymbol = symbol?.split("-");
1460
+ const ticker = splitSymbol?.length ? splitSymbol.length === 1 ? splitSymbol[0] : splitSymbol.slice(0, -1).join("-") : undefined;
1461
+ return { chain, symbol, ticker, synth };
1462
+ };
1463
+ var potentialScamRegex = new RegExp(/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/, "gmi");
1464
+ var evmAssetHasAddress = (assetString) => {
1465
+ const [chain, symbol] = assetString.split(".");
1466
+ if (!EVMChains.includes(chain))
1467
+ return true;
1468
+ const splitSymbol = symbol.split("-");
1469
+ const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
1470
+ return isGasAsset({ chain, symbol }) || !!address;
1471
+ };
1472
+ var filterAssets = (tokens2) => tokens2.filter(({ chain, value, symbol }) => {
1473
+ const assetString = `${chain}.${symbol}`;
1474
+ return !potentialScamRegex.test(assetString) && evmAssetHasAddress(assetString) && value !== "0";
1475
+ });
1476
+ // src/helpers/derivationPath.ts
1477
+ function getDerivationPathFor({ chain, index, addressIndex = 0, type }) {
1478
+ if (EVMChains.includes(chain)) {
1479
+ if (type === "legacy")
1480
+ return [44, 60, 0, index];
1481
+ if (type === "ledgerLive")
1482
+ return [44, 60, index, 0, addressIndex];
1483
+ return updatedLastIndex(NetworkDerivationPath[chain], index);
1484
+ }
1485
+ if ([Chain.Bitcoin, Chain.Litecoin].includes(chain)) {
1486
+ const chainId = chain === Chain.Bitcoin ? 0 : 2;
1487
+ if (type === "nativeSegwitMiddleAccount")
1488
+ return [84, chainId, index, 0, addressIndex];
1489
+ if (type === "segwit")
1490
+ return [49, chainId, 0, 0, index];
1491
+ if (type === "legacy")
1492
+ return [44, chainId, 0, 0, index];
1493
+ return updatedLastIndex(NetworkDerivationPath[chain], index);
1494
+ }
1495
+ return updatedLastIndex(NetworkDerivationPath[chain], index);
1496
+ }
1497
+ function getWalletFormatFor(path) {
1498
+ const [_, purpose, chainId] = path.split("/").map((p) => Number.parseInt(p, 10));
1499
+ if (chainId === 145)
1500
+ ;
1501
+ switch (purpose) {
1502
+ case 44:
1503
+ return "legacy";
1504
+ case 49:
1505
+ return "p2sh";
1506
+ default:
1507
+ return "bech32";
1508
+ }
1509
+ }
1510
+ var updatedLastIndex = (path, index) => [
1511
+ ...path.slice(0, path.length - 1),
1512
+ index
1513
+ ];
1514
+ // src/helpers/liquidity.ts
1515
+ function getAsymmetricRuneShare({
1516
+ liquidityUnits,
1517
+ poolUnits,
1518
+ runeDepth
1519
+ }) {
1520
+ const s = toTCSwapKitNumber(liquidityUnits);
1521
+ const T = toTCSwapKitNumber(poolUnits);
1522
+ const A = toTCSwapKitNumber(runeDepth);
1523
+ const part1 = s.mul(A);
1524
+ const part2 = T.mul(T).mul(2);
1525
+ const part3 = T.mul(s).mul(2);
1526
+ const part4 = s.mul(s);
1527
+ const part5 = T.mul(T).mul(T);
1528
+ const numerator = part1.mul(part2.sub(part3).add(part4));
1529
+ return numerator.div(part5);
1530
+ }
1531
+ function getAsymmetricAssetShare({
1532
+ liquidityUnits,
1533
+ poolUnits,
1534
+ assetDepth
1535
+ }) {
1536
+ const s = toTCSwapKitNumber(liquidityUnits);
1537
+ const T = toTCSwapKitNumber(poolUnits);
1538
+ const A = toTCSwapKitNumber(assetDepth);
1539
+ const part1 = s.mul(A);
1540
+ const part2 = T.mul(T).mul(2);
1541
+ const part3 = T.mul(s).mul(2);
1542
+ const part4 = s.mul(s);
1543
+ const numerator = part1.mul(part2.sub(part3).add(part4));
1544
+ const part5 = T.mul(T).mul(T);
1545
+ return numerator.div(part5);
1546
+ }
1547
+ function getAsymmetricRuneWithdrawAmount({
1548
+ percent,
1549
+ runeDepth,
1550
+ liquidityUnits,
1551
+ poolUnits
1552
+ }) {
1553
+ return getAsymmetricRuneShare({ runeDepth, liquidityUnits, poolUnits }).mul(percent);
1554
+ }
1555
+ function getAsymmetricAssetWithdrawAmount({
1556
+ percent,
1557
+ assetDepth,
1558
+ liquidityUnits,
1559
+ poolUnits
1560
+ }) {
1561
+ return getAsymmetricAssetShare({ assetDepth, liquidityUnits, poolUnits }).mul(percent);
1562
+ }
1563
+ var toTCSwapKitNumber = function(value) {
1564
+ return SwapKitNumber.fromBigInt(BigInt(value), BaseDecimal.THOR);
1565
+ };
1566
+ function getSymmetricPoolShare({
1567
+ liquidityUnits,
1568
+ poolUnits,
1569
+ runeDepth,
1570
+ assetDepth
1571
+ }) {
1572
+ return {
1573
+ assetAmount: toTCSwapKitNumber(assetDepth).mul(liquidityUnits).div(poolUnits),
1574
+ runeAmount: toTCSwapKitNumber(runeDepth).mul(liquidityUnits).div(poolUnits)
1575
+ };
1576
+ }
1577
+ function getSymmetricWithdraw({
1578
+ liquidityUnits,
1579
+ poolUnits,
1580
+ runeDepth,
1581
+ assetDepth,
1582
+ percent
1583
+ }) {
1584
+ return Object.fromEntries(Object.entries(getSymmetricPoolShare({ liquidityUnits, poolUnits, runeDepth, assetDepth })).map(([name, value]) => [name, value.mul(percent)]));
1585
+ }
1586
+ function getEstimatedPoolShare({
1587
+ runeDepth,
1588
+ poolUnits,
1589
+ assetDepth,
1590
+ liquidityUnits,
1591
+ runeAmount,
1592
+ assetAmount
1593
+ }) {
1594
+ const R = new SwapKitNumber({ value: runeDepth, decimal: 8 });
1595
+ const A = new SwapKitNumber({ value: assetDepth, decimal: 8 });
1596
+ const P = new SwapKitNumber({ value: poolUnits, decimal: 8 });
1597
+ const runeAddAmount = new SwapKitNumber({ value: runeAmount, decimal: 8 });
1598
+ const assetAddAmount = new SwapKitNumber({ value: assetAmount, decimal: 8 });
1599
+ const rA = runeAddAmount.mul(A);
1600
+ const aR = assetAddAmount.mul(R);
1601
+ const ra = runeAddAmount.mul(assetAddAmount);
1602
+ const RA = R.mul(A);
1603
+ const numerator = P.mul(rA.add(aR.add(ra.mul(2))));
1604
+ const denominator = rA.add(aR.add(RA.mul(2)));
1605
+ const liquidityUnitsAfterAdd = numerator.div(denominator);
1606
+ const estimatedLiquidityUnits = toTCSwapKitNumber(liquidityUnits).add(liquidityUnitsAfterAdd);
1607
+ if (liquidityUnitsAfterAdd.getBaseValue("number") === 0) {
1608
+ return estimatedLiquidityUnits.div(P).getBaseValue("number");
1609
+ }
1610
+ const newPoolUnits = P.add(estimatedLiquidityUnits);
1611
+ return estimatedLiquidityUnits.div(newPoolUnits).getBaseValue("number");
1612
+ }
1613
+ function getLiquiditySlippage({
1614
+ runeAmount,
1615
+ assetAmount,
1616
+ runeDepth,
1617
+ assetDepth
1618
+ }) {
1619
+ if (runeAmount === "0" || assetAmount === "0" || runeDepth === "0" || assetDepth === "0")
1620
+ return 0;
1621
+ const R = toTCSwapKitNumber(runeDepth);
1622
+ const T = toTCSwapKitNumber(assetDepth);
1623
+ const assetAddAmount = toTCSwapKitNumber(assetAmount);
1624
+ const runeAddAmount = toTCSwapKitNumber(runeAmount);
1625
+ const numerator = assetAddAmount.mul(R).sub(T.mul(runeAddAmount));
1626
+ const denominator = T.mul(runeAddAmount).add(R.mul(T));
1627
+ return Math.abs(numerator.div(denominator).getBaseValue("number"));
1628
+ }
1629
+ // src/helpers/memo.ts
1630
+ var getMemoFor = (memoType, options) => {
1631
+ switch (memoType) {
1632
+ case MemoType.LEAVE:
1633
+ case MemoType.BOND: {
1634
+ const { address } = options;
1635
+ return `${memoType}:${address}`;
1636
+ }
1637
+ case MemoType.UNBOND: {
1638
+ const { address, unbondAmount } = options;
1639
+ return `${memoType}:${address}:${unbondAmount}`;
1640
+ }
1641
+ case MemoType.THORNAME_REGISTER: {
1642
+ const { name, chain, address, owner } = options;
1643
+ return `${memoType}:${name}:${chain}:${address}${owner ? `:${owner}` : ""}`;
1644
+ }
1645
+ case MemoType.DEPOSIT: {
1646
+ const { chain, symbol, address, singleSide } = options;
1647
+ const getPoolIdentifier = (chain2, symbol2) => {
1648
+ switch (chain2) {
1649
+ case Chain.Litecoin:
1650
+ return "l";
1651
+ case Chain.Dogecoin:
1652
+ return "d";
1653
+ case Chain.BitcoinCash:
1654
+ return "c";
1655
+ default:
1656
+ return `${chain2}.${symbol2}`;
1657
+ }
1658
+ };
1659
+ return singleSide ? `${memoType}:${chain}/${symbol}` : `${memoType}:${getPoolIdentifier(chain, symbol)}:${address || ""}`;
1660
+ }
1661
+ case MemoType.WITHDRAW: {
1662
+ const { chain, ticker, symbol, basisPoints, targetAssetString, singleSide } = options;
1663
+ const shortenedSymbol = chain === "ETH" && ticker !== "ETH" ? `${ticker}-${symbol.slice(-3)}` : symbol;
1664
+ const target = !singleSide && targetAssetString ? `:${targetAssetString}` : "";
1665
+ const assetDivider = singleSide ? "/" : ".";
1666
+ return `${memoType}:${chain}${assetDivider}${shortenedSymbol}:${basisPoints}${target}`;
1667
+ }
1668
+ case MemoType.OPEN_LOAN:
1669
+ case MemoType.CLOSE_LOAN: {
1670
+ const { asset, address } = options;
1671
+ return `${memoType}:${asset}:${address}`;
1672
+ }
1673
+ default:
1674
+ return "";
1675
+ }
1676
+ };
1677
+ // src/modules/swapKitError.ts
1678
+ var errorMessages = {
1679
+ core_wallet_connection_not_found: 10001,
1680
+ core_estimated_max_spendable_chain_not_supported: 10002,
1681
+ core_extend_error: 10003,
1682
+ core_inbound_data_not_found: 10004,
1683
+ core_approve_asset_address_or_from_not_found: 10005,
1684
+ core_plugin_not_found: 10006,
1685
+ core_plugin_swap_not_found: 10007,
1686
+ core_approve_asset_target_invalid: 10008,
1687
+ core_chain_halted: 10099,
1688
+ core_wallet_xdefi_not_installed: 10101,
1689
+ core_wallet_evmwallet_not_installed: 10102,
1690
+ core_wallet_walletconnect_not_installed: 10103,
1691
+ core_wallet_keystore_not_installed: 10104,
1692
+ core_wallet_ledger_not_installed: 10105,
1693
+ core_wallet_trezor_not_installed: 10106,
1694
+ core_wallet_keplr_not_installed: 10107,
1695
+ core_wallet_okx_not_installed: 10108,
1696
+ core_wallet_keepkey_not_installed: 10109,
1697
+ core_swap_invalid_params: 10200,
1698
+ core_swap_route_not_complete: 10201,
1699
+ core_swap_asset_not_recognized: 10202,
1700
+ core_swap_contract_not_found: 10203,
1701
+ core_swap_route_transaction_not_found: 10204,
1702
+ core_swap_contract_not_supported: 10205,
1703
+ core_swap_transaction_error: 10206,
1704
+ core_swap_quote_mode_not_supported: 10207,
1705
+ core_transaction_deposit_error: 10301,
1706
+ core_transaction_create_liquidity_rune_error: 10302,
1707
+ core_transaction_create_liquidity_asset_error: 10303,
1708
+ core_transaction_create_liquidity_invalid_params: 10304,
1709
+ core_transaction_add_liquidity_invalid_params: 10305,
1710
+ core_transaction_add_liquidity_no_rune_address: 10306,
1711
+ core_transaction_add_liquidity_rune_error: 10307,
1712
+ core_transaction_add_liquidity_asset_error: 10308,
1713
+ core_transaction_withdraw_error: 10309,
1714
+ core_transaction_deposit_to_pool_error: 10310,
1715
+ core_transaction_deposit_insufficient_funds_error: 10311,
1716
+ core_transaction_deposit_gas_error: 10312,
1717
+ core_transaction_invalid_sender_address: 10313,
1718
+ core_transaction_deposit_server_error: 10314,
1719
+ core_transaction_user_rejected: 10315,
1720
+ wallet_ledger_connection_error: 20001,
1721
+ wallet_ledger_connection_claimed: 20002,
1722
+ wallet_ledger_get_address_error: 20003,
1723
+ wallet_ledger_device_not_found: 20004,
1724
+ wallet_ledger_device_locked: 20005,
1725
+ chainflip_channel_error: 30001,
1726
+ chainflip_broker_recipient_error: 30002,
1727
+ helpers_number_different_decimals: 99101
1728
+ };
1729
+
1730
+ class SwapKitError extends Error {
1731
+ constructor(errorKey, sourceError) {
1732
+ if (sourceError) {
1733
+ console.error(sourceError, {
1734
+ stack: sourceError?.stack,
1735
+ message: sourceError?.message
1736
+ });
1737
+ }
1738
+ super(errorKey, {
1739
+ cause: { code: errorMessages[errorKey], message: errorKey }
1740
+ });
1741
+ Object.setPrototypeOf(this, SwapKitError.prototype);
1742
+ }
1743
+ }
1744
+
1745
+ // src/helpers/others.ts
1746
+ function getTHORNameCost(numberOfYears) {
1747
+ if (numberOfYears < 0)
1748
+ throw new Error("Invalid number of years");
1749
+ return 10 + numberOfYears;
1750
+ }
1751
+ function getMAYANameCost(numberOfYears) {
1752
+ if (numberOfYears < 0)
1753
+ throw new Error("Invalid number of year");
1754
+ return Math.round((10 + numberOfYears * 1.0512) * 10000000000) / 10000000000;
1755
+ }
1756
+ function derivationPathToString([network3, chainId, account, change, index]) {
1757
+ const shortPath = typeof index !== "number";
1758
+ return `m/${network3}'/${chainId}'/${account}'/${change}${shortPath ? "" : `/${index}`}`;
1759
+ }
1760
+ function wrapWithThrow(fn, errorKey) {
1761
+ try {
1762
+ return fn();
1763
+ } catch (error) {
1764
+ if (errorKey) {
1765
+ throw new SwapKitError(errorKey, error);
1766
+ }
1767
+ return console.error(error);
1768
+ }
1769
+ }
1770
+ // src/helpers/validators.ts
1771
+ function validateIdentifier(identifier = "") {
1772
+ const uppercasedIdentifier = identifier.toUpperCase();
1773
+ const [chain] = uppercasedIdentifier.split(".");
1774
+ if (supportedChains.includes(chain))
1775
+ return true;
1776
+ const [synthChain] = uppercasedIdentifier.split("/");
1777
+ if (supportedChains.includes(synthChain))
1778
+ return true;
1779
+ throw new Error(`Invalid identifier: ${identifier}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`);
1780
+ }
1781
+ function validateTNS(name) {
1782
+ if (name.length > 30)
1783
+ return false;
1784
+ const regex = /^[a-zA-Z0-9+_-]+$/g;
1785
+ return !!name.match(regex);
1786
+ }
1787
+ var supportedChains = [...Object.values(Chain), "TERRA"];
1788
+ // src/helpers/web3wallets.ts
1789
+ var methodsToWrap = [
1790
+ "approve",
1791
+ "approvedAmount",
1792
+ "call",
1793
+ "sendTransaction",
1794
+ "transfer",
1795
+ "isApproved",
1796
+ "approvedAmount",
1797
+ "EIP1193SendTransaction",
1798
+ "getFeeData",
1799
+ "broadcastTransaction",
1800
+ "estimateCall",
1801
+ "estimateGasLimit",
1802
+ "estimateGasPrices",
1803
+ "createContractTxObject"
1804
+ ];
1805
+ var wrapMethodWithNetworkSwitch = (func, provider, chainId) => async (...args) => {
1806
+ try {
1807
+ await switchEVMWalletNetwork(provider, chainId);
1808
+ } catch (error) {
1809
+ throw new Error(`Failed to switch network: ${error}`);
1810
+ }
1811
+ return func(...args);
1812
+ };
1813
+ var providerRequest = ({ provider, params, method }) => {
1814
+ if (!provider?.send)
1815
+ throw new Error("Provider not found");
1816
+ const providerParams = params ? Array.isArray(params) ? params : [params] : [];
1817
+ return provider.send(method, providerParams);
1818
+ };
1819
+ var prepareNetworkSwitch = ({
1820
+ toolbox,
1821
+ chainId,
1822
+ provider = window.ethereum
1823
+ }) => {
1824
+ const wrappedMethods = methodsToWrap.reduce((object, methodName) => {
1825
+ if (!toolbox[methodName])
1826
+ return object;
1827
+ const method = toolbox[methodName];
1828
+ if (typeof method !== "function")
1829
+ return object;
1830
+ return {
1831
+ ...object,
1832
+ [methodName]: wrapMethodWithNetworkSwitch(method, provider, chainId)
1833
+ };
1834
+ }, {});
1835
+ return { ...toolbox, ...wrappedMethods };
1836
+ };
1837
+ var addEVMWalletNetwork = (provider, networkParams) => providerRequest({ provider, method: "wallet_addEthereumChain", params: [networkParams] });
1838
+ var switchEVMWalletNetwork = (provider, chainId = ChainId.EthereumHex) => providerRequest({ provider, method: "wallet_switchEthereumChain", params: [{ chainId }] });
1839
+ var addAccountsChangedCallback = (callback) => {
1840
+ window.ethereum?.on("accountsChanged", () => callback());
1841
+ window.xfi?.ethereum.on("accountsChanged", () => callback());
1842
+ };
1843
+ var getETHDefaultWallet = () => {
1844
+ const { isTrust, isBraveWallet, __XDEFI, overrideIsMetaMask, selectedProvider } = window?.ethereum || {};
1845
+ if (isTrust)
1846
+ return WalletOption.TRUSTWALLET_WEB;
1847
+ if (isBraveWallet)
1848
+ return WalletOption.BRAVE;
1849
+ if (overrideIsMetaMask && selectedProvider?.isCoinbaseWallet)
1850
+ return WalletOption.COINBASE_WEB;
1851
+ if (__XDEFI)
1852
+ WalletOption.XDEFI;
1853
+ return WalletOption.METAMASK;
1854
+ };
1855
+ var isDetected = (walletOption) => {
1856
+ return listWeb3EVMWallets().includes(walletOption);
1857
+ };
1858
+ var listWeb3EVMWallets = () => {
1859
+ const metamaskEnabled = window?.ethereum && !window.ethereum?.isBraveWallet;
1860
+ const xdefiEnabled = window?.xfi || window?.ethereum?.__XDEFI;
1861
+ const braveEnabled = window?.ethereum?.isBraveWallet;
1862
+ const trustEnabled = window?.ethereum?.isTrust || window?.trustwallet;
1863
+ const coinbaseEnabled = window?.ethereum?.overrideIsMetaMask && window?.ethereum?.selectedProvider?.isCoinbaseWallet || window?.coinbaseWalletExtension;
1864
+ const wallets = [];
1865
+ if (metamaskEnabled)
1866
+ wallets.push(WalletOption.METAMASK);
1867
+ if (xdefiEnabled)
1868
+ wallets.push(WalletOption.XDEFI);
1869
+ if (braveEnabled)
1870
+ wallets.push(WalletOption.BRAVE);
1871
+ if (trustEnabled)
1872
+ wallets.push(WalletOption.TRUSTWALLET_WEB);
1873
+ if (coinbaseEnabled)
1874
+ wallets.push(WalletOption.COINBASE_WEB);
1875
+ if (okxMobileEnabled())
1876
+ wallets.push(WalletOption.OKX_MOBILE);
1877
+ return wallets;
1878
+ };
1879
+ var okxMobileEnabled = () => {
1880
+ const ua = navigator.userAgent;
1881
+ const isIOS = /iphone|ipad|ipod|ios/i.test(ua);
1882
+ const isAndroid = /android|XiaoMi|MiuiBrowser/i.test(ua);
1883
+ const isMobile = isIOS || isAndroid;
1884
+ const isOKApp = /OKApp/i.test(ua);
1885
+ return isMobile && isOKApp;
1886
+ };
1887
+ var isWeb3Detected = () => typeof window.ethereum !== "undefined";
1888
+ // src/modules/bigIntArithmetics.ts
1889
+ function formatBigIntToSafeValue({
1890
+ value,
1891
+ bigIntDecimal = DEFAULT_DECIMAL,
1892
+ decimal = DEFAULT_DECIMAL
1893
+ }) {
1894
+ if (decimal === 0)
1895
+ return value.toString();
1896
+ const isNegative = value < 0n;
1897
+ let valueString = value.toString().substring(isNegative ? 1 : 0);
1898
+ const padLength = decimal - (valueString.length - 1);
1899
+ if (padLength > 0) {
1900
+ valueString = "0".repeat(padLength) + valueString;
1901
+ }
1902
+ const decimalIndex = valueString.length - decimal;
1903
+ let decimalString = valueString.slice(-decimal);
1904
+ if (Number.parseInt(decimalString[bigIntDecimal] || "0") >= 5) {
1905
+ decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(Number.parseInt(decimalString[bigIntDecimal - 1] || "0") + 1).toString()}`;
1906
+ } else {
1907
+ decimalString = decimalString.substring(0, bigIntDecimal);
1908
+ }
1909
+ return `${isNegative ? "-" : ""}${valueString.slice(0, decimalIndex)}.${decimalString}`.replace(/\.?0*$/, "");
1910
+ }
1911
+ var toSafeValue = function(value) {
1912
+ const parsedValue = typeof value === "number" ? numberFormatter.format(value) : getStringValue(value);
1913
+ const splitValue = `${parsedValue}`.replaceAll(",", ".").split(".");
1914
+ return splitValue.length > 1 ? `${splitValue.slice(0, -1).join("")}.${splitValue.at(-1)}` : splitValue[0] || "0";
1915
+ };
1916
+ var getFloatDecimals = function(value) {
1917
+ const decimals = value.split(".")[1]?.length || 0;
1918
+ return Math.max(decimals, DEFAULT_DECIMAL);
1919
+ };
1920
+ var getStringValue = function(param) {
1921
+ return typeof param === "object" ? "getValue" in param ? param.getValue("string") : param.value : param;
1922
+ };
1923
+ var DEFAULT_DECIMAL = 8;
1924
+ var toMultiplier = (decimal) => 10n ** BigInt(decimal);
1925
+ var decimalFromMultiplier = (multiplier) => Math.log10(Number.parseFloat(multiplier.toString()));
1926
+
1927
+ class BigIntArithmetics {
1928
+ decimalMultiplier = 10n ** 8n;
1929
+ bigIntValue = 0n;
1930
+ decimal;
1931
+ static fromBigInt(value, decimal) {
1932
+ return new BigIntArithmetics({
1933
+ decimal,
1934
+ value: formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal })
1935
+ });
1936
+ }
1937
+ static shiftDecimals({
1938
+ value,
1939
+ from,
1940
+ to
1941
+ }) {
1942
+ return BigIntArithmetics.fromBigInt(value.getBaseValue("bigint") * toMultiplier(to) / toMultiplier(from), to);
1943
+ }
1944
+ constructor(params) {
1945
+ const value = getStringValue(params);
1946
+ const isComplex = typeof params === "object";
1947
+ this.decimal = isComplex ? params.decimal : undefined;
1948
+ this.decimalMultiplier = isComplex && "decimalMultiplier" in params ? params.decimalMultiplier : toMultiplier(Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0));
1949
+ this.#setValue(value);
1950
+ }
1951
+ set(value) {
1952
+ return new this.constructor({ decimal: this.decimal, value, identifier: this.toString() });
1953
+ }
1954
+ add(...args) {
1955
+ return this.#arithmetics("add", ...args);
1956
+ }
1957
+ sub(...args) {
1958
+ return this.#arithmetics("sub", ...args);
1959
+ }
1960
+ mul(...args) {
1961
+ return this.#arithmetics("mul", ...args);
1962
+ }
1963
+ div(...args) {
1964
+ return this.#arithmetics("div", ...args);
1965
+ }
1966
+ gt(value) {
1967
+ return this.#comparison("gt", value);
1968
+ }
1969
+ gte(value) {
1970
+ return this.#comparison("gte", value);
1971
+ }
1972
+ lt(value) {
1973
+ return this.#comparison("lt", value);
1974
+ }
1975
+ lte(value) {
1976
+ return this.#comparison("lte", value);
1977
+ }
1978
+ eqValue(value) {
1979
+ return this.#comparison("eqValue", value);
1980
+ }
1981
+ getValue(type) {
1982
+ const value = this.formatBigIntToSafeValue(this.bigIntValue, this.decimal || decimalFromMultiplier(this.decimalMultiplier));
1983
+ switch (type) {
1984
+ case "number":
1985
+ return Number(value);
1986
+ case "string":
1987
+ return value;
1988
+ case "bigint":
1989
+ return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
1990
+ }
1991
+ }
1992
+ getBaseValue(type) {
1993
+ const divisor = this.decimalMultiplier / toMultiplier(this.decimal || BaseDecimal.THOR);
1994
+ const baseValue = this.bigIntValue / divisor;
1995
+ switch (type) {
1996
+ case "number":
1997
+ return Number(baseValue);
1998
+ case "string":
1999
+ return baseValue.toString();
2000
+ case "bigint":
2001
+ return baseValue;
2002
+ }
2003
+ }
2004
+ getBigIntValue(value, decimal) {
2005
+ if (!decimal && typeof value === "object")
2006
+ return value.bigIntValue;
2007
+ const stringValue = getStringValue(value);
2008
+ const safeValue = toSafeValue(stringValue);
2009
+ if (safeValue === "0" || safeValue === "undefined")
2010
+ return 0n;
2011
+ return this.#toBigInt(safeValue, decimal);
2012
+ }
2013
+ toSignificant(significantDigits = 6) {
2014
+ const [int, dec] = this.getValue("string").split(".");
2015
+ const integer = int || "";
2016
+ const decimal = dec || "";
2017
+ const valueLength = Number.parseInt(integer) ? integer.length + decimal.length : decimal.length;
2018
+ if (valueLength <= significantDigits) {
2019
+ return this.getValue("string");
2020
+ }
2021
+ if (integer.length >= significantDigits) {
2022
+ return integer.slice(0, significantDigits).padEnd(integer.length, "0");
2023
+ }
2024
+ if (Number.parseInt(integer)) {
2025
+ return `${integer}.${decimal.slice(0, significantDigits - integer.length)}`.padEnd(significantDigits - integer.length, "0");
2026
+ }
2027
+ const trimmedDecimal = Number.parseInt(decimal);
2028
+ const slicedDecimal = `${trimmedDecimal}`.slice(0, significantDigits);
2029
+ return `0.${slicedDecimal.padStart(decimal.length - `${trimmedDecimal}`.length + slicedDecimal.length, "0")}`;
2030
+ }
2031
+ toFixed(fixedDigits = 6) {
2032
+ const [int, dec] = this.getValue("string").split(".");
2033
+ const integer = int || "";
2034
+ const decimal = dec || "";
2035
+ if (Number.parseInt(integer)) {
2036
+ return `${integer}.${decimal.slice(0, fixedDigits)}`.padEnd(fixedDigits, "0");
2037
+ }
2038
+ const trimmedDecimal = Number.parseInt(decimal);
2039
+ const slicedDecimal = `${trimmedDecimal}`.slice(0, fixedDigits);
2040
+ return `0.${slicedDecimal.padStart(decimal.length - `${trimmedDecimal}`.length + slicedDecimal.length, "0")}`;
2041
+ }
2042
+ toAbbreviation(digits = 2) {
2043
+ const value = this.getValue("number");
2044
+ const abbreviations = ["", "K", "M", "B", "T", "Q", "Qi", "S"];
2045
+ const tier = Math.floor(Math.log10(Math.abs(value)) / 3);
2046
+ const suffix = abbreviations[tier];
2047
+ if (!suffix)
2048
+ return this.getValue("string");
2049
+ const scale = 10 ** (tier * 3);
2050
+ const scaled = value / scale;
2051
+ return `${scaled.toFixed(digits)}${suffix}`;
2052
+ }
2053
+ toCurrency(currency = "$", {
2054
+ currencyPosition = "start",
2055
+ decimal = 2,
2056
+ decimalSeparator = ".",
2057
+ thousandSeparator = ","
2058
+ } = {}) {
2059
+ const value = this.getValue("number");
2060
+ const [int = "", dec = ""] = value.toFixed(6).split(".");
2061
+ const integer = int.replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);
2062
+ const parsedValue = int || dec ? int === "0" ? `${Number.parseFloat(`0.${dec}`)}`.replace(".", decimalSeparator) : `${integer}${Number.parseInt(dec) ? `${decimalSeparator}${dec.slice(0, decimal)}` : ""}` : "0.00";
2063
+ return `${currencyPosition === "start" ? currency : ""}${parsedValue}${currencyPosition === "end" ? currency : ""}`;
2064
+ }
2065
+ formatBigIntToSafeValue(value, decimal) {
2066
+ const bigIntDecimal = decimal || this.decimal || DEFAULT_DECIMAL;
2067
+ const decimalToUseForConversion = Math.max(bigIntDecimal, decimalFromMultiplier(this.decimalMultiplier));
2068
+ const isNegative = value < 0n;
2069
+ const valueString = value.toString().substring(isNegative ? 1 : 0);
2070
+ const padLength = decimalToUseForConversion - (valueString.length - 1);
2071
+ const parsedValueString = padLength > 0 ? "0".repeat(padLength) + valueString : valueString;
2072
+ const decimalIndex = parsedValueString.length - decimalToUseForConversion;
2073
+ let decimalString = parsedValueString.slice(-decimalToUseForConversion);
2074
+ if (Number.parseInt(decimalString[bigIntDecimal] || "0") >= 5) {
2075
+ decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(Number.parseInt(decimalString[bigIntDecimal - 1] || "0") + 1).toString()}`;
2076
+ } else {
2077
+ decimalString = decimalString.substring(0, bigIntDecimal);
2078
+ }
2079
+ return `${isNegative ? "-" : ""}${parsedValueString.slice(0, decimalIndex)}.${decimalString}`.replace(/\.?0*$/, "");
2080
+ }
2081
+ #arithmetics(method, ...args) {
2082
+ const precisionDecimal = this.#retrievePrecisionDecimal(this, ...args);
2083
+ const decimal = Math.max(precisionDecimal, decimalFromMultiplier(this.decimalMultiplier));
2084
+ const precisionDecimalMultiplier = toMultiplier(decimal);
2085
+ const result = args.reduce((acc, arg) => {
2086
+ const value2 = this.getBigIntValue(arg, decimal);
2087
+ switch (method) {
2088
+ case "add":
2089
+ return acc + value2;
2090
+ case "sub":
2091
+ return acc - value2;
2092
+ case "mul":
2093
+ return acc * value2 / precisionDecimalMultiplier;
2094
+ case "div": {
2095
+ if (value2 === 0n)
2096
+ throw new RangeError("Division by zero");
2097
+ return acc * precisionDecimalMultiplier / value2;
2098
+ }
2099
+ default:
2100
+ return acc;
2101
+ }
2102
+ }, this.bigIntValue * precisionDecimalMultiplier / this.decimalMultiplier);
2103
+ const value = formatBigIntToSafeValue({
2104
+ bigIntDecimal: decimal,
2105
+ decimal,
2106
+ value: result
2107
+ });
2108
+ return new this.constructor({
2109
+ decimalMultiplier: toMultiplier(decimal),
2110
+ decimal: this.decimal,
2111
+ value,
2112
+ identifier: this.toString()
2113
+ });
2114
+ }
2115
+ #comparison(method, ...args) {
2116
+ const decimal = this.#retrievePrecisionDecimal(this, ...args);
2117
+ const value = this.getBigIntValue(args[0] || "0", decimal);
2118
+ const compareToValue = this.getBigIntValue(this, decimal);
2119
+ switch (method) {
2120
+ case "gt":
2121
+ return compareToValue > value;
2122
+ case "gte":
2123
+ return compareToValue >= value;
2124
+ case "lt":
2125
+ return compareToValue < value;
2126
+ case "lte":
2127
+ return compareToValue <= value;
2128
+ case "eqValue":
2129
+ return compareToValue === value;
2130
+ }
2131
+ }
2132
+ #setValue(value) {
2133
+ const safeValue = toSafeValue(value) || "0";
2134
+ this.bigIntValue = this.#toBigInt(safeValue);
2135
+ }
2136
+ #retrievePrecisionDecimal(...args) {
2137
+ const decimals = args.map((arg) => {
2138
+ const isObject = typeof arg === "object";
2139
+ const value = isObject ? arg.decimal || decimalFromMultiplier(arg.decimalMultiplier) : getFloatDecimals(toSafeValue(arg));
2140
+ return value;
2141
+ }).filter(Boolean);
2142
+ return Math.max(...decimals, DEFAULT_DECIMAL);
2143
+ }
2144
+ #toBigInt(value, decimal) {
2145
+ const multiplier = decimal ? toMultiplier(decimal) : this.decimalMultiplier;
2146
+ const padDecimal = decimalFromMultiplier(multiplier);
2147
+ const [integerPart = "", decimalPart = ""] = value.split(".");
2148
+ return BigInt(`${integerPart}${decimalPart.padEnd(padDecimal, "0")}`);
2149
+ }
2150
+ }
2151
+ var numberFormatter = Intl.NumberFormat("fullwide", {
2152
+ useGrouping: false,
2153
+ maximumFractionDigits: 20
2154
+ });
2155
+
2156
+ // src/modules/swapKitNumber.ts
2157
+ class SwapKitNumber extends BigIntArithmetics {
2158
+ constructor() {
2159
+ super(...arguments);
2160
+ }
2161
+ eq(value) {
2162
+ return this.eqValue(value);
2163
+ }
2164
+ static fromBigInt(value, decimal) {
2165
+ return new SwapKitNumber({
2166
+ decimal,
2167
+ value: formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal })
2168
+ });
2169
+ }
2170
+ }
2171
+
2172
+ // src/modules/assetValue.ts
2173
+ function getMinAmountByChain(chain) {
2174
+ const asset2 = AssetValue.fromChainOrSignature(chain);
2175
+ switch (chain) {
2176
+ case Chain.Bitcoin:
2177
+ case Chain.Litecoin:
2178
+ case Chain.BitcoinCash:
2179
+ return asset2.set(0.00010001);
2180
+ case Chain.Dogecoin:
2181
+ return asset2.set(1.00000001);
2182
+ case Chain.Avalanche:
2183
+ case Chain.Ethereum:
2184
+ return asset2.set(0.00000001);
2185
+ case Chain.THORChain:
2186
+ case Chain.Maya:
2187
+ return asset2.set(0);
2188
+ case Chain.Cosmos:
2189
+ return asset2.set(0.000001);
2190
+ default:
2191
+ return asset2.set(0.00000001);
2192
+ }
2193
+ }
2194
+ async function createAssetValue(identifier, value = 0) {
2195
+ validateIdentifier(identifier);
2196
+ const staticToken = staticTokensMap.get(identifier.toUpperCase());
2197
+ const decimal = staticToken?.decimal || await getDecimal(getAssetInfo(identifier));
2198
+ if (!staticToken) {
2199
+ staticTokensMap.set(identifier.toUpperCase(), { identifier, decimal });
2200
+ }
2201
+ return new AssetValue({ decimal, value: safeValue(value, decimal), identifier });
2202
+ }
2203
+ var createSyntheticAssetValue = function(identifier, value = 0) {
2204
+ const [synthChain, symbol] = identifier.split(".")?.[0]?.toUpperCase() === Chain.THORChain ? identifier.split(".").slice(1).join().split("/") : identifier.split("/");
2205
+ if (!(synthChain && symbol))
2206
+ throw new Error("Invalid asset identifier");
2207
+ return new AssetValue({
2208
+ decimal: 8,
2209
+ value: safeValue(value, 8),
2210
+ identifier: `${Chain.THORChain}.${synthChain}/${symbol}`
2211
+ });
2212
+ };
2213
+ var safeValue = function(value, decimal) {
2214
+ return typeof value === "bigint" ? formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal }) : value;
2215
+ };
2216
+ var getAssetInfo = function(identifier) {
2217
+ const isSynthetic = identifier.slice(0, 14).includes("/");
2218
+ const isThorchain = identifier.split(".")?.[0]?.toUpperCase() === Chain.THORChain;
2219
+ const isMaya = identifier.split(".")?.[0]?.toUpperCase() === Chain.Maya;
2220
+ const [synthChain, synthSymbol = ""] = isThorchain || isMaya ? identifier.split(".").slice(1).join().split("/") : identifier.split("/");
2221
+ if (isSynthetic && !(synthChain && synthSymbol))
2222
+ throw new Error("Invalid asset identifier");
2223
+ const adjustedIdentifier = identifier.includes(".") && !isSynthetic ? identifier : `${isMaya ? Chain.Maya : Chain.THORChain}.${synthSymbol}`;
2224
+ const [chain, ...rest] = adjustedIdentifier.split(".");
2225
+ const symbol = isSynthetic ? synthSymbol : rest.join(".");
2226
+ const splitSymbol = symbol.split("-");
2227
+ const ticker = splitSymbol.length === 1 ? splitSymbol[0] : splitSymbol.slice(0, -1).join("-");
2228
+ const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
2229
+ return {
2230
+ address: address?.toLowerCase(),
2231
+ chain,
2232
+ isGasAsset: isGasAsset({ chain, symbol }),
2233
+ isSynthetic,
2234
+ symbol: (isSynthetic ? `${synthChain}/` : "") + (address ? `${ticker}-${address?.toLowerCase() ?? ""}` : symbol),
2235
+ ticker
2236
+ };
2237
+ };
2238
+ var staticTokensMap = new Map;
2239
+
2240
+ class AssetValue extends BigIntArithmetics {
2241
+ address;
2242
+ chain;
2243
+ isGasAsset = false;
2244
+ isSynthetic = false;
2245
+ symbol;
2246
+ tax;
2247
+ ticker;
2248
+ type;
2249
+ chainId;
2250
+ constructor({
2251
+ value,
2252
+ decimal,
2253
+ tax,
2254
+ chain,
2255
+ symbol,
2256
+ identifier
2257
+ }) {
2258
+ super(typeof value === "object" ? value : { decimal, value });
2259
+ const assetInfo = getAssetInfo(identifier || `${chain}.${symbol}`);
2260
+ this.type = getAssetType(assetInfo);
2261
+ this.tax = tax;
2262
+ this.chain = assetInfo.chain;
2263
+ this.ticker = assetInfo.ticker;
2264
+ this.symbol = assetInfo.symbol;
2265
+ this.address = assetInfo.address;
2266
+ this.isSynthetic = assetInfo.isSynthetic;
2267
+ this.isGasAsset = assetInfo.isGasAsset;
2268
+ this.chainId = ChainToChainId[assetInfo.chain];
2269
+ }
2270
+ toString() {
2271
+ return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
2272
+ }
2273
+ toUrl() {
2274
+ return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
2275
+ }
2276
+ eq({ chain, symbol }) {
2277
+ return this.chain === chain && this.symbol === symbol;
2278
+ }
2279
+ static fromUrl(urlAsset, value = 0) {
2280
+ const [chain, ticker, symbol] = urlAsset.split(".");
2281
+ if (!(chain && ticker))
2282
+ throw new Error("Invalid asset url");
2283
+ const assetString = chain === Chain.THORChain && symbol ? `${chain}.${ticker}/${symbol}` : urlAsset;
2284
+ return createAssetValue(assetString, value);
2285
+ }
2286
+ static fromString(assetString, value = 0) {
2287
+ return createAssetValue(assetString, value);
2288
+ }
2289
+ static fromIdentifier(assetString, value = 0) {
2290
+ return createAssetValue(assetString, value);
2291
+ }
2292
+ static fromStringSync(assetString, value = 0) {
2293
+ const { chain, isSynthetic } = getAssetInfo(assetString);
2294
+ const tokenInfo = staticTokensMap.get(assetString.toUpperCase());
2295
+ if (isSynthetic)
2296
+ return createSyntheticAssetValue(assetString, value);
2297
+ const { tax, decimal, identifier } = tokenInfo || {
2298
+ decimal: BaseDecimal[chain],
2299
+ identifier: assetString
2300
+ };
2301
+ return new AssetValue({
2302
+ tax,
2303
+ value: safeValue(value, decimal),
2304
+ identifier: isSynthetic ? assetString : identifier,
2305
+ decimal: isSynthetic ? 8 : decimal
2306
+ });
2307
+ }
2308
+ static async fromStringWithBase(assetString, value = 0, baseDecimal = BaseDecimal.THOR) {
2309
+ const shiftedAmount = BigIntArithmetics.shiftDecimals({
2310
+ value: SwapKitNumber.fromBigInt(BigInt(value)),
2311
+ from: 0,
2312
+ to: baseDecimal
2313
+ }).getBaseValue("string");
2314
+ const assetValue = await AssetValue.fromString(assetString, value);
2315
+ return assetValue.set(shiftedAmount);
2316
+ }
2317
+ static fromStringWithBaseSync(assetString, value = 0, baseDecimal = BaseDecimal.THOR) {
2318
+ const { chain, isSynthetic } = getAssetInfo(assetString);
2319
+ const tokenInfo = staticTokensMap.get(assetString.toUpperCase());
2320
+ if (isSynthetic)
2321
+ return createSyntheticAssetValue(assetString, value);
2322
+ const { tax, decimal, identifier } = tokenInfo || {
2323
+ decimal: BaseDecimal[chain],
2324
+ identifier: assetString
2325
+ };
2326
+ return new AssetValue({
2327
+ tax,
2328
+ value: safeValue(BigInt(value), baseDecimal),
2329
+ identifier,
2330
+ decimal
2331
+ });
2332
+ }
2333
+ static fromIdentifierSync(assetString, value = 0) {
2334
+ const { chain, isSynthetic } = getAssetInfo(assetString);
2335
+ const tokenInfo = staticTokensMap.get(assetString);
2336
+ if (isSynthetic)
2337
+ return createSyntheticAssetValue(assetString, value);
2338
+ const { tax, decimal, identifier } = tokenInfo || {
2339
+ decimal: BaseDecimal[chain],
2340
+ identifier: assetString
2341
+ };
2342
+ return new AssetValue({ tax, decimal, identifier, value: safeValue(value, decimal) });
2343
+ }
2344
+ static fromChainOrSignature(assetString, value = 0) {
2345
+ const { decimal, identifier } = getCommonAssetInfo(assetString);
2346
+ return new AssetValue({ value: safeValue(value, decimal), decimal, identifier });
2347
+ }
2348
+ static loadStaticAssets() {
2349
+ return new Promise((resolve, reject) => {
2350
+ try {
2351
+ import("@swapkit/tokens").then((tokenPackages) => {
2352
+ for (const tokenList of Object.values(tokenPackages)) {
2353
+ for (const { identifier, chain, ...rest } of tokenList.tokens) {
2354
+ staticTokensMap.set(identifier.toUpperCase(), {
2355
+ identifier,
2356
+ decimal: "decimals" in rest ? rest.decimals : BaseDecimal[chain]
2357
+ });
2358
+ }
2359
+ }
2360
+ resolve({ ok: true });
2361
+ });
2362
+ } catch (error) {
2363
+ console.error(error);
2364
+ reject({
2365
+ ok: false,
2366
+ error,
2367
+ message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
2368
+ });
2369
+ }
2370
+ });
2371
+ }
2372
+ }
2373
+ export {
2374
+ wrapWithThrow,
2375
+ wrapMethodWithNetworkSwitch,
2376
+ validateTNS,
2377
+ validateIdentifier,
2378
+ switchEVMWalletNetwork,
2379
+ setRequestClientConfig,
2380
+ prepareNetworkSwitch,
2381
+ okxMobileEnabled,
2382
+ isWeb3Detected,
2383
+ isGasAsset,
2384
+ isDetected,
2385
+ getWalletFormatFor,
2386
+ getTHORNameCost,
2387
+ getSymmetricWithdraw,
2388
+ getSymmetricPoolShare,
2389
+ getMinAmountByChain,
2390
+ getMemoFor,
2391
+ getMAYANameCost,
2392
+ getLiquiditySlippage,
2393
+ getEstimatedPoolShare,
2394
+ getETHDefaultWallet,
2395
+ getDerivationPathFor,
2396
+ getDecimal,
2397
+ getCommonAssetInfo,
2398
+ getAsymmetricRuneWithdrawAmount,
2399
+ getAsymmetricRuneShare,
2400
+ getAsymmetricAssetWithdrawAmount,
2401
+ getAsymmetricAssetShare,
2402
+ getAssetType,
2403
+ formatBigIntToSafeValue,
2404
+ findAssetBy,
2405
+ filterAssets,
2406
+ erc20ABI,
2407
+ derivationPathToString,
2408
+ defaultRequestHeaders,
2409
+ assetFromString,
2410
+ addEVMWalletNetwork,
2411
+ addAccountsChangedCallback,
2412
+ WalletOption,
2413
+ UTXOChains,
2414
+ TCSupportedChains,
2415
+ TCEthereumVaultAbi,
2416
+ TCBscDepositABI,
2417
+ TCAvalancheDepositABI,
2418
+ SwapKitNumber,
2419
+ SwapKitError,
2420
+ SubstrateChains,
2421
+ SWAP_OUT,
2422
+ SWAP_IN,
2423
+ RequestClient,
2424
+ RPCUrl,
2425
+ QuoteMode,
2426
+ NetworkDerivationPath,
2427
+ MemoType,
2428
+ MayaEthereumVaultAbi,
2429
+ MayaArbitrumVaultAbi,
2430
+ MAYASupportedChains,
2431
+ LedgerErrorCode,
2432
+ FeeOption,
2433
+ ExplorerUrl,
2434
+ EVMChains,
2435
+ DerivationPath,
2436
+ CosmosChains,
2437
+ ContractAddress,
2438
+ ChainToRPC,
2439
+ ChainToHexChainId,
2440
+ ChainToExplorerUrl,
2441
+ ChainToChainId,
2442
+ ChainIdToChain,
2443
+ ChainId,
2444
+ Chain,
2445
+ BigIntArithmetics,
2446
+ BaseDecimal,
2447
+ AssetValue,
2448
+ ApproveMode,
2449
+ AGG_SWAP
2450
+ };
2451
+
2452
+ //# debugId=63419FAF023E175464756e2164756e21