@swapkit/core 1.0.0-rc.26 → 1.0.0-rc.28
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 +106 -122
- package/package.json +14 -14
- package/src/client/index.ts +15 -18
package/dist/index.es.js
CHANGED
|
@@ -775,23 +775,23 @@ const fn = [
|
|
|
775
775
|
"THOR"
|
|
776
776
|
/* THORChain */
|
|
777
777
|
];
|
|
778
|
-
var
|
|
779
|
-
const ae = Object.values(i), it = Object.keys(i),
|
|
778
|
+
var _e = /* @__PURE__ */ ((e) => (e.Arbitrum = "42161", e.ArbitrumHex = "0xa4b1", e.Avalanche = "43114", e.AvalancheHex = "0xa86a", e.Binance = "Binance-Chain-Tigris", e.BinanceSmartChain = "56", e.BinanceSmartChainHex = "0x38", e.Bitcoin = "bitcoin", e.BitcoinCash = "bitcoincash", e.Cosmos = "cosmoshub-4", e.Dogecoin = "dogecoin", e.Kujira = "kaiyo-1", e.Ethereum = "1", e.EthereumHex = "0x1", e.Litecoin = "litecoin", e.Maya = "mayachain-mainnet-v1", e.MayaStagenet = "mayachain-stagenet-v1", e.Optimism = "10", e.OptimismHex = "0xa", e.Polygon = "137", e.PolygonHex = "0x89", e.THORChain = "thorchain-mainnet-v1", e.THORChainStagenet = "thorchain-stagenet-v2", e))(_e || {}), Ne = /* @__PURE__ */ ((e) => (e.Arbitrum = "https://arb1.arbitrum.io/rpc", e.Avalanche = "https://node-router.thorswap.net/avalanche-c", e.Binance = "", e.BinanceSmartChain = "https://bsc-dataseed.binance.org", e.Bitcoin = "https://node-router.thorswap.net/bitcoin", e.BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash", e.Cosmos = "https://node-router.thorswap.net/cosmos/rpc", e.Kujira = "https://rpc-kujira.synergynodes.com/", e.Dogecoin = "https://node-router.thorswap.net/dogecoin", e.Ethereum = "https://node-router.thorswap.net/ethereum", e.Litecoin = "https://node-router.thorswap.net/litecoin", e.Maya = "https://tendermint.mayachain.info", e.MayaStagenet = "https://stagenet.tendermint.mayachain.info", e.Optimism = "https://mainnet.optimism.io", e.Polygon = "https://polygon-rpc.com", e.THORChain = "https://rpc.thorswap.net", e.THORChainStagenet = "https://stagenet-rpc.ninerealms.com", e))(Ne || {}), q = /* @__PURE__ */ ((e) => (e.Cosmos = "https://node-router.thorswap.net/cosmos/rest", e.Kujira = "https://lcd-kujira.synergynodes.com/", e.MayanodeMainnet = "https://mayanode.mayachain.info", e.MayanodeStagenet = "https://stagenet.mayanode.mayachain.info", e.ThornodeMainnet = "https://thornode.thorswap.net", e.ThornodeStagenet = "https://stagenet-thornode.ninerealms.com", e.ThorswapApi = "https://api.thorswap.finance", e.ThorswapStatic = "https://static.thorswap.net", e))(q || {});
|
|
779
|
+
const ae = Object.values(i), it = Object.keys(i), fe = ae.reduce(
|
|
780
780
|
(e, t) => {
|
|
781
781
|
const n = it.find((a) => i[a] === t);
|
|
782
782
|
return n && (e[t] = n), e;
|
|
783
783
|
},
|
|
784
784
|
{}
|
|
785
785
|
), rt = ae.reduce(
|
|
786
|
-
(e, t) => (e[t] =
|
|
786
|
+
(e, t) => (e[t] = _e[fe[t]], e),
|
|
787
787
|
{}
|
|
788
788
|
), ot = ae.reduce(
|
|
789
|
-
(e, t) => (e[t] = Ne[
|
|
789
|
+
(e, t) => (e[t] = Ne[fe[t]], e),
|
|
790
790
|
{}
|
|
791
791
|
), En = ae.reduce(
|
|
792
792
|
(e, t) => {
|
|
793
|
-
const n = `${
|
|
794
|
-
return e[t] =
|
|
793
|
+
const n = `${fe[t]}Hex`;
|
|
794
|
+
return e[t] = _e[n], e;
|
|
795
795
|
},
|
|
796
796
|
{}
|
|
797
797
|
), Rn = {
|
|
@@ -839,14 +839,14 @@ const ae = Object.values(i), it = Object.keys(i), _e = ae.reduce(
|
|
|
839
839
|
var pt = /* @__PURE__ */ ((e) => (e[e.NoError = 36864] = "NoError", e))(pt || {}), 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 || {}), dt = /* @__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))(dt || {}), ut = Object.defineProperty, lt = (e, t, n) => t in e ? ut(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, C = (e, t, n) => (lt(e, typeof t != "symbol" ? t + "" : t, n), n), yt = (e, t, n) => {
|
|
840
840
|
if (!t.has(e))
|
|
841
841
|
throw TypeError("Cannot " + n);
|
|
842
|
-
},
|
|
842
|
+
}, V = (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
|
}, 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
|
-
const { result: n } = await
|
|
849
|
+
const { result: n } = await we.post(ot[e], {
|
|
850
850
|
headers: {
|
|
851
851
|
accept: "*/*",
|
|
852
852
|
"content-type": "application/json",
|
|
@@ -1090,7 +1090,7 @@ const ct = "0x313ce567", De = async ({ chain: e, to: t }) => {
|
|
|
1090
1090
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
1091
1091
|
return !!e.match(t);
|
|
1092
1092
|
}, Dn = ([e, t, n, a, s]) => `${e}'/${t}'/${n}'/${a}${typeof s != "number" ? "" : `/${s}`}`;
|
|
1093
|
-
class
|
|
1093
|
+
class Ae extends Error {
|
|
1094
1094
|
constructor(t, n, a) {
|
|
1095
1095
|
const s = t.status || t.status === 0 ? t.status : "", r = t.statusText || "", o = `${s} ${r}`.trim(), p = o ? `status code ${o}` : "an unknown error";
|
|
1096
1096
|
super(`Request failed with ${p}`), Object.defineProperty(this, "response", {
|
|
@@ -1125,20 +1125,20 @@ const Q = (e) => e !== null && typeof e == "object", J = (...e) => {
|
|
|
1125
1125
|
for (const t of e)
|
|
1126
1126
|
if ((!Q(t) || Array.isArray(t)) && t !== void 0)
|
|
1127
1127
|
throw new TypeError("The `options` argument must be an object");
|
|
1128
|
-
return
|
|
1128
|
+
return be({}, ...e);
|
|
1129
1129
|
}, Be = (e = {}, t = {}) => {
|
|
1130
1130
|
const n = new globalThis.Headers(e), a = t instanceof globalThis.Headers, s = new globalThis.Headers(t);
|
|
1131
1131
|
for (const [r, o] of s.entries())
|
|
1132
1132
|
a && o === "undefined" || o === void 0 ? n.delete(r) : n.set(r, o);
|
|
1133
1133
|
return n;
|
|
1134
|
-
},
|
|
1134
|
+
}, be = (...e) => {
|
|
1135
1135
|
let t = {}, n = {};
|
|
1136
1136
|
for (const a of e)
|
|
1137
1137
|
if (Array.isArray(a))
|
|
1138
1138
|
Array.isArray(t) || (t = []), t = [...t, ...a];
|
|
1139
1139
|
else if (Q(a)) {
|
|
1140
1140
|
for (let [s, r] of Object.entries(a))
|
|
1141
|
-
Q(r) && s in t && (r =
|
|
1141
|
+
Q(r) && s in t && (r = be(t[s], r)), t = { ...t, [s]: r };
|
|
1142
1142
|
Q(a.headers) && (n = Be(n, a.headers), t.headers = n);
|
|
1143
1143
|
}
|
|
1144
1144
|
return t;
|
|
@@ -1153,13 +1153,13 @@ const Q = (e) => e !== null && typeof e == "object", J = (...e) => {
|
|
|
1153
1153
|
return e = !0, "half";
|
|
1154
1154
|
}
|
|
1155
1155
|
}).headers.has("Content-Type")), e && !t;
|
|
1156
|
-
})(), vt = typeof globalThis.AbortController == "function", Ct = typeof globalThis.ReadableStream == "function", Mt = typeof globalThis.FormData == "function",
|
|
1156
|
+
})(), vt = typeof globalThis.AbortController == "function", Ct = typeof globalThis.ReadableStream == "function", Mt = typeof globalThis.FormData == "function", Le = ["get", "post", "put", "patch", "head", "delete"], Nt = {
|
|
1157
1157
|
json: "application/json",
|
|
1158
1158
|
text: "text/*",
|
|
1159
1159
|
formData: "multipart/form-data",
|
|
1160
1160
|
arrayBuffer: "*/*",
|
|
1161
1161
|
blob: "*/*"
|
|
1162
|
-
}, re = 2147483647,
|
|
1162
|
+
}, re = 2147483647, Ve = Symbol("stop"), xt = {
|
|
1163
1163
|
json: !0,
|
|
1164
1164
|
parseJson: !0,
|
|
1165
1165
|
searchParams: !0,
|
|
@@ -1186,18 +1186,18 @@ const Q = (e) => e !== null && typeof e == "object", J = (...e) => {
|
|
|
1186
1186
|
window: !0,
|
|
1187
1187
|
dispatcher: !0,
|
|
1188
1188
|
duplex: !0
|
|
1189
|
-
}, Pt = (e) =>
|
|
1189
|
+
}, Pt = (e) => Le.includes(e) ? e.toUpperCase() : e, Bt = ["get", "put", "head", "delete", "options", "trace"], Lt = [408, 413, 429, 500, 502, 503, 504], Ue = [413, 429, 503], Ee = {
|
|
1190
1190
|
limit: 2,
|
|
1191
1191
|
methods: Bt,
|
|
1192
|
-
statusCodes:
|
|
1192
|
+
statusCodes: Lt,
|
|
1193
1193
|
afterStatusCodes: Ue,
|
|
1194
1194
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
1195
1195
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
1196
1196
|
delay: (e) => 0.3 * 2 ** (e - 1) * 1e3
|
|
1197
|
-
},
|
|
1197
|
+
}, Vt = (e = {}) => {
|
|
1198
1198
|
if (typeof e == "number")
|
|
1199
1199
|
return {
|
|
1200
|
-
...
|
|
1200
|
+
...Ee,
|
|
1201
1201
|
limit: e
|
|
1202
1202
|
};
|
|
1203
1203
|
if (e.methods && !Array.isArray(e.methods))
|
|
@@ -1205,7 +1205,7 @@ const Q = (e) => e !== null && typeof e == "object", J = (...e) => {
|
|
|
1205
1205
|
if (e.statusCodes && !Array.isArray(e.statusCodes))
|
|
1206
1206
|
throw new Error("retry.statusCodes must be an array");
|
|
1207
1207
|
return {
|
|
1208
|
-
...
|
|
1208
|
+
...Ee,
|
|
1209
1209
|
...e,
|
|
1210
1210
|
afterStatusCodes: Ue
|
|
1211
1211
|
};
|
|
@@ -1249,7 +1249,7 @@ class Z {
|
|
|
1249
1249
|
d instanceof globalThis.Response && (o = d);
|
|
1250
1250
|
}
|
|
1251
1251
|
if (a._decorateResponse(o), !o.ok && a._options.throwHttpErrors) {
|
|
1252
|
-
let p = new
|
|
1252
|
+
let p = new Ae(o, a.request, a._options);
|
|
1253
1253
|
for (const d of a._options.hooks.beforeError)
|
|
1254
1254
|
p = await d(p);
|
|
1255
1255
|
throw p;
|
|
@@ -1309,7 +1309,7 @@ class Z {
|
|
|
1309
1309
|
credentials: this._input.credentials || "same-origin",
|
|
1310
1310
|
...n,
|
|
1311
1311
|
headers: Be(this._input.headers, n.headers),
|
|
1312
|
-
hooks:
|
|
1312
|
+
hooks: be({
|
|
1313
1313
|
beforeRequest: [],
|
|
1314
1314
|
beforeRetry: [],
|
|
1315
1315
|
beforeError: [],
|
|
@@ -1318,7 +1318,7 @@ class Z {
|
|
|
1318
1318
|
method: Pt(n.method ?? this._input.method),
|
|
1319
1319
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
1320
1320
|
prefixUrl: String(n.prefixUrl || ""),
|
|
1321
|
-
retry:
|
|
1321
|
+
retry: Vt(n.retry),
|
|
1322
1322
|
throwHttpErrors: n.throwHttpErrors !== !1,
|
|
1323
1323
|
timeout: n.timeout ?? 1e4,
|
|
1324
1324
|
fetch: n.fetch ?? globalThis.fetch.bind(globalThis)
|
|
@@ -1346,7 +1346,7 @@ class Z {
|
|
|
1346
1346
|
}
|
|
1347
1347
|
_calculateRetryDelay(t) {
|
|
1348
1348
|
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof Pe)) {
|
|
1349
|
-
if (t instanceof
|
|
1349
|
+
if (t instanceof Ae) {
|
|
1350
1350
|
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
1351
1351
|
return 0;
|
|
1352
1352
|
const a = t.response.headers.get("Retry-After");
|
|
@@ -1378,7 +1378,7 @@ class Z {
|
|
|
1378
1378
|
options: this._options,
|
|
1379
1379
|
error: n,
|
|
1380
1380
|
retryCount: this._retryCount
|
|
1381
|
-
}) ===
|
|
1381
|
+
}) === Ve)
|
|
1382
1382
|
return;
|
|
1383
1383
|
return this._retry(t);
|
|
1384
1384
|
}
|
|
@@ -1433,20 +1433,20 @@ class Z {
|
|
|
1433
1433
|
}
|
|
1434
1434
|
}
|
|
1435
1435
|
/*! MIT License © Sindre Sorhus */
|
|
1436
|
-
const
|
|
1436
|
+
const pe = (e) => {
|
|
1437
1437
|
const t = (n, a) => Z.create(n, J(e, a));
|
|
1438
|
-
for (const n of
|
|
1438
|
+
for (const n of Le)
|
|
1439
1439
|
t[n] = (a, s) => Z.create(a, J(e, s, { method: n }));
|
|
1440
|
-
return t.create = (n) =>
|
|
1441
|
-
}, kt =
|
|
1442
|
-
get: (e, t) =>
|
|
1443
|
-
post: (e, t) =>
|
|
1444
|
-
},
|
|
1440
|
+
return t.create = (n) => pe(J(n)), t.extend = (n) => pe(J(e, n)), t.stop = Ve, t;
|
|
1441
|
+
}, kt = pe(), Ft = kt, Gt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, Re = Ft.create({ headers: Gt }), we = {
|
|
1442
|
+
get: (e, t) => Re.get(e, t).json(),
|
|
1443
|
+
post: (e, t) => Re.post(e, t).json()
|
|
1444
|
+
}, ge = Object.values(i), Wt = (e = "") => {
|
|
1445
1445
|
const t = e.toUpperCase(), [n] = t.split(".");
|
|
1446
|
-
if (
|
|
1446
|
+
if (ge.includes(n))
|
|
1447
1447
|
return !0;
|
|
1448
1448
|
const [a] = t.split("/");
|
|
1449
|
-
if (
|
|
1449
|
+
if (ge.includes(a))
|
|
1450
1450
|
return !0;
|
|
1451
1451
|
throw new Error(
|
|
1452
1452
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
@@ -1468,14 +1468,14 @@ function se({
|
|
|
1468
1468
|
""
|
|
1469
1469
|
);
|
|
1470
1470
|
}
|
|
1471
|
-
var U, k,
|
|
1471
|
+
var U, k, de, He, ue, Oe, ee, le, $, W, te, ye;
|
|
1472
1472
|
const qt = class $e {
|
|
1473
1473
|
constructor(t) {
|
|
1474
|
-
|
|
1475
|
-
const n =
|
|
1474
|
+
V(this, U), V(this, de), V(this, ue), V(this, ee), V(this, $), V(this, te), C(this, "decimalMultiplier", 10n ** 8n), C(this, "bigIntValue", 0n), C(this, "decimal");
|
|
1475
|
+
const n = me(t);
|
|
1476
1476
|
this.decimal = typeof t == "object" ? t.decimal : void 0, this.decimalMultiplier = H(
|
|
1477
|
-
Math.max(R(this, te,
|
|
1478
|
-
), R(this,
|
|
1477
|
+
Math.max(R(this, te, ye).call(this, R(this, $, W).call(this, n)), this.decimal || 0)
|
|
1478
|
+
), R(this, de, He).call(this, n);
|
|
1479
1479
|
}
|
|
1480
1480
|
static fromBigInt(t, n) {
|
|
1481
1481
|
return new $e({
|
|
@@ -1493,24 +1493,6 @@ const qt = class $e {
|
|
|
1493
1493
|
a
|
|
1494
1494
|
);
|
|
1495
1495
|
}
|
|
1496
|
-
/**
|
|
1497
|
-
* @deprecated Use `getBaseValue('string')` instead
|
|
1498
|
-
*/
|
|
1499
|
-
get baseValue() {
|
|
1500
|
-
return this.getBaseValue("string");
|
|
1501
|
-
}
|
|
1502
|
-
/**
|
|
1503
|
-
* @deprecated Use `getBaseValue('number')` instead
|
|
1504
|
-
*/
|
|
1505
|
-
get baseValueNumber() {
|
|
1506
|
-
return this.getBaseValue("number");
|
|
1507
|
-
}
|
|
1508
|
-
/**
|
|
1509
|
-
* @deprecated Use `getBaseValue('bigint')` instead
|
|
1510
|
-
*/
|
|
1511
|
-
get baseValueBigInt() {
|
|
1512
|
-
return this.getBaseValue("bigint");
|
|
1513
|
-
}
|
|
1514
1496
|
set(t) {
|
|
1515
1497
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
1516
1498
|
}
|
|
@@ -1569,8 +1551,8 @@ const qt = class $e {
|
|
|
1569
1551
|
getBigIntValue(t, n) {
|
|
1570
1552
|
if (!n && typeof t == "object")
|
|
1571
1553
|
return t.bigIntValue;
|
|
1572
|
-
const a =
|
|
1573
|
-
return s === "0" || s === "undefined" ? 0n : R(this, ee,
|
|
1554
|
+
const a = me(t), s = R(this, $, W).call(this, a);
|
|
1555
|
+
return s === "0" || s === "undefined" ? 0n : R(this, ee, le).call(this, s, n);
|
|
1574
1556
|
}
|
|
1575
1557
|
formatBigIntToSafeValue(t, n) {
|
|
1576
1558
|
const a = n || this.decimal || j, s = Math.max(
|
|
@@ -1617,9 +1599,18 @@ const qt = class $e {
|
|
|
1617
1599
|
const o = 10 ** (s * 3);
|
|
1618
1600
|
return `${(n / o).toFixed(t)}${r}`;
|
|
1619
1601
|
}
|
|
1602
|
+
toCurrency(t = "$", {
|
|
1603
|
+
currencyPosition: n = "start",
|
|
1604
|
+
decimal: a = 2,
|
|
1605
|
+
decimalSeparator: s = ".",
|
|
1606
|
+
thousandSeparator: r = ","
|
|
1607
|
+
} = {}) {
|
|
1608
|
+
const o = this.getValue("number"), [p, d = ""] = o.toFixed(6).split("."), y = p.replace(/\B(?=(\d{3})+(?!\d))/g, r), u = !p && !d ? "0.00" : p === "0" ? `${parseFloat(`0.${d}`)}`.replace(".", s) : `${y}${d ? `${s}${d.slice(0, a)}` : ""}`;
|
|
1609
|
+
return `${n === "start" ? t : ""}${u}${n === "end" ? t : ""}`;
|
|
1610
|
+
}
|
|
1620
1611
|
};
|
|
1621
1612
|
U = /* @__PURE__ */ new WeakSet(), k = function(e, ...t) {
|
|
1622
|
-
const n = R(this,
|
|
1613
|
+
const n = R(this, ue, Oe).call(this, this, ...t), a = H(n), s = t.reduce(
|
|
1623
1614
|
(o, p) => {
|
|
1624
1615
|
const d = this.getBigIntValue(p, n);
|
|
1625
1616
|
switch (e) {
|
|
@@ -1646,49 +1637,49 @@ U = /* @__PURE__ */ new WeakSet(), k = function(e, ...t) {
|
|
|
1646
1637
|
value: s
|
|
1647
1638
|
});
|
|
1648
1639
|
return new this.constructor({ decimal: this.decimal, value: r, identifier: this.toString() });
|
|
1649
|
-
},
|
|
1640
|
+
}, de = /* @__PURE__ */ new WeakSet(), He = function(e) {
|
|
1650
1641
|
const t = R(this, $, W).call(this, e) || "0";
|
|
1651
|
-
this.bigIntValue = R(this, ee,
|
|
1652
|
-
},
|
|
1642
|
+
this.bigIntValue = R(this, ee, le).call(this, t);
|
|
1643
|
+
}, ue = /* @__PURE__ */ new WeakSet(), Oe = function(...e) {
|
|
1653
1644
|
const t = e.map(
|
|
1654
|
-
(n) => typeof n == "object" ? n.decimal || G(n.decimalMultiplier) : R(this, te,
|
|
1645
|
+
(n) => typeof n == "object" ? n.decimal || G(n.decimalMultiplier) : R(this, te, ye).call(this, R(this, $, W).call(this, n))
|
|
1655
1646
|
).filter(Boolean);
|
|
1656
1647
|
return Math.max(...t, j);
|
|
1657
|
-
}, ee = /* @__PURE__ */ new WeakSet(),
|
|
1648
|
+
}, ee = /* @__PURE__ */ new WeakSet(), le = function(e, t) {
|
|
1658
1649
|
const n = t ? H(t) : this.decimalMultiplier, a = G(n), [s = "", r = ""] = e.split(".");
|
|
1659
1650
|
return BigInt(`${s}${r.padEnd(a, "0")}`);
|
|
1660
1651
|
}, $ = /* @__PURE__ */ new WeakSet(), W = function(e) {
|
|
1661
1652
|
const t = `${typeof e == "number" ? Number(e).toLocaleString("fullwide", {
|
|
1662
1653
|
useGrouping: !1,
|
|
1663
1654
|
maximumFractionDigits: 20
|
|
1664
|
-
}) :
|
|
1655
|
+
}) : me(e)}`.replaceAll(",", ".").split(".");
|
|
1665
1656
|
return t.length > 1 ? `${t.slice(0, -1).join("")}.${t.at(-1)}` : t[0];
|
|
1666
|
-
}, te = /* @__PURE__ */ new WeakSet(),
|
|
1657
|
+
}, te = /* @__PURE__ */ new WeakSet(), ye = function(e) {
|
|
1667
1658
|
var t;
|
|
1668
1659
|
const n = ((t = e.split(".")[1]) == null ? void 0 : t.length) || 0;
|
|
1669
1660
|
return Math.max(n, j);
|
|
1670
1661
|
};
|
|
1671
|
-
let
|
|
1672
|
-
function
|
|
1662
|
+
let ce = qt;
|
|
1663
|
+
function me(e) {
|
|
1673
1664
|
return typeof e == "object" ? "getValue" in e ? e.getValue("string") : e.value : e;
|
|
1674
1665
|
}
|
|
1675
1666
|
const z = (e, t) => typeof e == "bigint" ? se({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1676
|
-
let
|
|
1677
|
-
const
|
|
1678
|
-
if (!
|
|
1667
|
+
let Te;
|
|
1668
|
+
const Ie = (e) => {
|
|
1669
|
+
if (!Te)
|
|
1679
1670
|
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
|
|
1680
|
-
return
|
|
1681
|
-
},
|
|
1671
|
+
return Te.get(e.toUpperCase()) || { decimal: A.THOR, identifier: "" };
|
|
1672
|
+
}, Se = async (e, t = 0) => {
|
|
1682
1673
|
Wt(e);
|
|
1683
|
-
const n = await _t(
|
|
1674
|
+
const n = await _t(he(e)), a = z(t, n);
|
|
1684
1675
|
return new N({ decimal: n, value: a, identifier: e });
|
|
1685
1676
|
};
|
|
1686
|
-
class N extends
|
|
1677
|
+
class N extends ce {
|
|
1687
1678
|
constructor(t) {
|
|
1688
1679
|
super(
|
|
1689
|
-
t.value instanceof
|
|
1680
|
+
t.value instanceof ce ? t.value : { decimal: t.decimal, value: t.value }
|
|
1690
1681
|
), C(this, "address"), C(this, "chain"), C(this, "isSynthetic", !1), C(this, "isGasAsset", !1), C(this, "symbol"), C(this, "ticker"), C(this, "type");
|
|
1691
|
-
const n = "identifier" in t ? t.identifier : `${t.chain}.${t.symbol}`, a =
|
|
1682
|
+
const n = "identifier" in t ? t.identifier : `${t.chain}.${t.symbol}`, a = he(n);
|
|
1692
1683
|
this.type = At(a), this.chain = a.chain, this.ticker = a.ticker, this.symbol = a.symbol, this.address = a.address, this.isSynthetic = a.isSynthetic, this.isGasAsset = a.isGasAsset;
|
|
1693
1684
|
}
|
|
1694
1685
|
get assetValue() {
|
|
@@ -1705,19 +1696,19 @@ class N extends ye {
|
|
|
1705
1696
|
return this.chain === t && this.symbol === n;
|
|
1706
1697
|
}
|
|
1707
1698
|
static async fromString(t, n = 0) {
|
|
1708
|
-
return
|
|
1699
|
+
return Se(t, n);
|
|
1709
1700
|
}
|
|
1710
1701
|
static fromStringSync(t, n = 0) {
|
|
1711
|
-
const { isSynthetic: a } =
|
|
1702
|
+
const { isSynthetic: a } = he(t), { decimal: s, identifier: r } = Ie(
|
|
1712
1703
|
t
|
|
1713
1704
|
), o = z(n, s);
|
|
1714
1705
|
return r ? new N({ decimal: s, identifier: r, value: o }) : a ? new N({ decimal: 8, identifier: t, value: o }) : void 0;
|
|
1715
1706
|
}
|
|
1716
1707
|
static async fromIdentifier(t, n = 0) {
|
|
1717
|
-
return
|
|
1708
|
+
return Se(t, n);
|
|
1718
1709
|
}
|
|
1719
1710
|
static fromIdentifierSync(t, n = 0) {
|
|
1720
|
-
const { decimal: a, identifier: s } =
|
|
1711
|
+
const { decimal: a, identifier: s } = Ie(t), r = z(n, a);
|
|
1721
1712
|
return new N({ decimal: a, identifier: s, value: r });
|
|
1722
1713
|
}
|
|
1723
1714
|
static fromChainOrSignature(t, n = 0) {
|
|
@@ -1735,7 +1726,7 @@ class N extends ye {
|
|
|
1735
1726
|
NativeList: s,
|
|
1736
1727
|
...r
|
|
1737
1728
|
} = await import("@swapkit/tokens");
|
|
1738
|
-
|
|
1729
|
+
Te = [s, ...Object.values(r)].reduce(
|
|
1739
1730
|
(o, { tokens: p }) => (p.forEach(({ identifier: d, chain: y, ...u }) => {
|
|
1740
1731
|
const c = "decimals" in u ? u.decimals : A[y];
|
|
1741
1732
|
o.set(d, { identifier: d, decimal: c });
|
|
@@ -1753,25 +1744,25 @@ class N extends ye {
|
|
|
1753
1744
|
);
|
|
1754
1745
|
}
|
|
1755
1746
|
}
|
|
1756
|
-
const
|
|
1747
|
+
const oe = (e) => {
|
|
1757
1748
|
const t = N.fromChainOrSignature(e);
|
|
1758
1749
|
switch (e) {
|
|
1759
1750
|
case i.Bitcoin:
|
|
1760
1751
|
case i.Litecoin:
|
|
1761
1752
|
case i.BitcoinCash:
|
|
1762
|
-
return t.
|
|
1753
|
+
return t.set(10001e-8);
|
|
1763
1754
|
case i.Dogecoin:
|
|
1764
|
-
return t.
|
|
1755
|
+
return t.set(1.00000001);
|
|
1765
1756
|
case i.Avalanche:
|
|
1766
1757
|
case i.Ethereum:
|
|
1767
|
-
return t.
|
|
1758
|
+
return t.set(1e-8);
|
|
1768
1759
|
case i.THORChain:
|
|
1769
1760
|
case i.Maya:
|
|
1770
|
-
return t.
|
|
1761
|
+
return t.set(0);
|
|
1771
1762
|
default:
|
|
1772
|
-
return t.
|
|
1763
|
+
return t.set(1e-8);
|
|
1773
1764
|
}
|
|
1774
|
-
},
|
|
1765
|
+
}, he = (e) => {
|
|
1775
1766
|
const t = e.slice(0, 14).includes("/"), [n, a] = e.split(".").pop().split("/"), s = e.includes(".") && !t ? e : `${i.THORChain}.${a}`, [r, o] = s.split("."), [p, d] = (t ? a : o).split("-");
|
|
1776
1767
|
return {
|
|
1777
1768
|
address: d == null ? void 0 : d.toLowerCase(),
|
|
@@ -1843,7 +1834,7 @@ class m extends Error {
|
|
|
1843
1834
|
console.error(n), super(t, { cause: { code: jt[t], message: t } }), Object.setPrototypeOf(this, m.prototype);
|
|
1844
1835
|
}
|
|
1845
1836
|
}
|
|
1846
|
-
class D extends
|
|
1837
|
+
class D extends ce {
|
|
1847
1838
|
eq(t) {
|
|
1848
1839
|
return this.eqValue(t);
|
|
1849
1840
|
}
|
|
@@ -3653,15 +3644,15 @@ const Kt = [
|
|
|
3653
3644
|
}
|
|
3654
3645
|
}, yn = (e) => {
|
|
3655
3646
|
const t = e ? q.ThornodeStagenet : q.ThornodeMainnet;
|
|
3656
|
-
return
|
|
3647
|
+
return we.get(`${t}/thorchain/inbound_addresses`);
|
|
3657
3648
|
}, cn = (e) => {
|
|
3658
3649
|
const t = e ? q.ThornodeStagenet : q.ThornodeMainnet;
|
|
3659
|
-
return
|
|
3650
|
+
return we.get(`${t}/thorchain/mimir`);
|
|
3660
3651
|
}, ve = () => Object.values(i).reduce(
|
|
3661
3652
|
(e, t) => (e[t] = null, e),
|
|
3662
3653
|
{}
|
|
3663
3654
|
);
|
|
3664
|
-
var
|
|
3655
|
+
var L, ne, K, M, Y, X;
|
|
3665
3656
|
class Pn {
|
|
3666
3657
|
constructor({ stagenet: t } = {}) {
|
|
3667
3658
|
T(this, "connectedChains", ve());
|
|
@@ -3705,7 +3696,7 @@ class Pn {
|
|
|
3705
3696
|
const y = await N.fromString(a.calldata.fromAsset);
|
|
3706
3697
|
if (!y)
|
|
3707
3698
|
throw new m("core_swap_asset_not_recognized");
|
|
3708
|
-
const { address: u } = await f(this,
|
|
3699
|
+
const { address: u } = await f(this, L).call(this, y.chain), {
|
|
3709
3700
|
contract: c,
|
|
3710
3701
|
calldata: { expiration: _, amountIn: b, memo: w, memoStreamingSwap: E }
|
|
3711
3702
|
} = a, O = y.add(D.fromBigInt(BigInt(b), y.decimal)), I = t && E || w;
|
|
@@ -3800,7 +3791,7 @@ class Pn {
|
|
|
3800
3791
|
const { getChecksumAddressFromAsset: u } = await import("@swapkit/toolbox-evm"), c = r === i.Avalanche ? Xe : r === i.BinanceSmartChain ? Je : Ye;
|
|
3801
3792
|
return await d.call({
|
|
3802
3793
|
abi: c,
|
|
3803
|
-
contractAddress: a || (await f(this,
|
|
3794
|
+
contractAddress: a || (await f(this, L).call(this, r)).router,
|
|
3804
3795
|
funcName: "depositWithExpiry",
|
|
3805
3796
|
funcParams: [
|
|
3806
3797
|
n,
|
|
@@ -3900,22 +3891,15 @@ class Pn {
|
|
|
3900
3891
|
from: s,
|
|
3901
3892
|
to: r
|
|
3902
3893
|
}) => {
|
|
3903
|
-
const o = r === "rune" ? N.fromChainOrSignature(i.THORChain) : s === "sym" && r === "sym" || s === "rune" || s === "asset" ? void 0 : n
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
targetAssetString: o == null ? void 0 : o.toString(),
|
|
3913
|
-
singleSide: !1
|
|
3914
|
-
})
|
|
3915
|
-
});
|
|
3916
|
-
} catch (p) {
|
|
3917
|
-
throw new m("core_transaction_withdraw_error", p);
|
|
3918
|
-
}
|
|
3894
|
+
const o = r === "rune" ? N.fromChainOrSignature(i.THORChain) : s === "sym" && r === "sym" || s === "rune" || s === "asset" ? void 0 : n, p = oe(s === "asset" ? n.chain : i.THORChain), d = t || x(h.WITHDRAW, {
|
|
3895
|
+
symbol: n.symbol,
|
|
3896
|
+
chain: n.chain,
|
|
3897
|
+
ticker: n.ticker,
|
|
3898
|
+
basisPoints: Math.max(1e4, Math.round(a * 100)),
|
|
3899
|
+
targetAssetString: o == null ? void 0 : o.toString(),
|
|
3900
|
+
singleSide: !1
|
|
3901
|
+
});
|
|
3902
|
+
return f(this, M).call(this, { assetValue: p, memo: d });
|
|
3919
3903
|
});
|
|
3920
3904
|
T(this, "savings", async ({
|
|
3921
3905
|
assetValue: t,
|
|
@@ -3929,8 +3913,8 @@ class Pn {
|
|
|
3929
3913
|
chain: t.chain,
|
|
3930
3914
|
singleSide: !0,
|
|
3931
3915
|
basisPoints: a ? Math.min(1e4, Math.round(a * 100)) : void 0
|
|
3932
|
-
});
|
|
3933
|
-
return f(this, M).call(this, {
|
|
3916
|
+
}), p = r === h.DEPOSIT ? t : oe(t.chain);
|
|
3917
|
+
return f(this, M).call(this, { memo: o, assetValue: p });
|
|
3934
3918
|
});
|
|
3935
3919
|
T(this, "loan", ({
|
|
3936
3920
|
assetValue: t,
|
|
@@ -3956,7 +3940,7 @@ class Pn {
|
|
|
3956
3940
|
});
|
|
3957
3941
|
return f(this, Y).call(this, {
|
|
3958
3942
|
memo: r,
|
|
3959
|
-
assetValue: t === "bond" ? n :
|
|
3943
|
+
assetValue: t === "bond" ? n : oe(i.THORChain)
|
|
3960
3944
|
});
|
|
3961
3945
|
});
|
|
3962
3946
|
T(this, "registerThorname", ({
|
|
@@ -4043,7 +4027,7 @@ class Pn {
|
|
|
4043
4027
|
T(this, "disconnectChain", (t) => {
|
|
4044
4028
|
this.connectedChains[t] = null, this.connectedWallets[t] = null;
|
|
4045
4029
|
});
|
|
4046
|
-
B(this,
|
|
4030
|
+
B(this, L, async (t) => {
|
|
4047
4031
|
if (t === i.THORChain)
|
|
4048
4032
|
return {
|
|
4049
4033
|
gas_rate: "0",
|
|
@@ -4076,7 +4060,7 @@ class Pn {
|
|
|
4076
4060
|
const _ = this.getAddress(r);
|
|
4077
4061
|
if (!s || !_)
|
|
4078
4062
|
throw new m("core_approve_asset_address_or_from_not_found");
|
|
4079
|
-
const b = a || (await f(this,
|
|
4063
|
+
const b = a || (await f(this, L).call(this, r)).router;
|
|
4080
4064
|
return c({
|
|
4081
4065
|
amount: t.getBaseValue("bigint"),
|
|
4082
4066
|
assetAddress: s,
|
|
@@ -4093,7 +4077,7 @@ class Pn {
|
|
|
4093
4077
|
gas_rate: s,
|
|
4094
4078
|
router: r,
|
|
4095
4079
|
address: o
|
|
4096
|
-
} = await f(this,
|
|
4080
|
+
} = await f(this, L).call(this, t.chain), p = (parseInt(s) || 0) * ft[a];
|
|
4097
4081
|
return this.deposit({
|
|
4098
4082
|
assetValue: t,
|
|
4099
4083
|
recipient: o,
|
|
@@ -4117,16 +4101,16 @@ class Pn {
|
|
|
4117
4101
|
this.stagenet = !!t;
|
|
4118
4102
|
}
|
|
4119
4103
|
}
|
|
4120
|
-
|
|
4104
|
+
L = new WeakMap(), ne = new WeakMap(), K = new WeakMap(), M = new WeakMap(), Y = new WeakMap(), X = new WeakMap();
|
|
4121
4105
|
export {
|
|
4122
4106
|
ze as AGG_SWAP,
|
|
4123
4107
|
hn as ApiError,
|
|
4124
4108
|
q as ApiUrl,
|
|
4125
4109
|
N as AssetValue,
|
|
4126
4110
|
A as BaseDecimal,
|
|
4127
|
-
|
|
4111
|
+
ce as BigIntArithmetics,
|
|
4128
4112
|
i as Chain,
|
|
4129
|
-
|
|
4113
|
+
_e as ChainId,
|
|
4130
4114
|
Rn as ChainIdToChain,
|
|
4131
4115
|
rt as ChainToChainId,
|
|
4132
4116
|
xe as ChainToExplorerUrl,
|
|
@@ -4145,7 +4129,7 @@ export {
|
|
|
4145
4129
|
_n as NetworkDerivationPath,
|
|
4146
4130
|
Qe as QuoteMode,
|
|
4147
4131
|
Ne as RPCUrl,
|
|
4148
|
-
|
|
4132
|
+
we as RequestClient,
|
|
4149
4133
|
Ze as SWAP_IN,
|
|
4150
4134
|
et as SWAP_OUT,
|
|
4151
4135
|
Pn as SwapKitCore,
|
|
@@ -4173,7 +4157,7 @@ export {
|
|
|
4173
4157
|
Cn as getEstimatedPoolShare,
|
|
4174
4158
|
Mn as getLiquiditySlippage,
|
|
4175
4159
|
x as getMemoFor,
|
|
4176
|
-
|
|
4160
|
+
oe as getMinAmountByChain,
|
|
4177
4161
|
Ot as getSymmetricPoolShare,
|
|
4178
4162
|
vn as getSymmetricWithdraw,
|
|
4179
4163
|
Nn as getTHORNameCost,
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss-team",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@swapkit/types": "1.0.0-rc.
|
|
5
|
-
"@swapkit/helpers": "1.0.0-rc.
|
|
4
|
+
"@swapkit/types": "1.0.0-rc.8",
|
|
5
|
+
"@swapkit/helpers": "1.0.0-rc.22"
|
|
6
6
|
},
|
|
7
7
|
"description": "SwapKit Lib core",
|
|
8
8
|
"devDependencies": {
|
|
@@ -12,19 +12,19 @@
|
|
|
12
12
|
"vite-plugin-top-level-await": "1.3.1",
|
|
13
13
|
"vite-plugin-wasm": "3.2.2",
|
|
14
14
|
"vitest": "0.34.4",
|
|
15
|
-
"@internal/config": "0.0.0-
|
|
16
|
-
"@swapkit/api": "1.0.0-rc.
|
|
17
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
18
|
-
"@swapkit/toolbox-cosmos": "1.0.0-rc.
|
|
19
|
-
"@swapkit/toolbox-evm": "1.0.0-rc.
|
|
20
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
15
|
+
"@internal/config": "0.0.0-rc.1",
|
|
16
|
+
"@swapkit/api": "1.0.0-rc.8",
|
|
17
|
+
"@swapkit/tokens": "1.0.0-rc.8",
|
|
18
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.24",
|
|
19
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.24",
|
|
20
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.23"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@swapkit/api": "1.0.0-rc.
|
|
24
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
25
|
-
"@swapkit/toolbox-cosmos": "1.0.0-rc.
|
|
26
|
-
"@swapkit/toolbox-evm": "1.0.0-rc.
|
|
27
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
23
|
+
"@swapkit/api": "1.0.0-rc.8",
|
|
24
|
+
"@swapkit/tokens": "1.0.0-rc.8",
|
|
25
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.24",
|
|
26
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.24",
|
|
27
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.23"
|
|
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.
|
|
55
|
+
"version": "1.0.0-rc.28",
|
|
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",
|