@alephium/powfi-sdk 0.0.1-rc.21 → 0.0.1-rc.23

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/lib/index.js CHANGED
@@ -4912,1349 +4912,8 @@ var ModuleBase = class {
4912
4912
  }
4913
4913
  };
4914
4914
 
4915
- // ../../node_modules/bignumber.js/bignumber.mjs
4916
- var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
4917
- var mathceil = Math.ceil;
4918
- var mathfloor = Math.floor;
4919
- var bignumberError = "[BigNumber Error] ";
4920
- var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
4921
- var BASE = 1e14;
4922
- var LOG_BASE = 14;
4923
- var MAX_SAFE_INTEGER = 9007199254740991;
4924
- var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
4925
- var SQRT_BASE = 1e7;
4926
- var MAX = 1e9;
4927
- function clone(configObject) {
4928
- var div, convertBase, parseNumeric, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(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 = {
4929
- prefix: "",
4930
- groupSize: 3,
4931
- secondaryGroupSize: 0,
4932
- groupSeparator: ",",
4933
- decimalSeparator: ".",
4934
- fractionGroupSize: 0,
4935
- fractionGroupSeparator: "\xA0",
4936
- // non-breaking space
4937
- suffix: ""
4938
- }, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
4939
- function BigNumber2(v, b) {
4940
- var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
4941
- if (!(x instanceof BigNumber2)) return new BigNumber2(v, b);
4942
- if (b == null) {
4943
- if (v && v._isBigNumber === true) {
4944
- x.s = v.s;
4945
- if (!v.c || v.e > MAX_EXP) {
4946
- x.c = x.e = null;
4947
- } else if (v.e < MIN_EXP) {
4948
- x.c = [x.e = 0];
4949
- } else {
4950
- x.e = v.e;
4951
- x.c = v.c.slice();
4952
- }
4953
- return;
4954
- }
4955
- if ((isNum = typeof v == "number") && v * 0 == 0) {
4956
- x.s = 1 / v < 0 ? (v = -v, -1) : 1;
4957
- if (v === ~~v) {
4958
- for (e = 0, i = v; i >= 10; i /= 10, e++) ;
4959
- if (e > MAX_EXP) {
4960
- x.c = x.e = null;
4961
- } else {
4962
- x.e = e;
4963
- x.c = [v];
4964
- }
4965
- return;
4966
- }
4967
- str = String(v);
4968
- } else {
4969
- if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
4970
- x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
4971
- }
4972
- if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
4973
- if ((i = str.search(/e/i)) > 0) {
4974
- if (e < 0) e = i;
4975
- e += +str.slice(i + 1);
4976
- str = str.substring(0, i);
4977
- } else if (e < 0) {
4978
- e = str.length;
4979
- }
4980
- } else {
4981
- intCheck(b, 2, ALPHABET.length, "Base");
4982
- if (b == 10 && alphabetHasNormalDecimalDigits) {
4983
- x = new BigNumber2(v);
4984
- return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
4985
- }
4986
- str = String(v);
4987
- if (isNum = typeof v == "number") {
4988
- if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
4989
- x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
4990
- if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
4991
- throw Error(tooManyDigits + v);
4992
- }
4993
- } else {
4994
- x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
4995
- }
4996
- alphabet = ALPHABET.slice(0, b);
4997
- e = i = 0;
4998
- for (len = str.length; i < len; i++) {
4999
- if (alphabet.indexOf(c = str.charAt(i)) < 0) {
5000
- if (c == ".") {
5001
- if (i > e) {
5002
- e = len;
5003
- continue;
5004
- }
5005
- } else if (!caseChanged) {
5006
- if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
5007
- caseChanged = true;
5008
- i = -1;
5009
- e = 0;
5010
- continue;
5011
- }
5012
- }
5013
- return parseNumeric(x, String(v), isNum, b);
5014
- }
5015
- }
5016
- isNum = false;
5017
- str = convertBase(str, b, 10, x.s);
5018
- if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
5019
- else e = str.length;
5020
- }
5021
- for (i = 0; str.charCodeAt(i) === 48; i++) ;
5022
- for (len = str.length; str.charCodeAt(--len) === 48; ) ;
5023
- if (str = str.slice(i, ++len)) {
5024
- len -= i;
5025
- if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
5026
- throw Error(tooManyDigits + x.s * v);
5027
- }
5028
- if ((e = e - i - 1) > MAX_EXP) {
5029
- x.c = x.e = null;
5030
- } else if (e < MIN_EXP) {
5031
- x.c = [x.e = 0];
5032
- } else {
5033
- x.e = e;
5034
- x.c = [];
5035
- i = (e + 1) % LOG_BASE;
5036
- if (e < 0) i += LOG_BASE;
5037
- if (i < len) {
5038
- if (i) x.c.push(+str.slice(0, i));
5039
- for (len -= LOG_BASE; i < len; ) {
5040
- x.c.push(+str.slice(i, i += LOG_BASE));
5041
- }
5042
- i = LOG_BASE - (str = str.slice(i)).length;
5043
- } else {
5044
- i -= len;
5045
- }
5046
- for (; i--; str += "0") ;
5047
- x.c.push(+str);
5048
- }
5049
- } else {
5050
- x.c = [x.e = 0];
5051
- }
5052
- }
5053
- BigNumber2.clone = clone;
5054
- BigNumber2.ROUND_UP = 0;
5055
- BigNumber2.ROUND_DOWN = 1;
5056
- BigNumber2.ROUND_CEIL = 2;
5057
- BigNumber2.ROUND_FLOOR = 3;
5058
- BigNumber2.ROUND_HALF_UP = 4;
5059
- BigNumber2.ROUND_HALF_DOWN = 5;
5060
- BigNumber2.ROUND_HALF_EVEN = 6;
5061
- BigNumber2.ROUND_HALF_CEIL = 7;
5062
- BigNumber2.ROUND_HALF_FLOOR = 8;
5063
- BigNumber2.EUCLID = 9;
5064
- BigNumber2.config = BigNumber2.set = function(obj) {
5065
- var p, v;
5066
- if (obj != null) {
5067
- if (typeof obj == "object") {
5068
- if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
5069
- v = obj[p];
5070
- intCheck(v, 0, MAX, p);
5071
- DECIMAL_PLACES = v;
5072
- }
5073
- if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
5074
- v = obj[p];
5075
- intCheck(v, 0, 8, p);
5076
- ROUNDING_MODE = v;
5077
- }
5078
- if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
5079
- v = obj[p];
5080
- if (v && v.pop) {
5081
- intCheck(v[0], -MAX, 0, p);
5082
- intCheck(v[1], 0, MAX, p);
5083
- TO_EXP_NEG = v[0];
5084
- TO_EXP_POS = v[1];
5085
- } else {
5086
- intCheck(v, -MAX, MAX, p);
5087
- TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
5088
- }
5089
- }
5090
- if (obj.hasOwnProperty(p = "RANGE")) {
5091
- v = obj[p];
5092
- if (v && v.pop) {
5093
- intCheck(v[0], -MAX, -1, p);
5094
- intCheck(v[1], 1, MAX, p);
5095
- MIN_EXP = v[0];
5096
- MAX_EXP = v[1];
5097
- } else {
5098
- intCheck(v, -MAX, MAX, p);
5099
- if (v) {
5100
- MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
5101
- } else {
5102
- throw Error(bignumberError + p + " cannot be zero: " + v);
5103
- }
5104
- }
5105
- }
5106
- if (obj.hasOwnProperty(p = "CRYPTO")) {
5107
- v = obj[p];
5108
- if (v === !!v) {
5109
- if (v) {
5110
- if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
5111
- CRYPTO = v;
5112
- } else {
5113
- CRYPTO = !v;
5114
- throw Error(bignumberError + "crypto unavailable");
5115
- }
5116
- } else {
5117
- CRYPTO = v;
5118
- }
5119
- } else {
5120
- throw Error(bignumberError + p + " not true or false: " + v);
5121
- }
5122
- }
5123
- if (obj.hasOwnProperty(p = "MODULO_MODE")) {
5124
- v = obj[p];
5125
- intCheck(v, 0, 9, p);
5126
- MODULO_MODE = v;
5127
- }
5128
- if (obj.hasOwnProperty(p = "POW_PRECISION")) {
5129
- v = obj[p];
5130
- intCheck(v, 0, MAX, p);
5131
- POW_PRECISION = v;
5132
- }
5133
- if (obj.hasOwnProperty(p = "FORMAT")) {
5134
- v = obj[p];
5135
- if (typeof v == "object") FORMAT = v;
5136
- else throw Error(bignumberError + p + " not an object: " + v);
5137
- }
5138
- if (obj.hasOwnProperty(p = "ALPHABET")) {
5139
- v = obj[p];
5140
- if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
5141
- alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
5142
- ALPHABET = v;
5143
- } else {
5144
- throw Error(bignumberError + p + " invalid: " + v);
5145
- }
5146
- }
5147
- } else {
5148
- throw Error(bignumberError + "Object expected: " + obj);
5149
- }
5150
- }
5151
- return {
5152
- DECIMAL_PLACES,
5153
- ROUNDING_MODE,
5154
- EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
5155
- RANGE: [MIN_EXP, MAX_EXP],
5156
- CRYPTO,
5157
- MODULO_MODE,
5158
- POW_PRECISION,
5159
- FORMAT,
5160
- ALPHABET
5161
- };
5162
- };
5163
- BigNumber2.isBigNumber = function(v) {
5164
- if (!v || v._isBigNumber !== true) return false;
5165
- if (!BigNumber2.DEBUG) return true;
5166
- var i, n, c = v.c, e = v.e, s = v.s;
5167
- out: if ({}.toString.call(c) == "[object Array]") {
5168
- if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
5169
- if (c[0] === 0) {
5170
- if (e === 0 && c.length === 1) return true;
5171
- break out;
5172
- }
5173
- i = (e + 1) % LOG_BASE;
5174
- if (i < 1) i += LOG_BASE;
5175
- if (String(c[0]).length == i) {
5176
- for (i = 0; i < c.length; i++) {
5177
- n = c[i];
5178
- if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
5179
- }
5180
- if (n !== 0) return true;
5181
- }
5182
- }
5183
- } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
5184
- return true;
5185
- }
5186
- throw Error(bignumberError + "Invalid BigNumber: " + v);
5187
- };
5188
- BigNumber2.maximum = BigNumber2.max = function() {
5189
- return maxOrMin(arguments, -1);
5190
- };
5191
- BigNumber2.minimum = BigNumber2.min = function() {
5192
- return maxOrMin(arguments, 1);
5193
- };
5194
- BigNumber2.random = (function() {
5195
- var pow2_53 = 9007199254740992;
5196
- var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
5197
- return mathfloor(Math.random() * pow2_53);
5198
- } : function() {
5199
- return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
5200
- };
5201
- return function(dp) {
5202
- var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
5203
- if (dp == null) dp = DECIMAL_PLACES;
5204
- else intCheck(dp, 0, MAX);
5205
- k = mathceil(dp / LOG_BASE);
5206
- if (CRYPTO) {
5207
- if (crypto.getRandomValues) {
5208
- a = crypto.getRandomValues(new Uint32Array(k *= 2));
5209
- for (; i < k; ) {
5210
- v = a[i] * 131072 + (a[i + 1] >>> 11);
5211
- if (v >= 9e15) {
5212
- b = crypto.getRandomValues(new Uint32Array(2));
5213
- a[i] = b[0];
5214
- a[i + 1] = b[1];
5215
- } else {
5216
- c.push(v % 1e14);
5217
- i += 2;
5218
- }
5219
- }
5220
- i = k / 2;
5221
- } else if (crypto.randomBytes) {
5222
- a = crypto.randomBytes(k *= 7);
5223
- for (; i < k; ) {
5224
- 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];
5225
- if (v >= 9e15) {
5226
- crypto.randomBytes(7).copy(a, i);
5227
- } else {
5228
- c.push(v % 1e14);
5229
- i += 7;
5230
- }
5231
- }
5232
- i = k / 7;
5233
- } else {
5234
- CRYPTO = false;
5235
- throw Error(bignumberError + "crypto unavailable");
5236
- }
5237
- }
5238
- if (!CRYPTO) {
5239
- for (; i < k; ) {
5240
- v = random53bitInt();
5241
- if (v < 9e15) c[i++] = v % 1e14;
5242
- }
5243
- }
5244
- k = c[--i];
5245
- dp %= LOG_BASE;
5246
- if (k && dp) {
5247
- v = POWS_TEN[LOG_BASE - dp];
5248
- c[i] = mathfloor(k / v) * v;
5249
- }
5250
- for (; c[i] === 0; c.pop(), i--) ;
5251
- if (i < 0) {
5252
- c = [e = 0];
5253
- } else {
5254
- for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE) ;
5255
- for (i = 1, v = c[0]; v >= 10; v /= 10, i++) ;
5256
- if (i < LOG_BASE) e -= LOG_BASE - i;
5257
- }
5258
- rand.e = e;
5259
- rand.c = c;
5260
- return rand;
5261
- };
5262
- })();
5263
- BigNumber2.sum = function() {
5264
- var i = 1, args = arguments, sum = new BigNumber2(args[0]);
5265
- for (; i < args.length; ) sum = sum.plus(args[i++]);
5266
- return sum;
5267
- };
5268
- convertBase = /* @__PURE__ */ (function() {
5269
- var decimal = "0123456789";
5270
- function toBaseOut(str, baseIn, baseOut, alphabet) {
5271
- var j, arr = [0], arrL, i = 0, len = str.length;
5272
- for (; i < len; ) {
5273
- for (arrL = arr.length; arrL--; arr[arrL] *= baseIn) ;
5274
- arr[0] += alphabet.indexOf(str.charAt(i++));
5275
- for (j = 0; j < arr.length; j++) {
5276
- if (arr[j] > baseOut - 1) {
5277
- if (arr[j + 1] == null) arr[j + 1] = 0;
5278
- arr[j + 1] += arr[j] / baseOut | 0;
5279
- arr[j] %= baseOut;
5280
- }
5281
- }
5282
- }
5283
- return arr.reverse();
5284
- }
5285
- return function(str, baseIn, baseOut, sign, callerIsToString) {
5286
- var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
5287
- if (i >= 0) {
5288
- k = POW_PRECISION;
5289
- POW_PRECISION = 0;
5290
- str = str.replace(".", "");
5291
- y = new BigNumber2(baseIn);
5292
- x = y.pow(str.length - i);
5293
- POW_PRECISION = k;
5294
- y.c = toBaseOut(
5295
- toFixedPoint(coeffToString(x.c), x.e, "0"),
5296
- 10,
5297
- baseOut,
5298
- decimal
5299
- );
5300
- y.e = y.c.length;
5301
- }
5302
- xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
5303
- e = k = xc.length;
5304
- for (; xc[--k] == 0; xc.pop()) ;
5305
- if (!xc[0]) return alphabet.charAt(0);
5306
- if (i < 0) {
5307
- --e;
5308
- } else {
5309
- x.c = xc;
5310
- x.e = e;
5311
- x.s = sign;
5312
- x = div(x, y, dp, rm, baseOut);
5313
- xc = x.c;
5314
- r = x.r;
5315
- e = x.e;
5316
- }
5317
- d = e + dp + 1;
5318
- i = xc[d];
5319
- k = baseOut / 2;
5320
- r = r || d < 0 || xc[d + 1] != null;
5321
- 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));
5322
- if (d < 1 || !xc[0]) {
5323
- str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
5324
- } else {
5325
- xc.length = d;
5326
- if (r) {
5327
- for (--baseOut; ++xc[--d] > baseOut; ) {
5328
- xc[d] = 0;
5329
- if (!d) {
5330
- ++e;
5331
- xc = [1].concat(xc);
5332
- }
5333
- }
5334
- }
5335
- for (k = xc.length; !xc[--k]; ) ;
5336
- for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++])) ;
5337
- str = toFixedPoint(str, e, alphabet.charAt(0));
5338
- }
5339
- return str;
5340
- };
5341
- })();
5342
- div = /* @__PURE__ */ (function() {
5343
- function multiply(x, k, base) {
5344
- var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
5345
- for (x = x.slice(); i--; ) {
5346
- xlo = x[i] % SQRT_BASE;
5347
- xhi = x[i] / SQRT_BASE | 0;
5348
- m = khi * xlo + xhi * klo;
5349
- temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
5350
- carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
5351
- x[i] = temp % base;
5352
- }
5353
- if (carry) x = [carry].concat(x);
5354
- return x;
5355
- }
5356
- function compare2(a, b, aL, bL) {
5357
- var i, cmp;
5358
- if (aL != bL) {
5359
- cmp = aL > bL ? 1 : -1;
5360
- } else {
5361
- for (i = cmp = 0; i < aL; i++) {
5362
- if (a[i] != b[i]) {
5363
- cmp = a[i] > b[i] ? 1 : -1;
5364
- break;
5365
- }
5366
- }
5367
- }
5368
- return cmp;
5369
- }
5370
- function subtract(a, b, aL, base) {
5371
- var i = 0;
5372
- for (; aL--; ) {
5373
- a[aL] -= i;
5374
- i = a[aL] < b[aL] ? 1 : 0;
5375
- a[aL] = i * base + a[aL] - b[aL];
5376
- }
5377
- for (; !a[0] && a.length > 1; a.splice(0, 1)) ;
5378
- }
5379
- return function(x, y, dp, rm, base) {
5380
- 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;
5381
- if (!xc || !xc[0] || !yc || !yc[0]) {
5382
- return new BigNumber2(
5383
- // Return NaN if either NaN, or both Infinity or 0.
5384
- !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
5385
- // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
5386
- xc && xc[0] == 0 || !yc ? s * 0 : s / 0
5387
- )
5388
- );
5389
- }
5390
- q = new BigNumber2(s);
5391
- qc = q.c = [];
5392
- e = x.e - y.e;
5393
- s = dp + e + 1;
5394
- if (!base) {
5395
- base = BASE;
5396
- e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
5397
- s = s / LOG_BASE | 0;
5398
- }
5399
- for (i = 0; yc[i] == (xc[i] || 0); i++) ;
5400
- if (yc[i] > (xc[i] || 0)) e--;
5401
- if (s < 0) {
5402
- qc.push(1);
5403
- more = true;
5404
- } else {
5405
- xL = xc.length;
5406
- yL = yc.length;
5407
- i = 0;
5408
- s += 2;
5409
- n = mathfloor(base / (yc[0] + 1));
5410
- if (n > 1) {
5411
- yc = multiply(yc, n, base);
5412
- xc = multiply(xc, n, base);
5413
- yL = yc.length;
5414
- xL = xc.length;
5415
- }
5416
- xi = yL;
5417
- rem = xc.slice(0, yL);
5418
- remL = rem.length;
5419
- for (; remL < yL; rem[remL++] = 0) ;
5420
- yz = yc.slice();
5421
- yz = [0].concat(yz);
5422
- yc0 = yc[0];
5423
- if (yc[1] >= base / 2) yc0++;
5424
- do {
5425
- n = 0;
5426
- cmp = compare2(yc, rem, yL, remL);
5427
- if (cmp < 0) {
5428
- rem0 = rem[0];
5429
- if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
5430
- n = mathfloor(rem0 / yc0);
5431
- if (n > 1) {
5432
- if (n >= base) n = base - 1;
5433
- prod = multiply(yc, n, base);
5434
- prodL = prod.length;
5435
- remL = rem.length;
5436
- while (compare2(prod, rem, prodL, remL) == 1) {
5437
- n--;
5438
- subtract(prod, yL < prodL ? yz : yc, prodL, base);
5439
- prodL = prod.length;
5440
- cmp = 1;
5441
- }
5442
- } else {
5443
- if (n == 0) {
5444
- cmp = n = 1;
5445
- }
5446
- prod = yc.slice();
5447
- prodL = prod.length;
5448
- }
5449
- if (prodL < remL) prod = [0].concat(prod);
5450
- subtract(rem, prod, remL, base);
5451
- remL = rem.length;
5452
- if (cmp == -1) {
5453
- while (compare2(yc, rem, yL, remL) < 1) {
5454
- n++;
5455
- subtract(rem, yL < remL ? yz : yc, remL, base);
5456
- remL = rem.length;
5457
- }
5458
- }
5459
- } else if (cmp === 0) {
5460
- n++;
5461
- rem = [0];
5462
- }
5463
- qc[i++] = n;
5464
- if (rem[0]) {
5465
- rem[remL++] = xc[xi] || 0;
5466
- } else {
5467
- rem = [xc[xi]];
5468
- remL = 1;
5469
- }
5470
- } while ((xi++ < xL || rem[0] != null) && s--);
5471
- more = rem[0] != null;
5472
- if (!qc[0]) qc.splice(0, 1);
5473
- }
5474
- if (base == BASE) {
5475
- for (i = 1, s = qc[0]; s >= 10; s /= 10, i++) ;
5476
- round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
5477
- } else {
5478
- q.e = e;
5479
- q.r = +more;
5480
- }
5481
- return q;
5482
- };
5483
- })();
5484
- function format(n, i, rm, id) {
5485
- var c0, e, ne, len, str;
5486
- if (rm == null) rm = ROUNDING_MODE;
5487
- else intCheck(rm, 0, 8);
5488
- if (!n.c) return n.toString();
5489
- c0 = n.c[0];
5490
- ne = n.e;
5491
- if (i == null) {
5492
- str = coeffToString(n.c);
5493
- str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
5494
- } else {
5495
- n = round(new BigNumber2(n), i, rm);
5496
- e = n.e;
5497
- str = coeffToString(n.c);
5498
- len = str.length;
5499
- if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
5500
- for (; len < i; str += "0", len++) ;
5501
- str = toExponential(str, e);
5502
- } else {
5503
- i -= ne + (id === 2 && e > ne);
5504
- str = toFixedPoint(str, e, "0");
5505
- if (e + 1 > len) {
5506
- if (--i > 0) for (str += "."; i--; str += "0") ;
5507
- } else {
5508
- i += e - len;
5509
- if (i > 0) {
5510
- if (e + 1 == len) str += ".";
5511
- for (; i--; str += "0") ;
5512
- }
5513
- }
5514
- }
5515
- }
5516
- return n.s < 0 && c0 ? "-" + str : str;
5517
- }
5518
- function maxOrMin(args, n) {
5519
- var k, y, i = 1, x = new BigNumber2(args[0]);
5520
- for (; i < args.length; i++) {
5521
- y = new BigNumber2(args[i]);
5522
- if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
5523
- x = y;
5524
- }
5525
- }
5526
- return x;
5527
- }
5528
- function normalise(n, c, e) {
5529
- var i = 1, j = c.length;
5530
- for (; !c[--j]; c.pop()) ;
5531
- for (j = c[0]; j >= 10; j /= 10, i++) ;
5532
- if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
5533
- n.c = n.e = null;
5534
- } else if (e < MIN_EXP) {
5535
- n.c = [n.e = 0];
5536
- } else {
5537
- n.e = e;
5538
- n.c = c;
5539
- }
5540
- return n;
5541
- }
5542
- parseNumeric = /* @__PURE__ */ (function() {
5543
- var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
5544
- return function(x, str, isNum, b) {
5545
- var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
5546
- if (isInfinityOrNaN.test(s)) {
5547
- x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
5548
- } else {
5549
- if (!isNum) {
5550
- s = s.replace(basePrefix, function(m, p1, p2) {
5551
- base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
5552
- return !b || b == base ? p1 : m;
5553
- });
5554
- if (b) {
5555
- base = b;
5556
- s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
5557
- }
5558
- if (str != s) return new BigNumber2(s, base);
5559
- }
5560
- if (BigNumber2.DEBUG) {
5561
- throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
5562
- }
5563
- x.s = null;
5564
- }
5565
- x.c = x.e = null;
5566
- };
5567
- })();
5568
- function round(x, sd, rm, r) {
5569
- var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
5570
- if (xc) {
5571
- out: {
5572
- for (d = 1, k = xc[0]; k >= 10; k /= 10, d++) ;
5573
- i = sd - d;
5574
- if (i < 0) {
5575
- i += LOG_BASE;
5576
- j = sd;
5577
- n = xc[ni = 0];
5578
- rd = mathfloor(n / pows10[d - j - 1] % 10);
5579
- } else {
5580
- ni = mathceil((i + 1) / LOG_BASE);
5581
- if (ni >= xc.length) {
5582
- if (r) {
5583
- for (; xc.length <= ni; xc.push(0)) ;
5584
- n = rd = 0;
5585
- d = 1;
5586
- i %= LOG_BASE;
5587
- j = i - LOG_BASE + 1;
5588
- } else {
5589
- break out;
5590
- }
5591
- } else {
5592
- n = k = xc[ni];
5593
- for (d = 1; k >= 10; k /= 10, d++) ;
5594
- i %= LOG_BASE;
5595
- j = i - LOG_BASE + d;
5596
- rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
5597
- }
5598
- }
5599
- r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
5600
- // The expression n % pows10[d - j - 1] returns all digits of n to the right
5601
- // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
5602
- xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
5603
- r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
5604
- (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
5605
- if (sd < 1 || !xc[0]) {
5606
- xc.length = 0;
5607
- if (r) {
5608
- sd -= x.e + 1;
5609
- xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
5610
- x.e = -sd || 0;
5611
- } else {
5612
- xc[0] = x.e = 0;
5613
- }
5614
- return x;
5615
- }
5616
- if (i == 0) {
5617
- xc.length = ni;
5618
- k = 1;
5619
- ni--;
5620
- } else {
5621
- xc.length = ni + 1;
5622
- k = pows10[LOG_BASE - i];
5623
- xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
5624
- }
5625
- if (r) {
5626
- for (; ; ) {
5627
- if (ni == 0) {
5628
- for (i = 1, j = xc[0]; j >= 10; j /= 10, i++) ;
5629
- j = xc[0] += k;
5630
- for (k = 1; j >= 10; j /= 10, k++) ;
5631
- if (i != k) {
5632
- x.e++;
5633
- if (xc[0] == BASE) xc[0] = 1;
5634
- }
5635
- break;
5636
- } else {
5637
- xc[ni] += k;
5638
- if (xc[ni] != BASE) break;
5639
- xc[ni--] = 0;
5640
- k = 1;
5641
- }
5642
- }
5643
- }
5644
- for (i = xc.length; xc[--i] === 0; xc.pop()) ;
5645
- }
5646
- if (x.e > MAX_EXP) {
5647
- x.c = x.e = null;
5648
- } else if (x.e < MIN_EXP) {
5649
- x.c = [x.e = 0];
5650
- }
5651
- }
5652
- return x;
5653
- }
5654
- function valueOf(n) {
5655
- var str, e = n.e;
5656
- if (e === null) return n.toString();
5657
- str = coeffToString(n.c);
5658
- str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
5659
- return n.s < 0 ? "-" + str : str;
5660
- }
5661
- P.absoluteValue = P.abs = function() {
5662
- var x = new BigNumber2(this);
5663
- if (x.s < 0) x.s = 1;
5664
- return x;
5665
- };
5666
- P.comparedTo = function(y, b) {
5667
- return compare(this, new BigNumber2(y, b));
5668
- };
5669
- P.decimalPlaces = P.dp = function(dp, rm) {
5670
- var c, n, v, x = this;
5671
- if (dp != null) {
5672
- intCheck(dp, 0, MAX);
5673
- if (rm == null) rm = ROUNDING_MODE;
5674
- else intCheck(rm, 0, 8);
5675
- return round(new BigNumber2(x), dp + x.e + 1, rm);
5676
- }
5677
- if (!(c = x.c)) return null;
5678
- n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
5679
- if (v = c[v]) for (; v % 10 == 0; v /= 10, n--) ;
5680
- if (n < 0) n = 0;
5681
- return n;
5682
- };
5683
- P.dividedBy = P.div = function(y, b) {
5684
- return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
5685
- };
5686
- P.dividedToIntegerBy = P.idiv = function(y, b) {
5687
- return div(this, new BigNumber2(y, b), 0, 1);
5688
- };
5689
- P.exponentiatedBy = P.pow = function(n, m) {
5690
- var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
5691
- n = new BigNumber2(n);
5692
- if (n.c && !n.isInteger()) {
5693
- throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
5694
- }
5695
- if (m != null) m = new BigNumber2(m);
5696
- nIsBig = n.e > 14;
5697
- if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
5698
- y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
5699
- return m ? y.mod(m) : y;
5700
- }
5701
- nIsNeg = n.s < 0;
5702
- if (m) {
5703
- if (m.c ? !m.c[0] : !m.s) return new BigNumber2(NaN);
5704
- isModExp = !nIsNeg && x.isInteger() && m.isInteger();
5705
- if (isModExp) x = x.mod(m);
5706
- } 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))) {
5707
- k = x.s < 0 && isOdd(n) ? -0 : 0;
5708
- if (x.e > -1) k = 1 / k;
5709
- return new BigNumber2(nIsNeg ? 1 / k : k);
5710
- } else if (POW_PRECISION) {
5711
- k = mathceil(POW_PRECISION / LOG_BASE + 2);
5712
- }
5713
- if (nIsBig) {
5714
- half = new BigNumber2(0.5);
5715
- if (nIsNeg) n.s = 1;
5716
- nIsOdd = isOdd(n);
5717
- } else {
5718
- i = Math.abs(+valueOf(n));
5719
- nIsOdd = i % 2;
5720
- }
5721
- y = new BigNumber2(ONE);
5722
- for (; ; ) {
5723
- if (nIsOdd) {
5724
- y = y.times(x);
5725
- if (!y.c) break;
5726
- if (k) {
5727
- if (y.c.length > k) y.c.length = k;
5728
- } else if (isModExp) {
5729
- y = y.mod(m);
5730
- }
5731
- }
5732
- if (i) {
5733
- i = mathfloor(i / 2);
5734
- if (i === 0) break;
5735
- nIsOdd = i % 2;
5736
- } else {
5737
- n = n.times(half);
5738
- round(n, n.e + 1, 1);
5739
- if (n.e > 14) {
5740
- nIsOdd = isOdd(n);
5741
- } else {
5742
- i = +valueOf(n);
5743
- if (i === 0) break;
5744
- nIsOdd = i % 2;
5745
- }
5746
- }
5747
- x = x.times(x);
5748
- if (k) {
5749
- if (x.c && x.c.length > k) x.c.length = k;
5750
- } else if (isModExp) {
5751
- x = x.mod(m);
5752
- }
5753
- }
5754
- if (isModExp) return y;
5755
- if (nIsNeg) y = ONE.div(y);
5756
- return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
5757
- };
5758
- P.integerValue = function(rm) {
5759
- var n = new BigNumber2(this);
5760
- if (rm == null) rm = ROUNDING_MODE;
5761
- else intCheck(rm, 0, 8);
5762
- return round(n, n.e + 1, rm);
5763
- };
5764
- P.isEqualTo = P.eq = function(y, b) {
5765
- return compare(this, new BigNumber2(y, b)) === 0;
5766
- };
5767
- P.isFinite = function() {
5768
- return !!this.c;
5769
- };
5770
- P.isGreaterThan = P.gt = function(y, b) {
5771
- return compare(this, new BigNumber2(y, b)) > 0;
5772
- };
5773
- P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
5774
- return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
5775
- };
5776
- P.isInteger = function() {
5777
- return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
5778
- };
5779
- P.isLessThan = P.lt = function(y, b) {
5780
- return compare(this, new BigNumber2(y, b)) < 0;
5781
- };
5782
- P.isLessThanOrEqualTo = P.lte = function(y, b) {
5783
- return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
5784
- };
5785
- P.isNaN = function() {
5786
- return !this.s;
5787
- };
5788
- P.isNegative = function() {
5789
- return this.s < 0;
5790
- };
5791
- P.isPositive = function() {
5792
- return this.s > 0;
5793
- };
5794
- P.isZero = function() {
5795
- return !!this.c && this.c[0] == 0;
5796
- };
5797
- P.minus = function(y, b) {
5798
- var i, j, t, xLTy, x = this, a = x.s;
5799
- y = new BigNumber2(y, b);
5800
- b = y.s;
5801
- if (!a || !b) return new BigNumber2(NaN);
5802
- if (a != b) {
5803
- y.s = -b;
5804
- return x.plus(y);
5805
- }
5806
- var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
5807
- if (!xe || !ye) {
5808
- if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
5809
- if (!xc[0] || !yc[0]) {
5810
- return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : (
5811
- // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
5812
- ROUNDING_MODE == 3 ? -0 : 0
5813
- ));
5814
- }
5815
- }
5816
- xe = bitFloor(xe);
5817
- ye = bitFloor(ye);
5818
- xc = xc.slice();
5819
- if (a = xe - ye) {
5820
- if (xLTy = a < 0) {
5821
- a = -a;
5822
- t = xc;
5823
- } else {
5824
- ye = xe;
5825
- t = yc;
5826
- }
5827
- t.reverse();
5828
- for (b = a; b--; t.push(0)) ;
5829
- t.reverse();
5830
- } else {
5831
- j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
5832
- for (a = b = 0; b < j; b++) {
5833
- if (xc[b] != yc[b]) {
5834
- xLTy = xc[b] < yc[b];
5835
- break;
5836
- }
5837
- }
5838
- }
5839
- if (xLTy) {
5840
- t = xc;
5841
- xc = yc;
5842
- yc = t;
5843
- y.s = -y.s;
5844
- }
5845
- b = (j = yc.length) - (i = xc.length);
5846
- if (b > 0) for (; b--; xc[i++] = 0) ;
5847
- b = BASE - 1;
5848
- for (; j > a; ) {
5849
- if (xc[--j] < yc[j]) {
5850
- for (i = j; i && !xc[--i]; xc[i] = b) ;
5851
- --xc[i];
5852
- xc[j] += BASE;
5853
- }
5854
- xc[j] -= yc[j];
5855
- }
5856
- for (; xc[0] == 0; xc.splice(0, 1), --ye) ;
5857
- if (!xc[0]) {
5858
- y.s = ROUNDING_MODE == 3 ? -1 : 1;
5859
- y.c = [y.e = 0];
5860
- return y;
5861
- }
5862
- return normalise(y, xc, ye);
5863
- };
5864
- P.modulo = P.mod = function(y, b) {
5865
- var q, s, x = this;
5866
- y = new BigNumber2(y, b);
5867
- if (!x.c || !y.s || y.c && !y.c[0]) {
5868
- return new BigNumber2(NaN);
5869
- } else if (!y.c || x.c && !x.c[0]) {
5870
- return new BigNumber2(x);
5871
- }
5872
- if (MODULO_MODE == 9) {
5873
- s = y.s;
5874
- y.s = 1;
5875
- q = div(x, y, 0, 3);
5876
- y.s = s;
5877
- q.s *= s;
5878
- } else {
5879
- q = div(x, y, 0, MODULO_MODE);
5880
- }
5881
- y = x.minus(q.times(y));
5882
- if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
5883
- return y;
5884
- };
5885
- P.multipliedBy = P.times = function(y, b) {
5886
- var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber2(y, b)).c;
5887
- if (!xc || !yc || !xc[0] || !yc[0]) {
5888
- if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
5889
- y.c = y.e = y.s = null;
5890
- } else {
5891
- y.s *= x.s;
5892
- if (!xc || !yc) {
5893
- y.c = y.e = null;
5894
- } else {
5895
- y.c = [0];
5896
- y.e = 0;
5897
- }
5898
- }
5899
- return y;
5900
- }
5901
- e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
5902
- y.s *= x.s;
5903
- xcL = xc.length;
5904
- ycL = yc.length;
5905
- if (xcL < ycL) {
5906
- zc = xc;
5907
- xc = yc;
5908
- yc = zc;
5909
- i = xcL;
5910
- xcL = ycL;
5911
- ycL = i;
5912
- }
5913
- for (i = xcL + ycL, zc = []; i--; zc.push(0)) ;
5914
- base = BASE;
5915
- sqrtBase = SQRT_BASE;
5916
- for (i = ycL; --i >= 0; ) {
5917
- c = 0;
5918
- ylo = yc[i] % sqrtBase;
5919
- yhi = yc[i] / sqrtBase | 0;
5920
- for (k = xcL, j = i + k; j > i; ) {
5921
- xlo = xc[--k] % sqrtBase;
5922
- xhi = xc[k] / sqrtBase | 0;
5923
- m = yhi * xlo + xhi * ylo;
5924
- xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
5925
- c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
5926
- zc[j--] = xlo % base;
5927
- }
5928
- zc[j] = c;
5929
- }
5930
- if (c) {
5931
- ++e;
5932
- } else {
5933
- zc.splice(0, 1);
5934
- }
5935
- return normalise(y, zc, e);
5936
- };
5937
- P.negated = function() {
5938
- var x = new BigNumber2(this);
5939
- x.s = -x.s || null;
5940
- return x;
5941
- };
5942
- P.plus = function(y, b) {
5943
- var t, x = this, a = x.s;
5944
- y = new BigNumber2(y, b);
5945
- b = y.s;
5946
- if (!a || !b) return new BigNumber2(NaN);
5947
- if (a != b) {
5948
- y.s = -b;
5949
- return x.minus(y);
5950
- }
5951
- var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
5952
- if (!xe || !ye) {
5953
- if (!xc || !yc) return new BigNumber2(a / 0);
5954
- if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
5955
- }
5956
- xe = bitFloor(xe);
5957
- ye = bitFloor(ye);
5958
- xc = xc.slice();
5959
- if (a = xe - ye) {
5960
- if (a > 0) {
5961
- ye = xe;
5962
- t = yc;
5963
- } else {
5964
- a = -a;
5965
- t = xc;
5966
- }
5967
- t.reverse();
5968
- for (; a--; t.push(0)) ;
5969
- t.reverse();
5970
- }
5971
- a = xc.length;
5972
- b = yc.length;
5973
- if (a - b < 0) {
5974
- t = yc;
5975
- yc = xc;
5976
- xc = t;
5977
- b = a;
5978
- }
5979
- for (a = 0; b; ) {
5980
- a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
5981
- xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
5982
- }
5983
- if (a) {
5984
- xc = [a].concat(xc);
5985
- ++ye;
5986
- }
5987
- return normalise(y, xc, ye);
5988
- };
5989
- P.precision = P.sd = function(sd, rm) {
5990
- var c, n, v, x = this;
5991
- if (sd != null && sd !== !!sd) {
5992
- intCheck(sd, 1, MAX);
5993
- if (rm == null) rm = ROUNDING_MODE;
5994
- else intCheck(rm, 0, 8);
5995
- return round(new BigNumber2(x), sd, rm);
5996
- }
5997
- if (!(c = x.c)) return null;
5998
- v = c.length - 1;
5999
- n = v * LOG_BASE + 1;
6000
- if (v = c[v]) {
6001
- for (; v % 10 == 0; v /= 10, n--) ;
6002
- for (v = c[0]; v >= 10; v /= 10, n++) ;
6003
- }
6004
- if (sd && x.e + 1 > n) n = x.e + 1;
6005
- return n;
6006
- };
6007
- P.shiftedBy = function(k) {
6008
- intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
6009
- return this.times("1e" + k);
6010
- };
6011
- P.squareRoot = P.sqrt = function() {
6012
- var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
6013
- if (s !== 1 || !c || !c[0]) {
6014
- return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
6015
- }
6016
- s = Math.sqrt(+valueOf(x));
6017
- if (s == 0 || s == 1 / 0) {
6018
- n = coeffToString(c);
6019
- if ((n.length + e) % 2 == 0) n += "0";
6020
- s = Math.sqrt(+n);
6021
- e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
6022
- if (s == 1 / 0) {
6023
- n = "5e" + e;
6024
- } else {
6025
- n = s.toExponential();
6026
- n = n.slice(0, n.indexOf("e") + 1) + e;
6027
- }
6028
- r = new BigNumber2(n);
6029
- } else {
6030
- r = new BigNumber2(s + "");
6031
- }
6032
- if (r.c[0]) {
6033
- e = r.e;
6034
- s = e + dp;
6035
- if (s < 3) s = 0;
6036
- for (; ; ) {
6037
- t = r;
6038
- r = half.times(t.plus(div(x, t, dp, 1)));
6039
- if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
6040
- if (r.e < e) --s;
6041
- n = n.slice(s - 3, s + 1);
6042
- if (n == "9999" || !rep && n == "4999") {
6043
- if (!rep) {
6044
- round(t, t.e + DECIMAL_PLACES + 2, 0);
6045
- if (t.times(t).eq(x)) {
6046
- r = t;
6047
- break;
6048
- }
6049
- }
6050
- dp += 4;
6051
- s += 4;
6052
- rep = 1;
6053
- } else {
6054
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
6055
- round(r, r.e + DECIMAL_PLACES + 2, 1);
6056
- m = !r.times(r).eq(x);
6057
- }
6058
- break;
6059
- }
6060
- }
6061
- }
6062
- }
6063
- return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
6064
- };
6065
- P.toExponential = function(dp, rm) {
6066
- if (dp != null) {
6067
- intCheck(dp, 0, MAX);
6068
- dp++;
6069
- }
6070
- return format(this, dp, rm, 1);
6071
- };
6072
- P.toFixed = function(dp, rm) {
6073
- if (dp != null) {
6074
- intCheck(dp, 0, MAX);
6075
- dp = dp + this.e + 1;
6076
- }
6077
- return format(this, dp, rm);
6078
- };
6079
- P.toFormat = function(dp, rm, format2) {
6080
- var str, x = this;
6081
- if (format2 == null) {
6082
- if (dp != null && rm && typeof rm == "object") {
6083
- format2 = rm;
6084
- rm = null;
6085
- } else if (dp && typeof dp == "object") {
6086
- format2 = dp;
6087
- dp = rm = null;
6088
- } else {
6089
- format2 = FORMAT;
6090
- }
6091
- } else if (typeof format2 != "object") {
6092
- throw Error(bignumberError + "Argument not an object: " + format2);
6093
- }
6094
- str = x.toFixed(dp, rm);
6095
- if (x.c) {
6096
- var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
6097
- if (g2) {
6098
- i = g1;
6099
- g1 = g2;
6100
- g2 = i;
6101
- len -= i;
6102
- }
6103
- if (g1 > 0 && len > 0) {
6104
- i = len % g1 || g1;
6105
- intPart = intDigits.substr(0, i);
6106
- for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
6107
- if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
6108
- if (isNeg) intPart = "-" + intPart;
6109
- }
6110
- str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
6111
- new RegExp("\\d{" + g2 + "}\\B", "g"),
6112
- "$&" + (format2.fractionGroupSeparator || "")
6113
- ) : fractionPart) : intPart;
6114
- }
6115
- return (format2.prefix || "") + str + (format2.suffix || "");
6116
- };
6117
- P.toFraction = function(md) {
6118
- var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
6119
- if (md != null) {
6120
- n = new BigNumber2(md);
6121
- if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
6122
- throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
6123
- }
6124
- }
6125
- if (!xc) return new BigNumber2(x);
6126
- d = new BigNumber2(ONE);
6127
- n1 = d0 = new BigNumber2(ONE);
6128
- d1 = n0 = new BigNumber2(ONE);
6129
- s = coeffToString(xc);
6130
- e = d.e = s.length - x.e - 1;
6131
- d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
6132
- md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
6133
- exp = MAX_EXP;
6134
- MAX_EXP = 1 / 0;
6135
- n = new BigNumber2(s);
6136
- n0.c[0] = 0;
6137
- for (; ; ) {
6138
- q = div(n, d, 0, 1);
6139
- d2 = d0.plus(q.times(d1));
6140
- if (d2.comparedTo(md) == 1) break;
6141
- d0 = d1;
6142
- d1 = d2;
6143
- n1 = n0.plus(q.times(d2 = n1));
6144
- n0 = d2;
6145
- d = n.minus(q.times(d2 = d));
6146
- n = d2;
6147
- }
6148
- d2 = div(md.minus(d0), d1, 0, 1);
6149
- n0 = n0.plus(d2.times(n1));
6150
- d0 = d0.plus(d2.times(d1));
6151
- n0.s = n1.s = x.s;
6152
- e = e * 2;
6153
- r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
6154
- div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
6155
- ) < 1 ? [n1, d1] : [n0, d0];
6156
- MAX_EXP = exp;
6157
- return r;
6158
- };
6159
- P.toNumber = function() {
6160
- return +valueOf(this);
6161
- };
6162
- P.toPrecision = function(sd, rm) {
6163
- if (sd != null) intCheck(sd, 1, MAX);
6164
- return format(this, sd, rm, 2);
6165
- };
6166
- P.toString = function(b) {
6167
- var str, n = this, s = n.s, e = n.e;
6168
- if (e === null) {
6169
- if (s) {
6170
- str = "Infinity";
6171
- if (s < 0) str = "-" + str;
6172
- } else {
6173
- str = "NaN";
6174
- }
6175
- } else {
6176
- if (b == null) {
6177
- str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
6178
- } else if (b === 10 && alphabetHasNormalDecimalDigits) {
6179
- n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
6180
- str = toFixedPoint(coeffToString(n.c), n.e, "0");
6181
- } else {
6182
- intCheck(b, 2, ALPHABET.length, "Base");
6183
- str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
6184
- }
6185
- if (s < 0 && n.c[0]) str = "-" + str;
6186
- }
6187
- return str;
6188
- };
6189
- P.valueOf = P.toJSON = function() {
6190
- return valueOf(this);
6191
- };
6192
- P._isBigNumber = true;
6193
- P[Symbol.toStringTag] = "BigNumber";
6194
- P[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
6195
- if (configObject != null) BigNumber2.set(configObject);
6196
- return BigNumber2;
6197
- }
6198
- function bitFloor(n) {
6199
- var i = n | 0;
6200
- return n > 0 || n === i ? i : i - 1;
6201
- }
6202
- function coeffToString(a) {
6203
- var s, z, i = 1, j = a.length, r = a[0] + "";
6204
- for (; i < j; ) {
6205
- s = a[i++] + "";
6206
- z = LOG_BASE - s.length;
6207
- for (; z--; s = "0" + s) ;
6208
- r += s;
6209
- }
6210
- for (j = r.length; r.charCodeAt(--j) === 48; ) ;
6211
- return r.slice(0, j + 1 || 1);
6212
- }
6213
- function compare(x, y) {
6214
- var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
6215
- if (!i || !j) return null;
6216
- a = xc && !xc[0];
6217
- b = yc && !yc[0];
6218
- if (a || b) return a ? b ? 0 : -j : i;
6219
- if (i != j) return i;
6220
- a = i < 0;
6221
- b = k == l;
6222
- if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
6223
- if (!b) return k > l ^ a ? 1 : -1;
6224
- j = (k = xc.length) < (l = yc.length) ? k : l;
6225
- for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
6226
- return k == l ? 0 : k > l ^ a ? 1 : -1;
6227
- }
6228
- function intCheck(n, min, max, name) {
6229
- if (n < min || n > max || n !== mathfloor(n)) {
6230
- throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
6231
- }
6232
- }
6233
- function isOdd(n) {
6234
- var k = n.c.length - 1;
6235
- return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
6236
- }
6237
- function toExponential(str, e) {
6238
- return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
6239
- }
6240
- function toFixedPoint(str, e, z) {
6241
- var len, zs;
6242
- if (e < 0) {
6243
- for (zs = z + "."; ++e; zs += z) ;
6244
- str = zs + str;
6245
- } else {
6246
- len = str.length;
6247
- if (++e > len) {
6248
- for (zs = z, e -= len; --e; zs += z) ;
6249
- str += zs;
6250
- } else if (e < len) {
6251
- str = str.slice(0, e) + "." + str.slice(e);
6252
- }
6253
- }
6254
- return str;
6255
- }
6256
- var BigNumber = clone();
6257
- var bignumber_default = BigNumber;
4915
+ // src/cpmm/cpmm.ts
4916
+ var import_bignumber = __toESM(require("bignumber.js"));
6258
4917
 
