@swapkit/core 1.0.0-rc.8 → 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 +3 -2
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.es.js +6047 -816
- package/dist/index.es.js.map +1 -0
- package/package.json +21 -24
- package/src/aggregator/contracts/index.ts +2 -0
- package/src/aggregator/contracts/routers/index.ts +58 -0
- package/src/aggregator/contracts/routers/kyber.ts +402 -0
- package/src/aggregator/contracts/routers/oneinch.ts +2188 -0
- package/src/aggregator/contracts/routers/pancakeswap.ts +340 -0
- package/src/aggregator/contracts/routers/pangolin.ts +340 -0
- package/src/aggregator/contracts/routers/sushiswap.ts +340 -0
- package/src/aggregator/contracts/routers/traderJoe.ts +340 -0
- package/src/aggregator/contracts/routers/uniswapv2.ts +340 -0
- package/src/aggregator/contracts/routers/uniswapv3.ts +254 -0
- package/src/aggregator/contracts/routers/woofi.ts +171 -0
- package/src/client/__tests__/helpers.test.ts +41 -33
- package/src/client/explorerUrls.ts +7 -8
- package/src/client/index.ts +141 -73
- package/src/client/thornode.ts +3 -3
- package/dist/index-9e36735e.cjs +0 -1
- package/dist/index-cf1865cd.js +0 -649
package/dist/index-cf1865cd.js
DELETED
|
@@ -1,649 +0,0 @@
|
|
|
1
|
-
var Y = Object.defineProperty;
|
|
2
|
-
var tt = (i, t, e) => t in i ? Y(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
-
var k = (i, t, e) => (tt(i, typeof t != "symbol" ? t + "" : t, e), e), O = (i, t, e) => {
|
|
4
|
-
if (!t.has(i))
|
|
5
|
-
throw TypeError("Cannot " + e);
|
|
6
|
-
};
|
|
7
|
-
var s = (i, t, e) => (O(i, t, "read from private field"), e ? e.call(i) : t.get(i)), b = (i, t, e) => {
|
|
8
|
-
if (t.has(i))
|
|
9
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
-
t instanceof WeakSet ? t.add(i) : t.set(i, e);
|
|
11
|
-
}, v = (i, t, e, r) => (O(i, t, "write to private field"), r ? r.call(i, e) : t.set(i, e), e);
|
|
12
|
-
var u = (i, t, e) => (O(i, t, "access private method"), e);
|
|
13
|
-
const it = "6.7.1";
|
|
14
|
-
function et(i, t, e) {
|
|
15
|
-
const r = t.split("|").map((o) => o.trim());
|
|
16
|
-
for (let o = 0; o < r.length; o++)
|
|
17
|
-
switch (t) {
|
|
18
|
-
case "any":
|
|
19
|
-
return;
|
|
20
|
-
case "bigint":
|
|
21
|
-
case "boolean":
|
|
22
|
-
case "number":
|
|
23
|
-
case "string":
|
|
24
|
-
if (typeof i === t)
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const n = new Error(`invalid value for type ${t}`);
|
|
28
|
-
throw n.code = "INVALID_ARGUMENT", n.argument = `value.${e}`, n.value = i, n;
|
|
29
|
-
}
|
|
30
|
-
function q(i, t, e) {
|
|
31
|
-
for (let r in t) {
|
|
32
|
-
let n = t[r];
|
|
33
|
-
const o = e ? e[r] : null;
|
|
34
|
-
o && et(n, o, r), Object.defineProperty(i, r, { enumerable: !0, value: n, writable: !1 });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function x(i) {
|
|
38
|
-
if (i == null)
|
|
39
|
-
return "null";
|
|
40
|
-
if (Array.isArray(i))
|
|
41
|
-
return "[ " + i.map(x).join(", ") + " ]";
|
|
42
|
-
if (i instanceof Uint8Array) {
|
|
43
|
-
const t = "0123456789abcdef";
|
|
44
|
-
let e = "0x";
|
|
45
|
-
for (let r = 0; r < i.length; r++)
|
|
46
|
-
e += t[i[r] >> 4], e += t[i[r] & 15];
|
|
47
|
-
return e;
|
|
48
|
-
}
|
|
49
|
-
if (typeof i == "object" && typeof i.toJSON == "function")
|
|
50
|
-
return x(i.toJSON());
|
|
51
|
-
switch (typeof i) {
|
|
52
|
-
case "boolean":
|
|
53
|
-
case "symbol":
|
|
54
|
-
return i.toString();
|
|
55
|
-
case "bigint":
|
|
56
|
-
return BigInt(i).toString();
|
|
57
|
-
case "number":
|
|
58
|
-
return i.toString();
|
|
59
|
-
case "string":
|
|
60
|
-
return JSON.stringify(i);
|
|
61
|
-
case "object": {
|
|
62
|
-
const t = Object.keys(i);
|
|
63
|
-
return t.sort(), "{ " + t.map((e) => `${x(e)}: ${x(i[e])}`).join(", ") + " }";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return "[ COULD NOT SERIALIZE ]";
|
|
67
|
-
}
|
|
68
|
-
function rt(i, t, e) {
|
|
69
|
-
{
|
|
70
|
-
const n = [];
|
|
71
|
-
if (e) {
|
|
72
|
-
if ("message" in e || "code" in e || "name" in e)
|
|
73
|
-
throw new Error(`value will overwrite populated values: ${x(e)}`);
|
|
74
|
-
for (const o in e) {
|
|
75
|
-
const c = e[o];
|
|
76
|
-
n.push(o + "=" + x(c));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
n.push(`code=${t}`), n.push(`version=${it}`), n.length && (i += " (" + n.join(", ") + ")");
|
|
80
|
-
}
|
|
81
|
-
let r;
|
|
82
|
-
switch (t) {
|
|
83
|
-
case "INVALID_ARGUMENT":
|
|
84
|
-
r = new TypeError(i);
|
|
85
|
-
break;
|
|
86
|
-
case "NUMERIC_FAULT":
|
|
87
|
-
case "BUFFER_OVERRUN":
|
|
88
|
-
r = new RangeError(i);
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
r = new Error(i);
|
|
92
|
-
}
|
|
93
|
-
return q(r, { code: t }), e && Object.assign(r, e), r;
|
|
94
|
-
}
|
|
95
|
-
function g(i, t, e, r) {
|
|
96
|
-
if (!i)
|
|
97
|
-
throw rt(t, e, r);
|
|
98
|
-
}
|
|
99
|
-
function l(i, t, e, r) {
|
|
100
|
-
g(i, t, "INVALID_ARGUMENT", { argument: e, value: r });
|
|
101
|
-
}
|
|
102
|
-
["NFD", "NFC", "NFKD", "NFKC"].reduce((i, t) => {
|
|
103
|
-
try {
|
|
104
|
-
if ("test".normalize(t) !== "test")
|
|
105
|
-
throw new Error("bad");
|
|
106
|
-
if (t === "NFD") {
|
|
107
|
-
const e = String.fromCharCode(233).normalize("NFD"), r = String.fromCharCode(101, 769);
|
|
108
|
-
if (e !== r)
|
|
109
|
-
throw new Error("broken");
|
|
110
|
-
}
|
|
111
|
-
i.push(t);
|
|
112
|
-
} catch {
|
|
113
|
-
}
|
|
114
|
-
return i;
|
|
115
|
-
}, []);
|
|
116
|
-
function nt(i, t, e) {
|
|
117
|
-
if (e == null && (e = ""), i !== t) {
|
|
118
|
-
let r = e, n = "new";
|
|
119
|
-
e && (r += ".", n += " " + e), g(!1, `private constructor; use ${r}from* methods`, "UNSUPPORTED_OPERATION", {
|
|
120
|
-
operation: n
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function st(i, t, e) {
|
|
125
|
-
if (i instanceof Uint8Array)
|
|
126
|
-
return e ? new Uint8Array(i) : i;
|
|
127
|
-
if (typeof i == "string" && i.match(/^0x([0-9a-f][0-9a-f])*$/i)) {
|
|
128
|
-
const r = new Uint8Array((i.length - 2) / 2);
|
|
129
|
-
let n = 2;
|
|
130
|
-
for (let o = 0; o < r.length; o++)
|
|
131
|
-
r[o] = parseInt(i.substring(n, n + 2), 16), n += 2;
|
|
132
|
-
return r;
|
|
133
|
-
}
|
|
134
|
-
l(!1, "invalid BytesLike value", t || "value", i);
|
|
135
|
-
}
|
|
136
|
-
function ot(i, t) {
|
|
137
|
-
return st(i, t, !1);
|
|
138
|
-
}
|
|
139
|
-
function gt(i, t) {
|
|
140
|
-
return !(typeof i != "string" || !i.match(/^0x[0-9A-Fa-f]*$/) || typeof t == "number" && i.length !== 2 + 2 * t || t === !0 && i.length % 2 !== 0);
|
|
141
|
-
}
|
|
142
|
-
const X = BigInt(0), E = BigInt(1), F = 9007199254740991;
|
|
143
|
-
function D(i, t) {
|
|
144
|
-
const e = Q(i, "value"), r = BigInt(M(t, "width"));
|
|
145
|
-
if (g(e >> r === X, "overflow", "NUMERIC_FAULT", {
|
|
146
|
-
operation: "fromTwos",
|
|
147
|
-
fault: "overflow",
|
|
148
|
-
value: i
|
|
149
|
-
}), e >> r - E) {
|
|
150
|
-
const n = (E << r) - E;
|
|
151
|
-
return -((~e & n) + E);
|
|
152
|
-
}
|
|
153
|
-
return e;
|
|
154
|
-
}
|
|
155
|
-
function H(i, t) {
|
|
156
|
-
const e = Q(i, "value"), r = BigInt(M(t, "bits"));
|
|
157
|
-
return e & (E << r) - E;
|
|
158
|
-
}
|
|
159
|
-
function Z(i, t) {
|
|
160
|
-
switch (typeof i) {
|
|
161
|
-
case "bigint":
|
|
162
|
-
return i;
|
|
163
|
-
case "number":
|
|
164
|
-
return l(Number.isInteger(i), "underflow", t || "value", i), l(i >= -F && i <= F, "overflow", t || "value", i), BigInt(i);
|
|
165
|
-
case "string":
|
|
166
|
-
try {
|
|
167
|
-
if (i === "")
|
|
168
|
-
throw new Error("empty string");
|
|
169
|
-
return i[0] === "-" && i[1] !== "-" ? -BigInt(i.substring(1)) : BigInt(i);
|
|
170
|
-
} catch (e) {
|
|
171
|
-
l(!1, `invalid BigNumberish string: ${e.message}`, t || "value", i);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
l(!1, "invalid BigNumberish value", t || "value", i);
|
|
175
|
-
}
|
|
176
|
-
function Q(i, t) {
|
|
177
|
-
const e = Z(i, t);
|
|
178
|
-
return g(e >= X, "unsigned value cannot be negative", "NUMERIC_FAULT", {
|
|
179
|
-
fault: "overflow",
|
|
180
|
-
operation: "getUint",
|
|
181
|
-
value: i
|
|
182
|
-
}), e;
|
|
183
|
-
}
|
|
184
|
-
const K = "0123456789abcdef";
|
|
185
|
-
function ft(i) {
|
|
186
|
-
if (i instanceof Uint8Array) {
|
|
187
|
-
let t = "0x0";
|
|
188
|
-
for (const e of i)
|
|
189
|
-
t += K[e >> 4], t += K[e & 15];
|
|
190
|
-
return BigInt(t);
|
|
191
|
-
}
|
|
192
|
-
return Z(i);
|
|
193
|
-
}
|
|
194
|
-
function M(i, t) {
|
|
195
|
-
switch (typeof i) {
|
|
196
|
-
case "bigint":
|
|
197
|
-
return l(i >= -F && i <= F, "overflow", t || "value", i), Number(i);
|
|
198
|
-
case "number":
|
|
199
|
-
return l(Number.isInteger(i), "underflow", t || "value", i), l(i >= -F && i <= F, "overflow", t || "value", i), i;
|
|
200
|
-
case "string":
|
|
201
|
-
try {
|
|
202
|
-
if (i === "")
|
|
203
|
-
throw new Error("empty string");
|
|
204
|
-
return M(BigInt(i), t);
|
|
205
|
-
} catch (e) {
|
|
206
|
-
l(!1, `invalid numeric string: ${e.message}`, t || "value", i);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
l(!1, "invalid numeric value", t || "value", i);
|
|
210
|
-
}
|
|
211
|
-
const ut = BigInt(-1), d = BigInt(0), S = BigInt(1), ct = BigInt(5), B = {};
|
|
212
|
-
let A = "0000";
|
|
213
|
-
for (; A.length < 80; )
|
|
214
|
-
A += A;
|
|
215
|
-
function U(i) {
|
|
216
|
-
let t = A;
|
|
217
|
-
for (; t.length < i; )
|
|
218
|
-
t += t;
|
|
219
|
-
return BigInt("1" + t.substring(0, i));
|
|
220
|
-
}
|
|
221
|
-
function R(i, t, e) {
|
|
222
|
-
const r = BigInt(t.width);
|
|
223
|
-
if (t.signed) {
|
|
224
|
-
const n = S << r - S;
|
|
225
|
-
g(e == null || i >= -n && i < n, "overflow", "NUMERIC_FAULT", {
|
|
226
|
-
operation: e,
|
|
227
|
-
fault: "overflow",
|
|
228
|
-
value: i
|
|
229
|
-
}), i > d ? i = D(H(i, r), r) : i = -D(H(-i, r), r);
|
|
230
|
-
} else {
|
|
231
|
-
const n = S << r;
|
|
232
|
-
g(e == null || i >= 0 && i < n, "overflow", "NUMERIC_FAULT", {
|
|
233
|
-
operation: e,
|
|
234
|
-
fault: "overflow",
|
|
235
|
-
value: i
|
|
236
|
-
}), i = (i % n + n) % n & n - S;
|
|
237
|
-
}
|
|
238
|
-
return i;
|
|
239
|
-
}
|
|
240
|
-
function V(i) {
|
|
241
|
-
typeof i == "number" && (i = `fixed128x${i}`);
|
|
242
|
-
let t = !0, e = 128, r = 18;
|
|
243
|
-
if (typeof i == "string") {
|
|
244
|
-
if (i !== "fixed")
|
|
245
|
-
if (i === "ufixed")
|
|
246
|
-
t = !1;
|
|
247
|
-
else {
|
|
248
|
-
const o = i.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);
|
|
249
|
-
l(o, "invalid fixed format", "format", i), t = o[1] !== "u", e = parseInt(o[2]), r = parseInt(o[3]);
|
|
250
|
-
}
|
|
251
|
-
} else if (i) {
|
|
252
|
-
const o = i, c = (h, T, W) => o[h] == null ? W : (l(typeof o[h] === T, "invalid fixed format (" + h + " not " + T + ")", "format." + h, o[h]), o[h]);
|
|
253
|
-
t = c("signed", "boolean", t), e = c("width", "number", e), r = c("decimals", "number", r);
|
|
254
|
-
}
|
|
255
|
-
l(e % 8 === 0, "invalid FixedNumber width (not byte aligned)", "format.width", e), l(r <= 80, "invalid FixedNumber decimals (too large)", "format.decimals", r);
|
|
256
|
-
const n = (t ? "" : "u") + "fixed" + String(e) + "x" + String(r);
|
|
257
|
-
return { signed: t, width: e, decimals: r, name: n };
|
|
258
|
-
}
|
|
259
|
-
function lt(i, t) {
|
|
260
|
-
let e = "";
|
|
261
|
-
i < d && (e = "-", i *= ut);
|
|
262
|
-
let r = i.toString();
|
|
263
|
-
if (t === 0)
|
|
264
|
-
return e + r;
|
|
265
|
-
for (; r.length <= t; )
|
|
266
|
-
r = A + r;
|
|
267
|
-
const n = r.length - t;
|
|
268
|
-
for (r = r.substring(0, n) + "." + r.substring(n); r[0] === "0" && r[1] !== "."; )
|
|
269
|
-
r = r.substring(1);
|
|
270
|
-
for (; r[r.length - 1] === "0" && r[r.length - 2] !== "."; )
|
|
271
|
-
r = r.substring(0, r.length - 1);
|
|
272
|
-
return e + r;
|
|
273
|
-
}
|
|
274
|
-
var m, f, a, N, y, w, p, C, z, $, P, L, G, _, J;
|
|
275
|
-
const I = class I {
|
|
276
|
-
// Use this when changing this file to get some typing info,
|
|
277
|
-
// but then switch to any to mask the internal type
|
|
278
|
-
//constructor(guard: any, value: bigint, format: _FixedFormat) {
|
|
279
|
-
/**
|
|
280
|
-
* @private
|
|
281
|
-
*/
|
|
282
|
-
constructor(t, e, r) {
|
|
283
|
-
b(this, N);
|
|
284
|
-
b(this, w);
|
|
285
|
-
b(this, C);
|
|
286
|
-
b(this, $);
|
|
287
|
-
b(this, L);
|
|
288
|
-
b(this, _);
|
|
289
|
-
/**
|
|
290
|
-
* The specific fixed-point arithmetic field for this value.
|
|
291
|
-
*/
|
|
292
|
-
k(this, "format");
|
|
293
|
-
b(this, m, void 0);
|
|
294
|
-
// The actual value (accounting for decimals)
|
|
295
|
-
b(this, f, void 0);
|
|
296
|
-
// A base-10 value to multiple values by to maintain the magnitude
|
|
297
|
-
b(this, a, void 0);
|
|
298
|
-
/**
|
|
299
|
-
* This is a property so console.log shows a human-meaningful value.
|
|
300
|
-
*
|
|
301
|
-
* @private
|
|
302
|
-
*/
|
|
303
|
-
k(this, "_value");
|
|
304
|
-
nt(t, B, "FixedNumber"), v(this, f, e), v(this, m, r);
|
|
305
|
-
const n = lt(e, r.decimals);
|
|
306
|
-
q(this, { format: r.name, _value: n }), v(this, a, U(r.decimals));
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* If true, negative values are permitted, otherwise only
|
|
310
|
-
* positive values and zero are allowed.
|
|
311
|
-
*/
|
|
312
|
-
get signed() {
|
|
313
|
-
return s(this, m).signed;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* The number of bits available to store the value.
|
|
317
|
-
*/
|
|
318
|
-
get width() {
|
|
319
|
-
return s(this, m).width;
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* The number of decimal places in the fixed-point arithment field.
|
|
323
|
-
*/
|
|
324
|
-
get decimals() {
|
|
325
|
-
return s(this, m).decimals;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* The value as an integer, based on the smallest unit the
|
|
329
|
-
* [[decimals]] allow.
|
|
330
|
-
*/
|
|
331
|
-
get value() {
|
|
332
|
-
return s(this, f);
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Returns a new [[FixedNumber]] with the result of %%this%% added
|
|
336
|
-
* to %%other%%, ignoring overflow.
|
|
337
|
-
*/
|
|
338
|
-
addUnsafe(t) {
|
|
339
|
-
return u(this, C, z).call(this, t);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Returns a new [[FixedNumber]] with the result of %%this%% added
|
|
343
|
-
* to %%other%%. A [[NumericFaultError]] is thrown if overflow
|
|
344
|
-
* occurs.
|
|
345
|
-
*/
|
|
346
|
-
add(t) {
|
|
347
|
-
return u(this, C, z).call(this, t, "add");
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Returns a new [[FixedNumber]] with the result of %%other%% subtracted
|
|
351
|
-
* from %%this%%, ignoring overflow.
|
|
352
|
-
*/
|
|
353
|
-
subUnsafe(t) {
|
|
354
|
-
return u(this, $, P).call(this, t);
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Returns a new [[FixedNumber]] with the result of %%other%% subtracted
|
|
358
|
-
* from %%this%%. A [[NumericFaultError]] is thrown if overflow
|
|
359
|
-
* occurs.
|
|
360
|
-
*/
|
|
361
|
-
sub(t) {
|
|
362
|
-
return u(this, $, P).call(this, t, "sub");
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Returns a new [[FixedNumber]] with the result of %%this%% multiplied
|
|
366
|
-
* by %%other%%, ignoring overflow and underflow (precision loss).
|
|
367
|
-
*/
|
|
368
|
-
mulUnsafe(t) {
|
|
369
|
-
return u(this, L, G).call(this, t);
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Returns a new [[FixedNumber]] with the result of %%this%% multiplied
|
|
373
|
-
* by %%other%%. A [[NumericFaultError]] is thrown if overflow
|
|
374
|
-
* occurs.
|
|
375
|
-
*/
|
|
376
|
-
mul(t) {
|
|
377
|
-
return u(this, L, G).call(this, t, "mul");
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Returns a new [[FixedNumber]] with the result of %%this%% multiplied
|
|
381
|
-
* by %%other%%. A [[NumericFaultError]] is thrown if overflow
|
|
382
|
-
* occurs or if underflow (precision loss) occurs.
|
|
383
|
-
*/
|
|
384
|
-
mulSignal(t) {
|
|
385
|
-
u(this, N, y).call(this, t);
|
|
386
|
-
const e = s(this, f) * s(t, f);
|
|
387
|
-
return g(e % s(this, a) === d, "precision lost during signalling mul", "NUMERIC_FAULT", {
|
|
388
|
-
operation: "mulSignal",
|
|
389
|
-
fault: "underflow",
|
|
390
|
-
value: this
|
|
391
|
-
}), u(this, w, p).call(this, e / s(this, a), "mulSignal");
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Returns a new [[FixedNumber]] with the result of %%this%% divided
|
|
395
|
-
* by %%other%%, ignoring underflow (precision loss). A
|
|
396
|
-
* [[NumericFaultError]] is thrown if overflow occurs.
|
|
397
|
-
*/
|
|
398
|
-
divUnsafe(t) {
|
|
399
|
-
return u(this, _, J).call(this, t);
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Returns a new [[FixedNumber]] with the result of %%this%% divided
|
|
403
|
-
* by %%other%%, ignoring underflow (precision loss). A
|
|
404
|
-
* [[NumericFaultError]] is thrown if overflow occurs.
|
|
405
|
-
*/
|
|
406
|
-
div(t) {
|
|
407
|
-
return u(this, _, J).call(this, t, "div");
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Returns a new [[FixedNumber]] with the result of %%this%% divided
|
|
411
|
-
* by %%other%%. A [[NumericFaultError]] is thrown if underflow
|
|
412
|
-
* (precision loss) occurs.
|
|
413
|
-
*/
|
|
414
|
-
divSignal(t) {
|
|
415
|
-
g(s(t, f) !== d, "division by zero", "NUMERIC_FAULT", {
|
|
416
|
-
operation: "div",
|
|
417
|
-
fault: "divide-by-zero",
|
|
418
|
-
value: this
|
|
419
|
-
}), u(this, N, y).call(this, t);
|
|
420
|
-
const e = s(this, f) * s(this, a);
|
|
421
|
-
return g(e % s(t, f) === d, "precision lost during signalling div", "NUMERIC_FAULT", {
|
|
422
|
-
operation: "divSignal",
|
|
423
|
-
fault: "underflow",
|
|
424
|
-
value: this
|
|
425
|
-
}), u(this, w, p).call(this, e / s(t, f), "divSignal");
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Returns a comparison result between %%this%% and %%other%%.
|
|
429
|
-
*
|
|
430
|
-
* This is suitable for use in sorting, where ``-1`` implies %%this%%
|
|
431
|
-
* is smaller, ``1`` implies %%this%% is larger and ``0`` implies
|
|
432
|
-
* both are equal.
|
|
433
|
-
*/
|
|
434
|
-
cmp(t) {
|
|
435
|
-
let e = this.value, r = t.value;
|
|
436
|
-
const n = this.decimals - t.decimals;
|
|
437
|
-
return n > 0 ? r *= U(n) : n < 0 && (e *= U(-n)), e < r ? -1 : e > r ? 1 : 0;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Returns true if %%other%% is equal to %%this%%.
|
|
441
|
-
*/
|
|
442
|
-
eq(t) {
|
|
443
|
-
return this.cmp(t) === 0;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Returns true if %%other%% is less than to %%this%%.
|
|
447
|
-
*/
|
|
448
|
-
lt(t) {
|
|
449
|
-
return this.cmp(t) < 0;
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Returns true if %%other%% is less than or equal to %%this%%.
|
|
453
|
-
*/
|
|
454
|
-
lte(t) {
|
|
455
|
-
return this.cmp(t) <= 0;
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Returns true if %%other%% is greater than to %%this%%.
|
|
459
|
-
*/
|
|
460
|
-
gt(t) {
|
|
461
|
-
return this.cmp(t) > 0;
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
|
-
* Returns true if %%other%% is greater than or equal to %%this%%.
|
|
465
|
-
*/
|
|
466
|
-
gte(t) {
|
|
467
|
-
return this.cmp(t) >= 0;
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Returns a new [[FixedNumber]] which is the largest **integer**
|
|
471
|
-
* that is less than or equal to %%this%%.
|
|
472
|
-
*
|
|
473
|
-
* The decimal component of the result will always be ``0``.
|
|
474
|
-
*/
|
|
475
|
-
floor() {
|
|
476
|
-
let t = s(this, f);
|
|
477
|
-
return s(this, f) < d && (t -= s(this, a) - S), t = s(this, f) / s(this, a) * s(this, a), u(this, w, p).call(this, t, "floor");
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Returns a new [[FixedNumber]] which is the smallest **integer**
|
|
481
|
-
* that is greater than or equal to %%this%%.
|
|
482
|
-
*
|
|
483
|
-
* The decimal component of the result will always be ``0``.
|
|
484
|
-
*/
|
|
485
|
-
ceiling() {
|
|
486
|
-
let t = s(this, f);
|
|
487
|
-
return s(this, f) > d && (t += s(this, a) - S), t = s(this, f) / s(this, a) * s(this, a), u(this, w, p).call(this, t, "ceiling");
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Returns a new [[FixedNumber]] with the decimal component
|
|
491
|
-
* rounded up on ties at %%decimals%% places.
|
|
492
|
-
*/
|
|
493
|
-
round(t) {
|
|
494
|
-
if (t == null && (t = 0), t >= this.decimals)
|
|
495
|
-
return this;
|
|
496
|
-
const e = this.decimals - t, r = ct * U(e - 1);
|
|
497
|
-
let n = this.value + r;
|
|
498
|
-
const o = U(e);
|
|
499
|
-
return n = n / o * o, R(n, s(this, m), "round"), new I(B, n, s(this, m));
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Returns true if %%this%% is equal to ``0``.
|
|
503
|
-
*/
|
|
504
|
-
isZero() {
|
|
505
|
-
return s(this, f) === d;
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* Returns true if %%this%% is less than ``0``.
|
|
509
|
-
*/
|
|
510
|
-
isNegative() {
|
|
511
|
-
return s(this, f) < d;
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Returns the string representation of %%this%%.
|
|
515
|
-
*/
|
|
516
|
-
toString() {
|
|
517
|
-
return this._value;
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Returns a float approximation.
|
|
521
|
-
*
|
|
522
|
-
* Due to IEEE 754 precission (or lack thereof), this function
|
|
523
|
-
* can only return an approximation and most values will contain
|
|
524
|
-
* rounding errors.
|
|
525
|
-
*/
|
|
526
|
-
toUnsafeFloat() {
|
|
527
|
-
return parseFloat(this.toString());
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* Return a new [[FixedNumber]] with the same value but has had
|
|
531
|
-
* its field set to %%format%%.
|
|
532
|
-
*
|
|
533
|
-
* This will throw if the value cannot fit into %%format%%.
|
|
534
|
-
*/
|
|
535
|
-
toFormat(t) {
|
|
536
|
-
return I.fromString(this.toString(), t);
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Creates a new [[FixedNumber]] for %%value%% divided by
|
|
540
|
-
* %%decimal%% places with %%format%%.
|
|
541
|
-
*
|
|
542
|
-
* This will throw a [[NumericFaultError]] if %%value%% (once adjusted
|
|
543
|
-
* for %%decimals%%) cannot fit in %%format%%, either due to overflow
|
|
544
|
-
* or underflow (precision loss).
|
|
545
|
-
*/
|
|
546
|
-
static fromValue(t, e, r) {
|
|
547
|
-
const n = e == null ? 0 : M(e), o = V(r);
|
|
548
|
-
let c = Z(t, "value");
|
|
549
|
-
const h = n - o.decimals;
|
|
550
|
-
if (h > 0) {
|
|
551
|
-
const T = U(h);
|
|
552
|
-
g(c % T === d, "value loses precision for format", "NUMERIC_FAULT", {
|
|
553
|
-
operation: "fromValue",
|
|
554
|
-
fault: "underflow",
|
|
555
|
-
value: t
|
|
556
|
-
}), c /= T;
|
|
557
|
-
} else
|
|
558
|
-
h < 0 && (c *= U(-h));
|
|
559
|
-
return R(c, o, "fromValue"), new I(B, c, o);
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Creates a new [[FixedNumber]] for %%value%% with %%format%%.
|
|
563
|
-
*
|
|
564
|
-
* This will throw a [[NumericFaultError]] if %%value%% cannot fit
|
|
565
|
-
* in %%format%%, either due to overflow or underflow (precision loss).
|
|
566
|
-
*/
|
|
567
|
-
static fromString(t, e) {
|
|
568
|
-
const r = t.match(/^(-?)([0-9]*)\.?([0-9]*)$/);
|
|
569
|
-
l(r && r[2].length + r[3].length > 0, "invalid FixedNumber string value", "value", t);
|
|
570
|
-
const n = V(e);
|
|
571
|
-
let o = r[2] || "0", c = r[3] || "";
|
|
572
|
-
for (; c.length < n.decimals; )
|
|
573
|
-
c += A;
|
|
574
|
-
g(c.substring(n.decimals).match(/^0*$/), "too many decimals for format", "NUMERIC_FAULT", {
|
|
575
|
-
operation: "fromString",
|
|
576
|
-
fault: "underflow",
|
|
577
|
-
value: t
|
|
578
|
-
}), c = c.substring(0, n.decimals);
|
|
579
|
-
const h = BigInt(r[1] + o + c);
|
|
580
|
-
return R(h, n, "fromString"), new I(B, h, n);
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Creates a new [[FixedNumber]] with the big-endian representation
|
|
584
|
-
* %%value%% with %%format%%.
|
|
585
|
-
*
|
|
586
|
-
* This will throw a [[NumericFaultError]] if %%value%% cannot fit
|
|
587
|
-
* in %%format%% due to overflow.
|
|
588
|
-
*/
|
|
589
|
-
static fromBytes(t, e) {
|
|
590
|
-
let r = ft(ot(t, "value"));
|
|
591
|
-
const n = V(e);
|
|
592
|
-
return n.signed && (r = D(r, n.width)), R(r, n, "fromBytes"), new I(B, r, n);
|
|
593
|
-
}
|
|
594
|
-
};
|
|
595
|
-
m = new WeakMap(), f = new WeakMap(), a = new WeakMap(), N = new WeakSet(), y = function(t) {
|
|
596
|
-
l(this.format === t.format, "incompatible format; use fixedNumber.toFormat", "other", t);
|
|
597
|
-
}, w = new WeakSet(), p = function(t, e) {
|
|
598
|
-
return t = R(t, s(this, m), e), new I(B, t, s(this, m));
|
|
599
|
-
}, C = new WeakSet(), z = function(t, e) {
|
|
600
|
-
return u(this, N, y).call(this, t), u(this, w, p).call(this, s(this, f) + s(t, f), e);
|
|
601
|
-
}, $ = new WeakSet(), P = function(t, e) {
|
|
602
|
-
return u(this, N, y).call(this, t), u(this, w, p).call(this, s(this, f) - s(t, f), e);
|
|
603
|
-
}, L = new WeakSet(), G = function(t, e) {
|
|
604
|
-
return u(this, N, y).call(this, t), u(this, w, p).call(this, s(this, f) * s(t, f) / s(this, a), e);
|
|
605
|
-
}, _ = new WeakSet(), J = function(t, e) {
|
|
606
|
-
return g(s(t, f) !== d, "division by zero", "NUMERIC_FAULT", {
|
|
607
|
-
operation: "div",
|
|
608
|
-
fault: "divide-by-zero",
|
|
609
|
-
value: this
|
|
610
|
-
}), u(this, N, y).call(this, t), u(this, w, p).call(this, s(this, f) * s(this, a) / s(t, f), e);
|
|
611
|
-
};
|
|
612
|
-
let j = I;
|
|
613
|
-
const at = [
|
|
614
|
-
"wei",
|
|
615
|
-
"kwei",
|
|
616
|
-
"mwei",
|
|
617
|
-
"gwei",
|
|
618
|
-
"szabo",
|
|
619
|
-
"finney",
|
|
620
|
-
"ether"
|
|
621
|
-
];
|
|
622
|
-
function dt(i, t) {
|
|
623
|
-
l(typeof i == "string", "value must be a string", "value", i);
|
|
624
|
-
let e = 18;
|
|
625
|
-
if (typeof t == "string") {
|
|
626
|
-
const r = at.indexOf(t);
|
|
627
|
-
l(r >= 0, "invalid unit", "unit", t), e = 3 * r;
|
|
628
|
-
} else
|
|
629
|
-
t != null && (e = M(t, "unit"));
|
|
630
|
-
return j.fromString(i, { decimals: e, width: 512 }).value;
|
|
631
|
-
}
|
|
632
|
-
export {
|
|
633
|
-
j as FixedNumber,
|
|
634
|
-
g as assert,
|
|
635
|
-
l as assertArgument,
|
|
636
|
-
nt as assertPrivate,
|
|
637
|
-
q as defineProperties,
|
|
638
|
-
D as fromTwos,
|
|
639
|
-
Z as getBigInt,
|
|
640
|
-
ot as getBytes,
|
|
641
|
-
M as getNumber,
|
|
642
|
-
Q as getUint,
|
|
643
|
-
gt as isHexString,
|
|
644
|
-
rt as makeError,
|
|
645
|
-
H as mask,
|
|
646
|
-
dt as parseUnits,
|
|
647
|
-
ft as toBigInt,
|
|
648
|
-
it as version
|
|
649
|
-
};
|