@swapkit/helpers 1.0.0-rc.2 → 1.0.0-rc.22

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 CHANGED
@@ -1,317 +1,661 @@
1
- var rt = Object.defineProperty;
2
- var st = (n, t, e) => t in n ? rt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var _ = (n, t, e) => (st(n, typeof t != "symbol" ? t + "" : t, e), e), it = (n, t, e) => {
4
- if (!t.has(n))
1
+ var gt = Object.defineProperty;
2
+ var bt = (s, t, e) => t in s ? gt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var f = (s, t, e) => (bt(s, typeof t != "symbol" ? t + "" : t, e), e), yt = (s, t, e) => {
4
+ if (!t.has(s))
5
5
  throw TypeError("Cannot " + e);
6
6
  };
7
- var p = (n, t, e) => {
8
- if (t.has(n))
7
+ var y = (s, t, e) => {
8
+ if (t.has(s))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
- t instanceof WeakSet ? t.add(n) : t.set(n, e);
10
+ t instanceof WeakSet ? t.add(s) : t.set(s, e);
11
11
  };
12
- var d = (n, t, e) => (it(n, t, "access private method"), e);
13
- import { FeeOption as x, BaseDecimal as h, Chain as i, ChainToRPC as at, MemoType as f } from "@swapkit/types";
14
- const vt = (n) => {
15
- if (n < 0)
16
- throw new Error("Invalid number of year");
17
- return 10 + n;
18
- }, Ct = (n) => {
19
- if (n.length > 30)
20
- return !1;
21
- const t = /^[a-zA-Z0-9+_-]+$/g;
22
- return !!n.match(t);
23
- }, Tt = ([n, t, e, r, s]) => `${n}'/${t}'/${e}'/${r}${typeof s != "number" ? "" : `/${s}`}`, Bt = async (n, t) => {
24
- const e = Object.entries(t || {}).reduce(
25
- (s, [a, c]) => (c && (s[a] = c), s),
26
- {}
27
- );
28
- return (await fetch(
29
- `${n}${t ? `?${new URLSearchParams(e).toString()}` : ""}`,
30
- { method: "GET", mode: "cors", credentials: "omit", referrer: "https://sk.thorswap.net" }
31
- )).json();
32
- }, ct = async (n, t, e, r = !1) => {
33
- const s = await fetch(`${n}`, {
34
- body: t,
35
- headers: e,
36
- method: "POST",
37
- referrer: "https://sk.thorswap.net"
38
- });
39
- return r ? s.text() : s.json();
40
- }, ot = "0x313ce567", K = async ({ chain: n, to: t }) => {
12
+ var m = (s, t, e) => (yt(s, t, "access private method"), e);
13
+ import { FeeOption as L, BaseDecimal as d, Chain as o, ChainToRPC as wt, MemoType as g } from "@swapkit/types";
14
+ const At = "0x313ce567", nt = async ({ chain: s, to: t }) => {
41
15
  try {
42
- const e = await ct(
43
- at[n],
44
- JSON.stringify({
45
- method: "eth_call",
46
- params: [{ to: t.toLowerCase(), data: ot }, "latest"],
16
+ const { result: e } = await Qt.post(wt[s], {
17
+ headers: {
18
+ accept: "*/*",
19
+ "content-type": "application/json",
20
+ "cache-control": "no-cache"
21
+ },
22
+ body: JSON.stringify({
47
23
  id: 44,
48
- jsonrpc: "2.0"
49
- }),
50
- { accept: "*/*", "cache-control": "no-cache", "content-type": "application/json" },
51
- !0
52
- ), { result: r } = JSON.parse(e);
53
- return parseInt(BigInt(r).toString());
24
+ jsonrpc: "2.0",
25
+ method: "eth_call",
26
+ params: [{ to: t.toLowerCase(), data: At }, "latest"]
27
+ })
28
+ });
29
+ return parseInt(BigInt(e).toString());
54
30
  } catch (e) {
55
- return console.error(e), h[n];
56
- }
57
- }, ut = async (n) => {
58
- if (n === i.Ethereum)
59
- return h.ETH;
60
- const [, t] = n.split("-");
61
- return t != null && t.startsWith("0x") ? K({ chain: i.Ethereum, to: t }) : h.ETH;
62
- }, lt = async (n) => {
63
- const [, t] = n.split("-");
64
- return t != null && t.startsWith("0x") ? K({ chain: i.Avalanche, to: t.toLowerCase() }) : h.AVAX;
65
- }, dt = async (n) => n === i.BinanceSmartChain ? h.BSC : h.BSC, J = async ({ chain: n, symbol: t }) => {
66
- switch (n) {
67
- case i.Ethereum:
68
- return ut(t);
69
- case i.Avalanche:
70
- return lt(t);
71
- case i.BinanceSmartChain:
72
- return dt(t);
31
+ return console.error(e), d[s];
32
+ }
33
+ }, Tt = async (s) => {
34
+ if (s === o.Ethereum)
35
+ return d.ETH;
36
+ const [, t] = s.split("-");
37
+ return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH;
38
+ }, vt = async (s) => {
39
+ const [, t] = s.split("-");
40
+ return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX;
41
+ }, $t = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, Rt = async ({ chain: s, symbol: t }) => {
42
+ switch (s) {
43
+ case o.Ethereum:
44
+ return Tt(t);
45
+ case o.Avalanche:
46
+ return vt(t);
47
+ case o.BinanceSmartChain:
48
+ return $t(t);
73
49
  default:
74
- return h[n];
75
- }
76
- }, yt = {
77
- [x.Average]: 1.2,
78
- [x.Fast]: 1.5,
79
- [x.Fastest]: 2
80
- }, mt = ({ chain: n, symbol: t }) => {
81
- switch (n) {
82
- case i.Bitcoin:
83
- case i.BitcoinCash:
84
- case i.Litecoin:
85
- case i.Dogecoin:
86
- case i.Binance:
87
- case i.Ethereum:
88
- case i.Avalanche:
89
- return t === n;
90
- case i.Arbitrum:
91
- case i.Optimism:
50
+ return d[s];
51
+ }
52
+ }, re = {
53
+ [L.Average]: 1.2,
54
+ [L.Fast]: 1.5,
55
+ [L.Fastest]: 2
56
+ }, St = ({ chain: s, symbol: t }) => {
57
+ switch (s) {
58
+ case o.Bitcoin:
59
+ case o.BitcoinCash:
60
+ case o.Litecoin:
61
+ case o.Dogecoin:
62
+ case o.Binance:
63
+ case o.Ethereum:
64
+ case o.Avalanche:
65
+ return t === s;
66
+ case o.Arbitrum:
67
+ case o.Optimism:
92
68
  return t === "ETH";
93
- case i.Maya:
69
+ case o.Maya:
94
70
  return t === "CACAO";
95
- case i.Kujira:
71
+ case o.Kujira:
96
72
  return t === "KUJI";
97
- case i.Cosmos:
73
+ case o.Cosmos:
98
74
  return t === "ATOM";
99
- case i.Polygon:
75
+ case o.Polygon:
100
76
  return t === "MATIC";
101
- case i.BinanceSmartChain:
77
+ case o.BinanceSmartChain:
102
78
  return t === "BNB";
103
- case i.THORChain:
79
+ case o.THORChain:
104
80
  return t === "RUNE";
105
81
  }
106
- }, ht = (n) => {
107
- switch (n) {
82
+ }, Ct = (s) => {
83
+ switch (s) {
108
84
  case "ETH.THOR":
109
85
  return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
110
86
  case "ETH.vTHOR":
111
87
  return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
112
- case i.Cosmos:
113
- return { identifier: "GAIA.ATOM", decimal: h[n] };
114
- case i.THORChain:
115
- return { identifier: "THOR.RUNE", decimal: h[n] };
116
- case i.BinanceSmartChain:
117
- return { identifier: "BSC.BNB", decimal: h[n] };
118
- case i.Maya:
119
- return { identifier: "MAYA.CACAO", decimal: h.MAYA };
88
+ case o.Cosmos:
89
+ return { identifier: "GAIA.ATOM", decimal: d[s] };
90
+ case o.THORChain:
91
+ return { identifier: "THOR.RUNE", decimal: d[s] };
92
+ case o.BinanceSmartChain:
93
+ return { identifier: "BSC.BNB", decimal: d[s] };
94
+ case o.Maya:
95
+ return { identifier: "MAYA.CACAO", decimal: d.MAYA };
120
96
  case "MAYA.MAYA":
121
97
  return { identifier: "MAYA.MAYA", decimal: 4 };
122
- case i.Kujira:
123
- case i.Arbitrum:
124
- case i.Optimism:
125
- case i.BitcoinCash:
126
- case i.Litecoin:
127
- case i.Dogecoin:
128
- case i.Binance:
129
- case i.Avalanche:
130
- case i.Polygon:
131
- case i.Bitcoin:
132
- case i.Ethereum:
133
- return { identifier: `${n}.${n}`, decimal: h[n] };
134
- }
135
- }, _t = ({ chain: n, symbol: t }) => {
98
+ case o.Kujira:
99
+ case o.Arbitrum:
100
+ case o.Optimism:
101
+ case o.BitcoinCash:
102
+ case o.Litecoin:
103
+ case o.Dogecoin:
104
+ case o.Binance:
105
+ case o.Avalanche:
106
+ case o.Polygon:
107
+ case o.Bitcoin:
108
+ case o.Ethereum:
109
+ return { identifier: `${s}.${s}`, decimal: d[s] };
110
+ }
111
+ }, It = ({ chain: s, symbol: t }) => {
136
112
  if (t.includes("/"))
137
113
  return "Synth";
138
- switch (n) {
139
- case i.Bitcoin:
140
- case i.BitcoinCash:
141
- case i.Dogecoin:
142
- case i.Litecoin:
143
- case i.Maya:
144
- case i.THORChain:
114
+ switch (s) {
115
+ case o.Bitcoin:
116
+ case o.BitcoinCash:
117
+ case o.Dogecoin:
118
+ case o.Litecoin:
119
+ case o.Maya:
120
+ case o.THORChain:
145
121
  return "Native";
146
- case i.Cosmos:
147
- return t === "ATOM" ? "Native" : "GAIA";
148
- case i.Kujira:
149
- return t === "KUJI" ? "Native" : "KUJI";
150
- case i.Binance:
151
- return t === i.Binance ? "Native" : "BEP2";
152
- case i.BinanceSmartChain:
153
- return t === i.Binance ? "Native" : "BEP20";
154
- case i.Ethereum:
155
- return t === i.Ethereum ? "Native" : "ERC20";
156
- case i.Avalanche:
157
- return t === i.Avalanche ? "Native" : "AVAX";
158
- case i.Polygon:
159
- return t === i.Polygon ? "Native" : "POLYGON";
160
- case i.Arbitrum:
161
- return [i.Ethereum, i.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
162
- case i.Optimism:
163
- return [i.Ethereum, i.Optimism].includes(t) ? "Native" : "OPTIMISM";
164
- }
165
- }, Mt = (n) => {
122
+ case o.Cosmos:
123
+ return t === "ATOM" ? "Native" : o.Cosmos;
124
+ case o.Kujira:
125
+ return t === o.Kujira ? "Native" : o.Kujira;
126
+ case o.Binance:
127
+ return t === o.Binance ? "Native" : "BEP2";
128
+ case o.BinanceSmartChain:
129
+ return t === o.Binance ? "Native" : "BEP20";
130
+ case o.Ethereum:
131
+ return t === o.Ethereum ? "Native" : "ERC20";
132
+ case o.Avalanche:
133
+ return t === o.Avalanche ? "Native" : o.Avalanche;
134
+ case o.Polygon:
135
+ return t === o.Polygon ? "Native" : "POLYGON";
136
+ case o.Arbitrum:
137
+ return [o.Ethereum, o.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
138
+ case o.Optimism:
139
+ return [o.Ethereum, o.Optimism].includes(t) ? "Native" : "OPTIMISM";
140
+ }
141
+ }, se = (s) => {
166
142
  var c;
167
- const [t, ...e] = n.split("."), r = n.includes("/"), s = e.join("."), a = (c = s == null ? void 0 : s.split("-")) == null ? void 0 : c[0];
168
- return { chain: t, symbol: s, ticker: a, synth: r };
169
- }, gt = ({
170
- liquidityUnits: n,
143
+ const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (c = n == null ? void 0 : n.split("-")) == null ? void 0 : c[0];
144
+ return { chain: t, symbol: n, ticker: i, synth: r };
145
+ }, Et = new RegExp(
146
+ /(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
147
+ "gmi"
148
+ ), ne = (s) => s.filter(
149
+ (t) => !Et.test(t.toString()) && !t.toString().includes("undefined")
150
+ ), Ot = ({
151
+ liquidityUnits: s,
171
152
  poolUnits: t,
172
153
  runeDepth: e
173
154
  }) => {
174
- const r = m(n), s = m(t), a = m(e), c = r.mul(a), o = s.mul(s).mul(2), l = s.mul(r).mul(2), u = r.mul(r), g = s.mul(s).mul(s);
175
- return c.mul(o.sub(l).add(u)).div(g);
176
- }, pt = ({
177
- liquidityUnits: n,
155
+ const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = n.mul(n).mul(n);
156
+ return c.mul(a.sub(u).add(l)).div(h);
157
+ }, Bt = ({
158
+ liquidityUnits: s,
178
159
  poolUnits: t,
179
160
  assetDepth: e
180
161
  }) => {
181
- const r = m(n), s = m(t), a = m(e), c = r.mul(a), o = s.mul(s).mul(2), l = s.mul(r).mul(2), u = r.mul(r), g = c.mul(o.sub(l).add(u)), $ = s.mul(s).mul(s);
182
- return g.div($);
183
- }, Et = ({
184
- percent: n,
162
+ const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = c.mul(a.sub(u).add(l)), _ = n.mul(n).mul(n);
163
+ return h.div(_);
164
+ }, ie = ({
165
+ percent: s,
185
166
  runeDepth: t,
186
167
  liquidityUnits: e,
187
168
  poolUnits: r
188
- }) => gt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), Ot = ({
189
- percent: n,
169
+ }) => Ot({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), oe = ({
170
+ percent: s,
190
171
  assetDepth: t,
191
172
  liquidityUnits: e,
192
173
  poolUnits: r
193
- }) => pt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n), m = (n) => new bt({ value: n, decimal: h.THOR }), ft = ({
194
- liquidityUnits: n,
174
+ }) => Bt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), p = (s) => b.fromBigInt(BigInt(s), d.THOR), Mt = ({
175
+ liquidityUnits: s,
195
176
  poolUnits: t,
196
177
  runeDepth: e,
197
178
  assetDepth: r
198
179
  }) => ({
199
- assetAmount: m(r).mul(n).div(t),
200
- runeAmount: m(e).mul(n).div(t)
201
- }), Vt = ({
202
- liquidityUnits: n,
180
+ assetAmount: p(r).mul(s).div(t),
181
+ runeAmount: p(e).mul(s).div(t)
182
+ }), ae = ({
183
+ liquidityUnits: s,
203
184
  poolUnits: t,
204
185
  runeDepth: e,
205
186
  assetDepth: r,
206
- percent: s
187
+ percent: n
207
188
  }) => Object.fromEntries(
208
- Object.entries(ft({ liquidityUnits: n, poolUnits: t, runeDepth: e, assetDepth: r })).map(
209
- ([a, c]) => [a, c.mul(s)]
189
+ Object.entries(Mt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
190
+ ([i, c]) => [i, c.mul(n)]
210
191
  )
211
- ), Nt = ({
212
- runeDepth: n,
192
+ ), ce = ({
193
+ runeDepth: s,
213
194
  poolUnits: t,
214
195
  assetDepth: e,
215
196
  liquidityUnits: r,
216
- runeAmount: s,
217
- assetAmount: a
218
- }) => {
219
- const c = m(n), o = m(e), l = m(t), u = m(s), g = m(a), $ = u.mul(o), v = g.mul(c), D = u.mul(g), Z = c.mul(o), tt = l.mul($.add(v.add(D.mul(2)))), et = $.add(v.add(Z.mul(2))), U = tt.div(et), H = m(r).add(U);
220
- if (U.baseValueNumber === 0)
221
- return H.div(l).baseValueNumber;
222
- const nt = l.add(H);
223
- return H.div(nt).baseValueNumber;
224
- }, Rt = ({
225
197
  runeAmount: n,
198
+ assetAmount: i
199
+ }) => {
200
+ const c = new b({ value: s, decimal: 8 }), a = new b({ value: e, decimal: 8 }), u = new b({ value: t, decimal: 8 }), l = new b({ value: n, decimal: 8 }), h = new b({ value: i, decimal: 8 }), _ = l.mul(a), v = h.mul(c), j = l.mul(h), mt = c.mul(a), pt = u.mul(_.add(v.add(j.mul(2)))), ft = _.add(v.add(mt.mul(2))), Q = pt.div(ft), H = p(r).add(Q);
201
+ if (Q.getBaseValue("number") === 0)
202
+ return H.div(u).getBaseValue("number");
203
+ const _t = u.add(H);
204
+ return H.div(_t).getBaseValue("number");
205
+ }, ue = ({
206
+ runeAmount: s,
226
207
  assetAmount: t,
227
208
  runeDepth: e,
228
209
  assetDepth: r
229
210
  }) => {
230
- const s = m(e), a = m(r), c = m(t), o = m(n), l = c.mul(s).sub(a.mul(o)), u = a.mul(o).add(s.mul(a));
231
- return Math.abs(l.div(u).baseValueNumber);
232
- }, At = ({
233
- symbol: n,
211
+ if (s === "0" || t === "0" || e === "0" || r === "0")
212
+ return 0;
213
+ const n = p(e), i = p(r), c = p(t), a = p(s), u = c.mul(n).sub(i.mul(a)), l = i.mul(a).add(n.mul(i));
214
+ return Math.abs(u.div(l).getBaseValue("number"));
215
+ }, Vt = ({
216
+ symbol: s,
234
217
  ticker: t,
235
218
  chain: e
236
- }) => e === "ETH" && t !== "ETH" ? `${t}-${n.slice(-3)}` : n, kt = (n, t) => {
237
- switch (n) {
238
- case f.LEAVE:
239
- case f.BOND: {
219
+ }) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s, le = (s, t) => {
220
+ switch (s) {
221
+ case g.LEAVE:
222
+ case g.BOND: {
240
223
  const { address: e } = t;
241
- return `${n}:${e}`;
224
+ return `${s}:${e}`;
242
225
  }
243
- case f.UNBOND: {
226
+ case g.UNBOND: {
244
227
  const { address: e, unbondAmount: r } = t;
245
- return `${n}:${e}:${r * 10 ** 8}`;
228
+ return `${s}:${e}:${r * 10 ** 8}`;
246
229
  }
247
- case f.THORNAME_REGISTER: {
248
- const { name: e, chain: r, address: s, owner: a } = t;
249
- return `${n}:${e}:${r}:${s}${a ? `:${a}` : ""}`;
230
+ case g.THORNAME_REGISTER: {
231
+ const { name: e, chain: r, address: n, owner: i } = t;
232
+ return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`;
250
233
  }
251
- case f.DEPOSIT: {
252
- const { chain: e, symbol: r, address: s, singleSide: a } = t;
253
- return a ? `${n}:${e}/${r}::t:0` : `${n}:${e}.${r}:${s || ""}:t:0`;
234
+ case g.DEPOSIT: {
235
+ const { chain: e, symbol: r, address: n, singleSide: i } = t;
236
+ return i ? `${s}:${e}/${r}::t:0` : `${s}:${e}.${r}:${n || ""}:t:0`;
254
237
  }
255
- case f.WITHDRAW: {
256
- const { chain: e, ticker: r, symbol: s, basisPoints: a, targetAssetString: c, singleSide: o } = t, l = !o && c ? `:${c}` : "", u = At({ chain: e, symbol: s, ticker: r });
257
- return `${n}:${e}${o ? "/" : "."}${u}:${a}${l}`;
238
+ case g.WITHDRAW: {
239
+ const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = !a && c ? `:${c}` : "", l = Vt({ chain: e, symbol: n, ticker: r });
240
+ return `${s}:${e}${a ? "/" : "."}${l}:${i}${u}`;
258
241
  }
259
- case f.OPEN_LOAN:
260
- case f.CLOSE_LOAN: {
242
+ case g.OPEN_LOAN:
243
+ case g.CLOSE_LOAN: {
261
244
  const { asset: e, address: r } = t;
262
- return `${n}:${e}:${r}`;
245
+ return `${s}:${e}:${r}`;
263
246
  }
264
247
  default:
265
248
  return "";
266
249
  }
267
- }, y = 8, G = ({
268
- value: n,
269
- bigIntDecimal: t = y,
270
- decimal: e = y
271
- }) => {
272
- const r = n < 0n;
273
- let s = n.toString().substring(r ? 1 : 0);
274
- const a = e - (s.length - 1);
275
- a > 0 && (s = "0".repeat(a) + s);
276
- const c = s.length - e;
277
- let o = s.slice(-e);
278
- return parseInt(o[t]) >= 5 ? o = `${o.substring(0, t - 1)}${(parseInt(o[t - 1]) + 1).toString()}` : o = o.substring(0, t), `${r ? "-" : ""}${s.slice(0, c)}.${o}`.replace(
279
- /\.?0*$/,
280
- ""
281
- );
282
- }, W = Object.values(i), $t = (n = "") => {
283
- const t = n.toUpperCase(), [e] = t.split(".");
284
- if (W.includes(e))
250
+ }, he = (s) => {
251
+ if (s < 0)
252
+ throw new Error("Invalid number of year");
253
+ return 10 + s;
254
+ }, de = (s) => {
255
+ if (s.length > 30)
256
+ return !1;
257
+ const t = /^[a-zA-Z0-9+_-]+$/g;
258
+ return !!s.match(t);
259
+ }, me = ([s, t, e, r, n]) => `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
260
+ class X extends Error {
261
+ constructor(t, e, r) {
262
+ const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", c = `${n} ${i}`.trim(), a = c ? `status code ${c}` : "an unknown error";
263
+ super(`Request failed with ${a}`), Object.defineProperty(this, "response", {
264
+ enumerable: !0,
265
+ configurable: !0,
266
+ writable: !0,
267
+ value: void 0
268
+ }), Object.defineProperty(this, "request", {
269
+ enumerable: !0,
270
+ configurable: !0,
271
+ writable: !0,
272
+ value: void 0
273
+ }), Object.defineProperty(this, "options", {
274
+ enumerable: !0,
275
+ configurable: !0,
276
+ writable: !0,
277
+ value: void 0
278
+ }), this.name = "HTTPError", this.response = t, this.request = e, this.options = r;
279
+ }
280
+ }
281
+ class it extends Error {
282
+ constructor(t) {
283
+ super("Request timed out"), Object.defineProperty(this, "request", {
284
+ enumerable: !0,
285
+ configurable: !0,
286
+ writable: !0,
287
+ value: void 0
288
+ }), this.name = "TimeoutError", this.request = t;
289
+ }
290
+ }
291
+ const V = (s) => s !== null && typeof s == "object", M = (...s) => {
292
+ for (const t of s)
293
+ if ((!V(t) || Array.isArray(t)) && t !== void 0)
294
+ throw new TypeError("The `options` argument must be an object");
295
+ return J({}, ...s);
296
+ }, ot = (s = {}, t = {}) => {
297
+ const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
298
+ for (const [i, c] of n.entries())
299
+ r && c === "undefined" || c === void 0 ? e.delete(i) : e.set(i, c);
300
+ return e;
301
+ }, J = (...s) => {
302
+ let t = {}, e = {};
303
+ for (const r of s)
304
+ if (Array.isArray(r))
305
+ Array.isArray(t) || (t = []), t = [...t, ...r];
306
+ else if (V(r)) {
307
+ for (let [n, i] of Object.entries(r))
308
+ V(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
309
+ V(r.headers) && (e = ot(e, r.headers), t.headers = e);
310
+ }
311
+ return t;
312
+ }, kt = (() => {
313
+ let s = !1, t = !1;
314
+ const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
315
+ return e && r && (t = new globalThis.Request("https://empty.invalid", {
316
+ body: new globalThis.ReadableStream(),
317
+ method: "POST",
318
+ // @ts-expect-error - Types are outdated.
319
+ get duplex() {
320
+ return s = !0, "half";
321
+ }
322
+ }).headers.has("Content-Type")), s && !t;
323
+ })(), qt = typeof globalThis.AbortController == "function", xt = typeof globalThis.ReadableStream == "function", Pt = typeof globalThis.FormData == "function", at = ["get", "post", "put", "patch", "head", "delete"], Nt = {
324
+ json: "application/json",
325
+ text: "text/*",
326
+ formData: "multipart/form-data",
327
+ arrayBuffer: "*/*",
328
+ blob: "*/*"
329
+ }, D = 2147483647, ct = Symbol("stop"), jt = {
330
+ json: !0,
331
+ parseJson: !0,
332
+ searchParams: !0,
333
+ prefixUrl: !0,
334
+ retry: !0,
335
+ timeout: !0,
336
+ hooks: !0,
337
+ throwHttpErrors: !0,
338
+ onDownloadProgress: !0,
339
+ fetch: !0
340
+ }, Ht = {
341
+ method: !0,
342
+ headers: !0,
343
+ body: !0,
344
+ mode: !0,
345
+ credentials: !0,
346
+ cache: !0,
347
+ redirect: !0,
348
+ referrer: !0,
349
+ referrerPolicy: !0,
350
+ integrity: !0,
351
+ keepalive: !0,
352
+ signal: !0,
353
+ window: !0,
354
+ dispatcher: !0,
355
+ duplex: !0
356
+ }, Lt = (s) => at.includes(s) ? s.toUpperCase() : s, Dt = ["get", "put", "head", "delete", "options", "trace"], Ut = [408, 413, 429, 500, 502, 503, 504], ut = [413, 429, 503], Z = {
357
+ limit: 2,
358
+ methods: Dt,
359
+ statusCodes: Ut,
360
+ afterStatusCodes: ut,
361
+ maxRetryAfter: Number.POSITIVE_INFINITY,
362
+ backoffLimit: Number.POSITIVE_INFINITY,
363
+ delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
364
+ }, Ft = (s = {}) => {
365
+ if (typeof s == "number")
366
+ return {
367
+ ...Z,
368
+ limit: s
369
+ };
370
+ if (s.methods && !Array.isArray(s.methods))
371
+ throw new Error("retry.methods must be an array");
372
+ if (s.statusCodes && !Array.isArray(s.statusCodes))
373
+ throw new Error("retry.statusCodes must be an array");
374
+ return {
375
+ ...Z,
376
+ ...s,
377
+ afterStatusCodes: ut
378
+ };
379
+ };
380
+ async function Wt(s, t, e, r) {
381
+ return new Promise((n, i) => {
382
+ const c = setTimeout(() => {
383
+ e && e.abort(), i(new it(s));
384
+ }, r.timeout);
385
+ r.fetch(s, t).then(n).catch(i).then(() => {
386
+ clearTimeout(c);
387
+ });
388
+ });
389
+ }
390
+ async function Gt(s, { signal: t }) {
391
+ return new Promise((e, r) => {
392
+ t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
393
+ function n() {
394
+ clearTimeout(i), r(t.reason);
395
+ }
396
+ const i = setTimeout(() => {
397
+ t == null || t.removeEventListener("abort", n), e();
398
+ }, s);
399
+ });
400
+ }
401
+ const Yt = (s, t) => {
402
+ const e = {};
403
+ for (const r in t)
404
+ !(r in Ht) && !(r in jt) && !(r in s) && (e[r] = t[r]);
405
+ return e;
406
+ };
407
+ class q {
408
+ static create(t, e) {
409
+ const r = new q(t, e), n = async () => {
410
+ if (typeof r._options.timeout == "number" && r._options.timeout > D)
411
+ throw new RangeError(`The \`timeout\` option cannot be greater than ${D}`);
412
+ await Promise.resolve();
413
+ let a = await r._fetch();
414
+ for (const u of r._options.hooks.afterResponse) {
415
+ const l = await u(r.request, r._options, r._decorateResponse(a.clone()));
416
+ l instanceof globalThis.Response && (a = l);
417
+ }
418
+ if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) {
419
+ let u = new X(a, r.request, r._options);
420
+ for (const l of r._options.hooks.beforeError)
421
+ u = await l(u);
422
+ throw u;
423
+ }
424
+ if (r._options.onDownloadProgress) {
425
+ if (typeof r._options.onDownloadProgress != "function")
426
+ throw new TypeError("The `onDownloadProgress` option must be a function");
427
+ if (!xt)
428
+ throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
429
+ return r._stream(a.clone(), r._options.onDownloadProgress);
430
+ }
431
+ return a;
432
+ }, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
433
+ for (const [a, u] of Object.entries(Nt))
434
+ c[a] = async () => {
435
+ r.request.headers.set("accept", r.request.headers.get("accept") || u);
436
+ const h = (await c).clone();
437
+ if (a === "json") {
438
+ if (h.status === 204 || (await h.clone().arrayBuffer()).byteLength === 0)
439
+ return "";
440
+ if (e.parseJson)
441
+ return e.parseJson(await h.text());
442
+ }
443
+ return h[a]();
444
+ };
445
+ return c;
446
+ }
447
+ // eslint-disable-next-line complexity
448
+ constructor(t, e = {}) {
449
+ if (Object.defineProperty(this, "request", {
450
+ enumerable: !0,
451
+ configurable: !0,
452
+ writable: !0,
453
+ value: void 0
454
+ }), Object.defineProperty(this, "abortController", {
455
+ enumerable: !0,
456
+ configurable: !0,
457
+ writable: !0,
458
+ value: void 0
459
+ }), Object.defineProperty(this, "_retryCount", {
460
+ enumerable: !0,
461
+ configurable: !0,
462
+ writable: !0,
463
+ value: 0
464
+ }), Object.defineProperty(this, "_input", {
465
+ enumerable: !0,
466
+ configurable: !0,
467
+ writable: !0,
468
+ value: void 0
469
+ }), Object.defineProperty(this, "_options", {
470
+ enumerable: !0,
471
+ configurable: !0,
472
+ writable: !0,
473
+ value: void 0
474
+ }), this._input = t, this._options = {
475
+ // TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
476
+ credentials: this._input.credentials || "same-origin",
477
+ ...e,
478
+ headers: ot(this._input.headers, e.headers),
479
+ hooks: J({
480
+ beforeRequest: [],
481
+ beforeRetry: [],
482
+ beforeError: [],
483
+ afterResponse: []
484
+ }, e.hooks),
485
+ method: Lt(e.method ?? this._input.method),
486
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
487
+ prefixUrl: String(e.prefixUrl || ""),
488
+ retry: Ft(e.retry),
489
+ throwHttpErrors: e.throwHttpErrors !== !1,
490
+ timeout: e.timeout ?? 1e4,
491
+ fetch: e.fetch ?? globalThis.fetch.bind(globalThis)
492
+ }, typeof this._input != "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request))
493
+ throw new TypeError("`input` must be a string, URL, or Request");
494
+ if (this._options.prefixUrl && typeof this._input == "string") {
495
+ if (this._input.startsWith("/"))
496
+ throw new Error("`input` must not begin with a slash when using `prefixUrl`");
497
+ this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
498
+ }
499
+ if (qt) {
500
+ if (this.abortController = new globalThis.AbortController(), this._options.signal) {
501
+ const r = this._options.signal;
502
+ this._options.signal.addEventListener("abort", () => {
503
+ this.abortController.abort(r.reason);
504
+ });
505
+ }
506
+ this._options.signal = this.abortController.signal;
507
+ }
508
+ if (kt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
509
+ const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
510
+ (Pt && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(i, { ...this.request }), this._options);
511
+ }
512
+ this._options.json !== void 0 && (this._options.body = JSON.stringify(this._options.json), this.request.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json"), this.request = new globalThis.Request(this.request, { body: this._options.body }));
513
+ }
514
+ _calculateRetryDelay(t) {
515
+ if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof it)) {
516
+ if (t instanceof X) {
517
+ if (!this._options.retry.statusCodes.includes(t.response.status))
518
+ return 0;
519
+ const r = t.response.headers.get("Retry-After");
520
+ if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) {
521
+ let n = Number(r);
522
+ return Number.isNaN(n) ? n = Date.parse(r) - Date.now() : n *= 1e3, this._options.retry.maxRetryAfter !== void 0 && n > this._options.retry.maxRetryAfter ? 0 : n;
523
+ }
524
+ if (t.response.status === 413)
525
+ return 0;
526
+ }
527
+ const e = this._options.retry.delay(this._retryCount);
528
+ return Math.min(this._options.retry.backoffLimit, e);
529
+ }
530
+ return 0;
531
+ }
532
+ _decorateResponse(t) {
533
+ return this._options.parseJson && (t.json = async () => this._options.parseJson(await t.text())), t;
534
+ }
535
+ async _retry(t) {
536
+ try {
537
+ return await t();
538
+ } catch (e) {
539
+ const r = Math.min(this._calculateRetryDelay(e), D);
540
+ if (r !== 0 && this._retryCount > 0) {
541
+ await Gt(r, { signal: this._options.signal });
542
+ for (const n of this._options.hooks.beforeRetry)
543
+ if (await n({
544
+ request: this.request,
545
+ options: this._options,
546
+ error: e,
547
+ retryCount: this._retryCount
548
+ }) === ct)
549
+ return;
550
+ return this._retry(t);
551
+ }
552
+ throw e;
553
+ }
554
+ }
555
+ async _fetch() {
556
+ for (const e of this._options.hooks.beforeRequest) {
557
+ const r = await e(this.request, this._options);
558
+ if (r instanceof Request) {
559
+ this.request = r;
560
+ break;
561
+ }
562
+ if (r instanceof Response)
563
+ return r;
564
+ }
565
+ const t = Yt(this.request, this._options);
566
+ return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Wt(this.request.clone(), t, this.abortController, this._options);
567
+ }
568
+ /* istanbul ignore next */
569
+ _stream(t, e) {
570
+ const r = Number(t.headers.get("content-length")) || 0;
571
+ let n = 0;
572
+ return t.status === 204 ? (e && e({ percent: 1, totalBytes: r, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, {
573
+ status: t.status,
574
+ statusText: t.statusText,
575
+ headers: t.headers
576
+ })) : new globalThis.Response(new globalThis.ReadableStream({
577
+ async start(i) {
578
+ const c = t.body.getReader();
579
+ e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
580
+ async function a() {
581
+ const { done: u, value: l } = await c.read();
582
+ if (u) {
583
+ i.close();
584
+ return;
585
+ }
586
+ if (e) {
587
+ n += l.byteLength;
588
+ const h = r === 0 ? 0 : n / r;
589
+ e({ percent: h, transferredBytes: n, totalBytes: r }, l);
590
+ }
591
+ i.enqueue(l), await a();
592
+ }
593
+ await a();
594
+ }
595
+ }), {
596
+ status: t.status,
597
+ statusText: t.statusText,
598
+ headers: t.headers
599
+ });
600
+ }
601
+ }
602
+ /*! MIT License © Sindre Sorhus */
603
+ const F = (s) => {
604
+ const t = (e, r) => q.create(e, M(s, r));
605
+ for (const e of at)
606
+ t[e] = (r, n) => q.create(r, M(s, n, { method: e }));
607
+ return t.create = (e) => F(M(e)), t.extend = (e) => F(M(s, e)), t.stop = ct, t;
608
+ }, zt = F(), Jt = zt, Kt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Jt.create({ headers: Kt }), Qt = {
609
+ get: (s, t) => tt.get(s, t).json(),
610
+ post: (s, t) => tt.post(s, t).json()
611
+ }, et = Object.values(o), Xt = (s = "") => {
612
+ const t = s.toUpperCase(), [e] = t.split(".");
613
+ if (et.includes(e))
285
614
  return !0;
286
615
  const [r] = t.split("/");
287
- if (W.includes(r))
616
+ if (et.includes(r))
288
617
  return !0;
289
618
  throw new Error(
290
- `Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
619
+ `Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
620
+ );
621
+ }, I = 8, $ = (s) => 10n ** BigInt(s), R = (s) => Math.log10(parseFloat(s.toString()));
622
+ function x({
623
+ value: s,
624
+ bigIntDecimal: t = I,
625
+ decimal: e = I
626
+ }) {
627
+ const r = s < 0n;
628
+ let n = s.toString().substring(r ? 1 : 0);
629
+ const i = e - (n.length - 1);
630
+ i > 0 && (n = "0".repeat(i) + n);
631
+ const c = n.length - e;
632
+ let a = n.slice(-e);
633
+ return parseInt(a[t]) >= 5 ? a = `${a.substring(0, t - 1)}${(parseInt(a[t - 1]) + 1).toString()}` : a = a.substring(0, t), `${r ? "-" : ""}${n.slice(0, c)}.${a}`.replace(
634
+ /\.?0*$/,
635
+ ""
291
636
  );
292
- }, I = (n) => 10n ** BigInt(n), C = (n) => Math.log10(parseFloat(n.toString()));
293
- var w, T, R, z, k, X, O, L, b, B, V, j, S, N;
294
- const M = class M {
637
+ }
638
+ var A, S, P, lt, N, ht, O, W, T, C, B, G;
639
+ const K = class K {
295
640
  constructor(t) {
296
- p(this, w);
297
- p(this, R);
298
- p(this, k);
299
- p(this, O);
300
- p(this, b);
301
- p(this, V);
302
- p(this, S);
303
- _(this, "decimalMultiplier", 10n ** 8n);
304
- _(this, "bigIntValue", 0n);
305
- _(this, "decimal");
306
- const e = typeof t == "object", r = e ? t.value : t;
307
- this.decimal = e ? t.decimal : void 0, this.decimalMultiplier = I(
308
- Math.max(d(this, V, j).call(this, d(this, b, B).call(this, r)), this.decimal || 0)
309
- ), d(this, R, z).call(this, r);
641
+ y(this, A);
642
+ y(this, P);
643
+ y(this, N);
644
+ y(this, O);
645
+ y(this, T);
646
+ y(this, B);
647
+ f(this, "decimalMultiplier", 10n ** 8n);
648
+ f(this, "bigIntValue", 0n);
649
+ f(this, "decimal");
650
+ const e = U(t);
651
+ this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = $(
652
+ Math.max(m(this, B, G).call(this, m(this, T, C).call(this, e)), this.decimal || 0)
653
+ ), m(this, P, lt).call(this, e);
310
654
  }
311
655
  static fromBigInt(t, e) {
312
- return new M({
656
+ return new K({
313
657
  decimal: e,
314
- value: G({ value: t, bigIntDecimal: e, decimal: e })
658
+ value: x({ value: t, bigIntDecimal: e, decimal: e })
315
659
  });
316
660
  }
317
661
  static shiftDecimals({
@@ -319,40 +663,25 @@ const M = class M {
319
663
  from: e,
320
664
  to: r
321
665
  }) {
322
- return M.fromBigInt(
323
- new M(t).bigIntValue * I(r) / I(e),
666
+ return this.fromBigInt(
667
+ t.getBaseValue("bigint") * $(r) / $(e),
324
668
  r
325
669
  );
326
670
  }
327
- get unsafeNumber() {
328
- return parseFloat((this.bigIntValue / this.decimalMultiplier).toString());
329
- }
330
- get baseValue() {
331
- return d(this, S, N).call(this, "string");
332
- }
333
- get baseValueNumber() {
334
- return d(this, S, N).call(this, "number");
335
- }
336
- get baseValueBigInt() {
337
- return d(this, S, N).call(this, "number");
338
- }
339
- get value() {
340
- return this.formatBigIntToSafeValue(
341
- this.bigIntValue,
342
- this.decimal || C(this.decimalMultiplier)
343
- );
671
+ set(t) {
672
+ return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
344
673
  }
345
674
  add(...t) {
346
- return d(this, w, T).call(this, "add", ...t);
675
+ return m(this, A, S).call(this, "add", ...t);
347
676
  }
348
677
  sub(...t) {
349
- return d(this, w, T).call(this, "sub", ...t);
678
+ return m(this, A, S).call(this, "sub", ...t);
350
679
  }
351
680
  mul(...t) {
352
- return d(this, w, T).call(this, "mul", ...t);
681
+ return m(this, A, S).call(this, "mul", ...t);
353
682
  }
354
683
  div(...t) {
355
- return d(this, w, T).call(this, "div", ...t);
684
+ return m(this, A, S).call(this, "div", ...t);
356
685
  }
357
686
  gt(t) {
358
687
  return this.bigIntValue > this.getBigIntValue(t);
@@ -369,136 +698,204 @@ const M = class M {
369
698
  eqValue(t) {
370
699
  return this.bigIntValue === this.getBigIntValue(t);
371
700
  }
701
+ getValue(t) {
702
+ const e = this.formatBigIntToSafeValue(
703
+ this.bigIntValue,
704
+ this.decimal || R(this.decimalMultiplier)
705
+ );
706
+ switch (t) {
707
+ case "number":
708
+ return Number(e);
709
+ case "string":
710
+ return e;
711
+ default:
712
+ return this.bigIntValue * BigInt(this.decimal || 8n) / this.decimalMultiplier;
713
+ }
714
+ }
715
+ getBaseValue(t) {
716
+ const e = this.decimalMultiplier / $(this.decimal || d.THOR), r = this.bigIntValue / e;
717
+ switch (t) {
718
+ case "number":
719
+ return Number(r);
720
+ case "string":
721
+ return r.toString();
722
+ default:
723
+ return r;
724
+ }
725
+ }
372
726
  getBigIntValue(t, e) {
373
- return !e && typeof t == "object" ? t.bigIntValue : (t = typeof t == "object" ? t.value : t, d(this, O, L).call(this, d(this, b, B).call(this, t), e));
727
+ if (!e && typeof t == "object")
728
+ return t.bigIntValue;
729
+ const r = U(t), n = m(this, T, C).call(this, r);
730
+ return n === "0" || n === "undefined" ? 0n : m(this, O, W).call(this, n, e);
374
731
  }
375
732
  formatBigIntToSafeValue(t, e) {
376
- const r = e || this.decimal || y, s = Math.max(
733
+ const r = e || this.decimal || I, n = Math.max(
377
734
  r,
378
- C(this.decimalMultiplier)
379
- ), a = t < 0n;
380
- let c = t.toString().substring(a ? 1 : 0);
381
- const o = s - (c.length - 1);
382
- o > 0 && (c = "0".repeat(o) + c);
383
- const l = c.length - s;
384
- let u = c.slice(-s);
385
- return parseInt(u[r]) >= 5 ? u = `${u.substring(0, r - 1)}${(parseInt(u[r - 1]) + 1).toString()}` : u = u.substring(0, r), `${a ? "-" : ""}${c.slice(0, l)}.${u}`.replace(
386
- /\.?0*$/,
387
- ""
388
- );
735
+ R(this.decimalMultiplier)
736
+ ), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c, l = u.length - n;
737
+ let h = u.slice(-n);
738
+ return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${u.slice(
739
+ 0,
740
+ l
741
+ )}.${h}`.replace(/\.?0*$/, "");
742
+ }
743
+ toSignificant(t = 6) {
744
+ const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
745
+ if ((parseInt(n) ? n.length + i.length : i.length) <= t)
746
+ return this.getValue("string");
747
+ if (n.length >= t)
748
+ return n.slice(0, t).padEnd(n.length, "0");
749
+ if (parseInt(n))
750
+ return `${n}.${i.slice(0, t - n.length)}`.padEnd(
751
+ t - n.length,
752
+ "0"
753
+ );
754
+ const a = parseInt(i), u = `${a}`.slice(0, t);
755
+ return `0.${u.padStart(
756
+ i.length - `${a}`.length + u.length,
757
+ "0"
758
+ )}`;
759
+ }
760
+ toFixed(t = 6) {
761
+ const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
762
+ if (parseInt(n))
763
+ return `${n}.${i.slice(0, t)}`.padEnd(t, "0");
764
+ const c = parseInt(i), a = `${c}`.slice(0, t);
765
+ return `0.${a.padStart(
766
+ i.length - `${c}`.length + a.length,
767
+ "0"
768
+ )}`;
769
+ }
770
+ toAbbreviation(t = 2) {
771
+ const e = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], n = Math.floor(Math.log10(Math.abs(e)) / 3), i = r[n];
772
+ if (!i)
773
+ return this.getValue("string");
774
+ const c = 10 ** (n * 3);
775
+ return `${(e / c).toFixed(t)}${i}`;
389
776
  }
390
- toSignificant(t) {
391
- const e = this.value.split("."), r = e[0], s = e[1];
392
- return s ? `${r}.${s.slice(0, t || this.decimal)}`.replace(
393
- /\.?0*$/,
394
- ""
395
- ) : r;
777
+ toCurrency(t = "$", {
778
+ currencyPosition: e = "start",
779
+ decimal: r = 2,
780
+ decimalSeparator: n = ".",
781
+ thousandSeparator: i = ","
782
+ } = {}) {
783
+ const c = this.getValue("number"), [a, u = ""] = c.toFixed(6).split("."), l = a.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !a && !u ? "0.00" : a === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${l}${u ? `${n}${u.slice(0, r)}` : ""}`;
784
+ return `${e === "start" ? t : ""}${h}${e === "end" ? t : ""}`;
396
785
  }
397
786
  };
398
- w = new WeakSet(), T = function(t, ...e) {
399
- const r = d(this, k, X).call(this, this, ...e), s = I(r), a = e.reduce(
400
- (o, l) => {
401
- const u = this.getBigIntValue(l, r);
402
- if (t === "div" && u === 0n)
403
- throw new RangeError("Division by zero");
404
- return t === "add" ? o + u : t === "sub" ? o - u : t === "mul" ? o * u / s : o * s / u;
787
+ A = new WeakSet(), S = function(t, ...e) {
788
+ const r = m(this, N, ht).call(this, this, ...e), n = $(r), i = e.reduce(
789
+ (a, u) => {
790
+ const l = this.getBigIntValue(u, r);
791
+ switch (t) {
792
+ case "add":
793
+ return a + l;
794
+ case "sub":
795
+ return a - l;
796
+ case "mul":
797
+ return a * l / n;
798
+ case "div": {
799
+ if (l === 0n)
800
+ throw new RangeError("Division by zero");
801
+ return a * n / l;
802
+ }
803
+ default:
804
+ return a;
805
+ }
405
806
  },
406
807
  //normalize is to precision multiplier base
407
- this.bigIntValue * s / this.decimalMultiplier
408
- ), c = G({
808
+ this.bigIntValue * n / this.decimalMultiplier
809
+ ), c = x({
409
810
  bigIntDecimal: r,
410
- decimal: Math.max(r, C(this.decimalMultiplier)),
411
- value: a
811
+ decimal: Math.max(r, R(this.decimalMultiplier)),
812
+ value: i
412
813
  });
413
814
  return new this.constructor({ decimal: this.decimal, value: c, identifier: this.toString() });
414
- }, R = new WeakSet(), z = function(t, e) {
415
- const r = d(this, b, B).call(this, t) || "0";
416
- this.bigIntValue = e || d(this, O, L).call(this, r);
417
- }, k = new WeakSet(), X = function(...t) {
815
+ }, P = new WeakSet(), lt = function(t) {
816
+ const e = m(this, T, C).call(this, t) || "0";
817
+ this.bigIntValue = m(this, O, W).call(this, e);
818
+ }, N = new WeakSet(), ht = function(...t) {
418
819
  const e = t.map(
419
- (r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : d(this, V, j).call(this, d(this, b, B).call(this, r))
820
+ (r) => typeof r == "object" ? r.decimal || R(r.decimalMultiplier) : m(this, B, G).call(this, m(this, T, C).call(this, r))
420
821
  ).filter(Boolean);
421
- return Math.max(...e, y);
422
- }, O = new WeakSet(), L = function(t, e) {
423
- const r = e ? I(e) : this.decimalMultiplier, s = C(r), [a, c = ""] = t.split(".");
424
- return BigInt(`${a}${c.padEnd(s, "0")}`);
425
- }, b = new WeakSet(), B = function(t) {
822
+ return Math.max(...e, I);
823
+ }, O = new WeakSet(), W = function(t, e) {
824
+ const r = e ? $(e) : this.decimalMultiplier, n = R(r), [i = "", c = ""] = t.split(".");
825
+ return BigInt(`${i}${c.padEnd(n, "0")}`);
826
+ }, T = new WeakSet(), C = function(t) {
426
827
  const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
427
828
  useGrouping: !1,
428
829
  maximumFractionDigits: 20
429
- }) : t}`.replaceAll(",", ".").split(".");
830
+ }) : U(t)}`.replaceAll(",", ".").split(".");
430
831
  return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0];
431
- }, V = new WeakSet(), j = function(t) {
832
+ }, B = new WeakSet(), G = function(t) {
432
833
  var r;
433
834
  const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0;
434
- return Math.max(e, y);
435
- }, S = new WeakSet(), N = function(t) {
436
- const e = this.decimalMultiplier / I(this.decimal || 0), r = this.bigIntValue / e;
437
- switch (t) {
438
- case "number":
439
- return Number(r);
440
- case "string":
441
- return r.toString();
442
- default:
443
- return r;
444
- }
835
+ return Math.max(e, I);
445
836
  };
446
- let E = M, q;
447
- const P = (n) => {
448
- if (!q)
837
+ let E = K;
838
+ function U(s) {
839
+ return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
840
+ }
841
+ const k = (s, t) => typeof s == "bigint" ? x({ value: s, bigIntDecimal: t, decimal: t }) : s;
842
+ let Y;
843
+ const rt = (s) => {
844
+ if (!Y)
449
845
  throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
450
- return q.get(n.toUpperCase()) || { decimal: h.THOR, identifier: "" };
451
- }, Y = async (n, t = 0) => {
452
- $t(n);
453
- const e = await J(F(n));
454
- return new A({ decimal: e, value: t, identifier: n });
846
+ return Y.get(s.toUpperCase()) || { decimal: d.THOR, identifier: "" };
847
+ }, st = async (s, t = 0) => {
848
+ Xt(s);
849
+ const e = await Rt(z(s)), r = k(t, e);
850
+ return new w({ decimal: e, value: r, identifier: s });
455
851
  };
456
- class A extends E {
852
+ class w extends E {
457
853
  constructor(e) {
458
854
  super(
459
855
  e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value }
460
856
  );
461
- _(this, "address");
462
- _(this, "chain");
463
- _(this, "isSynthetic", !1);
464
- _(this, "isGasAsset", !1);
465
- _(this, "symbol");
466
- _(this, "ticker");
467
- _(this, "type");
468
- const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, s = F(r);
469
- this.type = _t(s), this.chain = s.chain, this.ticker = s.ticker, this.symbol = s.symbol, this.address = s.address, this.isSynthetic = s.isSynthetic, this.isGasAsset = s.isGasAsset;
857
+ f(this, "address");
858
+ f(this, "chain");
859
+ f(this, "isSynthetic", !1);
860
+ f(this, "isGasAsset", !1);
861
+ f(this, "symbol");
862
+ f(this, "ticker");
863
+ f(this, "type");
864
+ const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = z(r);
865
+ this.type = It(n), this.chain = n.chain, this.ticker = n.ticker, this.symbol = n.symbol, this.address = n.address, this.isSynthetic = n.isSynthetic, this.isGasAsset = n.isGasAsset;
866
+ }
867
+ get assetValue() {
868
+ return `${this.getValue("string")} ${this.ticker}`;
869
+ }
870
+ toString(e = !1) {
871
+ const r = this.isSynthetic ? this.symbol.split("-")[0] : `${this.chain}.${this.ticker}`;
872
+ return e ? r : (
873
+ // THOR.ETH/ETH | ETH.USDT-0x1234567890
874
+ `${this.chain}.${this.symbol}`
875
+ );
876
+ }
877
+ eq({ chain: e, symbol: r }) {
878
+ return this.chain === e && this.symbol === r;
470
879
  }
471
880
  static async fromString(e, r = 0) {
472
- return Y(e, r);
881
+ return st(e, r);
473
882
  }
474
883
  static fromStringSync(e, r = 0) {
475
- const { decimal: s, identifier: a } = P(
884
+ const { isSynthetic: n } = z(e), { decimal: i, identifier: c } = rt(
476
885
  e
477
- );
478
- return a ? new A({ decimal: s, identifier: a, value: r }) : void 0;
886
+ ), a = k(r, i);
887
+ return c ? new w({ decimal: i, identifier: c, value: a }) : n ? new w({ decimal: 8, identifier: e, value: a }) : void 0;
479
888
  }
480
889
  static async fromIdentifier(e, r = 0) {
481
- return Y(e, r);
890
+ return st(e, r);
482
891
  }
483
892
  static fromIdentifierSync(e, r = 0) {
484
- const { decimal: s, identifier: a } = P(e);
485
- return new A({ decimal: s, identifier: a, value: r });
893
+ const { decimal: n, identifier: i } = rt(e), c = k(r, n);
894
+ return new w({ decimal: n, identifier: i, value: c });
486
895
  }
487
896
  static fromChainOrSignature(e, r = 0) {
488
- const { decimal: s, identifier: a } = ht(e);
489
- return new A({ value: r, decimal: s, identifier: a });
490
- }
491
- static async fromTCQuote(e, r = 0) {
492
- const s = await J(F(e)), a = this.shiftDecimals({ value: r, from: h.THOR, to: s });
493
- return new A({ value: a, identifier: e, decimal: s });
494
- }
495
- static fromTCQuoteStatic(e, r = 0) {
496
- const s = P(e), a = this.shiftDecimals({
497
- value: r,
498
- from: h.THOR,
499
- to: s.decimal
500
- });
501
- return new A({ ...s, value: a });
897
+ const { decimal: n, identifier: i } = Ct(e), c = k(r, n);
898
+ return new w({ value: c, decimal: n, identifier: i });
502
899
  }
503
900
  static async loadStaticAssets() {
504
901
  return new Promise(
@@ -507,66 +904,57 @@ class A extends E {
507
904
  const {
508
905
  // Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
509
906
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
510
- ThorchainList: s,
511
- NativeList: a,
907
+ ThorchainList: n,
908
+ NativeList: i,
512
909
  ...c
513
910
  } = await import("@swapkit/tokens");
514
- q = [a, ...Object.values(c)].reduce(
515
- (l, { tokens: u }) => (u.forEach(({ identifier: g, chain: $, ...v }) => {
516
- const D = "decimals" in v ? v.decimals : h[$];
517
- l.set(g, { identifier: g, decimal: D });
518
- }), l),
911
+ Y = [i, ...Object.values(c)].reduce(
912
+ (u, { tokens: l }) => (l.forEach(({ identifier: h, chain: _, ...v }) => {
913
+ const j = "decimals" in v ? v.decimals : d[_];
914
+ u.set(h, { identifier: h, decimal: j });
915
+ }), u),
519
916
  /* @__PURE__ */ new Map()
520
917
  ), e({ ok: !0 });
521
- } catch (s) {
522
- console.error(s), r({
918
+ } catch (n) {
919
+ console.error(n), r({
523
920
  ok: !1,
524
- error: s,
921
+ error: n,
525
922
  message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
526
923
  });
527
924
  }
528
925
  }
529
926
  );
530
927
  }
531
- get assetValue() {
532
- return `${this.value} ${this.ticker}`;
533
- }
534
- toString() {
535
- return `${this.chain}.${this.symbol}`;
536
- }
537
- eq({ chain: e, symbol: r }) {
538
- return this.chain === e && this.symbol === r;
539
- }
540
928
  }
541
- const Dt = (n) => {
542
- const t = A.fromChainOrSignature(n);
543
- switch (n) {
544
- case i.Bitcoin:
545
- case i.Litecoin:
546
- case i.BitcoinCash:
547
- return t.add(10001);
548
- case i.Dogecoin:
549
- return t.add(100000001);
550
- case i.Avalanche:
551
- case i.Ethereum:
552
- return t.add(10 * 10 ** 9);
553
- case i.THORChain:
554
- case i.Maya:
555
- return t.add(0);
929
+ const pe = (s) => {
930
+ const t = w.fromChainOrSignature(s);
931
+ switch (s) {
932
+ case o.Bitcoin:
933
+ case o.Litecoin:
934
+ case o.BitcoinCash:
935
+ return t.set(10001e-8);
936
+ case o.Dogecoin:
937
+ return t.set(1.00000001);
938
+ case o.Avalanche:
939
+ case o.Ethereum:
940
+ return t.set(1e-8);
941
+ case o.THORChain:
942
+ case o.Maya:
943
+ return t.set(0);
556
944
  default:
557
- return t.add(1);
945
+ return t.set(1e-8);
558
946
  }
559
- }, F = (n) => {
560
- const t = n.slice(0, 14).includes("/"), e = n.includes(".") ? n : `${i.THORChain}.${n}`, [r, s] = e.split("."), [a, c] = s.split("-");
947
+ }, z = (s) => {
948
+ const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".").pop().split("/"), n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, c] = n.split("."), [a, u] = (t ? r : c).split("-");
561
949
  return {
562
- address: c == null ? void 0 : c.toLowerCase(),
563
- chain: r,
564
- isGasAsset: mt({ chain: r, symbol: s }),
950
+ address: u == null ? void 0 : u.toLowerCase(),
951
+ chain: i,
952
+ isGasAsset: St({ chain: i, symbol: c }),
565
953
  isSynthetic: t,
566
- symbol: c ? `${a}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : s,
567
- ticker: t ? s : a
954
+ symbol: (t ? `${e}/` : "") + (u ? `${a}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : c),
955
+ ticker: a
568
956
  };
569
- }, wt = {
957
+ }, Zt = {
570
958
  /**
571
959
  * Core
572
960
  */
@@ -623,44 +1011,47 @@ const Dt = (n) => {
623
1011
  */
624
1012
  helpers_number_different_decimals: 99101
625
1013
  };
626
- class Q extends Error {
1014
+ class dt extends Error {
627
1015
  constructor(t, e) {
628
- console.error(e), super(t, { cause: { code: wt[t], message: t } }), Object.setPrototypeOf(this, Q.prototype);
1016
+ console.error(e), super(t, { cause: { code: Zt[t], message: t } }), Object.setPrototypeOf(this, dt.prototype);
629
1017
  }
630
1018
  }
631
- class bt extends E {
1019
+ class b extends E {
632
1020
  eq(t) {
633
1021
  return this.eqValue(t);
634
1022
  }
635
- toString() {
636
- return this.value;
1023
+ static fromBigInt(t, e) {
1024
+ return new b({
1025
+ decimal: e,
1026
+ value: x({ value: t, bigIntDecimal: e, decimal: e })
1027
+ });
637
1028
  }
638
1029
  }
639
1030
  export {
640
- A as AssetValue,
641
- y as DEFAULT_DECIMAL,
642
- Q as SwapKitError,
643
- bt as SwapKitNumber,
644
- Mt as assetFromString,
645
- Tt as derivationPathToString,
646
- G as formatBigIntToSafeValue,
647
- yt as gasFeeMultiplier,
648
- _t as getAssetType,
649
- pt as getAsymmetricAssetShare,
650
- Ot as getAsymmetricAssetWithdrawAmount,
651
- gt as getAsymmetricRuneShare,
652
- Et as getAsymmetricRuneWithdrawAmount,
653
- ht as getCommonAssetInfo,
654
- J as getDecimal,
655
- Nt as getEstimatedPoolShare,
656
- Rt as getLiquiditySlippage,
657
- kt as getMemoFor,
658
- Dt as getMinAmountByChain,
659
- Bt as getRequest,
660
- ft as getSymmetricPoolShare,
661
- Vt as getSymmetricWithdraw,
662
- vt as getTHORNameCost,
663
- mt as isGasAsset,
664
- ct as postRequest,
665
- Ct as validateTHORName
1031
+ w as AssetValue,
1032
+ E as BigIntArithmetics,
1033
+ Qt as RequestClient,
1034
+ dt as SwapKitError,
1035
+ b as SwapKitNumber,
1036
+ se as assetFromString,
1037
+ me as derivationPathToString,
1038
+ ne as filterAssets,
1039
+ x as formatBigIntToSafeValue,
1040
+ re as gasFeeMultiplier,
1041
+ It as getAssetType,
1042
+ Bt as getAsymmetricAssetShare,
1043
+ oe as getAsymmetricAssetWithdrawAmount,
1044
+ Ot as getAsymmetricRuneShare,
1045
+ ie as getAsymmetricRuneWithdrawAmount,
1046
+ Ct as getCommonAssetInfo,
1047
+ Rt as getDecimal,
1048
+ ce as getEstimatedPoolShare,
1049
+ ue as getLiquiditySlippage,
1050
+ le as getMemoFor,
1051
+ pe as getMinAmountByChain,
1052
+ Mt as getSymmetricPoolShare,
1053
+ ae as getSymmetricWithdraw,
1054
+ he as getTHORNameCost,
1055
+ St as isGasAsset,
1056
+ de as validateTHORName
666
1057
  };