@swapkit/helpers 1.0.0-rc.55 → 1.0.0-rc.56

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
@@ -10,7 +10,7 @@ var v = (s, t, e) => {
10
10
  t instanceof WeakSet ? t.add(s) : t.set(s, e);
11
11
  };
12
12
  var m = (s, t, e) => (wt(s, t, "access private method"), e);
13
- import { FeeOption as U, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as $t, MemoType as _ } from "@swapkit/types";
13
+ import { FeeOption as L, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as $t, MemoType as _ } from "@swapkit/types";
14
14
  const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
15
15
  try {
16
16
  const { result: e } = await Xt.post($t[s], {
@@ -35,24 +35,24 @@ const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
35
35
  return d.ETH;
36
36
  const [, t] = s.split("-");
37
37
  return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH;
38
- }, Ct = async (s) => {
38
+ }, Rt = async (s) => {
39
39
  const [, t] = s.split("-");
40
40
  return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX;
41
- }, Rt = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, St = async ({ chain: s, symbol: t }) => {
41
+ }, Ct = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, St = async ({ chain: s, symbol: t }) => {
42
42
  switch (s) {
43
43
  case o.Ethereum:
44
44
  return Tt(t);
45
45
  case o.Avalanche:
46
- return Ct(t);
47
- case o.BinanceSmartChain:
48
46
  return Rt(t);
47
+ case o.BinanceSmartChain:
48
+ return Ct(t);
49
49
  default:
50
50
  return d[s];
51
51
  }
52
52
  }, ne = {
53
- [U.Average]: 1.2,
54
- [U.Fast]: 1.5,
55
- [U.Fastest]: 2
53
+ [L.Average]: 1.2,
54
+ [L.Fast]: 1.5,
55
+ [L.Fastest]: 2
56
56
  }, it = ({ chain: s, symbol: t }) => {
57
57
  switch (s) {
58
58
  case o.Bitcoin:
@@ -348,7 +348,7 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
348
348
  q(r.headers) && (e = at(e, r.headers), t.headers = e);
349
349
  }
350
350
  return t;
351
- }, Vt = (() => {
351
+ }, Pt = (() => {
352
352
  let s = !1, t = !1;
353
353
  const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
354
354
  return e && r && (t = new globalThis.Request("https://empty.invalid", {
@@ -359,13 +359,13 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
359
359
  return s = !0, "half";
360
360
  }
361
361
  }).headers.has("Content-Type")), s && !t;
362
- })(), Pt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function", Nt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], jt = {
362
+ })(), Vt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function", Nt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], jt = {
363
363
  json: "application/json",
364
364
  text: "text/*",
365
365
  formData: "multipart/form-data",
366
366
  arrayBuffer: "*/*",
367
367
  blob: "*/*"
