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

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
+ }, St = 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 St(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
+ }, $t = ({ 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) => {
166
- 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,
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) => {
142
+ var a;
143
+ const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (a = n == null ? void 0 : n.split("-")) == null ? void 0 : a[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
+ ), Bt = ({
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), a = r.mul(i), c = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = n.mul(n).mul(n);
156
+ return a.mul(c.sub(u).add(l)).div(h);
157
+ }, Ot = ({
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), a = r.mul(i), c = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = a.mul(c.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
+ }) => Bt({ 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
+ }) => Ot({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), p = (s) => b.fromBigInt(BigInt(s), d.THOR), Vt = ({
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(Vt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
190
+ ([i, a]) => [i, a.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 a = new b({ value: s, decimal: 8 }), c = 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(c), v = h.mul(a), j = l.mul(h), mt = a.mul(c), 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), a = p(t), c = p(s), u = a.mul(n).sub(i.mul(c)), l = i.mul(c).add(n.mul(i));
214
+ return Math.abs(u.div(l).getBaseValue("number"));
215
+ }, Mt = ({
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: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", l = Mt({ chain: e, symbol: n, ticker: r });
240
+ return `${s}:${e}${c ? "/" : "."}${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 || "", a = `${n} ${i}`.trim(), c = a ? `status code ${a}` : "an unknown error";
263
+ super(`Request failed with ${c}`), 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 M = (s) => s !== null && typeof s == "object", V = (...s) => {
292
+ for (const t of s)
293
+ if ((!M(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, a] of n.entries())
299
+ r && a === "undefined" || a === void 0 ? e.delete(i) : e.set(i, a);
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 (M(r)) {
307
+ for (let [n, i] of Object.entries(r))
308
+ M(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
309
+ M(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 a = setTimeout(() => {
383
+ e && e.abort(), i(new it(s));
384
+ }, r.timeout);
385
+ r.fetch(s, t).then(n).catch(i).then(() => {
386
+ clearTimeout(a);
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 c = await r._fetch();
414
+ for (const u of r._options.hooks.afterResponse) {
415
+ const l = await u(r.request, r._options, r._decorateResponse(c.clone()));
416
+ l instanceof globalThis.Response && (c = l);
417
+ }
418
+ if (r._decorateResponse(c), !c.ok && r._options.throwHttpErrors) {
419
+ let u = new X(c, 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(c.clone(), r._options.onDownloadProgress);
430
+ }
431
+ return c;
432
+ }, a = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
433
+ for (const [c, u] of Object.entries(Nt))
434
+ a[c] = async () => {
435
+ r.request.headers.set("accept", r.request.headers.get("accept") || u);
436
+ const h = (await a).clone();
437
+ if (c === "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[c]();
444
+ };
445
+ return a;
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 a = t.body.getReader();
579
+ e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
580
+ async function c() {
581
+ const { done: u, value: l } = await a.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 c();
592
+ }
593
+ await c();
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, V(s, r));
605
+ for (const e of at)
606
+ t[e] = (r, n) => q.create(r, V(s, n, { method: e }));
607
+ return t.create = (e) => F(V(e)), t.extend = (e) => F(V(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 = (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 a = n.length - e;
632
+ let c = n.slice(-e);
633
+ return parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${r ? "-" : ""}${n.slice(0, a)}.${c}`.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, $, P, lt, N, ht, B, W, T, C, O, 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, B);
645
+ y(this, T);
646
+ y(this, O);
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 = S(
652
+ Math.max(m(this, O, 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,43 @@ 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") * S(r) / S(e),
324
668
  r
325
669
  );
326
670
  }
327
- get unsafeNumber() {
328
- return parseFloat((this.bigIntValue / this.decimalMultiplier).toString());
329
- }
671
+ /**
672
+ * @deprecated Use `getBaseValue('string')` instead
673
+ */
330
674
  get baseValue() {
331
- return d(this, S, N).call(this, "string");
675
+ return this.getBaseValue("string");
332
676
  }
677
+ /**
678
+ * @deprecated Use `getBaseValue('number')` instead
679
+ */
333
680
  get baseValueNumber() {
334
- return d(this, S, N).call(this, "number");
681
+ return this.getBaseValue("number");
335
682
  }
683
+ /**
684
+ * @deprecated Use `getBaseValue('bigint')` instead
685
+ */
336
686
  get baseValueBigInt() {
337
- return d(this, S, N).call(this, "number");
687
+ return this.getBaseValue("bigint");
338
688
  }
339
- get value() {
340
- return this.formatBigIntToSafeValue(
341
- this.bigIntValue,
342
- this.decimal || C(this.decimalMultiplier)
343
- );
689
+ set(t) {
690
+ return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
344
691
  }
345
692
  add(...t) {
346
- return d(this, w, T).call(this, "add", ...t);
693
+ return m(this, A, $).call(this, "add", ...t);
347
694
  }
348
695
  sub(...t) {
349
- return d(this, w, T).call(this, "sub", ...t);
696
+ return m(this, A, $).call(this, "sub", ...t);
350
697
  }
351
698
  mul(...t) {
352
- return d(this, w, T).call(this, "mul", ...t);
699
+ return m(this, A, $).call(this, "mul", ...t);
353
700
  }
354
701
  div(...t) {
355
- return d(this, w, T).call(this, "div", ...t);
702
+ return m(this, A, $).call(this, "div", ...t);
356
703
  }
357
704
  gt(t) {
358
705
  return this.bigIntValue > this.getBigIntValue(t);
@@ -369,136 +716,195 @@ const M = class M {
369
716
  eqValue(t) {
370
717
  return this.bigIntValue === this.getBigIntValue(t);
371
718
  }
719
+ getValue(t) {
720
+ const e = this.formatBigIntToSafeValue(
721
+ this.bigIntValue,
722
+ this.decimal || R(this.decimalMultiplier)
723
+ );
724
+ switch (t) {
725
+ case "number":
726
+ return Number(e);
727
+ case "string":
728
+ return e;
729
+ default:
730
+ return this.bigIntValue * BigInt(this.decimal || 8n) / this.decimalMultiplier;
731
+ }
732
+ }
733
+ getBaseValue(t) {
734
+ const e = this.decimalMultiplier / S(this.decimal || d.THOR), r = this.bigIntValue / e;
735
+ switch (t) {
736
+ case "number":
737
+ return Number(r);
738
+ case "string":
739
+ return r.toString();
740
+ default:
741
+ return r;
742
+ }
743
+ }
372
744
  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));
745
+ if (!e && typeof t == "object")
746
+ return t.bigIntValue;
747
+ const r = U(t), n = m(this, T, C).call(this, r);
748
+ return n === "0" || n === "undefined" ? 0n : m(this, B, W).call(this, n, e);
374
749
  }
375
750
  formatBigIntToSafeValue(t, e) {
376
- const r = e || this.decimal || y, s = Math.max(
751
+ const r = e || this.decimal || I, n = Math.max(
377
752
  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
- );
753
+ R(this.decimalMultiplier)
754
+ ), i = t < 0n, a = t.toString().substring(i ? 1 : 0), c = n - (a.length - 1), u = c > 0 ? "0".repeat(c) + a : a, l = u.length - n;
755
+ let h = u.slice(-n);
756
+ 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(
757
+ 0,
758
+ l
759
+ )}.${h}`.replace(/\.?0*$/, "");
760
+ }
761
+ toSignificant(t = 6) {
762
+ const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
763
+ if ((parseInt(n) ? n.length + i.length : i.length) <= t)
764
+ return this.getValue("string");
765
+ if (n.length >= t)
766
+ return n.slice(0, t).padEnd(n.length, "0");
767
+ if (parseInt(n))
768
+ return `${n}.${i.slice(0, t - n.length)}`.padEnd(
769
+ t - n.length,
770
+ "0"
771
+ );
772
+ const c = parseInt(i), u = `${c}`.slice(0, t);
773
+ return `0.${u.padStart(
774
+ i.length - `${c}`.length + u.length,
775
+ "0"
776
+ )}`;
389
777
  }
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;
778
+ toFixed(t = 6) {
779
+ const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
780
+ if (parseInt(n))
781
+ return `${n}.${i.slice(0, t)}`.padEnd(t, "0");
782
+ const a = parseInt(i), c = `${a}`.slice(0, t);
783
+ return `0.${c.padStart(
784
+ i.length - `${a}`.length + c.length,
785
+ "0"
786
+ )}`;
787
+ }
788
+ toAbbreviation(t = 2) {
789
+ 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];
790
+ if (!i)
791
+ return this.getValue("string");
792
+ const a = 10 ** (n * 3);
793
+ return `${(e / a).toFixed(t)}${i}`;
396
794
  }
397
795
  };
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;
796
+ A = new WeakSet(), $ = function(t, ...e) {
797
+ const r = m(this, N, ht).call(this, this, ...e), n = S(r), i = e.reduce(
798
+ (c, u) => {
799
+ const l = this.getBigIntValue(u, r);
800
+ switch (t) {
801
+ case "add":
802
+ return c + l;
803
+ case "sub":
804
+ return c - l;
805
+ case "mul":
806
+ return c * l / n;
807
+ case "div": {
808
+ if (l === 0n)
809
+ throw new RangeError("Division by zero");
810
+ return c * n / l;
811
+ }
812
+ default:
813
+ return c;
814
+ }
405
815
  },
406
816
  //normalize is to precision multiplier base
407
- this.bigIntValue * s / this.decimalMultiplier
408
- ), c = G({
817
+ this.bigIntValue * n / this.decimalMultiplier
818
+ ), a = x({
409
819
  bigIntDecimal: r,
410
- decimal: Math.max(r, C(this.decimalMultiplier)),
411
- value: a
820
+ decimal: Math.max(r, R(this.decimalMultiplier)),
821
+ value: i
412
822
  });
413
- 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) {
823
+ return new this.constructor({ decimal: this.decimal, value: a, identifier: this.toString() });
824
+ }, P = new WeakSet(), lt = function(t) {
825
+ const e = m(this, T, C).call(this, t) || "0";
826
+ this.bigIntValue = m(this, B, W).call(this, e);
827
+ }, N = new WeakSet(), ht = function(...t) {
418
828
  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))
829
+ (r) => typeof r == "object" ? r.decimal || R(r.decimalMultiplier) : m(this, O, G).call(this, m(this, T, C).call(this, r))
420
830
  ).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) {
831
+ return Math.max(...e, I);
832
+ }, B = new WeakSet(), W = function(t, e) {
833
+ const r = e ? S(e) : this.decimalMultiplier, n = R(r), [i = "", a = ""] = t.split(".");
834
+ return BigInt(`${i}${a.padEnd(n, "0")}`);
835
+ }, T = new WeakSet(), C = function(t) {
426
836
  const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
427
837
  useGrouping: !1,
428
838
  maximumFractionDigits: 20
429
- }) : t}`.replaceAll(",", ".").split(".");
839
+ }) : U(t)}`.replaceAll(",", ".").split(".");
430
840
  return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0];
431
- }, V = new WeakSet(), j = function(t) {
841
+ }, O = new WeakSet(), G = function(t) {
432
842
  var r;
433
843
  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
- }
844
+ return Math.max(e, I);
445
845
  };
446
- let E = M, q;
447
- const P = (n) => {
448
- if (!q)
846
+ let E = K;
847
+ function U(s) {
848
+ return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
849
+ }
850
+ const k = (s, t) => typeof s == "bigint" ? x({ value: s, bigIntDecimal: t, decimal: t }) : s;
851
+ let Y;
852
+ const rt = (s) => {
853
+ if (!Y)
449
854
  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 });
855
+ return Y.get(s.toUpperCase()) || { decimal: d.THOR, identifier: "" };
856
+ }, st = async (s, t = 0) => {
857
+ Xt(s);
858
+ const e = await Rt(z(s)), r = k(t, e);
859
+ return new w({ decimal: e, value: r, identifier: s });
455
860
  };
456
- class A extends E {
861
+ class w extends E {
457
862
  constructor(e) {
458
863
  super(
459
864
  e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value }
460
865
  );
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;
866
+ f(this, "address");
867
+ f(this, "chain");
868
+ f(this, "isSynthetic", !1);
869
+ f(this, "isGasAsset", !1);
870
+ f(this, "symbol");
871
+ f(this, "ticker");
872
+ f(this, "type");
873
+ const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = z(r);
874
+ 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;
875
+ }
876
+ get assetValue() {
877
+ return `${this.getValue("string")} ${this.ticker}`;
878
+ }
879
+ toString(e = !1) {
880
+ const r = this.isSynthetic ? this.symbol.split("-")[0] : `${this.chain}.${this.ticker}`;
881
+ return e ? r : (
882
+ // THOR.ETH/ETH | ETH.USDT-0x1234567890
883
+ `${this.chain}.${this.symbol}`
884
+ );
885
+ }
886
+ eq({ chain: e, symbol: r }) {
887
+ return this.chain === e && this.symbol === r;
470
888
  }
471
889
  static async fromString(e, r = 0) {
472
- return Y(e, r);
890
+ return st(e, r);
473
891
  }
474
892
  static fromStringSync(e, r = 0) {
475
- const { decimal: s, identifier: a } = P(
893
+ const { isSynthetic: n } = z(e), { decimal: i, identifier: a } = rt(
476
894
  e
477
- );
478
- return a ? new A({ decimal: s, identifier: a, value: r }) : void 0;
895
+ ), c = k(r, i);
896
+ return a ? new w({ decimal: i, identifier: a, value: c }) : n ? new w({ decimal: 8, identifier: e, value: c }) : void 0;
479
897
  }
480
898
  static async fromIdentifier(e, r = 0) {
481
- return Y(e, r);
899
+ return st(e, r);
482
900
  }
483
901
  static fromIdentifierSync(e, r = 0) {
484
- const { decimal: s, identifier: a } = P(e);
485
- return new A({ decimal: s, identifier: a, value: r });
902
+ const { decimal: n, identifier: i } = rt(e), a = k(r, n);
903
+ return new w({ decimal: n, identifier: i, value: a });
486
904
  }
487
905
  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 });
906
+ const { decimal: n, identifier: i } = Ct(e), a = k(r, n);
907
+ return new w({ value: a, decimal: n, identifier: i });
502
908
  }
503
909
  static async loadStaticAssets() {
504
910
  return new Promise(
@@ -507,66 +913,57 @@ class A extends E {
507
913
  const {
508
914
  // Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
509
915
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
510
- ThorchainList: s,
511
- NativeList: a,
512
- ...c
916
+ ThorchainList: n,
917
+ NativeList: i,
918
+ ...a
513
919
  } = 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),
920
+ Y = [i, ...Object.values(a)].reduce(
921
+ (u, { tokens: l }) => (l.forEach(({ identifier: h, chain: _, ...v }) => {
922
+ const j = "decimals" in v ? v.decimals : d[_];
923
+ u.set(h, { identifier: h, decimal: j });
924
+ }), u),
519
925
  /* @__PURE__ */ new Map()
520
926
  ), e({ ok: !0 });
521
- } catch (s) {
522
- console.error(s), r({
927
+ } catch (n) {
928
+ console.error(n), r({
523
929
  ok: !1,
524
- error: s,
930
+ error: n,
525
931
  message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
526
932
  });
527
933
  }
528
934
  }
529
935
  );
530
936
  }
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
937
  }
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);
938
+ const pe = (s) => {
939
+ const t = w.fromChainOrSignature(s);
940
+ switch (s) {
941
+ case o.Bitcoin:
942
+ case o.Litecoin:
943
+ case o.BitcoinCash:
944
+ return t.set(10001e-8);
945
+ case o.Dogecoin:
946
+ return t.set(1.00000001);
947
+ case o.Avalanche:
948
+ case o.Ethereum:
949
+ return t.set(1e-8);
950
+ case o.THORChain:
951
+ case o.Maya:
952
+ return t.set(0);
556
953
  default:
557
- return t.add(1);
954
+ return t.set(1e-8);
558
955
  }
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("-");
956
+ }, z = (s) => {
957
+ const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".").pop().split("/"), n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, a] = n.split("."), [c, u] = (t ? r : a).split("-");
561
958
  return {
562
- address: c == null ? void 0 : c.toLowerCase(),
563
- chain: r,
564
- isGasAsset: mt({ chain: r, symbol: s }),
959
+ address: u == null ? void 0 : u.toLowerCase(),
960
+ chain: i,
961
+ isGasAsset: $t({ chain: i, symbol: a }),
565
962
  isSynthetic: t,
566
- symbol: c ? `${a}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : s,
567
- ticker: t ? s : a
963
+ symbol: (t ? `${e}/` : "") + (u ? `${c}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : a),
964
+ ticker: c
568
965
  };
569
- }, wt = {
966
+ }, Zt = {
570
967
  /**
571
968
  * Core
572
969
  */
@@ -623,44 +1020,47 @@ const Dt = (n) => {
623
1020
  */
624
1021
  helpers_number_different_decimals: 99101
625
1022
  };
626
- class Q extends Error {
1023
+ class dt extends Error {
627
1024
  constructor(t, e) {
628
- console.error(e), super(t, { cause: { code: wt[t], message: t } }), Object.setPrototypeOf(this, Q.prototype);
1025
+ console.error(e), super(t, { cause: { code: Zt[t], message: t } }), Object.setPrototypeOf(this, dt.prototype);
629
1026
  }
630
1027
  }
631
- class bt extends E {
1028
+ class b extends E {
632
1029
  eq(t) {
633
1030
  return this.eqValue(t);
634
1031
  }
635
- toString() {
636
- return this.value;
1032
+ static fromBigInt(t, e) {
1033
+ return new b({
1034
+ decimal: e,
1035
+ value: x({ value: t, bigIntDecimal: e, decimal: e })
1036
+ });
637
1037
  }
638
1038
  }
639
1039
  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
1040
+ w as AssetValue,
1041
+ E as BigIntArithmetics,
1042
+ Qt as RequestClient,
1043
+ dt as SwapKitError,
1044
+ b as SwapKitNumber,
1045
+ se as assetFromString,
1046
+ me as derivationPathToString,
1047
+ ne as filterAssets,
1048
+ x as formatBigIntToSafeValue,
1049
+ re as gasFeeMultiplier,
1050
+ It as getAssetType,
1051
+ Ot as getAsymmetricAssetShare,
1052
+ oe as getAsymmetricAssetWithdrawAmount,
1053
+ Bt as getAsymmetricRuneShare,
1054
+ ie as getAsymmetricRuneWithdrawAmount,
1055
+ Ct as getCommonAssetInfo,
1056
+ Rt as getDecimal,
1057
+ ce as getEstimatedPoolShare,
1058
+ ue as getLiquiditySlippage,
1059
+ le as getMemoFor,
1060
+ pe as getMinAmountByChain,
1061
+ Vt as getSymmetricPoolShare,
1062
+ ae as getSymmetricWithdraw,
1063
+ he as getTHORNameCost,
1064
+ $t as isGasAsset,
1065
+ de as validateTHORName
666
1066
  };