@swapkit/core 1.0.0-rc.24 → 1.0.0-rc.26

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
@@ -843,7 +843,7 @@ var pt = /* @__PURE__ */ ((e) => (e[e.NoError = 36864] = "NoError", e))(pt || {}
843
843
  if (t.has(e))
844
844
  throw TypeError("Cannot add the same private member more than once");
845
845
  t instanceof WeakSet ? t.add(e) : t.set(e, n);
846
- }, g = (e, t, n) => (yt(e, t, "access private method"), n);
846
+ }, R = (e, t, n) => (yt(e, t, "access private method"), n);
847
847
  const ct = "0x313ce567", De = async ({ chain: e, to: t }) => {
848
848
  try {
849
849
  const { result: n } = await be.post(ot[e], {
@@ -985,14 +985,14 @@ const ct = "0x313ce567", De = async ({ chain: e, to: t }) => {
985
985
  poolUnits: t,
986
986
  runeDepth: n
987
987
  }) => {
988
- const a = I(e), s = I(t), r = I(n), o = a.mul(r), p = s.mul(s).mul(2), d = s.mul(a).mul(2), y = a.mul(a), u = s.mul(s).mul(s);
988
+ const a = g(e), s = g(t), r = g(n), o = a.mul(r), p = s.mul(s).mul(2), d = s.mul(a).mul(2), y = a.mul(a), u = s.mul(s).mul(s);
989
989
  return o.mul(p.sub(d).add(y)).div(u);
990
990
  }, gt = ({
991
991
  liquidityUnits: e,
992
992
  poolUnits: t,
993
993
  assetDepth: n
994
994
  }) => {
995
- const a = I(e), s = I(t), r = I(n), o = a.mul(r), p = s.mul(s).mul(2), d = s.mul(a).mul(2), y = a.mul(a), u = o.mul(p.sub(d).add(y)), c = s.mul(s).mul(s);
995
+ const a = g(e), s = g(t), r = g(n), o = a.mul(r), p = s.mul(s).mul(2), d = s.mul(a).mul(2), y = a.mul(a), u = o.mul(p.sub(d).add(y)), c = s.mul(s).mul(s);
996
996
  return u.div(c);
997
997
  }, In = ({
998
998
  percent: e,
@@ -1004,14 +1004,14 @@ const ct = "0x313ce567", De = async ({ chain: e, to: t }) => {
1004
1004
  assetDepth: t,
1005
1005
  liquidityUnits: n,
1006
1006
  poolUnits: a
1007
- }) => gt({ assetDepth: t, liquidityUnits: n, poolUnits: a }).mul(e), I = (e) => N.fromBigInt(BigInt(e), A.THOR), Ot = ({
1007
+ }) => gt({ assetDepth: t, liquidityUnits: n, poolUnits: a }).mul(e), g = (e) => D.fromBigInt(BigInt(e), A.THOR), Ot = ({
1008
1008
  liquidityUnits: e,
1009
1009
  poolUnits: t,
1010
1010
  runeDepth: n,
1011
1011
  assetDepth: a
1012
1012
  }) => ({
1013
- assetAmount: I(a).mul(e).div(t),
1014
- runeAmount: I(n).mul(e).div(t)
1013
+ assetAmount: g(a).mul(e).div(t),
1014
+ runeAmount: g(n).mul(e).div(t)
1015
1015
  }), vn = ({
1016
1016
  liquidityUnits: e,
1017
1017
  poolUnits: t,
@@ -1030,8 +1030,8 @@ const ct = "0x313ce567", De = async ({ chain: e, to: t }) => {
1030
1030
  runeAmount: s,
1031
1031
  assetAmount: r
1032
1032
  }) => {
1033
- const o = new N({ value: e, decimal: 8 }), p = new N({ value: n, decimal: 8 }), d = new N({ value: t, decimal: 8 }), y = new N({ value: s, decimal: 8 }), u = new N({ value: r, decimal: 8 }), c = y.mul(p), _ = u.mul(o), b = y.mul(u), E = o.mul(p), R = d.mul(c.add(_.add(b.mul(2)))), w = c.add(_.add(E.mul(2))), O = R.div(w), S = I(a).add(O);
1034
- if (O.getBaseValue("number") === 0)
1033
+ const o = new D({ value: e, decimal: 8 }), p = new D({ value: n, decimal: 8 }), d = new D({ value: t, decimal: 8 }), y = new D({ value: s, decimal: 8 }), u = new D({ value: r, decimal: 8 }), c = y.mul(p), _ = u.mul(o), b = y.mul(u), w = o.mul(p), E = d.mul(c.add(_.add(b.mul(2)))), O = c.add(_.add(w.mul(2))), I = E.div(O), S = g(a).add(I);
1034
+ if (I.getBaseValue("number") === 0)
1035
1035
  return S.div(d).getBaseValue("number");
1036
1036
  const P = d.add(S);
1037
1037
  return S.div(P).getBaseValue("number");
@@ -1043,13 +1043,13 @@ const ct = "0x313ce567", De = async ({ chain: e, to: t }) => {
1043
1043
  }) => {
1044
1044
  if (e === "0" || t === "0" || n === "0" || a === "0")
1045
1045
  return 0;
1046
- const s = I(n), r = I(a), o = I(t), p = I(e), d = o.mul(s).sub(r.mul(p)), y = r.mul(p).add(s.mul(r));
1046
+ const s = g(n), r = g(a), o = g(t), p = g(e), d = o.mul(s).sub(r.mul(p)), y = r.mul(p).add(s.mul(r));
1047
1047
  return Math.abs(d.div(y).getBaseValue("number"));
1048
1048
  }, It = ({
1049
1049
  symbol: e,
1050
1050
  ticker: t,
1051
1051
  chain: n
1052
- }) => n === "ETH" && t !== "ETH" ? `${t}-${e.slice(-3)}` : e, D = (e, t) => {
1052
+ }) => n === "ETH" && t !== "ETH" ? `${t}-${e.slice(-3)}` : e, x = (e, t) => {
1053
1053
  switch (e) {
1054
1054
  case h.LEAVE:
1055
1055
  case h.BOND: {
@@ -1474,8 +1474,8 @@ const qt = class $e {
1474
1474
  L(this, U), L(this, pe), L(this, de), L(this, ee), L(this, $), L(this, te), C(this, "decimalMultiplier", 10n ** 8n), C(this, "bigIntValue", 0n), C(this, "decimal");
1475
1475
  const n = ce(t);
1476
1476
  this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = H(
1477
- Math.max(g(this, te, le).call(this, g(this, $, W).call(this, n)), this.decimal || 0)
1478
- ), g(this, pe, He).call(this, n);
1477
+ Math.max(R(this, te, le).call(this, R(this, $, W).call(this, n)), this.decimal || 0)
1478
+ ), R(this, pe, He).call(this, n);
1479
1479
  }
1480
1480
  static fromBigInt(t, n) {
1481
1481
  return new $e({
@@ -1515,16 +1515,16 @@ const qt = class $e {
1515
1515
  return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
1516
1516
  }
1517
1517
  add(...t) {
1518
- return g(this, U, k).call(this, "add", ...t);
1518
+ return R(this, U, k).call(this, "add", ...t);
1519
1519
  }
1520
1520
  sub(...t) {
1521
- return g(this, U, k).call(this, "sub", ...t);
1521
+ return R(this, U, k).call(this, "sub", ...t);
1522
1522
  }
1523
1523
  mul(...t) {
1524
- return g(this, U, k).call(this, "mul", ...t);
1524
+ return R(this, U, k).call(this, "mul", ...t);
1525
1525
  }
1526
1526
  div(...t) {
1527
- return g(this, U, k).call(this, "div", ...t);
1527
+ return R(this, U, k).call(this, "div", ...t);
1528
1528
  }
1529
1529
  gt(t) {
1530
1530
  return this.bigIntValue > this.getBigIntValue(t);
@@ -1569,8 +1569,8 @@ const qt = class $e {
1569
1569
  getBigIntValue(t, n) {
1570
1570
  if (!n && typeof t == "object")
1571
1571
  return t.bigIntValue;
1572
- const a = ce(t), s = g(this, $, W).call(this, a);
1573
- return s === "0" || s === "undefined" ? 0n : g(this, ee, ue).call(this, s, n);
1572
+ const a = ce(t), s = R(this, $, W).call(this, a);
1573
+ return s === "0" || s === "undefined" ? 0n : R(this, ee, ue).call(this, s, n);
1574
1574
  }
1575
1575
  formatBigIntToSafeValue(t, n) {
1576
1576
  const a = n || this.decimal || j, s = Math.max(
@@ -1619,7 +1619,7 @@ const qt = class $e {
1619
1619
  }
1620
1620
  };
1621
1621
  U = /* @__PURE__ */ new WeakSet(), k = function(e, ...t) {
1622
- const n = g(this, de, ge).call(this, this, ...t), a = H(n), s = t.reduce(
1622
+ const n = R(this, de, ge).call(this, this, ...t), a = H(n), s = t.reduce(
1623
1623
  (o, p) => {
1624
1624
  const d = this.getBigIntValue(p, n);
1625
1625
  switch (e) {
@@ -1647,11 +1647,11 @@ U = /* @__PURE__ */ new WeakSet(), k = function(e, ...t) {
1647
1647
  });
1648
1648
  return new this.constructor({ decimal: this.decimal, value: r, identifier: this.toString() });
1649
1649
  }, pe = /* @__PURE__ */ new WeakSet(), He = function(e) {
1650
- const t = g(this, $, W).call(this, e) || "0";
1651
- this.bigIntValue = g(this, ee, ue).call(this, t);
1650
+ const t = R(this, $, W).call(this, e) || "0";
1651
+ this.bigIntValue = R(this, ee, ue).call(this, t);
1652
1652
  }, de = /* @__PURE__ */ new WeakSet(), ge = function(...e) {
1653
1653
  const t = e.map(
1654
- (n) => typeof n == "object" ? n.decimal || G(n.decimalMultiplier) : g(this, te, le).call(this, g(this, $, W).call(this, n))
1654
+ (n) => typeof n == "object" ? n.decimal || G(n.decimalMultiplier) : R(this, te, le).call(this, R(this, $, W).call(this, n))
1655
1655
  ).filter(Boolean);
1656
1656
  return Math.max(...t, j);
1657
1657
  }, ee = /* @__PURE__ */ new WeakSet(), ue = function(e, t) {
@@ -1681,9 +1681,9 @@ const Oe = (e) => {
1681
1681
  }, Ie = async (e, t = 0) => {
1682
1682
  Wt(e);
1683
1683
  const n = await _t(Te(e)), a = z(t, n);
1684
- return new x({ decimal: n, value: a, identifier: e });
1684
+ return new N({ decimal: n, value: a, identifier: e });
1685
1685
  };
1686
- class x extends ye {
1686
+ class N extends ye {
1687
1687
  constructor(t) {
1688
1688
  super(
1689
1689
  t.value instanceof ye ? t.value : { decimal: t.decimal, value: t.value }
@@ -1711,18 +1711,18 @@ class x extends ye {
1711
1711
  const { isSynthetic: a } = Te(t), { decimal: s, identifier: r } = Oe(
1712
1712
  t
1713
1713
  ), o = z(n, s);
1714
- return r ? new x({ decimal: s, identifier: r, value: o }) : a ? new x({ decimal: 8, identifier: t, value: o }) : void 0;
1714
+ return r ? new N({ decimal: s, identifier: r, value: o }) : a ? new N({ decimal: 8, identifier: t, value: o }) : void 0;
1715
1715
  }
1716
1716
  static async fromIdentifier(t, n = 0) {
1717
1717
  return Ie(t, n);
1718
1718
  }
1719
1719
  static fromIdentifierSync(t, n = 0) {
1720
1720
  const { decimal: a, identifier: s } = Oe(t), r = z(n, a);
1721
- return new x({ decimal: a, identifier: s, value: r });
1721
+ return new N({ decimal: a, identifier: s, value: r });
1722
1722
  }
1723
1723
  static fromChainOrSignature(t, n = 0) {
1724
1724
  const { decimal: a, identifier: s } = wt(t), r = z(n, a);
1725
- return new x({ value: r, decimal: a, identifier: s });
1725
+ return new N({ value: r, decimal: a, identifier: s });
1726
1726
  }
1727
1727
  static async loadStaticAssets() {
1728
1728
  return new Promise(
@@ -1754,7 +1754,7 @@ class x extends ye {
1754
1754
  }
1755
1755
  }
1756
1756
  const Se = (e) => {
1757
- const t = x.fromChainOrSignature(e);
1757
+ const t = N.fromChainOrSignature(e);
1758
1758
  switch (e) {
1759
1759
  case i.Bitcoin:
1760
1760
  case i.Litecoin:
@@ -1843,12 +1843,12 @@ class m extends Error {
1843
1843
  console.error(n), super(t, { cause: { code: jt[t], message: t } }), Object.setPrototypeOf(this, m.prototype);
1844
1844
  }
1845
1845
  }
1846
- class N extends ye {
1846
+ class D extends ye {
1847
1847
  eq(t) {
1848
1848
  return this.eqValue(t);
1849
1849
  }
1850
1850
  static fromBigInt(t, n) {
1851
- return new N({
1851
+ return new D({
1852
1852
  decimal: n,
1853
1853
  value: se({ value: t, bigIntDecimal: n, decimal: n })
1854
1854
  });
@@ -3576,30 +3576,30 @@ const Kt = [
3576
3576
  tcMemo: c,
3577
3577
  tcRouter: _,
3578
3578
  tcVault: b,
3579
- vault: E,
3580
- token: R
3579
+ vault: w,
3580
+ token: E
3581
3581
  }
3582
3582
  }) => {
3583
- const w = !!ke[t.toLowerCase()];
3584
- if (w && !y)
3583
+ const O = !!ke[t.toLowerCase()];
3584
+ if (O && !y)
3585
3585
  throw new Error("Router is required on calldata for swapIn with GenericContract");
3586
- const O = c || d, S = e && u || O;
3587
- if (!b && !E)
3586
+ const I = c || d, S = e && u || I;
3587
+ if (!b && !w)
3588
3588
  throw new Error("TC Vault is required on calldata");
3589
3589
  if (!_ && !y)
3590
3590
  throw new Error("TC Router is required on calldata");
3591
3591
  if (!S)
3592
3592
  throw new Error("TC Memo is required on calldata");
3593
- if (!R)
3593
+ if (!E)
3594
3594
  throw new Error("Token is required on calldata");
3595
3595
  const P = [
3596
3596
  // v2 contracts don't have tcVault, tcRouter, tcMemo but vault, router, memo
3597
3597
  a(_ || y),
3598
- a(b || E),
3598
+ a(b || w),
3599
3599
  S.replace("{recipientAddress}", n),
3600
- a(R),
3600
+ a(E),
3601
3601
  s
3602
- ], Fe = w ? [a(y), o, p] : [r, p];
3602
+ ], Fe = O ? [a(y), o, p] : [r, p];
3603
3603
  return [...P, ...Fe];
3604
3604
  }, un = ({ chain: e, txHash: t }) => {
3605
3605
  const n = xe[e];
@@ -3690,31 +3690,29 @@ class Pn {
3690
3690
  throw new m("core_wallet_connection_not_found");
3691
3691
  if (!(t ? (p = a == null ? void 0 : a.streamingSwap) == null ? void 0 : p.transaction : a == null ? void 0 : a.transaction))
3692
3692
  throw new m("core_swap_route_transaction_not_found");
3693
- const { isHexString: c, parseUnits: _ } = await import("./index-cf1865cd.js"), { data: b, from: E, to: R, value: w } = a.transaction, O = {
3694
- data: b,
3695
- from: E,
3696
- to: R.toLowerCase(),
3693
+ const { data: c, from: _, to: b, value: w } = a.transaction, E = {
3694
+ data: c,
3695
+ from: _,
3696
+ to: b.toLowerCase(),
3697
3697
  chainId: BigInt(rt[o]),
3698
- value: w ? new N({
3699
- value: c(w) ? w : _(w, "wei").toString(16)
3700
- }).getBaseValue("bigint") : 0n
3698
+ value: w ? BigInt(w) : 0n
3701
3699
  };
3702
- return y.sendTransaction(O, s);
3700
+ return y.sendTransaction(E, s);
3703
3701
  }
3704
3702
  if (et.includes(r)) {
3705
3703
  if (!a.calldata.fromAsset)
3706
3704
  throw new m("core_swap_asset_not_recognized");
3707
- const y = await x.fromString(a.calldata.fromAsset);
3705
+ const y = await N.fromString(a.calldata.fromAsset);
3708
3706
  if (!y)
3709
3707
  throw new m("core_swap_asset_not_recognized");
3710
3708
  const { address: u } = await f(this, V).call(this, y.chain), {
3711
3709
  contract: c,
3712
- calldata: { expiration: _, amountIn: b, memo: E, memoStreamingSwap: R }
3713
- } = a, w = y.add(N.fromBigInt(BigInt(b), y.decimal)), O = t && R || E;
3710
+ calldata: { expiration: _, amountIn: b, memo: w, memoStreamingSwap: E }
3711
+ } = a, O = y.add(D.fromBigInt(BigInt(b), y.decimal)), I = t && E || w;
3714
3712
  return this.deposit({
3715
3713
  expiration: _,
3716
- assetValue: w,
3717
- memo: O,
3714
+ assetValue: O,
3715
+ memo: I,
3718
3716
  feeOptionKey: s,
3719
3717
  router: c,
3720
3718
  recipient: u
@@ -3727,13 +3725,13 @@ class Pn {
3727
3725
  const c = this.connectedWallets[o], _ = this.getAddress(o);
3728
3726
  if (!(c != null && c.sendTransaction) || !_)
3729
3727
  throw new m("core_wallet_connection_not_found");
3730
- const { getProvider: b, toChecksumAddress: E } = await import("@swapkit/toolbox-evm"), R = b(o), w = pn[u.toLowerCase()];
3731
- if (!w)
3728
+ const { getProvider: b, toChecksumAddress: w } = await import("@swapkit/toolbox-evm"), E = b(o), O = pn[u.toLowerCase()];
3729
+ if (!O)
3732
3730
  throw new m("core_swap_contract_not_supported", { contractAddress: u });
3733
- const S = await (await ((d = c.createContract) == null ? void 0 : d.call(c, u, w, R))).getFunction("swapIn").populateTransaction(
3731
+ const S = await (await ((d = c.createContract) == null ? void 0 : d.call(c, u, O, E))).getFunction("swapIn").populateTransaction(
3734
3732
  ...dn({
3735
3733
  streamSwap: t,
3736
- toChecksumAddress: E,
3734
+ toChecksumAddress: w,
3737
3735
  contractAddress: u,
3738
3736
  recipient: n,
3739
3737
  calldata: y
@@ -3752,7 +3750,7 @@ class Pn {
3752
3750
  const a = this.getAddress(t);
3753
3751
  if (!a)
3754
3752
  return null;
3755
- const s = [x.fromChainOrSignature(t)], r = (o = this.connectedChains[t]) == null ? void 0 : o.walletType;
3753
+ const s = [N.fromChainOrSignature(t)], r = (o = this.connectedChains[t]) == null ? void 0 : o.walletType;
3756
3754
  try {
3757
3755
  const d = await ((p = this.getWallet(t)) == null ? void 0 : p.getBalance(a, n));
3758
3756
  return this.connectedChains[t] = {
@@ -3807,10 +3805,9 @@ class Pn {
3807
3805
  funcParams: [
3808
3806
  n,
3809
3807
  u({ chain: r, symbol: o, ticker: p }, r),
3810
- // TODO: (@Towan) Re-Check on that conversion 🙏
3811
- t.getBaseValue("bigint").toString(),
3808
+ t.getBaseValue("string"),
3812
3809
  y.memo,
3813
- s.expiration
3810
+ s.expiration || parseInt(`${((/* @__PURE__ */ new Date()).getTime() + 15 * 60 * 1e3) / 1e3}`)
3814
3811
  ],
3815
3812
  txOverrides: {
3816
3813
  from: y.from,
@@ -3822,8 +3819,8 @@ class Pn {
3822
3819
  return await d.transfer(y);
3823
3820
  }
3824
3821
  } catch (u) {
3825
- const c = ((u == null ? void 0 : u.message) || (u == null ? void 0 : u.toString())).toLowerCase(), _ = c == null ? void 0 : c.includes("insufficient funds"), b = c == null ? void 0 : c.includes("gas"), E = c == null ? void 0 : c.includes("server"), R = _ ? "core_transaction_deposit_insufficient_funds_error" : b ? "core_transaction_deposit_gas_error" : E ? "core_transaction_deposit_server_error" : "core_transaction_deposit_error";
3826
- throw new m(R, u);
3822
+ const c = ((u == null ? void 0 : u.message) || (u == null ? void 0 : u.toString())).toLowerCase(), _ = c == null ? void 0 : c.includes("insufficient funds"), b = c == null ? void 0 : c.includes("gas"), w = c == null ? void 0 : c.includes("server"), E = _ ? "core_transaction_deposit_insufficient_funds_error" : b ? "core_transaction_deposit_gas_error" : w ? "core_transaction_deposit_server_error" : "core_transaction_deposit_error";
3823
+ throw new m(E, u);
3827
3824
  }
3828
3825
  });
3829
3826
  /**
@@ -3839,7 +3836,7 @@ class Pn {
3839
3836
  try {
3840
3837
  a = await f(this, M).call(this, {
3841
3838
  assetValue: t,
3842
- memo: D(h.DEPOSIT, {
3839
+ memo: x(h.DEPOSIT, {
3843
3840
  ...n,
3844
3841
  address: this.getAddress(n.chain)
3845
3842
  })
@@ -3850,7 +3847,7 @@ class Pn {
3850
3847
  try {
3851
3848
  s = await f(this, M).call(this, {
3852
3849
  assetValue: n,
3853
- memo: D(h.DEPOSIT, {
3850
+ memo: x(h.DEPOSIT, {
3854
3851
  ...n,
3855
3852
  address: this.getAddress(i.THORChain)
3856
3853
  })
@@ -3869,32 +3866,32 @@ class Pn {
3869
3866
  isPendingSymmAsset: o,
3870
3867
  mode: p = "sym"
3871
3868
  }) => {
3872
- const [d, ...y] = t.split("."), u = p === "sym", c = (n == null ? void 0 : n.gt(0)) && (u || p === "rune"), _ = (a == null ? void 0 : a.gt(0)) && (u || p === "asset"), b = o || c, E = b ? s || this.getAddress(i.THORChain) : "", R = u || p === "asset" ? r || this.getAddress(d) : "";
3869
+ const [d, ...y] = t.split("."), u = p === "sym", c = (n == null ? void 0 : n.gt(0)) && (u || p === "rune"), _ = (a == null ? void 0 : a.gt(0)) && (u || p === "asset"), b = o || c, w = b ? s || this.getAddress(i.THORChain) : "", E = u || p === "asset" ? r || this.getAddress(d) : "";
3873
3870
  if (!c && !_)
3874
3871
  throw new m("core_transaction_add_liquidity_invalid_params");
3875
- if (b && !E)
3872
+ if (b && !w)
3876
3873
  throw new m("core_transaction_add_liquidity_no_rune_address");
3877
- let w, O;
3874
+ let O, I;
3878
3875
  const S = { chain: d, symbol: y.join(".") };
3879
3876
  if (c && n)
3880
3877
  try {
3881
- w = await f(this, M).call(this, {
3878
+ O = await f(this, M).call(this, {
3882
3879
  assetValue: n,
3883
- memo: D(h.DEPOSIT, { ...S, address: R })
3880
+ memo: x(h.DEPOSIT, { ...S, address: E })
3884
3881
  });
3885
3882
  } catch (P) {
3886
3883
  throw new m("core_transaction_add_liquidity_rune_error", P);
3887
3884
  }
3888
3885
  if (_ && a)
3889
3886
  try {
3890
- O = await f(this, M).call(this, {
3887
+ I = await f(this, M).call(this, {
3891
3888
  assetValue: a,
3892
- memo: D(h.DEPOSIT, { ...S, address: E })
3889
+ memo: x(h.DEPOSIT, { ...S, address: w })
3893
3890
  });
3894
3891
  } catch (P) {
3895
3892
  throw new m("core_transaction_add_liquidity_asset_error", P);
3896
3893
  }
3897
- return { runeTx: w, assetTx: O };
3894
+ return { runeTx: O, assetTx: I };
3898
3895
  });
3899
3896
  T(this, "withdraw", async ({
3900
3897
  memo: t,
@@ -3903,11 +3900,11 @@ class Pn {
3903
3900
  from: s,
3904
3901
  to: r
3905
3902
  }) => {
3906
- const o = r === "rune" ? x.fromChainOrSignature(i.THORChain) : s === "sym" && r === "sym" || s === "rune" || s === "asset" ? void 0 : n;
3903
+ const o = r === "rune" ? N.fromChainOrSignature(i.THORChain) : s === "sym" && r === "sym" || s === "rune" || s === "asset" ? void 0 : n;
3907
3904
  try {
3908
3905
  return await f(this, M).call(this, {
3909
3906
  assetValue: Se(s === "asset" ? n.chain : i.THORChain),
3910
- memo: t || D(h.WITHDRAW, {
3907
+ memo: t || x(h.WITHDRAW, {
3911
3908
  symbol: n.symbol,
3912
3909
  chain: n.chain,
3913
3910
  ticker: n.ticker,
@@ -3926,12 +3923,12 @@ class Pn {
3926
3923
  percent: a,
3927
3924
  type: s
3928
3925
  }) => {
3929
- const r = s === "add" ? h.DEPOSIT : h.WITHDRAW, o = n || D(r, {
3926
+ const r = s === "add" ? h.DEPOSIT : h.WITHDRAW, o = n || x(r, {
3930
3927
  ticker: t.ticker,
3931
3928
  symbol: t.symbol,
3932
3929
  chain: t.chain,
3933
3930
  singleSide: !0,
3934
- basisPoints: a ? Math.max(1e4, Math.round(a * 100)) : void 0
3931
+ basisPoints: a ? Math.min(1e4, Math.round(a * 100)) : void 0
3935
3932
  });
3936
3933
  return f(this, M).call(this, { assetValue: t, memo: o });
3937
3934
  });
@@ -3942,7 +3939,7 @@ class Pn {
3942
3939
  type: s
3943
3940
  }) => f(this, M).call(this, {
3944
3941
  assetValue: t,
3945
- memo: n || D(s === "open" ? h.OPEN_LOAN : h.CLOSE_LOAN, {
3942
+ memo: n || x(s === "open" ? h.OPEN_LOAN : h.CLOSE_LOAN, {
3946
3943
  asset: t.toString(),
3947
3944
  minAmount: a.toString(),
3948
3945
  address: this.getAddress(t.chain)
@@ -3953,7 +3950,7 @@ class Pn {
3953
3950
  assetValue: n,
3954
3951
  address: a
3955
3952
  }) => {
3956
- const s = t === "bond" ? h.BOND : t === "unbond" ? h.UNBOND : h.LEAVE, r = D(s, {
3953
+ const s = t === "bond" ? h.BOND : t === "unbond" ? h.UNBOND : h.LEAVE, r = x(s, {
3957
3954
  address: a,
3958
3955
  unbondAmount: t === "unbond" ? n.getBaseValue("number") : void 0
3959
3956
  });
@@ -3965,7 +3962,7 @@ class Pn {
3965
3962
  T(this, "registerThorname", ({
3966
3963
  assetValue: t,
3967
3964
  ...n
3968
- }) => f(this, Y).call(this, { assetValue: t, memo: D(h.THORNAME_REGISTER, n) }));
3965
+ }) => f(this, Y).call(this, { assetValue: t, memo: x(h.THORNAME_REGISTER, n) }));
3969
3966
  T(this, "extend", ({ wallets: t, config: n, apis: a = {}, rpcUrls: s = {} }) => {
3970
3967
  try {
3971
3968
  t.forEach((r) => {
@@ -4066,23 +4063,23 @@ class Pn {
4066
4063
  this.connectedChains[t] = n, this.connectedWallets[t] = a;
4067
4064
  });
4068
4065
  B(this, K, async ({
4069
- assetValue: { getBaseValue: t, address: n, chain: a, isGasAsset: s, isSynthetic: r },
4070
- type: o = "checkOnly",
4071
- contractAddress: p
4066
+ assetValue: t,
4067
+ type: n = "checkOnly",
4068
+ contractAddress: a
4072
4069
  }) => {
4073
- const d = [i.Ethereum, i.Avalanche, i.BinanceSmartChain].includes(a);
4074
- if (d && s || !d || r)
4070
+ const { address: s, chain: r, isGasAsset: o, isSynthetic: p } = t, d = [i.Ethereum, i.Avalanche, i.BinanceSmartChain].includes(r);
4071
+ if (d && o || !d || p)
4075
4072
  return !0;
4076
- const u = this.connectedWallets[a], c = o === "checkOnly" ? u == null ? void 0 : u.isApproved : u == null ? void 0 : u.approve;
4073
+ const u = this.connectedWallets[r], c = n === "checkOnly" ? u == null ? void 0 : u.isApproved : u == null ? void 0 : u.approve;
4077
4074
  if (!c)
4078
4075
  throw new m("core_wallet_connection_not_found");
4079
- const _ = this.getAddress(a);
4080
- if (!n || !_)
4076
+ const _ = this.getAddress(r);
4077
+ if (!s || !_)
4081
4078
  throw new m("core_approve_asset_address_or_from_not_found");
4082
- const b = p || (await f(this, V).call(this, a)).router;
4079
+ const b = a || (await f(this, V).call(this, r)).router;
4083
4080
  return c({
4084
- amount: t("bigint"),
4085
- assetAddress: n,
4081
+ amount: t.getBaseValue("bigint"),
4082
+ assetAddress: s,
4086
4083
  from: _,
4087
4084
  spenderAddress: b
4088
4085
  });
@@ -4125,7 +4122,7 @@ export {
4125
4122
  ze as AGG_SWAP,
4126
4123
  hn as ApiError,
4127
4124
  q as ApiUrl,
4128
- x as AssetValue,
4125
+ N as AssetValue,
4129
4126
  A as BaseDecimal,
4130
4127
  ye as BigIntArithmetics,
4131
4128
  i as Chain,
@@ -4153,7 +4150,7 @@ export {
4153
4150
  et as SWAP_OUT,
4154
4151
  Pn as SwapKitCore,
4155
4152
  m as SwapKitError,
4156
- N as SwapKitNumber,
4153
+ D as SwapKitNumber,
4157
4154
  Xe as TCAvalancheDepositABI,
4158
4155
  Je as TCBscDepositABI,
4159
4156
  Ye as TCEthereumVaultAbi,
@@ -4175,7 +4172,7 @@ export {
4175
4172
  _t as getDecimal,
4176
4173
  Cn as getEstimatedPoolShare,
4177
4174
  Mn as getLiquiditySlippage,
4178
- D as getMemoFor,
4175
+ x as getMemoFor,
4179
4176
  Se as getMinAmountByChain,
4180
4177
  Ot as getSymmetricPoolShare,
4181
4178
  vn as getSymmetricWithdraw,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "swapkit-oss-team",
3
3
  "dependencies": {
4
4
  "@swapkit/types": "1.0.0-rc.7",
5
- "@swapkit/helpers": "1.0.0-rc.18"
5
+ "@swapkit/helpers": "1.0.0-rc.19"
6
6
  },
7
7
  "description": "SwapKit Lib core",
8
8
  "devDependencies": {
@@ -15,16 +15,16 @@
15
15
  "@internal/config": "0.0.0-internal.0",
16
16
  "@swapkit/api": "1.0.0-rc.7",
17
17
  "@swapkit/tokens": "1.0.0-rc.7",
18
- "@swapkit/toolbox-cosmos": "1.0.0-rc.20",
19
- "@swapkit/toolbox-evm": "1.0.0-rc.20",
20
- "@swapkit/toolbox-utxo": "1.0.0-rc.19"
18
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.21",
19
+ "@swapkit/toolbox-evm": "1.0.0-rc.22",
20
+ "@swapkit/toolbox-utxo": "1.0.0-rc.20"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@swapkit/api": "1.0.0-rc.7",
24
24
  "@swapkit/tokens": "1.0.0-rc.7",
25
- "@swapkit/toolbox-cosmos": "1.0.0-rc.20",
26
- "@swapkit/toolbox-evm": "1.0.0-rc.20",
27
- "@swapkit/toolbox-utxo": "1.0.0-rc.19"
25
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.21",
26
+ "@swapkit/toolbox-evm": "1.0.0-rc.22",
27
+ "@swapkit/toolbox-utxo": "1.0.0-rc.20"
28
28
  },
29
29
  "eslintConfig": {
30
30
  "extends": "../../../internal/eslint-config"
@@ -52,7 +52,7 @@
52
52
  "repository": "https://github.com/thorswap/SwapKit.git",
53
53
  "type": "module",
54
54
  "types": "./dist/index.d.ts",
55
- "version": "1.0.0-rc.24",
55
+ "version": "1.0.0-rc.26",
56
56
  "scripts": {
57
57
  "build": "NODE_OPTIONS=--max_old_space_size=16384 vite build",
58
58
  "clean": "rm -rf dist vite.config.ts.* .turbo node_modules",
@@ -94,7 +94,6 @@ export class SwapKitCore<T = ''> {
94
94
  const transaction = streamSwap ? route?.streamingSwap?.transaction : route?.transaction;
95
95
  if (!transaction) throw new SwapKitError('core_swap_route_transaction_not_found');
96
96
 
97
- const { isHexString, parseUnits } = await import('ethers');
98
97
  const { data, from, to, value } = route.transaction;
99
98
 
100
99
  const params = {
@@ -102,11 +101,7 @@ export class SwapKitCore<T = ''> {
102
101
  from,
103
102
  to: to.toLowerCase(),
104
103
  chainId: BigInt(ChainToChainId[evmChain]),
105
- value: value
106
- ? new SwapKitNumber({
107
- value: !isHexString(value) ? parseUnits(value, 'wei').toString(16) : value,
108
- }).getBaseValue('bigint')
109
- : 0n,
104
+ value: value ? BigInt(value) : 0n,
110
105
  };
111
106
 
112
107
  return walletMethods.sendTransaction(params, feeOptionKey) as Promise<string>;
@@ -258,10 +253,9 @@ export class SwapKitCore<T = ''> {
258
253
  funcParams: [
259
254
  recipient,
260
255
  getChecksumAddressFromAsset({ chain, symbol, ticker }, chain),
261
- // TODO: (@Towan) Re-Check on that conversion 🙏
262
- assetValue.getBaseValue('bigint').toString(),
256
+ assetValue.getBaseValue('string'),
263
257
  params.memo,
264
- rest.expiration,
258
+ rest.expiration || parseInt(`${(new Date().getTime() + 15 * 60 * 1000) / 1000}`),
265
259
  ],
266
260
  txOverrides: {
267
261
  from: params.from,
@@ -455,7 +449,7 @@ export class SwapKitCore<T = ''> {
455
449
  symbol: assetValue.symbol,
456
450
  chain: assetValue.chain,
457
451
  singleSide: true,
458
- basisPoints: percent ? Math.max(10000, Math.round(percent * 100)) : undefined,
452
+ basisPoints: percent ? Math.min(10000, Math.round(percent * 100)) : undefined,
459
453
  });
460
454
 
461
455
  return this.#depositToPool({ assetValue, memo: memoString });
@@ -627,7 +621,7 @@ export class SwapKitCore<T = ''> {
627
621
  };
628
622
 
629
623
  #approve = async <T = string>({
630
- assetValue: { getBaseValue, address, chain, isGasAsset, isSynthetic },
624
+ assetValue,
631
625
  type = 'checkOnly',
632
626
  contractAddress,
633
627
  }: {
@@ -635,6 +629,7 @@ export class SwapKitCore<T = ''> {
635
629
  type?: 'checkOnly' | 'approve';
636
630
  contractAddress?: string;
637
631
  }) => {
632
+ const { address, chain, isGasAsset, isSynthetic } = assetValue;
638
633
  const isEVMChain = [Chain.Ethereum, Chain.Avalanche, Chain.BinanceSmartChain].includes(chain);
639
634
  const isNativeEVM = isEVMChain && isGasAsset;
640
635
 
@@ -653,7 +648,7 @@ export class SwapKitCore<T = ''> {
653
648
  contractAddress || ((await this.#getInboundDataByChain(chain)).router as string);
654
649
 
655
650
  return walletAction({
656
- amount: getBaseValue('bigint'),
651
+ amount: assetValue.getBaseValue('bigint'),
657
652
  assetAddress: address,
658
653
  from,
659
654
  spenderAddress,
@@ -1 +0,0 @@
1
- "use strict";var nt=Object.defineProperty;var st=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var j=(e,t,r)=>(st(e,typeof t!="symbol"?t+"":t,r),r),D=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var s=(e,t,r)=>(D(e,t,"read from private field"),r?r.call(e):t.get(e)),b=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},M=(e,t,r,i)=>(D(e,t,"write to private field"),i?i.call(e,r):t.set(e,r),r);var u=(e,t,r)=>(D(e,t,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q="6.7.1";function ot(e,t,r){const i=t.split("|").map(o=>o.trim());for(let o=0;o<i.length;o++)switch(t){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeof e===t)return}const n=new Error(`invalid value for type ${t}`);throw n.code="INVALID_ARGUMENT",n.argument=`value.${r}`,n.value=e,n}function K(e,t,r){for(let i in t){let n=t[i];const o=r?r[i]:null;o&&ot(n,o,i),Object.defineProperty(e,i,{enumerable:!0,value:n,writable:!1})}}function x(e){if(e==null)return"null";if(Array.isArray(e))return"[ "+e.map(x).join(", ")+" ]";if(e instanceof Uint8Array){const t="0123456789abcdef";let r="0x";for(let i=0;i<e.length;i++)r+=t[e[i]>>4],r+=t[e[i]&15];return r}if(typeof e=="object"&&typeof e.toJSON=="function")return x(e.toJSON());switch(typeof e){case"boolean":case"symbol":return e.toString();case"bigint":return BigInt(e).toString();case"number":return e.toString();case"string":return JSON.stringify(e);case"object":{const t=Object.keys(e);return t.sort(),"{ "+t.map(r=>`${x(r)}: ${x(e[r])}`).join(", ")+" }"}}return"[ COULD NOT SERIALIZE ]"}function W(e,t,r){{const n=[];if(r){if("message"in r||"code"in r||"name"in r)throw new Error(`value will overwrite populated values: ${x(r)}`);for(const o in r){const l=r[o];n.push(o+"="+x(l))}}n.push(`code=${t}`),n.push(`version=${Q}`),n.length&&(e+=" ("+n.join(", ")+")")}let i;switch(t){case"INVALID_ARGUMENT":i=new TypeError(e);break;case"NUMERIC_FAULT":case"BUFFER_OVERRUN":i=new RangeError(e);break;default:i=new Error(e)}return K(i,{code:t}),r&&Object.assign(i,r),i}function g(e,t,r,i){if(!e)throw W(t,r,i)}function c(e,t,r,i){g(e,t,"INVALID_ARGUMENT",{argument:r,value:i})}["NFD","NFC","NFKD","NFKC"].reduce((e,t)=>{try{if("test".normalize(t)!=="test")throw new Error("bad");if(t==="NFD"){const r=String.fromCharCode(233).normalize("NFD"),i=String.fromCharCode(101,769);if(r!==i)throw new Error("broken")}e.push(t)}catch{}return e},[]);function Y(e,t,r){if(r==null&&(r=""),e!==t){let i=r,n="new";r&&(i+=".",n+=" "+r),g(!1,`private constructor; use ${i}from* methods`,"UNSUPPORTED_OPERATION",{operation:n})}}function ft(e,t,r){if(e instanceof Uint8Array)return r?new Uint8Array(e):e;if(typeof e=="string"&&e.match(/^0x([0-9a-f][0-9a-f])*$/i)){const i=new Uint8Array((e.length-2)/2);let n=2;for(let o=0;o<i.length;o++)i[o]=parseInt(e.substring(n,n+2),16),n+=2;return i}c(!1,"invalid BytesLike value",t||"value",e)}function tt(e,t){return ft(e,t,!1)}function ut(e,t){return!(typeof e!="string"||!e.match(/^0x[0-9A-Fa-f]*$/)||typeof t=="number"&&e.length!==2+2*t||t===!0&&e.length%2!==0)}const et=BigInt(0),E=BigInt(1),S=9007199254740991;function k(e,t){const r=q(e,"value"),i=BigInt(T(t,"width"));if(g(r>>i===et,"overflow","NUMERIC_FAULT",{operation:"fromTwos",fault:"overflow",value:e}),r>>i-E){const n=(E<<i)-E;return-((~r&n)+E)}return r}function z(e,t){const r=q(e,"value"),i=BigInt(T(t,"bits"));return r&(E<<i)-E}function V(e,t){switch(typeof e){case"bigint":return e;case"number":return c(Number.isInteger(e),"underflow",t||"value",e),c(e>=-S&&e<=S,"overflow",t||"value",e),BigInt(e);case"string":try{if(e==="")throw new Error("empty string");return e[0]==="-"&&e[1]!=="-"?-BigInt(e.substring(1)):BigInt(e)}catch(r){c(!1,`invalid BigNumberish string: ${r.message}`,t||"value",e)}}c(!1,"invalid BigNumberish value",t||"value",e)}function q(e,t){const r=V(e,t);return g(r>=et,"unsigned value cannot be negative","NUMERIC_FAULT",{fault:"overflow",operation:"getUint",value:e}),r}const X="0123456789abcdef";function rt(e){if(e instanceof Uint8Array){let t="0x0";for(const r of e)t+=X[r>>4],t+=X[r&15];return BigInt(t)}return V(e)}function T(e,t){switch(typeof e){case"bigint":return c(e>=-S&&e<=S,"overflow",t||"value",e),Number(e);case"number":return c(Number.isInteger(e),"underflow",t||"value",e),c(e>=-S&&e<=S,"overflow",t||"value",e),e;case"string":try{if(e==="")throw new Error("empty string");return T(BigInt(e),t)}catch(r){c(!1,`invalid numeric string: ${r.message}`,t||"value",e)}}c(!1,"invalid numeric value",t||"value",e)}const ct=BigInt(-1),d=BigInt(0),F=BigInt(1),lt=BigInt(5),B={};let A="0000";for(;A.length<80;)A+=A;function y(e){let t=A;for(;t.length<e;)t+=t;return BigInt("1"+t.substring(0,e))}function C(e,t,r){const i=BigInt(t.width);if(t.signed){const n=F<<i-F;g(r==null||e>=-n&&e<n,"overflow","NUMERIC_FAULT",{operation:r,fault:"overflow",value:e}),e>d?e=k(z(e,i),i):e=-k(z(-e,i),i)}else{const n=F<<i;g(r==null||e>=0&&e<n,"overflow","NUMERIC_FAULT",{operation:r,fault:"overflow",value:e}),e=(e%n+n)%n&n-F}return e}function P(e){typeof e=="number"&&(e=`fixed128x${e}`);let t=!0,r=128,i=18;if(typeof e=="string"){if(e!=="fixed")if(e==="ufixed")t=!1;else{const o=e.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);c(o,"invalid fixed format","format",e),t=o[1]!=="u",r=parseInt(o[2]),i=parseInt(o[3])}}else if(e){const o=e,l=(h,R,it)=>o[h]==null?it:(c(typeof o[h]===R,"invalid fixed format ("+h+" not "+R+")","format."+h,o[h]),o[h]);t=l("signed","boolean",t),r=l("width","number",r),i=l("decimals","number",i)}c(r%8===0,"invalid FixedNumber width (not byte aligned)","format.width",r),c(i<=80,"invalid FixedNumber decimals (too large)","format.decimals",i);const n=(t?"":"u")+"fixed"+String(r)+"x"+String(i);return{signed:t,width:r,decimals:i,name:n}}function at(e,t){let r="";e<d&&(r="-",e*=ct);let i=e.toString();if(t===0)return r+i;for(;i.length<=t;)i=A+i;const n=i.length-t;for(i=i.substring(0,n)+"."+i.substring(n);i[0]==="0"&&i[1]!==".";)i=i.substring(1);for(;i[i.length-1]==="0"&&i[i.length-2]!==".";)i=i.substring(0,i.length-1);return r+i}var m,f,a,N,U,w,p,$,G,L,H,v,J,_,Z;const I=class I{constructor(t,r,i){b(this,N);b(this,w);b(this,$);b(this,L);b(this,v);b(this,_);j(this,"format");b(this,m,void 0);b(this,f,void 0);b(this,a,void 0);j(this,"_value");Y(t,B,"FixedNumber"),M(this,f,r),M(this,m,i);const n=at(r,i.decimals);K(this,{format:i.name,_value:n}),M(this,a,y(i.decimals))}get signed(){return s(this,m).signed}get width(){return s(this,m).width}get decimals(){return s(this,m).decimals}get value(){return s(this,f)}addUnsafe(t){return u(this,$,G).call(this,t)}add(t){return u(this,$,G).call(this,t,"add")}subUnsafe(t){return u(this,L,H).call(this,t)}sub(t){return u(this,L,H).call(this,t,"sub")}mulUnsafe(t){return u(this,v,J).call(this,t)}mul(t){return u(this,v,J).call(this,t,"mul")}mulSignal(t){u(this,N,U).call(this,t);const r=s(this,f)*s(t,f);return g(r%s(this,a)===d,"precision lost during signalling mul","NUMERIC_FAULT",{operation:"mulSignal",fault:"underflow",value:this}),u(this,w,p).call(this,r/s(this,a),"mulSignal")}divUnsafe(t){return u(this,_,Z).call(this,t)}div(t){return u(this,_,Z).call(this,t,"div")}divSignal(t){g(s(t,f)!==d,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),u(this,N,U).call(this,t);const r=s(this,f)*s(this,a);return g(r%s(t,f)===d,"precision lost during signalling div","NUMERIC_FAULT",{operation:"divSignal",fault:"underflow",value:this}),u(this,w,p).call(this,r/s(t,f),"divSignal")}cmp(t){let r=this.value,i=t.value;const n=this.decimals-t.decimals;return n>0?i*=y(n):n<0&&(r*=y(-n)),r<i?-1:r>i?1:0}eq(t){return this.cmp(t)===0}lt(t){return this.cmp(t)<0}lte(t){return this.cmp(t)<=0}gt(t){return this.cmp(t)>0}gte(t){return this.cmp(t)>=0}floor(){let t=s(this,f);return s(this,f)<d&&(t-=s(this,a)-F),t=s(this,f)/s(this,a)*s(this,a),u(this,w,p).call(this,t,"floor")}ceiling(){let t=s(this,f);return s(this,f)>d&&(t+=s(this,a)-F),t=s(this,f)/s(this,a)*s(this,a),u(this,w,p).call(this,t,"ceiling")}round(t){if(t==null&&(t=0),t>=this.decimals)return this;const r=this.decimals-t,i=lt*y(r-1);let n=this.value+i;const o=y(r);return n=n/o*o,C(n,s(this,m),"round"),new I(B,n,s(this,m))}isZero(){return s(this,f)===d}isNegative(){return s(this,f)<d}toString(){return this._value}toUnsafeFloat(){return parseFloat(this.toString())}toFormat(t){return I.fromString(this.toString(),t)}static fromValue(t,r,i){const n=r==null?0:T(r),o=P(i);let l=V(t,"value");const h=n-o.decimals;if(h>0){const R=y(h);g(l%R===d,"value loses precision for format","NUMERIC_FAULT",{operation:"fromValue",fault:"underflow",value:t}),l/=R}else h<0&&(l*=y(-h));return C(l,o,"fromValue"),new I(B,l,o)}static fromString(t,r){const i=t.match(/^(-?)([0-9]*)\.?([0-9]*)$/);c(i&&i[2].length+i[3].length>0,"invalid FixedNumber string value","value",t);const n=P(r);let o=i[2]||"0",l=i[3]||"";for(;l.length<n.decimals;)l+=A;g(l.substring(n.decimals).match(/^0*$/),"too many decimals for format","NUMERIC_FAULT",{operation:"fromString",fault:"underflow",value:t}),l=l.substring(0,n.decimals);const h=BigInt(i[1]+o+l);return C(h,n,"fromString"),new I(B,h,n)}static fromBytes(t,r){let i=rt(tt(t,"value"));const n=P(r);return n.signed&&(i=k(i,n.width)),C(i,n,"fromBytes"),new I(B,i,n)}};m=new WeakMap,f=new WeakMap,a=new WeakMap,N=new WeakSet,U=function(t){c(this.format===t.format,"incompatible format; use fixedNumber.toFormat","other",t)},w=new WeakSet,p=function(t,r){return t=C(t,s(this,m),r),new I(B,t,s(this,m))},$=new WeakSet,G=function(t,r){return u(this,N,U).call(this,t),u(this,w,p).call(this,s(this,f)+s(t,f),r)},L=new WeakSet,H=function(t,r){return u(this,N,U).call(this,t),u(this,w,p).call(this,s(this,f)-s(t,f),r)},v=new WeakSet,J=function(t,r){return u(this,N,U).call(this,t),u(this,w,p).call(this,s(this,f)*s(t,f)/s(this,a),r)},_=new WeakSet,Z=function(t,r){return g(s(t,f)!==d,"division by zero","NUMERIC_FAULT",{operation:"div",fault:"divide-by-zero",value:this}),u(this,N,U).call(this,t),u(this,w,p).call(this,s(this,f)*s(this,a)/s(t,f),r)};let O=I;const ht=["wei","kwei","mwei","gwei","szabo","finney","ether"];function gt(e,t){c(typeof e=="string","value must be a string","value",e);let r=18;if(typeof t=="string"){const i=ht.indexOf(t);c(i>=0,"invalid unit","unit",t),r=3*i}else t!=null&&(r=T(t,"unit"));return O.fromString(e,{decimals:r,width:512}).value}exports.FixedNumber=O;exports.assert=g;exports.assertArgument=c;exports.assertPrivate=Y;exports.defineProperties=K;exports.fromTwos=k;exports.getBigInt=V;exports.getBytes=tt;exports.getNumber=T;exports.getUint=q;exports.isHexString=ut;exports.makeError=W;exports.mask=z;exports.parseUnits=gt;exports.toBigInt=rt;exports.version=Q;