@swapkit/helpers 1.0.0-rc.52 → 1.0.0-rc.53

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