Socket
Socket
Sign inDemoInstall

@swapkit/helpers

Package Overview
Dependencies
Maintainers
1
Versions
203
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swapkit/helpers - npm Package Compare versions

Comparing version 1.0.0-rc.63 to 1.0.0-rc.64

9

dist/index.d.ts

@@ -7,3 +7,2 @@ import { Chain } from '@swapkit/types';

import { MemoType } from '@swapkit/types';
import type { Options } from 'ky';
import type { PancakeswapETHList } from '@swapkit/tokens';

@@ -321,7 +320,2 @@ import type { PancakeswapList } from '@swapkit/tokens';

export declare const RequestClient: {
get: <T>(url: string | URL | Request, options?: Options) => Promise<T>;
post: <T_1>(url: string | URL | Request, options?: Options) => Promise<T_1>;
};
declare type ShareParams<T = {}> = T & {

@@ -374,2 +368,5 @@ liquidityUnits: string;

export * from "@swapkit/api";
export { }

@@ -1,305 +0,43 @@

var bt = Object.defineProperty;
var yt = (s, t, e) => t in s ? bt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
var f = (s, t, e) => (yt(s, typeof t != "symbol" ? t + "" : t, e), e), wt = (s, t, e) => {
if (!t.has(s))
throw TypeError("Cannot " + e);
var ye = Object.defineProperty;
var we = (e, t, n) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
var p = (e, t, n) => (we(e, typeof t != "symbol" ? t + "" : t, n), n), Ve = (e, t, n) => {
if (!t.has(e))
throw TypeError("Cannot " + n);
};
var v = (s, t, e) => {
if (t.has(s))
var O = (e, t, n) => {
if (t.has(e))
throw TypeError("Cannot add the same private member more than once");
t instanceof WeakSet ? t.add(s) : t.set(s, e);
t instanceof WeakSet ? t.add(e) : t.set(e, n);
};
var m = (s, t, e) => (wt(s, t, "access private method"), e);
import { FeeOption as D, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as $t, MemoType as _, ChainToChainId as vt } from "@swapkit/types";
const Tt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
try {
const { result: e } = await Zt.post($t[s], {
headers: {
accept: "*/*",
"content-type": "application/json",
"cache-control": "no-cache"
},
body: JSON.stringify({
id: 44,
jsonrpc: "2.0",
method: "eth_call",
params: [{ to: t.toLowerCase(), data: Tt }, "latest"]
})
});
return parseInt(BigInt(e).toString());
} catch (e) {
return console.error(e), d[s];
}
}, Ct = async (s) => {
if (s === o.Ethereum)
return d.ETH;
const [, t] = s.split("-");
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH;
}, Rt = async (s) => {
const [, t] = s.split("-");
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX;
}, St = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, It = async ({ chain: s, symbol: t }) => {
switch (s) {
case o.Ethereum:
return Ct(t);
case o.Avalanche:
return Rt(t);
case o.BinanceSmartChain:
return St(t);
default:
return d[s];
}
}, ie = {
[D.Average]: 1.2,
[D.Fast]: 1.5,
[D.Fastest]: 2
}, it = ({ chain: s, symbol: t }) => {
switch (s) {
case o.Bitcoin:
case o.BitcoinCash:
case o.Litecoin:
case o.Dogecoin:
case o.Binance:
case o.Ethereum:
case o.Avalanche:
return t === s;
case o.Arbitrum:
case o.Optimism:
return t === "ETH";
case o.Maya:
return t === "CACAO";
case o.Kujira:
return t === "KUJI";
case o.Cosmos:
return t === "ATOM";
case o.Polygon:
return t === "MATIC";
case o.BinanceSmartChain:
return t === "BNB";
case o.THORChain:
return t === "RUNE";
}
}, Ot = (s) => {
switch (s) {
case `${o.Ethereum}.THOR`:
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
case `${o.Ethereum}.vTHOR`:
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
case o.Cosmos:
return { identifier: "GAIA.ATOM", decimal: d[s] };
case o.THORChain:
return { identifier: "THOR.RUNE", decimal: d[s] };
case o.BinanceSmartChain:
return { identifier: "BSC.BNB", decimal: d[s] };
case o.Maya:
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
case `${o.Maya}.MAYA`:
return { identifier: "MAYA.MAYA", decimal: 4 };
case `${o.Kujira}.USK`:
return { identifier: `${o.Kujira}.USK`, decimal: 6 };
case o.Kujira:
case o.Arbitrum:
case o.Optimism:
case o.BitcoinCash:
case o.Litecoin:
case o.Dogecoin:
case o.Binance:
case o.Avalanche:
case o.Polygon:
case o.Bitcoin:
case o.Ethereum:
return { identifier: `${s}.${s}`, decimal: d[s] };
}
}, Et = ({ chain: s, symbol: t }) => {
if (t.includes("/"))
return "Synth";
switch (s) {
case o.Bitcoin:
case o.BitcoinCash:
case o.Dogecoin:
case o.Litecoin:
case o.Maya:
case o.THORChain:
return "Native";
case o.Cosmos:
return t === "ATOM" ? "Native" : o.Cosmos;
case o.Kujira:
return t === o.Kujira ? "Native" : o.Kujira;
case o.Binance:
return t === o.Binance ? "Native" : "BEP2";
case o.BinanceSmartChain:
return t === o.Binance ? "Native" : "BEP20";
case o.Ethereum:
return t === o.Ethereum ? "Native" : "ERC20";
case o.Avalanche:
return t === o.Avalanche ? "Native" : o.Avalanche;
case o.Polygon:
return t === o.Polygon ? "Native" : "POLYGON";
case o.Arbitrum:
return [o.Ethereum, o.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
case o.Optimism:
return [o.Ethereum, o.Optimism].includes(t) ? "Native" : "OPTIMISM";
}
}, oe = (s) => {
var c;
const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (c = n == null ? void 0 : n.split("-")) == null ? void 0 : c[0];
return { chain: t, symbol: n, ticker: i, synth: r };
}, Bt = new RegExp(
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
"gmi"
), Mt = (s) => {
const [t, e] = s.split(".");
if (!At.includes(t))
return !0;
const [, r] = e.split("-");
return it({ chain: t, symbol: e }) || !!r;
}, ae = (s) => s.filter((t) => {
const e = `${t.chain}.${t.symbol}`;
return !Bt.test(e) && Mt(e) && t.value !== "0";
});
function xt({
liquidityUnits: s,
poolUnits: t,
runeDepth: e
}) {
const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = n.mul(n).mul(n);
return c.mul(a.sub(u).add(l)).div(h);
}
function qt({
liquidityUnits: s,
poolUnits: t,
assetDepth: e
}) {
const r = p(s), n = p(t), i = p(e), c = r.mul(i), a = n.mul(n).mul(2), u = n.mul(r).mul(2), l = r.mul(r), h = c.mul(a.sub(u).add(l)), $ = n.mul(n).mul(n);
return h.div($);
}
function ce({
percent: s,
runeDepth: t,
liquidityUnits: e,
poolUnits: r
}) {
return xt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
}
function ue({
percent: s,
assetDepth: t,
liquidityUnits: e,
poolUnits: r
}) {
return qt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
}
function p(s) {
return g.fromBigInt(BigInt(s), d.THOR);
}
function Pt({
liquidityUnits: s,
poolUnits: t,
runeDepth: e,
assetDepth: r
}) {
return {
assetAmount: p(r).mul(s).div(t),
runeAmount: p(e).mul(s).div(t)
};
}
function le({
liquidityUnits: s,
poolUnits: t,
runeDepth: e,
assetDepth: r,
percent: n
}) {
return Object.fromEntries(
Object.entries(Pt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
([i, c]) => [i, c.mul(n)]
)
);
}
function he({
runeDepth: s,
poolUnits: t,
assetDepth: e,
liquidityUnits: r,
runeAmount: n,
assetAmount: i
}) {
const c = new g({ value: s, decimal: 8 }), a = new g({ value: e, decimal: 8 }), u = new g({ value: t, decimal: 8 }), l = new g({ value: n, decimal: 8 }), h = new g({ value: i, decimal: 8 }), $ = l.mul(a), H = h.mul(c), mt = l.mul(h), pt = c.mul(a), ft = u.mul($.add(H.add(mt.mul(2)))), _t = $.add(H.add(pt.mul(2))), Q = ft.div(_t), U = p(r).add(Q);
if (Q.getBaseValue("number") === 0)
return U.div(u).getBaseValue("number");
const gt = u.add(U);
return U.div(gt).getBaseValue("number");
}
function de({
runeAmount: s,
assetAmount: t,
runeDepth: e,
assetDepth: r
}) {
if (s === "0" || t === "0" || e === "0" || r === "0")
return 0;
const n = p(e), i = p(r), c = p(t), a = p(s), u = c.mul(n).sub(i.mul(a)), l = i.mul(a).add(n.mul(i));
return Math.abs(u.div(l).getBaseValue("number"));
}
const me = (s, t) => {
switch (s) {
case _.LEAVE:
case _.BOND: {
const { address: e } = t;
return `${s}:${e}`;
}
case _.UNBOND: {
const { address: e, unbondAmount: r } = t;
return `${s}:${e}:${r}`;
}
case _.THORNAME_REGISTER: {
const { name: e, chain: r, address: n, owner: i } = t;
return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`;
}
case _.DEPOSIT: {
const { chain: e, symbol: r, address: n, singleSide: i } = t;
return i ? `${s}:${e}/${r}::t:0` : `${s}:${((a, u) => {
switch (a) {
case o.Litecoin:
return "l";
case o.Dogecoin:
return "d";
case o.BitcoinCash:
return "c";
default:
return `${a}.${u}`;
}
})(e, r)}:${n || ""}:t:0`;
}
case _.WITHDRAW: {
const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: c, singleSide: a } = t, u = e === "ETH" && r !== "ETH" ? `${r}-${n.slice(-3)}` : n, l = !a && c ? `:${c}` : "";
return `${s}:${e}${a ? "/" : "."}${u}:${i}${l}`;
}
case _.OPEN_LOAN:
case _.CLOSE_LOAN: {
const { asset: e, address: r } = t;
return `${s}:${e}:${r}`;
}
default:
return "";
}
};
function pe(s) {
if (s < 0)
throw new Error("Invalid number of year");
return 10 + s;
}
function fe(s) {
if (s.length > 30)
return !1;
const t = /^[a-zA-Z0-9+_-]+$/g;
return !!s.match(t);
}
function _e([s, t, e, r, n]) {
return `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
}
class X extends Error {
constructor(t, e, r) {
const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", c = `${n} ${i}`.trim(), a = c ? `status code ${c}` : "an unknown error";
super(`Request failed with ${a}`), Object.defineProperty(this, "response", {
var T = (e, t, n) => (Ve(e, t, "access private method"), n);
import { FeeOption as Y, BaseDecimal as d, Chain as a, EVMChainList as Be, ChainToRPC as Ue, MemoType as E, ChainToChainId as Le } from "@swapkit/types";
var l = /* @__PURE__ */ ((e) => (e.INVALID_INPUT_PARAMETERS = "1000", e.UNKNOWN_PROVIDERS = "1001", e.CANNOT_FIND_INBOUND_ADDRESS = "1002", e.NO_INBOUND_ADDRESSES = "1003", e.CHAIN_HALTED_OR_UNSUPPORTED = "1004", e.MISSING_INPUT_PARAMETER = "1005", e.INVALID_TYPE_GENERIC = "1100", e.INVALID_NUMBER_STRING = "1101", e.INVALID_NUMBER = "1102", e.INVALID_BOOLEAN = "1103", e.INVALID_OBJECT = "1104", e.INVALID_ARRAY = "1105", e.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", e.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", e.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", e.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", e.AFF_ADDRESS_TOO_LONG = "2004", e.AFF_BPS_INTEGER_MAX_500 = "2005", e.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", e.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", e.PREFERRED_PROVIDER_NOT_SUPPORTED = "2008", e.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", e.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", e.SOURCE_ADDRESS_SMART_CONTRACT = "2011", e.INVALID_PROVIDER = "2100", e.MISSING_CROSS_CHAIN_PROVIDER = "2101", e.MISSING_AVAX_PROVIDER = "2102", e.MISSING_BSC_PROVIDER = "2103", e.MISSING_ETH_PROVIDER = "2104", e.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", e.MISSING_ARB_PROVIDER = "2106", e.INVALID_CHAIN = "2200", e.INVALID_ASSET = "2201", e.INVALID_ASSET_IDENTIFIER = "2202", e.UNSUPPORTED_CHAIN = "2204", e.UNSUPPORTED_ASSET = "2203", e.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", e.INVALID_SOURCE_ADDRESS = "2300", e.INVALID_DESTINATION_ADDRESS = "2301", e.THORNODE_QUOTE_GENERIC_ERROR = "3000", e.NOT_ENOUGH_SYNTH_BALANCE = "3001", e.SYNTH_MINTING_CAP_REACHED = "3002", e.INVALID_QUOTE_MODE = "4000", e.NO_QUOTES = "4001", e.SERVICE_UNAVAILABLE_GENERIC = "5000", e.MISSING_GAS_DATA_GENERIC = "5100", e.MISSING_TOKEN_INFO_GENERIC = "5200", e.CANT_FIND_TOKEN_LIST = "5201", e.NO_PRICE = "5202", e.PRICE_IS_STALE = "5203", e.ADDRESS_NOT_WHITELISTED = "6000", e.ADDRESS_ALREADY_CLAIMED = "6001", e.TEMPORARY_ERROR = "9999", e))(l || {});
l.INVALID_INPUT_PARAMETERS + "", l.UNKNOWN_PROVIDERS + "", l.CANNOT_FIND_INBOUND_ADDRESS + "", l.NO_INBOUND_ADDRESSES + "", l.CHAIN_HALTED_OR_UNSUPPORTED + "", l.MISSING_INPUT_PARAMETER + "", l.INVALID_TYPE_GENERIC + "", l.INVALID_NUMBER_STRING + "", l.INVALID_NUMBER + "", l.INVALID_BOOLEAN + "", l.INVALID_OBJECT + "", l.INVALID_ARRAY + "", l.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", l.SELL_BUY_ASSETS_ARE_THE_SAME + "", l.MISSING_SOURCE_ADDRESS_FOR_SYNTH + "", l.AFF_ADDRESS_AND_BPS_OR_NEITHER + "", l.AFF_ADDRESS_TOO_LONG + "", l.AFF_BPS_INTEGER_MAX_500 + "", l.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN + "", l.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN + "", l.PREFERRED_PROVIDER_NOT_SUPPORTED + "", l.SOURCE_ADDRESS_SMART_CONTRACT + "", l.DESTINATION_ADDRESS_SMART_CONTRACT + "", l.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", l.INVALID_PROVIDER + "", l.MISSING_CROSS_CHAIN_PROVIDER + "", l.MISSING_AVAX_PROVIDER + "", l.MISSING_BSC_PROVIDER + "", l.MISSING_ETH_PROVIDER + "", l.MISSING_ARB_PROVIDER + "", l.INVALID_PROVIDER_FOR_SWAP_OUT + "", l.INVALID_CHAIN + "", l.INVALID_ASSET + "", l.UNSUPPORTED_CHAIN + "", l.UNSUPPORTED_ASSET + "", l.UNSUPPORTED_ASSET_FOR_SWAPOUT + "", l.THORNODE_QUOTE_GENERIC_ERROR + "", l.INVALID_SOURCE_ADDRESS + "", l.INVALID_DESTINATION_ADDRESS + "", l.NOT_ENOUGH_SYNTH_BALANCE + "", l.SYNTH_MINTING_CAP_REACHED + "", l.INVALID_QUOTE_MODE + "", l.NO_QUOTES + "", l.SERVICE_UNAVAILABLE_GENERIC + "", l.MISSING_GAS_DATA_GENERIC + "", l.MISSING_TOKEN_INFO_GENERIC + "", l.CANT_FIND_TOKEN_LIST + "", l.NO_PRICE + "", l.PRICE_IS_STALE + "", l.ADDRESS_NOT_WHITELISTED + "", l.ADDRESS_ALREADY_CLAIMED + "";
var q = /* @__PURE__ */ ((e) => (e.Arbitrum = "ARB", e.Avalanche = "AVAX", e.Binance = "BNB", e.BinanceSmartChain = "BSC", e.Bitcoin = "BTC", e.BitcoinCash = "BCH", e.Cosmos = "GAIA", e.Dogecoin = "DOGE", e.Ethereum = "ETH", e.Kujira = "KUJI", e.Litecoin = "LTC", e.Maya = "MAYA", e.Optimism = "OP", e.Polygon = "MATIC", e.THORChain = "THOR", e))(q || {}), te = /* @__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))(te || {}), de = /* @__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))(de || {}), R = /* @__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.net", e.ThorswapStatic = "https://static.thorswap.net", e))(R || {});
const j = Object.values(q), $e = Object.keys(q), ne = j.reduce(
(e, t) => {
const n = $e.find((s) => q[s] === t);
return n && (e[t] = n), e;
},
{}
);
j.reduce(
(e, t) => (e[t] = te[ne[t]], e),
{}
);
j.reduce(
(e, t) => (e[t] = de[ne[t]], e),
{}
);
j.reduce(
(e, t) => {
const n = `${ne[t]}Hex`;
return e[t] = te[n], e;
},
{}
);
class oe extends Error {
constructor(t, n, s) {
const r = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", o = `${r} ${i}`.trim(), u = o ? `status code ${o}` : "an unknown error";
super(`Request failed with ${u}`), Object.defineProperty(this, "response", {
enumerable: !0,

@@ -319,6 +57,6 @@ configurable: !0,

value: void 0
}), this.name = "HTTPError", this.response = t, this.request = e, this.options = r;
}), this.name = "HTTPError", this.response = t, this.request = n, this.options = s;
}
}
class ot extends Error {
class Te extends Error {
constructor(t) {

@@ -333,27 +71,27 @@ super("Request timed out"), Object.defineProperty(this, "request", {

}
const q = (s) => s !== null && typeof s == "object", M = (...s) => {
for (const t of s)
if ((!q(t) || Array.isArray(t)) && t !== void 0)
const M = (e) => e !== null && typeof e == "object", $ = (...e) => {
for (const t of e)
if ((!M(t) || Array.isArray(t)) && t !== void 0)
throw new TypeError("The `options` argument must be an object");
return J({}, ...s);
}, at = (s = {}, t = {}) => {
const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
for (const [i, c] of n.entries())
r && c === "undefined" || c === void 0 ? e.delete(i) : e.set(i, c);
return e;
}, J = (...s) => {
let t = {}, e = {};
for (const r of s)
if (Array.isArray(r))
Array.isArray(t) || (t = []), t = [...t, ...r];
else if (q(r)) {
for (let [n, i] of Object.entries(r))
q(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
q(r.headers) && (e = at(e, r.headers), t.headers = e);
return se({}, ...e);
}, Ae = (e = {}, t = {}) => {
const n = new globalThis.Headers(e), s = t instanceof globalThis.Headers, r = new globalThis.Headers(t);
for (const [i, o] of r.entries())
s && o === "undefined" || o === void 0 ? n.delete(i) : n.set(i, o);
return n;
}, se = (...e) => {
let t = {}, n = {};
for (const s of e)
if (Array.isArray(s))
Array.isArray(t) || (t = []), t = [...t, ...s];
else if (M(s)) {
for (let [r, i] of Object.entries(s))
M(i) && r in t && (i = se(t[r], i)), t = { ...t, [r]: i };
M(s.headers) && (n = Ae(n, s.headers), t.headers = n);
}
return t;
}, Vt = (() => {
let s = !1, t = !1;
const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
return e && r && (t = new globalThis.Request("https://empty.invalid", {
}, ve = (() => {
let e = !1, t = !1;
const n = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function";
return n && s && (t = new globalThis.Request("https://empty.invalid", {
body: new globalThis.ReadableStream(),

@@ -363,6 +101,6 @@ method: "POST",

get duplex() {
return s = !0, "half";
return e = !0, "half";
}
}).headers.has("Content-Type")), s && !t;
})(), kt = typeof globalThis.AbortController == "function", jt = typeof globalThis.ReadableStream == "function", Nt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], Ht = {
}).headers.has("Content-Type")), e && !t;
})(), Me = typeof globalThis.AbortController == "function", He = typeof globalThis.ReadableStream == "function", xe = typeof globalThis.FormData == "function", pe = ["get", "post", "put", "patch", "head", "delete"], Fe = {
json: "application/json",

@@ -373,3 +111,3 @@ text: "text/*",

blob: "*/*"
}, L = 2147483647, ut = Symbol("stop"), Ut = {
}, K = 2147483647, Se = Symbol("stop"), Ge = {
json: !0,

@@ -385,3 +123,3 @@ parseJson: !0,

fetch: !0
}, Dt = {
}, We = {
method: !0,

@@ -402,95 +140,95 @@ headers: !0,

duplex: !0
}, Lt = (s) => ct.includes(s) ? s.toUpperCase() : s, Ft = ["get", "put", "head", "delete", "options", "trace"], Wt = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Z = {
}, ke = (e) => pe.includes(e) ? e.toUpperCase() : e, qe = ["get", "put", "head", "delete", "options", "trace"], je = [408, 413, 429, 500, 502, 503, 504], me = [413, 429, 503], ce = {
limit: 2,
methods: Ft,
statusCodes: Wt,
afterStatusCodes: lt,
methods: qe,
statusCodes: je,
afterStatusCodes: me,
maxRetryAfter: Number.POSITIVE_INFINITY,
backoffLimit: Number.POSITIVE_INFINITY,
delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
}, Kt = (s = {}) => {
if (typeof s == "number")
delay: (e) => 0.3 * 2 ** (e - 1) * 1e3
}, Xe = (e = {}) => {
if (typeof e == "number")
return {
...Z,
limit: s
...ce,
limit: e
};
if (s.methods && !Array.isArray(s.methods))
if (e.methods && !Array.isArray(e.methods))
throw new Error("retry.methods must be an array");
if (s.statusCodes && !Array.isArray(s.statusCodes))
if (e.statusCodes && !Array.isArray(e.statusCodes))
throw new Error("retry.statusCodes must be an array");
return {
...Z,
...s,
afterStatusCodes: lt
...ce,
...e,
afterStatusCodes: me
};
};
async function Gt(s, t, e, r) {
return new Promise((n, i) => {
const c = setTimeout(() => {
e && e.abort(), i(new ot(s));
}, r.timeout);
r.fetch(s, t).then(n).catch(i).then(() => {
clearTimeout(c);
async function Ye(e, t, n, s) {
return new Promise((r, i) => {
const o = setTimeout(() => {
n && n.abort(), i(new Te(e));
}, s.timeout);
s.fetch(e, t).then(r).catch(i).then(() => {
clearTimeout(o);
});
});
}
async function zt(s, { signal: t }) {
return new Promise((e, r) => {
t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
function n() {
clearTimeout(i), r(t.reason);
async function Ke(e, { signal: t }) {
return new Promise((n, s) => {
t && (t.throwIfAborted(), t.addEventListener("abort", r, { once: !0 }));
function r() {
clearTimeout(i), s(t.reason);
}
const i = setTimeout(() => {
t == null || t.removeEventListener("abort", n), e();
}, s);
t == null || t.removeEventListener("abort", r), n();
}, e);
});
}
const Jt = (s, t) => {
const e = {};
for (const r in t)
!(r in Dt) && !(r in Ut) && !(r in s) && (e[r] = t[r]);
return e;
const Je = (e, t) => {
const n = {};
for (const s in t)
!(s in We) && !(s in Ge) && !(s in e) && (n[s] = t[s]);
return n;
};
class V {
static create(t, e) {
const r = new V(t, e), n = async () => {
if (typeof r._options.timeout == "number" && r._options.timeout > L)
throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`);
class F {
static create(t, n) {
const s = new F(t, n), r = async () => {
if (typeof s._options.timeout == "number" && s._options.timeout > K)
throw new RangeError(`The \`timeout\` option cannot be greater than ${K}`);
await Promise.resolve();
let a = await r._fetch();
for (const u of r._options.hooks.afterResponse) {
const l = await u(r.request, r._options, r._decorateResponse(a.clone()));
l instanceof globalThis.Response && (a = l);
let o = await s._fetch();
for (const u of s._options.hooks.afterResponse) {
const c = await u(s.request, s._options, s._decorateResponse(o.clone()));
c instanceof globalThis.Response && (o = c);
}
if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) {
let u = new X(a, r.request, r._options);
for (const l of r._options.hooks.beforeError)
u = await l(u);
if (s._decorateResponse(o), !o.ok && s._options.throwHttpErrors) {
let u = new oe(o, s.request, s._options);
for (const c of s._options.hooks.beforeError)
u = await c(u);
throw u;
}
if (r._options.onDownloadProgress) {
if (typeof r._options.onDownloadProgress != "function")
if (s._options.onDownloadProgress) {
if (typeof s._options.onDownloadProgress != "function")
throw new TypeError("The `onDownloadProgress` option must be a function");
if (!jt)
if (!He)
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
return r._stream(a.clone(), r._options.onDownloadProgress);
return s._stream(o.clone(), s._options.onDownloadProgress);
}
return a;
}, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
for (const [a, u] of Object.entries(Ht))
c[a] = async () => {
r.request.headers.set("accept", r.request.headers.get("accept") || u);
const h = (await c).clone();
if (a === "json") {
if (h.status === 204 || (await h.clone().arrayBuffer()).byteLength === 0)
return o;
}, i = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(r) : r();
for (const [o, u] of Object.entries(Fe))
i[o] = async () => {
s.request.headers.set("accept", s.request.headers.get("accept") || u);
const c = (await i).clone();
if (o === "json") {
if (c.status === 204 || (await c.clone().arrayBuffer()).byteLength === 0)
return "";
if (e.parseJson)
return e.parseJson(await h.text());
if (n.parseJson)
return n.parseJson(await c.text());
}
return h[a]();
return c[o]();
};
return c;
return i;
}
// eslint-disable-next-line complexity
constructor(t, e = {}) {
constructor(t, n = {}) {
if (Object.defineProperty(this, "request", {

@@ -524,5 +262,5 @@ enumerable: !0,

credentials: this._input.credentials || "same-origin",
...e,
headers: at(this._input.headers, e.headers),
hooks: J({
...n,
headers: Ae(this._input.headers, n.headers),
hooks: se({
beforeRequest: [],

@@ -532,10 +270,10 @@ beforeRetry: [],

afterResponse: []
}, e.hooks),
method: Lt(e.method ?? this._input.method),
}, n.hooks),
method: ke(n.method ?? this._input.method),
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
prefixUrl: String(e.prefixUrl || ""),
retry: Kt(e.retry),
throwHttpErrors: e.throwHttpErrors !== !1,
timeout: e.timeout ?? 1e4,
fetch: e.fetch ?? globalThis.fetch.bind(globalThis)
prefixUrl: String(n.prefixUrl || ""),
retry: Xe(n.retry),
throwHttpErrors: n.throwHttpErrors !== !1,
timeout: n.timeout ?? 1e4,
fetch: n.fetch ?? globalThis.fetch.bind(globalThis)
}, typeof this._input != "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request))

@@ -548,7 +286,7 @@ throw new TypeError("`input` must be a string, URL, or Request");

}
if (kt) {
if (Me) {
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
const r = this._options.signal;
const s = this._options.signal;
this._options.signal.addEventListener("abort", () => {
this.abortController.abort(r.reason);
this.abortController.abort(s.reason);
});

@@ -558,5 +296,5 @@ }

}
if (Vt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
(Nt && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(i, { ...this.request }), this._options);
if (ve && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
const s = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), r = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, s);
(xe && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(r, { ...this.request }), this._options);
}

@@ -566,10 +304,10 @@ this._options.json !== void 0 && (this._options.body = JSON.stringify(this._options.json), this.request.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json"), this.request = new globalThis.Request(this.request, { body: this._options.body }));

_calculateRetryDelay(t) {
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof ot)) {
if (t instanceof X) {
if (this._retryCount++, this._retryCount <= this._options.retry.limit && !(t instanceof Te)) {
if (t instanceof oe) {
if (!this._options.retry.statusCodes.includes(t.response.status))
return 0;
const r = t.response.headers.get("Retry-After");
if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) {
let n = Number(r);
return Number.isNaN(n) ? n = Date.parse(r) - Date.now() : n *= 1e3, this._options.retry.maxRetryAfter !== void 0 && n > this._options.retry.maxRetryAfter ? 0 : n;
const s = t.response.headers.get("Retry-After");
if (s && this._options.retry.afterStatusCodes.includes(t.response.status)) {
let r = Number(s);
return Number.isNaN(r) ? r = Date.parse(s) - Date.now() : r *= 1e3, this._options.retry.maxRetryAfter !== void 0 && r > this._options.retry.maxRetryAfter ? 0 : r;
}

@@ -579,4 +317,4 @@ if (t.response.status === 413)

}
const e = this._options.retry.delay(this._retryCount);
return Math.min(this._options.retry.backoffLimit, e);
const n = this._options.retry.delay(this._retryCount);
return Math.min(this._options.retry.backoffLimit, n);
}

@@ -591,37 +329,37 @@ return 0;

return await t();
} catch (e) {
const r = Math.min(this._calculateRetryDelay(e), L);
if (r !== 0 && this._retryCount > 0) {
await zt(r, { signal: this._options.signal });
for (const n of this._options.hooks.beforeRetry)
if (await n({
} catch (n) {
const s = Math.min(this._calculateRetryDelay(n), K);
if (s !== 0 && this._retryCount > 0) {
await Ke(s, { signal: this._options.signal });
for (const r of this._options.hooks.beforeRetry)
if (await r({
request: this.request,
options: this._options,
error: e,
error: n,
retryCount: this._retryCount
}) === ut)
}) === Se)
return;
return this._retry(t);
}
throw e;
throw n;
}
}
async _fetch() {
for (const e of this._options.hooks.beforeRequest) {
const r = await e(this.request, this._options);
if (r instanceof Request) {
this.request = r;
for (const n of this._options.hooks.beforeRequest) {
const s = await n(this.request, this._options);
if (s instanceof Request) {
this.request = s;
break;
}
if (r instanceof Response)
return r;
if (s instanceof Response)
return s;
}
const t = Jt(this.request, this._options);
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Gt(this.request.clone(), t, this.abortController, this._options);
const t = Je(this.request, this._options);
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Ye(this.request.clone(), t, this.abortController, this._options);
}
/* istanbul ignore next */
_stream(t, e) {
const r = Number(t.headers.get("content-length")) || 0;
let n = 0;
return t.status === 204 ? (e && e({ percent: 1, totalBytes: r, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, {
_stream(t, n) {
const s = Number(t.headers.get("content-length")) || 0;
let r = 0;
return t.status === 204 ? (n && n({ percent: 1, totalBytes: s, transferredBytes: r }, new Uint8Array()), new globalThis.Response(null, {
status: t.status,

@@ -632,18 +370,18 @@ statusText: t.statusText,

async start(i) {
const c = t.body.getReader();
e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
async function a() {
const { done: u, value: l } = await c.read();
if (u) {
const o = t.body.getReader();
n && n({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array());
async function u() {
const { done: c, value: _ } = await o.read();
if (c) {
i.close();
return;
}
if (e) {
n += l.byteLength;
const h = r === 0 ? 0 : n / r;
e({ percent: h, transferredBytes: n, totalBytes: r }, l);
if (n) {
r += _.byteLength;
const h = s === 0 ? 0 : r / s;
n({ percent: h, transferredBytes: r, totalBytes: s }, _);
}
i.enqueue(l), await a();
i.enqueue(_), await u();
}
await a();
await u();
}

@@ -658,37 +396,357 @@ }), {

/*! MIT License © Sindre Sorhus */
const W = (s) => {
const t = (e, r) => V.create(e, M(s, r));
for (const e of ct)
t[e] = (r, n) => V.create(r, M(s, n, { method: e }));
return t.create = (e) => W(M(e)), t.extend = (e) => W(M(s, e)), t.stop = ut, t;
}, Yt = W(), Qt = Yt, Xt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Qt.create({ headers: Xt }), Zt = {
get: (s, t) => tt.get(s, t).json(),
post: (s, t) => tt.post(s, t).json()
}, et = [...Object.values(o), "TERRA"];
function te(s = "") {
const t = s.toUpperCase(), [e] = t.split(".");
if (et.includes(e))
const Q = (e) => {
const t = (n, s) => F.create(n, $(e, s));
for (const n of pe)
t[n] = (s, r) => F.create(s, $(e, r, { method: n }));
return t.create = (n) => Q($(n)), t.extend = (n) => Q($(e, n)), t.stop = Se, t;
}, Ee = Q();
let H;
const m = {
CachedPrices: `${R.ThorswapApi}/tokenlist/cached-price`,
GasRates: `${R.ThorswapApi}/resource-worker/gasPrice/getAll`,
Quote: `${R.ThorswapApi}/aggregator/tokens/quote`,
Txn: `${R.ThorswapApi}/apiusage/v2/txn`,
TokenlistProviders: `${R.ThorswapApi}/tokenlist/providers`,
TokenList: `${R.ThorswapStatic}/token-list`,
Thorname: `${R.ThorswapApi}/thorname`
}, Re = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, ue = () => H || (H = Ee.create({ headers: Re }), H), mt = ({ apiKey: e, ...t }) => {
H = Ee.create({
...t,
headers: { ...Re, ...t.headers, "x-api-key": e }
});
}, S = {
get: (e, t) => ue().get(e, t).json(),
post: (e, t) => ue().post(e, t).json()
}, Qe = ({ tokens: e, ...t }) => {
const n = new URLSearchParams();
return e.filter((s, r, i) => i.findIndex((o) => o === s) === r).forEach((s) => n.append("tokens", JSON.stringify(s))), t.metadata && n.append("metadata", "true"), t.lookup && n.append("lookup", "true"), t.sparkline && n.append("sparkline", "true"), S.post(m.CachedPrices, {
body: n.toString(),
headers: { "Content-Type": "application/x-www-form-urlencoded" }
});
}, Et = {
getCachedPrices: Qe,
getQuote: (e) => S.get(m.Quote, { searchParams: e }),
getGasRates: () => S.get(m.GasRates),
getTxnDetails: (e) => S.get(m.Txn, { searchParams: e }),
getTokenlistProviders: () => S.get(m.TokenlistProviders),
getTokenList: (e) => S.get(`${m.TokenList}/${e}.json`),
getThornameAddresses: (e) => S.get(`${m.Thorname}/${e}`),
getThornameRegisteredChains: (e) => S.get(`${m.Thorname}/chains/${e}`),
getThornameRlookup: (e, t) => S.get(`${m.Thorname}/rlookup`, { searchParams: { address: e, chain: t } })
};
var ze = /* @__PURE__ */ ((e) => (e.SWAP_TC_TO_TC = "SWAP:TC-TC", e.SWAP_ETH_TO_TC = "SWAP:ERC20-TC", e.SWAP_TC_TO_ETH = "SWAP:TC-ERC20", e.SWAP_ETH_TO_ETH = "SWAP:ERC20-ERC20", e.SWAP_AVAX_TO_TC = "SWAP:AVAX-TC", e.SWAP_TC_TO_AVAX = "SWAP:TC-AVAX", e.SWAP_AVAX_TO_AVAX = "SWAP:AVAX-AVAX", e.SWAP_ETH_TO_AVAX = "SWAP:ETH-AVAX", e.SWAP_AVAX_TO_ETH = "SWAP:AVAX-ETH", e.SWAP_TC_TO_GAIA = "SWAP:TC-GAIA", e.SWAP_GAIA_TO_TC = "SWAP:GAIA-TC", e.SWAP_TC_TO_BNB = "SWAP:TC-BNB", e.SWAP_BNB_TO_TC = "SWAP:BNB-TC", e.SWAP_TC_TO_BTC = "SWAP:TC-BTC", e.SWAP_BTC_TO_TC = "SWAP:BTC-TC", e.SWAP_TC_TO_BCH = "SWAP:TC-BCH", e.SWAP_BCH_TO_TC = "SWAP:BCH-TC", e.SWAP_TC_TO_LTC = "SWAP:TC-LTC", e.SWAP_LTC_TO_TC = "SWAP:LTC-TC", e.SWAP_TC_TO_DOGE = "SWAP:TC-DOGE", e.SWAP_DOGE_TO_TC = "SWAP:DOGE-TC", e.TC_STATUS = "TC:STATUS", e.TC_TRANSFER = "TC:TRANSFER", e.TC_DEPOSIT = "TC:DEPOSIT", e.TC_SEND = "TC:SEND", e.TC_SWITCH = "TC:SWITCH", e.TC_LP_ADD = "TC:ADDLIQUIDITY", e.TC_LP_WITHDRAW = "TC:WITHDRAW", e.TC_TNS_CREATE = "TC:TNS-CREATE", e.TC_TNS_EXTEND = "TC:TNS-EXTEND", e.TC_TNS_UPDATE = "TC:TNS-UPDATE", e.TC_SAVINGS_ADD = "TC:ADDSAVINGS", e.TC_SAVINGS_WITHDRAW = "TC:WITHDRAWSAVINGS", e.TC_LENDING_OPEN = "TC:LENDINGOPEN", e.TC_LENDING_CLOSE = "TC:LENDINGCLOSE", e.ETH_APPROVAL = "ETH:APPROVAL", e.ETH_STATUS = "ETH:STATUS", e.ETH_TRANSFER_TO_TC = "ETH:TRANSFER:IN", e.ETH_TRANSFER_FROM_TC = "ETH:TRANSFER:OUT", e.AVAX_APPROVAL = "AVAX:APPROVAL", e.AVAX_STATUS = "AVAX:STATUS", e.AVAX_TRANSFER_TO_TC = "AVAX:TRANSFER:IN", e.AVAX_TRANSFER_FROM_TC = "AVAX:TRANSFER:OUT", e.BSC_APPROVAL = "BSC:APPROVAL", e.BSC_STATUS = "BSC:STATUS", e.BSC_TRANSFER_TO_TC = "BSC:TRANSFER:IN", e.BSC_TRANSFER_FROM_TC = "BSC:TRANSFER:OUT", e.APPROVAL = "APPROVAL", e.STATUS = "STATUS", e.TRANSFER_TO_TC = "TRANSFER:IN", e.TRANSFER_FROM_TC = "TRANSFER:OUT", e.UNSUPPORTED = "UNSUPPORTED", e.TC_LENDING = "TC:LENDING", e))(ze || {}), Ze = /* @__PURE__ */ ((e) => (e.PENDING = "pending", e.SUCCESS = "success", e.CANCELLED = "cancelled", e.REFUNDED = "refunded", e.REPLACED = "replaced", e.ERROR = "error", e.UNKNOWN = "unknown", e.NOT_STARTED = "not_started", e.NOT_FOUND = "not_found", e.RETRIES_EXCEEDED = "retries_exceeded", e.STREAMING = "streaming", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e[e.NOT_STARTED = 0] = "NOT_STARTED", e[e.SUCCESS = 1] = "SUCCESS", e[e.REFUNDED = 2] = "REFUNDED", e))(et || {});
const tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
try {
const { result: n } = await S.post(Ue[e], {
headers: {
accept: "*/*",
"content-type": "application/json",
"cache-control": "no-cache"
},
body: JSON.stringify({
id: 44,
jsonrpc: "2.0",
method: "eth_call",
params: [{ to: t.toLowerCase(), data: tt }, "latest"]
})
});
return parseInt(BigInt(n).toString());
} catch (n) {
return console.error(n), d[e];
}
}, nt = async (e) => {
if (e === a.Ethereum)
return d.ETH;
const [, t] = e.split("-");
return t != null && t.startsWith("0x") ? Ie({ chain: a.Ethereum, to: t }) : d.ETH;
}, st = async (e) => {
const [, t] = e.split("-");
return t != null && t.startsWith("0x") ? Ie({ chain: a.Avalanche, to: t.toLowerCase() }) : d.AVAX;
}, rt = async (e) => e === a.BinanceSmartChain ? d.BSC : d.BSC, it = async ({ chain: e, symbol: t }) => {
switch (e) {
case a.Ethereum:
return nt(t);
case a.Avalanche:
return st(t);
case a.BinanceSmartChain:
return rt(t);
default:
return d[e];
}
}, Rt = {
[Y.Average]: 1.2,
[Y.Fast]: 1.5,
[Y.Fastest]: 2
}, fe = ({ chain: e, symbol: t }) => {
switch (e) {
case a.Bitcoin:
case a.BitcoinCash:
case a.Litecoin:
case a.Dogecoin:
case a.Binance:
case a.Ethereum:
case a.Avalanche:
return t === e;
case a.Arbitrum:
case a.Optimism:
return t === "ETH";
case a.Maya:
return t === "CACAO";
case a.Kujira:
return t === "KUJI";
case a.Cosmos:
return t === "ATOM";
case a.Polygon:
return t === "MATIC";
case a.BinanceSmartChain:
return t === "BNB";
case a.THORChain:
return t === "RUNE";
}
}, at = (e) => {
switch (e) {
case `${a.Ethereum}.THOR`:
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
case `${a.Ethereum}.vTHOR`:
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
case a.Cosmos:
return { identifier: "GAIA.ATOM", decimal: d[e] };
case a.THORChain:
return { identifier: "THOR.RUNE", decimal: d[e] };
case a.BinanceSmartChain:
return { identifier: "BSC.BNB", decimal: d[e] };
case a.Maya:
return { identifier: "MAYA.CACAO", decimal: d.MAYA };
case `${a.Maya}.MAYA`:
return { identifier: "MAYA.MAYA", decimal: 4 };
case `${a.Kujira}.USK`:
return { identifier: `${a.Kujira}.USK`, decimal: 6 };
case a.Kujira:
case a.Arbitrum:
case a.Optimism:
case a.BitcoinCash:
case a.Litecoin:
case a.Dogecoin:
case a.Binance:
case a.Avalanche:
case a.Polygon:
case a.Bitcoin:
case a.Ethereum:
return { identifier: `${e}.${e}`, decimal: d[e] };
}
}, ot = ({ chain: e, symbol: t }) => {
if (t.includes("/"))
return "Synth";
switch (e) {
case a.Bitcoin:
case a.BitcoinCash:
case a.Dogecoin:
case a.Litecoin:
case a.Maya:
case a.THORChain:
return "Native";
case a.Cosmos:
return t === "ATOM" ? "Native" : a.Cosmos;
case a.Kujira:
return t === a.Kujira ? "Native" : a.Kujira;
case a.Binance:
return t === a.Binance ? "Native" : "BEP2";
case a.BinanceSmartChain:
return t === a.Binance ? "Native" : "BEP20";
case a.Ethereum:
return t === a.Ethereum ? "Native" : "ERC20";
case a.Avalanche:
return t === a.Avalanche ? "Native" : a.Avalanche;
case a.Polygon:
return t === a.Polygon ? "Native" : "POLYGON";
case a.Arbitrum:
return [a.Ethereum, a.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
case a.Optimism:
return [a.Ethereum, a.Optimism].includes(t) ? "Native" : "OPTIMISM";
}
}, It = (e) => {
var o;
const [t, ...n] = e.split("."), s = e.includes("/"), r = n.join("."), i = (o = r == null ? void 0 : r.split("-")) == null ? void 0 : o[0];
return { chain: t, symbol: r, ticker: i, synth: s };
}, ct = new RegExp(
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
"gmi"
), ut = (e) => {
const [t, n] = e.split(".");
if (!Be.includes(t))
return !0;
const [r] = t.split("/");
if (et.includes(r))
const [, s] = n.split("-");
return fe({ chain: t, symbol: n }) || !!s;
}, ft = (e) => e.filter((t) => {
const n = `${t.chain}.${t.symbol}`;
return !ct.test(n) && ut(n) && t.value !== "0";
});
function lt({
liquidityUnits: e,
poolUnits: t,
runeDepth: n
}) {
const s = A(e), r = A(t), i = A(n), o = s.mul(i), u = r.mul(r).mul(2), c = r.mul(s).mul(2), _ = s.mul(s), h = r.mul(r).mul(r);
return o.mul(u.sub(c).add(_)).div(h);
}
function _t({
liquidityUnits: e,
poolUnits: t,
assetDepth: n
}) {
const s = A(e), r = A(t), i = A(n), o = s.mul(i), u = r.mul(r).mul(2), c = r.mul(s).mul(2), _ = s.mul(s), h = o.mul(u.sub(c).add(_)), P = r.mul(r).mul(r);
return h.div(P);
}
function Nt({
percent: e,
runeDepth: t,
liquidityUnits: n,
poolUnits: s
}) {
return lt({ runeDepth: t, liquidityUnits: n, poolUnits: s }).mul(e);
}
function Ct({
percent: e,
assetDepth: t,
liquidityUnits: n,
poolUnits: s
}) {
return _t({ assetDepth: t, liquidityUnits: n, poolUnits: s }).mul(e);
}
function A(e) {
return I.fromBigInt(BigInt(e), d.THOR);
}
function ht({
liquidityUnits: e,
poolUnits: t,
runeDepth: n,
assetDepth: s
}) {
return {
assetAmount: A(s).mul(e).div(t),
runeAmount: A(n).mul(e).div(t)
};
}
function gt({
liquidityUnits: e,
poolUnits: t,
runeDepth: n,
assetDepth: s,
percent: r
}) {
return Object.fromEntries(
Object.entries(ht({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth: s })).map(
([i, o]) => [i, o.mul(r)]
)
);
}
function Ot({
runeDepth: e,
poolUnits: t,
assetDepth: n,
liquidityUnits: s,
runeAmount: r,
assetAmount: i
}) {
const o = new I({ value: e, decimal: 8 }), u = new I({ value: n, decimal: 8 }), c = new I({ value: t, decimal: 8 }), _ = new I({ value: r, decimal: 8 }), h = new I({ value: i, decimal: 8 }), P = _.mul(u), ie = h.mul(o), ge = _.mul(h), Oe = o.mul(u), De = c.mul(P.add(ie.add(ge.mul(2)))), Pe = P.add(ie.add(Oe.mul(2))), ae = De.div(Pe), X = A(s).add(ae);
if (ae.getBaseValue("number") === 0)
return X.div(c).getBaseValue("number");
const be = c.add(X);
return X.div(be).getBaseValue("number");
}
function Dt({
runeAmount: e,
assetAmount: t,
runeDepth: n,
assetDepth: s
}) {
if (e === "0" || t === "0" || n === "0" || s === "0")
return 0;
const r = A(n), i = A(s), o = A(t), u = A(e), c = o.mul(r).sub(i.mul(u)), _ = i.mul(u).add(r.mul(i));
return Math.abs(c.div(_).getBaseValue("number"));
}
const Pt = (e, t) => {
switch (e) {
case E.LEAVE:
case E.BOND: {
const { address: n } = t;
return `${e}:${n}`;
}
case E.UNBOND: {
const { address: n, unbondAmount: s } = t;
return `${e}:${n}:${s}`;
}
case E.THORNAME_REGISTER: {
const { name: n, chain: s, address: r, owner: i } = t;
return `${e}:${n}:${s}:${r}${i ? `:${i}` : ""}`;
}
case E.DEPOSIT: {
const { chain: n, symbol: s, address: r, singleSide: i } = t;
return i ? `${e}:${n}/${s}::t:0` : `${e}:${((u, c) => {
switch (u) {
case a.Litecoin:
return "l";
case a.Dogecoin:
return "d";
case a.BitcoinCash:
return "c";
default:
return `${u}.${c}`;
}
})(n, s)}:${r || ""}:t:0`;
}
case E.WITHDRAW: {
const { chain: n, ticker: s, symbol: r, basisPoints: i, targetAssetString: o, singleSide: u } = t, c = n === "ETH" && s !== "ETH" ? `${s}-${r.slice(-3)}` : r, _ = !u && o ? `:${o}` : "";
return `${e}:${n}${u ? "/" : "."}${c}:${i}${_}`;
}
case E.OPEN_LOAN:
case E.CLOSE_LOAN: {
const { asset: n, address: s } = t;
return `${e}:${n}:${s}`;
}
default:
return "";
}
};
function bt(e) {
if (e < 0)
throw new Error("Invalid number of year");
return 10 + e;
}
function yt(e) {
if (e.length > 30)
return !1;
const t = /^[a-zA-Z0-9+_-]+$/g;
return !!e.match(t);
}
function wt([e, t, n, s, r]) {
return `${e}'/${t}'/${n}'/${s}${typeof r != "number" ? "" : `/${r}`}`;
}
const le = [...Object.values(a), "TERRA"];
function dt(e = "") {
const t = e.toUpperCase(), [n] = t.split(".");
if (le.includes(n))
return !0;
const [s] = t.split("/");
if (le.includes(s))
return !0;
throw new Error(
`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
);
}
const O = 8, y = (s) => 10n ** BigInt(s), C = (s) => Math.log10(parseFloat(s.toString()));
function k({
value: s,
bigIntDecimal: t = O,
decimal: e = O
const B = 8, N = (e) => 10n ** BigInt(e), b = (e) => Math.log10(parseFloat(e.toString()));
function G({
value: e,
bigIntDecimal: t = B,
decimal: n = B
}) {
if (e === 0)
return s.toString();
const r = s < 0n;
let n = s.toString().substring(r ? 1 : 0);
const i = e - (n.length - 1);
i > 0 && (n = "0".repeat(i) + n);
const c = n.length - e;
let a = n.slice(-e);
return parseInt(a[t]) >= 5 ? a = `${a.substring(0, t - 1)}${(parseInt(a[t - 1]) + 1).toString()}` : a = a.substring(0, t), `${r ? "-" : ""}${n.slice(0, c)}.${a}`.replace(
if (n === 0)
return e.toString();
const s = e < 0n;
let r = e.toString().substring(s ? 1 : 0);
const i = n - (r.length - 1);
i > 0 && (r = "0".repeat(i) + r);
const o = r.length - n;
let u = r.slice(-n);
return parseInt(u[t]) >= 5 ? u = `${u.substring(0, t - 1)}${(parseInt(u[t - 1]) + 1).toString()}` : u = u.substring(0, t), `${s ? "-" : ""}${r.slice(0, o)}.${u}`.replace(
/\.?0*$/,

@@ -698,20 +756,20 @@ ""

}
var w, R, b, T, N, ht, E, K, B, G;
const Y = class Y {
var C, y, f, D, k, Ne, U, z, L, Z;
const re = class re {
constructor(t) {
v(this, w);
v(this, b);
v(this, N);
v(this, E);
v(this, B);
f(this, "decimalMultiplier", 10n ** 8n);
f(this, "bigIntValue", 0n);
f(this, "decimal");
const e = z(t), r = typeof t == "object";
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : y(Math.max(rt(x(e)), this.decimal || 0)), m(this, N, ht).call(this, e);
O(this, C);
O(this, f);
O(this, k);
O(this, U);
O(this, L);
p(this, "decimalMultiplier", 10n ** 8n);
p(this, "bigIntValue", 0n);
p(this, "decimal");
const n = ee(t), s = typeof t == "object";
this.decimal = s ? t.decimal : void 0, this.decimalMultiplier = s && "decimalMultiplier" in t ? t.decimalMultiplier : N(Math.max(_e(v(n)), this.decimal || 0)), T(this, k, Ne).call(this, n);
}
static fromBigInt(t, e) {
return new Y({
decimal: e,
value: k({ value: t, bigIntDecimal: e, decimal: e })
static fromBigInt(t, n) {
return new re({
decimal: n,
value: G({ value: t, bigIntDecimal: n, decimal: n })
});

@@ -721,8 +779,8 @@ }

value: t,
from: e,
to: r
from: n,
to: s
}) {
return this.fromBigInt(
t.getBaseValue("bigint") * y(r) / y(e),
r
t.getBaseValue("bigint") * N(s) / N(n),
s
);

@@ -734,39 +792,39 @@ }

add(...t) {
return m(this, w, R).call(this, "add", ...t);
return T(this, C, y).call(this, "add", ...t);
}
sub(...t) {
return m(this, w, R).call(this, "sub", ...t);
return T(this, C, y).call(this, "sub", ...t);
}
mul(...t) {
return m(this, w, R).call(this, "mul", ...t);
return T(this, C, y).call(this, "mul", ...t);
}
div(...t) {
return m(this, w, R).call(this, "div", ...t);
return T(this, C, y).call(this, "div", ...t);
}
gt(t) {
return m(this, b, T).call(this, "gt", t);
return T(this, f, D).call(this, "gt", t);
}
gte(t) {
return m(this, b, T).call(this, "gte", t);
return T(this, f, D).call(this, "gte", t);
}
lt(t) {
return m(this, b, T).call(this, "lt", t);
return T(this, f, D).call(this, "lt", t);
}
lte(t) {
return m(this, b, T).call(this, "lte", t);
return T(this, f, D).call(this, "lte", t);
}
eqValue(t) {
return m(this, b, T).call(this, "eqValue", t);
return T(this, f, D).call(this, "eqValue", t);
}
// @ts-expect-error False positive
getValue(t) {
const e = this.formatBigIntToSafeValue(
const n = this.formatBigIntToSafeValue(
this.bigIntValue,
this.decimal || C(this.decimalMultiplier)
this.decimal || b(this.decimalMultiplier)
);
switch (t) {
case "number":
return Number(e);
return Number(n);
case "string":
return e;
return n;
case "bigint":

@@ -778,32 +836,32 @@ return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;

getBaseValue(t) {
const e = this.decimalMultiplier / y(this.decimal || d.THOR), r = this.bigIntValue / e;
const n = this.decimalMultiplier / N(this.decimal || d.THOR), s = this.bigIntValue / n;
switch (t) {
case "number":
return Number(r);
return Number(s);
case "string":
return r.toString();
return s.toString();
case "bigint":
return r;
return s;
}
}
getBigIntValue(t, e) {
if (!e && typeof t == "object")
getBigIntValue(t, n) {
if (!n && typeof t == "object")
return t.bigIntValue;
const r = z(t), n = x(r);
return n === "0" || n === "undefined" ? 0n : m(this, B, G).call(this, n, e);
const s = ee(t), r = v(s);
return r === "0" || r === "undefined" ? 0n : T(this, L, Z).call(this, r, n);
}
toSignificant(t = 6) {
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
if ((parseInt(n) ? n.length + i.length : i.length) <= t)
const [n, s] = this.getValue("string").split("."), r = n || "", i = s || "";
if ((parseInt(r) ? r.length + i.length : i.length) <= t)
return this.getValue("string");
if (n.length >= t)
return n.slice(0, t).padEnd(n.length, "0");
if (parseInt(n))
return `${n}.${i.slice(0, t - n.length)}`.padEnd(
t - n.length,
if (r.length >= t)
return r.slice(0, t).padEnd(r.length, "0");
if (parseInt(r))
return `${r}.${i.slice(0, t - r.length)}`.padEnd(
t - r.length,
"0"
);
const a = parseInt(i), u = `${a}`.slice(0, t);
return `0.${u.padStart(
i.length - `${a}`.length + u.length,
const u = parseInt(i), c = `${u}`.slice(0, t);
return `0.${c.padStart(
i.length - `${u}`.length + c.length,
"0"

@@ -813,8 +871,8 @@ )}`;

toFixed(t = 6) {
const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
if (parseInt(n))
return `${n}.${i.slice(0, t)}`.padEnd(t, "0");
const c = parseInt(i), a = `${c}`.slice(0, t);
return `0.${a.padStart(
i.length - `${c}`.length + a.length,
const [n, s] = this.getValue("string").split("."), r = n || "", i = s || "";
if (parseInt(r))
return `${r}.${i.slice(0, t)}`.padEnd(t, "0");
const o = parseInt(i), u = `${o}`.slice(0, t);
return `0.${u.padStart(
i.length - `${o}`.length + u.length,
"0"

@@ -824,47 +882,47 @@ )}`;

toAbbreviation(t = 2) {
const e = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], n = Math.floor(Math.log10(Math.abs(e)) / 3), i = r[n];
const n = this.getValue("number"), s = ["", "K", "M", "B", "T", "Q", "Qi", "S"], r = Math.floor(Math.log10(Math.abs(n)) / 3), i = s[r];
if (!i)
return this.getValue("string");
const c = 10 ** (n * 3);
return `${(e / c).toFixed(t)}${i}`;
const o = 10 ** (r * 3);
return `${(n / o).toFixed(t)}${i}`;
}
toCurrency(t = "$", {
currencyPosition: e = "start",
decimal: r = 2,
decimalSeparator: n = ".",
currencyPosition: n = "start",
decimal: s = 2,
decimalSeparator: r = ".",
thousandSeparator: i = ","
} = {}) {
const c = this.getValue("number"), [a, u = ""] = c.toFixed(6).split("."), l = a.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !a && !u ? "0.00" : a === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${l}${parseInt(u) ? `${n}${u.slice(0, r)}` : ""}`;
return `${e === "start" ? t : ""}${h}${e === "end" ? t : ""}`;
const o = this.getValue("number"), [u, c = ""] = o.toFixed(6).split("."), _ = u.replace(/\B(?=(\d{3})+(?!\d))/g, i), h = !u && !c ? "0.00" : u === "0" ? `${parseFloat(`0.${c}`)}`.replace(".", r) : `${_}${parseInt(c) ? `${r}${c.slice(0, s)}` : ""}`;
return `${n === "start" ? t : ""}${h}${n === "end" ? t : ""}`;
}
formatBigIntToSafeValue(t, e) {
const r = e || this.decimal || O, n = Math.max(
r,
C(this.decimalMultiplier)
), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c, l = u.length - n;
let h = u.slice(-n);
return parseInt(h[r]) >= 5 ? h = `${h.substring(0, r - 1)}${(parseInt(h[r - 1]) + 1).toString()}` : h = h.substring(0, r), `${i ? "-" : ""}${u.slice(
formatBigIntToSafeValue(t, n) {
const s = n || this.decimal || B, r = Math.max(
s,
b(this.decimalMultiplier)
), i = t < 0n, o = t.toString().substring(i ? 1 : 0), u = r - (o.length - 1), c = u > 0 ? "0".repeat(u) + o : o, _ = c.length - r;
let h = c.slice(-r);
return parseInt(h[s]) >= 5 ? h = `${h.substring(0, s - 1)}${(parseInt(h[s - 1]) + 1).toString()}` : h = h.substring(0, s), `${i ? "-" : ""}${c.slice(
0,
l
_
)}.${h}`.replace(/\.?0*$/, "");
}
};
w = new WeakSet(), R = function(t, ...e) {
const r = m(this, E, K).call(this, this, ...e), n = Math.max(r, C(this.decimalMultiplier)), i = y(n), c = e.reduce(
(u, l) => {
const h = this.getBigIntValue(l, n);
C = new WeakSet(), y = function(t, ...n) {
const s = T(this, U, z).call(this, this, ...n), r = Math.max(s, b(this.decimalMultiplier)), i = N(r), o = n.reduce(
(c, _) => {
const h = this.getBigIntValue(_, r);
switch (t) {
case "add":
return u + h;
return c + h;
case "sub":
return u - h;
return c - h;
case "mul":
return u * h / i;
return c * h / i;
case "div": {
if (h === 0n)
throw new RangeError("Division by zero");
return u * i / h;
return c * i / h;
}
default:
return u;
return c;
}

@@ -874,75 +932,75 @@ },

this.bigIntValue * i / this.decimalMultiplier
), a = k({
bigIntDecimal: n,
decimal: n,
value: c
), u = G({
bigIntDecimal: r,
decimal: r,
value: o
});
return new this.constructor({
decimalMultiplier: y(n),
decimalMultiplier: N(r),
decimal: this.decimal,
value: a,
value: u,
identifier: this.toString()
});
}, b = new WeakSet(), T = function(t, ...e) {
const r = m(this, E, K).call(this, this, ...e), n = this.getBigIntValue(e[0], r), i = this.getBigIntValue(this, r);
}, f = new WeakSet(), D = function(t, ...n) {
const s = T(this, U, z).call(this, this, ...n), r = this.getBigIntValue(n[0], s), i = this.getBigIntValue(this, s);
switch (t) {
case "gt":
return i > n;
return i > r;
case "gte":
return i >= n;
return i >= r;
case "lt":
return i < n;
return i < r;
case "lte":
return i <= n;
return i <= r;
case "eqValue":
return i === n;
return i === r;
}
}, N = new WeakSet(), ht = function(t) {
const e = x(t) || "0";
this.bigIntValue = m(this, B, G).call(this, e);
}, E = new WeakSet(), K = function(...t) {
const e = t.map((r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : rt(x(r))).filter(Boolean);
return Math.max(...e, O);
}, B = new WeakSet(), G = function(t, e) {
const r = e ? y(e) : this.decimalMultiplier, n = C(r), [i = "", c = ""] = t.split(".");
return BigInt(`${i}${c.padEnd(n, "0")}`);
}, k = new WeakSet(), Ne = function(t) {
const n = v(t) || "0";
this.bigIntValue = T(this, L, Z).call(this, n);
}, U = new WeakSet(), z = function(...t) {
const n = t.map((s) => typeof s == "object" ? s.decimal || b(s.decimalMultiplier) : _e(v(s))).filter(Boolean);
return Math.max(...n, B);
}, L = new WeakSet(), Z = function(t, n) {
const s = n ? N(n) : this.decimalMultiplier, r = b(s), [i = "", o = ""] = t.split(".");
return BigInt(`${i}${o.padEnd(r, "0")}`);
};
let j = Y;
const ee = Intl.NumberFormat("fullwide", {
let W = re;
const Tt = Intl.NumberFormat("fullwide", {
useGrouping: !1,
maximumFractionDigits: 20
});
function x(s) {
const e = `${typeof s == "number" ? ee.format(s) : z(s)}`.replaceAll(",", ".").split(".");
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
function v(e) {
const n = `${typeof e == "number" ? Tt.format(e) : ee(e)}`.replaceAll(",", ".").split(".");
return n.length > 1 ? `${n.slice(0, -1).join("")}.${n.at(-1)}` : n[0];
}
function rt(s) {
var e;
const t = ((e = s.split(".")[1]) == null ? void 0 : e.length) || 0;
return Math.max(t, O);
function _e(e) {
var n;
const t = ((n = e.split(".")[1]) == null ? void 0 : n.length) || 0;
return Math.max(t, B);
}
function z(s) {
return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
function ee(e) {
return typeof e == "object" ? "getValue" in e ? e.getValue("string") : e.value : e;
}
const S = /* @__PURE__ */ new Map();
class A extends j {
const w = /* @__PURE__ */ new Map();
class g extends W {
constructor({
value: e,
decimal: r,
tax: n,
value: n,
decimal: s,
tax: r,
chain: i,
symbol: c,
identifier: a
symbol: o,
identifier: u
}) {
super(typeof e == "object" ? e : { decimal: r, value: e });
f(this, "address");
f(this, "chain");
f(this, "isGasAsset", !1);
f(this, "isSynthetic", !1);
f(this, "symbol");
f(this, "tax");
f(this, "ticker");
f(this, "type");
const u = P(a || `${i}.${c}`);
this.type = Et(u), this.tax = n, this.chain = u.chain, this.ticker = u.ticker, this.symbol = u.symbol, this.address = u.address, this.isSynthetic = u.isSynthetic, this.isGasAsset = u.isGasAsset;
super(typeof n == "object" ? n : { decimal: s, value: n });
p(this, "address");
p(this, "chain");
p(this, "isGasAsset", !1);
p(this, "isSynthetic", !1);
p(this, "symbol");
p(this, "tax");
p(this, "ticker");
p(this, "type");
const c = x(u || `${i}.${o}`);
this.type = ot(c), this.tax = r, this.chain = c.chain, this.ticker = c.ticker, this.symbol = c.symbol, this.address = c.address, this.isSynthetic = c.isSynthetic, this.isGasAsset = c.isGasAsset;
}

@@ -955,7 +1013,7 @@ toString() {

}
eq({ chain: e, symbol: r }) {
return this.chain === e && this.symbol === r;
eq({ chain: n, symbol: s }) {
return this.chain === n && this.symbol === s;
}
chainId() {
return vt[this.chain];
return Le[this.chain];
}

@@ -965,62 +1023,62 @@ // THOR.RUNE

// ETH.THOR-0x1234567890
static fromUrl(e, r = 0) {
const [n, i, c] = e.split(".");
if (!n || !i)
static fromUrl(n, s = 0) {
const [r, i, o] = n.split(".");
if (!r || !i)
throw new Error("Invalid asset url");
const a = n === o.THORChain && c ? `${n}.${i}/${c}` : e;
return F(a, r);
const u = r === a.THORChain && o ? `${r}.${i}/${o}` : n;
return J(u, s);
}
static fromString(e, r = 0) {
return F(e, r);
static fromString(n, s = 0) {
return J(n, s);
}
static fromIdentifier(e, r = 0) {
return F(e, r);
static fromIdentifier(n, s = 0) {
return J(n, s);
}
static fromStringSync(e, r = 0) {
const { chain: n, isSynthetic: i } = P(e), c = S.get(e.toUpperCase());
static fromStringSync(n, s = 0) {
const { chain: r, isSynthetic: i } = x(n), o = w.get(n.toUpperCase());
if (i)
return st(e, r);
const { tax: a, decimal: u, identifier: l } = c || {
decimal: d[n],
identifier: e
return he(n, s);
const { tax: u, decimal: c, identifier: _ } = o || {
decimal: d[r],
identifier: n
};
return new A({
tax: a,
value: I(r, u),
identifier: i ? e : l,
decimal: i ? 8 : u
return new g({
tax: u,
value: V(s, c),
identifier: i ? n : _,
decimal: i ? 8 : c
});
}
static fromIdentifierSync(e, r = 0) {
const { chain: n, isSynthetic: i } = P(e), c = S.get(e);
static fromIdentifierSync(n, s = 0) {
const { chain: r, isSynthetic: i } = x(n), o = w.get(n);
if (i)
return st(e, r);
const { tax: a, decimal: u, identifier: l } = c || {
decimal: d[n],
identifier: e
return he(n, s);
const { tax: u, decimal: c, identifier: _ } = o || {
decimal: d[r],
identifier: n
};
return new A({ tax: a, decimal: u, identifier: l, value: I(r, u) });
return new g({ tax: u, decimal: c, identifier: _, value: V(s, c) });
}
static fromChainOrSignature(e, r = 0) {
const { decimal: n, identifier: i } = Ot(e);
return new A({ value: I(r, n), decimal: n, identifier: i });
static fromChainOrSignature(n, s = 0) {
const { decimal: r, identifier: i } = at(n);
return new g({ value: V(s, r), decimal: r, identifier: i });
}
static loadStaticAssets() {
return new Promise(
async (e, r) => {
async (n, s) => {
try {
const n = await import("@swapkit/tokens");
Object.values(n).forEach((i) => {
var c;
(c = i == null ? void 0 : i.tokens) == null || c.forEach(({ identifier: a, chain: u, ...l }) => {
S.set(a.toUpperCase(), {
identifier: a,
decimal: "decimals" in l ? l.decimals : d[u]
const r = await import("@swapkit/tokens");
Object.values(r).forEach((i) => {
var o;
(o = i == null ? void 0 : i.tokens) == null || o.forEach(({ identifier: u, chain: c, ..._ }) => {
w.set(u.toUpperCase(), {
identifier: u,
decimal: "decimals" in _ ? _.decimals : d[c]
});
});
}), e({ ok: !0 });
} catch (n) {
console.error(n), r({
}), n({ ok: !0 });
} catch (r) {
console.error(r), s({
ok: !1,
error: n,
error: r,
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"

@@ -1033,18 +1091,18 @@ });

}
function ge(s) {
const t = A.fromChainOrSignature(s);
switch (s) {
case o.Bitcoin:
case o.Litecoin:
case o.BitcoinCash:
function Vt(e) {
const t = g.fromChainOrSignature(e);
switch (e) {
case a.Bitcoin:
case a.Litecoin:
case a.BitcoinCash:
return t.set(10001e-8);
case o.Dogecoin:
case a.Dogecoin:
return t.set(1.00000001);
case o.Avalanche:
case o.Ethereum:
case a.Avalanche:
case a.Ethereum:
return t.set(1e-8);
case o.THORChain:
case o.Maya:
case a.THORChain:
case a.Maya:
return t.set(0);
case o.Cosmos:
case a.Cosmos:
return t.set(1e-6);

@@ -1055,35 +1113,35 @@ default:

}
async function F(s, t = 0) {
te(s);
const e = S.get(s.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await It(P(s));
return e || S.set(s.toUpperCase(), { identifier: s, decimal: r }), new A({ decimal: r, value: I(t, r), identifier: s });
async function J(e, t = 0) {
dt(e);
const n = w.get(e.toUpperCase()), s = (n == null ? void 0 : n.decimal) || await it(x(e));
return n || w.set(e.toUpperCase(), { identifier: e, decimal: s }), new g({ decimal: s, value: V(t, s), identifier: e });
}
function st(s, t = 0) {
const [e, r] = s.split(".")[0].toUpperCase() === o.THORChain ? s.split(".").slice(1).join().split("/") : s.split("/");
if (!e || !r)
function he(e, t = 0) {
const [n, s] = e.split(".")[0].toUpperCase() === a.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
if (!n || !s)
throw new Error("Invalid asset identifier");
return new A({
return new g({
decimal: 8,
value: I(t, 8),
identifier: `${o.THORChain}.${e}/${r}`
value: V(t, 8),
identifier: `${a.THORChain}.${n}/${s}`
});
}
function I(s, t) {
return typeof s == "bigint" ? k({ value: s, bigIntDecimal: t, decimal: t }) : s;
function V(e, t) {
return typeof e == "bigint" ? G({ value: e, bigIntDecimal: t, decimal: t }) : e;
}
function P(s) {
const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".")[0].toUpperCase() === o.THORChain ? s.split(".").slice(1).join().split("/") : s.split("/");
if (t && (!e || !r))
function x(e) {
const t = e.slice(0, 14).includes("/"), [n, s] = e.split(".")[0].toUpperCase() === a.THORChain ? e.split(".").slice(1).join().split("/") : e.split("/");
if (t && (!n || !s))
throw new Error("Invalid asset identifier");
const n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, c] = n.split("."), [a, u] = (t ? r : c).split("-");
const r = e.includes(".") && !t ? e : `${a.THORChain}.${s}`, [i, o] = r.split("."), [u, c] = (t ? s : o).split("-");
return {
address: u == null ? void 0 : u.toLowerCase(),
address: c == null ? void 0 : c.toLowerCase(),
chain: i,
isGasAsset: it({ chain: i, symbol: c }),
isGasAsset: fe({ chain: i, symbol: o }),
isSynthetic: t,
symbol: (t ? `${e}/` : "") + (u ? `${a}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : c),
ticker: a
symbol: (t ? `${n}/` : "") + (c ? `${u}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : o),
ticker: u
};
}
const re = {
const At = {
/**

@@ -1147,15 +1205,15 @@ * Core

};
class dt extends Error {
constructor(t, e) {
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: re[t], message: t } }), Object.setPrototypeOf(this, dt.prototype);
class Ce extends Error {
constructor(t, n) {
console.error(n, { stack: n == null ? void 0 : n.stack, message: n == null ? void 0 : n.message }), super(t, { cause: { code: At[t], message: t } }), Object.setPrototypeOf(this, Ce.prototype);
}
}
class g extends j {
class I extends W {
eq(t) {
return this.eqValue(t);
}
static fromBigInt(t, e) {
return new g({
decimal: e,
value: k({ value: t, bigIntDecimal: e, decimal: e })
static fromBigInt(t, n) {
return new I({
decimal: n,
value: G({ value: t, bigIntDecimal: n, decimal: n })
});

@@ -1165,29 +1223,36 @@ }

export {
A as AssetValue,
j as BigIntArithmetics,
Zt as RequestClient,
dt as SwapKitError,
g as SwapKitNumber,
oe as assetFromString,
_e as derivationPathToString,
ae as filterAssets,
k as formatBigIntToSafeValue,
ie as gasFeeMultiplier,
Et as getAssetType,
qt as getAsymmetricAssetShare,
ue as getAsymmetricAssetWithdrawAmount,
xt as getAsymmetricRuneShare,
ce as getAsymmetricRuneWithdrawAmount,
Ot as getCommonAssetInfo,
It as getDecimal,
he as getEstimatedPoolShare,
de as getLiquiditySlippage,
me as getMemoFor,
ge as getMinAmountByChain,
Pt as getSymmetricPoolShare,
le as getSymmetricWithdraw,
pe as getTHORNameCost,
it as isGasAsset,
fe as validateTHORName
m as ApiEndpoints,
g as AssetValue,
W as BigIntArithmetics,
S as RequestClient,
et as StreamingSwapProgressStatus,
Et as SwapKitApi,
Ce as SwapKitError,
I as SwapKitNumber,
ze as TransactionType,
Ze as TxStatus,
It as assetFromString,
Re as defaultRequestHeaders,
wt as derivationPathToString,
ft as filterAssets,
G as formatBigIntToSafeValue,
Rt as gasFeeMultiplier,
ot as getAssetType,
_t as getAsymmetricAssetShare,
Ct as getAsymmetricAssetWithdrawAmount,
lt as getAsymmetricRuneShare,
Nt as getAsymmetricRuneWithdrawAmount,
at as getCommonAssetInfo,
it as getDecimal,
Ot as getEstimatedPoolShare,
Dt as getLiquiditySlippage,
Pt as getMemoFor,
Vt as getMinAmountByChain,
ht as getSymmetricPoolShare,
gt as getSymmetricWithdraw,
bt as getTHORNameCost,
fe as isGasAsset,
mt as setRequestClientConfig,
yt as validateTHORName
};
//# sourceMappingURL=index.es.js.map

@@ -5,11 +5,11 @@ {

"dependencies": {
"ky": "1.1.3"
"@swapkit/api": "1.0.0-rc.34"
},
"devDependencies": {
"@vitest/coverage-istanbul": "1.0.4",
"vite": "5.0.7",
"vitest": "1.0.4",
"@internal/config": "0.0.1",
"@swapkit/tokens": "1.0.0-rc.32",
"@swapkit/types": "1.0.0-rc.32"
"@vitest/coverage-istanbul": "1.2.1",
"vite": "5.0.12",
"vitest": "1.2.1",
"@internal/config": "0.0.2-rc.0",
"@swapkit/tokens": "1.0.0-rc.33",
"@swapkit/types": "1.0.0-rc.33"
},

@@ -20,4 +20,4 @@ "eslintConfig": {

"peerDependencies": {
"@swapkit/tokens": "1.0.0-rc.32",
"@swapkit/types": "1.0.0-rc.32"
"@swapkit/tokens": "1.0.0-rc.33",
"@swapkit/types": "1.0.0-rc.33"
},

@@ -47,3 +47,3 @@ "exports": {

"types": "./dist/index.d.ts",
"version": "1.0.0-rc.63",
"version": "1.0.0-rc.64",
"scripts": {

@@ -50,0 +50,0 @@ "build": "vite build",

@@ -0,6 +1,5 @@

import { RequestClient } from '@swapkit/api';
import type { EVMChain } from '@swapkit/types';
import { BaseDecimal, Chain, ChainToRPC, EVMChainList, FeeOption } from '@swapkit/types';
import { RequestClient } from '../index.ts';
const getDecimalMethodHex = '0x313ce567';

@@ -7,0 +6,0 @@

@@ -0,1 +1,3 @@

export * from '@swapkit/api';
/**

@@ -8,3 +10,2 @@ * Helpers

export * from './helpers/others.ts';
export * from './helpers/request.ts';

@@ -11,0 +12,0 @@ /**

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc