@swapkit/helpers 1.0.0-rc.61 → 1.0.0-rc.63

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
@@ -4,16 +4,16 @@ var f = (s, t, e) => (yt(s, typeof t != "symbol" ? t + "" : t, e), e), wt = (s,
4
4
  if (!t.has(s))
5
5
  throw TypeError("Cannot " + e);
6
6
  };
7
- var $ = (s, t, e) => {
7
+ var v = (s, t, e) => {
8
8
  if (t.has(s))
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
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 Tt, MemoType as _, ChainToChainId as $t } from "@swapkit/types";
14
- const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
13
+ import { FeeOption as D, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as $t, MemoType as _, ChainToChainId as vt } from "@swapkit/types";
14
+ const Tt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
15
15
  try {
16
- const { result: e } = await Zt.post(Tt[s], {
16
+ const { result: e } = await Zt.post($t[s], {
17
17
  headers: {
18
18
  accept: "*/*",
19
19
  "content-type": "application/json",
@@ -23,7 +23,7 @@ const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
23
23
  id: 44,
24
24
  jsonrpc: "2.0",
25
25
  method: "eth_call",
26
- params: [{ to: t.toLowerCase(), data: vt }, "latest"]
26
+ params: [{ to: t.toLowerCase(), data: Tt }, "latest"]
27
27
  })
28
28
  });
29
29
  return parseInt(BigInt(e).toString());
@@ -50,9 +50,9 @@ const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
50
50
  return d[s];
51
51
  }
52
52
  }, ie = {
53
- [U.Average]: 1.2,
54
- [U.Fast]: 1.5,
55
- [U.Fastest]: 2
53
+ [D.Average]: 1.2,
54
+ [D.Fast]: 1.5,
55
+ [D.Fastest]: 2
56
56
  }, it = ({ chain: s, symbol: t }) => {
57
57
  switch (s) {
58
58
  case o.Bitcoin:
@@ -81,9 +81,9 @@ const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
81
81
  }
82
82
  }, Ot = (s) => {
83
83
  switch (s) {
84
- case "ETH.THOR":
84
+ case `${o.Ethereum}.THOR`:
85
85
  return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
86
- case "ETH.vTHOR":
86
+ case `${o.Ethereum}.vTHOR`:
87
87
  return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
88
88
  case o.Cosmos:
89
89
  return { identifier: "GAIA.ATOM", decimal: d[s] };
@@ -93,8 +93,10 @@ const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
93
93
  return { identifier: "BSC.BNB", decimal: d[s] };
94
94
  case o.Maya:
95
95
  return { identifier: "MAYA.CACAO", decimal: d.MAYA };
96
- case "MAYA.MAYA":
96
+ case `${o.Maya}.MAYA`:
97
97
  return { identifier: "MAYA.MAYA", decimal: 4 };
98
+ case `${o.Kujira}.USK`:
99
+ return { identifier: `${o.Kujira}.USK`, decimal: 6 };
98
100
  case o.Kujira:
99
101
  case o.Arbitrum:
100
102
  case o.Optimism:
@@ -168,8 +170,8 @@ function qt({
168
170
  poolUnits: t,
169
171
  assetDepth: e
170
172
  }) {
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), l = r.mul(r), h = c.mul(a.sub(u).add(l)), T = n.mul(n).mul(n);
172
- return h.div(T);
173
+ 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), l = r.mul(r), h = c.mul(a.sub(u).add(l)), $ = n.mul(n).mul(n);
174
+ return h.div($);
173
175
  }
174
176
  function ce({
175
177
  percent: s,
@@ -222,11 +224,11 @@ function he({
222
224
  runeAmount: n,
223
225
  assetAmount: i
224
226
  }) {
225
- const c = new g({ value: s, decimal: 8 }), a = new g({ value: e, decimal: 8 }), u = new g({ value: t, decimal: 8 }), l = new g({ value: n, decimal: 8 }), h = new g({ value: i, decimal: 8 }), T = l.mul(a), H = h.mul(c), mt = l.mul(h), pt = c.mul(a), ft = u.mul(T.add(H.add(mt.mul(2)))), _t = T.add(H.add(pt.mul(2))), Q = ft.div(_t), D = p(r).add(Q);
227
+ const c = new g({ value: s, decimal: 8 }), a = new g({ value: e, decimal: 8 }), u = new g({ value: t, decimal: 8 }), l = new g({ value: n, decimal: 8 }), h = new g({ value: i, decimal: 8 }), $ = l.mul(a), H = h.mul(c), mt = l.mul(h), pt = c.mul(a), ft = u.mul($.add(H.add(mt.mul(2)))), _t = $.add(H.add(pt.mul(2))), Q = ft.div(_t), U = p(r).add(Q);
226
228
  if (Q.getBaseValue("number") === 0)
227
- return D.div(u).getBaseValue("number");
228
- const gt = u.add(D);
229
- return D.div(gt).getBaseValue("number");
229
+ return U.div(u).getBaseValue("number");
230
+ const gt = u.add(U);
231
+ return U.div(gt).getBaseValue("number");
230
232
  }
231
233
  function de({
232
234
  runeAmount: s,
@@ -365,7 +367,7 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
365
367
  formData: "multipart/form-data",
366
368
  arrayBuffer: "*/*",
367
369
  blob: "*/*"
368
- }, L = 2147483647, ut = Symbol("stop"), Dt = {
370
+ }, L = 2147483647, ut = Symbol("stop"), Ut = {
369
371
  json: !0,
370
372
  parseJson: !0,
371
373
  searchParams: !0,
@@ -376,7 +378,7 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
376
378
  throwHttpErrors: !0,
377
379
  onDownloadProgress: !0,
378
380
  fetch: !0
379
- }, Ut = {
381
+ }, Dt = {
380
382
  method: !0,
381
383
  headers: !0,
382
384
  body: !0,
@@ -400,7 +402,7 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
400
402
  maxRetryAfter: Number.POSITIVE_INFINITY,
401
403
  backoffLimit: Number.POSITIVE_INFINITY,
402
404
  delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
403
- }, Gt = (s = {}) => {
405
+ }, Kt = (s = {}) => {
404
406
  if (typeof s == "number")
405
407
  return {
406
408
  ...Z,
@@ -416,7 +418,7 @@ const q = (s) => s !== null && typeof s == "object", M = (...s) => {
416
418
  afterStatusCodes: lt
417
419
  };
418
420
  };
419
- async function Yt(s, t, e, r) {
421
+ async function Gt(s, t, e, r) {
420
422
  return new Promise((n, i) => {
421
423
  const c = setTimeout(() => {
422
424
  e && e.abort(), i(new ot(s));
@@ -440,7 +442,7 @@ async function zt(s, { signal: t }) {
440
442
  const Jt = (s, t) => {
441
443
  const e = {};
442
444
  for (const r in t)
443
- !(r in Ut) && !(r in Dt) && !(r in s) && (e[r] = t[r]);
445
+ !(r in Dt) && !(r in Ut) && !(r in s) && (e[r] = t[r]);
444
446
  return e;
445
447
  };
446
448
  class V {
@@ -524,7 +526,7 @@ class V {
524
526
  method: Lt(e.method ?? this._input.method),
525
527
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
526
528
  prefixUrl: String(e.prefixUrl || ""),
527
- retry: Gt(e.retry),
529
+ retry: Kt(e.retry),
528
530
  throwHttpErrors: e.throwHttpErrors !== !1,
529
531
  timeout: e.timeout ?? 1e4,
530
532
  fetch: e.fetch ?? globalThis.fetch.bind(globalThis)
@@ -602,7 +604,7 @@ class V {
602
604
  return r;
603
605
  }
604
606
  const t = Jt(this.request, this._options);
605
- return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Yt(this.request.clone(), t, this.abortController, this._options);
607
+ return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Gt(this.request.clone(), t, this.abortController, this._options);
606
608
  }
607
609
  /* istanbul ignore next */
608
610
  _stream(t, e) {
@@ -644,7 +646,7 @@ const W = (s) => {
644
646
  for (const e of ct)
645
647
  t[e] = (r, n) => V.create(r, M(s, n, { method: e }));
646
648
  return t.create = (e) => W(M(e)), t.extend = (e) => W(M(s, e)), t.stop = ut, t;
647
- }, Kt = W(), Qt = Kt, Xt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Qt.create({ headers: Xt }), Zt = {
649
+ }, Yt = W(), Qt = Yt, Xt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Qt.create({ headers: Xt }), Zt = {
648
650
  get: (s, t) => tt.get(s, t).json(),
649
651
  post: (s, t) => tt.post(s, t).json()
650
652
  }, et = [...Object.values(o), "TERRA"];
@@ -678,14 +680,14 @@ function k({
678
680
  ""
679
681
  );
680
682
  }
681
- var w, R, b, v, N, ht, E, G, B, Y;
682
- const K = class K {
683
+ var w, R, b, T, N, ht, E, K, B, G;
684
+ const Y = class Y {
683
685
  constructor(t) {
684
- $(this, w);
685
- $(this, b);
686
- $(this, N);
687
- $(this, E);
688
- $(this, B);
686
+ v(this, w);
687
+ v(this, b);
688
+ v(this, N);
689
+ v(this, E);
690
+ v(this, B);
689
691
  f(this, "decimalMultiplier", 10n ** 8n);
690
692
  f(this, "bigIntValue", 0n);
691
693
  f(this, "decimal");
@@ -693,7 +695,7 @@ const K = class K {
693
695
  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
696
  }
695
697
  static fromBigInt(t, e) {
696
- return new K({
698
+ return new Y({
697
699
  decimal: e,
698
700
  value: k({ value: t, bigIntDecimal: e, decimal: e })
699
701
  });
@@ -724,19 +726,19 @@ const K = class K {
724
726
  return m(this, w, R).call(this, "div", ...t);
725
727
  }
726
728
  gt(t) {
727
- return m(this, b, v).call(this, "gt", t);
729
+ return m(this, b, T).call(this, "gt", t);
728
730
  }
729
731
  gte(t) {
730
- return m(this, b, v).call(this, "gte", t);
732
+ return m(this, b, T).call(this, "gte", t);
731
733
  }
732
734
  lt(t) {
733
- return m(this, b, v).call(this, "lt", t);
735
+ return m(this, b, T).call(this, "lt", t);
734
736
  }
735
737
  lte(t) {
736
- return m(this, b, v).call(this, "lte", t);
738
+ return m(this, b, T).call(this, "lte", t);
737
739
  }
738
740
  eqValue(t) {
739
- return m(this, b, v).call(this, "eqValue", t);
741
+ return m(this, b, T).call(this, "eqValue", t);
740
742
  }
741
743
  // @ts-expect-error False positive
742
744
  getValue(t) {
@@ -769,7 +771,7 @@ const K = class K {
769
771
  if (!e && typeof t == "object")
770
772
  return t.bigIntValue;
771
773
  const r = z(t), n = x(r);
772
- return n === "0" || n === "undefined" ? 0n : m(this, B, Y).call(this, n, e);
774
+ return n === "0" || n === "undefined" ? 0n : m(this, B, G).call(this, n, e);
773
775
  }
774
776
  toSignificant(t = 6) {
775
777
  const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
@@ -827,7 +829,7 @@ const K = class K {
827
829
  }
828
830
  };
829
831
  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(
832
+ const r = m(this, E, K).call(this, this, ...e), n = Math.max(r, C(this.decimalMultiplier)), i = y(n), c = e.reduce(
831
833
  (u, l) => {
832
834
  const h = this.getBigIntValue(l, n);
833
835
  switch (t) {
@@ -859,8 +861,8 @@ w = new WeakSet(), R = function(t, ...e) {
859
861
  value: a,
860
862
  identifier: this.toString()
861
863
  });
862
- }, b = new WeakSet(), v = function(t, ...e) {
863
- const r = m(this, E, G).call(this, this, ...e), n = this.getBigIntValue(e[0], r), i = this.getBigIntValue(this, r);
864
+ }, b = new WeakSet(), T = function(t, ...e) {
865
+ const r = m(this, E, K).call(this, this, ...e), n = this.getBigIntValue(e[0], r), i = this.getBigIntValue(this, r);
864
866
  switch (t) {
865
867
  case "gt":
866
868
  return i > n;
@@ -875,15 +877,15 @@ w = new WeakSet(), R = function(t, ...e) {
875
877
  }
876
878
  }, N = new WeakSet(), ht = function(t) {
877
879
  const e = x(t) || "0";
878
- this.bigIntValue = m(this, B, Y).call(this, e);
879
- }, E = new WeakSet(), G = function(...t) {
880
+ this.bigIntValue = m(this, B, G).call(this, e);
881
+ }, E = new WeakSet(), K = function(...t) {
880
882
  const e = t.map((r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : rt(x(r))).filter(Boolean);
881
883
  return Math.max(...e, O);
882
- }, B = new WeakSet(), Y = function(t, e) {
884
+ }, B = new WeakSet(), G = function(t, e) {
883
885
  const r = e ? y(e) : this.decimalMultiplier, n = C(r), [i = "", c = ""] = t.split(".");
884
886
  return BigInt(`${i}${c.padEnd(n, "0")}`);
885
887
  };
886
- let j = K;
888
+ let j = Y;
887
889
  const ee = Intl.NumberFormat("fullwide", {
888
890
  useGrouping: !1,
889
891
  maximumFractionDigits: 20
@@ -932,7 +934,7 @@ class A extends j {
932
934
  return this.chain === e && this.symbol === r;
933
935
  }
934
936
  chainId() {
935
- return $t[this.chain];
937
+ return vt[this.chain];
936
938
  }
937
939
  // THOR.RUNE
938
940
  // THOR.ETH.ETH
@@ -1078,6 +1080,7 @@ const re = {
1078
1080
  core_wallet_trezor_not_installed: 10106,
1079
1081
  core_wallet_keplr_not_installed: 10107,
1080
1082
  core_wallet_okx_not_installed: 10108,
1083
+ core_wallet_keepkey_not_installed: 10109,
1081
1084
  /**
1082
1085
  * Core - Swap
1083
1086
  */