@swapkit/helpers 1.0.0-rc.11 → 1.0.0-rc.111

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 (42) hide show
  1. package/dist/index.js +2900 -0
  2. package/dist/index.js.map +31 -0
  3. package/package.json +26 -37
  4. package/src/helpers/__tests__/asset.test.ts +186 -103
  5. package/src/helpers/__tests__/memo.test.ts +53 -41
  6. package/src/helpers/__tests__/others.test.ts +44 -37
  7. package/src/helpers/__tests__/validators.test.ts +24 -0
  8. package/src/helpers/asset.ts +184 -95
  9. package/src/helpers/derivationPath.ts +53 -0
  10. package/src/helpers/liquidity.ts +50 -43
  11. package/src/helpers/memo.ts +34 -31
  12. package/src/helpers/others.ts +46 -12
  13. package/src/helpers/validators.ts +15 -6
  14. package/src/helpers/web3wallets.ts +200 -0
  15. package/src/index.ts +14 -9
  16. package/src/modules/__tests__/assetValue.test.ts +486 -129
  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 +220 -162
  20. package/src/modules/bigIntArithmetics.ts +214 -165
  21. package/src/modules/requestClient.ts +38 -0
  22. package/src/modules/swapKitError.ts +41 -5
  23. package/src/modules/swapKitNumber.ts +1 -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 +226 -0
  28. package/src/types/commonTypes.ts +123 -0
  29. package/src/types/derivationPath.ts +58 -0
  30. package/src/types/errors/apiV1.ts +0 -0
  31. package/src/types/index.ts +12 -0
  32. package/src/types/network.ts +45 -0
  33. package/src/types/quotes.ts +391 -0
  34. package/src/types/radix.ts +14 -0
  35. package/src/types/sdk.ts +126 -0
  36. package/src/types/tokens.ts +30 -0
  37. package/src/types/wallet.ts +72 -0
  38. package/LICENSE +0 -201
  39. package/dist/index.cjs +0 -1
  40. package/dist/index.d.ts +0 -356
  41. package/dist/index.es.js +0 -1071
  42. package/src/helpers/request.ts +0 -16
