@swapkit/helpers 1.0.0-rc.10 → 1.0.0-rc.12

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,6 +1,6 @@
1
- var _t = Object.defineProperty;
2
- var gt = (s, t, e) => t in s ? _t(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var p = (s, t, e) => (gt(s, typeof t != "symbol" ? t + "" : t, e), e), bt = (s, t, e) => {
1
+ var bt = Object.defineProperty;
2
+ var yt = (s, t, e) => t in s ? bt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var p = (s, t, e) => (yt(s, typeof t != "symbol" ? t + "" : t, e), e), wt = (s, t, e) => {
4
4
  if (!t.has(s))
5
5
  throw TypeError("Cannot " + e);
6
6
  };
@@ -9,47 +9,47 @@ var y = (s, t, e) => {
9
9
  throw TypeError("Cannot add the same private member more than once");
10
10
  t instanceof WeakSet ? t.add(s) : t.set(s, e);
11
11
  };
12
- var f = (s, t, e) => (bt(s, t, "access private method"), e);
13
- import { FeeOption as H, BaseDecimal as m, Chain as o, ChainToRPC as yt, MemoType as g } from "@swapkit/types";
14
- const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
12
+ var f = (s, t, e) => (wt(s, t, "access private method"), e);
13
+ import { FeeOption as D, BaseDecimal as m, Chain as o, ChainToRPC as At, MemoType as g } from "@swapkit/types";
14
+ const Tt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
15
15
  try {
16
- const { result: e } = await zt.post(yt[s], {
16
+ const { result: e } = await Kt.post(At[s], {
17
17
  headers: { accept: "*/*", "cache-control": "no-cache" },
18
18
  body: JSON.stringify({
19
19
  id: 44,
20
20
  jsonrpc: "2.0",
21
21
  method: "eth_call",
22
- params: [{ to: t.toLowerCase(), data: wt }, "latest"]
22
+ params: [{ to: t.toLowerCase(), data: Tt }, "latest"]
23
23
  })
24
24
  });
25
25
  return parseInt(BigInt(e).toString());
26
26
  } catch (e) {
27
27
  return console.error(e), m[s];
28
28
  }
29
- }, At = async (s) => {
29
+ }, vt = async (s) => {
30
30
  if (s === o.Ethereum)
31
31
  return m.ETH;
32
32
  const [, t] = s.split("-");
33
- return t != null && t.startsWith("0x") ? rt({ chain: o.Ethereum, to: t }) : m.ETH;
34
- }, Tt = async (s) => {
33
+ return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : m.ETH;
34
+ }, Rt = async (s) => {
35
35
  const [, t] = s.split("-");
36
- return t != null && t.startsWith("0x") ? rt({ chain: o.Avalanche, to: t.toLowerCase() }) : m.AVAX;
37
- }, Rt = async (s) => s === o.BinanceSmartChain ? m.BSC : m.BSC, st = async ({ chain: s, symbol: t }) => {
36
+ return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : m.AVAX;
37
+ }, St = async (s) => s === o.BinanceSmartChain ? m.BSC : m.BSC, it = async ({ chain: s, symbol: t }) => {
38
38
  switch (s) {
39
39
  case o.Ethereum:
40
- return At(t);
40
+ return vt(t);
41
41
  case o.Avalanche:
42
- return Tt(t);
43
- case o.BinanceSmartChain:
44
42
  return Rt(t);
43
+ case o.BinanceSmartChain:
44
+ return St(t);
45
45
  default:
46
46
  return m[s];
47
47
  }
48
- }, te = {
49
- [H.Average]: 1.2,
50
- [H.Fast]: 1.5,
51
- [H.Fastest]: 2
52
- }, St = ({ chain: s, symbol: t }) => {
48
+ }, ee = {
49
+ [D.Average]: 1.2,
50
+ [D.Fast]: 1.5,
51
+ [D.Fastest]: 2
52
+ }, $t = ({ chain: s, symbol: t }) => {
53
53
  switch (s) {
54
54
  case o.Bitcoin:
55
55
  case o.BitcoinCash:
@@ -75,7 +75,7 @@ const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
75
75
  case o.THORChain:
76
76
  return t === "RUNE";
77
77
  }
78
- }, vt = (s) => {
78
+ }, Ct = (s) => {
79
79
  switch (s) {
80
80
  case "ETH.THOR":
81
81
  return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
@@ -104,7 +104,7 @@ const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
104
104
  case o.Ethereum:
105
105
  return { identifier: `${s}.${s}`, decimal: m[s] };
106
106
  }
107
- }, Ct = ({ chain: s, symbol: t }) => {
107
+ }, It = ({ chain: s, symbol: t }) => {
108
108
  if (t.includes("/"))
109
109
  return "Synth";
110
110
  switch (s) {
@@ -134,40 +134,40 @@ const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
134
134
  case o.Optimism:
135
135
  return [o.Ethereum, o.Optimism].includes(t) ? "Native" : "OPTIMISM";
136
136
  }
137
- }, ee = (s) => {
137
+ }, re = (s) => {
138
138
  var a;
139
139
  const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (a = n == null ? void 0 : n.split("-")) == null ? void 0 : a[0];
140
140
  return { chain: t, symbol: n, ticker: i, synth: r };
141
- }, $t = new RegExp(
141
+ }, Et = new RegExp(
142
142
  /(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
143
143
  "gmi"
144
- ), re = (s) => s.filter(
145
- (t) => !$t.test(t.toString()) && !t.toString().includes("undefined")
146
- ), It = ({
144
+ ), se = (s) => s.filter(
145
+ (t) => !Et.test(t.toString()) && !t.toString().includes("undefined")
146
+ ), Ot = ({
147
147
  liquidityUnits: s,
148
148
  poolUnits: t,
149
149
  runeDepth: e
150
150
  }) => {
151
151
  const r = d(s), n = d(t), i = d(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);
152
152
  return a.mul(c.sub(u).add(l)).div(h);
153
- }, Et = ({
153
+ }, Vt = ({
154
154
  liquidityUnits: s,
155
155
  poolUnits: t,
156
156
  assetDepth: e
157
157
  }) => {
158
158
  const r = d(s), n = d(t), i = d(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);
159
159
  return h.div(_);
160
- }, se = ({
160
+ }, ne = ({
161
161
  percent: s,
162
162
  runeDepth: t,
163
163
  liquidityUnits: e,
164
164
  poolUnits: r
165
- }) => It({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), ne = ({
165
+ }) => Ot({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), ie = ({
166
166
  percent: s,
167
167
  assetDepth: t,
168
168
  liquidityUnits: e,
169
169
  poolUnits: r
170
- }) => Et({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), d = (s) => new Qt({ value: s, decimal: m.THOR }), Ot = ({
170
+ }) => Vt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), d = (s) => new Q({ value: s, decimal: m.THOR }), Bt = ({
171
171
  liquidityUnits: s,
172
172
  poolUnits: t,
173
173
  runeDepth: e,
@@ -175,17 +175,17 @@ const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
175
175
  }) => ({
176
176
  assetAmount: d(r).mul(s).div(t),
177
177
  runeAmount: d(e).mul(s).div(t)
178
- }), ie = ({
178
+ }), oe = ({
179
179
  liquidityUnits: s,
180
180
  poolUnits: t,
181
181
  runeDepth: e,
182
182
  assetDepth: r,
183
183
  percent: n
184
184
  }) => Object.fromEntries(
185
- Object.entries(Ot({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
185
+ Object.entries(Bt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
186
186
  ([i, a]) => [i, a.mul(n)]
187
187
  )
188
- ), oe = ({
188
+ ), ae = ({
189
189
  runeDepth: s,
190
190
  poolUnits: t,
191
191
  assetDepth: e,
@@ -193,12 +193,12 @@ const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
193
193
  runeAmount: n,
194
194
  assetAmount: i
195
195
  }) => {
196
- const a = d(s), c = d(e), u = d(t), l = d(n), h = d(i), _ = l.mul(c), T = h.mul(a), P = l.mul(h), dt = a.mul(c), mt = u.mul(_.add(T.add(P.mul(2)))), ft = _.add(T.add(dt.mul(2))), J = mt.div(ft), N = d(r).add(J);
197
- if (J.baseValueNumber === 0)
198
- return N.div(u).baseValueNumber;
199
- const pt = u.add(N);
200
- return N.div(pt).baseValueNumber;
201
- }, ae = ({
196
+ const a = d(s), c = d(e), u = d(t), l = d(n), h = d(i), _ = l.mul(c), T = h.mul(a), H = l.mul(h), ft = a.mul(c), pt = u.mul(_.add(T.add(H.mul(2)))), _t = _.add(T.add(ft.mul(2))), X = pt.div(_t), j = d(r).add(X);
197
+ if (X.baseValueNumber === 0)
198
+ return j.div(u).baseValueNumber;
199
+ const gt = u.add(j);
200
+ return j.div(gt).baseValueNumber;
201
+ }, ce = ({
202
202
  runeAmount: s,
203
203
  assetAmount: t,
204
204
  runeDepth: e,
@@ -206,11 +206,11 @@ const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
206
206
  }) => {
207
207
  const n = d(e), i = d(r), a = d(t), c = d(s), u = a.mul(n).sub(i.mul(c)), l = i.mul(c).add(n.mul(i));
208
208
  return Math.abs(u.div(l).baseValueNumber);
209
- }, kt = ({
209
+ }, Mt = ({
210
210
  symbol: s,
211
211
  ticker: t,
212
212
  chain: e
213
- }) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s, ce = (s, t) => {
213
+ }) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s, ue = (s, t) => {
214
214
  switch (s) {
215
215
  case g.LEAVE:
216
216
  case g.BOND: {
@@ -230,7 +230,7 @@ const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
230
230
  return i ? `${s}:${e}/${r}::t:0` : `${s}:${e}.${r}:${n || ""}:t:0`;
231
231
  }
232
232
  case g.WITHDRAW: {
233
- const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", l = kt({ chain: e, symbol: n, ticker: r });
233
+ 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 });
234
234
  return `${s}:${e}${c ? "/" : "."}${l}:${i}${u}`;
235
235
  }
236
236
  case g.OPEN_LOAN:
@@ -241,17 +241,17 @@ const wt = "0x313ce567", rt = async ({ chain: s, to: t }) => {
241
241
  default:
242
242
  return "";
243
243
  }
244
- }, ue = (s) => {
244
+ }, le = (s) => {
245
245
  if (s < 0)
246
246
  throw new Error("Invalid number of year");
247
247
  return 10 + s;
248
- }, le = (s) => {
248
+ }, he = (s) => {
249
249
  if (s.length > 30)
250
250
  return !1;
251
251
  const t = /^[a-zA-Z0-9+_-]+$/g;
252
252
  return !!s.match(t);
253
- }, he = ([s, t, e, r, n]) => `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
254
- class K extends Error {
253
+ }, de = ([s, t, e, r, n]) => `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
254
+ class Z extends Error {
255
255
  constructor(t, e, r) {
256
256
  const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", a = `${n} ${i}`.trim(), c = a ? `status code ${a}` : "an unknown error";
257
257
  super(`Request failed with ${c}`), Object.defineProperty(this, "response", {
@@ -272,7 +272,7 @@ class K extends Error {
272
272
  }), this.name = "HTTPError", this.response = t, this.request = e, this.options = r;
273
273
  }
274
274
  }
275
- class nt extends Error {
275
+ class ot extends Error {
276
276
  constructor(t) {
277
277
  super("Request timed out"), Object.defineProperty(this, "request", {
278
278
  enumerable: !0,
@@ -282,28 +282,28 @@ class nt extends Error {
282
282
  }), this.name = "TimeoutError", this.request = t;
283
283
  }
284
284
  }
285
- const V = (s) => s !== null && typeof s == "object", B = (...s) => {
285
+ const B = (s) => s !== null && typeof s == "object", V = (...s) => {
286
286
  for (const t of s)
287
- if ((!V(t) || Array.isArray(t)) && t !== void 0)
287
+ if ((!B(t) || Array.isArray(t)) && t !== void 0)
288
288
  throw new TypeError("The `options` argument must be an object");
289
- return z({}, ...s);
290
- }, it = (s = {}, t = {}) => {
289
+ return K({}, ...s);
290
+ }, at = (s = {}, t = {}) => {
291
291
  const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
292
292
  for (const [i, a] of n.entries())
293
293
  r && a === "undefined" || a === void 0 ? e.delete(i) : e.set(i, a);
294
294
  return e;
295
- }, z = (...s) => {
295
+ }, K = (...s) => {
296
296
  let t = {}, e = {};
297
297
  for (const r of s)
298
298
  if (Array.isArray(r))
299
299
  Array.isArray(t) || (t = []), t = [...t, ...r];
300
- else if (V(r)) {
300
+ else if (B(r)) {
301
301
  for (let [n, i] of Object.entries(r))
302
- V(i) && n in t && (i = z(t[n], i)), t = { ...t, [n]: i };
303
- V(r.headers) && (e = it(e, r.headers), t.headers = e);
302
+ B(i) && n in t && (i = K(t[n], i)), t = { ...t, [n]: i };
303
+ B(r.headers) && (e = at(e, r.headers), t.headers = e);
304
304
  }
305
305
  return t;
306
- }, Bt = (() => {
306
+ }, kt = (() => {
307
307
  let s = !1, t = !1;
308
308
  const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
309
309
  return e && r && (t = new globalThis.Request("https://empty.invalid", {
@@ -314,13 +314,13 @@ const V = (s) => s !== null && typeof s == "object", B = (...s) => {
314
314
  return s = !0, "half";
315
315
  }
316
316
  }).headers.has("Content-Type")), s && !t;
317
- })(), Vt = typeof globalThis.AbortController == "function", qt = typeof globalThis.ReadableStream == "function", Mt = typeof globalThis.FormData == "function", ot = ["get", "post", "put", "patch", "head", "delete"], xt = {
317
+ })(), qt = typeof globalThis.AbortController == "function", xt = typeof globalThis.ReadableStream == "function", Pt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], Nt = {
318
318
  json: "application/json",
319
319
  text: "text/*",
320
320
  formData: "multipart/form-data",
321
321
  arrayBuffer: "*/*",
322
322
  blob: "*/*"
323
- }, j = 2147483647, at = Symbol("stop"), Pt = {
323
+ }, L = 2147483647, ut = Symbol("stop"), Ht = {
324
324
  json: !0,
325
325
  parseJson: !0,
326
326
  searchParams: !0,
@@ -331,7 +331,7 @@ const V = (s) => s !== null && typeof s == "object", B = (...s) => {
331
331
  throwHttpErrors: !0,
332
332
  onDownloadProgress: !0,
333
333
  fetch: !0
334
- }, Nt = {
334
+ }, jt = {
335
335
  method: !0,
336
336
  headers: !0,
337
337
  body: !0,
@@ -347,18 +347,18 @@ const V = (s) => s !== null && typeof s == "object", B = (...s) => {
347
347
  window: !0,
348
348
  dispatcher: !0,
349
349
  duplex: !0
350
- }, Ht = (s) => ot.includes(s) ? s.toUpperCase() : s, jt = ["get", "put", "head", "delete", "options", "trace"], Lt = [408, 413, 429, 500, 502, 503, 504], ct = [413, 429, 503], Q = {
350
+ }, Dt = (s) => ct.includes(s) ? s.toUpperCase() : s, Lt = ["get", "put", "head", "delete", "options", "trace"], Ut = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], tt = {
351
351
  limit: 2,
352
- methods: jt,
353
- statusCodes: Lt,
354
- afterStatusCodes: ct,
352
+ methods: Lt,
353
+ statusCodes: Ut,
354
+ afterStatusCodes: lt,
355
355
  maxRetryAfter: Number.POSITIVE_INFINITY,
356
356
  backoffLimit: Number.POSITIVE_INFINITY,
357
357
  delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
358
- }, Dt = (s = {}) => {
358
+ }, Ft = (s = {}) => {
359
359
  if (typeof s == "number")
360
360
  return {
361
- ...Q,
361
+ ...tt,
362
362
  limit: s
363
363
  };
364
364
  if (s.methods && !Array.isArray(s.methods))
@@ -366,22 +366,22 @@ const V = (s) => s !== null && typeof s == "object", B = (...s) => {
366
366
  if (s.statusCodes && !Array.isArray(s.statusCodes))
367
367
  throw new Error("retry.statusCodes must be an array");
368
368
  return {
369
- ...Q,
369
+ ...tt,
370
370
  ...s,
371
- afterStatusCodes: ct
371
+ afterStatusCodes: lt
372
372
  };
373
373
  };
374
- async function Ut(s, t, e, r) {
374
+ async function Wt(s, t, e, r) {
375
375
  return new Promise((n, i) => {
376
376
  const a = setTimeout(() => {
377
- e && e.abort(), i(new nt(s));
377
+ e && e.abort(), i(new ot(s));
378
378
  }, r.timeout);
379
379
  r.fetch(s, t).then(n).catch(i).then(() => {
380
380
  clearTimeout(a);
381
381
  });
382
382
  });
383
383
  }
384
- async function Ft(s, { signal: t }) {
384
+ async function Gt(s, { signal: t }) {
385
385
  return new Promise((e, r) => {
386
386
  t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
387
387
  function n() {
@@ -392,17 +392,17 @@ async function Ft(s, { signal: t }) {
392
392
  }, s);
393
393
  });
394
394
  }
395
- const Wt = (s, t) => {
395
+ const Yt = (s, t) => {
396
396
  const e = {};
397
397
  for (const r in t)
398
- !(r in Nt) && !(r in Pt) && !(r in s) && (e[r] = t[r]);
398
+ !(r in jt) && !(r in Ht) && !(r in s) && (e[r] = t[r]);
399
399
  return e;
400
400
  };
401
- class q {
401
+ class k {
402
402
  static create(t, e) {
403
- const r = new q(t, e), n = async () => {
404
- if (typeof r._options.timeout == "number" && r._options.timeout > j)
405
- throw new RangeError(`The \`timeout\` option cannot be greater than ${j}`);
403
+ const r = new k(t, e), n = async () => {
404
+ if (typeof r._options.timeout == "number" && r._options.timeout > L)
405
+ throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`);
406
406
  await Promise.resolve();
407
407
  let c = await r._fetch();
408
408
  for (const u of r._options.hooks.afterResponse) {
@@ -410,7 +410,7 @@ class q {
410
410
  l instanceof globalThis.Response && (c = l);
411
411
  }
412
412
  if (r._decorateResponse(c), !c.ok && r._options.throwHttpErrors) {
413
- let u = new K(c, r.request, r._options);
413
+ let u = new Z(c, r.request, r._options);
414
414
  for (const l of r._options.hooks.beforeError)
415
415
  u = await l(u);
416
416
  throw u;
@@ -418,13 +418,13 @@ class q {
418
418
  if (r._options.onDownloadProgress) {
419
419
  if (typeof r._options.onDownloadProgress != "function")
420
420
  throw new TypeError("The `onDownloadProgress` option must be a function");
421
- if (!qt)
421
+ if (!xt)
422
422
  throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
423
423
  return r._stream(c.clone(), r._options.onDownloadProgress);
424
424
  }
425
425
  return c;
426
426
  }, a = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
427
- for (const [c, u] of Object.entries(xt))
427
+ for (const [c, u] of Object.entries(Nt))
428
428
  a[c] = async () => {
429
429
  r.request.headers.set("accept", r.request.headers.get("accept") || u);
430
430
  const h = (await a).clone();
@@ -469,17 +469,17 @@ class q {
469
469
  // TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
470
470
  credentials: this._input.credentials || "same-origin",
471
471
  ...e,
472
- headers: it(this._input.headers, e.headers),
473
- hooks: z({
472
+ headers: at(this._input.headers, e.headers),
473
+ hooks: K({
474
474
  beforeRequest: [],
475
475
  beforeRetry: [],
476
476
  beforeError: [],
477
477
  afterResponse: []
478
478
  }, e.hooks),
479
- method: Ht(e.method ?? this._input.method),
479
+ method: Dt(e.method ?? this._input.method),
480
480
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
481
481
  prefixUrl: String(e.prefixUrl || ""),
482
- retry: Dt(e.retry),
482
+ retry: Ft(e.retry),
483
483
  throwHttpErrors: e.throwHttpErrors !== !1,
484
484
  timeout: e.timeout ?? 1e4,
485
485
  fetch: e.fetch ?? globalThis.fetch.bind(globalThis)
@@ -490,7 +490,7 @@ class q {
490
490
  throw new Error("`input` must not begin with a slash when using `prefixUrl`");
491
491
  this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
492
492
  }
493
- if (Vt) {
493
+ if (qt) {
494
494
  if (this.abortController = new globalThis.AbortController(), this._options.signal) {
495
495
  const r = this._options.signal;
496
496
  this._options.signal.addEventListener("abort", () => {
@@ -499,15 +499,15 @@ class q {
499
499
  }
500
500
  this._options.signal = this.abortController.signal;
501
501
  }
502
- if (Bt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
502
+ if (kt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
503
503
  const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
504
- (Mt && 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);
504
+ (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);
505
505
  }
506
506
  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 }));
507
507
  }
508
508
  _calculateRetryDelay(t) {
509
- if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof nt)) {
510
- if (t instanceof K) {
509
+ if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof ot)) {
510
+ if (t instanceof Z) {
511
511
  if (!this._options.retry.statusCodes.includes(t.response.status))
512
512
  return 0;
513
513
  const r = t.response.headers.get("Retry-After");
@@ -530,16 +530,16 @@ class q {
530
530
  try {
531
531
  return await t();
532
532
  } catch (e) {
533
- const r = Math.min(this._calculateRetryDelay(e), j);
533
+ const r = Math.min(this._calculateRetryDelay(e), L);
534
534
  if (r !== 0 && this._retryCount > 0) {
535
- await Ft(r, { signal: this._options.signal });
535
+ await Gt(r, { signal: this._options.signal });
536
536
  for (const n of this._options.hooks.beforeRetry)
537
537
  if (await n({
538
538
  request: this.request,
539
539
  options: this._options,
540
540
  error: e,
541
541
  retryCount: this._retryCount
542
- }) === at)
542
+ }) === ut)
543
543
  return;
544
544
  return this._retry(t);
545
545
  }
@@ -556,8 +556,8 @@ class q {
556
556
  if (r instanceof Response)
557
557
  return r;
558
558
  }
559
- const t = Wt(this.request, this._options);
560
- return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Ut(this.request.clone(), t, this.abortController, this._options);
559
+ const t = Yt(this.request, this._options);
560
+ return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Wt(this.request.clone(), t, this.abortController, this._options);
561
561
  }
562
562
  /* istanbul ignore next */
563
563
  _stream(t, e) {
@@ -594,35 +594,35 @@ class q {
594
594
  }
595
595
  }
596
596
  /*! MIT License © Sindre Sorhus */
597
- const U = (s) => {
598
- const t = (e, r) => q.create(e, B(s, r));
599
- for (const e of ot)
600
- t[e] = (r, n) => q.create(r, B(s, n, { method: e }));
601
- return t.create = (e) => U(B(e)), t.extend = (e) => U(B(s, e)), t.stop = at, t;
602
- }, Gt = U(), Yt = Gt, X = Yt.create({
597
+ const W = (s) => {
598
+ const t = (e, r) => k.create(e, V(s, r));
599
+ for (const e of ct)
600
+ t[e] = (r, n) => k.create(r, V(s, n, { method: e }));
601
+ return t.create = (e) => W(V(e)), t.extend = (e) => W(V(s, e)), t.stop = ut, t;
602
+ }, zt = W(), Jt = zt, et = Jt.create({
603
603
  headers: {
604
604
  referrer: "https://sk.thorswap.net",
605
605
  referer: "https://sk.thorswap.net",
606
606
  "Content-Type": "application/json"
607
607
  }
608
- }), zt = {
609
- get: (s, t) => X.get(s, t).json(),
610
- post: (s, t) => X.post(s, t).json()
611
- }, Z = Object.values(o), Jt = (s = "") => {
608
+ }), Kt = {
609
+ get: (s, t) => et.get(s, t).json(),
610
+ post: (s, t) => et.post(s, t).json()
611
+ }, rt = Object.values(o), Qt = (s = "") => {
612
612
  const t = s.toUpperCase(), [e] = t.split(".");
613
- if (Z.includes(e))
613
+ if (rt.includes(e))
614
614
  return !0;
615
615
  const [r] = t.split("/");
616
- if (Z.includes(r))
616
+ if (rt.includes(r))
617
617
  return !0;
618
618
  throw new Error(
619
619
  `Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
620
620
  );
621
- }, $ = 8, R = (s) => 10n ** BigInt(s), S = (s) => Math.log10(parseFloat(s.toString()));
622
- function tt({
621
+ }, C = 8, v = (s) => 10n ** BigInt(s), R = (s) => Math.log10(parseFloat(s.toString()));
622
+ function q({
623
623
  value: s,
624
- bigIntDecimal: t = $,
625
- decimal: e = $
624
+ bigIntDecimal: t = C,
625
+ decimal: e = C
626
626
  }) {
627
627
  const r = s < 0n;
628
628
  let n = s.toString().substring(r ? 1 : 0);
@@ -635,27 +635,27 @@ function tt({
635
635
  ""
636
636
  );
637
637
  }
638
- var w, v, M, ut, x, lt, O, F, A, C, k, W;
639
- const I = class I {
638
+ var w, S, x, ht, P, dt, E, G, A, $, O, Y;
639
+ const N = class N {
640
640
  constructor(t) {
641
641
  y(this, w);
642
- y(this, M);
643
642
  y(this, x);
644
- y(this, O);
643
+ y(this, P);
644
+ y(this, E);
645
645
  y(this, A);
646
- y(this, k);
646
+ y(this, O);
647
647
  p(this, "decimalMultiplier", 10n ** 8n);
648
648
  p(this, "bigIntValue", 0n);
649
649
  p(this, "decimal");
650
- const e = L(t);
651
- this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = R(
652
- Math.max(f(this, k, W).call(this, f(this, A, C).call(this, e)), this.decimal || 0)
653
- ), f(this, M, ut).call(this, e);
650
+ const e = U(t);
651
+ this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = v(
652
+ Math.max(f(this, O, Y).call(this, f(this, A, $).call(this, e)), this.decimal || 0)
653
+ ), f(this, x, ht).call(this, e);
654
654
  }
655
655
  static fromBigInt(t, e) {
656
- return new I({
656
+ return new N({
657
657
  decimal: e,
658
- value: tt({ value: t, bigIntDecimal: e, decimal: e })
658
+ value: q({ value: t, bigIntDecimal: e, decimal: e })
659
659
  });
660
660
  }
661
661
  static shiftDecimals({
@@ -663,8 +663,8 @@ const I = class I {
663
663
  from: e,
664
664
  to: r
665
665
  }) {
666
- return I.fromBigInt(
667
- new I(t).bigIntValue * R(r) / R(e),
666
+ return this.fromBigInt(
667
+ new N(t).bigIntValue * v(r) / v(e),
668
668
  r
669
669
  );
670
670
  }
@@ -690,16 +690,16 @@ const I = class I {
690
690
  return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
691
691
  }
692
692
  add(...t) {
693
- return f(this, w, v).call(this, "add", ...t);
693
+ return f(this, w, S).call(this, "add", ...t);
694
694
  }
695
695
  sub(...t) {
696
- return f(this, w, v).call(this, "sub", ...t);
696
+ return f(this, w, S).call(this, "sub", ...t);
697
697
  }
698
698
  mul(...t) {
699
- return f(this, w, v).call(this, "mul", ...t);
699
+ return f(this, w, S).call(this, "mul", ...t);
700
700
  }
701
701
  div(...t) {
702
- return f(this, w, v).call(this, "div", ...t);
702
+ return f(this, w, S).call(this, "div", ...t);
703
703
  }
704
704
  gt(t) {
705
705
  return this.bigIntValue > this.getBigIntValue(t);
@@ -719,7 +719,7 @@ const I = class I {
719
719
  getValue(t) {
720
720
  const e = this.formatBigIntToSafeValue(
721
721
  this.bigIntValue,
722
- this.decimal || S(this.decimalMultiplier)
722
+ this.decimal || R(this.decimalMultiplier)
723
723
  );
724
724
  switch (t) {
725
725
  case "number":
@@ -731,7 +731,7 @@ const I = class I {
731
731
  }
732
732
  }
733
733
  getBaseValue(t) {
734
- const e = this.decimalMultiplier / R(this.decimal || m.THOR), r = this.bigIntValue / e;
734
+ const e = this.decimalMultiplier / v(this.decimal || m.THOR), r = this.bigIntValue / e;
735
735
  switch (t) {
736
736
  case "number":
737
737
  return Number(r);
@@ -744,13 +744,13 @@ const I = class I {
744
744
  getBigIntValue(t, e) {
745
745
  if (!e && typeof t == "object")
746
746
  return t.bigIntValue;
747
- const r = L(t), n = f(this, A, C).call(this, r);
748
- return n === "0" || n === "undefined" ? 0n : f(this, O, F).call(this, n, e);
747
+ const r = U(t), n = f(this, A, $).call(this, r);
748
+ return n === "0" || n === "undefined" ? 0n : f(this, E, G).call(this, n, e);
749
749
  }
750
750
  formatBigIntToSafeValue(t, e) {
751
- const r = e || this.decimal || $, n = Math.max(
751
+ const r = e || this.decimal || C, n = Math.max(
752
752
  r,
753
- S(this.decimalMultiplier)
753
+ R(this.decimalMultiplier)
754
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
755
  let h = u.slice(-n);
756
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(
@@ -785,9 +785,16 @@ const I = class I {
785
785
  "0"
786
786
  )}`;
787
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 e;
792
+ const a = 10 ** (n * 3);
793
+ return `${(e / a).toFixed(t)}${i}`;
794
+ }
788
795
  };
789
- w = new WeakSet(), v = function(t, ...e) {
790
- const r = f(this, x, lt).call(this, this, ...e), n = R(r), i = e.reduce(
796
+ w = new WeakSet(), S = function(t, ...e) {
797
+ const r = f(this, P, dt).call(this, this, ...e), n = v(r), i = e.reduce(
791
798
  (c, u) => {
792
799
  const l = this.getBigIntValue(u, r);
793
800
  switch (t) {
@@ -808,52 +815,53 @@ w = new WeakSet(), v = function(t, ...e) {
808
815
  },
809
816
  //normalize is to precision multiplier base
810
817
  this.bigIntValue * n / this.decimalMultiplier
811
- ), a = tt({
818
+ ), a = q({
812
819
  bigIntDecimal: r,
813
- decimal: Math.max(r, S(this.decimalMultiplier)),
820
+ decimal: Math.max(r, R(this.decimalMultiplier)),
814
821
  value: i
815
822
  });
816
823
  return new this.constructor({ decimal: this.decimal, value: a, identifier: this.toString() });
817
- }, M = new WeakSet(), ut = function(t) {
818
- const e = f(this, A, C).call(this, t) || "0";
819
- this.bigIntValue = f(this, O, F).call(this, e);
820
- }, x = new WeakSet(), lt = function(...t) {
824
+ }, x = new WeakSet(), ht = function(t) {
825
+ const e = f(this, A, $).call(this, t) || "0";
826
+ this.bigIntValue = f(this, E, G).call(this, e);
827
+ }, P = new WeakSet(), dt = function(...t) {
821
828
  const e = t.map(
822
- (r) => typeof r == "object" ? r.decimal || S(r.decimalMultiplier) : f(this, k, W).call(this, f(this, A, C).call(this, r))
829
+ (r) => typeof r == "object" ? r.decimal || R(r.decimalMultiplier) : f(this, O, Y).call(this, f(this, A, $).call(this, r))
823
830
  ).filter(Boolean);
824
- return Math.max(...e, $);
825
- }, O = new WeakSet(), F = function(t, e) {
826
- const r = e ? R(e) : this.decimalMultiplier, n = S(r), [i = "", a = ""] = t.split(".");
831
+ return Math.max(...e, C);
832
+ }, E = new WeakSet(), G = function(t, e) {
833
+ const r = e ? v(e) : this.decimalMultiplier, n = R(r), [i = "", a = ""] = t.split(".");
827
834
  return BigInt(`${i}${a.padEnd(n, "0")}`);
828
- }, A = new WeakSet(), C = function(t) {
835
+ }, A = new WeakSet(), $ = function(t) {
829
836
  const r = `${typeof t == "number" ? Number(t).toLocaleString("fullwide", {
830
837
  useGrouping: !1,
831
838
  maximumFractionDigits: 20
832
- }) : L(t)}`.replaceAll(",", ".").split(".");
839
+ }) : U(t)}`.replaceAll(",", ".").split(".");
833
840
  return r.length > 1 ? `${r.slice(0, -1).join("")}.${r.at(-1)}` : r[0];
834
- }, k = new WeakSet(), W = function(t) {
841
+ }, O = new WeakSet(), Y = function(t) {
835
842
  var r;
836
843
  const e = ((r = t.split(".")[1]) == null ? void 0 : r.length) || 0;
837
- return Math.max(e, $);
844
+ return Math.max(e, C);
838
845
  };
839
- let E = I;
840
- function L(s) {
846
+ let I = N;
847
+ function U(s) {
841
848
  return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
842
849
  }
843
- let G;
844
- const D = (s) => {
845
- if (!G)
850
+ const M = (s, t) => typeof s == "bigint" ? q({ value: s, bigIntDecimal: t, decimal: t }) : s;
851
+ let z;
852
+ const F = (s) => {
853
+ if (!z)
846
854
  throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
847
- return G.get(s.toUpperCase()) || { decimal: m.THOR, identifier: "" };
848
- }, et = async (s, t = 0) => {
849
- Jt(s);
850
- const e = await st(Y(s));
851
- return new b({ decimal: e, value: t, identifier: s });
855
+ return z.get(s.toUpperCase()) || { decimal: m.THOR, identifier: "" };
856
+ }, st = async (s, t = 0) => {
857
+ Qt(s);
858
+ const e = await it(J(s)), r = M(t, e);
859
+ return new b({ decimal: e, value: r, identifier: s });
852
860
  };
853
- class b extends E {
861
+ class b extends I {
854
862
  constructor(e) {
855
863
  super(
856
- e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value }
864
+ e.value instanceof I ? e.value : { decimal: e.decimal, value: e.value }
857
865
  );
858
866
  p(this, "address");
859
867
  p(this, "chain");
@@ -862,8 +870,8 @@ class b extends E {
862
870
  p(this, "symbol");
863
871
  p(this, "ticker");
864
872
  p(this, "type");
865
- const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = Y(r);
866
- this.type = Ct(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;
873
+ const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`, n = J(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;
867
875
  }
868
876
  get assetValue() {
869
877
  return `${this.getValue("string")} ${this.ticker}`;
@@ -879,31 +887,31 @@ class b extends E {
879
887
  return this.chain === e && this.symbol === r;
880
888
  }
881
889
  static async fromString(e, r = 0) {
882
- return et(e, r);
890
+ return st(e, r);
883
891
  }
884
892
  static fromStringSync(e, r = 0) {
885
- const { decimal: n, identifier: i } = D(
893
+ const { decimal: n, identifier: i } = F(
886
894
  e
887
- );
888
- return i ? new b({ decimal: n, identifier: i, value: r }) : void 0;
895
+ ), a = M(r, n);
896
+ return i ? new b({ decimal: n, identifier: i, value: a }) : void 0;
889
897
  }
890
898
  static async fromIdentifier(e, r = 0) {
891
- return et(e, r);
899
+ return st(e, r);
892
900
  }
893
901
  static fromIdentifierSync(e, r = 0) {
894
- const { decimal: n, identifier: i } = D(e);
895
- return new b({ decimal: n, identifier: i, value: r });
902
+ const { decimal: n, identifier: i } = F(e), a = M(r, n);
903
+ return new b({ decimal: n, identifier: i, value: a });
896
904
  }
897
905
  static fromChainOrSignature(e, r = 0) {
898
- const { decimal: n, identifier: i } = vt(e);
899
- return new b({ value: r, decimal: n, identifier: i });
906
+ const { decimal: n, identifier: i } = Ct(e), a = M(r, n);
907
+ return new b({ value: a, decimal: n, identifier: i });
900
908
  }
901
909
  static async fromTCQuote(e, r = 0) {
902
- const n = await st(Y(e)), i = this.shiftDecimals({ value: r, from: m.THOR, to: n });
910
+ const n = await it(J(e)), i = this.shiftDecimals({ value: r, from: m.THOR, to: n });
903
911
  return new b({ value: i, identifier: e, decimal: n });
904
912
  }
905
913
  static fromTCQuoteStatic(e, r = 0) {
906
- const n = D(e), i = this.shiftDecimals({
914
+ const n = F(e), i = this.shiftDecimals({
907
915
  value: r,
908
916
  from: m.THOR,
909
917
  to: n.decimal
@@ -921,10 +929,10 @@ class b extends E {
921
929
  NativeList: i,
922
930
  ...a
923
931
  } = await import("@swapkit/tokens");
924
- G = [i, ...Object.values(a)].reduce(
932
+ z = [i, ...Object.values(a)].reduce(
925
933
  (u, { tokens: l }) => (l.forEach(({ identifier: h, chain: _, ...T }) => {
926
- const P = "decimals" in T ? T.decimals : m[_];
927
- u.set(h, { identifier: h, decimal: P });
934
+ const H = "decimals" in T ? T.decimals : m[_];
935
+ u.set(h, { identifier: h, decimal: H });
928
936
  }), u),
929
937
  /* @__PURE__ */ new Map()
930
938
  ), e({ ok: !0 });
@@ -939,7 +947,7 @@ class b extends E {
939
947
  );
940
948
  }
941
949
  }
942
- const de = (s) => {
950
+ const me = (s) => {
943
951
  const t = b.fromChainOrSignature(s);
944
952
  switch (s) {
945
953
  case o.Bitcoin:
@@ -957,17 +965,17 @@ const de = (s) => {
957
965
  default:
958
966
  return t.add(1);
959
967
  }
960
- }, Y = (s) => {
968
+ }, J = (s) => {
961
969
  const t = s.slice(0, 14).includes("/"), e = s.includes(".") ? s : `${o.THORChain}.${s}`, [r, n] = e.split("."), [i, a] = n.split("-");
962
970
  return {
963
971
  address: a == null ? void 0 : a.toLowerCase(),
964
972
  chain: r,
965
- isGasAsset: St({ chain: r, symbol: n }),
973
+ isGasAsset: $t({ chain: r, symbol: n }),
966
974
  isSynthetic: t,
967
975
  symbol: a ? `${i}-${(a == null ? void 0 : a.toLowerCase()) ?? ""}` : n,
968
976
  ticker: t ? n : i
969
977
  };
970
- }, Kt = {
978
+ }, Xt = {
971
979
  /**
972
980
  * Core
973
981
  */
@@ -1024,41 +1032,47 @@ const de = (s) => {
1024
1032
  */
1025
1033
  helpers_number_different_decimals: 99101
1026
1034
  };
1027
- class ht extends Error {
1035
+ class mt extends Error {
1028
1036
  constructor(t, e) {
1029
- console.error(e), super(t, { cause: { code: Kt[t], message: t } }), Object.setPrototypeOf(this, ht.prototype);
1037
+ console.error(e), super(t, { cause: { code: Xt[t], message: t } }), Object.setPrototypeOf(this, mt.prototype);
1030
1038
  }
1031
1039
  }
1032
- class Qt extends E {
1040
+ class Q extends I {
1033
1041
  eq(t) {
1034
1042
  return this.eqValue(t);
1035
1043
  }
1044
+ static fromBigInt(t, e) {
1045
+ return new Q({
1046
+ decimal: e,
1047
+ value: q({ value: t, bigIntDecimal: e, decimal: e })
1048
+ });
1049
+ }
1036
1050
  }
1037
1051
  export {
1038
1052
  b as AssetValue,
1039
- E as BigIntArithmetics,
1040
- zt as RequestClient,
1041
- ht as SwapKitError,
1042
- Qt as SwapKitNumber,
1043
- ee as assetFromString,
1044
- he as derivationPathToString,
1045
- re as filterAssets,
1046
- tt as formatBigIntToSafeValue,
1047
- te as gasFeeMultiplier,
1048
- Ct as getAssetType,
1049
- Et as getAsymmetricAssetShare,
1050
- ne as getAsymmetricAssetWithdrawAmount,
1051
- It as getAsymmetricRuneShare,
1052
- se as getAsymmetricRuneWithdrawAmount,
1053
- vt as getCommonAssetInfo,
1054
- st as getDecimal,
1055
- oe as getEstimatedPoolShare,
1056
- ae as getLiquiditySlippage,
1057
- ce as getMemoFor,
1058
- de as getMinAmountByChain,
1059
- Ot as getSymmetricPoolShare,
1060
- ie as getSymmetricWithdraw,
1061
- ue as getTHORNameCost,
1062
- St as isGasAsset,
1063
- le as validateTHORName
1053
+ I as BigIntArithmetics,
1054
+ Kt as RequestClient,
1055
+ mt as SwapKitError,
1056
+ Q as SwapKitNumber,
1057
+ re as assetFromString,
1058
+ de as derivationPathToString,
1059
+ se as filterAssets,
1060
+ q as formatBigIntToSafeValue,
1061
+ ee as gasFeeMultiplier,
1062
+ It as getAssetType,
1063
+ Vt as getAsymmetricAssetShare,
1064
+ ie as getAsymmetricAssetWithdrawAmount,
1065
+ Ot as getAsymmetricRuneShare,
1066
+ ne as getAsymmetricRuneWithdrawAmount,
1067
+ Ct as getCommonAssetInfo,
1068
+ it as getDecimal,
1069
+ ae as getEstimatedPoolShare,
1070
+ ce as getLiquiditySlippage,
1071
+ ue as getMemoFor,
1072
+ me as getMinAmountByChain,
1073
+ Bt as getSymmetricPoolShare,
1074
+ oe as getSymmetricWithdraw,
1075
+ le as getTHORNameCost,
1076
+ $t as isGasAsset,
1077
+ he as validateTHORName
1064
1078
  };