@swapkit/helpers 1.0.0-rc.83 → 1.0.0-rc.84

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.es.js DELETED
@@ -1,856 +0,0 @@
1
- var it = Object.defineProperty;
2
- var st = (n, t, e) => t in n ? it(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var f = (n, t, e) => (st(n, typeof t != "symbol" ? t + "" : t, e), e), at = (n, t, e) => {
4
- if (!t.has(n))
5
- throw TypeError("Cannot " + e);
6
- };
7
- var v = (n, t, e) => {
8
- if (t.has(n))
9
- throw TypeError("Cannot add the same private member more than once");
10
- t instanceof WeakSet ? t.add(n) : t.set(n, e);
11
- };
12
- var h = (n, t, e) => (at(n, t, "access private method"), e);
13
- import { RequestClient as ct } from "@swapkit/api";
14
- export * from "@swapkit/api";
15
- import { FeeOption as P, BaseDecimal as m, Chain as a, EVMChains as ot, ChainToRPC as lt, MemoType as $, ChainToChainId as ut } from "@swapkit/types";
16
- const dt = "0x313ce567", z = async ({ chain: n, to: t }) => {
17
- try {
18
- const { result: e } = await ct.post(lt[n], {
19
- headers: {
20
- accept: "*/*",
21
- "content-type": "application/json",
22
- "cache-control": "no-cache"
23
- },
24
- body: JSON.stringify({
25
- id: 44,
26
- jsonrpc: "2.0",
27
- method: "eth_call",
28
- params: [{ to: t.toLowerCase(), data: dt }, "latest"]
29
- })
30
- });
31
- return Number.parseInt(BigInt(e).toString());
32
- } catch (e) {
33
- return console.error(e), m[n];
34
- }
35
- }, mt = (n) => {
36
- if (n === a.Ethereum)
37
- return m.ETH;
38
- const [, t] = n.split("-");
39
- return t != null && t.startsWith("0x") ? z({ chain: a.Ethereum, to: t }) : m.ETH;
40
- }, ht = (n) => {
41
- const [, t] = n.split("-");
42
- return t != null && t.startsWith("0x") ? z({ chain: a.Avalanche, to: t.toLowerCase() }) : m.AVAX;
43
- }, _t = (n) => n === a.BinanceSmartChain ? m.BSC : m.BSC, ft = ({ chain: n, symbol: t }) => {
44
- switch (n) {
45
- case a.Ethereum:
46
- return mt(t);
47
- case a.Avalanche:
48
- return ht(t);
49
- case a.BinanceSmartChain:
50
- return _t(t);
51
- default:
52
- return m[n];
53
- }
54
- }, Ot = {
55
- [P.Average]: 1.2,
56
- [P.Fast]: 1.5,
57
- [P.Fastest]: 2
58
- }, J = ({ chain: n, symbol: t }) => {
59
- switch (n) {
60
- case a.Arbitrum:
61
- case a.Optimism:
62
- return t === "ETH";
63
- case a.Maya:
64
- return t === "CACAO";
65
- case a.Kujira:
66
- return t === "KUJI";
67
- case a.Cosmos:
68
- return t === "ATOM";
69
- case a.Polygon:
70
- return t === "MATIC";
71
- case a.BinanceSmartChain:
72
- return t === "BNB";
73
- case a.THORChain:
74
- return t === "RUNE";
75
- default:
76
- return t === n;
77
- }
78
- }, gt = (n) => {
79
- switch (n) {
80
- case `${a.Ethereum}.THOR`:
81
- return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
82
- case `${a.Ethereum}.vTHOR`:
83
- return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
84
- case a.Cosmos:
85
- return { identifier: "GAIA.ATOM", decimal: m[n] };
86
- case a.THORChain:
87
- return { identifier: "THOR.RUNE", decimal: m[n] };
88
- case a.BinanceSmartChain:
89
- return { identifier: "BSC.BNB", decimal: m[n] };
90
- case a.Maya:
91
- return { identifier: "MAYA.CACAO", decimal: m.MAYA };
92
- case `${a.Maya}.MAYA`:
93
- return { identifier: "MAYA.MAYA", decimal: 4 };
94
- case `${a.Kujira}.USK`:
95
- return { identifier: `${a.Kujira}.USK`, decimal: 6 };
96
- default:
97
- return { identifier: `${n}.${n}`, decimal: m[n] };
98
- }
99
- }, pt = ({ chain: n, symbol: t }) => {
100
- if (t.includes("/"))
101
- return "Synth";
102
- switch (n) {
103
- case a.Cosmos:
104
- return t === "ATOM" ? "Native" : a.Cosmos;
105
- case a.Kujira:
106
- return t === a.Kujira ? "Native" : a.Kujira;
107
- case a.Binance:
108
- return t === a.Binance ? "Native" : "BEP2";
109
- case a.BinanceSmartChain:
110
- return t === a.Binance ? "Native" : "BEP20";
111
- case a.Ethereum:
112
- return t === a.Ethereum ? "Native" : "ERC20";
113
- case a.Avalanche:
114
- return t === a.Avalanche ? "Native" : a.Avalanche;
115
- case a.Polygon:
116
- return t === a.Polygon ? "Native" : "POLYGON";
117
- case a.Arbitrum:
118
- return [a.Ethereum, a.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
119
- case a.Optimism:
120
- return [a.Ethereum, a.Optimism].includes(t) ? "Native" : "OPTIMISM";
121
- default:
122
- return "Native";
123
- }
124
- }, Tt = (n) => {
125
- var l;
126
- const [t, ...e] = n.split("."), r = n.includes("/"), i = e.join("."), s = (l = i == null ? void 0 : i.split("-")) == null ? void 0 : l[0];
127
- return { chain: t, symbol: i, ticker: s, synth: r };
128
- }, $t = new RegExp(
129
- /(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
130
- "gmi"
131
- ), At = (n) => {
132
- const [t, e] = n.split(".");
133
- if (!ot.includes(t))
134
- return !0;
135
- const [, r] = e.split("-");
136
- return J({ chain: t, symbol: e }) || !!r;
137
- }, Vt = (n) => n.filter(({ chain: t, value: e, symbol: r }) => {
138
- const i = `${t}.${r}`;
139
- return !$t.test(i) && At(i) && e !== "0";
140
- });
141
- async function Nt(n) {
142
- const t = await import("@swapkit/tokens");
143
- for (const e of Object.values(t))
144
- for (const { identifier: r, chain: i, ...s } of e.tokens)
145
- if ("identifier" in n && r === n.identifier || "address" in s && "chain" in n && i === n.chain && s.address.toLowerCase() === n.contract.toLowerCase())
146
- return r;
147
- }
148
- function bt({
149
- liquidityUnits: n,
150
- poolUnits: t,
151
- runeDepth: e
152
- }) {
153
- const r = _(n), i = _(t), s = _(e), l = r.mul(s), o = i.mul(i).mul(2), c = i.mul(r).mul(2), u = r.mul(r), d = i.mul(i).mul(i);
154
- return l.mul(o.sub(c).add(u)).div(d);
155
- }
156
- function wt({
157
- liquidityUnits: n,
158
- poolUnits: t,
159
- assetDepth: e
160
- }) {
161
- const r = _(n), i = _(t), s = _(e), l = r.mul(s), o = i.mul(i).mul(2), c = i.mul(r).mul(2), u = r.mul(r), d = l.mul(o.sub(c).add(u)), y = i.mul(i).mul(i);
162
- return d.div(y);
163
- }
164
- function Et({
165
- percent: n,
166
- runeDepth: t,
167
- liquidityUnits: e,
168
- poolUnits: r
169
- }) {
170
- return bt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n);
171
- }
172
- function Rt({
173
- percent: n,
174
- assetDepth: t,
175
- liquidityUnits: e,
176
- poolUnits: r
177
- }) {
178
- return wt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n);
179
- }
180
- function _(n) {
181
- return g.fromBigInt(BigInt(n), m.THOR);
182
- }
183
- function vt({
184
- liquidityUnits: n,
185
- poolUnits: t,
186
- runeDepth: e,
187
- assetDepth: r
188
- }) {
189
- return {
190
- assetAmount: _(r).mul(n).div(t),
191
- runeAmount: _(e).mul(n).div(t)
192
- };
193
- }
194
- function xt({
195
- liquidityUnits: n,
196
- poolUnits: t,
197
- runeDepth: e,
198
- assetDepth: r,
199
- percent: i
200
- }) {
201
- return Object.fromEntries(
202
- Object.entries(vt({ liquidityUnits: n, poolUnits: t, runeDepth: e, assetDepth: r })).map(
203
- ([s, l]) => [s, l.mul(i)]
204
- )
205
- );
206
- }
207
- function kt({
208
- runeDepth: n,
209
- poolUnits: t,
210
- assetDepth: e,
211
- liquidityUnits: r,
212
- runeAmount: i,
213
- assetAmount: s
214
- }) {
215
- const l = new g({ value: n, decimal: 8 }), o = new g({ value: e, decimal: 8 }), c = new g({ value: t, decimal: 8 }), u = new g({ value: i, decimal: 8 }), d = new g({ value: s, decimal: 8 }), y = u.mul(o), W = d.mul(l), Z = u.mul(d), tt = l.mul(o), et = c.mul(y.add(W.add(Z.mul(2)))), nt = y.add(W.add(tt.mul(2))), G = et.div(nt), j = _(r).add(G);
216
- if (G.getBaseValue("number") === 0)
217
- return j.div(c).getBaseValue("number");
218
- const rt = c.add(j);
219
- return j.div(rt).getBaseValue("number");
220
- }
221
- function Ht({
222
- runeAmount: n,
223
- assetAmount: t,
224
- runeDepth: e,
225
- assetDepth: r
226
- }) {
227
- if (n === "0" || t === "0" || e === "0" || r === "0")
228
- return 0;
229
- const i = _(e), s = _(r), l = _(t), o = _(n), c = l.mul(i).sub(s.mul(o)), u = s.mul(o).add(i.mul(s));
230
- return Math.abs(c.div(u).getBaseValue("number"));
231
- }
232
- const jt = (n, t) => {
233
- switch (n) {
234
- case $.LEAVE:
235
- case $.BOND: {
236
- const { address: e } = t;
237
- return `${n}:${e}`;
238
- }
239
- case $.UNBOND: {
240
- const { address: e, unbondAmount: r } = t;
241
- return `${n}:${e}:${r}`;
242
- }
243
- case $.THORNAME_REGISTER: {
244
- const { name: e, chain: r, address: i, owner: s } = t;
245
- return `${n}:${e}:${r}:${i}${s ? `:${s}` : ""}`;
246
- }
247
- case $.DEPOSIT: {
248
- const { chain: e, symbol: r, address: i, singleSide: s } = t;
249
- return s ? `${n}:${e}/${r}` : `${n}:${((o, c) => {
250
- switch (o) {
251
- case a.Litecoin:
252
- return "l";
253
- case a.Dogecoin:
254
- return "d";
255
- case a.BitcoinCash:
256
- return "c";
257
- default:
258
- return `${o}.${c}`;
259
- }
260
- })(e, r)}:${i || ""}`;
261
- }
262
- case $.WITHDRAW: {
263
- const { chain: e, ticker: r, symbol: i, basisPoints: s, targetAssetString: l, singleSide: o } = t, c = e === "ETH" && r !== "ETH" ? `${r}-${i.slice(-3)}` : i, u = !o && l ? `:${l}` : "";
264
- return `${n}:${e}${o ? "/" : "."}${c}:${s}${u}`;
265
- }
266
- case $.OPEN_LOAN:
267
- case $.CLOSE_LOAN: {
268
- const { asset: e, address: r } = t;
269
- return `${n}:${e}:${r}`;
270
- }
271
- default:
272
- return "";
273
- }
274
- };
275
- function Pt(n) {
276
- if (n < 0)
277
- throw new Error("Invalid number of year");
278
- return 10 + n;
279
- }
280
- function Dt(n) {
281
- if (n < 0)
282
- throw new Error("Invalid number of year");
283
- return Math.round((10 + n * 1.0512) * 1e10) / 1e10;
284
- }
285
- function Lt(n) {
286
- if (n.length > 30)
287
- return !1;
288
- const t = /^[a-zA-Z0-9+_-]+$/g;
289
- return !!n.match(t);
290
- }
291
- function Ut(n) {
292
- if (n.length > 30)
293
- return !1;
294
- const t = /^[a-zA-Z0-9+_-]+$/g;
295
- return !!n.match(t);
296
- }
297
- function Ft([n, t, e, r, i]) {
298
- return `${n}'/${t}'/${e}'/${r}${typeof i != "number" ? "" : `/${i}`}`;
299
- }
300
- const K = [...Object.values(a), "TERRA"];
301
- function Ct(n = "") {
302
- const t = n.toUpperCase(), [e] = t.split(".");
303
- if (K.includes(e))
304
- return !0;
305
- const [r] = t.split("/");
306
- if (K.includes(r))
307
- return !0;
308
- throw new Error(
309
- `Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
310
- );
311
- }
312
- const T = 8, b = (n) => 10n ** BigInt(n), B = (n) => Math.log10(Number.parseFloat(n.toString()));
313
- function x({
314
- value: n,
315
- bigIntDecimal: t = T,
316
- decimal: e = T
317
- }) {
318
- if (e === 0)
319
- return n.toString();
320
- const r = n < 0n;
321
- let i = n.toString().substring(r ? 1 : 0);
322
- const s = e - (i.length - 1);
323
- s > 0 && (i = "0".repeat(s) + i);
324
- const l = i.length - e;
325
- let o = i.slice(-e);
326
- return Number.parseInt(o[t]) >= 5 ? o = `${o.substring(0, t - 1)}${(Number.parseInt(o[t - 1]) + 1).toString()}` : o = o.substring(0, t), `${r ? "-" : ""}${i.slice(0, l)}.${o}`.replace(
327
- /\.?0*$/,
328
- ""
329
- );
330
- }
331
- var w, M, A, C, k, Q, N, U, E, F;
332
- const H = class H {
333
- constructor(t) {
334
- v(this, w);
335
- v(this, A);
336
- v(this, k);
337
- v(this, N);
338
- v(this, E);
339
- f(this, "decimalMultiplier", 10n ** 8n);
340
- f(this, "bigIntValue", 0n);
341
- f(this, "decimal");
342
- const e = q(t), r = typeof t == "object";
343
- this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : b(Math.max(Y(R(e)), this.decimal || 0)), h(this, k, Q).call(this, e);
344
- }
345
- static fromBigInt(t, e) {
346
- return new H({
347
- decimal: e,
348
- value: x({ value: t, bigIntDecimal: e, decimal: e })
349
- });
350
- }
351
- static shiftDecimals({
352
- value: t,
353
- from: e,
354
- to: r
355
- }) {
356
- return H.fromBigInt(
357
- t.getBaseValue("bigint") * b(r) / b(e),
358
- r
359
- );
360
- }
361
- set(t) {
362
- return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
363
- }
364
- add(...t) {
365
- return h(this, w, M).call(this, "add", ...t);
366
- }
367
- sub(...t) {
368
- return h(this, w, M).call(this, "sub", ...t);
369
- }
370
- mul(...t) {
371
- return h(this, w, M).call(this, "mul", ...t);
372
- }
373
- div(...t) {
374
- return h(this, w, M).call(this, "div", ...t);
375
- }
376
- gt(t) {
377
- return h(this, A, C).call(this, "gt", t);
378
- }
379
- gte(t) {
380
- return h(this, A, C).call(this, "gte", t);
381
- }
382
- lt(t) {
383
- return h(this, A, C).call(this, "lt", t);
384
- }
385
- lte(t) {
386
- return h(this, A, C).call(this, "lte", t);
387
- }
388
- eqValue(t) {
389
- return h(this, A, C).call(this, "eqValue", t);
390
- }
391
- // @ts-expect-error False positive
392
- getValue(t) {
393
- const e = this.formatBigIntToSafeValue(
394
- this.bigIntValue,
395
- this.decimal || B(this.decimalMultiplier)
396
- );
397
- switch (t) {
398
- case "number":
399
- return Number(e);
400
- case "string":
401
- return e;
402
- case "bigint":
403
- return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
404
- }
405
- }
406
- // @ts-expect-error
407
- getBaseValue(t) {
408
- const e = this.decimalMultiplier / b(this.decimal || m.THOR), r = this.bigIntValue / e;
409
- switch (t) {
410
- case "number":
411
- return Number(r);
412
- case "string":
413
- return r.toString();
414
- case "bigint":
415
- return r;
416
- }
417
- }
418
- getBigIntValue(t, e) {
419
- if (!e && typeof t == "object")
420
- return t.bigIntValue;
421
- const r = q(t), i = R(r);
422
- return i === "0" || i === "undefined" ? 0n : h(this, E, F).call(this, i, e);
423
- }
424
- toSignificant(t = 6) {
425
- const [e, r] = this.getValue("string").split("."), i = e || "", s = r || "";
426
- if ((Number.parseInt(i) ? i.length + s.length : s.length) <= t)
427
- return this.getValue("string");
428
- if (i.length >= t)
429
- return i.slice(0, t).padEnd(i.length, "0");
430
- if (Number.parseInt(i))
431
- return `${i}.${s.slice(0, t - i.length)}`.padEnd(
432
- t - i.length,
433
- "0"
434
- );
435
- const o = Number.parseInt(s), c = `${o}`.slice(0, t);
436
- return `0.${c.padStart(
437
- s.length - `${o}`.length + c.length,
438
- "0"
439
- )}`;
440
- }
441
- toFixed(t = 6) {
442
- const [e, r] = this.getValue("string").split("."), i = e || "", s = r || "";
443
- if (Number.parseInt(i))
444
- return `${i}.${s.slice(0, t)}`.padEnd(t, "0");
445
- const l = Number.parseInt(s), o = `${l}`.slice(0, t);
446
- return `0.${o.padStart(
447
- s.length - `${l}`.length + o.length,
448
- "0"
449
- )}`;
450
- }
451
- toAbbreviation(t = 2) {
452
- const e = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], i = Math.floor(Math.log10(Math.abs(e)) / 3), s = r[i];
453
- if (!s)
454
- return this.getValue("string");
455
- const l = 10 ** (i * 3);
456
- return `${(e / l).toFixed(t)}${s}`;
457
- }
458
- toCurrency(t = "$", {
459
- currencyPosition: e = "start",
460
- decimal: r = 2,
461
- decimalSeparator: i = ".",
462
- thousandSeparator: s = ","
463
- } = {}) {
464
- const l = this.getValue("number"), [o, c = ""] = l.toFixed(6).split("."), u = o.replace(/\B(?=(\d{3})+(?!\d))/g, s), d = o || c ? o === "0" ? `${Number.parseFloat(`0.${c}`)}`.replace(".", i) : `${u}${Number.parseInt(c) ? `${i}${c.slice(0, r)}` : ""}` : "0.00";
465
- return `${e === "start" ? t : ""}${d}${e === "end" ? t : ""}`;
466
- }
467
- formatBigIntToSafeValue(t, e) {
468
- const r = e || this.decimal || T, i = Math.max(
469
- r,
470
- B(this.decimalMultiplier)
471
- ), s = t < 0n, l = t.toString().substring(s ? 1 : 0), o = i - (l.length - 1), c = o > 0 ? "0".repeat(o) + l : l, u = c.length - i;
472
- let d = c.slice(-i);
473
- return Number.parseInt(d[r]) >= 5 ? d = `${d.substring(0, r - 1)}${(Number.parseInt(d[r - 1]) + 1).toString()}` : d = d.substring(0, r), `${s ? "-" : ""}${c.slice(
474
- 0,
475
- u
476
- )}.${d}`.replace(/\.?0*$/, "");
477
- }
478
- };
479
- w = new WeakSet(), M = function(t, ...e) {
480
- const r = h(this, N, U).call(this, this, ...e), i = Math.max(r, B(this.decimalMultiplier)), s = b(i), l = e.reduce(
481
- (c, u) => {
482
- const d = this.getBigIntValue(u, i);
483
- switch (t) {
484
- case "add":
485
- return c + d;
486
- case "sub":
487
- return c - d;
488
- case "mul":
489
- return c * d / s;
490
- case "div": {
491
- if (d === 0n)
492
- throw new RangeError("Division by zero");
493
- return c * s / d;
494
- }
495
- default:
496
- return c;
497
- }
498
- },
499
- //normalize is to precision multiplier base
500
- this.bigIntValue * s / this.decimalMultiplier
501
- ), o = x({
502
- bigIntDecimal: i,
503
- decimal: i,
504
- value: l
505
- });
506
- return new this.constructor({
507
- decimalMultiplier: b(i),
508
- decimal: this.decimal,
509
- value: o,
510
- identifier: this.toString()
511
- });
512
- }, A = new WeakSet(), C = function(t, ...e) {
513
- const r = h(this, N, U).call(this, this, ...e), i = this.getBigIntValue(e[0], r), s = this.getBigIntValue(this, r);
514
- switch (t) {
515
- case "gt":
516
- return s > i;
517
- case "gte":
518
- return s >= i;
519
- case "lt":
520
- return s < i;
521
- case "lte":
522
- return s <= i;
523
- case "eqValue":
524
- return s === i;
525
- }
526
- }, k = new WeakSet(), Q = function(t) {
527
- const e = R(t) || "0";
528
- this.bigIntValue = h(this, E, F).call(this, e);
529
- }, N = new WeakSet(), U = function(...t) {
530
- const e = t.map((r) => typeof r == "object" ? r.decimal || B(r.decimalMultiplier) : Y(R(r))).filter(Boolean);
531
- return Math.max(...e, T);
532
- }, E = new WeakSet(), F = function(t, e) {
533
- const r = e ? b(e) : this.decimalMultiplier, i = B(r), [s = "", l = ""] = t.split(".");
534
- return BigInt(`${s}${l.padEnd(i, "0")}`);
535
- };
536
- let V = H;
537
- const It = Intl.NumberFormat("fullwide", {
538
- useGrouping: !1,
539
- maximumFractionDigits: 20
540
- });
541
- function R(n) {
542
- const e = `${typeof n == "number" ? It.format(n) : q(n)}`.replaceAll(",", ".").split(".");
543
- return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
544
- }
545
- function Y(n) {
546
- var e;
547
- const t = ((e = n.split(".")[1]) == null ? void 0 : e.length) || 0;
548
- return Math.max(t, T);
549
- }
550
- function q(n) {
551
- return typeof n == "object" ? "getValue" in n ? n.getValue("string") : n.value : n;
552
- }
553
- class g extends V {
554
- eq(t) {
555
- return this.eqValue(t);
556
- }
557
- static fromBigInt(t, e) {
558
- return new g({
559
- decimal: e,
560
- value: x({ value: t, bigIntDecimal: e, decimal: e })
561
- });
562
- }
563
- }
564
- const I = /* @__PURE__ */ new Map();
565
- class p extends V {
566
- constructor({
567
- value: e,
568
- decimal: r,
569
- tax: i,
570
- chain: s,
571
- symbol: l,
572
- identifier: o
573
- }) {
574
- super(typeof e == "object" ? e : { decimal: r, value: e });
575
- f(this, "address");
576
- f(this, "chain");
577
- f(this, "isGasAsset", !1);
578
- f(this, "isSynthetic", !1);
579
- f(this, "symbol");
580
- f(this, "tax");
581
- f(this, "ticker");
582
- f(this, "type");
583
- const c = O(o || `${s}.${l}`);
584
- this.type = pt(c), this.tax = i, this.chain = c.chain, this.ticker = c.ticker, this.symbol = c.symbol, this.address = c.address, this.isSynthetic = c.isSynthetic, this.isGasAsset = c.isGasAsset;
585
- }
586
- toString() {
587
- return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
588
- }
589
- toUrl() {
590
- return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
591
- }
592
- eq({ chain: e, symbol: r }) {
593
- return this.chain === e && this.symbol === r;
594
- }
595
- chainId() {
596
- return ut[this.chain];
597
- }
598
- // THOR.RUNE
599
- // THOR.ETH.ETH
600
- // ETH.THOR-0x1234567890
601
- static fromUrl(e, r = 0) {
602
- const [i, s, l] = e.split(".");
603
- if (!(i && s))
604
- throw new Error("Invalid asset url");
605
- const o = i === a.THORChain && l ? `${i}.${s}/${l}` : e;
606
- return D(o, r);
607
- }
608
- static fromString(e, r = 0) {
609
- return D(e, r);
610
- }
611
- static fromIdentifier(e, r = 0) {
612
- return D(e, r);
613
- }
614
- static fromStringSync(e, r = 0) {
615
- const { chain: i, isSynthetic: s } = O(e), l = I.get(e.toUpperCase());
616
- if (s)
617
- return L(e, r);
618
- const { tax: o, decimal: c, identifier: u } = l || {
619
- decimal: m[i],
620
- identifier: e
621
- };
622
- return new p({
623
- tax: o,
624
- value: S(r, c),
625
- identifier: s ? e : u,
626
- decimal: s ? 8 : c
627
- });
628
- }
629
- static async fromStringWithBase(e, r = 0, i = m.THOR) {
630
- const s = V.shiftDecimals({
631
- value: g.fromBigInt(BigInt(r)),
632
- from: 0,
633
- to: i
634
- }).getBaseValue("string");
635
- return (await p.fromString(e, r)).set(s);
636
- }
637
- static fromStringWithBaseSync(e, r = 0, i = m.THOR) {
638
- const { chain: s, isSynthetic: l } = O(e), o = I.get(e.toUpperCase());
639
- if (l)
640
- return L(e, r);
641
- const { tax: c, decimal: u, identifier: d } = o || {
642
- decimal: m[s],
643
- identifier: e
644
- };
645
- return new p({
646
- tax: c,
647
- value: S(BigInt(r), i),
648
- identifier: d,
649
- decimal: u
650
- });
651
- }
652
- static fromIdentifierSync(e, r = 0) {
653
- const { chain: i, isSynthetic: s } = O(e), l = I.get(e);
654
- if (s)
655
- return L(e, r);
656
- const { tax: o, decimal: c, identifier: u } = l || {
657
- decimal: m[i],
658
- identifier: e
659
- };
660
- return new p({ tax: o, decimal: c, identifier: u, value: S(r, c) });
661
- }
662
- static fromChainOrSignature(e, r = 0) {
663
- const { decimal: i, identifier: s } = gt(e);
664
- return new p({ value: S(r, i), decimal: i, identifier: s });
665
- }
666
- static loadStaticAssets() {
667
- return new Promise(
668
- (e, r) => {
669
- try {
670
- import("@swapkit/tokens").then((i) => {
671
- for (const s of Object.values(i))
672
- for (const { identifier: l, chain: o, ...c } of s.tokens)
673
- I.set(l.toUpperCase(), {
674
- identifier: l,
675
- decimal: "decimals" in c ? c.decimals : m[o]
676
- });
677
- e({ ok: !0 });
678
- });
679
- } catch (i) {
680
- console.error(i), r({
681
- ok: !1,
682
- error: i,
683
- message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
684
- });
685
- }
686
- }
687
- );
688
- }
689
- }
690
- function qt(n) {
691
- const t = p.fromChainOrSignature(n);
692
- switch (n) {
693
- case a.Bitcoin:
694
- case a.Litecoin:
695
- case a.BitcoinCash:
696
- return t.set(10001e-8);
697
- case a.Dogecoin:
698
- return t.set(1.00000001);
699
- case a.Avalanche:
700
- case a.Ethereum:
701
- return t.set(1e-8);
702
- case a.THORChain:
703
- case a.Maya:
704
- return t.set(0);
705
- case a.Cosmos:
706
- return t.set(1e-6);
707
- default:
708
- return t.set(1e-8);
709
- }
710
- }
711
- async function D(n, t = 0) {
712
- Ct(n);
713
- const e = I.get(n.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await ft(O(n));
714
- return e || I.set(n.toUpperCase(), { identifier: n, decimal: r }), new p({ decimal: r, value: S(t, r), identifier: n });
715
- }
716
- function L(n, t = 0) {
717
- const [e, r] = n.split(".")[0].toUpperCase() === a.THORChain ? n.split(".").slice(1).join().split("/") : n.split("/");
718
- if (!(e && r))
719
- throw new Error("Invalid asset identifier");
720
- return new p({
721
- decimal: 8,
722
- value: S(t, 8),
723
- identifier: `${a.THORChain}.${e}/${r}`
724
- });
725
- }
726
- function S(n, t) {
727
- return typeof n == "bigint" ? x({ value: n, bigIntDecimal: t, decimal: t }) : n;
728
- }
729
- function O(n) {
730
- const t = n.slice(0, 14).includes("/"), [e, r] = n.split(".")[0].toUpperCase() === a.THORChain ? n.split(".").slice(1).join().split("/") : n.split("/");
731
- if (t && !(e && r))
732
- throw new Error("Invalid asset identifier");
733
- const i = n.includes(".") && !t ? n : `${a.THORChain}.${r}`, [s, ...l] = i.split("."), [o, c] = (t ? r : l.join(".")).split("-"), u = t ? r : l.join(".");
734
- return {
735
- address: c == null ? void 0 : c.toLowerCase(),
736
- chain: s,
737
- isGasAsset: J({ chain: s, symbol: u }),
738
- isSynthetic: t,
739
- symbol: (t ? `${e}/` : "") + (c ? `${o}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : u),
740
- ticker: o
741
- };
742
- }
743
- const St = {
744
- /**
745
- * Core
746
- */
747
- core_wallet_connection_not_found: 10001,
748
- core_estimated_max_spendable_chain_not_supported: 10002,
749
- core_extend_error: 10003,
750
- core_inbound_data_not_found: 10004,
751
- core_approve_asset_address_or_from_not_found: 10005,
752
- core_plugin_not_found: 10006,
753
- core_chain_halted: 10099,
754
- /**
755
- * Core - Wallet Connection
756
- */
757
- core_wallet_xdefi_not_installed: 10101,
758
- core_wallet_evmwallet_not_installed: 10102,
759
- core_wallet_walletconnect_not_installed: 10103,
760
- core_wallet_keystore_not_installed: 10104,
761
- core_wallet_ledger_not_installed: 10105,
762
- core_wallet_trezor_not_installed: 10106,
763
- core_wallet_keplr_not_installed: 10107,
764
- core_wallet_okx_not_installed: 10108,
765
- core_wallet_keepkey_not_installed: 10109,
766
- /**
767
- * Core - Swap
768
- */
769
- core_swap_invalid_params: 10200,
770
- core_swap_route_not_complete: 10201,
771
- core_swap_asset_not_recognized: 10202,
772
- core_swap_contract_not_found: 10203,
773
- core_swap_route_transaction_not_found: 10204,
774
- core_swap_contract_not_supported: 10205,
775
- core_swap_transaction_error: 10206,
776
- core_swap_quote_mode_not_supported: 10207,
777
- /**
778
- * Core - Transaction
779
- */
780
- core_transaction_deposit_error: 10301,
781
- core_transaction_create_liquidity_rune_error: 10302,
782
- core_transaction_create_liquidity_asset_error: 10303,
783
- core_transaction_create_liquidity_invalid_params: 10304,
784
- core_transaction_add_liquidity_invalid_params: 10305,
785
- core_transaction_add_liquidity_no_rune_address: 10306,
786
- core_transaction_add_liquidity_rune_error: 10307,
787
- core_transaction_add_liquidity_asset_error: 10308,
788
- core_transaction_withdraw_error: 10309,
789
- core_transaction_deposit_to_pool_error: 10310,
790
- core_transaction_deposit_insufficient_funds_error: 10311,
791
- core_transaction_deposit_gas_error: 10312,
792
- core_transaction_invalid_sender_address: 10313,
793
- core_transaction_deposit_server_error: 10314,
794
- core_transaction_user_rejected: 10315,
795
- /**
796
- * Wallets
797
- */
798
- wallet_ledger_connection_error: 20001,
799
- wallet_ledger_connection_claimed: 20002,
800
- wallet_ledger_get_address_error: 20003,
801
- wallet_ledger_device_not_found: 20004,
802
- wallet_ledger_device_locked: 20005,
803
- /**
804
- * Chainflip
805
- */
806
- chainflip_channel_error: 30001,
807
- chainflip_broker_recipient_error: 30002,
808
- /**
809
- * THORChain
810
- */
811
- /**
812
- * Helpers
813
- */
814
- helpers_number_different_decimals: 99101
815
- };
816
- class X extends Error {
817
- constructor(t, e) {
818
- e && console.error(e, {
819
- stack: e == null ? void 0 : e.stack,
820
- message: e == null ? void 0 : e.message
821
- }), super(t, {
822
- cause: { code: St[t], message: t }
823
- }), Object.setPrototypeOf(this, X.prototype);
824
- }
825
- }
826
- export {
827
- p as AssetValue,
828
- V as BigIntArithmetics,
829
- X as SwapKitError,
830
- g as SwapKitNumber,
831
- Tt as assetFromString,
832
- Ft as derivationPathToString,
833
- Vt as filterAssets,
834
- Nt as findAssetBy,
835
- x as formatBigIntToSafeValue,
836
- Ot as gasFeeMultiplier,
837
- pt as getAssetType,
838
- wt as getAsymmetricAssetShare,
839
- Rt as getAsymmetricAssetWithdrawAmount,
840
- bt as getAsymmetricRuneShare,
841
- Et as getAsymmetricRuneWithdrawAmount,
842
- gt as getCommonAssetInfo,
843
- ft as getDecimal,
844
- kt as getEstimatedPoolShare,
845
- Ht as getLiquiditySlippage,
846
- Dt as getMAYANameCost,
847
- jt as getMemoFor,
848
- qt as getMinAmountByChain,
849
- vt as getSymmetricPoolShare,
850
- xt as getSymmetricWithdraw,
851
- Pt as getTHORNameCost,
852
- J as isGasAsset,
853
- Ut as validateMAYAName,
854
- Lt as validateTHORName
855
- };
856
- //# sourceMappingURL=index.es.js.map