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