@swapkit/core 1.0.0-rc.22 → 1.0.0-rc.23
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 +136 -134
- package/package.json +8 -8
- package/src/client/index.ts +4 -4
package/dist/index.es.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var T = (e, t, n) => (
|
|
1
|
+
var qe = Object.defineProperty;
|
|
2
|
+
var We = (e, t, n) => t in e ? qe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var T = (e, t, n) => (We(e, typeof t != "symbol" ? t + "" : t, n), n), je = (e, t, n) => {
|
|
4
4
|
if (!t.has(e))
|
|
5
5
|
throw TypeError("Cannot " + n);
|
|
6
6
|
};
|
|
7
|
-
var f = (e, t, n) => (je(e, t, "read from private field"), n ? n.call(e) : t.get(e)),
|
|
7
|
+
var f = (e, t, n) => (je(e, t, "read from private field"), n ? n.call(e) : t.get(e)), B = (e, t, n) => {
|
|
8
8
|
if (t.has(e))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
10
|
t instanceof WeakSet ? t.add(e) : t.set(e, n);
|
|
@@ -836,14 +836,14 @@ const se = Object.values(i), rt = Object.keys(i), be = se.reduce(
|
|
|
836
836
|
MATIC: "https://polygonscan.com",
|
|
837
837
|
THOR: "https://viewblock.io/thorchain"
|
|
838
838
|
};
|
|
839
|
-
var dt = /* @__PURE__ */ ((e) => (e[e.NoError = 36864] = "NoError", e))(dt || {}), 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 || {}),
|
|
839
|
+
var dt = /* @__PURE__ */ ((e) => (e[e.NoError = 36864] = "NoError", e))(dt || {}), 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 || {}), ut = /* @__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))(ut || {}), lt = Object.defineProperty, yt = (e, t, n) => t in e ? lt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, M = (e, t, n) => (yt(e, typeof t != "symbol" ? t + "" : t, n), n), ct = (e, t, n) => {
|
|
840
840
|
if (!t.has(e))
|
|
841
841
|
throw TypeError("Cannot " + n);
|
|
842
|
-
},
|
|
842
|
+
}, L = (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);
|
|
846
|
-
},
|
|
846
|
+
}, g = (e, t, n) => (ct(e, t, "access private method"), n);
|
|
847
847
|
const mt = "0x313ce567", Pe = async ({ chain: e, to: t }) => {
|
|
848
848
|
try {
|
|
849
849
|
const { result: n } = await Ae.post(pt[e], {
|
|
@@ -883,9 +883,9 @@ const mt = "0x313ce567", Pe = async ({ chain: e, to: t }) => {
|
|
|
883
883
|
return b[e];
|
|
884
884
|
}
|
|
885
885
|
}, ft = {
|
|
886
|
-
[
|
|
887
|
-
[
|
|
888
|
-
[
|
|
886
|
+
[F.Average]: 1.2,
|
|
887
|
+
[F.Fast]: 1.5,
|
|
888
|
+
[F.Fastest]: 2
|
|
889
889
|
}, bt = ({ chain: e, symbol: t }) => {
|
|
890
890
|
switch (e) {
|
|
891
891
|
case i.Bitcoin:
|
|
@@ -985,14 +985,14 @@ const mt = "0x313ce567", Pe = async ({ chain: e, to: t }) => {
|
|
|
985
985
|
poolUnits: t,
|
|
986
986
|
runeDepth: n
|
|
987
987
|
}) => {
|
|
988
|
-
const a =
|
|
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);
|
|
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 =
|
|
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);
|
|
996
996
|
return u.div(c);
|
|
997
997
|
}, In = ({
|
|
998
998
|
percent: e,
|
|
@@ -1004,14 +1004,14 @@ const mt = "0x313ce567", Pe = 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),
|
|
1007
|
+
}) => gt({ assetDepth: t, liquidityUnits: n, poolUnits: a }).mul(e), I = (e) => x.fromBigInt(BigInt(e), b.THOR), Ot = ({
|
|
1008
1008
|
liquidityUnits: e,
|
|
1009
1009
|
poolUnits: t,
|
|
1010
1010
|
runeDepth: n,
|
|
1011
1011
|
assetDepth: a
|
|
1012
1012
|
}) => ({
|
|
1013
|
-
assetAmount:
|
|
1014
|
-
runeAmount:
|
|
1013
|
+
assetAmount: I(a).mul(e).div(t),
|
|
1014
|
+
runeAmount: I(n).mul(e).div(t)
|
|
1015
1015
|
}), vn = ({
|
|
1016
1016
|
liquidityUnits: e,
|
|
1017
1017
|
poolUnits: t,
|
|
@@ -1030,24 +1030,26 @@ const mt = "0x313ce567", Pe = async ({ chain: e, to: t }) => {
|
|
|
1030
1030
|
runeAmount: s,
|
|
1031
1031
|
assetAmount: r
|
|
1032
1032
|
}) => {
|
|
1033
|
-
const o =
|
|
1034
|
-
if (
|
|
1035
|
-
return v.div(d).
|
|
1036
|
-
const
|
|
1037
|
-
return v.div(
|
|
1033
|
+
const o = new x({ value: e, decimal: 8 }), p = new x({ value: n, decimal: 8 }), d = new x({ value: t, decimal: 8 }), y = new x({ value: s, decimal: 8 }), u = new x({ value: r, decimal: 8 }), c = y.mul(p), _ = u.mul(o), w = y.mul(u), E = o.mul(p), R = d.mul(c.add(_.add(w.mul(2)))), A = c.add(_.add(E.mul(2))), O = R.div(A), v = I(a).add(O);
|
|
1034
|
+
if (O.getBaseValue("number") === 0)
|
|
1035
|
+
return v.div(d).getBaseValue("number");
|
|
1036
|
+
const P = d.add(v);
|
|
1037
|
+
return v.div(P).getBaseValue("number");
|
|
1038
1038
|
}, Mn = ({
|
|
1039
1039
|
runeAmount: e,
|
|
1040
1040
|
assetAmount: t,
|
|
1041
1041
|
runeDepth: n,
|
|
1042
1042
|
assetDepth: a
|
|
1043
1043
|
}) => {
|
|
1044
|
-
|
|
1045
|
-
|
|
1044
|
+
if (e === "0" || t === "0" || n === "0" || a === "0")
|
|
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));
|
|
1047
|
+
return Math.abs(d.div(y).getBaseValue("number"));
|
|
1046
1048
|
}, It = ({
|
|
1047
1049
|
symbol: e,
|
|
1048
1050
|
ticker: t,
|
|
1049
1051
|
chain: n
|
|
1050
|
-
}) => n === "ETH" && t !== "ETH" ? `${t}-${e.slice(-3)}` : e,
|
|
1052
|
+
}) => n === "ETH" && t !== "ETH" ? `${t}-${e.slice(-3)}` : e, D = (e, t) => {
|
|
1051
1053
|
switch (e) {
|
|
1052
1054
|
case h.LEAVE:
|
|
1053
1055
|
case h.BOND: {
|
|
@@ -1439,7 +1441,7 @@ const de = (e) => {
|
|
|
1439
1441
|
}, kt = de(), Ft = kt, Gt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, ge = Ft.create({ headers: Gt }), Ae = {
|
|
1440
1442
|
get: (e, t) => ge.get(e, t).json(),
|
|
1441
1443
|
post: (e, t) => ge.post(e, t).json()
|
|
1442
|
-
}, Oe = Object.values(i),
|
|
1444
|
+
}, Oe = Object.values(i), qt = (e = "") => {
|
|
1443
1445
|
const t = e.toUpperCase(), [n] = t.split(".");
|
|
1444
1446
|
if (Oe.includes(n))
|
|
1445
1447
|
return !0;
|
|
@@ -1449,11 +1451,11 @@ const de = (e) => {
|
|
|
1449
1451
|
throw new Error(
|
|
1450
1452
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
1451
1453
|
);
|
|
1452
|
-
},
|
|
1454
|
+
}, j = 8, H = (e) => 10n ** BigInt(e), G = (e) => Math.log10(parseFloat(e.toString()));
|
|
1453
1455
|
function ie({
|
|
1454
1456
|
value: e,
|
|
1455
|
-
bigIntDecimal: t =
|
|
1456
|
-
decimal: n =
|
|
1457
|
+
bigIntDecimal: t = j,
|
|
1458
|
+
decimal: n = j
|
|
1457
1459
|
}) {
|
|
1458
1460
|
const a = e < 0n;
|
|
1459
1461
|
let s = e.toString().substring(a ? 1 : 0);
|
|
@@ -1466,14 +1468,14 @@ function ie({
|
|
|
1466
1468
|
""
|
|
1467
1469
|
);
|
|
1468
1470
|
}
|
|
1469
|
-
var
|
|
1470
|
-
const
|
|
1471
|
+
var U, k, ue, ke, le, Ie, te, ye, $, q, ne, ce;
|
|
1472
|
+
const Wt = class me {
|
|
1471
1473
|
constructor(t) {
|
|
1472
|
-
|
|
1474
|
+
L(this, U), L(this, ue), L(this, le), L(this, te), L(this, $), L(this, ne), M(this, "decimalMultiplier", 10n ** 8n), M(this, "bigIntValue", 0n), M(this, "decimal");
|
|
1473
1475
|
const n = he(t);
|
|
1474
|
-
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier =
|
|
1475
|
-
Math.max(
|
|
1476
|
-
),
|
|
1476
|
+
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = H(
|
|
1477
|
+
Math.max(g(this, ne, ce).call(this, g(this, $, q).call(this, n)), this.decimal || 0)
|
|
1478
|
+
), g(this, ue, ke).call(this, n);
|
|
1477
1479
|
}
|
|
1478
1480
|
static fromBigInt(t, n) {
|
|
1479
1481
|
return new me({
|
|
@@ -1487,7 +1489,7 @@ const qt = class me {
|
|
|
1487
1489
|
to: a
|
|
1488
1490
|
}) {
|
|
1489
1491
|
return this.fromBigInt(
|
|
1490
|
-
new me(t).bigIntValue *
|
|
1492
|
+
new me(t).bigIntValue * H(a) / H(n),
|
|
1491
1493
|
a
|
|
1492
1494
|
);
|
|
1493
1495
|
}
|
|
@@ -1513,16 +1515,16 @@ const qt = class me {
|
|
|
1513
1515
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
1514
1516
|
}
|
|
1515
1517
|
add(...t) {
|
|
1516
|
-
return
|
|
1518
|
+
return g(this, U, k).call(this, "add", ...t);
|
|
1517
1519
|
}
|
|
1518
1520
|
sub(...t) {
|
|
1519
|
-
return
|
|
1521
|
+
return g(this, U, k).call(this, "sub", ...t);
|
|
1520
1522
|
}
|
|
1521
1523
|
mul(...t) {
|
|
1522
|
-
return
|
|
1524
|
+
return g(this, U, k).call(this, "mul", ...t);
|
|
1523
1525
|
}
|
|
1524
1526
|
div(...t) {
|
|
1525
|
-
return
|
|
1527
|
+
return g(this, U, k).call(this, "div", ...t);
|
|
1526
1528
|
}
|
|
1527
1529
|
gt(t) {
|
|
1528
1530
|
return this.bigIntValue > this.getBigIntValue(t);
|
|
@@ -1542,7 +1544,7 @@ const qt = class me {
|
|
|
1542
1544
|
getValue(t) {
|
|
1543
1545
|
const n = this.formatBigIntToSafeValue(
|
|
1544
1546
|
this.bigIntValue,
|
|
1545
|
-
this.decimal ||
|
|
1547
|
+
this.decimal || G(this.decimalMultiplier)
|
|
1546
1548
|
);
|
|
1547
1549
|
switch (t) {
|
|
1548
1550
|
case "number":
|
|
@@ -1554,7 +1556,7 @@ const qt = class me {
|
|
|
1554
1556
|
}
|
|
1555
1557
|
}
|
|
1556
1558
|
getBaseValue(t) {
|
|
1557
|
-
const n = this.decimalMultiplier /
|
|
1559
|
+
const n = this.decimalMultiplier / H(this.decimal || b.THOR), a = this.bigIntValue / n;
|
|
1558
1560
|
switch (t) {
|
|
1559
1561
|
case "number":
|
|
1560
1562
|
return Number(a);
|
|
@@ -1567,13 +1569,13 @@ const qt = class me {
|
|
|
1567
1569
|
getBigIntValue(t, n) {
|
|
1568
1570
|
if (!n && typeof t == "object")
|
|
1569
1571
|
return t.bigIntValue;
|
|
1570
|
-
const a = he(t), s =
|
|
1571
|
-
return s === "0" || s === "undefined" ? 0n :
|
|
1572
|
+
const a = he(t), s = g(this, $, q).call(this, a);
|
|
1573
|
+
return s === "0" || s === "undefined" ? 0n : g(this, te, ye).call(this, s, n);
|
|
1572
1574
|
}
|
|
1573
1575
|
formatBigIntToSafeValue(t, n) {
|
|
1574
|
-
const a = n || this.decimal ||
|
|
1576
|
+
const a = n || this.decimal || j, s = Math.max(
|
|
1575
1577
|
a,
|
|
1576
|
-
|
|
1578
|
+
G(this.decimalMultiplier)
|
|
1577
1579
|
), r = t < 0n, o = t.toString().substring(r ? 1 : 0), p = s - (o.length - 1), d = p > 0 ? "0".repeat(p) + o : o, y = d.length - s;
|
|
1578
1580
|
let u = d.slice(-s);
|
|
1579
1581
|
return parseInt(u[a]) >= 5 ? u = `${u.substring(0, a - 1)}${(parseInt(u[a - 1]) + 1).toString()}` : u = u.substring(0, a), `${r ? "-" : ""}${d.slice(
|
|
@@ -1582,19 +1584,19 @@ const qt = class me {
|
|
|
1582
1584
|
)}.${u}`.replace(/\.?0*$/, "");
|
|
1583
1585
|
}
|
|
1584
1586
|
toSignificant(t = 6) {
|
|
1585
|
-
const [n, a] = this.getValue("string").split("."), s = n || "", r = a || ""
|
|
1586
|
-
if (
|
|
1587
|
+
const [n, a] = this.getValue("string").split("."), s = n || "", r = a || "";
|
|
1588
|
+
if ((parseInt(s) ? s.length + r.length : r.length) <= t)
|
|
1587
1589
|
return this.getValue("string");
|
|
1588
1590
|
if (s.length >= t)
|
|
1589
1591
|
return s.slice(0, t).padEnd(s.length, "0");
|
|
1590
1592
|
if (parseInt(s))
|
|
1591
1593
|
return `${s}.${r.slice(0, t - s.length)}`.padEnd(
|
|
1592
|
-
|
|
1594
|
+
t - s.length,
|
|
1593
1595
|
"0"
|
|
1594
1596
|
);
|
|
1595
|
-
const
|
|
1596
|
-
return `0.${
|
|
1597
|
-
r.length - `${
|
|
1597
|
+
const o = parseInt(r), p = `${o}`.slice(0, t);
|
|
1598
|
+
return `0.${p.padStart(
|
|
1599
|
+
r.length - `${o}`.length + p.length,
|
|
1598
1600
|
"0"
|
|
1599
1601
|
)}`;
|
|
1600
1602
|
}
|
|
@@ -1616,8 +1618,8 @@ const qt = class me {
|
|
|
1616
1618
|
return `${(n / o).toFixed(t)}${r}`;
|
|
1617
1619
|
}
|
|
1618
1620
|
};
|
|
1619
|
-
|
|
1620
|
-
const n =
|
|
1621
|
+
U = /* @__PURE__ */ new WeakSet(), k = function(e, ...t) {
|
|
1622
|
+
const n = g(this, le, Ie).call(this, this, ...t), a = H(n), s = t.reduce(
|
|
1621
1623
|
(o, p) => {
|
|
1622
1624
|
const d = this.getBigIntValue(p, n);
|
|
1623
1625
|
switch (e) {
|
|
@@ -1640,22 +1642,22 @@ L = /* @__PURE__ */ new WeakSet(), $ = function(e, ...t) {
|
|
|
1640
1642
|
this.bigIntValue * a / this.decimalMultiplier
|
|
1641
1643
|
), r = ie({
|
|
1642
1644
|
bigIntDecimal: n,
|
|
1643
|
-
decimal: Math.max(n,
|
|
1645
|
+
decimal: Math.max(n, G(this.decimalMultiplier)),
|
|
1644
1646
|
value: s
|
|
1645
1647
|
});
|
|
1646
1648
|
return new this.constructor({ decimal: this.decimal, value: r, identifier: this.toString() });
|
|
1647
1649
|
}, ue = /* @__PURE__ */ new WeakSet(), ke = function(e) {
|
|
1648
|
-
const t =
|
|
1649
|
-
this.bigIntValue =
|
|
1650
|
+
const t = g(this, $, q).call(this, e) || "0";
|
|
1651
|
+
this.bigIntValue = g(this, te, ye).call(this, t);
|
|
1650
1652
|
}, le = /* @__PURE__ */ new WeakSet(), Ie = function(...e) {
|
|
1651
1653
|
const t = e.map(
|
|
1652
|
-
(n) => typeof n == "object" ? n.decimal ||
|
|
1654
|
+
(n) => typeof n == "object" ? n.decimal || G(n.decimalMultiplier) : g(this, ne, ce).call(this, g(this, $, q).call(this, n))
|
|
1653
1655
|
).filter(Boolean);
|
|
1654
|
-
return Math.max(...t,
|
|
1656
|
+
return Math.max(...t, j);
|
|
1655
1657
|
}, te = /* @__PURE__ */ new WeakSet(), ye = function(e, t) {
|
|
1656
|
-
const n = t ?
|
|
1658
|
+
const n = t ? H(t) : this.decimalMultiplier, a = G(n), [s = "", r = ""] = e.split(".");
|
|
1657
1659
|
return BigInt(`${s}${r.padEnd(a, "0")}`);
|
|
1658
|
-
},
|
|
1660
|
+
}, $ = /* @__PURE__ */ new WeakSet(), q = function(e) {
|
|
1659
1661
|
const t = `${typeof e == "number" ? Number(e).toLocaleString("fullwide", {
|
|
1660
1662
|
useGrouping: !1,
|
|
1661
1663
|
maximumFractionDigits: 20
|
|
@@ -1664,9 +1666,9 @@ L = /* @__PURE__ */ new WeakSet(), $ = function(e, ...t) {
|
|
|
1664
1666
|
}, ne = /* @__PURE__ */ new WeakSet(), ce = function(e) {
|
|
1665
1667
|
var t;
|
|
1666
1668
|
const n = ((t = e.split(".")[1]) == null ? void 0 : t.length) || 0;
|
|
1667
|
-
return Math.max(n,
|
|
1669
|
+
return Math.max(n, j);
|
|
1668
1670
|
};
|
|
1669
|
-
let Te =
|
|
1671
|
+
let Te = Wt;
|
|
1670
1672
|
function he(e) {
|
|
1671
1673
|
return typeof e == "object" ? "getValue" in e ? e.getValue("string") : e.value : e;
|
|
1672
1674
|
}
|
|
@@ -1677,7 +1679,7 @@ const pe = (e) => {
|
|
|
1677
1679
|
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
|
|
1678
1680
|
return _e.get(e.toUpperCase()) || { decimal: b.THOR, identifier: "" };
|
|
1679
1681
|
}, Se = async (e, t = 0) => {
|
|
1680
|
-
|
|
1682
|
+
qt(e);
|
|
1681
1683
|
const n = await Be(Z(e)), a = z(t, n);
|
|
1682
1684
|
return new S({ decimal: n, value: a, identifier: e });
|
|
1683
1685
|
};
|
|
@@ -1853,12 +1855,12 @@ class m extends Error {
|
|
|
1853
1855
|
console.error(n), super(t, { cause: { code: jt[t], message: t } }), Object.setPrototypeOf(this, m.prototype);
|
|
1854
1856
|
}
|
|
1855
1857
|
}
|
|
1856
|
-
class
|
|
1858
|
+
class x extends Te {
|
|
1857
1859
|
eq(t) {
|
|
1858
1860
|
return this.eqValue(t);
|
|
1859
1861
|
}
|
|
1860
1862
|
static fromBigInt(t, n) {
|
|
1861
|
-
return new
|
|
1863
|
+
return new x({
|
|
1862
1864
|
decimal: n,
|
|
1863
1865
|
value: ie({ value: t, bigIntDecimal: n, decimal: n })
|
|
1864
1866
|
});
|
|
@@ -3585,32 +3587,32 @@ const Kt = [
|
|
|
3585
3587
|
memoStreamingSwap: u,
|
|
3586
3588
|
tcMemo: c,
|
|
3587
3589
|
tcRouter: _,
|
|
3588
|
-
tcVault:
|
|
3589
|
-
vault:
|
|
3590
|
-
token:
|
|
3590
|
+
tcVault: w,
|
|
3591
|
+
vault: E,
|
|
3592
|
+
token: R
|
|
3591
3593
|
}
|
|
3592
3594
|
}) => {
|
|
3593
|
-
const
|
|
3594
|
-
if (
|
|
3595
|
+
const A = !!Fe[t.toLowerCase()];
|
|
3596
|
+
if (A && !y)
|
|
3595
3597
|
throw new Error("Router is required on calldata for swapIn with GenericContract");
|
|
3596
|
-
const
|
|
3597
|
-
if (!
|
|
3598
|
+
const O = c || d, v = e && u || O;
|
|
3599
|
+
if (!w && !E)
|
|
3598
3600
|
throw new Error("TC Vault is required on calldata");
|
|
3599
3601
|
if (!_ && !y)
|
|
3600
3602
|
throw new Error("TC Router is required on calldata");
|
|
3601
3603
|
if (!v)
|
|
3602
3604
|
throw new Error("TC Memo is required on calldata");
|
|
3603
|
-
if (!
|
|
3605
|
+
if (!R)
|
|
3604
3606
|
throw new Error("Token is required on calldata");
|
|
3605
|
-
const
|
|
3607
|
+
const P = [
|
|
3606
3608
|
// v2 contracts don't have tcVault, tcRouter, tcMemo but vault, router, memo
|
|
3607
3609
|
a(_ || y),
|
|
3608
|
-
a(
|
|
3610
|
+
a(w || E),
|
|
3609
3611
|
v.replace("{recipientAddress}", n),
|
|
3610
|
-
a(
|
|
3612
|
+
a(R),
|
|
3611
3613
|
s
|
|
3612
|
-
], Ge =
|
|
3613
|
-
return [...
|
|
3614
|
+
], Ge = A ? [a(y), o, p] : [r, p];
|
|
3615
|
+
return [...P, ...Ge];
|
|
3614
3616
|
}, un = ({ chain: e, txHash: t }) => {
|
|
3615
3617
|
const n = De[e];
|
|
3616
3618
|
switch (e) {
|
|
@@ -3671,7 +3673,7 @@ const Kt = [
|
|
|
3671
3673
|
(e, t) => (e[t] = null, e),
|
|
3672
3674
|
{}
|
|
3673
3675
|
);
|
|
3674
|
-
var
|
|
3676
|
+
var V, ae, K, N, Y, X;
|
|
3675
3677
|
class Pn {
|
|
3676
3678
|
constructor({ stagenet: t } = {}) {
|
|
3677
3679
|
T(this, "connectedChains", Ce());
|
|
@@ -3700,16 +3702,16 @@ class Pn {
|
|
|
3700
3702
|
throw new m("core_wallet_connection_not_found");
|
|
3701
3703
|
if (!(t ? (p = a == null ? void 0 : a.streamingSwap) == null ? void 0 : p.transaction : a == null ? void 0 : a.transaction))
|
|
3702
3704
|
throw new m("core_swap_route_transaction_not_found");
|
|
3703
|
-
const { isHexString: c, parseUnits: _ } = await import("./index-cf1865cd.js"), { data:
|
|
3704
|
-
data:
|
|
3705
|
-
from:
|
|
3706
|
-
to:
|
|
3705
|
+
const { isHexString: c, parseUnits: _ } = await import("./index-cf1865cd.js"), { data: w, from: E, to: R, value: A } = a.transaction, O = {
|
|
3706
|
+
data: w,
|
|
3707
|
+
from: E,
|
|
3708
|
+
to: R.toLowerCase(),
|
|
3707
3709
|
chainId: BigInt(ot[o]),
|
|
3708
|
-
value:
|
|
3709
|
-
value: c(
|
|
3710
|
-
}).
|
|
3710
|
+
value: A ? new x({
|
|
3711
|
+
value: c(A) ? A : _(A, "wei").toString(16)
|
|
3712
|
+
}).getBaseValue("bigint") : 0n
|
|
3711
3713
|
};
|
|
3712
|
-
return y.sendTransaction(
|
|
3714
|
+
return y.sendTransaction(O, s);
|
|
3713
3715
|
}
|
|
3714
3716
|
if (tt.includes(r)) {
|
|
3715
3717
|
if (!a.calldata.fromAsset)
|
|
@@ -3717,14 +3719,14 @@ class Pn {
|
|
|
3717
3719
|
const y = await S.fromString(a.calldata.fromAsset);
|
|
3718
3720
|
if (!y)
|
|
3719
3721
|
throw new m("core_swap_asset_not_recognized");
|
|
3720
|
-
const { address: u } = await f(this,
|
|
3722
|
+
const { address: u } = await f(this, V).call(this, y.chain), {
|
|
3721
3723
|
contract: c,
|
|
3722
|
-
calldata: { expiration: _, amountIn:
|
|
3723
|
-
} = a,
|
|
3724
|
+
calldata: { expiration: _, amountIn: w, memo: E, memoStreamingSwap: R }
|
|
3725
|
+
} = a, A = y.add(x.fromBigInt(BigInt(w), y.decimal)), O = t && R || E;
|
|
3724
3726
|
return this.deposit({
|
|
3725
3727
|
expiration: _,
|
|
3726
|
-
assetValue:
|
|
3727
|
-
memo:
|
|
3728
|
+
assetValue: A,
|
|
3729
|
+
memo: O,
|
|
3728
3730
|
feeOptionKey: s,
|
|
3729
3731
|
router: c,
|
|
3730
3732
|
recipient: u
|
|
@@ -3737,13 +3739,13 @@ class Pn {
|
|
|
3737
3739
|
const c = this.connectedWallets[o], _ = this.getAddress(o);
|
|
3738
3740
|
if (!(c != null && c.sendTransaction) || !_)
|
|
3739
3741
|
throw new m("core_wallet_connection_not_found");
|
|
3740
|
-
const { getProvider:
|
|
3741
|
-
if (!
|
|
3742
|
+
const { getProvider: w, toChecksumAddress: E } = await import("@swapkit/toolbox-evm"), R = w(o), A = pn[u.toLowerCase()];
|
|
3743
|
+
if (!A)
|
|
3742
3744
|
throw new m("core_swap_contract_not_supported", { contractAddress: u });
|
|
3743
|
-
const v = await (await ((d = c.createContract) == null ? void 0 : d.call(c, u,
|
|
3745
|
+
const v = await (await ((d = c.createContract) == null ? void 0 : d.call(c, u, A, R))).getFunction("swapIn").populateTransaction(
|
|
3744
3746
|
...dn({
|
|
3745
3747
|
streamSwap: t,
|
|
3746
|
-
toChecksumAddress:
|
|
3748
|
+
toChecksumAddress: E,
|
|
3747
3749
|
contractAddress: u,
|
|
3748
3750
|
recipient: n,
|
|
3749
3751
|
calldata: y
|
|
@@ -3812,7 +3814,7 @@ class Pn {
|
|
|
3812
3814
|
const { getChecksumAddressFromAsset: u } = await import("@swapkit/toolbox-evm"), c = r === i.Avalanche ? Je : r === i.BinanceSmartChain ? Qe : Xe;
|
|
3813
3815
|
return await d.call({
|
|
3814
3816
|
abi: c,
|
|
3815
|
-
contractAddress: a || (await f(this,
|
|
3817
|
+
contractAddress: a || (await f(this, V).call(this, r)).router,
|
|
3816
3818
|
funcName: "depositWithExpiry",
|
|
3817
3819
|
funcParams: [
|
|
3818
3820
|
n,
|
|
@@ -3832,8 +3834,8 @@ class Pn {
|
|
|
3832
3834
|
return await d.transfer(y);
|
|
3833
3835
|
}
|
|
3834
3836
|
} catch (u) {
|
|
3835
|
-
const c = ((u == null ? void 0 : u.message) || (u == null ? void 0 : u.toString())).toLowerCase(), _ = c == null ? void 0 : c.includes("insufficient funds"),
|
|
3836
|
-
throw new m(
|
|
3837
|
+
const c = ((u == null ? void 0 : u.message) || (u == null ? void 0 : u.toString())).toLowerCase(), _ = c == null ? void 0 : c.includes("insufficient funds"), w = c == null ? void 0 : c.includes("gas"), E = c == null ? void 0 : c.includes("server"), R = _ ? "core_transaction_deposit_insufficient_funds_error" : w ? "core_transaction_deposit_gas_error" : E ? "core_transaction_deposit_server_error" : "core_transaction_deposit_error";
|
|
3838
|
+
throw new m(R, u);
|
|
3837
3839
|
}
|
|
3838
3840
|
});
|
|
3839
3841
|
/**
|
|
@@ -3849,7 +3851,7 @@ class Pn {
|
|
|
3849
3851
|
try {
|
|
3850
3852
|
a = await f(this, N).call(this, {
|
|
3851
3853
|
assetValue: t,
|
|
3852
|
-
memo:
|
|
3854
|
+
memo: D(h.DEPOSIT, {
|
|
3853
3855
|
...n,
|
|
3854
3856
|
address: this.getAddress(n.chain)
|
|
3855
3857
|
})
|
|
@@ -3860,7 +3862,7 @@ class Pn {
|
|
|
3860
3862
|
try {
|
|
3861
3863
|
s = await f(this, N).call(this, {
|
|
3862
3864
|
assetValue: n,
|
|
3863
|
-
memo:
|
|
3865
|
+
memo: D(h.DEPOSIT, {
|
|
3864
3866
|
...n,
|
|
3865
3867
|
address: this.getAddress(i.THORChain)
|
|
3866
3868
|
})
|
|
@@ -3879,32 +3881,32 @@ class Pn {
|
|
|
3879
3881
|
isPendingSymmAsset: o,
|
|
3880
3882
|
mode: p = "sym"
|
|
3881
3883
|
}) => {
|
|
3882
|
-
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"),
|
|
3884
|
+
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"), w = o || c, E = w ? s || this.getAddress(i.THORChain) : "", R = u || p === "asset" ? r || this.getAddress(d) : "";
|
|
3883
3885
|
if (!c && !_)
|
|
3884
3886
|
throw new m("core_transaction_add_liquidity_invalid_params");
|
|
3885
|
-
if (
|
|
3887
|
+
if (w && !E)
|
|
3886
3888
|
throw new m("core_transaction_add_liquidity_no_rune_address");
|
|
3887
|
-
let
|
|
3889
|
+
let A, O;
|
|
3888
3890
|
const v = { chain: d, symbol: y.join(".") };
|
|
3889
3891
|
if (c && n)
|
|
3890
3892
|
try {
|
|
3891
|
-
|
|
3893
|
+
A = await f(this, N).call(this, {
|
|
3892
3894
|
assetValue: n,
|
|
3893
|
-
memo:
|
|
3895
|
+
memo: D(h.DEPOSIT, { ...v, address: R })
|
|
3894
3896
|
});
|
|
3895
|
-
} catch (
|
|
3896
|
-
throw new m("core_transaction_add_liquidity_rune_error",
|
|
3897
|
+
} catch (P) {
|
|
3898
|
+
throw new m("core_transaction_add_liquidity_rune_error", P);
|
|
3897
3899
|
}
|
|
3898
3900
|
if (_ && a)
|
|
3899
3901
|
try {
|
|
3900
|
-
|
|
3902
|
+
O = await f(this, N).call(this, {
|
|
3901
3903
|
assetValue: a,
|
|
3902
|
-
memo:
|
|
3904
|
+
memo: D(h.DEPOSIT, { ...v, address: E })
|
|
3903
3905
|
});
|
|
3904
|
-
} catch (
|
|
3905
|
-
throw new m("core_transaction_add_liquidity_asset_error",
|
|
3906
|
+
} catch (P) {
|
|
3907
|
+
throw new m("core_transaction_add_liquidity_asset_error", P);
|
|
3906
3908
|
}
|
|
3907
|
-
return { runeTx:
|
|
3909
|
+
return { runeTx: A, assetTx: O };
|
|
3908
3910
|
});
|
|
3909
3911
|
T(this, "withdraw", async ({
|
|
3910
3912
|
memo: t,
|
|
@@ -3917,7 +3919,7 @@ class Pn {
|
|
|
3917
3919
|
try {
|
|
3918
3920
|
return await f(this, N).call(this, {
|
|
3919
3921
|
assetValue: ve(s === "asset" ? n.chain : i.THORChain),
|
|
3920
|
-
memo: t ||
|
|
3922
|
+
memo: t || D(h.WITHDRAW, {
|
|
3921
3923
|
symbol: n.symbol,
|
|
3922
3924
|
chain: n.chain,
|
|
3923
3925
|
ticker: n.ticker,
|
|
@@ -3936,7 +3938,7 @@ class Pn {
|
|
|
3936
3938
|
percent: a,
|
|
3937
3939
|
type: s
|
|
3938
3940
|
}) => {
|
|
3939
|
-
const r = s === "add" ? h.DEPOSIT : h.WITHDRAW, o = n ||
|
|
3941
|
+
const r = s === "add" ? h.DEPOSIT : h.WITHDRAW, o = n || D(r, {
|
|
3940
3942
|
ticker: t.ticker,
|
|
3941
3943
|
symbol: t.symbol,
|
|
3942
3944
|
chain: t.chain,
|
|
@@ -3952,7 +3954,7 @@ class Pn {
|
|
|
3952
3954
|
type: s
|
|
3953
3955
|
}) => f(this, N).call(this, {
|
|
3954
3956
|
assetValue: t,
|
|
3955
|
-
memo: n ||
|
|
3957
|
+
memo: n || D(s === "open" ? h.OPEN_LOAN : h.CLOSE_LOAN, {
|
|
3956
3958
|
asset: t.toString(),
|
|
3957
3959
|
minAmount: a.toString(),
|
|
3958
3960
|
address: this.getAddress(t.chain)
|
|
@@ -3963,9 +3965,9 @@ class Pn {
|
|
|
3963
3965
|
assetValue: n,
|
|
3964
3966
|
address: a
|
|
3965
3967
|
}) => {
|
|
3966
|
-
const s = t === "bond" ? h.BOND : t === "unbond" ? h.UNBOND : h.LEAVE, r =
|
|
3968
|
+
const s = t === "bond" ? h.BOND : t === "unbond" ? h.UNBOND : h.LEAVE, r = D(s, {
|
|
3967
3969
|
address: a,
|
|
3968
|
-
unbondAmount: t === "unbond" ? n.
|
|
3970
|
+
unbondAmount: t === "unbond" ? n.getBaseValue("number") : void 0
|
|
3969
3971
|
});
|
|
3970
3972
|
return f(this, Y).call(this, {
|
|
3971
3973
|
memo: r,
|
|
@@ -3975,7 +3977,7 @@ class Pn {
|
|
|
3975
3977
|
T(this, "registerThorname", ({
|
|
3976
3978
|
assetValue: t,
|
|
3977
3979
|
...n
|
|
3978
|
-
}) => f(this, Y).call(this, { assetValue: t, memo:
|
|
3980
|
+
}) => f(this, Y).call(this, { assetValue: t, memo: D(h.THORNAME_REGISTER, n) }));
|
|
3979
3981
|
T(this, "extend", ({ wallets: t, config: n, apis: a = {}, rpcUrls: s = {} }) => {
|
|
3980
3982
|
try {
|
|
3981
3983
|
t.forEach((r) => {
|
|
@@ -4056,7 +4058,7 @@ class Pn {
|
|
|
4056
4058
|
T(this, "disconnectChain", (t) => {
|
|
4057
4059
|
this.connectedChains[t] = null, this.connectedWallets[t] = null;
|
|
4058
4060
|
});
|
|
4059
|
-
|
|
4061
|
+
B(this, V, async (t) => {
|
|
4060
4062
|
if (t === i.THORChain)
|
|
4061
4063
|
return {
|
|
4062
4064
|
gas_rate: "0",
|
|
@@ -4072,11 +4074,11 @@ class Pn {
|
|
|
4072
4074
|
throw new m("core_chain_halted");
|
|
4073
4075
|
return a;
|
|
4074
4076
|
});
|
|
4075
|
-
|
|
4077
|
+
B(this, ae, ({ chain: t, wallet: n, walletMethods: a }) => {
|
|
4076
4078
|
this.connectedChains[t] = n, this.connectedWallets[t] = a;
|
|
4077
4079
|
});
|
|
4078
|
-
|
|
4079
|
-
assetValue: {
|
|
4080
|
+
B(this, K, async ({
|
|
4081
|
+
assetValue: { getBaseValue: t, address: n, chain: a, isGasAsset: s, isSynthetic: r },
|
|
4080
4082
|
type: o = "checkOnly",
|
|
4081
4083
|
contractAddress: p
|
|
4082
4084
|
}) => {
|
|
@@ -4089,24 +4091,24 @@ class Pn {
|
|
|
4089
4091
|
const _ = this.getAddress(a);
|
|
4090
4092
|
if (!n || !_)
|
|
4091
4093
|
throw new m("core_approve_asset_address_or_from_not_found");
|
|
4092
|
-
const
|
|
4094
|
+
const w = p || (await f(this, V).call(this, a)).router;
|
|
4093
4095
|
return c({
|
|
4094
|
-
amount: t,
|
|
4096
|
+
amount: t("bigint"),
|
|
4095
4097
|
assetAddress: n,
|
|
4096
4098
|
from: _,
|
|
4097
|
-
spenderAddress:
|
|
4099
|
+
spenderAddress: w
|
|
4098
4100
|
});
|
|
4099
4101
|
});
|
|
4100
|
-
|
|
4102
|
+
B(this, N, async ({
|
|
4101
4103
|
assetValue: t,
|
|
4102
4104
|
memo: n,
|
|
4103
|
-
feeOptionKey: a =
|
|
4105
|
+
feeOptionKey: a = F.Fast
|
|
4104
4106
|
}) => {
|
|
4105
4107
|
const {
|
|
4106
4108
|
gas_rate: s,
|
|
4107
4109
|
router: r,
|
|
4108
4110
|
address: o
|
|
4109
|
-
} = await f(this,
|
|
4111
|
+
} = await f(this, V).call(this, t.chain), p = (parseInt(s) || 0) * ft[a];
|
|
4110
4112
|
return this.deposit({
|
|
4111
4113
|
assetValue: t,
|
|
4112
4114
|
recipient: o,
|
|
@@ -4115,13 +4117,13 @@ class Pn {
|
|
|
4115
4117
|
feeRate: p
|
|
4116
4118
|
});
|
|
4117
4119
|
});
|
|
4118
|
-
|
|
4120
|
+
B(this, Y, async ({ memo: t, assetValue: n }) => {
|
|
4119
4121
|
const a = await cn(this.stagenet);
|
|
4120
4122
|
if (a.HALTCHAINGLOBAL >= 1 || a.HALTTHORCHAIN >= 1)
|
|
4121
4123
|
throw new m("core_chain_halted");
|
|
4122
4124
|
return this.deposit({ assetValue: n, recipient: "", memo: t });
|
|
4123
4125
|
});
|
|
4124
|
-
|
|
4126
|
+
B(this, X, ({ assetValue: t, ...n }) => ({
|
|
4125
4127
|
...n,
|
|
4126
4128
|
memo: n.memo || "",
|
|
4127
4129
|
from: this.getAddress(t.chain),
|
|
@@ -4130,7 +4132,7 @@ class Pn {
|
|
|
4130
4132
|
this.stagenet = !!t;
|
|
4131
4133
|
}
|
|
4132
4134
|
}
|
|
4133
|
-
|
|
4135
|
+
V = new WeakMap(), ae = new WeakMap(), K = new WeakMap(), N = new WeakMap(), Y = new WeakMap(), X = new WeakMap();
|
|
4134
4136
|
export {
|
|
4135
4137
|
Ze as AGG_SWAP,
|
|
4136
4138
|
hn as ApiError,
|
|
@@ -4153,7 +4155,7 @@ export {
|
|
|
4153
4155
|
Me as ERROR_TYPE,
|
|
4154
4156
|
fn as EVMChainList,
|
|
4155
4157
|
dt as ErrorCode,
|
|
4156
|
-
|
|
4158
|
+
F as FeeOption,
|
|
4157
4159
|
h as MemoType,
|
|
4158
4160
|
_n as NetworkDerivationPath,
|
|
4159
4161
|
ze as QuoteMode,
|
|
@@ -4163,7 +4165,7 @@ export {
|
|
|
4163
4165
|
tt as SWAP_OUT,
|
|
4164
4166
|
Pn as SwapKitCore,
|
|
4165
4167
|
m as SwapKitError,
|
|
4166
|
-
|
|
4168
|
+
x as SwapKitNumber,
|
|
4167
4169
|
Je as TCAvalancheDepositABI,
|
|
4168
4170
|
Qe as TCBscDepositABI,
|
|
4169
4171
|
Xe as TCEthereumVaultAbi,
|
|
@@ -4185,7 +4187,7 @@ export {
|
|
|
4185
4187
|
Be as getDecimal,
|
|
4186
4188
|
Cn as getEstimatedPoolShare,
|
|
4187
4189
|
Mn as getLiquiditySlippage,
|
|
4188
|
-
|
|
4190
|
+
D as getMemoFor,
|
|
4189
4191
|
ve as getMinAmountByChain,
|
|
4190
4192
|
Ot as getSymmetricPoolShare,
|
|
4191
4193
|
vn as getSymmetricWithdraw,
|