package/dist/index.js ADDED
@@ -0,0 +1,2900 @@
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["Radix"] = "https://radix-mainnet.rpc.grove.city/v1/326002fc/core";
957
+ RPCUrl2["THORChain"] = "https://rpc.thorswap.net";
958
+ RPCUrl2["THORChainStagenet"] = "https://stagenet-rpc.ninerealms.com";
959
+ })(RPCUrl || (RPCUrl = {}));
960
+ var ExplorerUrl;
961
+ (function(ExplorerUrl2) {
962
+ ExplorerUrl2["Arbitrum"] = "https://arbiscan.io";
963
+ ExplorerUrl2["Avalanche"] = "https://snowtrace.io";
964
+ ExplorerUrl2["Binance"] = "https://explorer.binance.org";
965
+ ExplorerUrl2["BinanceSmartChain"] = "https://bscscan.com";
966
+ ExplorerUrl2["Bitcoin"] = "https://blockchair.com/bitcoin";
967
+ ExplorerUrl2["BitcoinCash"] = "https://www.blockchair.com/bitcoin-cash";
968
+ ExplorerUrl2["Chainflip"] = "https://explorer.polkascan.io/polkadot";
969
+ ExplorerUrl2["Cosmos"] = "https://www.mintscan.io/cosmos";
970
+ ExplorerUrl2["Dash"] = "https://blockchair.com/dash";
971
+ ExplorerUrl2["Dogecoin"] = "https://blockchair.com/dogecoin";
972
+ ExplorerUrl2["Ethereum"] = "https://etherscan.io";
973
+ ExplorerUrl2["Kujira"] = "https://finder.kujira.network/kaiyo-1";
974
+ ExplorerUrl2["Litecoin"] = "https://blockchair.com/litecoin";
975
+ ExplorerUrl2["Maya"] = "https://www.mayascan.org";
976
+ ExplorerUrl2["Optimism"] = "https://optimistic.etherscan.io";
977
+ ExplorerUrl2["Polkadot"] = "https://polkadot.subscan.io/";
978
+ ExplorerUrl2["Polygon"] = "https://polygonscan.com";
979
+ ExplorerUrl2["Radix"] = "https://dashboard.radixdlt.com";
980
+ ExplorerUrl2["THORChain"] = "https://runescan.io";
981
+ })(ExplorerUrl || (ExplorerUrl = {}));
982
+
983
+ // src/types/chains.ts
984
+ var Chain;
985
+ (function(Chain2) {
986
+ Chain2["Arbitrum"] = "ARB";
987
+ Chain2["Avalanche"] = "AVAX";
988
+ Chain2["Binance"] = "BNB";
989
+ Chain2["BinanceSmartChain"] = "BSC";
990
+ Chain2["Bitcoin"] = "BTC";
991
+ Chain2["BitcoinCash"] = "BCH";
992
+ Chain2["Cosmos"] = "GAIA";
993
+ Chain2["Dash"] = "DASH";
994
+ Chain2["Dogecoin"] = "DOGE";
995
+ Chain2["Ethereum"] = "ETH";
996
+ Chain2["Kujira"] = "KUJI";
997
+ Chain2["Litecoin"] = "LTC";
998
+ Chain2["Maya"] = "MAYA";
999
+ Chain2["Optimism"] = "OP";
1000
+ Chain2["Polkadot"] = "DOT";
1001
+ Chain2["Chainflip"] = "FLIP";
1002
+ Chain2["Polygon"] = "MATIC";
1003
+ Chain2["Radix"] = "XRD";
1004
+ Chain2["THORChain"] = "THOR";
1005
+ })(Chain || (Chain = {}));
1006
+ var ChainId;
1007
+ (function(ChainId2) {
1008
+ ChainId2["Arbitrum"] = "42161";
1009
+ ChainId2["ArbitrumHex"] = "0xa4b1";
1010
+ ChainId2["Avalanche"] = "43114";
1011
+ ChainId2["AvalancheHex"] = "0xa86a";
1012
+ ChainId2["Binance"] = "Binance-Chain-Tigris";
1013
+ ChainId2["BinanceSmartChain"] = "56";
1014
+ ChainId2["BinanceSmartChainHex"] = "0x38";
1015
+ ChainId2["Bitcoin"] = "bitcoin";
1016
+ ChainId2["BitcoinCash"] = "bitcoincash";
1017
+ ChainId2["Chainflip"] = "chainflip";
1018
+ ChainId2["Cosmos"] = "cosmoshub-4";
1019
+ ChainId2["Dash"] = "dash";
1020
+ ChainId2["Dogecoin"] = "dogecoin";
1021
+ ChainId2["Kujira"] = "kaiyo-1";
1022
+ ChainId2["Ethereum"] = "1";
1023
+ ChainId2["EthereumHex"] = "0x1";
1024
+ ChainId2["Litecoin"] = "litecoin";
1025
+ ChainId2["Maya"] = "mayachain-mainnet-v1";
1026
+ ChainId2["MayaStagenet"] = "mayachain-stagenet-v1";
1027
+ ChainId2["Optimism"] = "10";
1028
+ ChainId2["OptimismHex"] = "0xa";
1029
+ ChainId2["Polkadot"] = "polkadot";
1030
+ ChainId2["Polygon"] = "137";
1031
+ ChainId2["PolygonHex"] = "0x89";
1032
+ ChainId2["Radix"] = "radix-mainnet";
1033
+ ChainId2["THORChain"] = "thorchain-mainnet-v1";
1034
+ ChainId2["THORChainStagenet"] = "thorchain-stagenet-v2";
1035
+ })(ChainId || (ChainId = {}));
1036
+ var ChainIdToChain = {
1037
+ [ChainId.ArbitrumHex]: Chain.Arbitrum,
1038
+ [ChainId.Arbitrum]: Chain.Arbitrum,
1039
+ [ChainId.AvalancheHex]: Chain.Avalanche,
1040
+ [ChainId.Avalanche]: Chain.Avalanche,
1041
+ [ChainId.BinanceSmartChainHex]: Chain.BinanceSmartChain,
1042
+ [ChainId.BinanceSmartChain]: Chain.BinanceSmartChain,
1043
+ [ChainId.Binance]: Chain.Binance,
1044
+ [ChainId.BitcoinCash]: Chain.BitcoinCash,
1045
+ [ChainId.Bitcoin]: Chain.Bitcoin,
1046
+ [ChainId.Chainflip]: Chain.Chainflip,
1047
+ [ChainId.Cosmos]: Chain.Cosmos,
1048
+ [ChainId.Dash]: Chain.Dash,
1049
+ [ChainId.Dogecoin]: Chain.Dogecoin,
1050
+ [ChainId.EthereumHex]: Chain.Ethereum,
1051
+ [ChainId.Kujira]: Chain.Kujira,
1052
+ [ChainId.Ethereum]: Chain.Ethereum,
1053
+ [ChainId.Litecoin]: Chain.Litecoin,
1054
+ [ChainId.MayaStagenet]: Chain.Maya,
1055
+ [ChainId.Maya]: Chain.Maya,
1056
+ [ChainId.OptimismHex]: Chain.Optimism,
1057
+ [ChainId.Optimism]: Chain.Optimism,
1058
+ [ChainId.Polkadot]: Chain.Polkadot,
1059
+ [ChainId.PolygonHex]: Chain.Polygon,
1060
+ [ChainId.Polygon]: Chain.Polygon,
1061
+ [ChainId.Radix]: Chain.Radix,
1062
+ [ChainId.THORChainStagenet]: Chain.THORChain,
1063
+ [ChainId.THORChain]: Chain.THORChain
1064
+ };
1065
+ var chainNames = Object.keys(Chain);
1066
+ var chains = Object.values(Chain);
1067
+ var BaseDecimal;
1068
+ (function(BaseDecimal2) {
1069
+ BaseDecimal2[BaseDecimal2["ARB"] = 18] = "ARB";
1070
+ BaseDecimal2[BaseDecimal2["AVAX"] = 18] = "AVAX";
1071
+ BaseDecimal2[BaseDecimal2["BCH"] = 8] = "BCH";
1072
+ BaseDecimal2[BaseDecimal2["BNB"] = 8] = "BNB";
1073
+ BaseDecimal2[BaseDecimal2["BSC"] = 18] = "BSC";
1074
+ BaseDecimal2[BaseDecimal2["BTC"] = 8] = "BTC";
1075
+ BaseDecimal2[BaseDecimal2["DASH"] = 8] = "DASH";
1076
+ BaseDecimal2[BaseDecimal2["DOGE"] = 8] = "DOGE";
1077
+ BaseDecimal2[BaseDecimal2["DOT"] = 10] = "DOT";
1078
+ BaseDecimal2[BaseDecimal2["ETH"] = 18] = "ETH";
1079
+ BaseDecimal2[BaseDecimal2["FLIP"] = 18] = "FLIP";
1080
+ BaseDecimal2[BaseDecimal2["GAIA"] = 6] = "GAIA";
1081
+ BaseDecimal2[BaseDecimal2["KUJI"] = 6] = "KUJI";
1082
+ BaseDecimal2[BaseDecimal2["LTC"] = 8] = "LTC";
1083
+ BaseDecimal2[BaseDecimal2["MATIC"] = 18] = "MATIC";
1084
+ BaseDecimal2[BaseDecimal2["MAYA"] = 10] = "MAYA";
1085
+ BaseDecimal2[BaseDecimal2["OP"] = 18] = "OP";
1086
+ BaseDecimal2[BaseDecimal2["THOR"] = 8] = "THOR";
1087
+ BaseDecimal2[BaseDecimal2["ZEC"] = 8] = "ZEC";
1088
+ BaseDecimal2[BaseDecimal2["XRD"] = 18] = "XRD";
1089
+ })(BaseDecimal || (BaseDecimal = {}));
1090
+ var SubstrateChains = [Chain.Polkadot, Chain.Chainflip];
1091
+ var EVMChains = [
1092
+ Chain.Ethereum,
1093
+ Chain.Avalanche,
1094
+ Chain.BinanceSmartChain,
1095
+ Chain.Arbitrum,
1096
+ Chain.Optimism,
1097
+ Chain.Polygon
1098
+ ];
1099
+ var UTXOChains = [
1100
+ Chain.Bitcoin,
1101
+ Chain.BitcoinCash,
1102
+ Chain.Dash,
1103
+ Chain.Dogecoin,
1104
+ Chain.Litecoin
1105
+ ];
1106
+ var CosmosChains = [
1107
+ Chain.Cosmos,
1108
+ Chain.THORChain,
1109
+ Chain.Binance,
1110
+ Chain.Maya,
1111
+ Chain.Kujira
1112
+ ];
1113
+ var TCSupportedChains = [
1114
+ Chain.Avalanche,
1115
+ Chain.Binance,
1116
+ Chain.BinanceSmartChain,
1117
+ Chain.Bitcoin,
1118
+ Chain.BitcoinCash,
1119
+ Chain.Cosmos,
1120
+ Chain.Dogecoin,
1121
+ Chain.Ethereum,
1122
+ Chain.Litecoin,
1123
+ Chain.THORChain
1124
+ ];
1125
+ var MAYASupportedChains = [
1126
+ Chain.Arbitrum,
1127
+ Chain.Dash,
1128
+ Chain.Ethereum,
1129
+ Chain.Kujira,
1130
+ Chain.Maya,
1131
+ Chain.THORChain
1132
+ ];
1133
+ var ChainToChainName = chains.reduce((acc, chain) => {
1134
+ const chainName = chainNames.find((key) => Chain[key] === chain);
1135
+ if (chainName)
1136
+ acc[chain] = chainName;
1137
+ return acc;
1138
+ }, {});
1139
+ var ChainToChainId = chains.reduce((acc, chain) => {
1140
+ acc[chain] = ChainId[ChainToChainName[chain]];
1141
+ return acc;
1142
+ }, {});
1143
+ var ChainToRPC = chains.reduce((acc, chain) => {
1144
+ acc[chain] = RPCUrl[ChainToChainName[chain]];
1145
+ return acc;
1146
+ }, {});
1147
+ var ChainToHexChainId = chains.reduce((acc, chain) => {
1148
+ const chainString = `${ChainToChainName[chain]}Hex`;
1149
+ acc[chain] = ChainId[chainString];
1150
+ return acc;
1151
+ }, {});
1152
+ var ChainToExplorerUrl = chains.reduce((acc, chain) => {
1153
+ acc[chain] = ExplorerUrl[ChainToChainName[chain]];
1154
+ return acc;
1155
+ }, {});
1156
+ // src/types/commonTypes.ts
1157
+ var QuoteMode;
1158
+ (function(QuoteMode2) {
1159
+ QuoteMode2["TC_SUPPORTED_TO_TC_SUPPORTED"] = "TC-TC";
1160
+ QuoteMode2["TC_SUPPORTED_TO_ETH"] = "TC-ERC20";
1161
+ QuoteMode2["TC_SUPPORTED_TO_AVAX"] = "TC-ARC20";
1162
+ QuoteMode2["TC_SUPPORTED_TO_BSC"] = "TC-BEP20";
1163
+ QuoteMode2["ETH_TO_TC_SUPPORTED"] = "ERC20-TC";
1164
+ QuoteMode2["ETH_TO_ETH"] = "ERC20-ERC20";
1165
+ QuoteMode2["ETH_TO_AVAX"] = "ERC20-ARC20";
1166
+ QuoteMode2["ETH_TO_BSC"] = "ERC20-BEP20";
1167
+ QuoteMode2["AVAX_TO_TC_SUPPORTED"] = "ARC20-TC";
1168
+ QuoteMode2["AVAX_TO_ETH"] = "ARC20-ERC20";
1169
+ QuoteMode2["AVAX_TO_AVAX"] = "ARC20-ARC20";
1170
+ QuoteMode2["AVAX_TO_BSC"] = "ARC20-BEP20";
1171
+ QuoteMode2["BSC_TO_TC_SUPPORTED"] = "BEP20-TC";
1172
+ QuoteMode2["BSC_TO_ETH"] = "BEP20-ERC20";
1173
+ QuoteMode2["BSC_TO_AVAX"] = "BEP20-ARC20";
1174
+ QuoteMode2["BSC_TO_BSC"] = "BEP20-BEP20";
1175
+ })(QuoteMode || (QuoteMode = {}));
1176
+ var AGG_SWAP = [QuoteMode.ETH_TO_ETH, QuoteMode.AVAX_TO_AVAX, QuoteMode.BSC_TO_BSC];
1177
+ var SWAP_IN = [
1178
+ QuoteMode.ETH_TO_TC_SUPPORTED,
1179
+ QuoteMode.ETH_TO_AVAX,
1180
+ QuoteMode.ETH_TO_BSC,
1181
+ QuoteMode.AVAX_TO_TC_SUPPORTED,
1182
+ QuoteMode.AVAX_TO_ETH,
1183
+ QuoteMode.AVAX_TO_BSC,
1184
+ QuoteMode.BSC_TO_TC_SUPPORTED,
1185
+ QuoteMode.BSC_TO_ETH,
1186
+ QuoteMode.BSC_TO_AVAX
1187
+ ];
1188
+ var SWAP_OUT = [
1189
+ QuoteMode.TC_SUPPORTED_TO_TC_SUPPORTED,
1190
+ QuoteMode.TC_SUPPORTED_TO_ETH,
1191
+ QuoteMode.TC_SUPPORTED_TO_AVAX,
1192
+ QuoteMode.TC_SUPPORTED_TO_BSC
1193
+ ];
1194
+ // src/types/derivationPath.ts
1195
+ var ContractAddress;
1196
+ (function(ContractAddress2) {
1197
+ ContractAddress2["ARB"] = "0x0000000000000000000000000000000000000000";
1198
+ ContractAddress2["AVAX"] = "0x0000000000000000000000000000000000000000";
1199
+ ContractAddress2["ETH"] = "0x0000000000000000000000000000000000000000";
1200
+ ContractAddress2["BSC"] = "0x0000000000000000000000000000000000000000";
1201
+ ContractAddress2["MATIC"] = "0x0000000000000000000000000000000000001010";
1202
+ ContractAddress2["OP"] = "0x4200000000000000000000000000000000000042";
1203
+ })(ContractAddress || (ContractAddress = {}));
1204
+ var DerivationPath;
1205
+ (function(DerivationPath2) {
1206
+ DerivationPath2["ARB"] = "m/44'/60'/0'/0";
1207
+ DerivationPath2["AVAX"] = "m/44'/60'/0'/0";
1208
+ DerivationPath2["BCH"] = "m/44'/145'/0'/0";
1209
+ DerivationPath2["BNB"] = "m/44'/714'/0'/0";
1210
+ DerivationPath2["BSC"] = "m/44'/60'/0'/0";
1211
+ DerivationPath2["BTC"] = "m/84'/0'/0'/0";
1212
+ DerivationPath2["DASH"] = "m/44'/5'/0'/0";
1213
+ DerivationPath2["DOGE"] = "m/44'/3'/0'/0";
1214
+ DerivationPath2["DOT"] = "////";
1215
+ DerivationPath2["ETH"] = "m/44'/60'/0'/0";
1216
+ DerivationPath2["FLIP"] = "////";
1217
+ DerivationPath2["GAIA"] = "m/44'/118'/0'/0";
1218
+ DerivationPath2["KUJI"] = "m/44'/118'/0'/0";
1219
+ DerivationPath2["LTC"] = "m/84'/2'/0'/0";
1220
+ DerivationPath2["MATIC"] = "m/44'/60'/0'/0";
1221
+ DerivationPath2["MAYA"] = "m/44'/931'/0'/0";
1222
+ DerivationPath2["OP"] = "m/44'/60'/0'/0";
1223
+ DerivationPath2["XRD"] = "////";
1224
+ DerivationPath2["THOR"] = "m/44'/931'/0'/0";
1225
+ })(DerivationPath || (DerivationPath = {}));
1226
+ var NetworkDerivationPath = {
1227
+ ARB: [44, 60, 0, 0, 0],
1228
+ AVAX: [44, 60, 0, 0, 0],
1229
+ BCH: [44, 145, 0, 0, 0],
1230
+ BNB: [44, 714, 0, 0, 0],
1231
+ BSC: [44, 60, 0, 0, 0],
1232
+ BTC: [84, 0, 0, 0, 0],
1233
+ DASH: [44, 5, 0, 0, 0],
1234
+ DOGE: [44, 3, 0, 0, 0],
1235
+ ETH: [44, 60, 0, 0, 0],
1236
+ GAIA: [44, 118, 0, 0, 0],
1237
+ KUJI: [44, 118, 0, 0, 0],
1238
+ LTC: [84, 2, 0, 0, 0],
1239
+ MATIC: [44, 60, 0, 0, 0],
1240
+ MAYA: [44, 931, 0, 0, 0],
1241
+ OP: [44, 60, 0, 0, 0],
1242
+ THOR: [44, 931, 0, 0, 0],
1243
+ XRD: [0, 0, 0, 0, 0],
1244
+ DOT: [0, 0, 0, 0, 0],
1245
+ FLIP: [0, 0, 0, 0, 0]
1246
+ };
1247
+ // src/types/wallet.ts
1248
+ var WalletOption;
1249
+ (function(WalletOption2) {
1250
+ WalletOption2["KEYSTORE"] = "KEYSTORE";
1251
+ WalletOption2["KEEPKEY"] = "KEEPKEY";
1252
+ WalletOption2["XDEFI"] = "XDEFI";
1253
+ WalletOption2["METAMASK"] = "METAMASK";
1254
+ WalletOption2["COINBASE_WEB"] = "COINBASE_WEB";
1255
+ WalletOption2["COINBASE_MOBILE"] = "COINBASE_MOBILE";
1256
+ WalletOption2["TREZOR"] = "TREZOR";
1257
+ WalletOption2["TRUSTWALLET_WEB"] = "TRUSTWALLET_WEB";
1258
+ WalletOption2["LEDGER"] = "LEDGER";
1259
+ WalletOption2["KEPLR"] = "KEPLR";
1260
+ WalletOption2["OKX"] = "OKX";
1261
+ WalletOption2["OKX_MOBILE"] = "OKX_MOBILE";
1262
+ WalletOption2["BRAVE"] = "BRAVE";
1263
+ WalletOption2["WALLETCONNECT"] = "WALLETCONNECT";
1264
+ WalletOption2["EIP6963"] = "EIP6963";
1265
+ WalletOption2["EXODUS"] = "EXODUS";
1266
+ WalletOption2["RADIX_WALLET"] = "RADIX_WALLET";
1267
+ })(WalletOption || (WalletOption = {}));
1268
+ var LedgerErrorCode;
1269
+ (function(LedgerErrorCode2) {
1270
+ LedgerErrorCode2[LedgerErrorCode2["NoError"] = 36864] = "NoError";
1271
+ LedgerErrorCode2[LedgerErrorCode2["LockedDevice"] = 21781] = "LockedDevice";
1272
+ LedgerErrorCode2[LedgerErrorCode2["TC_NotFound"] = 65535] = "TC_NotFound";
1273
+ })(LedgerErrorCode || (LedgerErrorCode = {}));
1274
+ // src/types/sdk.ts
1275
+ import {z} from "zod";
1276
+ var FeeOption;
1277
+ (function(FeeOption2) {
1278
+ FeeOption2["Average"] = "average";
1279
+ FeeOption2["Fast"] = "fast";
1280
+ FeeOption2["Fastest"] = "fastest";
1281
+ })(FeeOption || (FeeOption = {}));
1282
+ var ApproveMode;
1283
+ (function(ApproveMode2) {
1284
+ ApproveMode2["Approve"] = "approve";
1285
+ ApproveMode2["CheckOnly"] = "checkOnly";
1286
+ })(ApproveMode || (ApproveMode = {}));
1287
+ var MemoType;
1288
+ (function(MemoType2) {
1289
+ MemoType2["BOND"] = "BOND";
1290
+ MemoType2["DEPOSIT"] = "+";
1291
+ MemoType2["LEAVE"] = "LEAVE";
1292
+ MemoType2["NAME_REGISTER"] = "~";
1293
+ MemoType2["UNBOND"] = "UNBOND";
1294
+ MemoType2["WITHDRAW"] = "-";
1295
+ MemoType2["OPEN_LOAN"] = "$+";
1296
+ MemoType2["CLOSE_LOAN"] = "$-";
1297
+ })(MemoType || (MemoType = {}));
1298
+ var QuoteRequestSchema = z.object({
1299
+ sellAsset: z.string({
1300
+ description: "Asset to sell"
1301
+ }),
1302
+ buyAsset: z.string({
1303
+ description: "Asset to buy"
1304
+ }),
1305
+ sellAmount: z.number({
1306
+ description: "Amount of asset to sell"
1307
+ }).refine((amount) => amount > 0, {
1308
+ message: "sellAmount must be greater than 0",
1309
+ path: ["sellAmount"]
1310
+ }),
1311
+ providers: z.optional(z.array(z.string({
1312
+ description: "List of providers to use"
1313
+ }))),
1314
+ sourceAddress: z.optional(z.string({
1315
+ description: "Address to send asset from"
1316
+ })),
1317
+ destinationAddress: z.optional(z.string({
1318
+ description: "Address to send asset to"
1319
+ })),
1320
+ slippage: z.optional(z.number({
1321
+ description: "Slippage tolerance as a percentage. Default is 3%."
1322
+ })),
1323
+ affiliate: z.optional(z.string({
1324
+ description: "Affiliate thorname"
1325
+ })),
1326
+ affiliateFee: z.optional(z.number({
1327
+ description: "Affiliate fee in basis points"
1328
+ }).refine((fee) => {
1329
+ return fee === Math.floor(fee) && fee >= 0;
1330
+ }, { message: "affiliateFee must be a positive integer", path: ["affiliateFee"] })),
1331
+ allowSmartContractSender: z.optional(z.boolean({
1332
+ description: "Allow smart contract as sender"
1333
+ })),
1334
+ allowSmartContractReceiver: z.optional(z.boolean({
1335
+ description: "Allow smart contract as recipient"
1336
+ })),
1337
+ disableSecurityChecks: z.optional(z.boolean({
1338
+ description: "Disable security checks"
1339
+ }))
1340
+ }).refine((data) => data.sellAsset !== data.buyAsset, {
1341
+ message: "Must be different",
1342
+ path: ["sellAsset", "buyAsset"]
1343
+ });
1344
+ // src/types/quotes.ts
1345
+ import {z as z2} from "zod";
1346
+ var WarningCodeEnum;
1347
+ (function(WarningCodeEnum2) {
1348
+ WarningCodeEnum2["highSlippage"] = "highSlippage";
1349
+ WarningCodeEnum2["highPriceImpact"] = "highPriceImpact";
1350
+ })(WarningCodeEnum || (WarningCodeEnum = {}));
1351
+ var EVMTransactionDetailsParamsSchema = z2.array(z2.union([
1352
+ z2.string(),
1353
+ z2.number(),
1354
+ z2.array(z2.string()),
1355
+ z2.object({
1356
+ from: z2.string(),
1357
+ value: z2.string()
1358
+ }).describe("Parameters to pass to the contract method")
1359
+ ]));
1360
+ var EVMTransactionDetailsSchema = z2.object({
1361
+ contractAddress: z2.string({
1362
+ description: "Address of the contract to interact with"
1363
+ }),
1364
+ contractMethod: z2.string({
1365
+ description: "Name of the method to call"
1366
+ }),
1367
+ contractParams: EVMTransactionDetailsParamsSchema,
1368
+ contractParamNames: z2.array(z2.string({
1369
+ description: "Names of the parameters to pass to the contract method"
1370
+ })),
1371
+ approvalToken: z2.optional(z2.string({
1372
+ description: "Address of the token to approve spending of"
1373
+ })),
1374
+ approvalSpender: z2.optional(z2.string({
1375
+ description: "Address of the spender to approve"
1376
+ }))
1377
+ });
1378
+ var EstimatedTimeSchema = z2.object({
1379
+ inbound: z2.optional(z2.number({
1380
+ description: "Time to receive inbound asset in seconds"
1381
+ })),
1382
+ swap: z2.optional(z2.number({
1383
+ description: "Time to swap assets in seconds"
1384
+ })),
1385
+ outbound: z2.optional(z2.number({
1386
+ description: "Time to receive outbound asset in seconds"
1387
+ })),
1388
+ total: z2.number({
1389
+ description: "Total time in seconds"
1390
+ })
1391
+ });
1392
+ var ProviderName;
1393
+ (function(ProviderName2) {
1394
+ ProviderName2["CHAINFLIP"] = "CHAINFLIP";
1395
+ ProviderName2["TRADERJOE_V1"] = "TRADERJOE_V1";
1396
+ ProviderName2["PANGOLIN_V1"] = "PANGOLIN_V1";
1397
+ ProviderName2["UNISWAP_V2"] = "UNISWAP_V2";
1398
+ ProviderName2["THORCHAIN"] = "THORCHAIN";
1399
+ ProviderName2["THORCHAIN_STREAMING"] = "THORCHAIN_STREAMING";
1400
+ ProviderName2["MAYACHAIN"] = "MAYACHAIN";
1401
+ ProviderName2["ONEINCH"] = "ONEINCH";
1402
+ ProviderName2["SUSHISWAP_V2"] = "SUSHISWAP_V2";
1403
+ ProviderName2["WOOFI_V2"] = "WOOFI_V2";
1404
+ ProviderName2["PANCAKESWAP"] = "PANCAKESWAP";
1405
+ })(ProviderName || (ProviderName = {}));
1406
+ var FeeTypeEnum;
1407
+ (function(FeeTypeEnum2) {
1408
+ FeeTypeEnum2["LIQUIDITY"] = "liquidity";
1409
+ FeeTypeEnum2["NETWORK"] = "network";
1410
+ FeeTypeEnum2["INBOUND"] = "inbound";
1411
+ FeeTypeEnum2["OUTBOUND"] = "outbound";
1412
+ FeeTypeEnum2["AFFILIATE"] = "affiliate";
1413
+ FeeTypeEnum2["TAX"] = "tax";
1414
+ })(FeeTypeEnum || (FeeTypeEnum = {}));
1415
+ var FeesSchema = z2.array(z2.object({
1416
+ type: z2.nativeEnum(FeeTypeEnum),
1417
+ amount: z2.string(),
1418
+ asset: z2.string(),
1419
+ chain: z2.string(),
1420
+ protocol: z2.nativeEnum(ProviderName)
1421
+ }));
1422
+ var RouteLegSchema = z2.object({
1423
+ sellAsset: z2.string({
1424
+ description: "Asset to sell"
1425
+ }),
1426
+ buyAsset: z2.string({
1427
+ description: "Asset to buy"
1428
+ }),
1429
+ provider: z2.nativeEnum(ProviderName),
1430
+ sourceAddress: z2.string({
1431
+ description: "Source address"
1432
+ }),
1433
+ destinationAddress: z2.string({
1434
+ description: "Destination address"
1435
+ }),
1436
+ estimatedTime: EstimatedTimeSchema.optional(),
1437
+ affiliate: z2.string({
1438
+ description: "Affiliate address"
1439
+ }).optional(),
1440
+ affiliateFee: z2.number({
1441
+ description: "Affiliate fee"
1442
+ }).optional(),
1443
+ slipPercentage: z2.number({
1444
+ description: "Slippage as a percentage"
1445
+ })
1446
+ });
1447
+ var RouteLegWithoutAddressesSchema = RouteLegSchema.omit({
1448
+ sourceAddress: true,
1449
+ destinationAddress: true,
1450
+ slipPercentage: true
1451
+ });
1452
+ var RouteQuoteMetadataAssetSchema = z2.object({
1453
+ name: z2.string({
1454
+ description: "Asset name"
1455
+ }),
1456
+ price: z2.number({
1457
+ description: "Price in USD"
1458
+ }),
1459
+ image: z2.string({
1460
+ description: "Asset image"
1461
+ })
1462
+ });
1463
+ var RouteQuoteMetadataSchema = z2.object({
1464
+ priceImpact: z2.number({
1465
+ description: "Price impact"
1466
+ }),
1467
+ assets: z2.optional(z2.array(RouteQuoteMetadataAssetSchema))
1468
+ });
1469
+ var RouteQuoteWarningSchema = z2.array(z2.object({
1470
+ code: z2.nativeEnum(WarningCodeEnum),
1471
+ display: z2.string(),
1472
+ tooltip: z2.string().optional()
1473
+ }));
1474
+ var RouteQuoteLegSchema = z2.object({
1475
+ sellAsset: z2.string({
1476
+ description: "Asset to sell"
1477
+ }),
1478
+ buyAsset: z2.string({
1479
+ description: "Asset to buy"
1480
+ }),
1481
+ provider: z2.nativeEnum(ProviderName),
1482
+ buyAmount: z2.string({
1483
+ description: "Amount of asset to buy"
1484
+ }),
1485
+ buyAmountMaxSlippage: z2.string({
1486
+ description: "Amount of asset to buy"
1487
+ }),
1488
+ sellAmount: z2.string({
1489
+ description: "Amount of asset to sell"
1490
+ }),
1491
+ sourceAddress: z2.string({
1492
+ description: "Source address"
1493
+ }),
1494
+ destinationAddress: z2.string({
1495
+ description: "Destination address"
1496
+ }),
1497
+ slippageBps: z2.number({
1498
+ description: "Slippage in bps"
1499
+ }),
1500
+ targetAddress: z2.optional(z2.string({
1501
+ description: "Target address for contract call or transfer address"
1502
+ })),
1503
+ inboundAddress: z2.optional(z2.string({
1504
+ description: "Inbound address"
1505
+ })),
1506
+ routerAddress: z2.optional(z2.string({
1507
+ description: "Inbound address"
1508
+ })),
1509
+ contractMethod: z2.optional(z2.string({
1510
+ description: "Contract method"
1511
+ })),
1512
+ fees: z2.optional(FeesSchema),
1513
+ estimatedTime: z2.optional(EstimatedTimeSchema),
1514
+ memo: z2.optional(z2.string({
1515
+ description: "Memo"
1516
+ })),
1517
+ expiration: z2.optional(z2.string({
1518
+ description: "Expiration"
1519
+ }))
1520
+ });
1521
+ var RouteQuoteSchema = z2.object({
1522
+ providers: z2.array(z2.nativeEnum(ProviderName)),
1523
+ sellAsset: z2.string({
1524
+ description: "Asset to sell"
1525
+ }),
1526
+ sellAmount: z2.string({
1527
+ description: "sell amount"
1528
+ }),
1529
+ buyAsset: z2.string({
1530
+ description: "Asset to buy"
1531
+ }),
1532
+ expectedBuyAmount: z2.string({
1533
+ description: "Expected Buy amount"
1534
+ }),
1535
+ expectedBuyAmountMaxSlippage: z2.string({
1536
+ description: "Expected Buy amount max slippage"
1537
+ }),
1538
+ sourceAddress: z2.string({
1539
+ description: "Source address"
1540
+ }),
1541
+ destinationAddress: z2.string({
1542
+ description: "Destination address"
1543
+ }),
1544
+ targetAddress: z2.optional(z2.string({
1545
+ description: "Target address"
1546
+ })),
1547
+ routerAddress: z2.optional(z2.string({
1548
+ description: "Router address"
1549
+ })),
1550
+ inboundAddress: z2.optional(z2.string({
1551
+ description: "Inbound address"
1552
+ })),
1553
+ expiration: z2.optional(z2.string({
1554
+ description: "Expiration"
1555
+ })),
1556
+ memo: z2.optional(z2.string({
1557
+ description: "Memo"
1558
+ })),
1559
+ evmTransactionDetails: z2.optional(EVMTransactionDetailsSchema),
1560
+ routePathArray: z2.optional(z2.array(z2.string())),
1561
+ estimatedTime: z2.optional(EstimatedTimeSchema),
1562
+ totalSlippageBps: z2.number({
1563
+ description: "Total slippage in bps"
1564
+ }),
1565
+ legs: z2.array(RouteQuoteLegSchema),
1566
+ errorCode: z2.optional(z2.string()),
1567
+ warnings: RouteQuoteWarningSchema,
1568
+ meta: RouteQuoteMetadataSchema
1569
+ });
1570
+ var QuoteResponseRouteLegItem = z2.object({
1571
+ provider: z2.nativeEnum(ProviderName),
1572
+ sellAsset: z2.string({
1573
+ description: "Asset to sell"
1574
+ }),
1575
+ sellAmount: z2.string({
1576
+ description: "Sell amount"
1577
+ }),
1578
+ buyAsset: z2.string({
1579
+ description: "Asset to buy"
1580
+ }),
1581
+ buyAmount: z2.string({
1582
+ description: "Buy amount"
1583
+ }),
1584
+ buyAmountMaxSlippage: z2.string({
1585
+ description: "Buy amount max slippage"
1586
+ }),
1587
+ fees: z2.optional(FeesSchema)
1588
+ });
1589
+ var QuoteResponseRouteItem = z2.object({
1590
+ providers: z2.array(z2.nativeEnum(ProviderName)),
1591
+ sellAsset: z2.string({
1592
+ description: "Asset to sell"
1593
+ }),
1594
+ sellAmount: z2.string({
1595
+ description: "sell amount"
1596
+ }),
1597
+ buyAsset: z2.string({
1598
+ description: "Asset to buy"
1599
+ }),
1600
+ expectedBuyAmount: z2.string({
1601
+ description: "Expected Buy amount"
1602
+ }),
1603
+ expectedBuyAmountMaxSlippage: z2.string({
1604
+ description: "Expected Buy amount max slippage"
1605
+ }),
1606
+ sourceAddress: z2.string({
1607
+ description: "Source address"
1608
+ }),
1609
+ destinationAddress: z2.string({
1610
+ description: "Destination address"
1611
+ }),
1612
+ targetAddress: z2.optional(z2.string({
1613
+ description: "Target address"
1614
+ })),
1615
+ expiration: z2.optional(z2.string({
1616
+ description: "Expiration"
1617
+ })),
1618
+ memo: z2.optional(z2.string({
1619
+ description: "Memo"
1620
+ })),
1621
+ evmTransactionDetails: z2.optional(EVMTransactionDetailsSchema),
1622
+ estimatedTime: z2.optional(EstimatedTimeSchema),
1623
+ totalSlippageBps: z2.number({
1624
+ description: "Total slippage in bps"
1625
+ }),
1626
+ legs: z2.array(QuoteResponseRouteLegItem),
1627
+ warnings: RouteQuoteWarningSchema,
1628
+ meta: RouteQuoteMetadataSchema
1629
+ });
1630
+ var QuoteResponseSchema = z2.object({
1631
+ quoteId: z2.string({
1632
+ description: "Quote ID"
1633
+ }),
1634
+ routes: z2.array(QuoteResponseRouteItem),
1635
+ error: z2.optional(z2.string({
1636
+ description: "Error message"
1637
+ }))
1638
+ });
1639
+ // src/helpers/validators.ts
1640
+ function validateIdentifier(identifier = "") {
1641
+ const uppercasedIdentifier = identifier.toUpperCase();
1642
+ const [chain] = uppercasedIdentifier.split(".");
1643
+ if (supportedChains.includes(chain))
1644
+ return true;
1645
+ const [synthChain] = uppercasedIdentifier.split("/");
1646
+ if (supportedChains.includes(synthChain))
1647
+ return true;
1648
+ throw new Error(`Invalid identifier: ${identifier}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`);
1649
+ }
1650
+ function validateTNS(name) {
1651
+ if (name.length > 30)
1652
+ return false;
1653
+ const regex = /^[a-zA-Z0-9+_-]+$/g;
1654
+ return !!name.match(regex);
1655
+ }
1656
+ var supportedChains = [...Object.values(Chain), "TERRA"];
1657
+
1658
+ // src/modules/bigIntArithmetics.ts
1659
+ function formatBigIntToSafeValue({
1660
+ value,
1661
+ bigIntDecimal = DEFAULT_DECIMAL,
1662
+ decimal = DEFAULT_DECIMAL
1663
+ }) {
1664
+ if (decimal === 0)
1665
+ return value.toString();
1666
+ const isNegative = value < 0n;
1667
+ let valueString = value.toString().substring(isNegative ? 1 : 0);
1668
+ const padLength = decimal - (valueString.length - 1);
1669
+ if (padLength > 0) {
1670
+ valueString = "0".repeat(padLength) + valueString;
1671
+ }
1672
+ const decimalIndex = valueString.length - decimal;
1673
+ let decimalString = valueString.slice(-decimal);
1674
+ if (Number.parseInt(decimalString[bigIntDecimal] || "0") >= 5) {
1675
+ decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(Number.parseInt(decimalString[bigIntDecimal - 1] || "0") + 1).toString()}`;
1676
+ } else {
1677
+ decimalString = decimalString.substring(0, bigIntDecimal);
1678
+ }
1679
+ return `${isNegative ? "-" : ""}${valueString.slice(0, decimalIndex)}.${decimalString}`.replace(/\.?0*$/, "");
1680
+ }
1681
+ var toSafeValue = function(value) {
1682
+ const parsedValue = typeof value === "number" ? numberFormatter.format(value) : getStringValue(value);
1683
+ const splitValue = `${parsedValue}`.replaceAll(",", ".").split(".");
1684
+ return splitValue.length > 1 ? `${splitValue.slice(0, -1).join("")}.${splitValue.at(-1)}` : splitValue[0] || "0";
1685
+ };
1686
+ var getFloatDecimals = function(value) {
1687
+ const decimals = value.split(".")[1]?.length || 0;
1688
+ return Math.max(decimals, DEFAULT_DECIMAL);
1689
+ };
1690
+ var getStringValue = function(param) {
1691
+ return typeof param === "object" ? "getValue" in param ? param.getValue("string") : param.value : param;
1692
+ };
1693
+ var DEFAULT_DECIMAL = 8;
1694
+ var toMultiplier = (decimal) => 10n ** BigInt(decimal);
1695
+ var decimalFromMultiplier = (multiplier) => Math.log10(Number.parseFloat(multiplier.toString()));
1696
+
1697
+ class BigIntArithmetics {
1698
+ decimalMultiplier = 10n ** 8n;
1699
+ bigIntValue = 0n;
1700
+ decimal;
1701
+ static fromBigInt(value, decimal) {
1702
+ return new BigIntArithmetics({
1703
+ decimal,
1704
+ value: formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal })
1705
+ });
1706
+ }
1707
+ static shiftDecimals({
1708
+ value,
1709
+ from,
1710
+ to
1711
+ }) {
1712
+ return BigIntArithmetics.fromBigInt(value.getBaseValue("bigint") * toMultiplier(to) / toMultiplier(from), to);
1713
+ }
1714
+ constructor(params) {
1715
+ const value = getStringValue(params);
1716
+ const isComplex = typeof params === "object";
1717
+ this.decimal = isComplex ? params.decimal : undefined;
1718
+ this.decimalMultiplier = isComplex && "decimalMultiplier" in params ? params.decimalMultiplier : toMultiplier(Math.max(getFloatDecimals(toSafeValue(value)), this.decimal || 0));
1719
+ this.#setValue(value);
1720
+ }
1721
+ set(value) {
1722
+ return new this.constructor({ decimal: this.decimal, value, identifier: this.toString() });
1723
+ }
1724
+ add(...args) {
1725
+ return this.#arithmetics("add", ...args);
1726
+ }
1727
+ sub(...args) {
1728
+ return this.#arithmetics("sub", ...args);
1729
+ }
1730
+ mul(...args) {
1731
+ return this.#arithmetics("mul", ...args);
1732
+ }
1733
+ div(...args) {
1734
+ return this.#arithmetics("div", ...args);
1735
+ }
1736
+ gt(value) {
1737
+ return this.#comparison("gt", value);
1738
+ }
1739
+ gte(value) {
1740
+ return this.#comparison("gte", value);
1741
+ }
1742
+ lt(value) {
1743
+ return this.#comparison("lt", value);
1744
+ }
1745
+ lte(value) {
1746
+ return this.#comparison("lte", value);
1747
+ }
1748
+ eqValue(value) {
1749
+ return this.#comparison("eqValue", value);
1750
+ }
1751
+ getValue(type) {
1752
+ const value = this.formatBigIntToSafeValue(this.bigIntValue, this.decimal || decimalFromMultiplier(this.decimalMultiplier));
1753
+ switch (type) {
1754
+ case "number":
1755
+ return Number(value);
1756
+ case "string":
1757
+ return value;
1758
+ case "bigint":
1759
+ return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
1760
+ }
1761
+ }
1762
+ getBaseValue(type) {
1763
+ const divisor = this.decimalMultiplier / toMultiplier(this.decimal || BaseDecimal.THOR);
1764
+ const baseValue = this.bigIntValue / divisor;
1765
+ switch (type) {
1766
+ case "number":
1767
+ return Number(baseValue);
1768
+ case "string":
1769
+ return baseValue.toString();
1770
+ case "bigint":
1771
+ return baseValue;
1772
+ }
1773
+ }
1774
+ getBigIntValue(value, decimal) {
1775
+ if (!decimal && typeof value === "object")
1776
+ return value.bigIntValue;
1777
+ const stringValue = getStringValue(value);
1778
+ const safeValue = toSafeValue(stringValue);
1779
+ if (safeValue === "0" || safeValue === "undefined")
1780
+ return 0n;
1781
+ return this.#toBigInt(safeValue, decimal);
1782
+ }
1783
+ toSignificant(significantDigits = 6) {
1784
+ const [int, dec] = this.getValue("string").split(".");
1785
+ const integer = int || "";
1786
+ const decimal = dec || "";
1787
+ const valueLength = Number.parseInt(integer) ? integer.length + decimal.length : decimal.length;
1788
+ if (valueLength <= significantDigits) {
1789
+ return this.getValue("string");
1790
+ }
1791
+ if (integer.length >= significantDigits) {
1792
+ return integer.slice(0, significantDigits).padEnd(integer.length, "0");
1793
+ }
1794
+ if (Number.parseInt(integer)) {
1795
+ return `${integer}.${decimal.slice(0, significantDigits - integer.length)}`.padEnd(significantDigits - integer.length, "0");
1796
+ }
1797
+ const trimmedDecimal = Number.parseInt(decimal);
1798
+ const slicedDecimal = `${trimmedDecimal}`.slice(0, significantDigits);
1799
+ return `0.${slicedDecimal.padStart(decimal.length - `${trimmedDecimal}`.length + slicedDecimal.length, "0")}`;
1800
+ }
1801
+ toFixed(fixedDigits = 6) {
1802
+ const [int, dec] = this.getValue("string").split(".");
1803
+ const integer = int || "";
1804
+ const decimal = dec || "";
1805
+ if (Number.parseInt(integer)) {
1806
+ return `${integer}.${decimal.slice(0, fixedDigits)}`.padEnd(fixedDigits, "0");
1807
+ }
1808
+ const trimmedDecimal = Number.parseInt(decimal);
1809
+ const slicedDecimal = `${trimmedDecimal}`.slice(0, fixedDigits);
1810
+ return `0.${slicedDecimal.padStart(decimal.length - `${trimmedDecimal}`.length + slicedDecimal.length, "0")}`;
1811
+ }
1812
+ toAbbreviation(digits = 2) {
1813
+ const value = this.getValue("number");
1814
+ const abbreviations = ["", "K", "M", "B", "T", "Q", "Qi", "S"];
1815
+ const tier = Math.floor(Math.log10(Math.abs(value)) / 3);
1816
+ const suffix = abbreviations[tier];
1817
+ if (!suffix)
1818
+ return this.getValue("string");
1819
+ const scale = 10 ** (tier * 3);
1820
+ const scaled = value / scale;
1821
+ return `${scaled.toFixed(digits)}${suffix}`;
1822
+ }
1823
+ toCurrency(currency = "$", {
1824
+ currencyPosition = "start",
1825
+ decimal = 2,
1826
+ decimalSeparator = ".",
1827
+ thousandSeparator = ","
1828
+ } = {}) {
1829
+ const value = this.getValue("number");
1830
+ const [int = "", dec = ""] = value.toFixed(6).split(".");
1831
+ const integer = int.replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);
1832
+ const parsedValue = int || dec ? int === "0" ? `${Number.parseFloat(`0.${dec}`)}`.replace(".", decimalSeparator) : `${integer}${Number.parseInt(dec) ? `${decimalSeparator}${dec.slice(0, decimal)}` : ""}` : "0.00";
1833
+ return `${currencyPosition === "start" ? currency : ""}${parsedValue}${currencyPosition === "end" ? currency : ""}`;
1834
+ }
1835
+ formatBigIntToSafeValue(value, decimal) {
1836
+ const bigIntDecimal = decimal || this.decimal || DEFAULT_DECIMAL;
1837
+ const decimalToUseForConversion = Math.max(bigIntDecimal, decimalFromMultiplier(this.decimalMultiplier));
1838
+ const isNegative = value < 0n;
1839
+ const valueString = value.toString().substring(isNegative ? 1 : 0);
1840
+ const padLength = decimalToUseForConversion - (valueString.length - 1);
1841
+ const parsedValueString = padLength > 0 ? "0".repeat(padLength) + valueString : valueString;
1842
+ const decimalIndex = parsedValueString.length - decimalToUseForConversion;
1843
+ let decimalString = parsedValueString.slice(-decimalToUseForConversion);
1844
+ if (Number.parseInt(decimalString[bigIntDecimal] || "0") >= 5) {
1845
+ decimalString = `${decimalString.substring(0, bigIntDecimal - 1)}${(Number.parseInt(decimalString[bigIntDecimal - 1] || "0") + 1).toString()}`;
1846
+ } else {
1847
+ decimalString = decimalString.substring(0, bigIntDecimal);
1848
+ }
1849
+ return `${isNegative ? "-" : ""}${parsedValueString.slice(0, decimalIndex)}.${decimalString}`.replace(/\.?0*$/, "");
1850
+ }
1851
+ #arithmetics(method, ...args) {
1852
+ const precisionDecimal = this.#retrievePrecisionDecimal(this, ...args);
1853
+ const decimal = Math.max(precisionDecimal, decimalFromMultiplier(this.decimalMultiplier));
1854
+ const precisionDecimalMultiplier = toMultiplier(decimal);
1855
+ const result = args.reduce((acc, arg) => {
1856
+ const value2 = this.getBigIntValue(arg, decimal);
1857
+ switch (method) {
1858
+ case "add":
1859
+ return acc + value2;
1860
+ case "sub":
1861
+ return acc - value2;
1862
+ case "mul":
1863
+ return acc * value2 / precisionDecimalMultiplier;
1864
+ case "div": {
1865
+ if (value2 === 0n)
1866
+ throw new RangeError("Division by zero");
1867
+ return acc * precisionDecimalMultiplier / value2;
1868
+ }
1869
+ default:
1870
+ return acc;
1871
+ }
1872
+ }, this.bigIntValue * precisionDecimalMultiplier / this.decimalMultiplier);
1873
+ const value = formatBigIntToSafeValue({
1874
+ bigIntDecimal: decimal,
1875
+ decimal,
1876
+ value: result
1877
+ });
1878
+ return new this.constructor({
1879
+ decimalMultiplier: toMultiplier(decimal),
1880
+ decimal: this.decimal,
1881
+ value,
1882
+ identifier: this.toString()
1883
+ });
1884
+ }
1885
+ #comparison(method, ...args) {
1886
+ const decimal = this.#retrievePrecisionDecimal(this, ...args);
1887
+ const value = this.getBigIntValue(args[0] || "0", decimal);
1888
+ const compareToValue = this.getBigIntValue(this, decimal);
1889
+ switch (method) {
1890
+ case "gt":
1891
+ return compareToValue > value;
1892
+ case "gte":
1893
+ return compareToValue >= value;
1894
+ case "lt":
1895
+ return compareToValue < value;
1896
+ case "lte":
1897
+ return compareToValue <= value;
1898
+ case "eqValue":
1899
+ return compareToValue === value;
1900
+ }
1901
+ }
1902
+ #setValue(value) {
1903
+ const safeValue = toSafeValue(value) || "0";
1904
+ this.bigIntValue = this.#toBigInt(safeValue);
1905
+ }
1906
+ #retrievePrecisionDecimal(...args) {
1907
+ const decimals = args.map((arg) => {
1908
+ const isObject = typeof arg === "object";
1909
+ const value = isObject ? arg.decimal || decimalFromMultiplier(arg.decimalMultiplier) : getFloatDecimals(toSafeValue(arg));
1910
+ return value;
1911
+ }).filter(Boolean);
1912
+ return Math.max(...decimals, DEFAULT_DECIMAL);
1913
+ }
1914
+ #toBigInt(value, decimal) {
1915
+ const multiplier = decimal ? toMultiplier(decimal) : this.decimalMultiplier;
1916
+ const padDecimal = decimalFromMultiplier(multiplier);
1917
+ const [integerPart = "", decimalPart = ""] = value.split(".");
1918
+ return BigInt(`${integerPart}${decimalPart.padEnd(padDecimal, "0")}`);
1919
+ }
1920
+ }
1921
+ var numberFormatter = Intl.NumberFormat("fullwide", {
1922
+ useGrouping: false,
1923
+ maximumFractionDigits: 20
1924
+ });
1925
+
1926
+ // src/modules/swapKitNumber.ts
1927
+ class SwapKitNumber extends BigIntArithmetics {
1928
+ eq(value) {
1929
+ return this.eqValue(value);
1930
+ }
1931
+ static fromBigInt(value, decimal) {
1932
+ return new SwapKitNumber({
1933
+ decimal,
1934
+ value: formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal })
1935
+ });
1936
+ }
1937
+ }
1938
+
1939
+ // src/modules/assetValue.ts
1940
+ function getMinAmountByChain(chain) {
1941
+ const asset2 = AssetValue.fromChainOrSignature(chain);
1942
+ switch (chain) {
1943
+ case Chain.Bitcoin:
1944
+ case Chain.Litecoin:
1945
+ case Chain.BitcoinCash:
1946
+ return asset2.set(0.00010001);
1947
+ case Chain.Dogecoin:
1948
+ return asset2.set(1.00000001);
1949
+ case Chain.Avalanche:
1950
+ case Chain.Ethereum:
1951
+ return asset2.set(0.00000001);
1952
+ case Chain.THORChain:
1953
+ case Chain.Maya:
1954
+ return asset2.set(0);
1955
+ case Chain.Cosmos:
1956
+ return asset2.set(0.000001);
1957
+ default:
1958
+ return asset2.set(0.00000001);
1959
+ }
1960
+ }
1961
+ async function createAssetValue(identifier, value = 0) {
1962
+ validateIdentifier(identifier);
1963
+ const staticToken = staticTokensMap.get(identifier.toUpperCase());
1964
+ const decimal = staticToken?.decimal || await getDecimal(getAssetInfo(identifier));
1965
+ if (!staticToken) {
1966
+ staticTokensMap.set(identifier.toUpperCase(), { identifier, decimal });
1967
+ }
1968
+ return new AssetValue({ decimal, value: safeValue(value, decimal), identifier });
1969
+ }
1970
+ var createSyntheticAssetValue = function(identifier, value = 0) {
1971
+ const [synthChain, symbol] = identifier.split(".")?.[0]?.toUpperCase() === Chain.THORChain ? identifier.split(".").slice(1).join().split("/") : identifier.split("/");
1972
+ if (!(synthChain && symbol))
1973
+ throw new Error("Invalid asset identifier");
1974
+ return new AssetValue({
1975
+ decimal: 8,
1976
+ value: safeValue(value, 8),
1977
+ identifier: `${Chain.THORChain}.${synthChain}/${symbol}`
1978
+ });
1979
+ };
1980
+ var safeValue = function(value, decimal) {
1981
+ return typeof value === "bigint" ? formatBigIntToSafeValue({ value, bigIntDecimal: decimal, decimal }) : value;
1982
+ };
1983
+ var getAssetInfo = function(identifier) {
1984
+ const isSynthetic = identifier.slice(0, 14).includes("/");
1985
+ const isThorchain = identifier.split(".")?.[0]?.toUpperCase() === Chain.THORChain;
1986
+ const isMaya = identifier.split(".")?.[0]?.toUpperCase() === Chain.Maya;
1987
+ const [synthChain, synthSymbol = ""] = isThorchain || isMaya ? identifier.split(".").slice(1).join().split("/") : identifier.split("/");
1988
+ if (isSynthetic && !(synthChain && synthSymbol))
1989
+ throw new Error("Invalid asset identifier");
1990
+ const adjustedIdentifier = identifier.includes(".") && !isSynthetic ? identifier : `${isMaya ? Chain.Maya : Chain.THORChain}.${synthSymbol}`;
1991
+ const [chain, ...rest] = adjustedIdentifier.split(".");
1992
+ const symbol = isSynthetic ? synthSymbol : rest.join(".");
1993
+ const splitSymbol = symbol.split("-");
1994
+ const ticker = splitSymbol.length === 1 ? splitSymbol[0] : splitSymbol.slice(0, -1).join("-");
1995
+ const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
1996
+ return {
1997
+ address: address?.toLowerCase(),
1998
+ chain,
1999
+ isGasAsset: isGasAsset({ chain, symbol }),
2000
+ isSynthetic,
2001
+ symbol: (isSynthetic ? `${synthChain}/` : "") + (address ? `${ticker}-${address?.toLowerCase() ?? ""}` : symbol),
2002
+ ticker
2003
+ };
2004
+ };
2005
+ var staticTokensMap = new Map;
2006
+
2007
+ class AssetValue extends BigIntArithmetics {
2008
+ address;
2009
+ chain;
2010
+ isGasAsset = false;
2011
+ isSynthetic = false;
2012
+ symbol;
2013
+ tax;
2014
+ ticker;
2015
+ type;
2016
+ chainId;
2017
+ constructor({
2018
+ value,
2019
+ decimal,
2020
+ tax,
2021
+ chain,
2022
+ symbol,
2023
+ identifier
2024
+ }) {
2025
+ super(typeof value === "object" ? value : { decimal, value });
2026
+ const assetInfo = getAssetInfo(identifier || `${chain}.${symbol}`);
2027
+ this.type = getAssetType(assetInfo);
2028
+ this.tax = tax;
2029
+ this.chain = assetInfo.chain;
2030
+ this.ticker = assetInfo.ticker;
2031
+ this.symbol = assetInfo.symbol;
2032
+ this.address = assetInfo.address;
2033
+ this.isSynthetic = assetInfo.isSynthetic;
2034
+ this.isGasAsset = assetInfo.isGasAsset;
2035
+ this.chainId = ChainToChainId[assetInfo.chain];
2036
+ }
2037
+ toString() {
2038
+ return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
2039
+ }
2040
+ toUrl() {
2041
+ return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
2042
+ }
2043
+ eqAsset({ chain, symbol }) {
2044
+ return this.chain === chain && this.symbol === symbol;
2045
+ }
2046
+ eq(assetValue) {
2047
+ return this.eqAsset(assetValue) && this.eqValue(assetValue);
2048
+ }
2049
+ static fromUrl(urlAsset, value = 0) {
2050
+ const [chain, ticker, symbol] = urlAsset.split(".");
2051
+ if (!(chain && ticker))
2052
+ throw new Error("Invalid asset url");
2053
+ const assetString = chain === Chain.THORChain && symbol ? `${chain}.${ticker}/${symbol}` : urlAsset;
2054
+ return createAssetValue(assetString, value);
2055
+ }
2056
+ static fromString(assetString, value = 0) {
2057
+ return createAssetValue(assetString, value);
2058
+ }
2059
+ static fromIdentifier(assetString, value = 0) {
2060
+ return createAssetValue(assetString, value);
2061
+ }
2062
+ static fromStringSync(assetString, value = 0) {
2063
+ const { chain, isSynthetic } = getAssetInfo(assetString);
2064
+ const tokenInfo = staticTokensMap.get(assetString.toUpperCase());
2065
+ if (isSynthetic)
2066
+ return createSyntheticAssetValue(assetString, value);
2067
+ const { tax, decimal, identifier } = tokenInfo || {
2068
+ decimal: BaseDecimal[chain],
2069
+ identifier: assetString
2070
+ };
2071
+ return new AssetValue({
2072
+ tax,
2073
+ value: safeValue(value, decimal),
2074
+ identifier: isSynthetic ? assetString : identifier,
2075
+ decimal: isSynthetic ? 8 : decimal
2076
+ });
2077
+ }
2078
+ static async fromStringWithBase(assetString, value = 0, baseDecimal = BaseDecimal.THOR) {
2079
+ const shiftedAmount = BigIntArithmetics.shiftDecimals({
2080
+ value: SwapKitNumber.fromBigInt(BigInt(value)),
2081
+ from: 0,
2082
+ to: baseDecimal
2083
+ }).getBaseValue("string");
2084
+ const assetValue = await AssetValue.fromString(assetString, value);
2085
+ return assetValue.set(shiftedAmount);
2086
+ }
2087
+ static fromStringWithBaseSync(assetString, value = 0, baseDecimal = BaseDecimal.THOR) {
2088
+ const { chain, isSynthetic } = getAssetInfo(assetString);
2089
+ const tokenInfo = staticTokensMap.get(assetString.toUpperCase());
2090
+ if (isSynthetic)
2091
+ return createSyntheticAssetValue(assetString, value);
2092
+ const { tax, decimal, identifier } = tokenInfo || {
2093
+ decimal: BaseDecimal[chain],
2094
+ identifier: assetString
2095
+ };
2096
+ return new AssetValue({
2097
+ tax,
2098
+ value: safeValue(BigInt(value), baseDecimal),
2099
+ identifier,
2100
+ decimal
2101
+ });
2102
+ }
2103
+ static fromIdentifierSync(assetString, value = 0) {
2104
+ const { chain, isSynthetic } = getAssetInfo(assetString);
2105
+ const tokenInfo = staticTokensMap.get(assetString);
2106
+ if (isSynthetic)
2107
+ return createSyntheticAssetValue(assetString, value);
2108
+ const { tax, decimal, identifier } = tokenInfo || {
2109
+ decimal: BaseDecimal[chain],
2110
+ identifier: assetString
2111
+ };
2112
+ return new AssetValue({ tax, decimal, identifier, value: safeValue(value, decimal) });
2113
+ }
2114
+ static fromChainOrSignature(assetString, value = 0) {
2115
+ const { decimal, identifier } = getCommonAssetInfo(assetString);
2116
+ return new AssetValue({ value: safeValue(value, decimal), decimal, identifier });
2117
+ }
2118
+ static loadStaticAssets() {
2119
+ return new Promise((resolve, reject) => {
2120
+ try {
2121
+ import("@swapkit/tokens").then((tokenPackages) => {
2122
+ for (const tokenList of Object.values(tokenPackages)) {
2123
+ for (const { identifier, chain, ...rest } of tokenList.tokens) {
2124
+ staticTokensMap.set(identifier.toUpperCase(), {
2125
+ identifier,
2126
+ decimal: "decimals" in rest ? rest.decimals : BaseDecimal[chain]
2127
+ });
2128
+ }
2129
+ }
2130
+ resolve({ ok: true });
2131
+ });
2132
+ } catch (error) {
2133
+ console.error(error);
2134
+ reject({
2135
+ ok: false,
2136
+ error,
2137
+ message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
2138
+ });
2139
+ }
2140
+ });
2141
+ }
2142
+ }
2143
+
2144
+ // src/modules/requestClient.ts
2145
+ import ky from "ky";
2146
+ function setRequestClientConfig({ apiKey, ...config }) {
2147
+ kyClient = ky.create({
2148
+ ...config,
2149
+ headers: { ...defaultRequestHeaders, ...config.headers, "x-api-key": apiKey }
2150
+ });
2151
+ }
2152
+ var getKyClient = function() {
2153
+ if (kyClient)
2154
+ return kyClient;
2155
+ kyClient = ky.create({ headers: defaultRequestHeaders });
2156
+ return kyClient;
2157
+ };
2158
+ var kyClient;
2159
+ var defaultRequestHeaders = typeof window !== "undefined" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" };
2160
+ var getTypedBaseRequestClient = (ky2) => ({
2161
+ get: (url, options) => ky2.get(url, options).json(),
2162
+ post: (url, options) => ky2.post(url, options).json()
2163
+ });
2164
+ var RequestClient = {
2165
+ ...getTypedBaseRequestClient(getKyClient()),
2166
+ extend: (options) => {
2167
+ const extendedClient = getKyClient().extend(options);
2168
+ return {
2169
+ ...getTypedBaseRequestClient(extendedClient),
2170
+ extend: RequestClient.extend
2171
+ };
2172
+ }
2173
+ };
2174
+
2175
+ // src/helpers/asset.ts
2176
+ async function findAssetBy(params) {
2177
+ const tokenPackages = await import("@swapkit/tokens");
2178
+ for (const tokenList of Object.values(tokenPackages)) {
2179
+ for (const { identifier, chain: tokenChain, ...rest } of tokenList.tokens) {
2180
+ if ("identifier" in params && identifier === params.identifier) {
2181
+ return identifier;
2182
+ }
2183
+ if ("address" in rest && "chain" in params && tokenChain === params.chain && rest.address.toLowerCase() === params.contract.toLowerCase())
2184
+ return identifier;
2185
+ }
2186
+ }
2187
+ return;
2188
+ }
2189
+ var getDecimalMethodHex = "0x313ce567";
2190
+ var getContractDecimals = async ({ chain, to }) => {
2191
+ try {
2192
+ const { result } = await RequestClient.post(ChainToRPC[chain], {
2193
+ headers: {
2194
+ accept: "*/*",
2195
+ "content-type": "application/json",
2196
+ "cache-control": "no-cache"
2197
+ },
2198
+ body: JSON.stringify({
2199
+ id: 44,
2200
+ jsonrpc: "2.0",
2201
+ method: "eth_call",
2202
+ params: [{ to: to.toLowerCase(), data: getDecimalMethodHex }, "latest"]
2203
+ })
2204
+ });
2205
+ return Number.parseInt(BigInt(result || BaseDecimal[chain]).toString());
2206
+ } catch (error) {
2207
+ console.error(error);
2208
+ return BaseDecimal[chain];
2209
+ }
2210
+ };
2211
+ var getRadixResourceDecimals = async ({ symbol }) => {
2212
+ try {
2213
+ const resourceAddress = symbol.split("-")[1]?.toLowerCase();
2214
+ const { manager } = await RequestClient.post(`${ChainToRPC[Chain.Radix]}/state/resource`, {
2215
+ headers: {
2216
+ Accept: "*/*",
2217
+ "Content-Type": "application/json"
2218
+ },
2219
+ body: JSON.stringify({
2220
+ network: "mainnet",
2221
+ resource_address: resourceAddress
2222
+ })
2223
+ });
2224
+ return manager.divisibility.value.divisibility;
2225
+ } catch (error) {
2226
+ console.error(error);
2227
+ return BaseDecimal[Chain.Radix];
2228
+ }
2229
+ };
2230
+ var getETHAssetDecimal = (symbol) => {
2231
+ if (symbol === Chain.Ethereum)
2232
+ return BaseDecimal.ETH;
2233
+ const splitSymbol = symbol.split("-");
2234
+ const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1]?.toLowerCase();
2235
+ return address?.startsWith("0x") ? getContractDecimals({ chain: Chain.Ethereum, to: address }) : BaseDecimal.ETH;
2236
+ };
2237
+ var getAVAXAssetDecimal = (symbol) => {
2238
+ const splitSymbol = symbol.split("-");
2239
+ const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
2240
+ return address?.startsWith("0x") ? getContractDecimals({ chain: Chain.Avalanche, to: address.toLowerCase() }) : BaseDecimal.AVAX;
2241
+ };
2242
+ var getBSCAssetDecimal = (symbol) => {
2243
+ if (symbol === Chain.BinanceSmartChain)
2244
+ return BaseDecimal.BSC;
2245
+ return BaseDecimal.BSC;
2246
+ };
2247
+ var getRadixAssetDecimal = (symbol) => {
2248
+ if (symbol === Chain.Radix)
2249
+ return BaseDecimal.XRD;
2250
+ return getRadixResourceDecimals({ symbol });
2251
+ };
2252
+ var getDecimal = ({ chain, symbol }) => {
2253
+ switch (chain) {
2254
+ case Chain.Ethereum:
2255
+ return getETHAssetDecimal(symbol);
2256
+ case Chain.Avalanche:
2257
+ return getAVAXAssetDecimal(symbol);
2258
+ case Chain.BinanceSmartChain:
2259
+ return getBSCAssetDecimal(symbol);
2260
+ case Chain.Radix:
2261
+ return getRadixAssetDecimal(symbol);
2262
+ default:
2263
+ return BaseDecimal[chain];
2264
+ }
2265
+ };
2266
+ var getGasAsset = ({ chain }) => {
2267
+ switch (chain) {
2268
+ case Chain.Arbitrum:
2269
+ case Chain.Optimism:
2270
+ return AssetValue.fromStringSync(`${chain}.ETH`);
2271
+ case Chain.Maya:
2272
+ return AssetValue.fromStringSync(`${chain}.CACAO`);
2273
+ case Chain.Cosmos:
2274
+ return AssetValue.fromStringSync(`${chain}.ATOM`);
2275
+ case Chain.BinanceSmartChain:
2276
+ return AssetValue.fromStringSync(`${chain}.BNB`);
2277
+ case Chain.THORChain:
2278
+ return AssetValue.fromStringSync(`${chain}.RUNE`);
2279
+ default:
2280
+ return AssetValue.fromStringSync(`${chain}.${chain}`);
2281
+ }
2282
+ };
2283
+ var isGasAsset = ({ chain, symbol }) => {
2284
+ switch (chain) {
2285
+ case Chain.Arbitrum:
2286
+ case Chain.Optimism:
2287
+ return symbol === "ETH";
2288
+ case Chain.Maya:
2289
+ return symbol === "CACAO";
2290
+ case Chain.Cosmos:
2291
+ return symbol === "ATOM";
2292
+ case Chain.BinanceSmartChain:
2293
+ return symbol === "BNB";
2294
+ case Chain.THORChain:
2295
+ return symbol === "RUNE";
2296
+ default:
2297
+ return symbol === chain;
2298
+ }
2299
+ };
2300
+ var getCommonAssetInfo = (assetString) => {
2301
+ switch (assetString) {
2302
+ case `${Chain.Ethereum}.THOR`:
2303
+ return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
2304
+ case `${Chain.Ethereum}.vTHOR`:
2305
+ return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
2306
+ case Chain.Arbitrum:
2307
+ return { identifier: `${Chain.Arbitrum}.ETH`, decimal: BaseDecimal[assetString] };
2308
+ case Chain.Optimism:
2309
+ return { identifier: `${Chain.Optimism}.ETH`, decimal: BaseDecimal[assetString] };
2310
+ case Chain.Cosmos:
2311
+ return { identifier: "GAIA.ATOM", decimal: BaseDecimal[assetString] };
2312
+ case Chain.THORChain:
2313
+ return { identifier: "THOR.RUNE", decimal: BaseDecimal[assetString] };
2314
+ case Chain.BinanceSmartChain:
2315
+ return { identifier: "BSC.BNB", decimal: BaseDecimal[assetString] };
2316
+ case Chain.Maya:
2317
+ return { identifier: "MAYA.CACAO", decimal: BaseDecimal.MAYA };
2318
+ case `${Chain.Maya}.MAYA`:
2319
+ return { identifier: "MAYA.MAYA", decimal: 4 };
2320
+ case `${Chain.Kujira}.USK`:
2321
+ return { identifier: `${Chain.Kujira}.USK`, decimal: 6 };
2322
+ case Chain.Radix:
2323
+ return { identifier: `${Chain.Radix}.XRD`, decimal: BaseDecimal.XRD };
2324
+ default:
2325
+ return { identifier: `${assetString}.${assetString}`, decimal: BaseDecimal[assetString] };
2326
+ }
2327
+ };
2328
+ var getAssetType = ({ chain, symbol }) => {
2329
+ if (symbol.includes("/"))
2330
+ return "Synth";
2331
+ switch (chain) {
2332
+ case Chain.Cosmos:
2333
+ return symbol === "ATOM" ? "Native" : Chain.Cosmos;
2334
+ case Chain.Kujira:
2335
+ return symbol === Chain.Kujira ? "Native" : Chain.Kujira;
2336
+ case Chain.Binance:
2337
+ return symbol === Chain.Binance ? "Native" : "BEP2";
2338
+ case Chain.BinanceSmartChain:
2339
+ return symbol === Chain.Binance ? "Native" : "BEP20";
2340
+ case Chain.Ethereum:
2341
+ return symbol === Chain.Ethereum ? "Native" : "ERC20";
2342
+ case Chain.Avalanche:
2343
+ return symbol === Chain.Avalanche ? "Native" : Chain.Avalanche;
2344
+ case Chain.Polygon:
2345
+ return symbol === Chain.Polygon ? "Native" : "POLYGON";
2346
+ case Chain.Arbitrum:
2347
+ return [Chain.Ethereum, Chain.Arbitrum].includes(symbol) ? "Native" : "ARBITRUM";
2348
+ case Chain.Optimism:
2349
+ return [Chain.Ethereum, Chain.Optimism].includes(symbol) ? "Native" : "OPTIMISM";
2350
+ case Chain.Radix:
2351
+ return symbol === Chain.Radix ? "Native" : "RADIX";
2352
+ default:
2353
+ return "Native";
2354
+ }
2355
+ };
2356
+ var assetFromString = (assetString) => {
2357
+ const [chain, ...symbolArray] = assetString.split(".");
2358
+ const synth = assetString.includes("/");
2359
+ const symbol = symbolArray.join(".");
2360
+ const splitSymbol = symbol?.split("-");
2361
+ const ticker = splitSymbol?.length ? splitSymbol.length === 1 ? splitSymbol[0] : splitSymbol.slice(0, -1).join("-") : undefined;
2362
+ return { chain, symbol, ticker, synth };
2363
+ };
2364
+ var potentialScamRegex = new RegExp(/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/, "gmi");
2365
+ var evmAssetHasAddress = (assetString) => {
2366
+ const [chain, symbol] = assetString.split(".");
2367
+ if (!EVMChains.includes(chain))
2368
+ return true;
2369
+ const splitSymbol = symbol.split("-");
2370
+ const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
2371
+ return isGasAsset({ chain, symbol }) || !!address;
2372
+ };
2373
+ var filterAssets = (tokens2) => tokens2.filter(({ chain, value, symbol }) => {
2374
+ const assetString = `${chain}.${symbol}`;
2375
+ return !potentialScamRegex.test(assetString) && evmAssetHasAddress(assetString) && value !== "0";
2376
+ });
2377
+ // src/helpers/derivationPath.ts
2378
+ function getDerivationPathFor({ chain, index, addressIndex = 0, type }) {
2379
+ if (EVMChains.includes(chain)) {
2380
+ if (type === "legacy")
2381
+ return [44, 60, 0, index];
2382
+ if (type === "ledgerLive")
2383
+ return [44, 60, index, 0, addressIndex];
2384
+ return updatedLastIndex(NetworkDerivationPath[chain], index);
2385
+ }
2386
+ if ([Chain.Bitcoin, Chain.Litecoin].includes(chain)) {
2387
+ const chainId = chain === Chain.Bitcoin ? 0 : 2;
2388
+ if (type === "nativeSegwitMiddleAccount")
2389
+ return [84, chainId, index, 0, addressIndex];
2390
+ if (type === "segwit")
2391
+ return [49, chainId, 0, 0, index];
2392
+ if (type === "legacy")
2393
+ return [44, chainId, 0, 0, index];
2394
+ return updatedLastIndex(NetworkDerivationPath[chain], index);
2395
+ }
2396
+ return updatedLastIndex(NetworkDerivationPath[chain], index);
2397
+ }
2398
+ function getWalletFormatFor(path) {
2399
+ const [_, purpose, chainId] = path.split("/").map((p) => Number.parseInt(p, 10));
2400
+ if (chainId === 145)
2401
+ ;
2402
+ switch (purpose) {
2403
+ case 44:
2404
+ return "legacy";
2405
+ case 49:
2406
+ return "p2sh";
2407
+ default:
2408
+ return "bech32";
2409
+ }
2410
+ }
2411
+ var updatedLastIndex = (path, index) => [
2412
+ ...path.slice(0, path.length - 1),
2413
+ index
2414
+ ];
2415
+ // src/helpers/liquidity.ts
2416
+ function getAsymmetricRuneShare({
2417
+ liquidityUnits,
2418
+ poolUnits,
2419
+ runeDepth
2420
+ }) {
2421
+ const s = toTCSwapKitNumber(liquidityUnits);
2422
+ const T = toTCSwapKitNumber(poolUnits);
2423
+ const A = toTCSwapKitNumber(runeDepth);
2424
+ const part1 = s.mul(A);
2425
+ const part2 = T.mul(T).mul(2);
2426
+ const part3 = T.mul(s).mul(2);
2427
+ const part4 = s.mul(s);
2428
+ const part5 = T.mul(T).mul(T);
2429
+ const numerator = part1.mul(part2.sub(part3).add(part4));
2430
+ return numerator.div(part5);
2431
+ }
2432
+ function getAsymmetricAssetShare({
2433
+ liquidityUnits,
2434
+ poolUnits,
2435
+ assetDepth
2436
+ }) {
2437
+ const s = toTCSwapKitNumber(liquidityUnits);
2438
+ const T = toTCSwapKitNumber(poolUnits);
2439
+ const A = toTCSwapKitNumber(assetDepth);
2440
+ const part1 = s.mul(A);
2441
+ const part2 = T.mul(T).mul(2);
2442
+ const part3 = T.mul(s).mul(2);
2443
+ const part4 = s.mul(s);
2444
+ const numerator = part1.mul(part2.sub(part3).add(part4));
2445
+ const part5 = T.mul(T).mul(T);
2446
+ return numerator.div(part5);
2447
+ }
2448
+ function getAsymmetricRuneWithdrawAmount({
2449
+ percent,
2450
+ runeDepth,
2451
+ liquidityUnits,
2452
+ poolUnits
2453
+ }) {
2454
+ return getAsymmetricRuneShare({ runeDepth, liquidityUnits, poolUnits }).mul(percent);
2455
+ }
2456
+ function getAsymmetricAssetWithdrawAmount({
2457
+ percent,
2458
+ assetDepth,
2459
+ liquidityUnits,
2460
+ poolUnits
2461
+ }) {
2462
+ return getAsymmetricAssetShare({ assetDepth, liquidityUnits, poolUnits }).mul(percent);
2463
+ }
2464
+ var toTCSwapKitNumber = function(value) {
2465
+ return SwapKitNumber.fromBigInt(BigInt(value), BaseDecimal.THOR);
2466
+ };
2467
+ function getSymmetricPoolShare({
2468
+ liquidityUnits,
2469
+ poolUnits,
2470
+ runeDepth,
2471
+ assetDepth
2472
+ }) {
2473
+ return {
2474
+ assetAmount: toTCSwapKitNumber(assetDepth).mul(liquidityUnits).div(poolUnits),
2475
+ runeAmount: toTCSwapKitNumber(runeDepth).mul(liquidityUnits).div(poolUnits)
2476
+ };
2477
+ }
2478
+ function getSymmetricWithdraw({
2479
+ liquidityUnits,
2480
+ poolUnits,
2481
+ runeDepth,
2482
+ assetDepth,
2483
+ percent
2484
+ }) {
2485
+ return Object.fromEntries(Object.entries(getSymmetricPoolShare({ liquidityUnits, poolUnits, runeDepth, assetDepth })).map(([name, value]) => [name, value.mul(percent)]));
2486
+ }
2487
+ function getEstimatedPoolShare({
2488
+ runeDepth,
2489
+ poolUnits,
2490
+ assetDepth,
2491
+ liquidityUnits,
2492
+ runeAmount,
2493
+ assetAmount
2494
+ }) {
2495
+ const R = new SwapKitNumber({ value: runeDepth, decimal: 8 });
2496
+ const A = new SwapKitNumber({ value: assetDepth, decimal: 8 });
2497
+ const P = new SwapKitNumber({ value: poolUnits, decimal: 8 });
2498
+ const runeAddAmount = new SwapKitNumber({ value: runeAmount, decimal: 8 });
2499
+ const assetAddAmount = new SwapKitNumber({ value: assetAmount, decimal: 8 });
2500
+ const rA = runeAddAmount.mul(A);
2501
+ const aR = assetAddAmount.mul(R);
2502
+ const ra = runeAddAmount.mul(assetAddAmount);
2503
+ const RA = R.mul(A);
2504
+ const numerator = P.mul(rA.add(aR.add(ra.mul(2))));
2505
+ const denominator = rA.add(aR.add(RA.mul(2)));
2506
+ const liquidityUnitsAfterAdd = numerator.div(denominator);
2507
+ const estimatedLiquidityUnits = toTCSwapKitNumber(liquidityUnits).add(liquidityUnitsAfterAdd);
2508
+ if (liquidityUnitsAfterAdd.getBaseValue("number") === 0) {
2509
+ return estimatedLiquidityUnits.div(P).getBaseValue("number");
2510
+ }
2511
+ const newPoolUnits = P.add(estimatedLiquidityUnits);
2512
+ return estimatedLiquidityUnits.div(newPoolUnits).getBaseValue("number");
2513
+ }
2514
+ function getLiquiditySlippage({
2515
+ runeAmount,
2516
+ assetAmount,
2517
+ runeDepth,
2518
+ assetDepth
2519
+ }) {
2520
+ if (runeAmount === "0" || assetAmount === "0" || runeDepth === "0" || assetDepth === "0")
2521
+ return 0;
2522
+ const R = toTCSwapKitNumber(runeDepth);
2523
+ const T = toTCSwapKitNumber(assetDepth);
2524
+ const assetAddAmount = toTCSwapKitNumber(assetAmount);
2525
+ const runeAddAmount = toTCSwapKitNumber(runeAmount);
2526
+ const numerator = assetAddAmount.mul(R).sub(T.mul(runeAddAmount));
2527
+ const denominator = T.mul(runeAddAmount).add(R.mul(T));
2528
+ return Math.abs(numerator.div(denominator).getBaseValue("number"));
2529
+ }
2530
+ // src/helpers/memo.ts
2531
+ var getMemoFor = (memoType, options) => {
2532
+ switch (memoType) {
2533
+ case MemoType.LEAVE:
2534
+ case MemoType.BOND: {
2535
+ const { address } = options;
2536
+ return `${memoType}:${address}`;
2537
+ }
2538
+ case MemoType.UNBOND: {
2539
+ const { address, unbondAmount } = options;
2540
+ return `${memoType}:${address}:${unbondAmount}`;
2541
+ }
2542
+ case MemoType.NAME_REGISTER: {
2543
+ const { name, chain, address, owner } = options;
2544
+ return `${memoType}:${name}:${chain}:${address}${owner ? `:${owner}` : ""}`;
2545
+ }
2546
+ case MemoType.DEPOSIT: {
2547
+ const { chain, symbol, address, singleSide } = options;
2548
+ const getPoolIdentifier = (chain2, symbol2) => {
2549
+ switch (chain2) {
2550
+ case Chain.Litecoin:
2551
+ return "l";
2552
+ case Chain.Dogecoin:
2553
+ return "d";
2554
+ case Chain.BitcoinCash:
2555
+ return "c";
2556
+ default:
2557
+ return `${chain2}.${symbol2}`;
2558
+ }
2559
+ };
2560
+ return singleSide ? `${memoType}:${chain}/${symbol}` : `${memoType}:${getPoolIdentifier(chain, symbol)}:${address || ""}`;
2561
+ }
2562
+ case MemoType.WITHDRAW: {
2563
+ const { chain, ticker, symbol, basisPoints, targetAssetString, singleSide } = options;
2564
+ const shortenedSymbol = chain === "ETH" && ticker !== "ETH" ? `${ticker}-${symbol.slice(-3)}` : symbol;
2565
+ const target = !singleSide && targetAssetString ? `:${targetAssetString}` : "";
2566
+ const assetDivider = singleSide ? "/" : ".";
2567
+ return `${memoType}:${chain}${assetDivider}${shortenedSymbol}:${basisPoints}${target}`;
2568
+ }
2569
+ case MemoType.OPEN_LOAN:
2570
+ case MemoType.CLOSE_LOAN: {
2571
+ const { asset: asset2, address } = options;
2572
+ return `${memoType}:${asset2}:${address}`;
2573
+ }
2574
+ default:
2575
+ return "";
2576
+ }
2577
+ };
2578
+ // src/modules/swapKitError.ts
2579
+ var errorMessages = {
2580
+ core_wallet_connection_not_found: 10001,
2581
+ core_estimated_max_spendable_chain_not_supported: 10002,
2582
+ core_extend_error: 10003,
2583
+ core_inbound_data_not_found: 10004,
2584
+ core_approve_asset_address_or_from_not_found: 10005,
2585
+ core_plugin_not_found: 10006,
2586
+ core_plugin_swap_not_found: 10007,
2587
+ core_approve_asset_target_invalid: 10008,
2588
+ core_chain_halted: 10099,
2589
+ core_wallet_xdefi_not_installed: 10101,
2590
+ core_wallet_evmwallet_not_installed: 10102,
2591
+ core_wallet_walletconnect_not_installed: 10103,
2592
+ core_wallet_keystore_not_installed: 10104,
2593
+ core_wallet_ledger_not_installed: 10105,
2594
+ core_wallet_trezor_not_installed: 10106,
2595
+ core_wallet_keplr_not_installed: 10107,
2596
+ core_wallet_okx_not_installed: 10108,
2597
+ core_wallet_keepkey_not_installed: 10109,
2598
+ core_swap_invalid_params: 10200,
2599
+ core_swap_route_not_complete: 10201,
2600
+ core_swap_asset_not_recognized: 10202,
2601
+ core_swap_contract_not_found: 10203,
2602
+ core_swap_route_transaction_not_found: 10204,
2603
+ core_swap_contract_not_supported: 10205,
2604
+ core_swap_transaction_error: 10206,
2605
+ core_swap_quote_mode_not_supported: 10207,
2606
+ core_transaction_deposit_error: 10301,
2607
+ core_transaction_create_liquidity_rune_error: 10302,
2608
+ core_transaction_create_liquidity_asset_error: 10303,
2609
+ core_transaction_create_liquidity_invalid_params: 10304,
2610
+ core_transaction_add_liquidity_invalid_params: 10305,
2611
+ core_transaction_add_liquidity_no_rune_address: 10306,
2612
+ core_transaction_add_liquidity_rune_error: 10307,
2613
+ core_transaction_add_liquidity_asset_error: 10308,
2614
+ core_transaction_withdraw_error: 10309,
2615
+ core_transaction_deposit_to_pool_error: 10310,
2616
+ core_transaction_deposit_insufficient_funds_error: 10311,
2617
+ core_transaction_deposit_gas_error: 10312,
2618
+ core_transaction_invalid_sender_address: 10313,
2619
+ core_transaction_deposit_server_error: 10314,
2620
+ core_transaction_user_rejected: 10315,
2621
+ core_transaction_create_liquidity_cacao_error: 10316,
2622
+ core_transaction_add_liquidity_no_cacao_address: 10306,
2623
+ core_transaction_add_liquidity_cacao_error: 10307,
2624
+ wallet_ledger_connection_error: 20001,
2625
+ wallet_ledger_connection_claimed: 20002,
2626
+ wallet_ledger_get_address_error: 20003,
2627
+ wallet_ledger_device_not_found: 20004,
2628
+ wallet_ledger_device_locked: 20005,
2629
+ chainflip_channel_error: 30001,
2630
+ chainflip_broker_recipient_error: 30002,
2631
+ api_v2_invalid_response: 40001,
2632
+ helpers_number_different_decimals: 99101
2633
+ };
2634
+
2635
+ class SwapKitError extends Error {
2636
+ constructor(errorKey, sourceError) {
2637
+ if (sourceError) {
2638
+ console.error(sourceError, {
2639
+ stack: sourceError?.stack,
2640
+ message: sourceError?.message
2641
+ });
2642
+ }
2643
+ super(errorKey, {
2644
+ cause: { code: errorMessages[errorKey], message: errorKey }
2645
+ });
2646
+ Object.setPrototypeOf(this, SwapKitError.prototype);
2647
+ }
2648
+ }
2649
+
2650
+ // src/helpers/others.ts
2651
+ function getTHORNameCost(numberOfYears) {
2652
+ if (numberOfYears < 0)
2653
+ throw new Error("Invalid number of years");
2654
+ return 10 + numberOfYears;
2655
+ }
2656
+ function getMAYANameCost(numberOfYears) {
2657
+ if (numberOfYears < 0)
2658
+ throw new Error("Invalid number of year");
2659
+ return Math.round((10 + numberOfYears * 1.0512) * 10000000000) / 10000000000;
2660
+ }
2661
+ function derivationPathToString([network3, chainId, account, change, index]) {
2662
+ const shortPath = typeof index !== "number";
2663
+ return `m/${network3}'/${chainId}'/${account}'/${change}${shortPath ? "" : `/${index}`}`;
2664
+ }
2665
+ function wrapWithThrow(fn, errorKey) {
2666
+ try {
2667
+ return fn();
2668
+ } catch (error) {
2669
+ if (errorKey) {
2670
+ throw new SwapKitError(errorKey, error);
2671
+ }
2672
+ return console.error(error);
2673
+ }
2674
+ }
2675
+ var getChainIdentifier = (chain) => {
2676
+ switch (chain) {
2677
+ case Chain.THORChain:
2678
+ return `${chain}.RUNE`;
2679
+ case Chain.Cosmos:
2680
+ return `${chain}.ATOM`;
2681
+ case Chain.BinanceSmartChain:
2682
+ return `${chain}`;
2683
+ default:
2684
+ return `${chain}.${chain}`;
2685
+ }
2686
+ };
2687
+ // src/helpers/web3wallets.ts
2688
+ function getEIP6963Wallets() {
2689
+ const providers = [];
2690
+ function onAnnouncement(event) {
2691
+ if (providers.map((p) => p.info.uuid).includes(event.detail.info.uuid))
2692
+ return;
2693
+ providers.push(event.detail);
2694
+ }
2695
+ window.addEventListener("eip6963:announceProvider", onAnnouncement);
2696
+ window.dispatchEvent(new Event("eip6963:requestProvider"));
2697
+ function removeEIP6963EventListener() {
2698
+ window.removeEventListener("eip6963:announceProvider", onAnnouncement);
2699
+ }
2700
+ return { providers, removeEIP6963EventListener };
2701
+ }
2702
+ var methodsToWrap = [
2703
+ "approve",
2704
+ "approvedAmount",
2705
+ "call",
2706
+ "sendTransaction",
2707
+ "transfer",
2708
+ "isApproved",
2709
+ "approvedAmount",
2710
+ "EIP1193SendTransaction",
2711
+ "getFeeData",
2712
+ "broadcastTransaction",
2713
+ "estimateCall",
2714
+ "estimateGasLimit",
2715
+ "estimateGasPrices",
2716
+ "createContractTxObject"
2717
+ ];
2718
+ var wrapMethodWithNetworkSwitch = (func, provider, chainId) => async (...args) => {
2719
+ try {
2720
+ await switchEVMWalletNetwork(provider, chainId);
2721
+ } catch (error) {
2722
+ throw new Error(`Failed to switch network: ${error}`);
2723
+ }
2724
+ return func(...args);
2725
+ };
2726
+ var providerRequest = ({ provider, params, method }) => {
2727
+ if (!provider?.send)
2728
+ throw new Error("Provider not found");
2729
+ const providerParams = params ? Array.isArray(params) ? params : [params] : [];
2730
+ return provider.send(method, providerParams);
2731
+ };
2732
+ var prepareNetworkSwitch = ({
2733
+ toolbox,
2734
+ chainId,
2735
+ provider = window.ethereum
2736
+ }) => {
2737
+ const wrappedMethods = methodsToWrap.reduce((object, methodName) => {
2738
+ if (!toolbox[methodName])
2739
+ return object;
2740
+ const method = toolbox[methodName];
2741
+ if (typeof method !== "function")
2742
+ return object;
2743
+ return {
2744
+ ...object,
2745
+ [methodName]: wrapMethodWithNetworkSwitch(method, provider, chainId)
2746
+ };
2747
+ }, {});
2748
+ return { ...toolbox, ...wrappedMethods };
2749
+ };
2750
+ var addEVMWalletNetwork = (provider, networkParams) => providerRequest({ provider, method: "wallet_addEthereumChain", params: [networkParams] });
2751
+ var switchEVMWalletNetwork = (provider, chainId = ChainId.EthereumHex) => providerRequest({ provider, method: "wallet_switchEthereumChain", params: [{ chainId }] });
2752
+ var addAccountsChangedCallback = (callback) => {
2753
+ window.ethereum?.on("accountsChanged", () => callback());
2754
+ window.xfi?.ethereum.on("accountsChanged", () => callback());
2755
+ };
2756
+ var getETHDefaultWallet = () => {
2757
+ const { isTrust, isBraveWallet, __XDEFI, overrideIsMetaMask, selectedProvider } = window?.ethereum || {};
2758
+ if (isTrust)
2759
+ return WalletOption.TRUSTWALLET_WEB;
2760
+ if (isBraveWallet)
2761
+ return WalletOption.BRAVE;
2762
+ if (overrideIsMetaMask && selectedProvider?.isCoinbaseWallet)
2763
+ return WalletOption.COINBASE_WEB;
2764
+ if (__XDEFI)
2765
+ WalletOption.XDEFI;
2766
+ return WalletOption.METAMASK;
2767
+ };
2768
+ var isDetected = (walletOption) => {
2769
+ return listWeb3EVMWallets().includes(walletOption);
2770
+ };
2771
+ var listWeb3EVMWallets = () => {
2772
+ const metamaskEnabled = window?.ethereum && !window.ethereum?.isBraveWallet;
2773
+ const xdefiEnabled = window?.xfi || window?.ethereum?.__XDEFI;
2774
+ const braveEnabled = window?.ethereum?.isBraveWallet;
2775
+ const trustEnabled = window?.ethereum?.isTrust || window?.trustwallet;
2776
+ const coinbaseEnabled = window?.ethereum?.overrideIsMetaMask && window?.ethereum?.selectedProvider?.isCoinbaseWallet || window?.coinbaseWalletExtension;
2777
+ const wallets = [];
2778
+ if (metamaskEnabled)
2779
+ wallets.push(WalletOption.METAMASK);
2780
+ if (xdefiEnabled)
2781
+ wallets.push(WalletOption.XDEFI);
2782
+ if (braveEnabled)
2783
+ wallets.push(WalletOption.BRAVE);
2784
+ if (trustEnabled)
2785
+ wallets.push(WalletOption.TRUSTWALLET_WEB);
2786
+ if (coinbaseEnabled)
2787
+ wallets.push(WalletOption.COINBASE_WEB);
2788
+ if (okxMobileEnabled())
2789
+ wallets.push(WalletOption.OKX_MOBILE);
2790
+ return wallets;
2791
+ };
2792
+ var okxMobileEnabled = () => {
2793
+ const ua = navigator.userAgent;
2794
+ const isIOS = /iphone|ipad|ipod|ios/i.test(ua);
2795
+ const isAndroid = /android|XiaoMi|MiuiBrowser/i.test(ua);
2796
+ const isMobile = isIOS || isAndroid;
2797
+ const isOKApp = /OKApp/i.test(ua);
2798
+ return isMobile && isOKApp;
2799
+ };
2800
+ var isWeb3Detected = () => typeof window.ethereum !== "undefined";
2801
+ export {
2802
+ wrapWithThrow,
2803
+ wrapMethodWithNetworkSwitch,
2804
+ validateTNS,
2805
+ validateIdentifier,
2806
+ switchEVMWalletNetwork,
2807
+ setRequestClientConfig,
2808
+ prepareNetworkSwitch,
2809
+ okxMobileEnabled,
2810
+ listWeb3EVMWallets,
2811
+ isWeb3Detected,
2812
+ isGasAsset,
2813
+ isDetected,
2814
+ getWalletFormatFor,
2815
+ getTHORNameCost,
2816
+ getSymmetricWithdraw,
2817
+ getSymmetricPoolShare,
2818
+ getMinAmountByChain,
2819
+ getMemoFor,
2820
+ getMAYANameCost,
2821
+ getLiquiditySlippage,
2822
+ getGasAsset,
2823
+ getEstimatedPoolShare,
2824
+ getETHDefaultWallet,
2825
+ getEIP6963Wallets,
2826
+ getDerivationPathFor,
2827
+ getDecimal,
2828
+ getCommonAssetInfo,
2829
+ getChainIdentifier,
2830
+ getAsymmetricRuneWithdrawAmount,
2831
+ getAsymmetricRuneShare,
2832
+ getAsymmetricAssetWithdrawAmount,
2833
+ getAsymmetricAssetShare,
2834
+ getAssetType,
2835
+ formatBigIntToSafeValue,
2836
+ findAssetBy,
2837
+ filterAssets,
2838
+ erc20ABI,
2839
+ derivationPathToString,
2840
+ defaultRequestHeaders,
2841
+ assetFromString,
2842
+ addEVMWalletNetwork,
2843
+ addAccountsChangedCallback,
2844
+ WarningCodeEnum,
2845
+ WalletOption,
2846
+ UTXOChains,
2847
+ TCSupportedChains,
2848
+ TCEthereumVaultAbi,
2849
+ TCBscDepositABI,
2850
+ TCAvalancheDepositABI,
2851
+ SwapKitNumber,
2852
+ SwapKitError,
2853
+ SubstrateChains,
2854
+ SWAP_OUT,
2855
+ SWAP_IN,
2856
+ RouteQuoteWarningSchema,
2857
+ RouteQuoteSchema,
2858
+ RouteQuoteMetadataSchema,
2859
+ RouteQuoteMetadataAssetSchema,
2860
+ RouteQuoteLegSchema,
2861
+ RouteLegWithoutAddressesSchema,
2862
+ RouteLegSchema,
2863
+ RequestClient,
2864
+ RPCUrl,
2865
+ QuoteResponseSchema,
2866
+ QuoteRequestSchema,
2867
+ QuoteMode,
2868
+ ProviderName,
2869
+ NetworkDerivationPath,
2870
+ MemoType,
2871
+ MayaEthereumVaultAbi,
2872
+ MayaArbitrumVaultAbi,
2873
+ MAYASupportedChains,
2874
+ LedgerErrorCode,
2875
+ FeesSchema,
2876
+ FeeTypeEnum,
2877
+ FeeOption,
2878
+ ExplorerUrl,
2879
+ EstimatedTimeSchema,
2880
+ EVMTransactionDetailsSchema,
2881
+ EVMTransactionDetailsParamsSchema,
2882
+ EVMChains,
2883
+ DerivationPath,
2884
+ CosmosChains,
2885
+ ContractAddress,
2886
+ ChainToRPC,
2887
+ ChainToHexChainId,
2888
+ ChainToExplorerUrl,
2889
+ ChainToChainId,
2890
+ ChainIdToChain,
2891
+ ChainId,
2892
+ Chain,
2893
+ BigIntArithmetics,
2894
+ BaseDecimal,
2895
+ AssetValue,
2896
+ ApproveMode,
2897
+ AGG_SWAP
2898
+ };
2899
+
2900
+ //# debugId=C3A4C0BF90BFB8F664756e2164756e21