@injectivelabs/wallet-base 1.16.38-alpha.7 → 1.16.39-alpha.0

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/esm/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { WalletErrorActionModule } from "@injectivelabs/exceptions";
2
- import "@bangjelkoski/store2";
3
- import "http-status-codes";
2
+ import { getStdFee, toBigNumber } from "@injectivelabs/utils";
4
3
  import * as viemChains from "viem/chains";
5
4
  import { injective } from "viem/chains";
6
5
  import { EvmChainId } from "@injectivelabs/ts-types";
@@ -68,1281 +67,6 @@ const TurnkeyProvider = {
68
67
  Apple: "apple"
69
68
  };
70
69
 
71
- //#endregion
72
- //#region ../../../node_modules/.pnpm/bignumber.js@9.3.1/node_modules/bignumber.js/bignumber.mjs
73
- var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i, mathceil = Math.ceil, mathfloor = Math.floor, bignumberError = "[BigNumber Error] ", tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ", BASE = 0x5af3107a4000, LOG_BASE = 14, MAX_SAFE_INTEGER = 9007199254740991, POWS_TEN = [
74
- 1,
75
- 10,
76
- 100,
77
- 1e3,
78
- 1e4,
79
- 1e5,
80
- 1e6,
81
- 1e7,
82
- 1e8,
83
- 1e9,
84
- 1e10,
85
- 1e11,
86
- 0xe8d4a51000,
87
- 0x9184e72a000
88
- ], SQRT_BASE = 1e7, MAX = 1e9;
89
- function clone(configObject) {
90
- var div, convertBase, parseNumeric, P = BigNumber$1.prototype = {
91
- constructor: BigNumber$1,
92
- toString: null,
93
- valueOf: null
94
- }, ONE = new BigNumber$1(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
95
- prefix: "",
96
- groupSize: 3,
97
- secondaryGroupSize: 0,
98
- groupSeparator: ",",
99
- decimalSeparator: ".",
100
- fractionGroupSize: 0,
101
- fractionGroupSeparator: "\xA0",
102
- suffix: ""
103
- }, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
104
- function BigNumber$1(v, b) {
105
- var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
106
- if (!(x instanceof BigNumber$1)) return new BigNumber$1(v, b);
107
- if (b == null) {
108
- if (v && v._isBigNumber === true) {
109
- x.s = v.s;
110
- if (!v.c || v.e > MAX_EXP) x.c = x.e = null;
111
- else if (v.e < MIN_EXP) x.c = [x.e = 0];
112
- else {
113
- x.e = v.e;
114
- x.c = v.c.slice();
115
- }
116
- return;
117
- }
118
- if ((isNum = typeof v == "number") && v * 0 == 0) {
119
- x.s = 1 / v < 0 ? (v = -v, -1) : 1;
120
- if (v === ~~v) {
121
- for (e = 0, i = v; i >= 10; i /= 10, e++);
122
- if (e > MAX_EXP) x.c = x.e = null;
123
- else {
124
- x.e = e;
125
- x.c = [v];
126
- }
127
- return;
128
- }
129
- str = String(v);
130
- } else {
131
- if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
132
- x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
133
- }
134
- if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
135
- if ((i = str.search(/e/i)) > 0) {
136
- if (e < 0) e = i;
137
- e += +str.slice(i + 1);
138
- str = str.substring(0, i);
139
- } else if (e < 0) e = str.length;
140
- } else {
141
- intCheck(b, 2, ALPHABET.length, "Base");
142
- if (b == 10 && alphabetHasNormalDecimalDigits) {
143
- x = new BigNumber$1(v);
144
- return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
145
- }
146
- str = String(v);
147
- if (isNum = typeof v == "number") {
148
- if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
149
- x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
150
- if (BigNumber$1.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) throw Error(tooManyDigits + v);
151
- } else x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
152
- alphabet = ALPHABET.slice(0, b);
153
- e = i = 0;
154
- for (len = str.length; i < len; i++) if (alphabet.indexOf(c = str.charAt(i)) < 0) {
155
- if (c == ".") {
156
- if (i > e) {
157
- e = len;
158
- continue;
159
- }
160
- } else if (!caseChanged) {
161
- if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
162
- caseChanged = true;
163
- i = -1;
164
- e = 0;
165
- continue;
166
- }
167
- }
168
- return parseNumeric(x, String(v), isNum, b);
169
- }
170
- isNum = false;
171
- str = convertBase(str, b, 10, x.s);
172
- if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
173
- else e = str.length;
174
- }
175
- for (i = 0; str.charCodeAt(i) === 48; i++);
176
- for (len = str.length; str.charCodeAt(--len) === 48;);
177
- if (str = str.slice(i, ++len)) {
178
- len -= i;
179
- if (isNum && BigNumber$1.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) throw Error(tooManyDigits + x.s * v);
180
- if ((e = e - i - 1) > MAX_EXP) x.c = x.e = null;
181
- else if (e < MIN_EXP) x.c = [x.e = 0];
182
- else {
183
- x.e = e;
184
- x.c = [];
185
- i = (e + 1) % LOG_BASE;
186
- if (e < 0) i += LOG_BASE;
187
- if (i < len) {
188
- if (i) x.c.push(+str.slice(0, i));
189
- for (len -= LOG_BASE; i < len;) x.c.push(+str.slice(i, i += LOG_BASE));
190
- i = LOG_BASE - (str = str.slice(i)).length;
191
- } else i -= len;
192
- for (; i--; str += "0");
193
- x.c.push(+str);
194
- }
195
- } else x.c = [x.e = 0];
196
- }
197
- BigNumber$1.clone = clone;
198
- BigNumber$1.ROUND_UP = 0;
199
- BigNumber$1.ROUND_DOWN = 1;
200
- BigNumber$1.ROUND_CEIL = 2;
201
- BigNumber$1.ROUND_FLOOR = 3;
202
- BigNumber$1.ROUND_HALF_UP = 4;
203
- BigNumber$1.ROUND_HALF_DOWN = 5;
204
- BigNumber$1.ROUND_HALF_EVEN = 6;
205
- BigNumber$1.ROUND_HALF_CEIL = 7;
206
- BigNumber$1.ROUND_HALF_FLOOR = 8;
207
- BigNumber$1.EUCLID = 9;
208
- BigNumber$1.config = BigNumber$1.set = function(obj) {
209
- var p, v;
210
- if (obj != null) if (typeof obj == "object") {
211
- if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
212
- v = obj[p];
213
- intCheck(v, 0, MAX, p);
214
- DECIMAL_PLACES = v;
215
- }
216
- if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
217
- v = obj[p];
218
- intCheck(v, 0, 8, p);
219
- ROUNDING_MODE = v;
220
- }
221
- if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
222
- v = obj[p];
223
- if (v && v.pop) {
224
- intCheck(v[0], -MAX, 0, p);
225
- intCheck(v[1], 0, MAX, p);
226
- TO_EXP_NEG = v[0];
227
- TO_EXP_POS = v[1];
228
- } else {
229
- intCheck(v, -MAX, MAX, p);
230
- TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
231
- }
232
- }
233
- if (obj.hasOwnProperty(p = "RANGE")) {
234
- v = obj[p];
235
- if (v && v.pop) {
236
- intCheck(v[0], -MAX, -1, p);
237
- intCheck(v[1], 1, MAX, p);
238
- MIN_EXP = v[0];
239
- MAX_EXP = v[1];
240
- } else {
241
- intCheck(v, -MAX, MAX, p);
242
- if (v) MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
243
- else throw Error(bignumberError + p + " cannot be zero: " + v);
244
- }
245
- }
246
- if (obj.hasOwnProperty(p = "CRYPTO")) {
247
- v = obj[p];
248
- if (v === !!v) if (v) if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) CRYPTO = v;
249
- else {
250
- CRYPTO = !v;
251
- throw Error(bignumberError + "crypto unavailable");
252
- }
253
- else CRYPTO = v;
254
- else throw Error(bignumberError + p + " not true or false: " + v);
255
- }
256
- if (obj.hasOwnProperty(p = "MODULO_MODE")) {
257
- v = obj[p];
258
- intCheck(v, 0, 9, p);
259
- MODULO_MODE = v;
260
- }
261
- if (obj.hasOwnProperty(p = "POW_PRECISION")) {
262
- v = obj[p];
263
- intCheck(v, 0, MAX, p);
264
- POW_PRECISION = v;
265
- }
266
- if (obj.hasOwnProperty(p = "FORMAT")) {
267
- v = obj[p];
268
- if (typeof v == "object") FORMAT = v;
269
- else throw Error(bignumberError + p + " not an object: " + v);
270
- }
271
- if (obj.hasOwnProperty(p = "ALPHABET")) {
272
- v = obj[p];
273
- if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
274
- alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
275
- ALPHABET = v;
276
- } else throw Error(bignumberError + p + " invalid: " + v);
277
- }
278
- } else throw Error(bignumberError + "Object expected: " + obj);
279
- return {
280
- DECIMAL_PLACES,
281
- ROUNDING_MODE,
282
- EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
283
- RANGE: [MIN_EXP, MAX_EXP],
284
- CRYPTO,
285
- MODULO_MODE,
286
- POW_PRECISION,
287
- FORMAT,
288
- ALPHABET
289
- };
290
- };
291
- BigNumber$1.isBigNumber = function(v) {
292
- if (!v || v._isBigNumber !== true) return false;
293
- if (!BigNumber$1.DEBUG) return true;
294
- var i, n, c = v.c, e = v.e, s = v.s;
295
- out: if ({}.toString.call(c) == "[object Array]") {
296
- if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
297
- if (c[0] === 0) {
298
- if (e === 0 && c.length === 1) return true;
299
- break out;
300
- }
301
- i = (e + 1) % LOG_BASE;
302
- if (i < 1) i += LOG_BASE;
303
- if (String(c[0]).length == i) {
304
- for (i = 0; i < c.length; i++) {
305
- n = c[i];
306
- if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
307
- }
308
- if (n !== 0) return true;
309
- }
310
- }
311
- } else if (c === null && e === null && (s === null || s === 1 || s === -1)) return true;
312
- throw Error(bignumberError + "Invalid BigNumber: " + v);
313
- };
314
- BigNumber$1.maximum = BigNumber$1.max = function() {
315
- return maxOrMin(arguments, -1);
316
- };
317
- BigNumber$1.minimum = BigNumber$1.min = function() {
318
- return maxOrMin(arguments, 1);
319
- };
320
- BigNumber$1.random = (function() {
321
- var pow2_53 = 9007199254740992;
322
- var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
323
- return mathfloor(Math.random() * pow2_53);
324
- } : function() {
325
- return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
326
- };
327
- return function(dp) {
328
- var a, b, e, k, v, i = 0, c = [], rand = new BigNumber$1(ONE);
329
- if (dp == null) dp = DECIMAL_PLACES;
330
- else intCheck(dp, 0, MAX);
331
- k = mathceil(dp / LOG_BASE);
332
- if (CRYPTO) if (crypto.getRandomValues) {
333
- a = crypto.getRandomValues(new Uint32Array(k *= 2));
334
- for (; i < k;) {
335
- v = a[i] * 131072 + (a[i + 1] >>> 11);
336
- if (v >= 9e15) {
337
- b = crypto.getRandomValues(new Uint32Array(2));
338
- a[i] = b[0];
339
- a[i + 1] = b[1];
340
- } else {
341
- c.push(v % 0x5af3107a4000);
342
- i += 2;
343
- }
344
- }
345
- i = k / 2;
346
- } else if (crypto.randomBytes) {
347
- a = crypto.randomBytes(k *= 7);
348
- for (; i < k;) {
349
- v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
350
- if (v >= 9e15) crypto.randomBytes(7).copy(a, i);
351
- else {
352
- c.push(v % 0x5af3107a4000);
353
- i += 7;
354
- }
355
- }
356
- i = k / 7;
357
- } else {
358
- CRYPTO = false;
359
- throw Error(bignumberError + "crypto unavailable");
360
- }
361
- if (!CRYPTO) for (; i < k;) {
362
- v = random53bitInt();
363
- if (v < 9e15) c[i++] = v % 0x5af3107a4000;
364
- }
365
- k = c[--i];
366
- dp %= LOG_BASE;
367
- if (k && dp) {
368
- v = POWS_TEN[LOG_BASE - dp];
369
- c[i] = mathfloor(k / v) * v;
370
- }
371
- for (; c[i] === 0; c.pop(), i--);
372
- if (i < 0) c = [e = 0];
373
- else {
374
- for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);
375
- for (i = 1, v = c[0]; v >= 10; v /= 10, i++);
376
- if (i < LOG_BASE) e -= LOG_BASE - i;
377
- }
378
- rand.e = e;
379
- rand.c = c;
380
- return rand;
381
- };
382
- })();
383
- BigNumber$1.sum = function() {
384
- var i = 1, args = arguments, sum = new BigNumber$1(args[0]);
385
- for (; i < args.length;) sum = sum.plus(args[i++]);
386
- return sum;
387
- };
388
- convertBase = (function() {
389
- var decimal = "0123456789";
390
- function toBaseOut(str, baseIn, baseOut, alphabet) {
391
- var j, arr = [0], arrL, i = 0, len = str.length;
392
- for (; i < len;) {
393
- for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);
394
- arr[0] += alphabet.indexOf(str.charAt(i++));
395
- for (j = 0; j < arr.length; j++) if (arr[j] > baseOut - 1) {
396
- if (arr[j + 1] == null) arr[j + 1] = 0;
397
- arr[j + 1] += arr[j] / baseOut | 0;
398
- arr[j] %= baseOut;
399
- }
400
- }
401
- return arr.reverse();
402
- }
403
- return function(str, baseIn, baseOut, sign, callerIsToString) {
404
- var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
405
- if (i >= 0) {
406
- k = POW_PRECISION;
407
- POW_PRECISION = 0;
408
- str = str.replace(".", "");
409
- y = new BigNumber$1(baseIn);
410
- x = y.pow(str.length - i);
411
- POW_PRECISION = k;
412
- y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, "0"), 10, baseOut, decimal);
413
- y.e = y.c.length;
414
- }
415
- xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
416
- e = k = xc.length;
417
- for (; xc[--k] == 0; xc.pop());
418
- if (!xc[0]) return alphabet.charAt(0);
419
- if (i < 0) --e;
420
- else {
421
- x.c = xc;
422
- x.e = e;
423
- x.s = sign;
424
- x = div(x, y, dp, rm, baseOut);
425
- xc = x.c;
426
- r = x.r;
427
- e = x.e;
428
- }
429
- d = e + dp + 1;
430
- i = xc[d];
431
- k = baseOut / 2;
432
- r = r || d < 0 || xc[d + 1] != null;
433
- r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
434
- if (d < 1 || !xc[0]) str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
435
- else {
436
- xc.length = d;
437
- if (r) for (--baseOut; ++xc[--d] > baseOut;) {
438
- xc[d] = 0;
439
- if (!d) {
440
- ++e;
441
- xc = [1].concat(xc);
442
- }
443
- }
444
- for (k = xc.length; !xc[--k];);
445
- for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++]));
446
- str = toFixedPoint(str, e, alphabet.charAt(0));
447
- }
448
- return str;
449
- };
450
- })();
451
- div = (function() {
452
- function multiply(x, k, base) {
453
- var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
454
- for (x = x.slice(); i--;) {
455
- xlo = x[i] % SQRT_BASE;
456
- xhi = x[i] / SQRT_BASE | 0;
457
- m = khi * xlo + xhi * klo;
458
- temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
459
- carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
460
- x[i] = temp % base;
461
- }
462
- if (carry) x = [carry].concat(x);
463
- return x;
464
- }
465
- function compare$1(a, b, aL, bL) {
466
- var i, cmp;
467
- if (aL != bL) cmp = aL > bL ? 1 : -1;
468
- else for (i = cmp = 0; i < aL; i++) if (a[i] != b[i]) {
469
- cmp = a[i] > b[i] ? 1 : -1;
470
- break;
471
- }
472
- return cmp;
473
- }
474
- function subtract(a, b, aL, base) {
475
- var i = 0;
476
- for (; aL--;) {
477
- a[aL] -= i;
478
- i = a[aL] < b[aL] ? 1 : 0;
479
- a[aL] = i * base + a[aL] - b[aL];
480
- }
481
- for (; !a[0] && a.length > 1; a.splice(0, 1));
482
- }
483
- return function(x, y, dp, rm, base) {
484
- var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
485
- if (!xc || !xc[0] || !yc || !yc[0]) return new BigNumber$1(!x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : xc && xc[0] == 0 || !yc ? s * 0 : s / 0);
486
- q = new BigNumber$1(s);
487
- qc = q.c = [];
488
- e = x.e - y.e;
489
- s = dp + e + 1;
490
- if (!base) {
491
- base = BASE;
492
- e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
493
- s = s / LOG_BASE | 0;
494
- }
495
- for (i = 0; yc[i] == (xc[i] || 0); i++);
496
- if (yc[i] > (xc[i] || 0)) e--;
497
- if (s < 0) {
498
- qc.push(1);
499
- more = true;
500
- } else {
501
- xL = xc.length;
502
- yL = yc.length;
503
- i = 0;
504
- s += 2;
505
- n = mathfloor(base / (yc[0] + 1));
506
- if (n > 1) {
507
- yc = multiply(yc, n, base);
508
- xc = multiply(xc, n, base);
509
- yL = yc.length;
510
- xL = xc.length;
511
- }
512
- xi = yL;
513
- rem = xc.slice(0, yL);
514
- remL = rem.length;
515
- for (; remL < yL; rem[remL++] = 0);
516
- yz = yc.slice();
517
- yz = [0].concat(yz);
518
- yc0 = yc[0];
519
- if (yc[1] >= base / 2) yc0++;
520
- do {
521
- n = 0;
522
- cmp = compare$1(yc, rem, yL, remL);
523
- if (cmp < 0) {
524
- rem0 = rem[0];
525
- if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
526
- n = mathfloor(rem0 / yc0);
527
- if (n > 1) {
528
- if (n >= base) n = base - 1;
529
- prod = multiply(yc, n, base);
530
- prodL = prod.length;
531
- remL = rem.length;
532
- while (compare$1(prod, rem, prodL, remL) == 1) {
533
- n--;
534
- subtract(prod, yL < prodL ? yz : yc, prodL, base);
535
- prodL = prod.length;
536
- cmp = 1;
537
- }
538
- } else {
539
- if (n == 0) cmp = n = 1;
540
- prod = yc.slice();
541
- prodL = prod.length;
542
- }
543
- if (prodL < remL) prod = [0].concat(prod);
544
- subtract(rem, prod, remL, base);
545
- remL = rem.length;
546
- if (cmp == -1) while (compare$1(yc, rem, yL, remL) < 1) {
547
- n++;
548
- subtract(rem, yL < remL ? yz : yc, remL, base);
549
- remL = rem.length;
550
- }
551
- } else if (cmp === 0) {
552
- n++;
553
- rem = [0];
554
- }
555
- qc[i++] = n;
556
- if (rem[0]) rem[remL++] = xc[xi] || 0;
557
- else {
558
- rem = [xc[xi]];
559
- remL = 1;
560
- }
561
- } while ((xi++ < xL || rem[0] != null) && s--);
562
- more = rem[0] != null;
563
- if (!qc[0]) qc.splice(0, 1);
564
- }
565
- if (base == BASE) {
566
- for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);
567
- round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
568
- } else {
569
- q.e = e;
570
- q.r = +more;
571
- }
572
- return q;
573
- };
574
- })();
575
- function format(n, i, rm, id) {
576
- var c0, e, ne, len, str;
577
- if (rm == null) rm = ROUNDING_MODE;
578
- else intCheck(rm, 0, 8);
579
- if (!n.c) return n.toString();
580
- c0 = n.c[0];
581
- ne = n.e;
582
- if (i == null) {
583
- str = coeffToString(n.c);
584
- str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
585
- } else {
586
- n = round(new BigNumber$1(n), i, rm);
587
- e = n.e;
588
- str = coeffToString(n.c);
589
- len = str.length;
590
- if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
591
- for (; len < i; str += "0", len++);
592
- str = toExponential(str, e);
593
- } else {
594
- i -= ne + (id === 2 && e > ne);
595
- str = toFixedPoint(str, e, "0");
596
- if (e + 1 > len) {
597
- if (--i > 0) for (str += "."; i--; str += "0");
598
- } else {
599
- i += e - len;
600
- if (i > 0) {
601
- if (e + 1 == len) str += ".";
602
- for (; i--; str += "0");
603
- }
604
- }
605
- }
606
- }
607
- return n.s < 0 && c0 ? "-" + str : str;
608
- }
609
- function maxOrMin(args, n) {
610
- var k, y, i = 1, x = new BigNumber$1(args[0]);
611
- for (; i < args.length; i++) {
612
- y = new BigNumber$1(args[i]);
613
- if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) x = y;
614
- }
615
- return x;
616
- }
617
- function normalise(n, c, e) {
618
- var i = 1, j = c.length;
619
- for (; !c[--j]; c.pop());
620
- for (j = c[0]; j >= 10; j /= 10, i++);
621
- if ((e = i + e * LOG_BASE - 1) > MAX_EXP) n.c = n.e = null;
622
- else if (e < MIN_EXP) n.c = [n.e = 0];
623
- else {
624
- n.e = e;
625
- n.c = c;
626
- }
627
- return n;
628
- }
629
- parseNumeric = (function() {
630
- var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
631
- return function(x, str, isNum, b) {
632
- var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
633
- if (isInfinityOrNaN.test(s)) x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
634
- else {
635
- if (!isNum) {
636
- s = s.replace(basePrefix, function(m, p1, p2) {
637
- base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
638
- return !b || b == base ? p1 : m;
639
- });
640
- if (b) {
641
- base = b;
642
- s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
643
- }
644
- if (str != s) return new BigNumber$1(s, base);
645
- }
646
- if (BigNumber$1.DEBUG) throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
647
- x.s = null;
648
- }
649
- x.c = x.e = null;
650
- };
651
- })();
652
- function round(x, sd, rm, r) {
653
- var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
654
- if (xc) {
655
- out: {
656
- for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);
657
- i = sd - d;
658
- if (i < 0) {
659
- i += LOG_BASE;
660
- j = sd;
661
- n = xc[ni = 0];
662
- rd = mathfloor(n / pows10[d - j - 1] % 10);
663
- } else {
664
- ni = mathceil((i + 1) / LOG_BASE);
665
- if (ni >= xc.length) if (r) {
666
- for (; xc.length <= ni; xc.push(0));
667
- n = rd = 0;
668
- d = 1;
669
- i %= LOG_BASE;
670
- j = i - LOG_BASE + 1;
671
- } else break out;
672
- else {
673
- n = k = xc[ni];
674
- for (d = 1; k >= 10; k /= 10, d++);
675
- i %= LOG_BASE;
676
- j = i - LOG_BASE + d;
677
- rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
678
- }
679
- }
680
- r = r || sd < 0 || xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
681
- r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
682
- if (sd < 1 || !xc[0]) {
683
- xc.length = 0;
684
- if (r) {
685
- sd -= x.e + 1;
686
- xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
687
- x.e = -sd || 0;
688
- } else xc[0] = x.e = 0;
689
- return x;
690
- }
691
- if (i == 0) {
692
- xc.length = ni;
693
- k = 1;
694
- ni--;
695
- } else {
696
- xc.length = ni + 1;
697
- k = pows10[LOG_BASE - i];
698
- xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
699
- }
700
- if (r) for (;;) if (ni == 0) {
701
- for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);
702
- j = xc[0] += k;
703
- for (k = 1; j >= 10; j /= 10, k++);
704
- if (i != k) {
705
- x.e++;
706
- if (xc[0] == BASE) xc[0] = 1;
707
- }
708
- break;
709
- } else {
710
- xc[ni] += k;
711
- if (xc[ni] != BASE) break;
712
- xc[ni--] = 0;
713
- k = 1;
714
- }
715
- for (i = xc.length; xc[--i] === 0; xc.pop());
716
- }
717
- if (x.e > MAX_EXP) x.c = x.e = null;
718
- else if (x.e < MIN_EXP) x.c = [x.e = 0];
719
- }
720
- return x;
721
- }
722
- function valueOf(n) {
723
- var str, e = n.e;
724
- if (e === null) return n.toString();
725
- str = coeffToString(n.c);
726
- str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
727
- return n.s < 0 ? "-" + str : str;
728
- }
729
- P.absoluteValue = P.abs = function() {
730
- var x = new BigNumber$1(this);
731
- if (x.s < 0) x.s = 1;
732
- return x;
733
- };
734
- P.comparedTo = function(y, b) {
735
- return compare(this, new BigNumber$1(y, b));
736
- };
737
- P.decimalPlaces = P.dp = function(dp, rm) {
738
- var c, n, v, x = this;
739
- if (dp != null) {
740
- intCheck(dp, 0, MAX);
741
- if (rm == null) rm = ROUNDING_MODE;
742
- else intCheck(rm, 0, 8);
743
- return round(new BigNumber$1(x), dp + x.e + 1, rm);
744
- }
745
- if (!(c = x.c)) return null;
746
- n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
747
- if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);
748
- if (n < 0) n = 0;
749
- return n;
750
- };
751
- P.dividedBy = P.div = function(y, b) {
752
- return div(this, new BigNumber$1(y, b), DECIMAL_PLACES, ROUNDING_MODE);
753
- };
754
- P.dividedToIntegerBy = P.idiv = function(y, b) {
755
- return div(this, new BigNumber$1(y, b), 0, 1);
756
- };
757
- P.exponentiatedBy = P.pow = function(n, m) {
758
- var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
759
- n = new BigNumber$1(n);
760
- if (n.c && !n.isInteger()) throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
761
- if (m != null) m = new BigNumber$1(m);
762
- nIsBig = n.e > 14;
763
- if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
764
- y = new BigNumber$1(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
765
- return m ? y.mod(m) : y;
766
- }
767
- nIsNeg = n.s < 0;
768
- if (m) {
769
- if (m.c ? !m.c[0] : !m.s) return new BigNumber$1(NaN);
770
- isModExp = !nIsNeg && x.isInteger() && m.isInteger();
771
- if (isModExp) x = x.mod(m);
772
- } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
773
- k = x.s < 0 && isOdd(n) ? -0 : 0;
774
- if (x.e > -1) k = 1 / k;
775
- return new BigNumber$1(nIsNeg ? 1 / k : k);
776
- } else if (POW_PRECISION) k = mathceil(POW_PRECISION / LOG_BASE + 2);
777
- if (nIsBig) {
778
- half = new BigNumber$1(.5);
779
- if (nIsNeg) n.s = 1;
780
- nIsOdd = isOdd(n);
781
- } else {
782
- i = Math.abs(+valueOf(n));
783
- nIsOdd = i % 2;
784
- }
785
- y = new BigNumber$1(ONE);
786
- for (;;) {
787
- if (nIsOdd) {
788
- y = y.times(x);
789
- if (!y.c) break;
790
- if (k) {
791
- if (y.c.length > k) y.c.length = k;
792
- } else if (isModExp) y = y.mod(m);
793
- }
794
- if (i) {
795
- i = mathfloor(i / 2);
796
- if (i === 0) break;
797
- nIsOdd = i % 2;
798
- } else {
799
- n = n.times(half);
800
- round(n, n.e + 1, 1);
801
- if (n.e > 14) nIsOdd = isOdd(n);
802
- else {
803
- i = +valueOf(n);
804
- if (i === 0) break;
805
- nIsOdd = i % 2;
806
- }
807
- }
808
- x = x.times(x);
809
- if (k) {
810
- if (x.c && x.c.length > k) x.c.length = k;
811
- } else if (isModExp) x = x.mod(m);
812
- }
813
- if (isModExp) return y;
814
- if (nIsNeg) y = ONE.div(y);
815
- return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
816
- };
817
- P.integerValue = function(rm) {
818
- var n = new BigNumber$1(this);
819
- if (rm == null) rm = ROUNDING_MODE;
820
- else intCheck(rm, 0, 8);
821
- return round(n, n.e + 1, rm);
822
- };
823
- P.isEqualTo = P.eq = function(y, b) {
824
- return compare(this, new BigNumber$1(y, b)) === 0;
825
- };
826
- P.isFinite = function() {
827
- return !!this.c;
828
- };
829
- P.isGreaterThan = P.gt = function(y, b) {
830
- return compare(this, new BigNumber$1(y, b)) > 0;
831
- };
832
- P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
833
- return (b = compare(this, new BigNumber$1(y, b))) === 1 || b === 0;
834
- };
835
- P.isInteger = function() {
836
- return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
837
- };
838
- P.isLessThan = P.lt = function(y, b) {
839
- return compare(this, new BigNumber$1(y, b)) < 0;
840
- };
841
- P.isLessThanOrEqualTo = P.lte = function(y, b) {
842
- return (b = compare(this, new BigNumber$1(y, b))) === -1 || b === 0;
843
- };
844
- P.isNaN = function() {
845
- return !this.s;
846
- };
847
- P.isNegative = function() {
848
- return this.s < 0;
849
- };
850
- P.isPositive = function() {
851
- return this.s > 0;
852
- };
853
- P.isZero = function() {
854
- return !!this.c && this.c[0] == 0;
855
- };
856
- P.minus = function(y, b) {
857
- var i, j, t, xLTy, x = this, a = x.s;
858
- y = new BigNumber$1(y, b);
859
- b = y.s;
860
- if (!a || !b) return new BigNumber$1(NaN);
861
- if (a != b) {
862
- y.s = -b;
863
- return x.plus(y);
864
- }
865
- var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
866
- if (!xe || !ye) {
867
- if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber$1(yc ? x : NaN);
868
- if (!xc[0] || !yc[0]) return yc[0] ? (y.s = -b, y) : new BigNumber$1(xc[0] ? x : ROUNDING_MODE == 3 ? -0 : 0);
869
- }
870
- xe = bitFloor(xe);
871
- ye = bitFloor(ye);
872
- xc = xc.slice();
873
- if (a = xe - ye) {
874
- if (xLTy = a < 0) {
875
- a = -a;
876
- t = xc;
877
- } else {
878
- ye = xe;
879
- t = yc;
880
- }
881
- t.reverse();
882
- for (b = a; b--; t.push(0));
883
- t.reverse();
884
- } else {
885
- j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
886
- for (a = b = 0; b < j; b++) if (xc[b] != yc[b]) {
887
- xLTy = xc[b] < yc[b];
888
- break;
889
- }
890
- }
891
- if (xLTy) {
892
- t = xc;
893
- xc = yc;
894
- yc = t;
895
- y.s = -y.s;
896
- }
897
- b = (j = yc.length) - (i = xc.length);
898
- if (b > 0) for (; b--; xc[i++] = 0);
899
- b = BASE - 1;
900
- for (; j > a;) {
901
- if (xc[--j] < yc[j]) {
902
- for (i = j; i && !xc[--i]; xc[i] = b);
903
- --xc[i];
904
- xc[j] += BASE;
905
- }
906
- xc[j] -= yc[j];
907
- }
908
- for (; xc[0] == 0; xc.splice(0, 1), --ye);
909
- if (!xc[0]) {
910
- y.s = ROUNDING_MODE == 3 ? -1 : 1;
911
- y.c = [y.e = 0];
912
- return y;
913
- }
914
- return normalise(y, xc, ye);
915
- };
916
- P.modulo = P.mod = function(y, b) {
917
- var q, s, x = this;
918
- y = new BigNumber$1(y, b);
919
- if (!x.c || !y.s || y.c && !y.c[0]) return new BigNumber$1(NaN);
920
- else if (!y.c || x.c && !x.c[0]) return new BigNumber$1(x);
921
- if (MODULO_MODE == 9) {
922
- s = y.s;
923
- y.s = 1;
924
- q = div(x, y, 0, 3);
925
- y.s = s;
926
- q.s *= s;
927
- } else q = div(x, y, 0, MODULO_MODE);
928
- y = x.minus(q.times(y));
929
- if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
930
- return y;
931
- };
932
- P.multipliedBy = P.times = function(y, b) {
933
- var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber$1(y, b)).c;
934
- if (!xc || !yc || !xc[0] || !yc[0]) {
935
- if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) y.c = y.e = y.s = null;
936
- else {
937
- y.s *= x.s;
938
- if (!xc || !yc) y.c = y.e = null;
939
- else {
940
- y.c = [0];
941
- y.e = 0;
942
- }
943
- }
944
- return y;
945
- }
946
- e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
947
- y.s *= x.s;
948
- xcL = xc.length;
949
- ycL = yc.length;
950
- if (xcL < ycL) {
951
- zc = xc;
952
- xc = yc;
953
- yc = zc;
954
- i = xcL;
955
- xcL = ycL;
956
- ycL = i;
957
- }
958
- for (i = xcL + ycL, zc = []; i--; zc.push(0));
959
- base = BASE;
960
- sqrtBase = SQRT_BASE;
961
- for (i = ycL; --i >= 0;) {
962
- c = 0;
963
- ylo = yc[i] % sqrtBase;
964
- yhi = yc[i] / sqrtBase | 0;
965
- for (k = xcL, j = i + k; j > i;) {
966
- xlo = xc[--k] % sqrtBase;
967
- xhi = xc[k] / sqrtBase | 0;
968
- m = yhi * xlo + xhi * ylo;
969
- xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
970
- c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
971
- zc[j--] = xlo % base;
972
- }
973
- zc[j] = c;
974
- }
975
- if (c) ++e;
976
- else zc.splice(0, 1);
977
- return normalise(y, zc, e);
978
- };
979
- P.negated = function() {
980
- var x = new BigNumber$1(this);
981
- x.s = -x.s || null;
982
- return x;
983
- };
984
- P.plus = function(y, b) {
985
- var t, x = this, a = x.s;
986
- y = new BigNumber$1(y, b);
987
- b = y.s;
988
- if (!a || !b) return new BigNumber$1(NaN);
989
- if (a != b) {
990
- y.s = -b;
991
- return x.minus(y);
992
- }
993
- var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
994
- if (!xe || !ye) {
995
- if (!xc || !yc) return new BigNumber$1(a / 0);
996
- if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber$1(xc[0] ? x : a * 0);
997
- }
998
- xe = bitFloor(xe);
999
- ye = bitFloor(ye);
1000
- xc = xc.slice();
1001
- if (a = xe - ye) {
1002
- if (a > 0) {
1003
- ye = xe;
1004
- t = yc;
1005
- } else {
1006
- a = -a;
1007
- t = xc;
1008
- }
1009
- t.reverse();
1010
- for (; a--; t.push(0));
1011
- t.reverse();
1012
- }
1013
- a = xc.length;
1014
- b = yc.length;
1015
- if (a - b < 0) {
1016
- t = yc;
1017
- yc = xc;
1018
- xc = t;
1019
- b = a;
1020
- }
1021
- for (a = 0; b;) {
1022
- a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
1023
- xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
1024
- }
1025
- if (a) {
1026
- xc = [a].concat(xc);
1027
- ++ye;
1028
- }
1029
- return normalise(y, xc, ye);
1030
- };
1031
- P.precision = P.sd = function(sd, rm) {
1032
- var c, n, v, x = this;
1033
- if (sd != null && sd !== !!sd) {
1034
- intCheck(sd, 1, MAX);
1035
- if (rm == null) rm = ROUNDING_MODE;
1036
- else intCheck(rm, 0, 8);
1037
- return round(new BigNumber$1(x), sd, rm);
1038
- }
1039
- if (!(c = x.c)) return null;
1040
- v = c.length - 1;
1041
- n = v * LOG_BASE + 1;
1042
- if (v = c[v]) {
1043
- for (; v % 10 == 0; v /= 10, n--);
1044
- for (v = c[0]; v >= 10; v /= 10, n++);
1045
- }
1046
- if (sd && x.e + 1 > n) n = x.e + 1;
1047
- return n;
1048
- };
1049
- P.shiftedBy = function(k) {
1050
- intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
1051
- return this.times("1e" + k);
1052
- };
1053
- P.squareRoot = P.sqrt = function() {
1054
- var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber$1("0.5");
1055
- if (s !== 1 || !c || !c[0]) return new BigNumber$1(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : Infinity);
1056
- s = Math.sqrt(+valueOf(x));
1057
- if (s == 0 || s == Infinity) {
1058
- n = coeffToString(c);
1059
- if ((n.length + e) % 2 == 0) n += "0";
1060
- s = Math.sqrt(+n);
1061
- e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
1062
- if (s == Infinity) n = "5e" + e;
1063
- else {
1064
- n = s.toExponential();
1065
- n = n.slice(0, n.indexOf("e") + 1) + e;
1066
- }
1067
- r = new BigNumber$1(n);
1068
- } else r = new BigNumber$1(s + "");
1069
- if (r.c[0]) {
1070
- e = r.e;
1071
- s = e + dp;
1072
- if (s < 3) s = 0;
1073
- for (;;) {
1074
- t = r;
1075
- r = half.times(t.plus(div(x, t, dp, 1)));
1076
- if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
1077
- if (r.e < e) --s;
1078
- n = n.slice(s - 3, s + 1);
1079
- if (n == "9999" || !rep && n == "4999") {
1080
- if (!rep) {
1081
- round(t, t.e + DECIMAL_PLACES + 2, 0);
1082
- if (t.times(t).eq(x)) {
1083
- r = t;
1084
- break;
1085
- }
1086
- }
1087
- dp += 4;
1088
- s += 4;
1089
- rep = 1;
1090
- } else {
1091
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
1092
- round(r, r.e + DECIMAL_PLACES + 2, 1);
1093
- m = !r.times(r).eq(x);
1094
- }
1095
- break;
1096
- }
1097
- }
1098
- }
1099
- }
1100
- return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
1101
- };
1102
- P.toExponential = function(dp, rm) {
1103
- if (dp != null) {
1104
- intCheck(dp, 0, MAX);
1105
- dp++;
1106
- }
1107
- return format(this, dp, rm, 1);
1108
- };
1109
- P.toFixed = function(dp, rm) {
1110
- if (dp != null) {
1111
- intCheck(dp, 0, MAX);
1112
- dp = dp + this.e + 1;
1113
- }
1114
- return format(this, dp, rm);
1115
- };
1116
- P.toFormat = function(dp, rm, format$1) {
1117
- var str, x = this;
1118
- if (format$1 == null) if (dp != null && rm && typeof rm == "object") {
1119
- format$1 = rm;
1120
- rm = null;
1121
- } else if (dp && typeof dp == "object") {
1122
- format$1 = dp;
1123
- dp = rm = null;
1124
- } else format$1 = FORMAT;
1125
- else if (typeof format$1 != "object") throw Error(bignumberError + "Argument not an object: " + format$1);
1126
- str = x.toFixed(dp, rm);
1127
- if (x.c) {
1128
- var i, arr = str.split("."), g1 = +format$1.groupSize, g2 = +format$1.secondaryGroupSize, groupSeparator = format$1.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
1129
- if (g2) {
1130
- i = g1;
1131
- g1 = g2;
1132
- g2 = i;
1133
- len -= i;
1134
- }
1135
- if (g1 > 0 && len > 0) {
1136
- i = len % g1 || g1;
1137
- intPart = intDigits.substr(0, i);
1138
- for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
1139
- if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
1140
- if (isNeg) intPart = "-" + intPart;
1141
- }
1142
- str = fractionPart ? intPart + (format$1.decimalSeparator || "") + ((g2 = +format$1.fractionGroupSize) ? fractionPart.replace(new RegExp("\\d{" + g2 + "}\\B", "g"), "$&" + (format$1.fractionGroupSeparator || "")) : fractionPart) : intPart;
1143
- }
1144
- return (format$1.prefix || "") + str + (format$1.suffix || "");
1145
- };
1146
- P.toFraction = function(md) {
1147
- var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
1148
- if (md != null) {
1149
- n = new BigNumber$1(md);
1150
- if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
1151
- }
1152
- if (!xc) return new BigNumber$1(x);
1153
- d = new BigNumber$1(ONE);
1154
- n1 = d0 = new BigNumber$1(ONE);
1155
- d1 = n0 = new BigNumber$1(ONE);
1156
- s = coeffToString(xc);
1157
- e = d.e = s.length - x.e - 1;
1158
- d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
1159
- md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
1160
- exp = MAX_EXP;
1161
- MAX_EXP = Infinity;
1162
- n = new BigNumber$1(s);
1163
- n0.c[0] = 0;
1164
- for (;;) {
1165
- q = div(n, d, 0, 1);
1166
- d2 = d0.plus(q.times(d1));
1167
- if (d2.comparedTo(md) == 1) break;
1168
- d0 = d1;
1169
- d1 = d2;
1170
- n1 = n0.plus(q.times(d2 = n1));
1171
- n0 = d2;
1172
- d = n.minus(q.times(d2 = d));
1173
- n = d2;
1174
- }
1175
- d2 = div(md.minus(d0), d1, 0, 1);
1176
- n0 = n0.plus(d2.times(n1));
1177
- d0 = d0.plus(d2.times(d1));
1178
- n0.s = n1.s = x.s;
1179
- e = e * 2;
1180
- r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
1181
- MAX_EXP = exp;
1182
- return r;
1183
- };
1184
- P.toNumber = function() {
1185
- return +valueOf(this);
1186
- };
1187
- P.toPrecision = function(sd, rm) {
1188
- if (sd != null) intCheck(sd, 1, MAX);
1189
- return format(this, sd, rm, 2);
1190
- };
1191
- P.toString = function(b) {
1192
- var str, n = this, s = n.s, e = n.e;
1193
- if (e === null) if (s) {
1194
- str = "Infinity";
1195
- if (s < 0) str = "-" + str;
1196
- } else str = "NaN";
1197
- else {
1198
- if (b == null) str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
1199
- else if (b === 10 && alphabetHasNormalDecimalDigits) {
1200
- n = round(new BigNumber$1(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
1201
- str = toFixedPoint(coeffToString(n.c), n.e, "0");
1202
- } else {
1203
- intCheck(b, 2, ALPHABET.length, "Base");
1204
- str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
1205
- }
1206
- if (s < 0 && n.c[0]) str = "-" + str;
1207
- }
1208
- return str;
1209
- };
1210
- P.valueOf = P.toJSON = function() {
1211
- return valueOf(this);
1212
- };
1213
- P._isBigNumber = true;
1214
- P[Symbol.toStringTag] = "BigNumber";
1215
- P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
1216
- if (configObject != null) BigNumber$1.set(configObject);
1217
- return BigNumber$1;
1218
- }
1219
- function bitFloor(n) {
1220
- var i = n | 0;
1221
- return n > 0 || n === i ? i : i - 1;
1222
- }
1223
- function coeffToString(a) {
1224
- var s, z, i = 1, j = a.length, r = a[0] + "";
1225
- for (; i < j;) {
1226
- s = a[i++] + "";
1227
- z = LOG_BASE - s.length;
1228
- for (; z--; s = "0" + s);
1229
- r += s;
1230
- }
1231
- for (j = r.length; r.charCodeAt(--j) === 48;);
1232
- return r.slice(0, j + 1 || 1);
1233
- }
1234
- function compare(x, y) {
1235
- var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
1236
- if (!i || !j) return null;
1237
- a = xc && !xc[0];
1238
- b = yc && !yc[0];
1239
- if (a || b) return a ? b ? 0 : -j : i;
1240
- if (i != j) return i;
1241
- a = i < 0;
1242
- b = k == l;
1243
- if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
1244
- if (!b) return k > l ^ a ? 1 : -1;
1245
- j = (k = xc.length) < (l = yc.length) ? k : l;
1246
- for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
1247
- return k == l ? 0 : k > l ^ a ? 1 : -1;
1248
- }
1249
- function intCheck(n, min, max, name) {
1250
- if (n < min || n > max || n !== mathfloor(n)) throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
1251
- }
1252
- function isOdd(n) {
1253
- var k = n.c.length - 1;
1254
- return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
1255
- }
1256
- function toExponential(str, e) {
1257
- return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
1258
- }
1259
- function toFixedPoint(str, e, z) {
1260
- var len, zs;
1261
- if (e < 0) {
1262
- for (zs = z + "."; ++e; zs += z);
1263
- str = zs + str;
1264
- } else {
1265
- len = str.length;
1266
- if (++e > len) {
1267
- for (zs = z, e -= len; --e; zs += z);
1268
- str += zs;
1269
- } else if (e < len) str = str.slice(0, e) + "." + str.slice(e);
1270
- }
1271
- return str;
1272
- }
1273
- var BigNumber = clone();
1274
-
1275
- //#endregion
1276
- //#region ../../utils/dist/esm/constants-BxcSsKjm.js
1277
- var BigNumber_default = BigNumber;
1278
- /**
1279
- * Converts a value to BigNumber if it isn't already
1280
- */
1281
- const toBigNumber = (value) => {
1282
- if (value instanceof BigNumber) return value;
1283
- return new BigNumber(value);
1284
- };
1285
- /**
1286
- * Converts a value to Wei (multiplies by 10^decimals) default to 18 decimals
1287
- */
1288
- const toChainFormat = (value, decimals = 18) => {
1289
- return toBigNumber(value).multipliedBy(new BigNumber(10).pow(decimals));
1290
- };
1291
- const DEFAULT_GAS_LIMIT = 4e5;
1292
- const DEFAULT_GAS_PRICE = 16e7;
1293
- const DEFAULT_BLOCK_TIMEOUT_HEIGHT = 120;
1294
- const DEFAULT_BLOCK_TIME_IN_SECONDS = .7;
1295
- /**
1296
- * Default timeout for transaction block inclusion polling.
1297
- *
1298
- * Calculation: 120 blocks × 0.7 seconds/block = 84 seconds = 84,000ms
1299
- */
1300
- const DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS = Math.floor(DEFAULT_BLOCK_TIMEOUT_HEIGHT * DEFAULT_BLOCK_TIME_IN_SECONDS * 1e3);
1301
- const DEFAULT_TIMESTAMP_TIMEOUT_MS = 60 * 1e3 * 3;
1302
- const getDefaultStdFee = () => ({
1303
- amount: [{
1304
- amount: new BigNumber_default(DEFAULT_GAS_LIMIT).times(DEFAULT_GAS_PRICE).toString(),
1305
- denom: "inj"
1306
- }],
1307
- gas: DEFAULT_GAS_LIMIT.toString(),
1308
- payer: "",
1309
- granter: "",
1310
- feePayer: ""
1311
- });
1312
-
1313
- //#endregion
1314
- //#region ../../utils/dist/esm/index.js
1315
- const getStdFeeFromObject = (args) => {
1316
- if (!args) return getDefaultStdFee();
1317
- const { payer, granter, feePayer, gasPrice = DEFAULT_GAS_PRICE, gas = DEFAULT_GAS_LIMIT.toString() } = args;
1318
- const gasNormalized = toBigNumber(gas).toFixed(0);
1319
- const gasPriceNormalized = toBigNumber(gasPrice).toFixed(0);
1320
- return {
1321
- amount: [{
1322
- denom: "inj",
1323
- amount: toBigNumber(gasNormalized).times(gasPriceNormalized).toFixed()
1324
- }],
1325
- gas: toBigNumber(gasNormalized).toFixed(),
1326
- payer,
1327
- granter,
1328
- feePayer
1329
- };
1330
- };
1331
- const getStdFeeFromString = (gasPrice) => {
1332
- const matchResult = gasPrice.match(/^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/);
1333
- if (!matchResult) throw new Error("Invalid gas price string");
1334
- const [_, amount] = matchResult;
1335
- return getStdFeeFromObject({
1336
- gas: toChainFormat(amount, 18).dividedBy(DEFAULT_GAS_PRICE).toFixed(0),
1337
- gasPrice: DEFAULT_GAS_PRICE
1338
- });
1339
- };
1340
- const getStdFee = (args) => {
1341
- if (!args) return getDefaultStdFee();
1342
- if (typeof args === "string") return getStdFeeFromString(args);
1343
- return getStdFeeFromObject({ ...args });
1344
- };
1345
-
1346
70
  //#endregion
1347
71
  //#region src/utils/tx.ts
1348
72
  const createEip712StdSignDoc = ({ memo, chainId, accountNumber, timeoutHeight, sequence, gas, msgs }) => ({