@swapkit/helpers 1.0.0-rc.79 → 1.0.0-rc.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.es.js +488 -906
- package/dist/index.es.js.map +1 -1
- package/package.json +9 -8
- package/src/helpers/__tests__/others.test.ts +2 -2
- package/src/helpers/others.ts +7 -1
package/dist/index.es.js
CHANGED
|
@@ -1,431 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
if (!t.has(
|
|
5
|
-
throw TypeError("Cannot " +
|
|
1
|
+
var it = Object.defineProperty;
|
|
2
|
+
var st = (n, t, e) => t in n ? it(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var f = (n, t, e) => (st(n, typeof t != "symbol" ? t + "" : t, e), e), at = (n, t, e) => {
|
|
4
|
+
if (!t.has(n))
|
|
5
|
+
throw TypeError("Cannot " + e);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
8
|
-
if (t.has(
|
|
7
|
+
var v = (n, t, e) => {
|
|
8
|
+
if (t.has(n))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
-
t instanceof WeakSet ? t.add(
|
|
10
|
+
t instanceof WeakSet ? t.add(n) : t.set(n, e);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const n = Ve.find((r) => F[r] === t);
|
|
18
|
-
return n && (e[t] = n), e;
|
|
19
|
-
},
|
|
20
|
-
{}
|
|
21
|
-
);
|
|
22
|
-
G.reduce(
|
|
23
|
-
(e, t) => (e[t] = ne[re[t]], e),
|
|
24
|
-
{}
|
|
25
|
-
);
|
|
26
|
-
G.reduce(
|
|
27
|
-
(e, t) => (e[t] = de[re[t]], e),
|
|
28
|
-
{}
|
|
29
|
-
);
|
|
30
|
-
G.reduce(
|
|
31
|
-
(e, t) => {
|
|
32
|
-
const n = `${re[t]}Hex`;
|
|
33
|
-
return e[t] = ne[n], e;
|
|
34
|
-
},
|
|
35
|
-
{}
|
|
36
|
-
);
|
|
37
|
-
class ae extends Error {
|
|
38
|
-
constructor(t, n, r) {
|
|
39
|
-
const s = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", o = `${s} ${i}`.trim(), c = o ? `status code ${o}` : "an unknown error";
|
|
40
|
-
super(`Request failed with ${c}`), Object.defineProperty(this, "response", {
|
|
41
|
-
enumerable: !0,
|
|
42
|
-
configurable: !0,
|
|
43
|
-
writable: !0,
|
|
44
|
-
value: void 0
|
|
45
|
-
}), Object.defineProperty(this, "request", {
|
|
46
|
-
enumerable: !0,
|
|
47
|
-
configurable: !0,
|
|
48
|
-
writable: !0,
|
|
49
|
-
value: void 0
|
|
50
|
-
}), Object.defineProperty(this, "options", {
|
|
51
|
-
enumerable: !0,
|
|
52
|
-
configurable: !0,
|
|
53
|
-
writable: !0,
|
|
54
|
-
value: void 0
|
|
55
|
-
}), this.name = "HTTPError", this.response = t, this.request = n, this.options = r;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
class pe extends Error {
|
|
59
|
-
constructor(t) {
|
|
60
|
-
super("Request timed out"), Object.defineProperty(this, "request", {
|
|
61
|
-
enumerable: !0,
|
|
62
|
-
configurable: !0,
|
|
63
|
-
writable: !0,
|
|
64
|
-
value: void 0
|
|
65
|
-
}), this.name = "TimeoutError", this.request = t;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const M = (e) => e !== null && typeof e == "object", x = (...e) => {
|
|
69
|
-
for (const t of e)
|
|
70
|
-
if ((!M(t) || Array.isArray(t)) && t !== void 0)
|
|
71
|
-
throw new TypeError("The `options` argument must be an object");
|
|
72
|
-
return se({}, ...e);
|
|
73
|
-
}, me = (e = {}, t = {}) => {
|
|
74
|
-
const n = new globalThis.Headers(e), r = t instanceof globalThis.Headers, s = new globalThis.Headers(t);
|
|
75
|
-
for (const [i, o] of s.entries())
|
|
76
|
-
r && o === "undefined" || o === void 0 ? n.delete(i) : n.set(i, o);
|
|
77
|
-
return n;
|
|
78
|
-
}, se = (...e) => {
|
|
79
|
-
let t = {}, n = {};
|
|
80
|
-
for (const r of e)
|
|
81
|
-
if (Array.isArray(r))
|
|
82
|
-
Array.isArray(t) || (t = []), t = [...t, ...r];
|
|
83
|
-
else if (M(r)) {
|
|
84
|
-
for (let [s, i] of Object.entries(r))
|
|
85
|
-
M(i) && s in t && (i = se(t[s], i)), t = { ...t, [s]: i };
|
|
86
|
-
M(r.headers) && (n = me(n, r.headers), t.headers = n);
|
|
87
|
-
}
|
|
88
|
-
return t;
|
|
89
|
-
}, He = (() => {
|
|
90
|
-
let e = !1, t = !1;
|
|
91
|
-
const n = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
|
|
92
|
-
return n && r && (t = new globalThis.Request("https://empty.invalid", {
|
|
93
|
-
body: new globalThis.ReadableStream(),
|
|
94
|
-
method: "POST",
|
|
95
|
-
// @ts-expect-error - Types are outdated.
|
|
96
|
-
get duplex() {
|
|
97
|
-
return e = !0, "half";
|
|
98
|
-
}
|
|
99
|
-
}).headers.has("Content-Type")), e && !t;
|
|
100
|
-
})(), xe = typeof globalThis.AbortController == "function", ke = typeof globalThis.ReadableStream == "function", Me = typeof globalThis.FormData == "function", _e = ["get", "post", "put", "patch", "head", "delete"], Le = {
|
|
101
|
-
json: "application/json",
|
|
102
|
-
text: "text/*",
|
|
103
|
-
formData: "multipart/form-data",
|
|
104
|
-
arrayBuffer: "*/*",
|
|
105
|
-
blob: "*/*"
|
|
106
|
-
}, Y = 2147483647, fe = Symbol("stop"), We = {
|
|
107
|
-
json: !0,
|
|
108
|
-
parseJson: !0,
|
|
109
|
-
searchParams: !0,
|
|
110
|
-
prefixUrl: !0,
|
|
111
|
-
retry: !0,
|
|
112
|
-
timeout: !0,
|
|
113
|
-
hooks: !0,
|
|
114
|
-
throwHttpErrors: !0,
|
|
115
|
-
onDownloadProgress: !0,
|
|
116
|
-
fetch: !0
|
|
117
|
-
}, Ue = {
|
|
118
|
-
method: !0,
|
|
119
|
-
headers: !0,
|
|
120
|
-
body: !0,
|
|
121
|
-
mode: !0,
|
|
122
|
-
credentials: !0,
|
|
123
|
-
cache: !0,
|
|
124
|
-
redirect: !0,
|
|
125
|
-
referrer: !0,
|
|
126
|
-
referrerPolicy: !0,
|
|
127
|
-
integrity: !0,
|
|
128
|
-
keepalive: !0,
|
|
129
|
-
signal: !0,
|
|
130
|
-
window: !0,
|
|
131
|
-
dispatcher: !0,
|
|
132
|
-
duplex: !0
|
|
133
|
-
}, je = (e) => _e.includes(e) ? e.toUpperCase() : e, qe = ["get", "put", "head", "delete", "options", "trace"], Fe = [408, 413, 429, 500, 502, 503, 504], Te = [413, 429, 503], ce = {
|
|
134
|
-
limit: 2,
|
|
135
|
-
methods: qe,
|
|
136
|
-
statusCodes: Fe,
|
|
137
|
-
afterStatusCodes: Te,
|
|
138
|
-
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
139
|
-
backoffLimit: Number.POSITIVE_INFINITY,
|
|
140
|
-
delay: (e) => 0.3 * 2 ** (e - 1) * 1e3
|
|
141
|
-
}, Ge = (e = {}) => {
|
|
142
|
-
if (typeof e == "number")
|
|
143
|
-
return {
|
|
144
|
-
...ce,
|
|
145
|
-
limit: e
|
|
146
|
-
};
|
|
147
|
-
if (e.methods && !Array.isArray(e.methods))
|
|
148
|
-
throw new Error("retry.methods must be an array");
|
|
149
|
-
if (e.statusCodes && !Array.isArray(e.statusCodes))
|
|
150
|
-
throw new Error("retry.statusCodes must be an array");
|
|
151
|
-
return {
|
|
152
|
-
...ce,
|
|
153
|
-
...e,
|
|
154
|
-
afterStatusCodes: Te
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
async function Xe(e, t, n, r) {
|
|
158
|
-
return new Promise((s, i) => {
|
|
159
|
-
const o = setTimeout(() => {
|
|
160
|
-
n && n.abort(), i(new pe(e));
|
|
161
|
-
}, r.timeout);
|
|
162
|
-
r.fetch(e, t).then(s).catch(i).then(() => {
|
|
163
|
-
clearTimeout(o);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
async function Ke(e, { signal: t }) {
|
|
168
|
-
return new Promise((n, r) => {
|
|
169
|
-
t && (t.throwIfAborted(), t.addEventListener("abort", s, { once: !0 }));
|
|
170
|
-
function s() {
|
|
171
|
-
clearTimeout(i), r(t.reason);
|
|
172
|
-
}
|
|
173
|
-
const i = setTimeout(() => {
|
|
174
|
-
t == null || t.removeEventListener("abort", s), n();
|
|
175
|
-
}, e);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
const Ye = (e, t) => {
|
|
179
|
-
const n = {};
|
|
180
|
-
for (const r in t)
|
|
181
|
-
!(r in Ue) && !(r in We) && !(r in e) && (n[r] = t[r]);
|
|
182
|
-
return n;
|
|
183
|
-
};
|
|
184
|
-
class W {
|
|
185
|
-
static create(t, n) {
|
|
186
|
-
const r = new W(t, n), s = async () => {
|
|
187
|
-
if (typeof r._options.timeout == "number" && r._options.timeout > Y)
|
|
188
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${Y}`);
|
|
189
|
-
await Promise.resolve();
|
|
190
|
-
let o = await r._fetch();
|
|
191
|
-
for (const c of r._options.hooks.afterResponse) {
|
|
192
|
-
const a = await c(r.request, r._options, r._decorateResponse(o.clone()));
|
|
193
|
-
a instanceof globalThis.Response && (o = a);
|
|
194
|
-
}
|
|
195
|
-
if (r._decorateResponse(o), !o.ok && r._options.throwHttpErrors) {
|
|
196
|
-
let c = new ae(o, r.request, r._options);
|
|
197
|
-
for (const a of r._options.hooks.beforeError)
|
|
198
|
-
c = await a(c);
|
|
199
|
-
throw c;
|
|
200
|
-
}
|
|
201
|
-
if (r._options.onDownloadProgress) {
|
|
202
|
-
if (typeof r._options.onDownloadProgress != "function")
|
|
203
|
-
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
204
|
-
if (!ke)
|
|
205
|
-
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
206
|
-
return r._stream(o.clone(), r._options.onDownloadProgress);
|
|
207
|
-
}
|
|
208
|
-
return o;
|
|
209
|
-
}, i = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(s) : s();
|
|
210
|
-
for (const [o, c] of Object.entries(Le))
|
|
211
|
-
i[o] = async () => {
|
|
212
|
-
r.request.headers.set("accept", r.request.headers.get("accept") || c);
|
|
213
|
-
const a = (await i).clone();
|
|
214
|
-
if (o === "json") {
|
|
215
|
-
if (a.status === 204 || (await a.clone().arrayBuffer()).byteLength === 0)
|
|
216
|
-
return "";
|
|
217
|
-
if (n.parseJson)
|
|
218
|
-
return n.parseJson(await a.text());
|
|
219
|
-
}
|
|
220
|
-
return a[o]();
|
|
221
|
-
};
|
|
222
|
-
return i;
|
|
223
|
-
}
|
|
224
|
-
// eslint-disable-next-line complexity
|
|
225
|
-
constructor(t, n = {}) {
|
|
226
|
-
Object.defineProperty(this, "request", {
|
|
227
|
-
enumerable: !0,
|
|
228
|
-
configurable: !0,
|
|
229
|
-
writable: !0,
|
|
230
|
-
value: void 0
|
|
231
|
-
}), Object.defineProperty(this, "abortController", {
|
|
232
|
-
enumerable: !0,
|
|
233
|
-
configurable: !0,
|
|
234
|
-
writable: !0,
|
|
235
|
-
value: void 0
|
|
236
|
-
}), Object.defineProperty(this, "_retryCount", {
|
|
237
|
-
enumerable: !0,
|
|
238
|
-
configurable: !0,
|
|
239
|
-
writable: !0,
|
|
240
|
-
value: 0
|
|
241
|
-
}), Object.defineProperty(this, "_input", {
|
|
242
|
-
enumerable: !0,
|
|
243
|
-
configurable: !0,
|
|
244
|
-
writable: !0,
|
|
245
|
-
value: void 0
|
|
246
|
-
}), Object.defineProperty(this, "_options", {
|
|
247
|
-
enumerable: !0,
|
|
248
|
-
configurable: !0,
|
|
249
|
-
writable: !0,
|
|
250
|
-
value: void 0
|
|
251
|
-
}), this._input = t;
|
|
252
|
-
const r = "credentials" in Request.prototype;
|
|
253
|
-
if (this._options = {
|
|
254
|
-
credentials: r ? this._input.credentials : void 0,
|
|
255
|
-
...n,
|
|
256
|
-
headers: me(this._input.headers, n.headers),
|
|
257
|
-
hooks: se({
|
|
258
|
-
beforeRequest: [],
|
|
259
|
-
beforeRetry: [],
|
|
260
|
-
beforeError: [],
|
|
261
|
-
afterResponse: []
|
|
262
|
-
}, n.hooks),
|
|
263
|
-
method: je(n.method ?? this._input.method),
|
|
264
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
265
|
-
prefixUrl: String(n.prefixUrl || ""),
|
|
266
|
-
retry: Ge(n.retry),
|
|
267
|
-
throwHttpErrors: n.throwHttpErrors !== !1,
|
|
268
|
-
timeout: n.timeout ?? 1e4,
|
|
269
|
-
fetch: n.fetch ?? globalThis.fetch.bind(globalThis)
|
|
270
|
-
}, typeof this._input != "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request))
|
|
271
|
-
throw new TypeError("`input` must be a string, URL, or Request");
|
|
272
|
-
if (this._options.prefixUrl && typeof this._input == "string") {
|
|
273
|
-
if (this._input.startsWith("/"))
|
|
274
|
-
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
275
|
-
this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
|
|
276
|
-
}
|
|
277
|
-
if (xe) {
|
|
278
|
-
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
279
|
-
const s = this._options.signal;
|
|
280
|
-
this._options.signal.addEventListener("abort", () => {
|
|
281
|
-
this.abortController.abort(s.reason);
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
this._options.signal = this.abortController.signal;
|
|
285
|
-
}
|
|
286
|
-
if (He && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
287
|
-
const s = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, s);
|
|
288
|
-
(Me && 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);
|
|
289
|
-
}
|
|
290
|
-
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 }));
|
|
291
|
-
}
|
|
292
|
-
_calculateRetryDelay(t) {
|
|
293
|
-
if (this._retryCount++, this._retryCount <= this._options.retry.limit && !(t instanceof pe)) {
|
|
294
|
-
if (t instanceof ae) {
|
|
295
|
-
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
296
|
-
return 0;
|
|
297
|
-
const r = t.response.headers.get("Retry-After");
|
|
298
|
-
if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) {
|
|
299
|
-
let s = Number(r);
|
|
300
|
-
return Number.isNaN(s) ? s = Date.parse(r) - Date.now() : s *= 1e3, this._options.retry.maxRetryAfter !== void 0 && s > this._options.retry.maxRetryAfter ? 0 : s;
|
|
301
|
-
}
|
|
302
|
-
if (t.response.status === 413)
|
|
303
|
-
return 0;
|
|
304
|
-
}
|
|
305
|
-
const n = this._options.retry.delay(this._retryCount);
|
|
306
|
-
return Math.min(this._options.retry.backoffLimit, n);
|
|
307
|
-
}
|
|
308
|
-
return 0;
|
|
309
|
-
}
|
|
310
|
-
_decorateResponse(t) {
|
|
311
|
-
return this._options.parseJson && (t.json = async () => this._options.parseJson(await t.text())), t;
|
|
312
|
-
}
|
|
313
|
-
async _retry(t) {
|
|
314
|
-
try {
|
|
315
|
-
return await t();
|
|
316
|
-
} catch (n) {
|
|
317
|
-
const r = Math.min(this._calculateRetryDelay(n), Y);
|
|
318
|
-
if (r !== 0 && this._retryCount > 0) {
|
|
319
|
-
await Ke(r, { signal: this._options.signal });
|
|
320
|
-
for (const s of this._options.hooks.beforeRetry)
|
|
321
|
-
if (await s({
|
|
322
|
-
request: this.request,
|
|
323
|
-
options: this._options,
|
|
324
|
-
error: n,
|
|
325
|
-
retryCount: this._retryCount
|
|
326
|
-
}) === fe)
|
|
327
|
-
return;
|
|
328
|
-
return this._retry(t);
|
|
329
|
-
}
|
|
330
|
-
throw n;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
async _fetch() {
|
|
334
|
-
for (const n of this._options.hooks.beforeRequest) {
|
|
335
|
-
const r = await n(this.request, this._options);
|
|
336
|
-
if (r instanceof Request) {
|
|
337
|
-
this.request = r;
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
if (r instanceof Response)
|
|
341
|
-
return r;
|
|
342
|
-
}
|
|
343
|
-
const t = Ye(this.request, this._options);
|
|
344
|
-
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Xe(this.request.clone(), t, this.abortController, this._options);
|
|
345
|
-
}
|
|
346
|
-
/* istanbul ignore next */
|
|
347
|
-
_stream(t, n) {
|
|
348
|
-
const r = Number(t.headers.get("content-length")) || 0;
|
|
349
|
-
let s = 0;
|
|
350
|
-
return t.status === 204 ? (n && n({ percent: 1, totalBytes: r, transferredBytes: s }, new Uint8Array()), new globalThis.Response(null, {
|
|
351
|
-
status: t.status,
|
|
352
|
-
statusText: t.statusText,
|
|
353
|
-
headers: t.headers
|
|
354
|
-
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
355
|
-
async start(i) {
|
|
356
|
-
const o = t.body.getReader();
|
|
357
|
-
n && n({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
|
|
358
|
-
async function c() {
|
|
359
|
-
const { done: a, value: l } = await o.read();
|
|
360
|
-
if (a) {
|
|
361
|
-
i.close();
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
if (n) {
|
|
365
|
-
s += l.byteLength;
|
|
366
|
-
const h = r === 0 ? 0 : s / r;
|
|
367
|
-
n({ percent: h, transferredBytes: s, totalBytes: r }, l);
|
|
368
|
-
}
|
|
369
|
-
i.enqueue(l), await c();
|
|
370
|
-
}
|
|
371
|
-
await c();
|
|
372
|
-
}
|
|
373
|
-
}), {
|
|
374
|
-
status: t.status,
|
|
375
|
-
statusText: t.statusText,
|
|
376
|
-
headers: t.headers
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
/*! MIT License © Sindre Sorhus */
|
|
381
|
-
const z = (e) => {
|
|
382
|
-
const t = (n, r) => W.create(n, x(e, r));
|
|
383
|
-
for (const n of _e)
|
|
384
|
-
t[n] = (r, s) => W.create(r, x(e, s, { method: n }));
|
|
385
|
-
return t.create = (n) => z(x(n)), t.extend = (n) => z(x(e, n)), t.stop = fe, t;
|
|
386
|
-
}, ge = z();
|
|
387
|
-
let L;
|
|
388
|
-
const T = {
|
|
389
|
-
CachedPrices: `${S.ThorswapApi}/tokenlist/cached-price`,
|
|
390
|
-
GasRates: `${S.ThorswapApi}/resource-worker/gasPrice/getAll`,
|
|
391
|
-
Quote: `${S.ThorswapApi}/aggregator/tokens/quote`,
|
|
392
|
-
Txn: `${S.ThorswapApi}/apiusage/v2/txn`,
|
|
393
|
-
TokenlistProviders: `${S.ThorswapApi}/tokenlist/providers`,
|
|
394
|
-
TokenList: `${S.ThorswapStatic}/token-list`,
|
|
395
|
-
Thorname: `${S.ThorswapApi}/thorname`
|
|
396
|
-
}, Ae = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, ue = () => L || (L = ge.create({ headers: Ae }), L), Tt = ({ apiKey: e, ...t }) => {
|
|
397
|
-
L = ge.create({
|
|
398
|
-
...t,
|
|
399
|
-
headers: { ...Ae, ...t.headers, "x-api-key": e }
|
|
400
|
-
});
|
|
401
|
-
}, f = {
|
|
402
|
-
get: (e, t) => ue().get(e, t).json(),
|
|
403
|
-
post: (e, t) => ue().post(e, t).json()
|
|
404
|
-
}, Je = ({ tokens: e, ...t }) => {
|
|
405
|
-
const n = new URLSearchParams(), r = e.filter(
|
|
406
|
-
(s, i, o) => o.findIndex((c) => c === s) === i
|
|
407
|
-
);
|
|
408
|
-
for (const s of r)
|
|
409
|
-
n.append("tokens", JSON.stringify(s));
|
|
410
|
-
return t.metadata && n.append("metadata", "true"), t.lookup && n.append("lookup", "true"), t.sparkline && n.append("sparkline", "true"), f.post(T.CachedPrices, {
|
|
411
|
-
body: n.toString(),
|
|
412
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" }
|
|
413
|
-
});
|
|
414
|
-
}, gt = {
|
|
415
|
-
getCachedPrices: Je,
|
|
416
|
-
getQuote: (e) => f.get(T.Quote, { searchParams: e }),
|
|
417
|
-
getGasRates: () => f.get(T.GasRates),
|
|
418
|
-
getTxnDetails: (e) => f.get(T.Txn, { searchParams: e }),
|
|
419
|
-
getTokenlistProviders: () => f.get(T.TokenlistProviders),
|
|
420
|
-
getTokenList: (e) => f.get(`${T.TokenList}/${e}.json`),
|
|
421
|
-
getThornameAddresses: (e) => f.get(`${T.Thorname}/${e}`),
|
|
422
|
-
getThornameRegisteredChains: (e) => f.get(`${T.Thorname}/chains/${e}`),
|
|
423
|
-
getThornameRlookup: (e, t) => f.get(`${T.Thorname}/rlookup`, { searchParams: { address: e, chain: t } })
|
|
424
|
-
};
|
|
425
|
-
var Qe = /* @__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))(Qe || {}), 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 || {}), Ze = /* @__PURE__ */ ((e) => (e[e.NOT_STARTED = 0] = "NOT_STARTED", e[e.SUCCESS = 1] = "SUCCESS", e[e.REFUNDED = 2] = "REFUNDED", e))(Ze || {});
|
|
426
|
-
const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
12
|
+
var h = (n, t, e) => (at(n, t, "access private method"), e);
|
|
13
|
+
import { RequestClient as ct } from "@swapkit/api";
|
|
14
|
+
export * from "@swapkit/api";
|
|
15
|
+
import { FeeOption as P, BaseDecimal as m, Chain as a, EVMChains as ot, ChainToRPC as lt, MemoType as $, ChainToChainId as ut } from "@swapkit/types";
|
|
16
|
+
const dt = "0x313ce567", z = async ({ chain: n, to: t }) => {
|
|
427
17
|
try {
|
|
428
|
-
const { result:
|
|
18
|
+
const { result: e } = await ct.post(lt[n], {
|
|
429
19
|
headers: {
|
|
430
20
|
accept: "*/*",
|
|
431
21
|
"content-type": "application/json",
|
|
@@ -435,336 +25,336 @@ const et = "0x313ce567", Ce = async ({ chain: e, to: t }) => {
|
|
|
435
25
|
id: 44,
|
|
436
26
|
jsonrpc: "2.0",
|
|
437
27
|
method: "eth_call",
|
|
438
|
-
params: [{ to: t.toLowerCase(), data:
|
|
28
|
+
params: [{ to: t.toLowerCase(), data: dt }, "latest"]
|
|
439
29
|
})
|
|
440
30
|
});
|
|
441
|
-
return Number.parseInt(BigInt(
|
|
442
|
-
} catch (
|
|
443
|
-
return console.error(
|
|
444
|
-
}
|
|
445
|
-
},
|
|
446
|
-
if (
|
|
447
|
-
return
|
|
448
|
-
const [, t] =
|
|
449
|
-
return t != null && t.startsWith("0x") ?
|
|
450
|
-
},
|
|
451
|
-
const [, t] =
|
|
452
|
-
return t != null && t.startsWith("0x") ?
|
|
453
|
-
},
|
|
454
|
-
switch (
|
|
455
|
-
case
|
|
456
|
-
return
|
|
457
|
-
case
|
|
458
|
-
return
|
|
459
|
-
case
|
|
460
|
-
return
|
|
31
|
+
return Number.parseInt(BigInt(e).toString());
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return console.error(e), m[n];
|
|
34
|
+
}
|
|
35
|
+
}, mt = (n) => {
|
|
36
|
+
if (n === a.Ethereum)
|
|
37
|
+
return m.ETH;
|
|
38
|
+
const [, t] = n.split("-");
|
|
39
|
+
return t != null && t.startsWith("0x") ? z({ chain: a.Ethereum, to: t }) : m.ETH;
|
|
40
|
+
}, ht = (n) => {
|
|
41
|
+
const [, t] = n.split("-");
|
|
42
|
+
return t != null && t.startsWith("0x") ? z({ chain: a.Avalanche, to: t.toLowerCase() }) : m.AVAX;
|
|
43
|
+
}, _t = (n) => n === a.BinanceSmartChain ? m.BSC : m.BSC, ft = ({ chain: n, symbol: t }) => {
|
|
44
|
+
switch (n) {
|
|
45
|
+
case a.Ethereum:
|
|
46
|
+
return mt(t);
|
|
47
|
+
case a.Avalanche:
|
|
48
|
+
return ht(t);
|
|
49
|
+
case a.BinanceSmartChain:
|
|
50
|
+
return _t(t);
|
|
461
51
|
default:
|
|
462
|
-
return
|
|
463
|
-
}
|
|
464
|
-
},
|
|
465
|
-
[
|
|
466
|
-
[
|
|
467
|
-
[
|
|
468
|
-
},
|
|
469
|
-
switch (
|
|
470
|
-
case
|
|
471
|
-
case
|
|
52
|
+
return m[n];
|
|
53
|
+
}
|
|
54
|
+
}, Ot = {
|
|
55
|
+
[P.Average]: 1.2,
|
|
56
|
+
[P.Fast]: 1.5,
|
|
57
|
+
[P.Fastest]: 2
|
|
58
|
+
}, J = ({ chain: n, symbol: t }) => {
|
|
59
|
+
switch (n) {
|
|
60
|
+
case a.Arbitrum:
|
|
61
|
+
case a.Optimism:
|
|
472
62
|
return t === "ETH";
|
|
473
|
-
case
|
|
63
|
+
case a.Maya:
|
|
474
64
|
return t === "CACAO";
|
|
475
|
-
case
|
|
65
|
+
case a.Kujira:
|
|
476
66
|
return t === "KUJI";
|
|
477
|
-
case
|
|
67
|
+
case a.Cosmos:
|
|
478
68
|
return t === "ATOM";
|
|
479
|
-
case
|
|
69
|
+
case a.Polygon:
|
|
480
70
|
return t === "MATIC";
|
|
481
|
-
case
|
|
71
|
+
case a.BinanceSmartChain:
|
|
482
72
|
return t === "BNB";
|
|
483
|
-
case
|
|
73
|
+
case a.THORChain:
|
|
484
74
|
return t === "RUNE";
|
|
485
75
|
default:
|
|
486
|
-
return t ===
|
|
76
|
+
return t === n;
|
|
487
77
|
}
|
|
488
|
-
},
|
|
489
|
-
switch (
|
|
490
|
-
case `${
|
|
78
|
+
}, gt = (n) => {
|
|
79
|
+
switch (n) {
|
|
80
|
+
case `${a.Ethereum}.THOR`:
|
|
491
81
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
492
|
-
case `${
|
|
82
|
+
case `${a.Ethereum}.vTHOR`:
|
|
493
83
|
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
494
|
-
case
|
|
495
|
-
return { identifier: "GAIA.ATOM", decimal:
|
|
496
|
-
case
|
|
497
|
-
return { identifier: "THOR.RUNE", decimal:
|
|
498
|
-
case
|
|
499
|
-
return { identifier: "BSC.BNB", decimal:
|
|
500
|
-
case
|
|
501
|
-
return { identifier: "MAYA.CACAO", decimal:
|
|
502
|
-
case `${
|
|
84
|
+
case a.Cosmos:
|
|
85
|
+
return { identifier: "GAIA.ATOM", decimal: m[n] };
|
|
86
|
+
case a.THORChain:
|
|
87
|
+
return { identifier: "THOR.RUNE", decimal: m[n] };
|
|
88
|
+
case a.BinanceSmartChain:
|
|
89
|
+
return { identifier: "BSC.BNB", decimal: m[n] };
|
|
90
|
+
case a.Maya:
|
|
91
|
+
return { identifier: "MAYA.CACAO", decimal: m.MAYA };
|
|
92
|
+
case `${a.Maya}.MAYA`:
|
|
503
93
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
504
|
-
case `${
|
|
505
|
-
return { identifier: `${
|
|
94
|
+
case `${a.Kujira}.USK`:
|
|
95
|
+
return { identifier: `${a.Kujira}.USK`, decimal: 6 };
|
|
506
96
|
default:
|
|
507
|
-
return { identifier: `${
|
|
97
|
+
return { identifier: `${n}.${n}`, decimal: m[n] };
|
|
508
98
|
}
|
|
509
|
-
},
|
|
99
|
+
}, pt = ({ chain: n, symbol: t }) => {
|
|
510
100
|
if (t.includes("/"))
|
|
511
101
|
return "Synth";
|
|
512
|
-
switch (
|
|
513
|
-
case
|
|
514
|
-
return t === "ATOM" ? "Native" :
|
|
515
|
-
case
|
|
516
|
-
return t ===
|
|
517
|
-
case
|
|
518
|
-
return t ===
|
|
519
|
-
case
|
|
520
|
-
return t ===
|
|
521
|
-
case
|
|
522
|
-
return t ===
|
|
523
|
-
case
|
|
524
|
-
return t ===
|
|
525
|
-
case
|
|
526
|
-
return t ===
|
|
527
|
-
case
|
|
528
|
-
return [
|
|
529
|
-
case
|
|
530
|
-
return [
|
|
102
|
+
switch (n) {
|
|
103
|
+
case a.Cosmos:
|
|
104
|
+
return t === "ATOM" ? "Native" : a.Cosmos;
|
|
105
|
+
case a.Kujira:
|
|
106
|
+
return t === a.Kujira ? "Native" : a.Kujira;
|
|
107
|
+
case a.Binance:
|
|
108
|
+
return t === a.Binance ? "Native" : "BEP2";
|
|
109
|
+
case a.BinanceSmartChain:
|
|
110
|
+
return t === a.Binance ? "Native" : "BEP20";
|
|
111
|
+
case a.Ethereum:
|
|
112
|
+
return t === a.Ethereum ? "Native" : "ERC20";
|
|
113
|
+
case a.Avalanche:
|
|
114
|
+
return t === a.Avalanche ? "Native" : a.Avalanche;
|
|
115
|
+
case a.Polygon:
|
|
116
|
+
return t === a.Polygon ? "Native" : "POLYGON";
|
|
117
|
+
case a.Arbitrum:
|
|
118
|
+
return [a.Ethereum, a.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
119
|
+
case a.Optimism:
|
|
120
|
+
return [a.Ethereum, a.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
531
121
|
default:
|
|
532
122
|
return "Native";
|
|
533
123
|
}
|
|
534
|
-
},
|
|
535
|
-
var
|
|
536
|
-
const [t, ...
|
|
537
|
-
return { chain: t, symbol:
|
|
538
|
-
},
|
|
124
|
+
}, Tt = (n) => {
|
|
125
|
+
var l;
|
|
126
|
+
const [t, ...e] = n.split("."), r = n.includes("/"), i = e.join("."), s = (l = i == null ? void 0 : i.split("-")) == null ? void 0 : l[0];
|
|
127
|
+
return { chain: t, symbol: i, ticker: s, synth: r };
|
|
128
|
+
}, $t = new RegExp(
|
|
539
129
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
540
130
|
"gmi"
|
|
541
|
-
),
|
|
542
|
-
const [t,
|
|
543
|
-
if (!
|
|
131
|
+
), At = (n) => {
|
|
132
|
+
const [t, e] = n.split(".");
|
|
133
|
+
if (!ot.includes(t))
|
|
544
134
|
return !0;
|
|
545
|
-
const [, r] =
|
|
546
|
-
return
|
|
547
|
-
},
|
|
548
|
-
const
|
|
549
|
-
return
|
|
135
|
+
const [, r] = e.split("-");
|
|
136
|
+
return J({ chain: t, symbol: e }) || !!r;
|
|
137
|
+
}, Vt = (n) => n.filter(({ chain: t, value: e, symbol: r }) => {
|
|
138
|
+
const i = `${t}.${r}`;
|
|
139
|
+
return !$t.test(i) && At(i) && e !== "0";
|
|
550
140
|
});
|
|
551
|
-
async function
|
|
141
|
+
async function Nt(n) {
|
|
552
142
|
const t = await import("@swapkit/tokens");
|
|
553
|
-
for (const
|
|
554
|
-
for (const { identifier: r, chain:
|
|
555
|
-
if ("identifier" in
|
|
143
|
+
for (const e of Object.values(t))
|
|
144
|
+
for (const { identifier: r, chain: i, ...s } of e.tokens)
|
|
145
|
+
if ("identifier" in n && r === n.identifier || "address" in s && "chain" in n && i === n.chain && s.address.toLowerCase() === n.contract.toLowerCase())
|
|
556
146
|
return r;
|
|
557
147
|
}
|
|
558
|
-
function
|
|
559
|
-
liquidityUnits:
|
|
148
|
+
function bt({
|
|
149
|
+
liquidityUnits: n,
|
|
560
150
|
poolUnits: t,
|
|
561
|
-
runeDepth:
|
|
151
|
+
runeDepth: e
|
|
562
152
|
}) {
|
|
563
|
-
const r =
|
|
564
|
-
return
|
|
153
|
+
const r = _(n), i = _(t), s = _(e), l = r.mul(s), o = i.mul(i).mul(2), c = i.mul(r).mul(2), u = r.mul(r), d = i.mul(i).mul(i);
|
|
154
|
+
return l.mul(o.sub(c).add(u)).div(d);
|
|
565
155
|
}
|
|
566
|
-
function
|
|
567
|
-
liquidityUnits:
|
|
156
|
+
function wt({
|
|
157
|
+
liquidityUnits: n,
|
|
568
158
|
poolUnits: t,
|
|
569
|
-
assetDepth:
|
|
159
|
+
assetDepth: e
|
|
570
160
|
}) {
|
|
571
|
-
const r =
|
|
572
|
-
return
|
|
161
|
+
const r = _(n), i = _(t), s = _(e), l = r.mul(s), o = i.mul(i).mul(2), c = i.mul(r).mul(2), u = r.mul(r), d = l.mul(o.sub(c).add(u)), y = i.mul(i).mul(i);
|
|
162
|
+
return d.div(y);
|
|
573
163
|
}
|
|
574
|
-
function
|
|
575
|
-
percent:
|
|
164
|
+
function Et({
|
|
165
|
+
percent: n,
|
|
576
166
|
runeDepth: t,
|
|
577
|
-
liquidityUnits:
|
|
167
|
+
liquidityUnits: e,
|
|
578
168
|
poolUnits: r
|
|
579
169
|
}) {
|
|
580
|
-
return
|
|
170
|
+
return bt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(n);
|
|
581
171
|
}
|
|
582
|
-
function
|
|
583
|
-
percent:
|
|
172
|
+
function Rt({
|
|
173
|
+
percent: n,
|
|
584
174
|
assetDepth: t,
|
|
585
|
-
liquidityUnits:
|
|
175
|
+
liquidityUnits: e,
|
|
586
176
|
poolUnits: r
|
|
587
177
|
}) {
|
|
588
|
-
return
|
|
178
|
+
return wt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(n);
|
|
589
179
|
}
|
|
590
|
-
function
|
|
591
|
-
return g.fromBigInt(BigInt(
|
|
180
|
+
function _(n) {
|
|
181
|
+
return g.fromBigInt(BigInt(n), m.THOR);
|
|
592
182
|
}
|
|
593
|
-
function
|
|
594
|
-
liquidityUnits:
|
|
183
|
+
function vt({
|
|
184
|
+
liquidityUnits: n,
|
|
595
185
|
poolUnits: t,
|
|
596
|
-
runeDepth:
|
|
186
|
+
runeDepth: e,
|
|
597
187
|
assetDepth: r
|
|
598
188
|
}) {
|
|
599
189
|
return {
|
|
600
|
-
assetAmount:
|
|
601
|
-
runeAmount:
|
|
190
|
+
assetAmount: _(r).mul(n).div(t),
|
|
191
|
+
runeAmount: _(e).mul(n).div(t)
|
|
602
192
|
};
|
|
603
193
|
}
|
|
604
|
-
function
|
|
605
|
-
liquidityUnits:
|
|
194
|
+
function xt({
|
|
195
|
+
liquidityUnits: n,
|
|
606
196
|
poolUnits: t,
|
|
607
|
-
runeDepth:
|
|
197
|
+
runeDepth: e,
|
|
608
198
|
assetDepth: r,
|
|
609
|
-
percent:
|
|
199
|
+
percent: i
|
|
610
200
|
}) {
|
|
611
201
|
return Object.fromEntries(
|
|
612
|
-
Object.entries(
|
|
613
|
-
([
|
|
202
|
+
Object.entries(vt({ liquidityUnits: n, poolUnits: t, runeDepth: e, assetDepth: r })).map(
|
|
203
|
+
([s, l]) => [s, l.mul(i)]
|
|
614
204
|
)
|
|
615
205
|
);
|
|
616
206
|
}
|
|
617
|
-
function
|
|
618
|
-
runeDepth:
|
|
207
|
+
function kt({
|
|
208
|
+
runeDepth: n,
|
|
619
209
|
poolUnits: t,
|
|
620
|
-
assetDepth:
|
|
210
|
+
assetDepth: e,
|
|
621
211
|
liquidityUnits: r,
|
|
622
|
-
runeAmount:
|
|
623
|
-
assetAmount:
|
|
212
|
+
runeAmount: i,
|
|
213
|
+
assetAmount: s
|
|
624
214
|
}) {
|
|
625
|
-
const
|
|
626
|
-
if (
|
|
627
|
-
return
|
|
628
|
-
const
|
|
629
|
-
return
|
|
630
|
-
}
|
|
631
|
-
function
|
|
632
|
-
runeAmount:
|
|
215
|
+
const l = new g({ value: n, decimal: 8 }), o = new g({ value: e, decimal: 8 }), c = new g({ value: t, decimal: 8 }), u = new g({ value: i, decimal: 8 }), d = new g({ value: s, decimal: 8 }), y = u.mul(o), W = d.mul(l), Z = u.mul(d), tt = l.mul(o), et = c.mul(y.add(W.add(Z.mul(2)))), nt = y.add(W.add(tt.mul(2))), G = et.div(nt), j = _(r).add(G);
|
|
216
|
+
if (G.getBaseValue("number") === 0)
|
|
217
|
+
return j.div(c).getBaseValue("number");
|
|
218
|
+
const rt = c.add(j);
|
|
219
|
+
return j.div(rt).getBaseValue("number");
|
|
220
|
+
}
|
|
221
|
+
function Ht({
|
|
222
|
+
runeAmount: n,
|
|
633
223
|
assetAmount: t,
|
|
634
|
-
runeDepth:
|
|
224
|
+
runeDepth: e,
|
|
635
225
|
assetDepth: r
|
|
636
226
|
}) {
|
|
637
|
-
if (
|
|
227
|
+
if (n === "0" || t === "0" || e === "0" || r === "0")
|
|
638
228
|
return 0;
|
|
639
|
-
const
|
|
640
|
-
return Math.abs(
|
|
641
|
-
}
|
|
642
|
-
const
|
|
643
|
-
switch (
|
|
644
|
-
case
|
|
645
|
-
case
|
|
646
|
-
const { address:
|
|
647
|
-
return `${
|
|
229
|
+
const i = _(e), s = _(r), l = _(t), o = _(n), c = l.mul(i).sub(s.mul(o)), u = s.mul(o).add(i.mul(s));
|
|
230
|
+
return Math.abs(c.div(u).getBaseValue("number"));
|
|
231
|
+
}
|
|
232
|
+
const jt = (n, t) => {
|
|
233
|
+
switch (n) {
|
|
234
|
+
case $.LEAVE:
|
|
235
|
+
case $.BOND: {
|
|
236
|
+
const { address: e } = t;
|
|
237
|
+
return `${n}:${e}`;
|
|
648
238
|
}
|
|
649
|
-
case
|
|
650
|
-
const { address:
|
|
651
|
-
return `${
|
|
239
|
+
case $.UNBOND: {
|
|
240
|
+
const { address: e, unbondAmount: r } = t;
|
|
241
|
+
return `${n}:${e}:${r}`;
|
|
652
242
|
}
|
|
653
|
-
case
|
|
654
|
-
const { name:
|
|
655
|
-
return `${
|
|
243
|
+
case $.THORNAME_REGISTER: {
|
|
244
|
+
const { name: e, chain: r, address: i, owner: s } = t;
|
|
245
|
+
return `${n}:${e}:${r}:${i}${s ? `:${s}` : ""}`;
|
|
656
246
|
}
|
|
657
|
-
case
|
|
658
|
-
const { chain:
|
|
659
|
-
return
|
|
660
|
-
switch (
|
|
661
|
-
case
|
|
247
|
+
case $.DEPOSIT: {
|
|
248
|
+
const { chain: e, symbol: r, address: i, singleSide: s } = t;
|
|
249
|
+
return s ? `${n}:${e}/${r}` : `${n}:${((o, c) => {
|
|
250
|
+
switch (o) {
|
|
251
|
+
case a.Litecoin:
|
|
662
252
|
return "l";
|
|
663
|
-
case
|
|
253
|
+
case a.Dogecoin:
|
|
664
254
|
return "d";
|
|
665
|
-
case
|
|
255
|
+
case a.BitcoinCash:
|
|
666
256
|
return "c";
|
|
667
257
|
default:
|
|
668
|
-
return `${
|
|
258
|
+
return `${o}.${c}`;
|
|
669
259
|
}
|
|
670
|
-
})(
|
|
260
|
+
})(e, r)}:${i || ""}`;
|
|
671
261
|
}
|
|
672
|
-
case
|
|
673
|
-
const { chain:
|
|
674
|
-
return `${
|
|
262
|
+
case $.WITHDRAW: {
|
|
263
|
+
const { chain: e, ticker: r, symbol: i, basisPoints: s, targetAssetString: l, singleSide: o } = t, c = e === "ETH" && r !== "ETH" ? `${r}-${i.slice(-3)}` : i, u = !o && l ? `:${l}` : "";
|
|
264
|
+
return `${n}:${e}${o ? "/" : "."}${c}:${s}${u}`;
|
|
675
265
|
}
|
|
676
|
-
case
|
|
677
|
-
case
|
|
678
|
-
const { asset:
|
|
679
|
-
return `${
|
|
266
|
+
case $.OPEN_LOAN:
|
|
267
|
+
case $.CLOSE_LOAN: {
|
|
268
|
+
const { asset: e, address: r } = t;
|
|
269
|
+
return `${n}:${e}:${r}`;
|
|
680
270
|
}
|
|
681
271
|
default:
|
|
682
272
|
return "";
|
|
683
273
|
}
|
|
684
274
|
};
|
|
685
|
-
function
|
|
686
|
-
if (
|
|
275
|
+
function Pt(n) {
|
|
276
|
+
if (n < 0)
|
|
687
277
|
throw new Error("Invalid number of year");
|
|
688
|
-
return 10 +
|
|
278
|
+
return 10 + n;
|
|
689
279
|
}
|
|
690
|
-
function
|
|
691
|
-
if (
|
|
280
|
+
function Dt(n) {
|
|
281
|
+
if (n < 0)
|
|
692
282
|
throw new Error("Invalid number of year");
|
|
693
|
-
return Math.round((10 +
|
|
283
|
+
return Math.round((10 + n * 1.0512) * 1e10) / 1e10;
|
|
694
284
|
}
|
|
695
|
-
function
|
|
696
|
-
if (
|
|
285
|
+
function Lt(n) {
|
|
286
|
+
if (n.length > 30)
|
|
697
287
|
return !1;
|
|
698
288
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
699
|
-
return !!
|
|
289
|
+
return !!n.match(t);
|
|
700
290
|
}
|
|
701
|
-
function
|
|
702
|
-
if (
|
|
291
|
+
function Ut(n) {
|
|
292
|
+
if (n.length > 30)
|
|
703
293
|
return !1;
|
|
704
294
|
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
705
|
-
return !!
|
|
295
|
+
return !!n.match(t);
|
|
706
296
|
}
|
|
707
|
-
function
|
|
708
|
-
return `${
|
|
297
|
+
function Ft([n, t, e, r, i]) {
|
|
298
|
+
return `${n}'/${t}'/${e}'/${r}${typeof i != "number" ? "" : `/${i}`}`;
|
|
709
299
|
}
|
|
710
|
-
const
|
|
711
|
-
function
|
|
712
|
-
const t =
|
|
713
|
-
if (
|
|
300
|
+
const K = [...Object.values(a), "TERRA"];
|
|
301
|
+
function Ct(n = "") {
|
|
302
|
+
const t = n.toUpperCase(), [e] = t.split(".");
|
|
303
|
+
if (K.includes(e))
|
|
714
304
|
return !0;
|
|
715
305
|
const [r] = t.split("/");
|
|
716
|
-
if (
|
|
306
|
+
if (K.includes(r))
|
|
717
307
|
return !0;
|
|
718
308
|
throw new Error(
|
|
719
|
-
`Invalid identifier: ${
|
|
309
|
+
`Invalid identifier: ${n}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
720
310
|
);
|
|
721
311
|
}
|
|
722
|
-
const
|
|
723
|
-
function
|
|
724
|
-
value:
|
|
725
|
-
bigIntDecimal: t =
|
|
726
|
-
decimal:
|
|
312
|
+
const T = 8, b = (n) => 10n ** BigInt(n), B = (n) => Math.log10(Number.parseFloat(n.toString()));
|
|
313
|
+
function x({
|
|
314
|
+
value: n,
|
|
315
|
+
bigIntDecimal: t = T,
|
|
316
|
+
decimal: e = T
|
|
727
317
|
}) {
|
|
728
|
-
if (
|
|
729
|
-
return
|
|
730
|
-
const r =
|
|
731
|
-
let
|
|
732
|
-
const
|
|
733
|
-
|
|
734
|
-
const
|
|
735
|
-
let
|
|
736
|
-
return Number.parseInt(
|
|
318
|
+
if (e === 0)
|
|
319
|
+
return n.toString();
|
|
320
|
+
const r = n < 0n;
|
|
321
|
+
let i = n.toString().substring(r ? 1 : 0);
|
|
322
|
+
const s = e - (i.length - 1);
|
|
323
|
+
s > 0 && (i = "0".repeat(s) + i);
|
|
324
|
+
const l = i.length - e;
|
|
325
|
+
let o = i.slice(-e);
|
|
326
|
+
return Number.parseInt(o[t]) >= 5 ? o = `${o.substring(0, t - 1)}${(Number.parseInt(o[t - 1]) + 1).toString()}` : o = o.substring(0, t), `${r ? "-" : ""}${i.slice(0, l)}.${o}`.replace(
|
|
737
327
|
/\.?0*$/,
|
|
738
328
|
""
|
|
739
329
|
);
|
|
740
330
|
}
|
|
741
|
-
var
|
|
742
|
-
const
|
|
331
|
+
var w, M, A, C, k, Q, N, U, E, F;
|
|
332
|
+
const H = class H {
|
|
743
333
|
constructor(t) {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
const
|
|
753
|
-
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier :
|
|
754
|
-
}
|
|
755
|
-
static fromBigInt(t,
|
|
756
|
-
return new
|
|
757
|
-
decimal:
|
|
758
|
-
value:
|
|
334
|
+
v(this, w);
|
|
335
|
+
v(this, A);
|
|
336
|
+
v(this, k);
|
|
337
|
+
v(this, N);
|
|
338
|
+
v(this, E);
|
|
339
|
+
f(this, "decimalMultiplier", 10n ** 8n);
|
|
340
|
+
f(this, "bigIntValue", 0n);
|
|
341
|
+
f(this, "decimal");
|
|
342
|
+
const e = q(t), r = typeof t == "object";
|
|
343
|
+
this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : b(Math.max(Y(R(e)), this.decimal || 0)), h(this, k, Q).call(this, e);
|
|
344
|
+
}
|
|
345
|
+
static fromBigInt(t, e) {
|
|
346
|
+
return new H({
|
|
347
|
+
decimal: e,
|
|
348
|
+
value: x({ value: t, bigIntDecimal: e, decimal: e })
|
|
759
349
|
});
|
|
760
350
|
}
|
|
761
351
|
static shiftDecimals({
|
|
762
352
|
value: t,
|
|
763
|
-
from:
|
|
353
|
+
from: e,
|
|
764
354
|
to: r
|
|
765
355
|
}) {
|
|
766
|
-
return
|
|
767
|
-
t.getBaseValue("bigint") *
|
|
356
|
+
return H.fromBigInt(
|
|
357
|
+
t.getBaseValue("bigint") * b(r) / b(e),
|
|
768
358
|
r
|
|
769
359
|
);
|
|
770
360
|
}
|
|
@@ -772,50 +362,50 @@ const q = class q {
|
|
|
772
362
|
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
773
363
|
}
|
|
774
364
|
add(...t) {
|
|
775
|
-
return
|
|
365
|
+
return h(this, w, M).call(this, "add", ...t);
|
|
776
366
|
}
|
|
777
367
|
sub(...t) {
|
|
778
|
-
return
|
|
368
|
+
return h(this, w, M).call(this, "sub", ...t);
|
|
779
369
|
}
|
|
780
370
|
mul(...t) {
|
|
781
|
-
return
|
|
371
|
+
return h(this, w, M).call(this, "mul", ...t);
|
|
782
372
|
}
|
|
783
373
|
div(...t) {
|
|
784
|
-
return
|
|
374
|
+
return h(this, w, M).call(this, "div", ...t);
|
|
785
375
|
}
|
|
786
376
|
gt(t) {
|
|
787
|
-
return
|
|
377
|
+
return h(this, A, C).call(this, "gt", t);
|
|
788
378
|
}
|
|
789
379
|
gte(t) {
|
|
790
|
-
return
|
|
380
|
+
return h(this, A, C).call(this, "gte", t);
|
|
791
381
|
}
|
|
792
382
|
lt(t) {
|
|
793
|
-
return
|
|
383
|
+
return h(this, A, C).call(this, "lt", t);
|
|
794
384
|
}
|
|
795
385
|
lte(t) {
|
|
796
|
-
return
|
|
386
|
+
return h(this, A, C).call(this, "lte", t);
|
|
797
387
|
}
|
|
798
388
|
eqValue(t) {
|
|
799
|
-
return
|
|
389
|
+
return h(this, A, C).call(this, "eqValue", t);
|
|
800
390
|
}
|
|
801
391
|
// @ts-expect-error False positive
|
|
802
392
|
getValue(t) {
|
|
803
|
-
const
|
|
393
|
+
const e = this.formatBigIntToSafeValue(
|
|
804
394
|
this.bigIntValue,
|
|
805
|
-
this.decimal ||
|
|
395
|
+
this.decimal || B(this.decimalMultiplier)
|
|
806
396
|
);
|
|
807
397
|
switch (t) {
|
|
808
398
|
case "number":
|
|
809
|
-
return Number(
|
|
399
|
+
return Number(e);
|
|
810
400
|
case "string":
|
|
811
|
-
return
|
|
401
|
+
return e;
|
|
812
402
|
case "bigint":
|
|
813
403
|
return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
|
|
814
404
|
}
|
|
815
405
|
}
|
|
816
406
|
// @ts-expect-error
|
|
817
407
|
getBaseValue(t) {
|
|
818
|
-
const
|
|
408
|
+
const e = this.decimalMultiplier / b(this.decimal || m.THOR), r = this.bigIntValue / e;
|
|
819
409
|
switch (t) {
|
|
820
410
|
case "number":
|
|
821
411
|
return Number(r);
|
|
@@ -825,173 +415,173 @@ const q = class q {
|
|
|
825
415
|
return r;
|
|
826
416
|
}
|
|
827
417
|
}
|
|
828
|
-
getBigIntValue(t,
|
|
829
|
-
if (!
|
|
418
|
+
getBigIntValue(t, e) {
|
|
419
|
+
if (!e && typeof t == "object")
|
|
830
420
|
return t.bigIntValue;
|
|
831
|
-
const r =
|
|
832
|
-
return
|
|
421
|
+
const r = q(t), i = R(r);
|
|
422
|
+
return i === "0" || i === "undefined" ? 0n : h(this, E, F).call(this, i, e);
|
|
833
423
|
}
|
|
834
424
|
toSignificant(t = 6) {
|
|
835
|
-
const [
|
|
836
|
-
if ((Number.parseInt(
|
|
425
|
+
const [e, r] = this.getValue("string").split("."), i = e || "", s = r || "";
|
|
426
|
+
if ((Number.parseInt(i) ? i.length + s.length : s.length) <= t)
|
|
837
427
|
return this.getValue("string");
|
|
838
|
-
if (
|
|
839
|
-
return
|
|
840
|
-
if (Number.parseInt(
|
|
841
|
-
return `${
|
|
842
|
-
t -
|
|
428
|
+
if (i.length >= t)
|
|
429
|
+
return i.slice(0, t).padEnd(i.length, "0");
|
|
430
|
+
if (Number.parseInt(i))
|
|
431
|
+
return `${i}.${s.slice(0, t - i.length)}`.padEnd(
|
|
432
|
+
t - i.length,
|
|
843
433
|
"0"
|
|
844
434
|
);
|
|
845
|
-
const
|
|
846
|
-
return `0.${
|
|
847
|
-
|
|
435
|
+
const o = Number.parseInt(s), c = `${o}`.slice(0, t);
|
|
436
|
+
return `0.${c.padStart(
|
|
437
|
+
s.length - `${o}`.length + c.length,
|
|
848
438
|
"0"
|
|
849
439
|
)}`;
|
|
850
440
|
}
|
|
851
441
|
toFixed(t = 6) {
|
|
852
|
-
const [
|
|
853
|
-
if (Number.parseInt(
|
|
854
|
-
return `${
|
|
855
|
-
const
|
|
856
|
-
return `0.${
|
|
857
|
-
|
|
442
|
+
const [e, r] = this.getValue("string").split("."), i = e || "", s = r || "";
|
|
443
|
+
if (Number.parseInt(i))
|
|
444
|
+
return `${i}.${s.slice(0, t)}`.padEnd(t, "0");
|
|
445
|
+
const l = Number.parseInt(s), o = `${l}`.slice(0, t);
|
|
446
|
+
return `0.${o.padStart(
|
|
447
|
+
s.length - `${l}`.length + o.length,
|
|
858
448
|
"0"
|
|
859
449
|
)}`;
|
|
860
450
|
}
|
|
861
451
|
toAbbreviation(t = 2) {
|
|
862
|
-
const
|
|
863
|
-
if (!
|
|
452
|
+
const e = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], i = Math.floor(Math.log10(Math.abs(e)) / 3), s = r[i];
|
|
453
|
+
if (!s)
|
|
864
454
|
return this.getValue("string");
|
|
865
|
-
const
|
|
866
|
-
return `${(
|
|
455
|
+
const l = 10 ** (i * 3);
|
|
456
|
+
return `${(e / l).toFixed(t)}${s}`;
|
|
867
457
|
}
|
|
868
458
|
toCurrency(t = "$", {
|
|
869
|
-
currencyPosition:
|
|
459
|
+
currencyPosition: e = "start",
|
|
870
460
|
decimal: r = 2,
|
|
871
|
-
decimalSeparator:
|
|
872
|
-
thousandSeparator:
|
|
461
|
+
decimalSeparator: i = ".",
|
|
462
|
+
thousandSeparator: s = ","
|
|
873
463
|
} = {}) {
|
|
874
|
-
const
|
|
875
|
-
return `${
|
|
464
|
+
const l = this.getValue("number"), [o, c = ""] = l.toFixed(6).split("."), u = o.replace(/\B(?=(\d{3})+(?!\d))/g, s), d = o || c ? o === "0" ? `${Number.parseFloat(`0.${c}`)}`.replace(".", i) : `${u}${Number.parseInt(c) ? `${i}${c.slice(0, r)}` : ""}` : "0.00";
|
|
465
|
+
return `${e === "start" ? t : ""}${d}${e === "end" ? t : ""}`;
|
|
876
466
|
}
|
|
877
|
-
formatBigIntToSafeValue(t,
|
|
878
|
-
const r =
|
|
467
|
+
formatBigIntToSafeValue(t, e) {
|
|
468
|
+
const r = e || this.decimal || T, i = Math.max(
|
|
879
469
|
r,
|
|
880
|
-
|
|
881
|
-
),
|
|
882
|
-
let
|
|
883
|
-
return Number.parseInt(
|
|
470
|
+
B(this.decimalMultiplier)
|
|
471
|
+
), s = t < 0n, l = t.toString().substring(s ? 1 : 0), o = i - (l.length - 1), c = o > 0 ? "0".repeat(o) + l : l, u = c.length - i;
|
|
472
|
+
let d = c.slice(-i);
|
|
473
|
+
return Number.parseInt(d[r]) >= 5 ? d = `${d.substring(0, r - 1)}${(Number.parseInt(d[r - 1]) + 1).toString()}` : d = d.substring(0, r), `${s ? "-" : ""}${c.slice(
|
|
884
474
|
0,
|
|
885
|
-
|
|
886
|
-
)}.${
|
|
475
|
+
u
|
|
476
|
+
)}.${d}`.replace(/\.?0*$/, "");
|
|
887
477
|
}
|
|
888
478
|
};
|
|
889
|
-
|
|
890
|
-
const r =
|
|
891
|
-
(
|
|
892
|
-
const
|
|
479
|
+
w = new WeakSet(), M = function(t, ...e) {
|
|
480
|
+
const r = h(this, N, U).call(this, this, ...e), i = Math.max(r, B(this.decimalMultiplier)), s = b(i), l = e.reduce(
|
|
481
|
+
(c, u) => {
|
|
482
|
+
const d = this.getBigIntValue(u, i);
|
|
893
483
|
switch (t) {
|
|
894
484
|
case "add":
|
|
895
|
-
return
|
|
485
|
+
return c + d;
|
|
896
486
|
case "sub":
|
|
897
|
-
return
|
|
487
|
+
return c - d;
|
|
898
488
|
case "mul":
|
|
899
|
-
return
|
|
489
|
+
return c * d / s;
|
|
900
490
|
case "div": {
|
|
901
|
-
if (
|
|
491
|
+
if (d === 0n)
|
|
902
492
|
throw new RangeError("Division by zero");
|
|
903
|
-
return
|
|
493
|
+
return c * s / d;
|
|
904
494
|
}
|
|
905
495
|
default:
|
|
906
|
-
return
|
|
496
|
+
return c;
|
|
907
497
|
}
|
|
908
498
|
},
|
|
909
499
|
//normalize is to precision multiplier base
|
|
910
|
-
this.bigIntValue *
|
|
911
|
-
),
|
|
912
|
-
bigIntDecimal:
|
|
913
|
-
decimal:
|
|
914
|
-
value:
|
|
500
|
+
this.bigIntValue * s / this.decimalMultiplier
|
|
501
|
+
), o = x({
|
|
502
|
+
bigIntDecimal: i,
|
|
503
|
+
decimal: i,
|
|
504
|
+
value: l
|
|
915
505
|
});
|
|
916
506
|
return new this.constructor({
|
|
917
|
-
decimalMultiplier:
|
|
507
|
+
decimalMultiplier: b(i),
|
|
918
508
|
decimal: this.decimal,
|
|
919
|
-
value:
|
|
509
|
+
value: o,
|
|
920
510
|
identifier: this.toString()
|
|
921
511
|
});
|
|
922
|
-
},
|
|
923
|
-
const r =
|
|
512
|
+
}, A = new WeakSet(), C = function(t, ...e) {
|
|
513
|
+
const r = h(this, N, U).call(this, this, ...e), i = this.getBigIntValue(e[0], r), s = this.getBigIntValue(this, r);
|
|
924
514
|
switch (t) {
|
|
925
515
|
case "gt":
|
|
926
|
-
return
|
|
516
|
+
return s > i;
|
|
927
517
|
case "gte":
|
|
928
|
-
return
|
|
518
|
+
return s >= i;
|
|
929
519
|
case "lt":
|
|
930
|
-
return
|
|
520
|
+
return s < i;
|
|
931
521
|
case "lte":
|
|
932
|
-
return
|
|
522
|
+
return s <= i;
|
|
933
523
|
case "eqValue":
|
|
934
|
-
return
|
|
935
|
-
}
|
|
936
|
-
},
|
|
937
|
-
const
|
|
938
|
-
this.bigIntValue =
|
|
939
|
-
},
|
|
940
|
-
const
|
|
941
|
-
return Math.max(...
|
|
942
|
-
},
|
|
943
|
-
const r =
|
|
944
|
-
return BigInt(`${
|
|
524
|
+
return s === i;
|
|
525
|
+
}
|
|
526
|
+
}, k = new WeakSet(), Q = function(t) {
|
|
527
|
+
const e = R(t) || "0";
|
|
528
|
+
this.bigIntValue = h(this, E, F).call(this, e);
|
|
529
|
+
}, N = new WeakSet(), U = function(...t) {
|
|
530
|
+
const e = t.map((r) => typeof r == "object" ? r.decimal || B(r.decimalMultiplier) : Y(R(r))).filter(Boolean);
|
|
531
|
+
return Math.max(...e, T);
|
|
532
|
+
}, E = new WeakSet(), F = function(t, e) {
|
|
533
|
+
const r = e ? b(e) : this.decimalMultiplier, i = B(r), [s = "", l = ""] = t.split(".");
|
|
534
|
+
return BigInt(`${s}${l.padEnd(i, "0")}`);
|
|
945
535
|
};
|
|
946
|
-
let
|
|
947
|
-
const
|
|
536
|
+
let V = H;
|
|
537
|
+
const It = Intl.NumberFormat("fullwide", {
|
|
948
538
|
useGrouping: !1,
|
|
949
539
|
maximumFractionDigits: 20
|
|
950
540
|
});
|
|
951
|
-
function
|
|
952
|
-
const
|
|
953
|
-
return
|
|
541
|
+
function R(n) {
|
|
542
|
+
const e = `${typeof n == "number" ? It.format(n) : q(n)}`.replaceAll(",", ".").split(".");
|
|
543
|
+
return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
|
|
954
544
|
}
|
|
955
|
-
function
|
|
956
|
-
var
|
|
957
|
-
const t = ((
|
|
958
|
-
return Math.max(t,
|
|
545
|
+
function Y(n) {
|
|
546
|
+
var e;
|
|
547
|
+
const t = ((e = n.split(".")[1]) == null ? void 0 : e.length) || 0;
|
|
548
|
+
return Math.max(t, T);
|
|
959
549
|
}
|
|
960
|
-
function
|
|
961
|
-
return typeof
|
|
550
|
+
function q(n) {
|
|
551
|
+
return typeof n == "object" ? "getValue" in n ? n.getValue("string") : n.value : n;
|
|
962
552
|
}
|
|
963
|
-
class g extends
|
|
553
|
+
class g extends V {
|
|
964
554
|
eq(t) {
|
|
965
555
|
return this.eqValue(t);
|
|
966
556
|
}
|
|
967
|
-
static fromBigInt(t,
|
|
557
|
+
static fromBigInt(t, e) {
|
|
968
558
|
return new g({
|
|
969
|
-
decimal:
|
|
970
|
-
value:
|
|
559
|
+
decimal: e,
|
|
560
|
+
value: x({ value: t, bigIntDecimal: e, decimal: e })
|
|
971
561
|
});
|
|
972
562
|
}
|
|
973
563
|
}
|
|
974
|
-
const
|
|
975
|
-
class
|
|
564
|
+
const I = /* @__PURE__ */ new Map();
|
|
565
|
+
class p extends V {
|
|
976
566
|
constructor({
|
|
977
|
-
value:
|
|
567
|
+
value: e,
|
|
978
568
|
decimal: r,
|
|
979
|
-
tax:
|
|
980
|
-
chain:
|
|
981
|
-
symbol:
|
|
982
|
-
identifier:
|
|
569
|
+
tax: i,
|
|
570
|
+
chain: s,
|
|
571
|
+
symbol: l,
|
|
572
|
+
identifier: o
|
|
983
573
|
}) {
|
|
984
|
-
super(typeof
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
const
|
|
994
|
-
this.type =
|
|
574
|
+
super(typeof e == "object" ? e : { decimal: r, value: e });
|
|
575
|
+
f(this, "address");
|
|
576
|
+
f(this, "chain");
|
|
577
|
+
f(this, "isGasAsset", !1);
|
|
578
|
+
f(this, "isSynthetic", !1);
|
|
579
|
+
f(this, "symbol");
|
|
580
|
+
f(this, "tax");
|
|
581
|
+
f(this, "ticker");
|
|
582
|
+
f(this, "type");
|
|
583
|
+
const c = O(o || `${s}.${l}`);
|
|
584
|
+
this.type = pt(c), this.tax = i, this.chain = c.chain, this.ticker = c.ticker, this.symbol = c.symbol, this.address = c.address, this.isSynthetic = c.isSynthetic, this.isGasAsset = c.isGasAsset;
|
|
995
585
|
}
|
|
996
586
|
toString() {
|
|
997
587
|
return this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
|
|
@@ -999,97 +589,97 @@ class A extends D {
|
|
|
999
589
|
toUrl() {
|
|
1000
590
|
return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
|
|
1001
591
|
}
|
|
1002
|
-
eq({ chain:
|
|
1003
|
-
return this.chain ===
|
|
592
|
+
eq({ chain: e, symbol: r }) {
|
|
593
|
+
return this.chain === e && this.symbol === r;
|
|
1004
594
|
}
|
|
1005
595
|
chainId() {
|
|
1006
|
-
return
|
|
596
|
+
return ut[this.chain];
|
|
1007
597
|
}
|
|
1008
598
|
// THOR.RUNE
|
|
1009
599
|
// THOR.ETH.ETH
|
|
1010
600
|
// ETH.THOR-0x1234567890
|
|
1011
|
-
static fromUrl(
|
|
1012
|
-
const [
|
|
1013
|
-
if (!(
|
|
601
|
+
static fromUrl(e, r = 0) {
|
|
602
|
+
const [i, s, l] = e.split(".");
|
|
603
|
+
if (!(i && s))
|
|
1014
604
|
throw new Error("Invalid asset url");
|
|
1015
|
-
const
|
|
1016
|
-
return
|
|
1017
|
-
}
|
|
1018
|
-
static fromString(
|
|
1019
|
-
return
|
|
1020
|
-
}
|
|
1021
|
-
static fromIdentifier(
|
|
1022
|
-
return
|
|
1023
|
-
}
|
|
1024
|
-
static fromStringSync(
|
|
1025
|
-
const { chain:
|
|
1026
|
-
if (
|
|
1027
|
-
return
|
|
1028
|
-
const { tax:
|
|
1029
|
-
decimal:
|
|
1030
|
-
identifier:
|
|
605
|
+
const o = i === a.THORChain && l ? `${i}.${s}/${l}` : e;
|
|
606
|
+
return D(o, r);
|
|
607
|
+
}
|
|
608
|
+
static fromString(e, r = 0) {
|
|
609
|
+
return D(e, r);
|
|
610
|
+
}
|
|
611
|
+
static fromIdentifier(e, r = 0) {
|
|
612
|
+
return D(e, r);
|
|
613
|
+
}
|
|
614
|
+
static fromStringSync(e, r = 0) {
|
|
615
|
+
const { chain: i, isSynthetic: s } = O(e), l = I.get(e.toUpperCase());
|
|
616
|
+
if (s)
|
|
617
|
+
return L(e, r);
|
|
618
|
+
const { tax: o, decimal: c, identifier: u } = l || {
|
|
619
|
+
decimal: m[i],
|
|
620
|
+
identifier: e
|
|
1031
621
|
};
|
|
1032
|
-
return new
|
|
1033
|
-
tax:
|
|
1034
|
-
value:
|
|
1035
|
-
identifier:
|
|
1036
|
-
decimal:
|
|
622
|
+
return new p({
|
|
623
|
+
tax: o,
|
|
624
|
+
value: S(r, c),
|
|
625
|
+
identifier: s ? e : u,
|
|
626
|
+
decimal: s ? 8 : c
|
|
1037
627
|
});
|
|
1038
628
|
}
|
|
1039
|
-
static async fromStringWithBase(
|
|
1040
|
-
const
|
|
629
|
+
static async fromStringWithBase(e, r = 0, i = m.THOR) {
|
|
630
|
+
const s = V.shiftDecimals({
|
|
1041
631
|
value: g.fromBigInt(BigInt(r)),
|
|
1042
632
|
from: 0,
|
|
1043
|
-
to:
|
|
633
|
+
to: i
|
|
1044
634
|
}).getBaseValue("string");
|
|
1045
|
-
return (await
|
|
1046
|
-
}
|
|
1047
|
-
static fromStringWithBaseSync(
|
|
1048
|
-
const { chain:
|
|
1049
|
-
if (
|
|
1050
|
-
return
|
|
1051
|
-
const { tax:
|
|
1052
|
-
decimal:
|
|
1053
|
-
identifier:
|
|
635
|
+
return (await p.fromString(e, r)).set(s);
|
|
636
|
+
}
|
|
637
|
+
static fromStringWithBaseSync(e, r = 0, i = m.THOR) {
|
|
638
|
+
const { chain: s, isSynthetic: l } = O(e), o = I.get(e.toUpperCase());
|
|
639
|
+
if (l)
|
|
640
|
+
return L(e, r);
|
|
641
|
+
const { tax: c, decimal: u, identifier: d } = o || {
|
|
642
|
+
decimal: m[s],
|
|
643
|
+
identifier: e
|
|
1054
644
|
};
|
|
1055
|
-
return new
|
|
1056
|
-
tax:
|
|
1057
|
-
value:
|
|
1058
|
-
identifier:
|
|
1059
|
-
decimal:
|
|
645
|
+
return new p({
|
|
646
|
+
tax: c,
|
|
647
|
+
value: S(BigInt(r), i),
|
|
648
|
+
identifier: d,
|
|
649
|
+
decimal: u
|
|
1060
650
|
});
|
|
1061
651
|
}
|
|
1062
|
-
static fromIdentifierSync(
|
|
1063
|
-
const { chain:
|
|
1064
|
-
if (
|
|
1065
|
-
return
|
|
1066
|
-
const { tax:
|
|
1067
|
-
decimal:
|
|
1068
|
-
identifier:
|
|
652
|
+
static fromIdentifierSync(e, r = 0) {
|
|
653
|
+
const { chain: i, isSynthetic: s } = O(e), l = I.get(e);
|
|
654
|
+
if (s)
|
|
655
|
+
return L(e, r);
|
|
656
|
+
const { tax: o, decimal: c, identifier: u } = l || {
|
|
657
|
+
decimal: m[i],
|
|
658
|
+
identifier: e
|
|
1069
659
|
};
|
|
1070
|
-
return new
|
|
660
|
+
return new p({ tax: o, decimal: c, identifier: u, value: S(r, c) });
|
|
1071
661
|
}
|
|
1072
|
-
static fromChainOrSignature(
|
|
1073
|
-
const { decimal:
|
|
1074
|
-
return new
|
|
662
|
+
static fromChainOrSignature(e, r = 0) {
|
|
663
|
+
const { decimal: i, identifier: s } = gt(e);
|
|
664
|
+
return new p({ value: S(r, i), decimal: i, identifier: s });
|
|
1075
665
|
}
|
|
1076
666
|
static loadStaticAssets() {
|
|
1077
667
|
return new Promise(
|
|
1078
|
-
(
|
|
668
|
+
(e, r) => {
|
|
1079
669
|
try {
|
|
1080
|
-
import("@swapkit/tokens").then((
|
|
1081
|
-
for (const
|
|
1082
|
-
for (const { identifier:
|
|
1083
|
-
|
|
1084
|
-
identifier:
|
|
1085
|
-
decimal: "decimals" in
|
|
670
|
+
import("@swapkit/tokens").then((i) => {
|
|
671
|
+
for (const s of Object.values(i))
|
|
672
|
+
for (const { identifier: l, chain: o, ...c } of s.tokens)
|
|
673
|
+
I.set(l.toUpperCase(), {
|
|
674
|
+
identifier: l,
|
|
675
|
+
decimal: "decimals" in c ? c.decimals : m[o]
|
|
1086
676
|
});
|
|
1087
|
-
|
|
677
|
+
e({ ok: !0 });
|
|
1088
678
|
});
|
|
1089
|
-
} catch (
|
|
1090
|
-
console.error(
|
|
679
|
+
} catch (i) {
|
|
680
|
+
console.error(i), r({
|
|
1091
681
|
ok: !1,
|
|
1092
|
-
error:
|
|
682
|
+
error: i,
|
|
1093
683
|
message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
|
|
1094
684
|
});
|
|
1095
685
|
}
|
|
@@ -1097,60 +687,60 @@ class A extends D {
|
|
|
1097
687
|
);
|
|
1098
688
|
}
|
|
1099
689
|
}
|
|
1100
|
-
function
|
|
1101
|
-
const t =
|
|
1102
|
-
switch (
|
|
1103
|
-
case
|
|
1104
|
-
case
|
|
1105
|
-
case
|
|
690
|
+
function qt(n) {
|
|
691
|
+
const t = p.fromChainOrSignature(n);
|
|
692
|
+
switch (n) {
|
|
693
|
+
case a.Bitcoin:
|
|
694
|
+
case a.Litecoin:
|
|
695
|
+
case a.BitcoinCash:
|
|
1106
696
|
return t.set(10001e-8);
|
|
1107
|
-
case
|
|
697
|
+
case a.Dogecoin:
|
|
1108
698
|
return t.set(1.00000001);
|
|
1109
|
-
case
|
|
1110
|
-
case
|
|
699
|
+
case a.Avalanche:
|
|
700
|
+
case a.Ethereum:
|
|
1111
701
|
return t.set(1e-8);
|
|
1112
|
-
case
|
|
1113
|
-
case
|
|
702
|
+
case a.THORChain:
|
|
703
|
+
case a.Maya:
|
|
1114
704
|
return t.set(0);
|
|
1115
|
-
case
|
|
705
|
+
case a.Cosmos:
|
|
1116
706
|
return t.set(1e-6);
|
|
1117
707
|
default:
|
|
1118
708
|
return t.set(1e-8);
|
|
1119
709
|
}
|
|
1120
710
|
}
|
|
1121
|
-
async function
|
|
1122
|
-
|
|
1123
|
-
const
|
|
1124
|
-
return
|
|
711
|
+
async function D(n, t = 0) {
|
|
712
|
+
Ct(n);
|
|
713
|
+
const e = I.get(n.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await ft(O(n));
|
|
714
|
+
return e || I.set(n.toUpperCase(), { identifier: n, decimal: r }), new p({ decimal: r, value: S(t, r), identifier: n });
|
|
1125
715
|
}
|
|
1126
|
-
function
|
|
1127
|
-
const [
|
|
1128
|
-
if (!(
|
|
716
|
+
function L(n, t = 0) {
|
|
717
|
+
const [e, r] = n.split(".")[0].toUpperCase() === a.THORChain ? n.split(".").slice(1).join().split("/") : n.split("/");
|
|
718
|
+
if (!(e && r))
|
|
1129
719
|
throw new Error("Invalid asset identifier");
|
|
1130
|
-
return new
|
|
720
|
+
return new p({
|
|
1131
721
|
decimal: 8,
|
|
1132
|
-
value:
|
|
1133
|
-
identifier: `${
|
|
722
|
+
value: S(t, 8),
|
|
723
|
+
identifier: `${a.THORChain}.${e}/${r}`
|
|
1134
724
|
});
|
|
1135
725
|
}
|
|
1136
|
-
function
|
|
1137
|
-
return typeof
|
|
726
|
+
function S(n, t) {
|
|
727
|
+
return typeof n == "bigint" ? x({ value: n, bigIntDecimal: t, decimal: t }) : n;
|
|
1138
728
|
}
|
|
1139
|
-
function
|
|
1140
|
-
const t =
|
|
1141
|
-
if (t && !(
|
|
729
|
+
function O(n) {
|
|
730
|
+
const t = n.slice(0, 14).includes("/"), [e, r] = n.split(".")[0].toUpperCase() === a.THORChain ? n.split(".").slice(1).join().split("/") : n.split("/");
|
|
731
|
+
if (t && !(e && r))
|
|
1142
732
|
throw new Error("Invalid asset identifier");
|
|
1143
|
-
const
|
|
733
|
+
const i = n.includes(".") && !t ? n : `${a.THORChain}.${r}`, [s, ...l] = i.split("."), [o, c] = (t ? r : l.join(".")).split("-"), u = t ? r : l.join(".");
|
|
1144
734
|
return {
|
|
1145
|
-
address:
|
|
1146
|
-
chain:
|
|
1147
|
-
isGasAsset:
|
|
735
|
+
address: c == null ? void 0 : c.toLowerCase(),
|
|
736
|
+
chain: s,
|
|
737
|
+
isGasAsset: J({ chain: s, symbol: u }),
|
|
1148
738
|
isSynthetic: t,
|
|
1149
|
-
symbol: (t ? `${
|
|
1150
|
-
ticker:
|
|
739
|
+
symbol: (t ? `${e}/` : "") + (c ? `${o}-${(c == null ? void 0 : c.toLowerCase()) ?? ""}` : u),
|
|
740
|
+
ticker: o
|
|
1151
741
|
};
|
|
1152
742
|
}
|
|
1153
|
-
const
|
|
743
|
+
const St = {
|
|
1154
744
|
/**
|
|
1155
745
|
* Core
|
|
1156
746
|
*/
|
|
@@ -1223,52 +813,44 @@ const mt = {
|
|
|
1223
813
|
*/
|
|
1224
814
|
helpers_number_different_decimals: 99101
|
|
1225
815
|
};
|
|
1226
|
-
class
|
|
1227
|
-
constructor(t,
|
|
1228
|
-
|
|
1229
|
-
stack:
|
|
1230
|
-
message:
|
|
816
|
+
class X extends Error {
|
|
817
|
+
constructor(t, e) {
|
|
818
|
+
e && console.error(e, {
|
|
819
|
+
stack: e == null ? void 0 : e.stack,
|
|
820
|
+
message: e == null ? void 0 : e.message
|
|
1231
821
|
}), super(t, {
|
|
1232
|
-
cause: { code:
|
|
1233
|
-
}), Object.setPrototypeOf(this,
|
|
822
|
+
cause: { code: St[t], message: t }
|
|
823
|
+
}), Object.setPrototypeOf(this, X.prototype);
|
|
1234
824
|
}
|
|
1235
825
|
}
|
|
1236
826
|
export {
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
f as RequestClient,
|
|
1241
|
-
Ze as StreamingSwapProgressStatus,
|
|
1242
|
-
gt as SwapKitApi,
|
|
1243
|
-
we as SwapKitError,
|
|
827
|
+
p as AssetValue,
|
|
828
|
+
V as BigIntArithmetics,
|
|
829
|
+
X as SwapKitError,
|
|
1244
830
|
g as SwapKitNumber,
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
vt as
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
Se as isGasAsset,
|
|
1270
|
-
Tt as setRequestClientConfig,
|
|
1271
|
-
It as validateMAYAName,
|
|
1272
|
-
$t as validateTHORName
|
|
831
|
+
Tt as assetFromString,
|
|
832
|
+
Ft as derivationPathToString,
|
|
833
|
+
Vt as filterAssets,
|
|
834
|
+
Nt as findAssetBy,
|
|
835
|
+
x as formatBigIntToSafeValue,
|
|
836
|
+
Ot as gasFeeMultiplier,
|
|
837
|
+
pt as getAssetType,
|
|
838
|
+
wt as getAsymmetricAssetShare,
|
|
839
|
+
Rt as getAsymmetricAssetWithdrawAmount,
|
|
840
|
+
bt as getAsymmetricRuneShare,
|
|
841
|
+
Et as getAsymmetricRuneWithdrawAmount,
|
|
842
|
+
gt as getCommonAssetInfo,
|
|
843
|
+
ft as getDecimal,
|
|
844
|
+
kt as getEstimatedPoolShare,
|
|
845
|
+
Ht as getLiquiditySlippage,
|
|
846
|
+
Dt as getMAYANameCost,
|
|
847
|
+
jt as getMemoFor,
|
|
848
|
+
qt as getMinAmountByChain,
|
|
849
|
+
vt as getSymmetricPoolShare,
|
|
850
|
+
xt as getSymmetricWithdraw,
|
|
851
|
+
Pt as getTHORNameCost,
|
|
852
|
+
J as isGasAsset,
|
|
853
|
+
Ut as validateMAYAName,
|
|
854
|
+
Lt as validateTHORName
|
|
1273
855
|
};
|
|
1274
856
|
//# sourceMappingURL=index.es.js.map
|