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

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
@@ -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,7 +359,7 @@ 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", jt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], Nt = {
363
363
  json: "application/json",
364
364
  text: "text/*",
365
365
  formData: "multipart/form-data",
@@ -443,9 +443,9 @@ 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 () => {
448
+ const r = new V(t, e), n = async () => {
449
449
  if (typeof r._options.timeout == "number" && r._options.timeout > L)
450
450
  throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`);
451
451
  await Promise.resolve();
@@ -469,7 +469,7 @@ class P {
469
469
  }
470
470
  return a;
471
471
  }, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
472
- for (const [a, u] of Object.entries(jt))
472
+ for (const [a, u] of Object.entries(Nt))
473
473
  c[a] = async () => {
474
474
  r.request.headers.set("accept", r.request.headers.get("accept") || u);
475
475
  const h = (await c).clone();
@@ -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,9 +544,9 @@ 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
- (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);
549
+ (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);
550
550
  }
551
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 }));
552
552
  }
@@ -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(),
@@ -678,19 +678,19 @@ function k({
678
678
  ""
679
679
  );
680
680
  }
681
- var w, R, b, T, j, ht, E, G, B, Y;
681
+ var w, R, b, T, N, ht, E, G, B, Y;
682
682
  const K = class K {
683
683
  constructor(t) {
684
684
  v(this, w);
685
685
  v(this, b);
686
- v(this, j);
686
+ v(this, N);
687
687
  v(this, E);
688
688
  v(this, B);
689
689
  f(this, "decimalMultiplier", 10n ** 8n);
690
690
  f(this, "bigIntValue", 0n);
691
691
  f(this, "decimal");
692
692
  const e = z(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(x(e)), this.decimal || 0)), m(this, j, ht).call(this, e);
693
+ this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(rt(x(e)), this.decimal || 0)), m(this, N, ht).call(this, e);
694
694
  }
695
695
  static fromBigInt(t, e) {
696
696
  return new K({
@@ -873,7 +873,7 @@ w = new WeakSet(), R = function(t, ...e) {
873
873
  case "eqValue":
874
874
  return i === n;
875
875
  }
876
- }, j = new WeakSet(), ht = function(t) {
876
+ }, N = new WeakSet(), ht = function(t) {
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) {
@@ -883,7 +883,7 @@ w = new WeakSet(), R = function(t, ...e) {
883
883
  const r = e ? y(e) : this.decimalMultiplier, n = C(r), [i = "", c = ""] = t.split(".");
884
884
  return BigInt(`${i}${c.padEnd(n, "0")}`);
885
885
  };
886
- let N = K;
886
+ let j = K;
887
887
  const te = Intl.NumberFormat("fullwide", {
888
888
  useGrouping: !1,
889
889
  maximumFractionDigits: 20
@@ -901,7 +901,7 @@ function z(s) {
901
901
  return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
902
902
  }
903
903
  const S = /* @__PURE__ */ new Map();
904
- class A extends N {
904
+ class A extends j {
905
905
  constructor({
906
906
  value: e,
907
907
  decimal: r,
@@ -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,11 +1022,13 @@ 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) {
1035
- const [e, r] = s.split("/");
1029
+ const [e, r] = s.split(".")[0].toUpperCase() === o.THORChain ? s.split(".").slice(1).join().split("/") : s.split("/");
1030
+ if (!e || !r)
1031
+ throw new Error("Invalid asset identifier");
1036
1032
  return new A({
1037
1033
  decimal: 8,
1038
1034
  value: I(t, 8),
@@ -1042,8 +1038,11 @@ function st(s, t = 0) {
1042
1038
  function I(s, t) {
1043
1039
  return typeof s == "bigint" ? k({ value: s, bigIntDecimal: t, decimal: t }) : s;
1044
1040
  }
1045
- function V(s) {
1046
- 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("-");
1041
+ function P(s) {
1042
+ const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".")[0].toUpperCase() === o.THORChain ? s.split(".").slice(1).join().split("/") : s.split("/");
1043
+ if (t && (!e || !r))
1044
+ throw new Error("Invalid asset identifier");
1045
+ const n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, c] = n.split("."), [a, u] = (t ? r : c).split("-");
1047
1046
  return {
1048
1047
  address: u == null ? void 0 : u.toLowerCase(),
1049
1048
  chain: i,
@@ -1116,7 +1115,7 @@ class dt extends Error {
1116
1115
  console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: ee[t], message: t } }), Object.setPrototypeOf(this, dt.prototype);
1117
1116
  }
1118
1117
  }
1119
- class g extends N {
1118
+ class g extends j {
1120
1119
  eq(t) {
1121
1120
  return this.eqValue(t);
1122
1121
  }
@@ -1129,7 +1128,7 @@ class g extends N {
1129
1128
  }
1130
1129
  export {
1131
1130
  A as AssetValue,
1132
- N as BigIntArithmetics,
1131
+ j as BigIntArithmetics,
1133
1132
  Xt as RequestClient,
1134
1133
  dt as SwapKitError,
1135
1134
  g as SwapKitNumber,