@swapkit/core 1.0.0-rc.56 → 1.0.0-rc.58
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.cjs +2 -2
- package/dist/index.es.js +144 -153
- package/package.json +14 -14
package/dist/index.es.js
CHANGED
|
@@ -690,19 +690,19 @@ let wn = class Ce extends Error {
|
|
|
690
690
|
code: s,
|
|
691
691
|
message: r,
|
|
692
692
|
type: o,
|
|
693
|
-
options: { shouldLog: p, shouldThrow: d, shouldTrace:
|
|
693
|
+
options: { shouldLog: p, shouldThrow: d, shouldTrace: u } = {
|
|
694
694
|
shouldLog: !0,
|
|
695
695
|
shouldThrow: !0,
|
|
696
696
|
shouldTrace: !0
|
|
697
697
|
},
|
|
698
|
-
displayMessageParams:
|
|
698
|
+
displayMessageParams: l
|
|
699
699
|
}) {
|
|
700
|
-
const
|
|
701
|
-
super(
|
|
700
|
+
const m = r || re(s, l || []) || "";
|
|
701
|
+
super(m), C(this, "status"), C(this, "revision"), C(this, "type"), C(this, "module"), C(this, "code"), C(this, "message"), C(this, "display"), C(this, "stack"), C(this, "options"), C(this, "displayMessageParams"), this.status = t, this.revision = n || "NO_REVISION", this.module = a, this.message = m, this.display = re(s, l || []), this.code = s, this.type = o || ve.UNHANDLED_ERROR, this.options = {
|
|
702
702
|
shouldLog: p || !0,
|
|
703
|
-
shouldTrace:
|
|
703
|
+
shouldTrace: u || !0,
|
|
704
704
|
shouldThrow: d || !1
|
|
705
|
-
}, this.displayMessageParams =
|
|
705
|
+
}, this.displayMessageParams = l || [], this.options.shouldTrace && Error.captureStackTrace(this);
|
|
706
706
|
}
|
|
707
707
|
static fromErrorInfo(t) {
|
|
708
708
|
return new Ce(t);
|
|
@@ -839,7 +839,7 @@ const ae = Object.values(i), ot = Object.keys(i), fe = ae.reduce(
|
|
|
839
839
|
var ut = /* @__PURE__ */ ((e) => (e[e.NoError = 36864] = "NoError", e))(ut || {}), h = /* @__PURE__ */ ((e) => (e.BOND = "BOND", e.DEPOSIT = "+", e.LEAVE = "LEAVE", e.THORNAME_REGISTER = "~", e.UNBOND = "UNBOND", e.WITHDRAW = "-", e.OPEN_LOAN = "$+", e.CLOSE_LOAN = "$-", e))(h || {}), F = /* @__PURE__ */ ((e) => (e.Average = "average", e.Fast = "fast", e.Fastest = "fastest", e))(F || {}), lt = /* @__PURE__ */ ((e) => (e.KEYSTORE = "KEYSTORE", e.XDEFI = "XDEFI", e.METAMASK = "METAMASK", e.COINBASE_WEB = "COINBASE_WEB", e.TREZOR = "TREZOR", e.TRUSTWALLET_WEB = "TRUSTWALLET_WEB", e.LEDGER = "LEDGER", e.KEPLR = "KEPLR", e.OKX = "OKX", e.BRAVE = "BRAVE", e.WALLETCONNECT = "WALLETCONNECT", e))(lt || {}), yt = Object.defineProperty, ct = (e, t, n) => t in e ? yt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, I = (e, t, n) => (ct(e, typeof t != "symbol" ? t + "" : t, n), n), mt = (e, t, n) => {
|
|
840
840
|
if (!t.has(e))
|
|
841
841
|
throw TypeError("Cannot " + n);
|
|
842
|
-
},
|
|
842
|
+
}, H = (e, t, n) => {
|
|
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);
|
|
@@ -992,15 +992,15 @@ const Tt = "0x313ce567", xe = async ({ chain: e, to: t }) => {
|
|
|
992
992
|
poolUnits: t,
|
|
993
993
|
runeDepth: n
|
|
994
994
|
}) => {
|
|
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),
|
|
996
|
-
return o.mul(p.sub(d).add(
|
|
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), u = a.mul(a), l = s.mul(s).mul(s);
|
|
996
|
+
return o.mul(p.sub(d).add(u)).div(l);
|
|
997
997
|
}, St = ({
|
|
998
998
|
liquidityUnits: e,
|
|
999
999
|
poolUnits: t,
|
|
1000
1000
|
assetDepth: n
|
|
1001
1001
|
}) => {
|
|
1002
|
-
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),
|
|
1003
|
-
return
|
|
1002
|
+
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), u = a.mul(a), l = o.mul(p.sub(d).add(u)), m = s.mul(s).mul(s);
|
|
1003
|
+
return l.div(m);
|
|
1004
1004
|
}, Cn = ({
|
|
1005
1005
|
percent: e,
|
|
1006
1006
|
runeDepth: t,
|
|
@@ -1037,7 +1037,7 @@ const Tt = "0x313ce567", xe = async ({ chain: e, to: t }) => {
|
|
|
1037
1037
|
runeAmount: s,
|
|
1038
1038
|
assetAmount: r
|
|
1039
1039
|
}) => {
|
|
1040
|
-
const o = new x({ value: e, decimal: 8 }), p = new x({ value: n, decimal: 8 }), d = new x({ value: t, decimal: 8 }),
|
|
1040
|
+
const o = new x({ value: e, decimal: 8 }), p = new x({ value: n, decimal: 8 }), d = new x({ value: t, decimal: 8 }), u = new x({ value: s, decimal: 8 }), l = new x({ value: r, decimal: 8 }), m = u.mul(p), _ = l.mul(o), b = u.mul(l), A = o.mul(p), E = d.mul(m.add(_.add(b.mul(2)))), O = m.add(_.add(A.mul(2))), S = E.div(O), D = g(a).add(S);
|
|
1041
1041
|
if (S.getBaseValue("number") === 0)
|
|
1042
1042
|
return D.div(d).getBaseValue("number");
|
|
1043
1043
|
const ie = d.add(D);
|
|
@@ -1050,8 +1050,8 @@ const Tt = "0x313ce567", xe = async ({ chain: e, to: t }) => {
|
|
|
1050
1050
|
}) => {
|
|
1051
1051
|
if (e === "0" || t === "0" || n === "0" || a === "0")
|
|
1052
1052
|
return 0;
|
|
1053
|
-
const s = g(n), r = g(a), o = g(t), p = g(e), d = o.mul(s).sub(r.mul(p)),
|
|
1054
|
-
return Math.abs(d.div(
|
|
1053
|
+
const s = g(n), r = g(a), o = g(t), p = g(e), d = o.mul(s).sub(r.mul(p)), u = r.mul(p).add(s.mul(r));
|
|
1054
|
+
return Math.abs(d.div(u).getBaseValue("number"));
|
|
1055
1055
|
}, vt = ({
|
|
1056
1056
|
symbol: e,
|
|
1057
1057
|
ticker: t,
|
|
@@ -1076,8 +1076,8 @@ const Tt = "0x313ce567", xe = async ({ chain: e, to: t }) => {
|
|
|
1076
1076
|
return r ? `${e}:${n}/${a}::t:0` : `${e}:${n}.${a}:${s || ""}:t:0`;
|
|
1077
1077
|
}
|
|
1078
1078
|
case h.WITHDRAW: {
|
|
1079
|
-
const { chain: n, ticker: a, symbol: s, basisPoints: r, targetAssetString: o, singleSide: p } = t, d = !p && o ? `:${o}` : "",
|
|
1080
|
-
return `${e}:${n}${p ? "/" : "."}${
|
|
1079
|
+
const { chain: n, ticker: a, symbol: s, basisPoints: r, targetAssetString: o, singleSide: p } = t, d = !p && o ? `:${o}` : "", u = vt({ chain: n, symbol: s, ticker: a });
|
|
1080
|
+
return `${e}:${n}${p ? "/" : "."}${u}:${r}${d}`;
|
|
1081
1081
|
}
|
|
1082
1082
|
case h.OPEN_LOAN:
|
|
1083
1083
|
case h.CLOSE_LOAN: {
|
|
@@ -1201,7 +1201,7 @@ const J = (e) => e !== null && typeof e == "object", X = (...e) => {
|
|
|
1201
1201
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
1202
1202
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
1203
1203
|
delay: (e) => 0.3 * 2 ** (e - 1) * 1e3
|
|
1204
|
-
},
|
|
1204
|
+
}, $t = (e = {}) => {
|
|
1205
1205
|
if (typeof e == "number")
|
|
1206
1206
|
return {
|
|
1207
1207
|
...Ee,
|
|
@@ -1217,7 +1217,7 @@ const J = (e) => e !== null && typeof e == "object", X = (...e) => {
|
|
|
1217
1217
|
afterStatusCodes: Ue
|
|
1218
1218
|
};
|
|
1219
1219
|
};
|
|
1220
|
-
async function
|
|
1220
|
+
async function Ht(e, t, n, a) {
|
|
1221
1221
|
return new Promise((s, r) => {
|
|
1222
1222
|
const o = setTimeout(() => {
|
|
1223
1223
|
n && n.abort(), r(new Pe(e));
|
|
@@ -1325,7 +1325,7 @@ class Z {
|
|
|
1325
1325
|
method: Lt(n.method ?? this._input.method),
|
|
1326
1326
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
1327
1327
|
prefixUrl: String(n.prefixUrl || ""),
|
|
1328
|
-
retry:
|
|
1328
|
+
retry: $t(n.retry),
|
|
1329
1329
|
throwHttpErrors: n.throwHttpErrors !== !1,
|
|
1330
1330
|
timeout: n.timeout ?? 1e4,
|
|
1331
1331
|
fetch: n.fetch ?? globalThis.fetch.bind(globalThis)
|
|
@@ -1403,7 +1403,7 @@ class Z {
|
|
|
1403
1403
|
return a;
|
|
1404
1404
|
}
|
|
1405
1405
|
const t = Ft(this.request, this._options);
|
|
1406
|
-
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) :
|
|
1406
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Ht(this.request.clone(), t, this.abortController, this._options);
|
|
1407
1407
|
}
|
|
1408
1408
|
/* istanbul ignore next */
|
|
1409
1409
|
_stream(t, n) {
|
|
@@ -1418,17 +1418,17 @@ class Z {
|
|
|
1418
1418
|
const o = t.body.getReader();
|
|
1419
1419
|
n && n({ percent: 0, transferredBytes: 0, totalBytes: a }, new Uint8Array());
|
|
1420
1420
|
async function p() {
|
|
1421
|
-
const { done: d, value:
|
|
1421
|
+
const { done: d, value: u } = await o.read();
|
|
1422
1422
|
if (d) {
|
|
1423
1423
|
r.close();
|
|
1424
1424
|
return;
|
|
1425
1425
|
}
|
|
1426
1426
|
if (n) {
|
|
1427
|
-
s +=
|
|
1428
|
-
const
|
|
1429
|
-
n({ percent:
|
|
1427
|
+
s += u.byteLength;
|
|
1428
|
+
const l = a === 0 ? 0 : s / a;
|
|
1429
|
+
n({ percent: l, transferredBytes: s, totalBytes: a }, u);
|
|
1430
1430
|
}
|
|
1431
|
-
r.enqueue(
|
|
1431
|
+
r.enqueue(u), await p();
|
|
1432
1432
|
}
|
|
1433
1433
|
await p();
|
|
1434
1434
|
}
|
|
@@ -1475,15 +1475,15 @@ function se({
|
|
|
1475
1475
|
""
|
|
1476
1476
|
);
|
|
1477
1477
|
}
|
|
1478
|
-
var U, k, B,
|
|
1479
|
-
const Kt = class
|
|
1478
|
+
var U, k, B, $, le, $e, Q, pe, ee, ye;
|
|
1479
|
+
const Kt = class He {
|
|
1480
1480
|
constructor(t) {
|
|
1481
|
-
|
|
1481
|
+
H(this, U), H(this, B), H(this, le), H(this, Q), H(this, ee), I(this, "decimalMultiplier", 10n ** 8n), I(this, "bigIntValue", 0n), I(this, "decimal");
|
|
1482
1482
|
const n = me(t), a = typeof t == "object";
|
|
1483
|
-
this.decimal = a ? t.decimal : void 0, this.decimalMultiplier = a && "decimalMultiplier" in t ? t.decimalMultiplier : L(Math.max(ke(te(n)), this.decimal || 0)), R(this, le,
|
|
1483
|
+
this.decimal = a ? t.decimal : void 0, this.decimalMultiplier = a && "decimalMultiplier" in t ? t.decimalMultiplier : L(Math.max(ke(te(n)), this.decimal || 0)), R(this, le, $e).call(this, n);
|
|
1484
1484
|
}
|
|
1485
1485
|
static fromBigInt(t, n) {
|
|
1486
|
-
return new
|
|
1486
|
+
return new He({
|
|
1487
1487
|
decimal: n,
|
|
1488
1488
|
value: se({ value: t, bigIntDecimal: n, decimal: n })
|
|
1489
1489
|
});
|
|
@@ -1514,19 +1514,19 @@ const Kt = class $e {
|
|
|
1514
1514
|
return R(this, U, k).call(this, "div", ...t);
|
|
1515
1515
|
}
|
|
1516
1516
|
gt(t) {
|
|
1517
|
-
return R(this, B,
|
|
1517
|
+
return R(this, B, $).call(this, "gt", t);
|
|
1518
1518
|
}
|
|
1519
1519
|
gte(t) {
|
|
1520
|
-
return R(this, B,
|
|
1520
|
+
return R(this, B, $).call(this, "gte", t);
|
|
1521
1521
|
}
|
|
1522
1522
|
lt(t) {
|
|
1523
|
-
return R(this, B,
|
|
1523
|
+
return R(this, B, $).call(this, "lt", t);
|
|
1524
1524
|
}
|
|
1525
1525
|
lte(t) {
|
|
1526
|
-
return R(this, B,
|
|
1526
|
+
return R(this, B, $).call(this, "lte", t);
|
|
1527
1527
|
}
|
|
1528
1528
|
eqValue(t) {
|
|
1529
|
-
return R(this, B,
|
|
1529
|
+
return R(this, B, $).call(this, "eqValue", t);
|
|
1530
1530
|
}
|
|
1531
1531
|
// @ts-expect-error False positive
|
|
1532
1532
|
getValue(t) {
|
|
@@ -1601,36 +1601,36 @@ const Kt = class $e {
|
|
|
1601
1601
|
decimalSeparator: s = ".",
|
|
1602
1602
|
thousandSeparator: r = ","
|
|
1603
1603
|
} = {}) {
|
|
1604
|
-
const o = this.getValue("number"), [p, d = ""] = o.toFixed(6).split("."),
|
|
1605
|
-
return `${n === "start" ? t : ""}${
|
|
1604
|
+
const o = this.getValue("number"), [p, d = ""] = o.toFixed(6).split("."), u = p.replace(/\B(?=(\d{3})+(?!\d))/g, r), l = !p && !d ? "0.00" : p === "0" ? `${parseFloat(`0.${d}`)}`.replace(".", s) : `${u}${parseInt(d) ? `${s}${d.slice(0, a)}` : ""}`;
|
|
1605
|
+
return `${n === "start" ? t : ""}${l}${n === "end" ? t : ""}`;
|
|
1606
1606
|
}
|
|
1607
1607
|
formatBigIntToSafeValue(t, n) {
|
|
1608
1608
|
const a = n || this.decimal || W, s = Math.max(
|
|
1609
1609
|
a,
|
|
1610
1610
|
G(this.decimalMultiplier)
|
|
1611
|
-
), r = t < 0n, o = t.toString().substring(r ? 1 : 0), p = s - (o.length - 1), d = p > 0 ? "0".repeat(p) + o : o,
|
|
1612
|
-
let
|
|
1613
|
-
return parseInt(
|
|
1611
|
+
), r = t < 0n, o = t.toString().substring(r ? 1 : 0), p = s - (o.length - 1), d = p > 0 ? "0".repeat(p) + o : o, u = d.length - s;
|
|
1612
|
+
let l = d.slice(-s);
|
|
1613
|
+
return parseInt(l[a]) >= 5 ? l = `${l.substring(0, a - 1)}${(parseInt(l[a - 1]) + 1).toString()}` : l = l.substring(0, a), `${r ? "-" : ""}${d.slice(
|
|
1614
1614
|
0,
|
|
1615
|
-
|
|
1616
|
-
)}.${
|
|
1615
|
+
u
|
|
1616
|
+
)}.${l}`.replace(/\.?0*$/, "");
|
|
1617
1617
|
}
|
|
1618
1618
|
};
|
|
1619
1619
|
U = /* @__PURE__ */ new WeakSet(), k = function(e, ...t) {
|
|
1620
1620
|
const n = R(this, Q, pe).call(this, this, ...t), a = Math.max(n, G(this.decimalMultiplier)), s = L(a), r = t.reduce(
|
|
1621
1621
|
(p, d) => {
|
|
1622
|
-
const
|
|
1622
|
+
const u = this.getBigIntValue(d, a);
|
|
1623
1623
|
switch (e) {
|
|
1624
1624
|
case "add":
|
|
1625
|
-
return p +
|
|
1625
|
+
return p + u;
|
|
1626
1626
|
case "sub":
|
|
1627
|
-
return p -
|
|
1627
|
+
return p - u;
|
|
1628
1628
|
case "mul":
|
|
1629
|
-
return p *
|
|
1629
|
+
return p * u / s;
|
|
1630
1630
|
case "div": {
|
|
1631
|
-
if (
|
|
1631
|
+
if (u === 0n)
|
|
1632
1632
|
throw new RangeError("Division by zero");
|
|
1633
|
-
return p * s /
|
|
1633
|
+
return p * s / u;
|
|
1634
1634
|
}
|
|
1635
1635
|
default:
|
|
1636
1636
|
return p;
|
|
@@ -1649,7 +1649,7 @@ U = /* @__PURE__ */ new WeakSet(), k = function(e, ...t) {
|
|
|
1649
1649
|
value: o,
|
|
1650
1650
|
identifier: this.toString()
|
|
1651
1651
|
});
|
|
1652
|
-
}, B = /* @__PURE__ */ new WeakSet(),
|
|
1652
|
+
}, B = /* @__PURE__ */ new WeakSet(), $ = function(e, ...t) {
|
|
1653
1653
|
const n = R(this, Q, pe).call(this, this, ...t), a = this.getBigIntValue(t[0], n), s = this.getBigIntValue(this, n);
|
|
1654
1654
|
switch (e) {
|
|
1655
1655
|
case "gt":
|
|
@@ -1663,7 +1663,7 @@ U = /* @__PURE__ */ new WeakSet(), k = function(e, ...t) {
|
|
|
1663
1663
|
case "eqValue":
|
|
1664
1664
|
return s === a;
|
|
1665
1665
|
}
|
|
1666
|
-
}, le = /* @__PURE__ */ new WeakSet(),
|
|
1666
|
+
}, le = /* @__PURE__ */ new WeakSet(), $e = function(e) {
|
|
1667
1667
|
const t = te(e) || "0";
|
|
1668
1668
|
this.bigIntValue = R(this, ee, ye).call(this, t);
|
|
1669
1669
|
}, Q = /* @__PURE__ */ new WeakSet(), pe = function(...e) {
|
|
@@ -1752,20 +1752,11 @@ class M extends ce {
|
|
|
1752
1752
|
return new Promise(
|
|
1753
1753
|
async (t, n) => {
|
|
1754
1754
|
try {
|
|
1755
|
-
const
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
...r
|
|
1761
|
-
} = await import("@swapkit/tokens");
|
|
1762
|
-
Te = [s, ...Object.values(r)].reduce(
|
|
1763
|
-
(o, { tokens: p }) => (p.forEach(({ identifier: d, chain: l, ...u }) => {
|
|
1764
|
-
const c = "decimals" in u ? u.decimals : w[l];
|
|
1765
|
-
o.set(d, { identifier: d, decimal: c });
|
|
1766
|
-
}), o),
|
|
1767
|
-
/* @__PURE__ */ new Map()
|
|
1768
|
-
), t({ ok: !0 });
|
|
1755
|
+
const a = await import("@swapkit/tokens");
|
|
1756
|
+
Te = Object.values(a).reduce((s, { tokens: r }) => (r.forEach(({ identifier: o, chain: p, ...d }) => {
|
|
1757
|
+
const u = "decimals" in d ? d.decimals : w[p];
|
|
1758
|
+
s.set(o, { identifier: o, decimal: u });
|
|
1759
|
+
}), s), /* @__PURE__ */ new Map()), t({ ok: !0 });
|
|
1769
1760
|
} catch (a) {
|
|
1770
1761
|
console.error(a), n({
|
|
1771
1762
|
ok: !1,
|
|
@@ -1863,9 +1854,9 @@ const de = (e) => {
|
|
|
1863
1854
|
*/
|
|
1864
1855
|
helpers_number_different_decimals: 99101
|
|
1865
1856
|
};
|
|
1866
|
-
class
|
|
1857
|
+
class c extends Error {
|
|
1867
1858
|
constructor(t, n) {
|
|
1868
|
-
console.error(n, { stack: n == null ? void 0 : n.stack, message: n == null ? void 0 : n.message }), super(t, { cause: { code: Xt[t], message: t } }), Object.setPrototypeOf(this,
|
|
1859
|
+
console.error(n, { stack: n == null ? void 0 : n.stack, message: n == null ? void 0 : n.message }), super(t, { cause: { code: Xt[t], message: t } }), Object.setPrototypeOf(this, c.prototype);
|
|
1869
1860
|
}
|
|
1870
1861
|
}
|
|
1871
1862
|
class x extends ce {
|
|
@@ -3596,9 +3587,9 @@ const Jt = [
|
|
|
3596
3587
|
data: o = "",
|
|
3597
3588
|
deadline: p,
|
|
3598
3589
|
memo: d,
|
|
3599
|
-
router:
|
|
3600
|
-
memoStreamingSwap:
|
|
3601
|
-
tcMemo:
|
|
3590
|
+
router: u,
|
|
3591
|
+
memoStreamingSwap: l,
|
|
3592
|
+
tcMemo: m,
|
|
3602
3593
|
tcRouter: _,
|
|
3603
3594
|
tcVault: b,
|
|
3604
3595
|
vault: A,
|
|
@@ -3606,12 +3597,12 @@ const Jt = [
|
|
|
3606
3597
|
}
|
|
3607
3598
|
}) => {
|
|
3608
3599
|
const O = !!Fe[t.toLowerCase()];
|
|
3609
|
-
if (O && !
|
|
3600
|
+
if (O && !u)
|
|
3610
3601
|
throw new Error("Router is required on calldata for swapIn with GenericContract");
|
|
3611
|
-
const S =
|
|
3602
|
+
const S = m || d, D = e && l || S;
|
|
3612
3603
|
if (!b && !A)
|
|
3613
3604
|
throw new Error("TC Vault is required on calldata");
|
|
3614
|
-
if (!_ && !
|
|
3605
|
+
if (!_ && !u)
|
|
3615
3606
|
throw new Error("TC Router is required on calldata");
|
|
3616
3607
|
if (!D)
|
|
3617
3608
|
throw new Error("TC Memo is required on calldata");
|
|
@@ -3619,12 +3610,12 @@ const Jt = [
|
|
|
3619
3610
|
throw new Error("Token is required on calldata");
|
|
3620
3611
|
const ie = [
|
|
3621
3612
|
// v2 contracts don't have tcVault, tcRouter, tcMemo but vault, router, memo
|
|
3622
|
-
a(_ ||
|
|
3613
|
+
a(_ || u),
|
|
3623
3614
|
a(b || A),
|
|
3624
3615
|
D.replace("{recipientAddress}", n),
|
|
3625
3616
|
a(E),
|
|
3626
3617
|
s
|
|
3627
|
-
], Ge = O ? [a(
|
|
3618
|
+
], Ge = O ? [a(u), o, p] : [r, p];
|
|
3628
3619
|
return [...ie, ...Ge];
|
|
3629
3620
|
}, cn = ({ chain: e, txHash: t }) => {
|
|
3630
3621
|
const n = Ne[e];
|
|
@@ -3719,67 +3710,67 @@ class Vn {
|
|
|
3719
3710
|
var p, d;
|
|
3720
3711
|
const { quoteMode: r } = a.meta, o = r.startsWith("ERC20-") ? i.Ethereum : r.startsWith("ARC20-") ? i.Avalanche : i.BinanceSmartChain;
|
|
3721
3712
|
if (!a.complete)
|
|
3722
|
-
throw new
|
|
3713
|
+
throw new c("core_swap_route_not_complete");
|
|
3723
3714
|
try {
|
|
3724
3715
|
if (Ze.includes(r)) {
|
|
3725
|
-
const
|
|
3726
|
-
if (!(
|
|
3727
|
-
throw new
|
|
3716
|
+
const u = this.connectedWallets[o];
|
|
3717
|
+
if (!(u != null && u.sendTransaction))
|
|
3718
|
+
throw new c("core_wallet_connection_not_found");
|
|
3728
3719
|
if (!(t ? (p = a == null ? void 0 : a.streamingSwap) == null ? void 0 : p.transaction : a == null ? void 0 : a.transaction))
|
|
3729
|
-
throw new
|
|
3730
|
-
const { data:
|
|
3731
|
-
data:
|
|
3720
|
+
throw new c("core_swap_route_transaction_not_found");
|
|
3721
|
+
const { data: m, from: _, to: b, value: A } = a.transaction, E = {
|
|
3722
|
+
data: m,
|
|
3732
3723
|
from: _,
|
|
3733
3724
|
to: b.toLowerCase(),
|
|
3734
3725
|
chainId: BigInt(pt[o]),
|
|
3735
3726
|
value: A ? BigInt(A) : 0n
|
|
3736
3727
|
};
|
|
3737
|
-
return
|
|
3728
|
+
return u.sendTransaction(E, s);
|
|
3738
3729
|
}
|
|
3739
3730
|
if (tt.includes(r)) {
|
|
3740
3731
|
if (!a.calldata.fromAsset)
|
|
3741
|
-
throw new
|
|
3742
|
-
const
|
|
3743
|
-
if (!
|
|
3744
|
-
throw new
|
|
3745
|
-
const { address:
|
|
3746
|
-
contract:
|
|
3732
|
+
throw new c("core_swap_asset_not_recognized");
|
|
3733
|
+
const u = await M.fromString(a.calldata.fromAsset);
|
|
3734
|
+
if (!u)
|
|
3735
|
+
throw new c("core_swap_asset_not_recognized");
|
|
3736
|
+
const { address: l } = await f(this, V).call(this, u.chain), {
|
|
3737
|
+
contract: m,
|
|
3747
3738
|
calldata: { expiration: _, amountIn: b, memo: A, memoStreamingSwap: E }
|
|
3748
|
-
} = a, O =
|
|
3739
|
+
} = a, O = u.add(x.fromBigInt(BigInt(b), u.decimal)), S = t && E || A;
|
|
3749
3740
|
return this.deposit({
|
|
3750
3741
|
expiration: _,
|
|
3751
3742
|
assetValue: O,
|
|
3752
3743
|
memo: S,
|
|
3753
3744
|
feeOptionKey: s,
|
|
3754
|
-
router:
|
|
3755
|
-
recipient:
|
|
3745
|
+
router: m,
|
|
3746
|
+
recipient: l
|
|
3756
3747
|
});
|
|
3757
3748
|
}
|
|
3758
3749
|
if (et.includes(r)) {
|
|
3759
|
-
const { calldata:
|
|
3760
|
-
if (!
|
|
3761
|
-
throw new
|
|
3762
|
-
const
|
|
3763
|
-
if (!(
|
|
3764
|
-
throw new
|
|
3765
|
-
const { getProvider: b, toChecksumAddress: A } = await import("@swapkit/toolbox-evm"), E = b(o), O = ln[
|
|
3750
|
+
const { calldata: u, contract: l } = a;
|
|
3751
|
+
if (!l)
|
|
3752
|
+
throw new c("core_swap_contract_not_found");
|
|
3753
|
+
const m = this.connectedWallets[o], _ = this.getAddress(o);
|
|
3754
|
+
if (!(m != null && m.sendTransaction) || !_)
|
|
3755
|
+
throw new c("core_wallet_connection_not_found");
|
|
3756
|
+
const { getProvider: b, toChecksumAddress: A } = await import("@swapkit/toolbox-evm"), E = b(o), O = ln[l.toLowerCase()];
|
|
3766
3757
|
if (!O)
|
|
3767
|
-
throw new
|
|
3768
|
-
const D = await (await ((d =
|
|
3758
|
+
throw new c("core_swap_contract_not_supported", { contractAddress: l });
|
|
3759
|
+
const D = await (await ((d = m.createContract) == null ? void 0 : d.call(m, l, O, E))).getFunction("swapIn").populateTransaction(
|
|
3769
3760
|
...yn({
|
|
3770
3761
|
streamSwap: t,
|
|
3771
3762
|
toChecksumAddress: A,
|
|
3772
|
-
contractAddress:
|
|
3763
|
+
contractAddress: l,
|
|
3773
3764
|
recipient: n,
|
|
3774
|
-
calldata:
|
|
3765
|
+
calldata: u
|
|
3775
3766
|
}),
|
|
3776
3767
|
{ from: _ }
|
|
3777
3768
|
);
|
|
3778
|
-
return
|
|
3769
|
+
return m.sendTransaction(D, s);
|
|
3779
3770
|
}
|
|
3780
|
-
throw new
|
|
3781
|
-
} catch (
|
|
3782
|
-
throw new
|
|
3771
|
+
throw new c("core_swap_quote_mode_not_supported", { quoteMode: r });
|
|
3772
|
+
} catch (u) {
|
|
3773
|
+
throw new c("core_swap_transaction_error", u);
|
|
3783
3774
|
}
|
|
3784
3775
|
});
|
|
3785
3776
|
T(this, "getWalletByChain", async (t, n) => {
|
|
@@ -3808,11 +3799,11 @@ class Vn {
|
|
|
3808
3799
|
T(this, "transfer", async (t) => {
|
|
3809
3800
|
const n = this.connectedWallets[t.assetValue.chain];
|
|
3810
3801
|
if (!n)
|
|
3811
|
-
throw new
|
|
3802
|
+
throw new c("core_wallet_connection_not_found");
|
|
3812
3803
|
try {
|
|
3813
3804
|
return await n.transfer(f(this, Y).call(this, t));
|
|
3814
3805
|
} catch (a) {
|
|
3815
|
-
throw new
|
|
3806
|
+
throw new c("core_swap_transaction_error", a);
|
|
3816
3807
|
}
|
|
3817
3808
|
});
|
|
3818
3809
|
T(this, "deposit", async ({
|
|
@@ -3823,43 +3814,43 @@ class Vn {
|
|
|
3823
3814
|
}) => {
|
|
3824
3815
|
const { chain: r, symbol: o, ticker: p } = t, d = this.connectedWallets[r];
|
|
3825
3816
|
if (!await _n({ address: await (d == null ? void 0 : d.getAddress()), chain: r }))
|
|
3826
|
-
throw new
|
|
3817
|
+
throw new c("core_transaction_invalid_sender_address");
|
|
3827
3818
|
if (!d)
|
|
3828
|
-
throw new
|
|
3829
|
-
const
|
|
3819
|
+
throw new c("core_wallet_connection_not_found");
|
|
3820
|
+
const u = f(this, Y).call(this, { assetValue: t, recipient: n, router: a, ...s });
|
|
3830
3821
|
try {
|
|
3831
3822
|
switch (r) {
|
|
3832
3823
|
case i.THORChain: {
|
|
3833
|
-
const
|
|
3834
|
-
return await (n === "" ?
|
|
3824
|
+
const l = d;
|
|
3825
|
+
return await (n === "" ? l.deposit(u) : l.transfer(u));
|
|
3835
3826
|
}
|
|
3836
3827
|
case i.Ethereum:
|
|
3837
3828
|
case i.BinanceSmartChain:
|
|
3838
3829
|
case i.Avalanche: {
|
|
3839
|
-
const { getChecksumAddressFromAsset:
|
|
3830
|
+
const { getChecksumAddressFromAsset: l } = await import("@swapkit/toolbox-evm"), m = r === i.Avalanche ? Je : r === i.BinanceSmartChain ? Qe : Xe;
|
|
3840
3831
|
return await d.call({
|
|
3841
|
-
abi:
|
|
3832
|
+
abi: m,
|
|
3842
3833
|
contractAddress: a || (await f(this, V).call(this, r)).router,
|
|
3843
3834
|
funcName: "depositWithExpiry",
|
|
3844
3835
|
funcParams: [
|
|
3845
3836
|
n,
|
|
3846
|
-
|
|
3837
|
+
l({ chain: r, symbol: o, ticker: p }, r),
|
|
3847
3838
|
t.getBaseValue("string"),
|
|
3848
|
-
|
|
3839
|
+
u.memo,
|
|
3849
3840
|
s.expiration || parseInt(`${((/* @__PURE__ */ new Date()).getTime() + 15 * 60 * 1e3) / 1e3}`)
|
|
3850
3841
|
],
|
|
3851
3842
|
txOverrides: {
|
|
3852
|
-
from:
|
|
3843
|
+
from: u.from,
|
|
3853
3844
|
value: t.isGasAsset ? t.getBaseValue("bigint") : void 0
|
|
3854
3845
|
}
|
|
3855
3846
|
});
|
|
3856
3847
|
}
|
|
3857
3848
|
default:
|
|
3858
|
-
return await d.transfer(
|
|
3849
|
+
return await d.transfer(u);
|
|
3859
3850
|
}
|
|
3860
|
-
} catch (
|
|
3861
|
-
const
|
|
3862
|
-
throw new
|
|
3851
|
+
} catch (l) {
|
|
3852
|
+
const m = ((l == null ? void 0 : l.message) || (l == null ? void 0 : l.toString())).toLowerCase(), _ = m == null ? void 0 : m.includes("insufficient funds"), b = m == null ? void 0 : m.includes("gas"), A = m == null ? void 0 : m.includes("server"), E = _ ? "core_transaction_deposit_insufficient_funds_error" : b ? "core_transaction_deposit_gas_error" : A ? "core_transaction_deposit_server_error" : "core_transaction_deposit_error";
|
|
3853
|
+
throw new c(E, l);
|
|
3863
3854
|
}
|
|
3864
3855
|
});
|
|
3865
3856
|
/**
|
|
@@ -3870,7 +3861,7 @@ class Vn {
|
|
|
3870
3861
|
assetValue: n
|
|
3871
3862
|
}) => {
|
|
3872
3863
|
if (t.lte(0) || n.lte(0))
|
|
3873
|
-
throw new
|
|
3864
|
+
throw new c("core_transaction_create_liquidity_invalid_params");
|
|
3874
3865
|
let a = "", s = "";
|
|
3875
3866
|
try {
|
|
3876
3867
|
a = await f(this, v).call(this, {
|
|
@@ -3881,7 +3872,7 @@ class Vn {
|
|
|
3881
3872
|
})
|
|
3882
3873
|
});
|
|
3883
3874
|
} catch (r) {
|
|
3884
|
-
throw new
|
|
3875
|
+
throw new c("core_transaction_create_liquidity_rune_error", r);
|
|
3885
3876
|
}
|
|
3886
3877
|
try {
|
|
3887
3878
|
s = await f(this, v).call(this, {
|
|
@@ -3892,7 +3883,7 @@ class Vn {
|
|
|
3892
3883
|
})
|
|
3893
3884
|
});
|
|
3894
3885
|
} catch (r) {
|
|
3895
|
-
throw new
|
|
3886
|
+
throw new c("core_transaction_create_liquidity_asset_error", r);
|
|
3896
3887
|
}
|
|
3897
3888
|
return { runeTx: a, assetTx: s };
|
|
3898
3889
|
});
|
|
@@ -3904,29 +3895,29 @@ class Vn {
|
|
|
3904
3895
|
isPendingSymmAsset: r,
|
|
3905
3896
|
mode: o = "sym"
|
|
3906
3897
|
}) => {
|
|
3907
|
-
const { chain: p, symbol: d } = n,
|
|
3908
|
-
if (!
|
|
3909
|
-
throw new
|
|
3898
|
+
const { chain: p, symbol: d } = n, u = o === "sym", l = (t == null ? void 0 : t.gt(0)) && (u || o === "rune"), m = (n == null ? void 0 : n.gt(0)) && (u || o === "asset"), _ = r || l, b = _ ? a || this.getAddress(i.THORChain) : "", A = u || o === "asset" ? s || this.getAddress(p) : "";
|
|
3899
|
+
if (!l && !m)
|
|
3900
|
+
throw new c("core_transaction_add_liquidity_invalid_params");
|
|
3910
3901
|
if (_ && !b)
|
|
3911
|
-
throw new
|
|
3902
|
+
throw new c("core_transaction_add_liquidity_no_rune_address");
|
|
3912
3903
|
let E, O;
|
|
3913
|
-
if (
|
|
3904
|
+
if (l && t)
|
|
3914
3905
|
try {
|
|
3915
3906
|
E = await f(this, v).call(this, {
|
|
3916
3907
|
assetValue: t,
|
|
3917
3908
|
memo: N(h.DEPOSIT, { chain: p, symbol: d, address: A })
|
|
3918
3909
|
});
|
|
3919
3910
|
} catch (S) {
|
|
3920
|
-
throw new
|
|
3911
|
+
throw new c("core_transaction_add_liquidity_rune_error", S);
|
|
3921
3912
|
}
|
|
3922
|
-
if (
|
|
3913
|
+
if (m && n)
|
|
3923
3914
|
try {
|
|
3924
3915
|
O = await f(this, v).call(this, {
|
|
3925
3916
|
assetValue: n,
|
|
3926
3917
|
memo: N(h.DEPOSIT, { chain: p, symbol: d, address: b })
|
|
3927
3918
|
});
|
|
3928
3919
|
} catch (S) {
|
|
3929
|
-
throw new
|
|
3920
|
+
throw new c("core_transaction_add_liquidity_asset_error", S);
|
|
3930
3921
|
}
|
|
3931
3922
|
return { runeTx: E, assetTx: O };
|
|
3932
3923
|
});
|
|
@@ -3937,7 +3928,7 @@ class Vn {
|
|
|
3937
3928
|
symmetric: s
|
|
3938
3929
|
}) => {
|
|
3939
3930
|
if (s && !a)
|
|
3940
|
-
throw new
|
|
3931
|
+
throw new c("core_transaction_add_liquidity_invalid_params");
|
|
3941
3932
|
const r = s && a || "";
|
|
3942
3933
|
return f(this, v).call(this, { assetValue: t, memo: `+:${n}:${r}:t:0` });
|
|
3943
3934
|
});
|
|
@@ -4015,7 +4006,7 @@ class Vn {
|
|
|
4015
4006
|
});
|
|
4016
4007
|
});
|
|
4017
4008
|
} catch (r) {
|
|
4018
|
-
throw new
|
|
4009
|
+
throw new c("core_extend_error", r);
|
|
4019
4010
|
}
|
|
4020
4011
|
});
|
|
4021
4012
|
T(this, "estimateMaxSendableAmount", async ({
|
|
@@ -4051,35 +4042,35 @@ class Vn {
|
|
|
4051
4042
|
});
|
|
4052
4043
|
}
|
|
4053
4044
|
default:
|
|
4054
|
-
throw new
|
|
4045
|
+
throw new c("core_estimated_max_spendable_chain_not_supported");
|
|
4055
4046
|
}
|
|
4056
4047
|
});
|
|
4057
4048
|
/**
|
|
4058
4049
|
* Wallet connection methods
|
|
4059
4050
|
*/
|
|
4060
4051
|
T(this, "connectXDEFI", async (t) => {
|
|
4061
|
-
throw new
|
|
4052
|
+
throw new c("core_wallet_xdefi_not_installed");
|
|
4062
4053
|
});
|
|
4063
4054
|
T(this, "connectEVMWallet", async (t, n) => {
|
|
4064
|
-
throw new
|
|
4055
|
+
throw new c("core_wallet_evmwallet_not_installed");
|
|
4065
4056
|
});
|
|
4066
4057
|
T(this, "connectWalletconnect", async (t, n) => {
|
|
4067
|
-
throw new
|
|
4058
|
+
throw new c("core_wallet_walletconnect_not_installed");
|
|
4068
4059
|
});
|
|
4069
4060
|
T(this, "connectKeystore", async (t, n) => {
|
|
4070
|
-
throw new
|
|
4061
|
+
throw new c("core_wallet_keystore_not_installed");
|
|
4071
4062
|
});
|
|
4072
4063
|
T(this, "connectLedger", async (t, n) => {
|
|
4073
|
-
throw new
|
|
4064
|
+
throw new c("core_wallet_ledger_not_installed");
|
|
4074
4065
|
});
|
|
4075
4066
|
T(this, "connectTrezor", async (t, n) => {
|
|
4076
|
-
throw new
|
|
4067
|
+
throw new c("core_wallet_trezor_not_installed");
|
|
4077
4068
|
});
|
|
4078
4069
|
T(this, "connectKeplr", async (t) => {
|
|
4079
|
-
throw new
|
|
4070
|
+
throw new c("core_wallet_keplr_not_installed");
|
|
4080
4071
|
});
|
|
4081
4072
|
T(this, "connectOkx", async (t) => {
|
|
4082
|
-
throw new
|
|
4073
|
+
throw new c("core_wallet_okx_not_installed");
|
|
4083
4074
|
});
|
|
4084
4075
|
T(this, "disconnectChain", (t) => {
|
|
4085
4076
|
this.connectedChains[t] = null, this.connectedWallets[t] = null;
|
|
@@ -4095,9 +4086,9 @@ class Vn {
|
|
|
4095
4086
|
};
|
|
4096
4087
|
const a = (await Tn(this.stagenet)).find((s) => s.chain === t);
|
|
4097
4088
|
if (!a)
|
|
4098
|
-
throw new
|
|
4089
|
+
throw new c("core_inbound_data_not_found");
|
|
4099
4090
|
if (a != null && a.halted)
|
|
4100
|
-
throw new
|
|
4091
|
+
throw new c("core_chain_halted");
|
|
4101
4092
|
return a;
|
|
4102
4093
|
});
|
|
4103
4094
|
P(this, ne, ({ chain: t, wallet: n, walletMethods: a }) => {
|
|
@@ -4111,14 +4102,14 @@ class Vn {
|
|
|
4111
4102
|
const { address: s, chain: r, isGasAsset: o, isSynthetic: p } = t, d = [i.Ethereum, i.Avalanche, i.BinanceSmartChain].includes(r);
|
|
4112
4103
|
if (d && o || !d || p)
|
|
4113
4104
|
return !0;
|
|
4114
|
-
const
|
|
4115
|
-
if (!
|
|
4116
|
-
throw new
|
|
4105
|
+
const l = this.connectedWallets[r], m = n === "checkOnly" ? l == null ? void 0 : l.isApproved : l == null ? void 0 : l.approve;
|
|
4106
|
+
if (!m)
|
|
4107
|
+
throw new c("core_wallet_connection_not_found");
|
|
4117
4108
|
const _ = this.getAddress(r);
|
|
4118
4109
|
if (!s || !_)
|
|
4119
|
-
throw new
|
|
4110
|
+
throw new c("core_approve_asset_address_or_from_not_found");
|
|
4120
4111
|
const b = a || (await f(this, V).call(this, r)).router;
|
|
4121
|
-
return
|
|
4112
|
+
return m({
|
|
4122
4113
|
amount: t.getBaseValue("bigint"),
|
|
4123
4114
|
assetAddress: s,
|
|
4124
4115
|
from: _,
|
|
@@ -4146,7 +4137,7 @@ class Vn {
|
|
|
4146
4137
|
P(this, K, async ({ memo: t, assetValue: n }) => {
|
|
4147
4138
|
const a = await hn(this.stagenet);
|
|
4148
4139
|
if (a.HALTCHAINGLOBAL >= 1 || a.HALTTHORCHAIN >= 1)
|
|
4149
|
-
throw new
|
|
4140
|
+
throw new c("core_chain_halted");
|
|
4150
4141
|
return this.deposit({ assetValue: n, recipient: "", memo: t });
|
|
4151
4142
|
});
|
|
4152
4143
|
P(this, Y, ({ assetValue: t, ...n }) => ({
|
|
@@ -4190,7 +4181,7 @@ export {
|
|
|
4190
4181
|
et as SWAP_IN,
|
|
4191
4182
|
tt as SWAP_OUT,
|
|
4192
4183
|
Vn as SwapKitCore,
|
|
4193
|
-
|
|
4184
|
+
c as SwapKitError,
|
|
4194
4185
|
x as SwapKitNumber,
|
|
4195
4186
|
Je as TCAvalancheDepositABI,
|
|
4196
4187
|
Qe as TCBscDepositABI,
|