368
- }, L = 2147483647, ut = Symbol("stop"), Ht = {
368
+ }, U = 2147483647, ut = Symbol("stop"), Ht = {
369
369
  json: !0,
370
370
  parseJson: !0,
371
371
  searchParams: !0,
@@ -392,9 +392,9 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
392
392
  window: !0,
393
393
  dispatcher: !0,
394
394
  duplex: !0
395
- }, Ut = (s) => ct.includes(s) ? s.toUpperCase() : s, Lt = ["get", "put", "head", "delete", "options", "trace"], Ft = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Z = {
395
+ }, Lt = (s) => ct.includes(s) ? s.toUpperCase() : s, Ut = ["get", "put", "head", "delete", "options", "trace"], Ft = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Z = {
396
396
  limit: 2,
397
- methods: Lt,
397
+ methods: Ut,
398
398
  statusCodes: Ft,
399
399
  afterStatusCodes: lt,
400
400
  maxRetryAfter: Number.POSITIVE_INFINITY,
@@ -443,11 +443,11 @@ const zt = (s, t) => {
443
443
  !(r in Dt) && !(r in Ht) && !(r in s) && (e[r] = t[r]);
444
444
  return e;
445
445
  };
446
- class P {
446
+ class V {
447
447
  static create(t, e) {
448
- const r = new P(t, e), n = async () => {
449
- if (typeof r._options.timeout == "number" && r._options.timeout > L)
450
- throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`);
448
+ const r = new V(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}`);
451
451
  await Promise.resolve();
452
452
  let a = await r._fetch();
453
453
  for (const u of r._options.hooks.afterResponse) {
@@ -521,7 +521,7 @@ class P {
521
521
  beforeError: [],
522
522
  afterResponse: []
523
523
  }, e.hooks),
524
- method: Ut(e.method ?? this._input.method),
524
+ method: Lt(e.method ?? this._input.method),
525
525
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
526
526
  prefixUrl: String(e.prefixUrl || ""),
527
527
  retry: Wt(e.retry),
@@ -535,7 +535,7 @@ class P {
535
535
  throw new Error("`input` must not begin with a slash when using `prefixUrl`");
536
536
  this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
537
537
  }
538
- if (Pt) {
538
+ if (Vt) {
539
539
  if (this.abortController = new globalThis.AbortController(), this._options.signal) {
540
540
  const r = this._options.signal;
541
541
  this._options.signal.addEventListener("abort", () => {
@@ -544,7 +544,7 @@ class P {
544
544
  }
545
545
  this._options.signal = this.abortController.signal;
546
546
  }
547
- if (Vt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
547
+ if (Pt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
548
548
  const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
549
549
  (Nt && 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);
550
550
  }
@@ -575,7 +575,7 @@ class P {
575
575
  try {
576
576
  return await t();
577
577
  } catch (e) {
578
- const r = Math.min(this._calculateRetryDelay(e), L);
578
+ const r = Math.min(this._calculateRetryDelay(e), U);
579
579
  if (r !== 0 && this._retryCount > 0) {
580
580
  await Yt(r, { signal: this._options.signal });
581
581
  for (const n of this._options.hooks.beforeRetry)
@@ -640,9 +640,9 @@ class P {
640
640
  }
641
641
  /*! MIT License © Sindre Sorhus */
642
642
  const W = (s) => {
643
- const t = (e, r) => P.create(e, M(s, r));
643
+ const t = (e, r) => V.create(e, M(s, r));
644
644
  for (const e of ct)
645
- t[e] = (r, n) => P.create(r, M(s, n, { method: e }));
645
+ t[e] = (r, n) => V.create(r, M(s, n, { method: e }));
646
646
  return t.create = (e) => W(M(e)), t.extend = (e) => W(M(s, e)), t.stop = ut, t;
647
647
  }, Jt = W(), Kt = Jt, Qt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Kt.create({ headers: Qt }), Xt = {
648
648
  get: (s, t) => tt.get(s, t).json(),
@@ -659,7 +659,7 @@ function Zt(s = "") {
659
659
  `Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
660
660
  );
661
661
  }
662
- const O = 8, y = (s) => 10n ** BigInt(s), C = (s) => Math.log10(parseFloat(s.toString()));
662
+ const O = 8, y = (s) => 10n ** BigInt(s), R = (s) => Math.log10(parseFloat(s.toString()));
663
663
  function k({
664
664
  value: s,
665
665
  bigIntDecimal: t = O,
@@ -678,7 +678,7 @@ function k({
678
678
  ""
679
679
  );
680
680
  }
681
- var w, R, b, T, j, ht, E, G, B, Y;
681
+ var w, C, b, T, j, ht, E, G, B, Y;
682
682
  const K = class K {
683
683
  constructor(t) {
684
684
  v(this, w);
@@ -712,16 +712,16 @@ const K = class K {
712
712
  return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
713
713
  }
714
714
  add(...t) {
715
- return m(this, w, R).call(this, "add", ...t);
715
+ return m(this, w, C).call(this, "add", ...t);
716
716
  }
717
717
  sub(...t) {
718
- return m(this, w, R).call(this, "sub", ...t);
718
+ return m(this, w, C).call(this, "sub", ...t);
719
719
  }
720
720
  mul(...t) {
721
- return m(this, w, R).call(this, "mul", ...t);
721
+ return m(this, w, C).call(this, "mul", ...t);
722
722
  }
723
723
  div(...t) {
724
- return m(this, w, R).call(this, "div", ...t);
724
+ return m(this, w, C).call(this, "div", ...t);
725
725
  }
726
726
  gt(t) {
727
727
  return m(this, b, T).call(this, "gt", t);
@@ -742,7 +742,7 @@ const K = class K {
742
742
  getValue(t) {
743
743
  const e = this.formatBigIntToSafeValue(
744
744
  this.bigIntValue,
745
- this.decimal || C(this.decimalMultiplier)
745
+ this.decimal || R(this.decimalMultiplier)
746
746
  );
747
747
  switch (t) {
748
748
  case "number":
@@ -817,7 +817,7 @@ const K = class K {
817
817
  formatBigIntToSafeValue(t, e) {
818
818
  const r = e || this.decimal || O, n = Math.max(
819
819
  r,
820
- C(this.decimalMultiplier)
820
+ R(this.decimalMultiplier)
821
821
  ), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c, l = u.length - n;
822
822
  let h = u.slice(-n);
823
823
  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(
@@ -826,8 +826,8 @@ const K = class K {
826
826
  )}.${h}`.replace(/\.?0*$/, "");
827
827
  }
828
828
  };
829
- w = new WeakSet(), R = function(t, ...e) {
830
- const r = m(this, E, G).call(this, this, ...e), n = Math.max(r, C(this.decimalMultiplier)), i = y(n), c = e.reduce(
829
+ w = new WeakSet(), C = function(t, ...e) {
830
+ const r = m(this, E, G).call(this, this, ...e), n = Math.max(r, R(this.decimalMultiplier)), i = y(n), c = e.reduce(
831
831
  (u, l) => {
832
832
  const h = this.getBigIntValue(l, n);
833
833
  switch (t) {
@@ -877,10 +877,10 @@ w = new WeakSet(), R = function(t, ...e) {
877
877
  const e = x(t) || "0";
878
878
  this.bigIntValue = m(this, B, Y).call(this, e);
879
879
  }, E = new WeakSet(), G = function(...t) {
880
- const e = t.map((r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : rt(x(r))).filter(Boolean);
880
+ const e = t.map((r) => typeof r == "object" ? r.decimal || R(r.decimalMultiplier) : rt(x(r))).filter(Boolean);
881
881
  return Math.max(...e, O);
882
882
  }, B = new WeakSet(), Y = function(t, e) {
883
- const r = e ? y(e) : this.decimalMultiplier, n = C(r), [i = "", c = ""] = t.split(".");
883
+ const r = e ? y(e) : this.decimalMultiplier, n = R(r), [i = "", c = ""] = t.split(".");
884
884
  return BigInt(`${i}${c.padEnd(n, "0")}`);
885
885
  };
886
886
  let N = K;
@@ -919,7 +919,7 @@ class A extends N {
919
919
  f(this, "tax");
920
920
  f(this, "ticker");
921
921
  f(this, "type");
922
- const u = V(a || `${i}.${c}`);
922
+ const u = P(a || `${i}.${c}`);
923
923
  this.type = Ot(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;
924
924
  }
925
925
  toString() {
@@ -948,12 +948,9 @@ class A extends N {
948
948
  return F(e, r);
949
949
  }
950
950
  static fromStringSync(e, r = 0) {
951
- const { chain: n, isSynthetic: i } = V(e), c = S.get(e.toUpperCase());
951
+ const { chain: n, isSynthetic: i } = P(e), c = S.get(e.toUpperCase());
952
952
  if (i)
953
953
  return st(e, r);
954
- c || console.error(
955
- `Asset ${e} is not loaded. Use AssetValue.loadStaticAssets() to load it`
956
- );
957
954
  const { tax: a, decimal: u, identifier: l } = c || {
958
955
  decimal: d[n],
959
956
  identifier: e
@@ -966,12 +963,9 @@ class A extends N {
966
963
  });
967
964
  }
968
965
  static fromIdentifierSync(e, r = 0) {
969
- const { chain: n, isSynthetic: i } = V(e), c = S.get(e);
966
+ const { chain: n, isSynthetic: i } = P(e), c = S.get(e);
970
967
  if (i)
971
968
  return st(e, r);
972
- c || console.error(
973
- `Asset ${e} is not loaded. - Loading with base Chain. Use AssetValue.loadStaticAssets() to load it`
974
- );
975
969
  const { tax: a, decimal: u, identifier: l } = c || {
976
970
  decimal: d[n],
977
971
  identifier: e
@@ -1028,7 +1022,7 @@ function _e(s) {
1028
1022
  }
1029
1023
  async function F(s, t = 0) {
1030
1024
  Zt(s);
1031
- const e = S.get(s.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await St(V(s));
1025
+ const e = S.get(s.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await St(P(s));
1032
1026
  return e || S.set(s.toUpperCase(), { identifier: s, decimal: r }), new A({ decimal: r, value: I(t, r), identifier: s });
1033
1027
  }
1034
1028
  function st(s, t = 0) {
@@ -1042,7 +1036,7 @@ function st(s, t = 0) {
1042
1036
  function I(s, t) {
1043
1037
  return typeof s == "bigint" ? k({ value: s, bigIntDecimal: t, decimal: t }) : s;
1044
1038
  }
1045
- function V(s) {
1039
+ function P(s) {
1046
1040
  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("-");
1047
1041
  return {
1048
1042
  address: u == null ? void 0 : u.toLowerCase(),