@coinmasters/helpers
Advanced tools
Comparing version
@@ -6,3 +6,3 @@ import { Chain } from '@coinmasters/types'; | ||
import { MemoType } from '@coinmasters/types'; | ||
import type { Options } from 'ky'; | ||
import { Options } from 'ky'; | ||
import type { PancakeswapETHList } from '@coinmasters/tokens'; | ||
@@ -9,0 +9,0 @@ import type { PancakeswapList } from '@coinmasters/tokens'; |
@@ -16,3 +16,3 @@ var bt = Object.defineProperty; | ||
try { | ||
const { result: e } = await Xt.post(vt[r], { | ||
const { result: e } = await te.post(vt[r], { | ||
headers: { | ||
@@ -53,3 +53,3 @@ accept: "*/*", | ||
} | ||
}, ie = { | ||
}, ae = { | ||
[L.Average]: 1.2, | ||
@@ -158,3 +158,3 @@ [L.Fast]: 1.5, | ||
} | ||
}, ae = (r) => { | ||
}, oe = (r) => { | ||
var o; | ||
@@ -172,3 +172,3 @@ const [t, ...e] = r.split("."), s = r.includes("/"), n = e.join("."), a = (o = n == null ? void 0 : n.split("-")) == null ? void 0 : o[0]; | ||
return ot({ chain: t, symbol: e }) || !!s; | ||
}, oe = (r) => r.filter((t) => { | ||
}, ce = (r) => r.filter((t) => { | ||
const e = `${t.chain}.${t.symbol}`; | ||
@@ -190,3 +190,3 @@ return !Bt.test(e) && Et(e) && t.value !== "0"; | ||
return l.div(_); | ||
}, ce = ({ | ||
}, ue = ({ | ||
percent: r, | ||
@@ -196,3 +196,3 @@ runeDepth: t, | ||
poolUnits: s | ||
}) => Mt({ runeDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), ue = ({ | ||
}) => Mt({ runeDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), le = ({ | ||
percent: r, | ||
@@ -210,3 +210,3 @@ assetDepth: t, | ||
runeAmount: p(e).mul(r).div(t) | ||
}), le = ({ | ||
}), he = ({ | ||
liquidityUnits: r, | ||
@@ -221,3 +221,3 @@ poolUnits: t, | ||
) | ||
), he = ({ | ||
), de = ({ | ||
runeDepth: r, | ||
@@ -235,3 +235,3 @@ poolUnits: t, | ||
return D.div(gt).getBaseValue("number"); | ||
}, de = ({ | ||
}, me = ({ | ||
runeAmount: r, | ||
@@ -250,3 +250,3 @@ assetAmount: t, | ||
chain: e | ||
}) => e === "ETH" && t !== "ETH" ? `${t}-${r.slice(-3)}` : r, me = (r, t) => { | ||
}) => e === "ETH" && t !== "ETH" ? `${t}-${r.slice(-3)}` : r, pe = (r, t) => { | ||
switch (r) { | ||
@@ -282,7 +282,7 @@ case b.LEAVE: | ||
} | ||
}, pe = (r) => { | ||
}, fe = (r) => { | ||
if (r < 0) | ||
throw new Error("Invalid number of year"); | ||
return 10 + r; | ||
}, fe = (r) => { | ||
}, _e = (r) => { | ||
if (r.length > 30) | ||
@@ -292,3 +292,3 @@ return !1; | ||
return !!r.match(t); | ||
}, _e = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`; | ||
}, ge = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`; | ||
class X extends Error { | ||
@@ -642,6 +642,22 @@ constructor(t, e, s) { | ||
return t.create = (e) => F(k(e)), t.extend = (e) => F(k(r, e)), t.stop = ht, t; | ||
}, Kt = F(), Zt = Kt, Qt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, et = Zt.create({ headers: Qt }), Xt = { | ||
get: (r, t) => et.get(r, t).json(), | ||
post: (r, t) => et.post(r, t).json() | ||
}, st = Object.values(i), te = (r = "") => { | ||
}, Kt = F(), Zt = Kt, Qt = typeof window < "u" ? {} : { | ||
Referrer: "https://sk.thorswap.net", | ||
Referer: "https://sk.thorswap.net" | ||
}, Xt = { | ||
headers: Qt, | ||
timeout: 3e4, | ||
// Example: 10000 milliseconds = 10 seconds | ||
retry: { | ||
limit: 2, | ||
// Maximum number of retry attempts | ||
methods: ["get", "post", "put", "patch", "head", "delete"], | ||
// HTTP methods to retry | ||
statusCodes: [408, 500, 502, 503, 504] | ||
// HTTP status codes to retry | ||
} | ||
}, et = Zt.create(Xt), te = { | ||
get: async (r, t) => et.get(r, t).json(), | ||
post: async (r, t) => et.post(r, t).json() | ||
// Implement other methods (put, delete, patch, head) as needed | ||
}, st = Object.values(i), ee = (r = "") => { | ||
const t = r.toUpperCase(), [e] = t.split("."); | ||
@@ -879,3 +895,3 @@ if (st.includes(e)) | ||
let E = Z; | ||
const ee = Intl.NumberFormat("fullwide", { | ||
const se = Intl.NumberFormat("fullwide", { | ||
useGrouping: !1, | ||
@@ -885,3 +901,3 @@ maximumFractionDigits: 20 | ||
function q(r) { | ||
const e = `${typeof r == "number" ? ee.format(r) : Y(r)}`.replaceAll(",", ".").split("."); | ||
const e = `${typeof r == "number" ? se.format(r) : Y(r)}`.replaceAll(",", ".").split("."); | ||
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0]; | ||
@@ -904,3 +920,3 @@ } | ||
}, it = async (r, t = 0) => { | ||
te(r); | ||
ee(r); | ||
const e = await Ct(J(r)), s = P(t, e); | ||
@@ -1008,3 +1024,3 @@ return new v({ decimal: e, value: s, identifier: r }); | ||
} | ||
const ge = (r) => { | ||
const be = (r) => { | ||
const t = v.fromChainOrSignature(r); | ||
@@ -1040,3 +1056,3 @@ switch (r) { | ||
}; | ||
}, se = { | ||
}, re = { | ||
/** | ||
@@ -1102,3 +1118,3 @@ * Core | ||
constructor(t, e) { | ||
console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: se[t], message: t } }), Object.setPrototypeOf(this, pt.prototype); | ||
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, pt.prototype); | ||
} | ||
@@ -1120,26 +1136,26 @@ } | ||
E as BigIntArithmetics, | ||
Xt as RequestClient, | ||
te as RequestClient, | ||
pt as SwapKitError, | ||
y as SwapKitNumber, | ||
ae as assetFromString, | ||
_e as derivationPathToString, | ||
oe as filterAssets, | ||
oe as assetFromString, | ||
ge as derivationPathToString, | ||
ce as filterAssets, | ||
j as formatBigIntToSafeValue, | ||
ie as gasFeeMultiplier, | ||
ae as gasFeeMultiplier, | ||
Ot as getAssetType, | ||
xt as getAsymmetricAssetShare, | ||
ue as getAsymmetricAssetWithdrawAmount, | ||
le as getAsymmetricAssetWithdrawAmount, | ||
Mt as getAsymmetricRuneShare, | ||
ce as getAsymmetricRuneWithdrawAmount, | ||
ue as getAsymmetricRuneWithdrawAmount, | ||
It as getCommonAssetInfo, | ||
Ct as getDecimal, | ||
he as getEstimatedPoolShare, | ||
de as getLiquiditySlippage, | ||
me as getMemoFor, | ||
ge as getMinAmountByChain, | ||
de as getEstimatedPoolShare, | ||
me as getLiquiditySlippage, | ||
pe as getMemoFor, | ||
be as getMinAmountByChain, | ||
kt as getSymmetricPoolShare, | ||
le as getSymmetricWithdraw, | ||
pe as getTHORNameCost, | ||
he as getSymmetricWithdraw, | ||
fe as getTHORNameCost, | ||
ot as isGasAsset, | ||
fe as validateTHORName | ||
_e as validateTHORName | ||
}; |
@@ -11,5 +11,5 @@ { | ||
"vitest": "0.34.6", | ||
"@coinmasters/tokens": "3.5.0", | ||
"@internal/config": "2.5.0", | ||
"@coinmasters/types": "4.5.0" | ||
"@coinmasters/types": "4.5.0", | ||
"@coinmasters/tokens": "3.5.1", | ||
"@internal/config": "2.5.0" | ||
}, | ||
@@ -20,4 +20,4 @@ "eslintConfig": { | ||
"peerDependencies": { | ||
"@coinmasters/types": "4.5.0", | ||
"@coinmasters/tokens": "3.5.0" | ||
"@coinmasters/tokens": "3.5.1", | ||
"@coinmasters/types": "4.5.0" | ||
}, | ||
@@ -47,3 +47,3 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"version": "9.0.0", | ||
"version": "9.0.1", | ||
"scripts": { | ||
@@ -50,0 +50,0 @@ "build": "vite build", |
@@ -1,3 +0,2 @@ | ||
import type { Options } from 'ky'; | ||
import ky from 'ky'; | ||
import ky, { type Options } from 'ky'; | ||
@@ -7,10 +6,29 @@ const headers = | ||
? {} | ||
: { referrer: 'https://sk.thorswap.net', referer: 'https://sk.thorswap.net' }; | ||
: { | ||
Referrer: 'https://sk.thorswap.net', | ||
Referer: 'https://sk.thorswap.net', | ||
}; | ||
const kyClient = ky.create({ headers }); | ||
// Define default options for the new ky instance | ||
const defaultOptions: Options = { | ||
headers: headers, | ||
timeout: 30000, // Example: 10000 milliseconds = 10 seconds | ||
retry: { | ||
limit: 2, // Maximum number of retry attempts | ||
methods: ['get', 'post', 'put', 'patch', 'head', 'delete'], // HTTP methods to retry | ||
statusCodes: [408, 500, 502, 503, 504], // HTTP status codes to retry | ||
}, | ||
}; | ||
// Create a new ky instance with the default options | ||
const kyInstance = ky.create(defaultOptions); | ||
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>(), | ||
get: async <T>(url: string | URL | Request, options?: Options): Promise<T> => { | ||
return kyInstance.get(url, options).json<T>(); | ||
}, | ||
post: async <T>(url: string | URL | Request, options?: Options): Promise<T> => { | ||
return kyInstance.post(url, options).json<T>(); | ||
}, | ||
// Implement other methods (put, delete, patch, head) as needed | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
207284
0.61%3874
0.86%