6259
4918
  // src/common/math.ts
6260
4919
  var MathUtil = class {
@@ -6700,7 +5359,7 @@ var CpmmModule = class _CpmmModule extends ModuleBase {
6700
5359
  const amount1 = liquidityToRemove * state.reserve1 / state.totalSupply;
6701
5360
  const remainShareAmount = totalLiquidity - liquidityToRemove;
6702
5361
  const remainPoolLiquidity = state.totalSupply - liquidityToRemove;
6703
- const remainSharePercentage = bignumber_default((100n * remainShareAmount).toString()).div(bignumber_default(remainPoolLiquidity.toString())).toFixed(5);
5362
+ const remainSharePercentage = (0, import_bignumber.default)((100n * remainShareAmount).toString()).div((0, import_bignumber.default)(remainPoolLiquidity.toString())).toFixed(5);
6704
5363
  return {
6705
5364
  state,
6706
5365
  token0: state.token0Info,
@@ -6731,7 +5390,7 @@ var CpmmModule = class _CpmmModule extends ModuleBase {
6731
5390
  const [reserveIn, reserveOut] = token0Id === tokenInId ? [reserve0, reserve1] : [reserve1, reserve0];
6732
5391
  const numerator = (reserveOut * (reserveIn + amountIn) - (reserveOut - amountOut) * reserveIn) * 100n;
6733
5392
  const denumerator = reserveIn * (reserveOut - amountOut);
6734
- const impact = new bignumber_default(numerator.toString()).div(new bignumber_default(denumerator.toString())).toFixed();
5393
+ const impact = new import_bignumber.default(numerator.toString()).div(new import_bignumber.default(denumerator.toString())).toFixed();
6735
5394
  return parseFloat(impact);
6736
5395
  }
6737
5396
  static getLiquidityDetails(state, inputTokenId, inputAmount, inputType) {
@@ -6742,7 +5401,7 @@ var CpmmModule = class _CpmmModule extends ModuleBase {
6742
5401
  const liquidityB = outputAmount * state.totalSupply / reserveB;
6743
5402
  const liquidity = liquidityA < liquidityB ? liquidityA : liquidityB;
6744
5403
  const totalSupply = state.totalSupply + liquidity;
6745
- const percentage = bignumber_default((100n * liquidity).toString()).div(bignumber_default(totalSupply.toString())).toFixed(5);
5404
+ const percentage = (0, import_bignumber.default)((100n * liquidity).toString()).div((0, import_bignumber.default)(totalSupply.toString())).toFixed(5);
6746
5405
  const sharePercentage = parseFloat(percentage);
6747
5406
  const outputTokenId = isInputToken0 ? state.token1Info.id : state.token0Info.id;
6748
5407
  const [tokenAId, tokenBId] = inputType === "TokenA" ? [inputTokenId, outputTokenId] : [outputTokenId, inputTokenId];
@@ -15622,7 +14281,7 @@ var TickUtils = class {
15622
14281
  }
15623
14282
  static getNextTick(tick, tickSpacing, tokenBase, tokenQuote, baseIn, isAdd) {
15624
14283
  const reverse = tokenBase.id > tokenQuote.id == baseIn;
15625
- const delta = isAdd == reverse ? tickSpacing : -tickSpacing;
14284
+ const delta = isAdd == reverse ? -tickSpacing : tickSpacing;
15626
14285
  return tick + delta;
15627
14286
  }
15628
14287
  static getAlignedPrice(priceIn, tokenBase, tokenQuote, tickSpacing, baseIn) {
@@ -16491,6 +15150,7 @@ var TokenModule = class extends ModuleBase {
16491
15150
  this.scope = scope;
16492
15151
  this.cacheTimeMs = cacheTimeDays * 24 * 60 * 60 * 1e3;
16493
15152
  }
15153
+ cacheTimeDays;
16494
15154
  cache;
16495
15155
  cacheTimeMs;
16496
15156
  async getTokens() {