Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@swapkit/helpers

Package Overview
Dependencies
Maintainers
1
Versions
221
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.59 to 1.0.0-rc.60

2

dist/index.d.ts
import { Chain } from '@swapkit/types';
import { ChainId } from '@swapkit/types';
import type { CoinGeckoList } from '@swapkit/tokens';

@@ -54,2 +55,3 @@ import { FeeOption } from '@swapkit/types';

}): boolean;
chainId(): ChainId;
static fromUrl(urlAsset: string, value?: NumberPrimitives): Promise<AssetValue>;

@@ -56,0 +58,0 @@ static fromString(assetString: string, value?: NumberPrimitives): Promise<AssetValue>;

203

dist/index.es.js

@@ -7,3 +7,3 @@ var bt = Object.defineProperty;

};
var v = (s, t, e) => {
var $ = (s, t, e) => {
if (t.has(s))

@@ -14,6 +14,6 @@ throw TypeError("Cannot add the same private member more than once");

var m = (s, t, e) => (wt(s, t, "access private method"), e);
import { FeeOption as U, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as $t, MemoType as _ } from "@swapkit/types";
import { FeeOption as U, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as Tt, MemoType as _, ChainToChainId as $t } from "@swapkit/types";
const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => {
try {
const { result: e } = await Xt.post($t[s], {
const { result: e } = await Zt.post(Tt[s], {
headers: {

@@ -35,3 +35,3 @@ accept: "*/*",

}
}, Tt = async (s) => {
}, Ct = async (s) => {
if (s === o.Ethereum)

@@ -41,17 +41,17 @@ return d.ETH;

return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH;
}, Ct = async (s) => {
}, Rt = async (s) => {
const [, t] = s.split("-");
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX;
}, Rt = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, St = async ({ chain: s, symbol: t }) => {
}, St = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, It = async ({ chain: s, symbol: t }) => {
switch (s) {
case o.Ethereum:
return Tt(t);
return Ct(t);
case o.Avalanche:
return Ct(t);
return Rt(t);
case o.BinanceSmartChain:
return Rt(t);
return St(t);
default:
return d[s];
}
}, ne = {
}, ie = {
[U.Average]: 1.2,

@@ -86,3 +86,3 @@ [U.Fast]: 1.5,

}
}, It = (s) => {
}, Ot = (s) => {
switch (s) {

@@ -116,3 +116,3 @@ case "ETH.THOR":

}
}, Ot = ({ chain: s, symbol: t }) => {
}, Et = ({ chain: s, symbol: t }) => {
if (t.includes("/"))

@@ -147,10 +147,10 @@ return "Synth";

}
}, ie = (s) => {
}, 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 };
}, Et = new RegExp(
}, Bt = new RegExp(
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
"gmi"
), Bt = (s) => {
), Mt = (s) => {
const [t, e] = s.split(".");

@@ -161,7 +161,7 @@ if (!At.includes(t))

return it({ chain: t, symbol: e }) || !!r;
}, oe = (s) => s.filter((t) => {
}, ae = (s) => s.filter((t) => {
const e = `${t.chain}.${t.symbol}`;
return !Et.test(e) && Bt(e) && t.value !== "0";
return !Bt.test(e) && Mt(e) && t.value !== "0";
});
function Mt({
function xt({
liquidityUnits: s,

@@ -174,3 +174,3 @@ poolUnits: t,

}
function xt({
function qt({
liquidityUnits: s,

@@ -180,6 +180,6 @@ poolUnits: t,

}) {
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($);
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)), T = n.mul(n).mul(n);
return h.div(T);
}
function ae({
function ce({
percent: s,

@@ -190,5 +190,5 @@ runeDepth: t,

}) {
return Mt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
return xt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
}
function ce({
function ue({
percent: s,

@@ -199,3 +199,3 @@ assetDepth: t,

}) {
return xt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
return qt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s);
}

@@ -205,3 +205,3 @@ function p(s) {

}
function qt({
function Pt({
liquidityUnits: s,

@@ -217,3 +217,3 @@ poolUnits: t,

}
function ue({
function le({
liquidityUnits: s,

@@ -226,3 +226,3 @@ poolUnits: t,

return Object.fromEntries(
Object.entries(qt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
Object.entries(Pt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
([i, c]) => [i, c.mul(n)]

@@ -232,3 +232,3 @@ )

}
function le({
function he({
runeDepth: s,

@@ -241,3 +241,3 @@ poolUnits: t,

}) {
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), D = p(r).add(Q);
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 }), T = l.mul(a), H = h.mul(c), mt = l.mul(h), pt = c.mul(a), ft = u.mul(T.add(H.add(mt.mul(2)))), _t = T.add(H.add(pt.mul(2))), Q = ft.div(_t), D = p(r).add(Q);
if (Q.getBaseValue("number") === 0)

@@ -248,3 +248,3 @@ return D.div(u).getBaseValue("number");

}
function he({
function de({
runeAmount: s,

@@ -260,3 +260,3 @@ assetAmount: t,

}
const de = (s, t) => {
const me = (s, t) => {
switch (s) {

@@ -304,3 +304,3 @@ case _.LEAVE:

};
function me(s) {
function pe(s) {
if (s < 0)

@@ -310,3 +310,3 @@ throw new Error("Invalid number of year");

}
function pe(s) {
function fe(s) {
if (s.length > 30)

@@ -317,3 +317,3 @@ return !1;

}
function fe([s, t, e, r, n]) {
function _e([s, t, e, r, n]) {
return `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;

@@ -373,3 +373,3 @@ }

return t;
}, Pt = (() => {
}, Vt = (() => {
let s = !1, t = !1;

@@ -385,3 +385,3 @@ const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";

}).headers.has("Content-Type")), s && !t;
})(), Vt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function", jt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], Nt = {
})(), kt = typeof globalThis.AbortController == "function", jt = typeof globalThis.ReadableStream == "function", Nt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], Ht = {
json: "application/json",

@@ -392,3 +392,3 @@ text: "text/*",

blob: "*/*"
}, L = 2147483647, ut = Symbol("stop"), Ht = {
}, L = 2147483647, ut = Symbol("stop"), Dt = {
json: !0,

@@ -404,3 +404,3 @@ parseJson: !0,

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

@@ -421,6 +421,6 @@ headers: !0,

duplex: !0
}, Ut = (s) => ct.includes(s) ? s.toUpperCase() : s, Lt = ["get", "put", "head", "delete", "options", "trace"], Ft = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Z = {
}, 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 = {
limit: 2,
methods: Lt,
statusCodes: Ft,
methods: Ft,
statusCodes: Wt,
afterStatusCodes: lt,

@@ -430,3 +430,3 @@ maxRetryAfter: Number.POSITIVE_INFINITY,

delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
}, Wt = (s = {}) => {
}, Gt = (s = {}) => {
if (typeof s == "number")

@@ -447,3 +447,3 @@ return {

};
async function Gt(s, t, e, r) {
async function Yt(s, t, e, r) {
return new Promise((n, i) => {

@@ -458,3 +458,3 @@ const c = setTimeout(() => {

}
async function Yt(s, { signal: t }) {
async function zt(s, { signal: t }) {
return new Promise((e, r) => {

@@ -470,6 +470,6 @@ t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));

}
const zt = (s, t) => {
const Jt = (s, t) => {
const e = {};
for (const r in t)
!(r in Dt) && !(r in Ht) && !(r in s) && (e[r] = t[r]);
!(r in Ut) && !(r in Dt) && !(r in s) && (e[r] = t[r]);
return e;

@@ -497,3 +497,3 @@ };

throw new TypeError("The `onDownloadProgress` option must be a function");
if (!kt)
if (!jt)
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");

@@ -504,3 +504,3 @@ return r._stream(a.clone(), r._options.onDownloadProgress);

}, c = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
for (const [a, u] of Object.entries(Nt))
for (const [a, u] of Object.entries(Ht))
c[a] = async () => {

@@ -557,6 +557,6 @@ r.request.headers.set("accept", r.request.headers.get("accept") || u);

}, e.hooks),
method: Ut(e.method ?? this._input.method),
method: Lt(e.method ?? this._input.method),
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
prefixUrl: String(e.prefixUrl || ""),
retry: Wt(e.retry),
retry: Gt(e.retry),
throwHttpErrors: e.throwHttpErrors !== !1,

@@ -572,3 +572,3 @@ timeout: e.timeout ?? 1e4,

}
if (Vt) {
if (kt) {
if (this.abortController = new globalThis.AbortController(), this._options.signal) {

@@ -582,5 +582,5 @@ const r = this._options.signal;

}
if (Pt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
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);
(jt && 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);
(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);
}

@@ -616,3 +616,3 @@ 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 }));

if (r !== 0 && this._retryCount > 0) {
await Yt(r, { signal: this._options.signal });
await zt(r, { signal: this._options.signal });
for (const n of this._options.hooks.beforeRetry)

@@ -641,4 +641,4 @@ if (await n({

}
const t = zt(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 = Jt(this.request, this._options);
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Yt(this.request.clone(), t, this.abortController, this._options);
}

@@ -685,7 +685,7 @@ /* istanbul ignore next */

return t.create = (e) => W(M(e)), t.extend = (e) => W(M(s, e)), t.stop = ut, t;
}, Jt = W(), Kt = Jt, Qt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Kt.create({ headers: Qt }), Xt = {
}, Kt = W(), Qt = Kt, 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 Zt(s = "") {
function te(s = "") {
const t = s.toUpperCase(), [e] = t.split(".");

@@ -720,10 +720,10 @@ if (et.includes(e))

}
var w, R, b, T, N, ht, E, G, B, Y;
var w, R, b, v, N, ht, E, G, B, Y;
const K = class K {
constructor(t) {
v(this, w);
v(this, b);
v(this, N);
v(this, E);
v(this, B);
$(this, w);
$(this, b);
$(this, N);
$(this, E);
$(this, B);
f(this, "decimalMultiplier", 10n ** 8n);

@@ -767,15 +767,15 @@ f(this, "bigIntValue", 0n);

gt(t) {
return m(this, b, T).call(this, "gt", t);
return m(this, b, v).call(this, "gt", t);
}
gte(t) {
return m(this, b, T).call(this, "gte", t);
return m(this, b, v).call(this, "gte", t);
}
lt(t) {
return m(this, b, T).call(this, "lt", t);
return m(this, b, v).call(this, "lt", t);
}
lte(t) {
return m(this, b, T).call(this, "lte", t);
return m(this, b, v).call(this, "lte", t);
}
eqValue(t) {
return m(this, b, T).call(this, "eqValue", t);
return m(this, b, v).call(this, "eqValue", t);
}

@@ -903,3 +903,3 @@ // @ts-expect-error False positive

});
}, b = new WeakSet(), T = function(t, ...e) {
}, b = new WeakSet(), v = function(t, ...e) {
const r = m(this, E, G).call(this, this, ...e), n = this.getBigIntValue(e[0], r), i = this.getBigIntValue(this, r);

@@ -929,3 +929,3 @@ switch (t) {

let j = K;
const te = Intl.NumberFormat("fullwide", {
const ee = Intl.NumberFormat("fullwide", {
useGrouping: !1,

@@ -935,3 +935,3 @@ maximumFractionDigits: 20

function x(s) {
const e = `${typeof s == "number" ? te.format(s) : z(s)}`.replaceAll(",", ".").split(".");
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];

@@ -967,3 +967,3 @@ }

const u = P(a || `${i}.${c}`);
this.type = Ot(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;
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;
}

@@ -979,2 +979,5 @@ toString() {

}
chainId() {
return $t[this.chain];
}
// THOR.RUNE

@@ -1022,3 +1025,3 @@ // THOR.ETH.ETH

static fromChainOrSignature(e, r = 0) {
const { decimal: n, identifier: i } = It(e);
const { decimal: n, identifier: i } = Ot(e);
return new A({ value: I(r, n), decimal: n, identifier: i });

@@ -1051,3 +1054,3 @@ }

}
function _e(s) {
function ge(s) {
const t = A.fromChainOrSignature(s);

@@ -1074,4 +1077,4 @@ switch (s) {

async function F(s, t = 0) {
Zt(s);
const e = S.get(s.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await St(P(s));
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 });

@@ -1106,3 +1109,3 @@ }

}
const ee = {
const re = {
/**

@@ -1167,3 +1170,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: ee[t], message: t } }), Object.setPrototypeOf(this, dt.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, dt.prototype);
}

@@ -1185,27 +1188,27 @@ }

j as BigIntArithmetics,
Xt as RequestClient,
Zt as RequestClient,
dt as SwapKitError,
g as SwapKitNumber,
ie as assetFromString,
fe as derivationPathToString,
oe as filterAssets,
oe as assetFromString,
_e as derivationPathToString,
ae as filterAssets,
k as formatBigIntToSafeValue,
ne as gasFeeMultiplier,
Ot as getAssetType,
xt as getAsymmetricAssetShare,
ce as getAsymmetricAssetWithdrawAmount,
Mt as getAsymmetricRuneShare,
ae as getAsymmetricRuneWithdrawAmount,
It as getCommonAssetInfo,
St as getDecimal,
le as getEstimatedPoolShare,
he as getLiquiditySlippage,
de as getMemoFor,
_e as getMinAmountByChain,
qt as getSymmetricPoolShare,
ue as getSymmetricWithdraw,
me as getTHORNameCost,
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,
pe as validateTHORName
fe as validateTHORName
};
//# sourceMappingURL=index.es.js.map

@@ -38,10 +38,10 @@ {

"name": "@swapkit/helpers",
"publishConfig": {
"access": "public"
"react-native": "./src/index.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/thorswap/SwapKit.git"
},
"react-native": "./src/index.ts",
"repository": "https://github.com/thorswap/SwapKit.git",
"type": "module",
"types": "./dist/index.d.ts",
"version": "1.0.0-rc.59",
"version": "1.0.0-rc.60",
"scripts": {

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

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

import { BaseDecimal, Chain } from '@swapkit/types';
import { BaseDecimal, Chain, ChainToChainId } from '@swapkit/types';

@@ -64,2 +64,6 @@ import type { CommonAssetString } from '../helpers/asset.ts';

chainId() {
return ChainToChainId[this.chain];
}
// THOR.RUNE

@@ -66,0 +70,0 @@ // THOR.ETH.ETH

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