New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@coinmasters/api

Package Overview
Dependencies
Maintainers
2
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coinmasters/api - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

472

dist/index.es.js

@@ -1,69 +0,435 @@

var A = /* @__PURE__ */ ((_) => (_.INVALID_INPUT_PARAMETERS = "1000", _.UNKNOWN_PROVIDERS = "1001", _.CANNOT_FIND_INBOUND_ADDRESS = "1002", _.NO_INBOUND_ADDRESSES = "1003", _.CHAIN_HALTED_OR_UNSUPPORTED = "1004", _.MISSING_INPUT_PARAMETER = "1005", _.INVALID_TYPE_GENERIC = "1100", _.INVALID_NUMBER_STRING = "1101", _.INVALID_NUMBER = "1102", _.INVALID_BOOLEAN = "1103", _.INVALID_OBJECT = "1104", _.INVALID_ARRAY = "1105", _.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", _.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", _.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", _.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", _.AFF_ADDRESS_TOO_LONG = "2004", _.AFF_BPS_INTEGER_0_100 = "2005", _.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", _.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", _.PREFERRED_PROFVIDER_NOT_SUPPORTED = "2008", _.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", _.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", _.SOURCE_ADDRESS_SMART_CONTRACT = "2011", _.INVALID_PROVIDER = "2100", _.MISSING_CROSS_CHAIN_PROVIDER = "2101", _.MISSING_AVAX_PROVIDER = "2102", _.MISSING_BSC_PROVIDER = "2103", _.MISSING_ETH_PROVIDER = "2104", _.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", _.MISSING_ARB_PROVIDER = "2106", _.INVALID_CHAIN = "2200", _.INVALID_ASSET = "2201", _.INVALID_ASSET_IDENTIFIER = "2202", _.UNSUPPORTED_CHAIN = "2204", _.UNSUPPORTED_ASSET = "2203", _.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", _.INVALID_SOURCE_ADDRESS = "2300", _.INVALID_DESTINATION_ADDRESS = "2301", _.THORNODE_QUOTE_GENERIC_ERROR = "3000", _.NOT_ENOUGH_SYNTH_BALANCE = "3001", _.SYNTH_MINTING_CAP_REACHED = "3002", _.INVALID_QUOTE_MODE = "4000", _.NO_QUOTES = "4001", _.SERVICE_UNAVAILABLE_GENERIC = "5000", _.MISSING_GAS_DATA_GENERIC = "5100", _.MISSING_TOKEN_INFO_GENERIC = "5200", _.CANT_FIND_TOKEN_LIST = "5201", _.NO_PRICE = "5202", _.PRICE_IS_STALE = "5203", _.ADDRESS_NOT_WHITELISTED = "6000", _.ADDRESS_ALREADY_CLAIMED = "6001", _.TEMPORARY_ERROR = "9999", _))(A || {});
A.INVALID_INPUT_PARAMETERS + "", A.UNKNOWN_PROVIDERS + "", A.CANNOT_FIND_INBOUND_ADDRESS + "", A.NO_INBOUND_ADDRESSES + "", A.CHAIN_HALTED_OR_UNSUPPORTED + "", A.MISSING_INPUT_PARAMETER + "", A.INVALID_TYPE_GENERIC + "", A.INVALID_NUMBER_STRING + "", A.INVALID_NUMBER + "", A.INVALID_BOOLEAN + "", A.INVALID_OBJECT + "", A.INVALID_ARRAY + "", A.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", A.SELL_BUY_ASSETS_ARE_THE_SAME + "", A.MISSING_SOURCE_ADDRESS_FOR_SYNTH + "", A.AFF_ADDRESS_AND_BPS_OR_NEITHER + "", A.AFF_ADDRESS_TOO_LONG + "", A.AFF_BPS_INTEGER_0_100 + "", A.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN + "", A.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN + "", A.PREFERRED_PROFVIDER_NOT_SUPPORTED + "", A.DESTINATION_ADDRESS_SMART_CONTRACT + "", A.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", A.INVALID_PROVIDER + "", A.MISSING_CROSS_CHAIN_PROVIDER + "", A.MISSING_AVAX_PROVIDER + "", A.MISSING_BSC_PROVIDER + "", A.MISSING_ETH_PROVIDER + "", A.MISSING_ARB_PROVIDER + "", A.INVALID_PROVIDER_FOR_SWAP_OUT + "", A.INVALID_CHAIN + "", A.INVALID_ASSET + "", A.UNSUPPORTED_CHAIN + "", A.UNSUPPORTED_ASSET + "", A.UNSUPPORTED_ASSET_FOR_SWAPOUT + "", A.THORNODE_QUOTE_GENERIC_ERROR + "", A.INVALID_SOURCE_ADDRESS + "", A.INVALID_DESTINATION_ADDRESS + "", A.NOT_ENOUGH_SYNTH_BALANCE + "", A.SYNTH_MINTING_CAP_REACHED + "", A.INVALID_QUOTE_MODE + "", A.NO_QUOTES + "", A.SERVICE_UNAVAILABLE_GENERIC + "", A.MISSING_GAS_DATA_GENERIC + "", A.MISSING_TOKEN_INFO_GENERIC + "", A.CANT_FIND_TOKEN_LIST + "", A.NO_PRICE + "", A.PRICE_IS_STALE + "", A.ADDRESS_NOT_WHITELISTED + "", A.ADDRESS_ALREADY_CLAIMED + "";
var e = /* @__PURE__ */ ((_) => (_.Arbitrum = "ARB", _.Avalanche = "AVAX", _.Base = "BASE", _.Binance = "BNB", _.BinanceSmartChain = "BSC", _.Bitcoin = "BTC", _.BitcoinCash = "BCH", _.Cosmos = "GAIA", _.Dash = "DASH", _.Digibyte = "DGB", _.Dogecoin = "DOGE", _.EOS = "EOS", _.Ethereum = "ETH", _.Kujira = "KUJI", _.Litecoin = "LTC", _.Maya = "MAYA", _.Optimism = "OP", _.Polygon = "MATIC", _.Ripple = "XRP", _.THORChain = "THOR", _.Zcash = "ZEC", _))(e || {}), i = /* @__PURE__ */ ((_) => (_.Arbitrum = "42161", _.ArbitrumHex = "0xa4b1", _.Avalanche = "43114", _.AvalancheHex = "0xa86a", _.Base = "8453", _.Binance = "Binance-Chain-Tigris", _.BinanceSmartChain = "56", _.BinanceSmartChainHex = "0x38", _.Bitcoin = "bitcoin", _.BitcoinCash = "bitcoincash", _.Cosmos = "cosmoshub-4", _.Dash = "dash", _.Dogecoin = "dogecoin", _.Kujira = "kaiyo-1", _.Ethereum = "1", _.EthereumHex = "0x1", _.Litecoin = "litecoin", _.Maya = "mayachain-mainnet-v1", _.MayaStagenet = "mayachain-stagenet-v1", _.Optimism = "10", _.OptimismHex = "0xa", _.Polygon = "137", _.PolygonHex = "0x89", _.THORChain = "thorchain-mainnet-v1", _.THORChainStagenet = "thorchain-stagenet-v2", _))(i || {}), O = /* @__PURE__ */ ((_) => (_.Arbitrum = "https://arb1.arbitrum.io/rpc", _.Avalanche = "https://node-router.thorswap.net/avalanche-c", _.Binance = "https://base.llamarpc.com", _.BinanceSmartChain = "https://bsc-dataseed.binance.org", _.Bitcoin = "https://node-router.thorswap.net/bitcoin", _.BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash", _.Cosmos = "https://node-router.thorswap.net/cosmos/rpc", _.Kujira = "https://rpc-kujira.synergynodes.com/", _.Dash = "https://dash.nownodes.io", _.Dogecoin = "https://node-router.thorswap.net/dogecoin", _.Ethereum = "https://node-router.thorswap.net/ethereum", _.Litecoin = "https://node-router.thorswap.net/litecoin", _.Maya = "https://tendermint.mayachain.info", _.MayaStagenet = "https://stagenet.tendermint.mayachain.info", _.Optimism = "https://mainnet.optimism.io", _.Polygon = "https://polygon-rpc.com", _.THORChain = "https://rpc.thorswap.net", _.THORChainStagenet = "https://stagenet-rpc.ninerealms.com", _))(O || {}), R = /* @__PURE__ */ ((_) => (_.Cosmos = "https://node-router.thorswap.net/cosmos/rest", _.Kujira = "https://lcd-kujira.synergynodes.com/", _.MayanodeMainnet = "https://mayanode.mayachain.info", _.MayanodeStagenet = "https://stagenet.mayanode.mayachain.info", _.ThornodeMainnet = "https://thornode.thorswap.net", _.ThornodeStagenet = "https://stagenet-thornode.ninerealms.com", _.ThorswapApi = "https://api.thorswap.finance", _.ThorswapStatic = "https://static.thorswap.net", _))(R || {});
const r = Object.values(e), n = Object.keys(e), D = r.reduce(
(_, S) => {
const E = n.find((t) => e[t] === S);
return E && (_[S] = E), _;
var o = /* @__PURE__ */ ((t) => (t.INVALID_INPUT_PARAMETERS = "1000", t.UNKNOWN_PROVIDERS = "1001", t.CANNOT_FIND_INBOUND_ADDRESS = "1002", t.NO_INBOUND_ADDRESSES = "1003", t.CHAIN_HALTED_OR_UNSUPPORTED = "1004", t.MISSING_INPUT_PARAMETER = "1005", t.INVALID_TYPE_GENERIC = "1100", t.INVALID_NUMBER_STRING = "1101", t.INVALID_NUMBER = "1102", t.INVALID_BOOLEAN = "1103", t.INVALID_OBJECT = "1104", t.INVALID_ARRAY = "1105", t.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", t.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", t.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", t.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", t.AFF_ADDRESS_TOO_LONG = "2004", t.AFF_BPS_INTEGER_0_100 = "2005", t.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", t.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", t.PREFERRED_PROFVIDER_NOT_SUPPORTED = "2008", t.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", t.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", t.SOURCE_ADDRESS_SMART_CONTRACT = "2011", t.INVALID_PROVIDER = "2100", t.MISSING_CROSS_CHAIN_PROVIDER = "2101", t.MISSING_AVAX_PROVIDER = "2102", t.MISSING_BSC_PROVIDER = "2103", t.MISSING_ETH_PROVIDER = "2104", t.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", t.MISSING_ARB_PROVIDER = "2106", t.INVALID_CHAIN = "2200", t.INVALID_ASSET = "2201", t.INVALID_ASSET_IDENTIFIER = "2202", t.UNSUPPORTED_CHAIN = "2204", t.UNSUPPORTED_ASSET = "2203", t.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", t.INVALID_SOURCE_ADDRESS = "2300", t.INVALID_DESTINATION_ADDRESS = "2301", t.THORNODE_QUOTE_GENERIC_ERROR = "3000", t.NOT_ENOUGH_SYNTH_BALANCE = "3001", t.SYNTH_MINTING_CAP_REACHED = "3002", t.INVALID_QUOTE_MODE = "4000", t.NO_QUOTES = "4001", t.SERVICE_UNAVAILABLE_GENERIC = "5000", t.MISSING_GAS_DATA_GENERIC = "5100", t.MISSING_TOKEN_INFO_GENERIC = "5200", t.CANT_FIND_TOKEN_LIST = "5201", t.NO_PRICE = "5202", t.PRICE_IS_STALE = "5203", t.ADDRESS_NOT_WHITELISTED = "6000", t.ADDRESS_ALREADY_CLAIMED = "6001", t.TEMPORARY_ERROR = "9999", t))(o || {});
o.INVALID_INPUT_PARAMETERS + "", o.UNKNOWN_PROVIDERS + "", o.CANNOT_FIND_INBOUND_ADDRESS + "", o.NO_INBOUND_ADDRESSES + "", o.CHAIN_HALTED_OR_UNSUPPORTED + "", o.MISSING_INPUT_PARAMETER + "", o.INVALID_TYPE_GENERIC + "", o.INVALID_NUMBER_STRING + "", o.INVALID_NUMBER + "", o.INVALID_BOOLEAN + "", o.INVALID_OBJECT + "", o.INVALID_ARRAY + "", o.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", o.SELL_BUY_ASSETS_ARE_THE_SAME + "", o.MISSING_SOURCE_ADDRESS_FOR_SYNTH + "", o.AFF_ADDRESS_AND_BPS_OR_NEITHER + "", o.AFF_ADDRESS_TOO_LONG + "", o.AFF_BPS_INTEGER_0_100 + "", o.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN + "", o.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN + "", o.PREFERRED_PROFVIDER_NOT_SUPPORTED + "", o.DESTINATION_ADDRESS_SMART_CONTRACT + "", o.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER + "", o.INVALID_PROVIDER + "", o.MISSING_CROSS_CHAIN_PROVIDER + "", o.MISSING_AVAX_PROVIDER + "", o.MISSING_BSC_PROVIDER + "", o.MISSING_ETH_PROVIDER + "", o.MISSING_ARB_PROVIDER + "", o.INVALID_PROVIDER_FOR_SWAP_OUT + "", o.INVALID_CHAIN + "", o.INVALID_ASSET + "", o.UNSUPPORTED_CHAIN + "", o.UNSUPPORTED_ASSET + "", o.UNSUPPORTED_ASSET_FOR_SWAPOUT + "", o.THORNODE_QUOTE_GENERIC_ERROR + "", o.INVALID_SOURCE_ADDRESS + "", o.INVALID_DESTINATION_ADDRESS + "", o.NOT_ENOUGH_SYNTH_BALANCE + "", o.SYNTH_MINTING_CAP_REACHED + "", o.INVALID_QUOTE_MODE + "", o.NO_QUOTES + "", o.SERVICE_UNAVAILABLE_GENERIC + "", o.MISSING_GAS_DATA_GENERIC + "", o.MISSING_TOKEN_INFO_GENERIC + "", o.CANT_FIND_TOKEN_LIST + "", o.NO_PRICE + "", o.PRICE_IS_STALE + "", o.ADDRESS_NOT_WHITELISTED + "", o.ADDRESS_ALREADY_CLAIMED + "";
var R = /* @__PURE__ */ ((t) => (t.Arbitrum = "ARB", t.Avalanche = "AVAX", t.Base = "BASE", t.Binance = "BNB", t.BinanceSmartChain = "BSC", t.Bitcoin = "BTC", t.BitcoinCash = "BCH", t.Cosmos = "GAIA", t.Dash = "DASH", t.Digibyte = "DGB", t.Dogecoin = "DOGE", t.EOS = "EOS", t.Ethereum = "ETH", t.Kujira = "KUJI", t.Litecoin = "LTC", t.Maya = "MAYA", t.Optimism = "OP", t.Osmosis = "OSMO", t.Polygon = "MATIC", t.Ripple = "XRP", t.THORChain = "THOR", t.Zcash = "ZEC", t))(R || {});
const B = {
ARB: "eip155:42161",
AVAX: "eip155:43114",
BSC: "eip155:56",
BNB: "binance:bnb-beacon-chain",
BCH: "bip122:000000000000000000651ef99cb9fcbe",
BTC: "bip122:000000000019d6689c085ae165831e93",
BASE: "eip155:8453",
GAIA: "cosmos:cosmoshub-4",
DASH: "bip122:dash-hash",
DGB: "bip122:digibytes-hash",
DOGE: "bip122:00000000001a91e3dace36e2be3bf030",
KUJI: "cosmos:kaiyo-1",
EOS: "eos:cf057bbfb72640471fd910bcb67639c2",
ETH: "eip155:1",
LTC: "bip122:12a765e31ffd4059bada1e25190f6e98",
MAYA: "cosmos:maya-mainnet-v1",
OP: "eip155:10",
OSMO: "cosmos:osmosis-1",
MATIC: "eip155:137",
XRP: "ripple:unknown",
THOR: "cosmos:thorchain-mainnet-v1",
ZEC: "bip122:0000000000196a45"
};
for (const t in R)
B[R[t]], R[t];
var f = /* @__PURE__ */ ((t) => (t.Arbitrum = "42161", t.ArbitrumHex = "0xa4b1", t.Avalanche = "43114", t.AvalancheHex = "0xa86a", t.Base = "8453", t.Binance = "Binance-Chain-Tigris", t.BinanceSmartChain = "56", t.BinanceSmartChainHex = "0x38", t.Bitcoin = "bitcoin", t.BitcoinCash = "bitcoincash", t.Cosmos = "cosmoshub-4", t.Dash = "dash", t.Dogecoin = "dogecoin", t.Kujira = "kaiyo-1", t.Ethereum = "1", t.EthereumHex = "0x1", t.Litecoin = "litecoin", t.Maya = "mayachain-mainnet-v1", t.MayaStagenet = "mayachain-stagenet-v1", t.Optimism = "10", t.OptimismHex = "0xa", t.Osmosis = "osmosis-1", t.Polygon = "137", t.PolygonHex = "0x89", t.THORChain = "thorchain-mainnet-v1", t.THORChainStagenet = "thorchain-stagenet-v2", t))(f || {}), b = /* @__PURE__ */ ((t) => (t.Arbitrum = "https://arb1.arbitrum.io/rpc", t.Avalanche = "https://node-router.thorswap.net/avalanche-c", t.Binance = "https://base.llamarpc.com", t.BinanceSmartChain = "https://bsc-dataseed.binance.org", t.Bitcoin = "https://node-router.thorswap.net/bitcoin", t.BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash", t.Cosmos = "https://node-router.thorswap.net/cosmos/rpc", t.Kujira = "https://rpc-kujira.synergynodes.com/", t.Dash = "https://dash.nownodes.io", t.Dogecoin = "https://node-router.thorswap.net/dogecoin", t.Ethereum = "https://node-router.thorswap.net/ethereum", t.Litecoin = "https://node-router.thorswap.net/litecoin", t.Maya = "https://tendermint.mayachain.info", t.MayaStagenet = "https://stagenet.tendermint.mayachain.info", t.Optimism = "https://mainnet.optimism.io", t.Osmosis = "https://rpc-osmosis.keplr.app", t.Polygon = "https://polygon-rpc.com", t.THORChain = "https://rpc.thorswap.net", t.THORChainStagenet = "https://stagenet-rpc.ninerealms.com", t))(b || {}), E = /* @__PURE__ */ ((t) => (t.Cosmos = "https://node-router.thorswap.net/cosmos/rest", t.Kujira = "https://lcd-kujira.synergynodes.com/", t.MayanodeMainnet = "https://mayanode.mayachain.info", t.MayanodeStagenet = "https://stagenet.mayanode.mayachain.info", t.ThornodeMainnet = "https://thornode.thorswap.net", t.ThornodeStagenet = "https://stagenet-thornode.ninerealms.com", t.ThorswapApi = "https://api.thorswap.net", t.ThorswapStatic = "https://static.thorswap.net", t))(E || {});
const I = Object.values(R), V = Object.keys(R), C = I.reduce(
(t, e) => {
const r = V.find((s) => R[s] === e);
return r && (t[e] = r), t;
},
{}
);
r.reduce(
(_, S) => (_[S] = i[D[S]], _),
I.reduce(
(t, e) => (t[e] = f[C[e]], t),
{}
);
r.reduce(
(_, S) => (_[S] = O[D[S]], _),
I.reduce(
(t, e) => (t[e] = b[C[e]], t),
{}
);
r.reduce(
(_, S) => {
const E = `${D[S]}Hex`;
return _[S] = i[E], _;
I.reduce(
(t, e) => {
const r = `${C[e]}Hex`;
return t[e] = f[r], t;
},
{}
);
const C = (_) => ("recipientAddress" in _ && _.recipientAddress && (_.recipientAddress = _.recipientAddress.replace(/(bchtest:|bitcoincash:)/, "")), new URLSearchParams(_).toString()), I = {
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`
}, N = {
get: (_, S, E) => fetch(`${_}${S ? `?${C(S)}` : ""}`, {
referrer: "https://sk.thorswap.net"
}).then((t) => t.json()).catch((t) => {
var T;
return console.error(t), (T = E == null ? void 0 : E.onError) == null || T.call(E, t), Promise.reject(t);
}),
post: (_, S, E) => fetch(_, {
class D extends Error {
constructor(e, r, s) {
const i = e.status || e.status === 0 ? e.status : "", n = e.statusText || "", a = `${i} ${n}`.trim(), _ = a ? `status code ${a}` : "an unknown error";
super(`Request failed with ${_}`), Object.defineProperty(this, "response", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "request", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "options", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), this.name = "HTTPError", this.response = e, this.request = r, this.options = s;
}
}
class g extends Error {
constructor(e) {
super("Request timed out"), Object.defineProperty(this, "request", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), this.name = "TimeoutError", this.request = e;
}
}
const d = (t) => t !== null && typeof t == "object", T = (...t) => {
for (const e of t)
if ((!d(e) || Array.isArray(e)) && e !== void 0)
throw new TypeError("The `options` argument must be an object");
return O({}, ...t);
}, y = (t = {}, e = {}) => {
const r = new globalThis.Headers(t), s = e instanceof globalThis.Headers, i = new globalThis.Headers(e);
for (const [n, a] of i.entries())
s && a === "undefined" || a === void 0 ? r.delete(n) : r.set(n, a);
return r;
}, O = (...t) => {
let e = {}, r = {};
for (const s of t)
if (Array.isArray(s))
Array.isArray(e) || (e = []), e = [...e, ...s];
else if (d(s)) {
for (let [i, n] of Object.entries(s))
d(n) && i in e && (n = O(e[i], n)), e = { ...e, [i]: n };
d(s.headers) && (r = y(r, s.headers), e.headers = r);
}
return e;
}, H = (() => {
let t = !1, e = !1;
const r = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function";
return r && s && (e = new globalThis.Request("https://empty.invalid", {
body: new globalThis.ReadableStream(),
method: "POST",
referrer: "https://sk.thorswap.net",
headers: { "Content-Type": "application/json", ...(E == null ? void 0 : E.headers) || {} },
body: typeof S == "string" ? S : C(S)
}).then((t) => t.json())
}, a = ({ tokens: _, ...S }) => {
const E = new URLSearchParams();
return _.filter((t, T, o) => o.findIndex((s) => s === t) === T).forEach((t) => E.append("tokens", JSON.stringify(t))), S.metadata && E.append("metadata", "true"), S.lookup && E.append("lookup", "true"), S.sparkline && E.append("sparkline", "true"), N.post(I.CachedPrices, E.toString(), {
// @ts-expect-error - Types are outdated.
get duplex() {
return t = !0, "half";
}
}).headers.has("Content-Type")), t && !e;
})(), v = typeof globalThis.AbortController == "function", M = typeof globalThis.ReadableStream == "function", G = typeof globalThis.FormData == "function", U = ["get", "post", "put", "patch", "head", "delete"], F = {
json: "application/json",
text: "text/*",
formData: "multipart/form-data",
arrayBuffer: "*/*",
blob: "*/*"
}, p = 2147483647, L = Symbol("stop"), W = {
json: !0,
parseJson: !0,
searchParams: !0,
prefixUrl: !0,
retry: !0,
timeout: !0,
hooks: !0,
throwHttpErrors: !0,
onDownloadProgress: !0,
fetch: !0
}, k = {
method: !0,
headers: !0,
body: !0,
mode: !0,
credentials: !0,
cache: !0,
redirect: !0,
referrer: !0,
referrerPolicy: !0,
integrity: !0,
keepalive: !0,
signal: !0,
window: !0,
dispatcher: !0,
duplex: !0
}, q = (t) => U.includes(t) ? t.toUpperCase() : t, x = ["get", "put", "head", "delete", "options", "trace"], j = [408, 413, 429, 500, 502, 503, 504], w = [413, 429, 503], m = {
limit: 2,
methods: x,
statusCodes: j,
afterStatusCodes: w,
maxRetryAfter: Number.POSITIVE_INFINITY,
backoffLimit: Number.POSITIVE_INFINITY,
delay: (t) => 0.3 * 2 ** (t - 1) * 1e3
}, X = (t = {}) => {
if (typeof t == "number")
return {
...m,
limit: t
};
if (t.methods && !Array.isArray(t.methods))
throw new Error("retry.methods must be an array");
if (t.statusCodes && !Array.isArray(t.statusCodes))
throw new Error("retry.statusCodes must be an array");
return {
...m,
...t,
afterStatusCodes: w
};
};
async function Y(t, e, r, s) {
return new Promise((i, n) => {
const a = setTimeout(() => {
r && r.abort(), n(new g(t));
}, s.timeout);
s.fetch(t, e).then(i).catch(n).then(() => {
clearTimeout(a);
});
});
}
async function $(t, { signal: e }) {
return new Promise((r, s) => {
e && (e.throwIfAborted(), e.addEventListener("abort", i, { once: !0 }));
function i() {
clearTimeout(n), s(e.reason);
}
const n = setTimeout(() => {
e == null || e.removeEventListener("abort", i), r();
}, t);
});
}
const K = (t, e) => {
const r = {};
for (const s in e)
!(s in k) && !(s in W) && !(s in t) && (r[s] = e[s]);
return r;
};
class l {
static create(e, r) {
const s = new l(e, r), i = async () => {
if (typeof s._options.timeout == "number" && s._options.timeout > p)
throw new RangeError(`The \`timeout\` option cannot be greater than ${p}`);
await Promise.resolve();
let _ = await s._fetch();
for (const A of s._options.hooks.afterResponse) {
const u = await A(s.request, s._options, s._decorateResponse(_.clone()));
u instanceof globalThis.Response && (_ = u);
}
if (s._decorateResponse(_), !_.ok && s._options.throwHttpErrors) {
let A = new D(_, s.request, s._options);
for (const u of s._options.hooks.beforeError)
A = await u(A);
throw A;
}
if (s._options.onDownloadProgress) {
if (typeof s._options.onDownloadProgress != "function")
throw new TypeError("The `onDownloadProgress` option must be a function");
if (!M)
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
return s._stream(_.clone(), s._options.onDownloadProgress);
}
return _;
}, a = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(i) : i();
for (const [_, A] of Object.entries(F))
a[_] = async () => {
s.request.headers.set("accept", s.request.headers.get("accept") || A);
const c = (await a).clone();
if (_ === "json") {
if (c.status === 204 || (await c.clone().arrayBuffer()).byteLength === 0)
return "";
if (r.parseJson)
return r.parseJson(await c.text());
}
return c[_]();
};
return a;
}
// eslint-disable-next-line complexity
constructor(e, r = {}) {
if (Object.defineProperty(this, "request", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "abortController", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "_retryCount", {
enumerable: !0,
configurable: !0,
writable: !0,
value: 0
}), Object.defineProperty(this, "_input", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), Object.defineProperty(this, "_options", {
enumerable: !0,
configurable: !0,
writable: !0,
value: void 0
}), this._input = e, this._options = {
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
credentials: this._input.credentials || "same-origin",
...r,
headers: y(this._input.headers, r.headers),
hooks: O({
beforeRequest: [],
beforeRetry: [],
beforeError: [],
afterResponse: []
}, r.hooks),
method: q(r.method ?? this._input.method),
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
prefixUrl: String(r.prefixUrl || ""),
retry: X(r.retry),
throwHttpErrors: r.throwHttpErrors !== !1,
timeout: r.timeout ?? 1e4,
fetch: r.fetch ?? globalThis.fetch.bind(globalThis)
}, typeof this._input != "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request))
throw new TypeError("`input` must be a string, URL, or Request");
if (this._options.prefixUrl && typeof this._input == "string") {
if (this._input.startsWith("/"))
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
}
if (v) {
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
const s = this._options.signal;
this._options.signal.addEventListener("abort", () => {
this.abortController.abort(s.reason);
});
}
this._options.signal = this.abortController.signal;
}
if (H && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
const i = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), n = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, i);
(G && 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(n, { ...this.request }), this._options);
}
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(e) {
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(e instanceof g)) {
if (e instanceof D) {
if (!this._options.retry.statusCodes.includes(e.response.status))
return 0;
const s = e.response.headers.get("Retry-After");
if (s && this._options.retry.afterStatusCodes.includes(e.response.status)) {
let i = Number(s);
return Number.isNaN(i) ? i = Date.parse(s) - Date.now() : i *= 1e3, this._options.retry.maxRetryAfter !== void 0 && i > this._options.retry.maxRetryAfter ? 0 : i;
}
if (e.response.status === 413)
return 0;
}
const r = this._options.retry.delay(this._retryCount);
return Math.min(this._options.retry.backoffLimit, r);
}
return 0;
}
_decorateResponse(e) {
return this._options.parseJson && (e.json = async () => this._options.parseJson(await e.text())), e;
}
async _retry(e) {
try {
return await e();
} catch (r) {
const s = Math.min(this._calculateRetryDelay(r), p);
if (s !== 0 && this._retryCount > 0) {
await $(s, { signal: this._options.signal });
for (const i of this._options.hooks.beforeRetry)
if (await i({
request: this.request,
options: this._options,
error: r,
retryCount: this._retryCount
}) === L)
return;
return this._retry(e);
}
throw r;
}
}
async _fetch() {
for (const r of this._options.hooks.beforeRequest) {
const s = await r(this.request, this._options);
if (s instanceof Request) {
this.request = s;
break;
}
if (s instanceof Response)
return s;
}
const e = K(this.request, this._options);
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), e) : Y(this.request.clone(), e, this.abortController, this._options);
}
/* istanbul ignore next */
_stream(e, r) {
const s = Number(e.headers.get("content-length")) || 0;
let i = 0;
return e.status === 204 ? (r && r({ percent: 1, totalBytes: s, transferredBytes: i }, new Uint8Array()), new globalThis.Response(null, {
status: e.status,
statusText: e.statusText,
headers: e.headers
})) : new globalThis.Response(new globalThis.ReadableStream({
async start(n) {
const a = e.body.getReader();
r && r({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array());
async function _() {
const { done: A, value: u } = await a.read();
if (A) {
n.close();
return;
}
if (r) {
i += u.byteLength;
const c = s === 0 ? 0 : i / s;
r({ percent: c, transferredBytes: i, totalBytes: s }, u);
}
n.enqueue(u), await _();
}
await _();
}
}), {
status: e.status,
statusText: e.statusText,
headers: e.headers
});
}
}
/*! MIT License © Sindre Sorhus */
const N = (t) => {
const e = (r, s) => l.create(r, T(t, s));
for (const r of U)
e[r] = (s, i) => l.create(s, T(t, i, { method: r }));
return e.create = (r) => N(T(r)), e.extend = (r) => N(T(t, r)), e.stop = L, e;
}, J = N(), Q = J, h = {
CachedPrices: `${E.ThorswapApi}/tokenlist/cached-price`,
GasRates: `${E.ThorswapApi}/resource-worker/gasPrice/getAll`,
Quote: `${E.ThorswapApi}/aggregator/tokens/quote`,
Txn: `${E.ThorswapApi}/apiusage/v2/txn`,
TokenlistProviders: `${E.ThorswapApi}/tokenlist/providers`,
TokenList: `${E.ThorswapStatic}/token-list`,
Thorname: `${E.ThorswapApi}/thorname`
}, z = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, P = Q.create({ headers: z }), S = {
get: (t, e) => P.get(t, e).json(),
post: (t, e) => P.post(t, e).json()
}, Z = ({ tokens: t, ...e }) => {
const r = new URLSearchParams();
return t.filter((s, i, n) => n.findIndex((a) => a === s) === i).forEach((s) => r.append("tokens", JSON.stringify(s))), e.metadata && r.append("metadata", "true"), e.lookup && r.append("lookup", "true"), e.sparkline && r.append("sparkline", "true"), S.post(h.CachedPrices, {
body: r.toString(),
headers: { "Content-Type": "application/x-www-form-urlencoded" }
});
}, U = {
getCachedPrices: a,
getQuote: (_) => N.get(I.Quote, _),
getGasRates: () => N.get(I.GasRates),
getTxnDetails: (_) => N.get(I.Txn, { txHash: _ }),
getTokenlistProviders: () => N.get(I.TokenlistProviders),
getTokenList: (_) => N.get(`${I.TokenList}/${_}.json`),
getThornameAddresses: (_) => N.get(`${I.Thorname}/${_}`),
getThornameRegisteredChains: (_) => N.get(`${I.Thorname}/chains/${_}`),
getThornameRlookup: (_, S) => N.get(`${I.Thorname}/rlookup`, { address: _, chain: S })
}, it = {
getCachedPrices: Z,
getQuote: (t) => S.get(h.Quote, { searchParams: t }),
getGasRates: () => S.get(h.GasRates),
getTxnDetails: (t) => S.get(h.Txn, { searchParams: t }),
getTokenlistProviders: () => S.get(h.TokenlistProviders),
getTokenList: (t) => S.get(`${h.TokenList}/${t}.json`),
getThornameAddresses: (t) => S.get(`${h.Thorname}/${t}`),
getThornameRegisteredChains: (t) => S.get(`${h.Thorname}/chains/${t}`),
getThornameRlookup: (t, e) => S.get(`${h.Thorname}/rlookup`, { searchParams: { address: t, chain: e } })
};
var P = /* @__PURE__ */ ((_) => (_.SWAP_TC_TO_TC = "SWAP:TC-TC", _.SWAP_ETH_TO_TC = "SWAP:ERC20-TC", _.SWAP_TC_TO_ETH = "SWAP:TC-ERC20", _.SWAP_ETH_TO_ETH = "SWAP:ERC20-ERC20", _.SWAP_AVAX_TO_TC = "SWAP:AVAX-TC", _.SWAP_TC_TO_AVAX = "SWAP:TC-AVAX", _.SWAP_AVAX_TO_AVAX = "SWAP:AVAX-AVAX", _.SWAP_ETH_TO_AVAX = "SWAP:ETH-AVAX", _.SWAP_AVAX_TO_ETH = "SWAP:AVAX-ETH", _.SWAP_TC_TO_GAIA = "SWAP:TC-GAIA", _.SWAP_GAIA_TO_TC = "SWAP:GAIA-TC", _.SWAP_TC_TO_BNB = "SWAP:TC-BNB", _.SWAP_BNB_TO_TC = "SWAP:BNB-TC", _.SWAP_TC_TO_BTC = "SWAP:TC-BTC", _.SWAP_BTC_TO_TC = "SWAP:BTC-TC", _.SWAP_TC_TO_BCH = "SWAP:TC-BCH", _.SWAP_BCH_TO_TC = "SWAP:BCH-TC", _.SWAP_TC_TO_LTC = "SWAP:TC-LTC", _.SWAP_LTC_TO_TC = "SWAP:LTC-TC", _.SWAP_TC_TO_DOGE = "SWAP:TC-DOGE", _.SWAP_DOGE_TO_TC = "SWAP:DOGE-TC", _.TC_STATUS = "TC:STATUS", _.TC_TRANSFER = "TC:TRANSFER", _.TC_DEPOSIT = "TC:DEPOSIT", _.TC_SEND = "TC:SEND", _.TC_SWITCH = "TC:SWITCH", _.TC_LP_ADD = "TC:ADDLIQUIDITY", _.TC_LP_WITHDRAW = "TC:WITHDRAW", _.TC_TNS_CREATE = "TC:TNS-CREATE", _.TC_TNS_EXTEND = "TC:TNS-EXTEND", _.TC_TNS_UPDATE = "TC:TNS-UPDATE", _.TC_SAVINGS_ADD = "TC:ADDSAVINGS", _.TC_SAVINGS_WITHDRAW = "TC:WITHDRAWSAVINGS", _.TC_LENDING_OPEN = "TC:LENDINGOPEN", _.TC_LENDING_CLOSE = "TC:LENDINGCLOSE", _.ETH_APPROVAL = "ETH:APPROVAL", _.ETH_STATUS = "ETH:STATUS", _.ETH_TRANSFER_TO_TC = "ETH:TRANSFER:IN", _.ETH_TRANSFER_FROM_TC = "ETH:TRANSFER:OUT", _.AVAX_APPROVAL = "AVAX:APPROVAL", _.AVAX_STATUS = "AVAX:STATUS", _.AVAX_TRANSFER_TO_TC = "AVAX:TRANSFER:IN", _.AVAX_TRANSFER_FROM_TC = "AVAX:TRANSFER:OUT", _.BSC_APPROVAL = "BSC:APPROVAL", _.BSC_STATUS = "BSC:STATUS", _.BSC_TRANSFER_TO_TC = "BSC:TRANSFER:IN", _.BSC_TRANSFER_FROM_TC = "BSC:TRANSFER:OUT", _.APPROVAL = "APPROVAL", _.STATUS = "STATUS", _.TRANSFER_TO_TC = "TRANSFER:IN", _.TRANSFER_FROM_TC = "TRANSFER:OUT", _.UNSUPPORTED = "UNSUPPORTED", _.TC_LENDING = "TC:LENDING", _))(P || {}), d = /* @__PURE__ */ ((_) => (_.PENDING = "pending", _.SUCCESS = "success", _.CANCELLED = "cancelled", _.REFUNDED = "refunded", _.REPLACED = "replaced", _.ERROR = "error", _.UNKNOWN = "unknown", _.NOT_STARTED = "not_started", _.NOT_FOUND = "not_found", _.RETRIES_EXCEEDED = "retries_exceeded", _.STREAMING = "streaming", _))(d || {}), h = /* @__PURE__ */ ((_) => (_[_.NOT_STARTED = 0] = "NOT_STARTED", _[_.SUCCESS = 1] = "SUCCESS", _[_.REFUNDED = 2] = "REFUNDED", _))(h || {});
var tt = /* @__PURE__ */ ((t) => (t.SWAP_TC_TO_TC = "SWAP:TC-TC", t.SWAP_ETH_TO_TC = "SWAP:ERC20-TC", t.SWAP_TC_TO_ETH = "SWAP:TC-ERC20", t.SWAP_ETH_TO_ETH = "SWAP:ERC20-ERC20", t.SWAP_AVAX_TO_TC = "SWAP:AVAX-TC", t.SWAP_TC_TO_AVAX = "SWAP:TC-AVAX", t.SWAP_AVAX_TO_AVAX = "SWAP:AVAX-AVAX", t.SWAP_ETH_TO_AVAX = "SWAP:ETH-AVAX", t.SWAP_AVAX_TO_ETH = "SWAP:AVAX-ETH", t.SWAP_TC_TO_GAIA = "SWAP:TC-GAIA", t.SWAP_GAIA_TO_TC = "SWAP:GAIA-TC", t.SWAP_TC_TO_BNB = "SWAP:TC-BNB", t.SWAP_BNB_TO_TC = "SWAP:BNB-TC", t.SWAP_TC_TO_BTC = "SWAP:TC-BTC", t.SWAP_BTC_TO_TC = "SWAP:BTC-TC", t.SWAP_TC_TO_BCH = "SWAP:TC-BCH", t.SWAP_BCH_TO_TC = "SWAP:BCH-TC", t.SWAP_TC_TO_LTC = "SWAP:TC-LTC", t.SWAP_LTC_TO_TC = "SWAP:LTC-TC", t.SWAP_TC_TO_DOGE = "SWAP:TC-DOGE", t.SWAP_DOGE_TO_TC = "SWAP:DOGE-TC", t.TC_STATUS = "TC:STATUS", t.TC_TRANSFER = "TC:TRANSFER", t.TC_DEPOSIT = "TC:DEPOSIT", t.TC_SEND = "TC:SEND", t.TC_SWITCH = "TC:SWITCH", t.TC_LP_ADD = "TC:ADDLIQUIDITY", t.TC_LP_WITHDRAW = "TC:WITHDRAW", t.TC_TNS_CREATE = "TC:TNS-CREATE", t.TC_TNS_EXTEND = "TC:TNS-EXTEND", t.TC_TNS_UPDATE = "TC:TNS-UPDATE", t.TC_SAVINGS_ADD = "TC:ADDSAVINGS", t.TC_SAVINGS_WITHDRAW = "TC:WITHDRAWSAVINGS", t.TC_LENDING_OPEN = "TC:LENDINGOPEN", t.TC_LENDING_CLOSE = "TC:LENDINGCLOSE", t.ETH_APPROVAL = "ETH:APPROVAL", t.ETH_STATUS = "ETH:STATUS", t.ETH_TRANSFER_TO_TC = "ETH:TRANSFER:IN", t.ETH_TRANSFER_FROM_TC = "ETH:TRANSFER:OUT", t.AVAX_APPROVAL = "AVAX:APPROVAL", t.AVAX_STATUS = "AVAX:STATUS", t.AVAX_TRANSFER_TO_TC = "AVAX:TRANSFER:IN", t.AVAX_TRANSFER_FROM_TC = "AVAX:TRANSFER:OUT", t.BSC_APPROVAL = "BSC:APPROVAL", t.BSC_STATUS = "BSC:STATUS", t.BSC_TRANSFER_TO_TC = "BSC:TRANSFER:IN", t.BSC_TRANSFER_FROM_TC = "BSC:TRANSFER:OUT", t.APPROVAL = "APPROVAL", t.STATUS = "STATUS", t.TRANSFER_TO_TC = "TRANSFER:IN", t.TRANSFER_FROM_TC = "TRANSFER:OUT", t.UNSUPPORTED = "UNSUPPORTED", t.TC_LENDING = "TC:LENDING", t))(tt || {}), et = /* @__PURE__ */ ((t) => (t.PENDING = "pending", t.SUCCESS = "success", t.CANCELLED = "cancelled", t.REFUNDED = "refunded", t.REPLACED = "replaced", t.ERROR = "error", t.UNKNOWN = "unknown", t.NOT_STARTED = "not_started", t.NOT_FOUND = "not_found", t.RETRIES_EXCEEDED = "retries_exceeded", t.STREAMING = "streaming", t))(et || {}), st = /* @__PURE__ */ ((t) => (t[t.NOT_STARTED = 0] = "NOT_STARTED", t[t.SUCCESS = 1] = "SUCCESS", t[t.REFUNDED = 2] = "REFUNDED", t))(st || {});
export {
h as StreamingSwapProgressStatus,
U as SwapKitApi,
P as TransactionType,
d as TxStatus
st as StreamingSwapProgressStatus,
it as SwapKitApi,
tt as TransactionType,
et as TxStatus
};

13

package.json
{
"author": "swapkit-oss-team",
"dependencies": {
"@coinmasters/types": "4.0.0"
"ky": "1.1.3",
"@coinmasters/types": "4.0.1"
},
"description": "SwapKit Lib swapkit-api",
"devDependencies": {
"@vitest/coverage-istanbul": "0.34.4",
"vite": "4.4.9",
"vitest": "0.34.4",
"@internal/config": "2.0.0"
"@vitest/coverage-istanbul": "0.34.6",
"vite": "4.5.0",
"vitest": "0.34.6",
"@internal/config": "2.0.1"
},

@@ -39,3 +40,3 @@ "eslintConfig": {

"types": "./dist/index.d.ts",
"version": "3.0.1",
"version": "3.0.2",
"scripts": {

@@ -42,0 +43,0 @@ "build": "vite build",

@@ -1,2 +0,2 @@

import { ApiEndpoints, FetchWrapper } from './fetchWrapper.ts';
import { ApiEndpoints, RequestClient } from './fetchWrapper.ts';
import type {

@@ -23,3 +23,4 @@ CachedPricesParams,

return FetchWrapper.post<CachedPricesResponse[]>(ApiEndpoints.CachedPrices, body.toString(), {
return RequestClient.post<CachedPricesResponse[]>(ApiEndpoints.CachedPrices, {
body: body.toString(),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },

@@ -31,15 +32,17 @@ });

getCachedPrices,
getQuote: (params: QuoteParams) => FetchWrapper.get<QuoteResponse>(ApiEndpoints.Quote, params),
getGasRates: () => FetchWrapper.get<GasRatesResponse>(ApiEndpoints.GasRates),
getTxnDetails: (txHash: string) => FetchWrapper.get<TxnResponse>(ApiEndpoints.Txn, { txHash }),
getQuote: (params: QuoteParams) =>
RequestClient.get<QuoteResponse>(ApiEndpoints.Quote, { searchParams: params }),
getGasRates: () => RequestClient.get<GasRatesResponse>(ApiEndpoints.GasRates),
getTxnDetails: (txHash: string) =>
RequestClient.get<TxnResponse>(ApiEndpoints.Txn, { searchParams: txHash }),
getTokenlistProviders: () =>
FetchWrapper.get<TokenlistProvidersResponse>(ApiEndpoints.TokenlistProviders),
RequestClient.get<TokenlistProvidersResponse>(ApiEndpoints.TokenlistProviders),
getTokenList: (tokenlist: string) =>
FetchWrapper.get(`${ApiEndpoints.TokenList}/${tokenlist}.json`),
RequestClient.get(`${ApiEndpoints.TokenList}/${tokenlist}.json`),
getThornameAddresses: (address: string) =>
FetchWrapper.get<ThornameResponse>(`${ApiEndpoints.Thorname}/${address}`),
RequestClient.get<ThornameResponse>(`${ApiEndpoints.Thorname}/${address}`),
getThornameRegisteredChains: (address: string) =>
FetchWrapper.get<string[]>(`${ApiEndpoints.Thorname}/chains/${address}`),
RequestClient.get<string[]>(`${ApiEndpoints.Thorname}/chains/${address}`),
getThornameRlookup: (address: string, chain: string) =>
FetchWrapper.get(`${ApiEndpoints.Thorname}/rlookup`, { address, chain }),
RequestClient.get(`${ApiEndpoints.Thorname}/rlookup`, { searchParams: { address, chain } }),
};
import { ApiUrl } from '@coinmasters/types';
import type { Options } from 'ky';
import ky from 'ky';
import type { ApiParams } from './types/index.ts';
type RequestConfig = {
onError?: (error: any) => void;
headers?: Record<string, string>;
};
const paramsToString = (params: { [key: string]: any }) => {
if ('recipientAddress' in params && params.recipientAddress) {
params.recipientAddress = params.recipientAddress.replace(/(bchtest:|bitcoincash:)/, '');
}
return new URLSearchParams(params).toString();
};
/**

@@ -31,20 +18,13 @@ * Api Wrapper helpers

export const FetchWrapper = {
get: <T>(url: string, params?: ApiParams, config?: RequestConfig) =>
fetch(`${url}${params ? `?${paramsToString(params)}` : ''}`, {
referrer: 'https://sk.thorswap.net',
})
.then((res) => res.json() as Promise<T>)
.catch((error) => {
console.error(error);
config?.onError?.(error);
return Promise.reject(error);
}),
post: <T>(url: string, params: ApiParams | string, config?: RequestConfig) =>
fetch(url, {
method: 'POST',
referrer: 'https://sk.thorswap.net',
headers: { 'Content-Type': 'application/json', ...(config?.headers || {}) },
body: typeof params === 'string' ? params : paramsToString(params),
}).then((res) => res.json() as Promise<T>),
const headers =
typeof window !== 'undefined'
? {}
: { referrer: 'https://sk.thorswap.net', referer: 'https://sk.thorswap.net' };
const kyClient = ky.create({ headers });
export const RequestClient = {
get: <T>(url: string | URL | Request, options?: Options) => kyClient.get(url, options).json<T>(),
post: <T>(url: string | URL | Request, options?: Options) =>
kyClient.post(url, options).json<T>(),
};

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