@proton/wrap-constants 0.2.187 → 0.2.188

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.mjs CHANGED
@@ -1489,7 +1489,6 @@ var initializeConstants = (chain) => {
1489
1489
  VEST_CONTRACT: "vest",
1490
1490
  DEX_CONTRACT: "dex",
1491
1491
  FEE_FACTOR,
1492
- GOOGLE_MAPS_KEY: "AIzaSyDb2_CrK032kSIqBXbkdwmaLKWELl0SxVs",
1493
1492
  SWAP_URL: chain === "proton" ? "https://otc.protonswap.com" : "https://otc-test.protonswap.com",
1494
1493
  WRAP_SERVER_URL: chain === "proton" ? "https://www.api.bloks.io/proton-wrap-public2" : "https://www.api.bloks.io/proton-wrap-testnet-public2",
1495
1494
  WRAP_CONTRACT,
@@ -2507,1497 +2506,24 @@ var Graph = class {
2507
2506
  }
2508
2507
  };
2509
2508
 
2510
- // node_modules/bignumber.js/bignumber.mjs
2511
- var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
2512
- var mathceil = Math.ceil;
2513
- var mathfloor = Math.floor;
2514
- var bignumberError = "[BigNumber Error] ";
2515
- var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
2516
- var BASE = 1e14;
2517
- var LOG_BASE = 14;
2518
- var MAX_SAFE_INTEGER = 9007199254740991;
2519
- var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
2520
- var SQRT_BASE = 1e7;
2521
- var MAX = 1e9;
2522
- function clone(configObject) {
2523
- 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 = {
2524
- prefix: "",
2525
- groupSize: 3,
2526
- secondaryGroupSize: 0,
2527
- groupSeparator: ",",
2528
- decimalSeparator: ".",
2529
- fractionGroupSize: 0,
2530
- fractionGroupSeparator: "\xA0",
2531
- // non-breaking space
2532
- suffix: ""
2533
- }, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
2534
- function BigNumber2(v, b) {
2535
- var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
2536
- if (!(x instanceof BigNumber2))
2537
- return new BigNumber2(v, b);
2538
- if (b == null) {
2539
- if (v && v._isBigNumber === true) {
2540
- x.s = v.s;
2541
- if (!v.c || v.e > MAX_EXP) {
2542
- x.c = x.e = null;
2543
- } else if (v.e < MIN_EXP) {
2544
- x.c = [x.e = 0];
2545
- } else {
2546
- x.e = v.e;
2547
- x.c = v.c.slice();
2548
- }
2549
- return;
2550
- }
2551
- if ((isNum = typeof v == "number") && v * 0 == 0) {
2552
- x.s = 1 / v < 0 ? (v = -v, -1) : 1;
2553
- if (v === ~~v) {
2554
- for (e = 0, i = v; i >= 10; i /= 10, e++)
2555
- ;
2556
- if (e > MAX_EXP) {
2557
- x.c = x.e = null;
2558
- } else {
2559
- x.e = e;
2560
- x.c = [v];
2561
- }
2562
- return;
2563
- }
2564
- str = String(v);
2565
- } else {
2566
- if (!isNumeric.test(str = String(v)))
2567
- return parseNumeric(x, str, isNum);
2568
- x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
2569
- }
2570
- if ((e = str.indexOf(".")) > -1)
2571
- str = str.replace(".", "");
2572
- if ((i = str.search(/e/i)) > 0) {
2573
- if (e < 0)
2574
- e = i;
2575
- e += +str.slice(i + 1);
2576
- str = str.substring(0, i);
2577
- } else if (e < 0) {
2578
- e = str.length;
2579
- }
2580
- } else {
2581
- intCheck(b, 2, ALPHABET.length, "Base");
2582
- if (b == 10 && alphabetHasNormalDecimalDigits) {
2583
- x = new BigNumber2(v);
2584
- return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
2585
- }
2586
- str = String(v);
2587
- if (isNum = typeof v == "number") {
2588
- if (v * 0 != 0)
2589
- return parseNumeric(x, str, isNum, b);
2590
- x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
2591
- if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
2592
- throw Error(tooManyDigits + v);
2593
- }
2594
- } else {
2595
- x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
2596
- }
2597
- alphabet = ALPHABET.slice(0, b);
2598
- e = i = 0;
2599
- for (len = str.length; i < len; i++) {
2600
- if (alphabet.indexOf(c = str.charAt(i)) < 0) {
2601
- if (c == ".") {
2602
- if (i > e) {
2603
- e = len;
2604
- continue;
2605
- }
2606
- } else if (!caseChanged) {
2607
- if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
2608
- caseChanged = true;
2609
- i = -1;
2610
- e = 0;
2611
- continue;
2612
- }
2613
- }
2614
- return parseNumeric(x, String(v), isNum, b);
2615
- }
2616
- }
2617
- isNum = false;
2618
- str = convertBase(str, b, 10, x.s);
2619
- if ((e = str.indexOf(".")) > -1)
2620
- str = str.replace(".", "");
2621
- else
2622
- e = str.length;
2623
- }
2624
- for (i = 0; str.charCodeAt(i) === 48; i++)
2625
- ;
2626
- for (len = str.length; str.charCodeAt(--len) === 48; )
2627
- ;
2628
- if (str = str.slice(i, ++len)) {
2629
- len -= i;
2630
- if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
2631
- throw Error(tooManyDigits + x.s * v);
2632
- }
2633
- if ((e = e - i - 1) > MAX_EXP) {
2634
- x.c = x.e = null;
2635
- } else if (e < MIN_EXP) {
2636
- x.c = [x.e = 0];
2637
- } else {
2638
- x.e = e;
2639
- x.c = [];
2640
- i = (e + 1) % LOG_BASE;
2641
- if (e < 0)
2642
- i += LOG_BASE;
2643
- if (i < len) {
2644
- if (i)
2645
- x.c.push(+str.slice(0, i));
2646
- for (len -= LOG_BASE; i < len; ) {
2647
- x.c.push(+str.slice(i, i += LOG_BASE));
2648
- }
2649
- i = LOG_BASE - (str = str.slice(i)).length;
2650
- } else {
2651
- i -= len;
2652
- }
2653
- for (; i--; str += "0")
2654
- ;
2655
- x.c.push(+str);
2656
- }
2657
- } else {
2658
- x.c = [x.e = 0];
2659
- }
2660
- }
2661
- BigNumber2.clone = clone;
2662
- BigNumber2.ROUND_UP = 0;
2663
- BigNumber2.ROUND_DOWN = 1;
2664
- BigNumber2.ROUND_CEIL = 2;
2665
- BigNumber2.ROUND_FLOOR = 3;
2666
- BigNumber2.ROUND_HALF_UP = 4;
2667
- BigNumber2.ROUND_HALF_DOWN = 5;
2668
- BigNumber2.ROUND_HALF_EVEN = 6;
2669
- BigNumber2.ROUND_HALF_CEIL = 7;
2670
- BigNumber2.ROUND_HALF_FLOOR = 8;
2671
- BigNumber2.EUCLID = 9;
2672
- BigNumber2.config = BigNumber2.set = function(obj) {
2673
- var p, v;
2674
- if (obj != null) {
2675
- if (typeof obj == "object") {
2676
- if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
2677
- v = obj[p];
2678
- intCheck(v, 0, MAX, p);
2679
- DECIMAL_PLACES = v;
2680
- }
2681
- if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
2682
- v = obj[p];
2683
- intCheck(v, 0, 8, p);
2684
- ROUNDING_MODE = v;
2685
- }
2686
- if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
2687
- v = obj[p];
2688
- if (v && v.pop) {
2689
- intCheck(v[0], -MAX, 0, p);
2690
- intCheck(v[1], 0, MAX, p);
2691
- TO_EXP_NEG = v[0];
2692
- TO_EXP_POS = v[1];
2693
- } else {
2694
- intCheck(v, -MAX, MAX, p);
2695
- TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
2696
- }
2697
- }
2698
- if (obj.hasOwnProperty(p = "RANGE")) {
2699
- v = obj[p];
2700
- if (v && v.pop) {
2701
- intCheck(v[0], -MAX, -1, p);
2702
- intCheck(v[1], 1, MAX, p);
2703
- MIN_EXP = v[0];
2704
- MAX_EXP = v[1];
2705
- } else {
2706
- intCheck(v, -MAX, MAX, p);
2707
- if (v) {
2708
- MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
2709
- } else {
2710
- throw Error(bignumberError + p + " cannot be zero: " + v);
2711
- }
2712
- }
2713
- }
2714
- if (obj.hasOwnProperty(p = "CRYPTO")) {
2715
- v = obj[p];
2716
- if (v === !!v) {
2717
- if (v) {
2718
- if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
2719
- CRYPTO = v;
2720
- } else {
2721
- CRYPTO = !v;
2722
- throw Error(bignumberError + "crypto unavailable");
2723
- }
2724
- } else {
2725
- CRYPTO = v;
2726
- }
2727
- } else {
2728
- throw Error(bignumberError + p + " not true or false: " + v);
2729
- }
2730
- }
2731
- if (obj.hasOwnProperty(p = "MODULO_MODE")) {
2732
- v = obj[p];
2733
- intCheck(v, 0, 9, p);
2734
- MODULO_MODE = v;
2735
- }
2736
- if (obj.hasOwnProperty(p = "POW_PRECISION")) {
2737
- v = obj[p];
2738
- intCheck(v, 0, MAX, p);
2739
- POW_PRECISION = v;
2740
- }
2741
- if (obj.hasOwnProperty(p = "FORMAT")) {
2742
- v = obj[p];
2743
- if (typeof v == "object")
2744
- FORMAT = v;
2745
- else
2746
- throw Error(bignumberError + p + " not an object: " + v);
2747
- }
2748
- if (obj.hasOwnProperty(p = "ALPHABET")) {
2749
- v = obj[p];
2750
- if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
2751
- alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
2752
- ALPHABET = v;
2753
- } else {
2754
- throw Error(bignumberError + p + " invalid: " + v);
2755
- }
2756
- }
2757
- } else {
2758
- throw Error(bignumberError + "Object expected: " + obj);
2759
- }
2760
- }
2761
- return {
2762
- DECIMAL_PLACES,
2763
- ROUNDING_MODE,
2764
- EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
2765
- RANGE: [MIN_EXP, MAX_EXP],
2766
- CRYPTO,
2767
- MODULO_MODE,
2768
- POW_PRECISION,
2769
- FORMAT,
2770
- ALPHABET
2771
- };
2772
- };
2773
- BigNumber2.isBigNumber = function(v) {
2774
- if (!v || v._isBigNumber !== true)
2775
- return false;
2776
- if (!BigNumber2.DEBUG)
2777
- return true;
2778
- var i, n, c = v.c, e = v.e, s = v.s;
2779
- out:
2780
- if ({}.toString.call(c) == "[object Array]") {
2781
- if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
2782
- if (c[0] === 0) {
2783
- if (e === 0 && c.length === 1)
2784
- return true;
2785
- break out;
2786
- }
2787
- i = (e + 1) % LOG_BASE;
2788
- if (i < 1)
2789
- i += LOG_BASE;
2790
- if (String(c[0]).length == i) {
2791
- for (i = 0; i < c.length; i++) {
2792
- n = c[i];
2793
- if (n < 0 || n >= BASE || n !== mathfloor(n))
2794
- break out;
2795
- }
2796
- if (n !== 0)
2797
- return true;
2798
- }
2799
- }
2800
- } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
2801
- return true;
2802
- }
2803
- throw Error(bignumberError + "Invalid BigNumber: " + v);
2804
- };
2805
- BigNumber2.maximum = BigNumber2.max = function() {
2806
- return maxOrMin(arguments, -1);
2807
- };
2808
- BigNumber2.minimum = BigNumber2.min = function() {
2809
- return maxOrMin(arguments, 1);
2810
- };
2811
- BigNumber2.random = function() {
2812
- var pow2_53 = 9007199254740992;
2813
- var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
2814
- return mathfloor(Math.random() * pow2_53);
2815
- } : function() {
2816
- return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
2817
- };
2818
- return function(dp) {
2819
- var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
2820
- if (dp == null)
2821
- dp = DECIMAL_PLACES;
2822
- else
2823
- intCheck(dp, 0, MAX);
2824
- k = mathceil(dp / LOG_BASE);
2825
- if (CRYPTO) {
2826
- if (crypto.getRandomValues) {
2827
- a = crypto.getRandomValues(new Uint32Array(k *= 2));
2828
- for (; i < k; ) {
2829
- v = a[i] * 131072 + (a[i + 1] >>> 11);
2830
- if (v >= 9e15) {
2831
- b = crypto.getRandomValues(new Uint32Array(2));
2832
- a[i] = b[0];
2833
- a[i + 1] = b[1];
2834
- } else {
2835
- c.push(v % 1e14);
2836
- i += 2;
2837
- }
2838
- }
2839
- i = k / 2;
2840
- } else if (crypto.randomBytes) {
2841
- a = crypto.randomBytes(k *= 7);
2842
- for (; i < k; ) {
2843
- 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];
2844
- if (v >= 9e15) {
2845
- crypto.randomBytes(7).copy(a, i);
2846
- } else {
2847
- c.push(v % 1e14);
2848
- i += 7;
2849
- }
2850
- }
2851
- i = k / 7;
2852
- } else {
2853
- CRYPTO = false;
2854
- throw Error(bignumberError + "crypto unavailable");
2855
- }
2856
- }
2857
- if (!CRYPTO) {
2858
- for (; i < k; ) {
2859
- v = random53bitInt();
2860
- if (v < 9e15)
2861
- c[i++] = v % 1e14;
2862
- }
2863
- }
2864
- k = c[--i];
2865
- dp %= LOG_BASE;
2866
- if (k && dp) {
2867
- v = POWS_TEN[LOG_BASE - dp];
2868
- c[i] = mathfloor(k / v) * v;
2869
- }
2870
- for (; c[i] === 0; c.pop(), i--)
2871
- ;
2872
- if (i < 0) {
2873
- c = [e = 0];
2874
- } else {
2875
- for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE)
2876
- ;
2877
- for (i = 1, v = c[0]; v >= 10; v /= 10, i++)
2878
- ;
2879
- if (i < LOG_BASE)
2880
- e -= LOG_BASE - i;
2881
- }
2882
- rand.e = e;
2883
- rand.c = c;
2884
- return rand;
2885
- };
2886
- }();
2887
- BigNumber2.sum = function() {
2888
- var i = 1, args = arguments, sum = new BigNumber2(args[0]);
2889
- for (; i < args.length; )
2890
- sum = sum.plus(args[i++]);
2891
- return sum;
2892
- };
2893
- convertBase = function() {
2894
- var decimal = "0123456789";
2895
- function toBaseOut(str, baseIn, baseOut, alphabet) {
2896
- var j, arr = [0], arrL, i = 0, len = str.length;
2897
- for (; i < len; ) {
2898
- for (arrL = arr.length; arrL--; arr[arrL] *= baseIn)
2899
- ;
2900
- arr[0] += alphabet.indexOf(str.charAt(i++));
2901
- for (j = 0; j < arr.length; j++) {
2902
- if (arr[j] > baseOut - 1) {
2903
- if (arr[j + 1] == null)
2904
- arr[j + 1] = 0;
2905
- arr[j + 1] += arr[j] / baseOut | 0;
2906
- arr[j] %= baseOut;
2907
- }
2908
- }
2909
- }
2910
- return arr.reverse();
2911
- }
2912
- return function(str, baseIn, baseOut, sign, callerIsToString) {
2913
- var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
2914
- if (i >= 0) {
2915
- k = POW_PRECISION;
2916
- POW_PRECISION = 0;
2917
- str = str.replace(".", "");
2918
- y = new BigNumber2(baseIn);
2919
- x = y.pow(str.length - i);
2920
- POW_PRECISION = k;
2921
- y.c = toBaseOut(
2922
- toFixedPoint(coeffToString(x.c), x.e, "0"),
2923
- 10,
2924
- baseOut,
2925
- decimal
2926
- );
2927
- y.e = y.c.length;
2928
- }
2929
- xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
2930
- e = k = xc.length;
2931
- for (; xc[--k] == 0; xc.pop())
2932
- ;
2933
- if (!xc[0])
2934
- return alphabet.charAt(0);
2935
- if (i < 0) {
2936
- --e;
2937
- } else {
2938
- x.c = xc;
2939
- x.e = e;
2940
- x.s = sign;
2941
- x = div(x, y, dp, rm, baseOut);
2942
- xc = x.c;
2943
- r = x.r;
2944
- e = x.e;
2945
- }
2946
- d = e + dp + 1;
2947
- i = xc[d];
2948
- k = baseOut / 2;
2949
- r = r || d < 0 || xc[d + 1] != null;
2950
- 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));
2951
- if (d < 1 || !xc[0]) {
2952
- str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
2953
- } else {
2954
- xc.length = d;
2955
- if (r) {
2956
- for (--baseOut; ++xc[--d] > baseOut; ) {
2957
- xc[d] = 0;
2958
- if (!d) {
2959
- ++e;
2960
- xc = [1].concat(xc);
2961
- }
2962
- }
2963
- }
2964
- for (k = xc.length; !xc[--k]; )
2965
- ;
2966
- for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++]))
2967
- ;
2968
- str = toFixedPoint(str, e, alphabet.charAt(0));
2969
- }
2970
- return str;
2971
- };
2972
- }();
2973
- div = function() {
2974
- function multiply(x, k, base) {
2975
- var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
2976
- for (x = x.slice(); i--; ) {
2977
- xlo = x[i] % SQRT_BASE;
2978
- xhi = x[i] / SQRT_BASE | 0;
2979
- m = khi * xlo + xhi * klo;
2980
- temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
2981
- carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
2982
- x[i] = temp % base;
2983
- }
2984
- if (carry)
2985
- x = [carry].concat(x);
2986
- return x;
2987
- }
2988
- function compare2(a, b, aL, bL) {
2989
- var i, cmp;
2990
- if (aL != bL) {
2991
- cmp = aL > bL ? 1 : -1;
2992
- } else {
2993
- for (i = cmp = 0; i < aL; i++) {
2994
- if (a[i] != b[i]) {
2995
- cmp = a[i] > b[i] ? 1 : -1;
2996
- break;
2997
- }
2998
- }
2999
- }
3000
- return cmp;
3001
- }
3002
- function subtract(a, b, aL, base) {
3003
- var i = 0;
3004
- for (; aL--; ) {
3005
- a[aL] -= i;
3006
- i = a[aL] < b[aL] ? 1 : 0;
3007
- a[aL] = i * base + a[aL] - b[aL];
3008
- }
3009
- for (; !a[0] && a.length > 1; a.splice(0, 1))
3010
- ;
3011
- }
3012
- return function(x, y, dp, rm, base) {
3013
- 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;
3014
- if (!xc || !xc[0] || !yc || !yc[0]) {
3015
- return new BigNumber2(
3016
- // Return NaN if either NaN, or both Infinity or 0.
3017
- !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
3018
- // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
3019
- xc && xc[0] == 0 || !yc ? s * 0 : s / 0
3020
- )
3021
- );
3022
- }
3023
- q = new BigNumber2(s);
3024
- qc = q.c = [];
3025
- e = x.e - y.e;
3026
- s = dp + e + 1;
3027
- if (!base) {
3028
- base = BASE;
3029
- e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
3030
- s = s / LOG_BASE | 0;
3031
- }
3032
- for (i = 0; yc[i] == (xc[i] || 0); i++)
3033
- ;
3034
- if (yc[i] > (xc[i] || 0))
3035
- e--;
3036
- if (s < 0) {
3037
- qc.push(1);
3038
- more = true;
3039
- } else {
3040
- xL = xc.length;
3041
- yL = yc.length;
3042
- i = 0;
3043
- s += 2;
3044
- n = mathfloor(base / (yc[0] + 1));
3045
- if (n > 1) {
3046
- yc = multiply(yc, n, base);
3047
- xc = multiply(xc, n, base);
3048
- yL = yc.length;
3049
- xL = xc.length;
3050
- }
3051
- xi = yL;
3052
- rem = xc.slice(0, yL);
3053
- remL = rem.length;
3054
- for (; remL < yL; rem[remL++] = 0)
3055
- ;
3056
- yz = yc.slice();
3057
- yz = [0].concat(yz);
3058
- yc0 = yc[0];
3059
- if (yc[1] >= base / 2)
3060
- yc0++;
3061
- do {
3062
- n = 0;
3063
- cmp = compare2(yc, rem, yL, remL);
3064
- if (cmp < 0) {
3065
- rem0 = rem[0];
3066
- if (yL != remL)
3067
- rem0 = rem0 * base + (rem[1] || 0);
3068
- n = mathfloor(rem0 / yc0);
3069
- if (n > 1) {
3070
- if (n >= base)
3071
- n = base - 1;
3072
- prod = multiply(yc, n, base);
3073
- prodL = prod.length;
3074
- remL = rem.length;
3075
- while (compare2(prod, rem, prodL, remL) == 1) {
3076
- n--;
3077
- subtract(prod, yL < prodL ? yz : yc, prodL, base);
3078
- prodL = prod.length;
3079
- cmp = 1;
3080
- }
3081
- } else {
3082
- if (n == 0) {
3083
- cmp = n = 1;
3084
- }
3085
- prod = yc.slice();
3086
- prodL = prod.length;
3087
- }
3088
- if (prodL < remL)
3089
- prod = [0].concat(prod);
3090
- subtract(rem, prod, remL, base);
3091
- remL = rem.length;
3092
- if (cmp == -1) {
3093
- while (compare2(yc, rem, yL, remL) < 1) {
3094
- n++;
3095
- subtract(rem, yL < remL ? yz : yc, remL, base);
3096
- remL = rem.length;
3097
- }
3098
- }
3099
- } else if (cmp === 0) {
3100
- n++;
3101
- rem = [0];
3102
- }
3103
- qc[i++] = n;
3104
- if (rem[0]) {
3105
- rem[remL++] = xc[xi] || 0;
3106
- } else {
3107
- rem = [xc[xi]];
3108
- remL = 1;
3109
- }
3110
- } while ((xi++ < xL || rem[0] != null) && s--);
3111
- more = rem[0] != null;
3112
- if (!qc[0])
3113
- qc.splice(0, 1);
3114
- }
3115
- if (base == BASE) {
3116
- for (i = 1, s = qc[0]; s >= 10; s /= 10, i++)
3117
- ;
3118
- round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
3119
- } else {
3120
- q.e = e;
3121
- q.r = +more;
3122
- }
3123
- return q;
3124
- };
3125
- }();
3126
- function format(n, i, rm, id) {
3127
- var c0, e, ne, len, str;
3128
- if (rm == null)
3129
- rm = ROUNDING_MODE;
3130
- else
3131
- intCheck(rm, 0, 8);
3132
- if (!n.c)
3133
- return n.toString();
3134
- c0 = n.c[0];
3135
- ne = n.e;
3136
- if (i == null) {
3137
- str = coeffToString(n.c);
3138
- str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
3139
- } else {
3140
- n = round(new BigNumber2(n), i, rm);
3141
- e = n.e;
3142
- str = coeffToString(n.c);
3143
- len = str.length;
3144
- if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
3145
- for (; len < i; str += "0", len++)
3146
- ;
3147
- str = toExponential(str, e);
3148
- } else {
3149
- i -= ne;
3150
- str = toFixedPoint(str, e, "0");
3151
- if (e + 1 > len) {
3152
- if (--i > 0)
3153
- for (str += "."; i--; str += "0")
3154
- ;
3155
- } else {
3156
- i += e - len;
3157
- if (i > 0) {
3158
- if (e + 1 == len)
3159
- str += ".";
3160
- for (; i--; str += "0")
3161
- ;
3162
- }
3163
- }
3164
- }
3165
- }
3166
- return n.s < 0 && c0 ? "-" + str : str;
3167
- }
3168
- function maxOrMin(args, n) {
3169
- var k, y, i = 1, x = new BigNumber2(args[0]);
3170
- for (; i < args.length; i++) {
3171
- y = new BigNumber2(args[i]);
3172
- if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
3173
- x = y;
3174
- }
3175
- }
3176
- return x;
3177
- }
3178
- function normalise(n, c, e) {
3179
- var i = 1, j = c.length;
3180
- for (; !c[--j]; c.pop())
3181
- ;
3182
- for (j = c[0]; j >= 10; j /= 10, i++)
3183
- ;
3184
- if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
3185
- n.c = n.e = null;
3186
- } else if (e < MIN_EXP) {
3187
- n.c = [n.e = 0];
3188
- } else {
3189
- n.e = e;
3190
- n.c = c;
3191
- }
3192
- return n;
3193
- }
3194
- parseNumeric = function() {
3195
- var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
3196
- return function(x, str, isNum, b) {
3197
- var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
3198
- if (isInfinityOrNaN.test(s)) {
3199
- x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
3200
- } else {
3201
- if (!isNum) {
3202
- s = s.replace(basePrefix, function(m, p1, p2) {
3203
- base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
3204
- return !b || b == base ? p1 : m;
3205
- });
3206
- if (b) {
3207
- base = b;
3208
- s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
3209
- }
3210
- if (str != s)
3211
- return new BigNumber2(s, base);
3212
- }
3213
- if (BigNumber2.DEBUG) {
3214
- throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
3215
- }
3216
- x.s = null;
3217
- }
3218
- x.c = x.e = null;
3219
- };
3220
- }();
3221
- function round(x, sd, rm, r) {
3222
- var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
3223
- if (xc) {
3224
- out: {
3225
- for (d = 1, k = xc[0]; k >= 10; k /= 10, d++)
3226
- ;
3227
- i = sd - d;
3228
- if (i < 0) {
3229
- i += LOG_BASE;
3230
- j = sd;
3231
- n = xc[ni = 0];
3232
- rd = mathfloor(n / pows10[d - j - 1] % 10);
3233
- } else {
3234
- ni = mathceil((i + 1) / LOG_BASE);
3235
- if (ni >= xc.length) {
3236
- if (r) {
3237
- for (; xc.length <= ni; xc.push(0))
3238
- ;
3239
- n = rd = 0;
3240
- d = 1;
3241
- i %= LOG_BASE;
3242
- j = i - LOG_BASE + 1;
3243
- } else {
3244
- break out;
3245
- }
3246
- } else {
3247
- n = k = xc[ni];
3248
- for (d = 1; k >= 10; k /= 10, d++)
3249
- ;
3250
- i %= LOG_BASE;
3251
- j = i - LOG_BASE + d;
3252
- rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
3253
- }
3254
- }
3255
- r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
3256
- // The expression n % pows10[d - j - 1] returns all digits of n to the right
3257
- // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
3258
- xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
3259
- 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.
3260
- (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
3261
- if (sd < 1 || !xc[0]) {
3262
- xc.length = 0;
3263
- if (r) {
3264
- sd -= x.e + 1;
3265
- xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
3266
- x.e = -sd || 0;
3267
- } else {
3268
- xc[0] = x.e = 0;
3269
- }
3270
- return x;
3271
- }
3272
- if (i == 0) {
3273
- xc.length = ni;
3274
- k = 1;
3275
- ni--;
3276
- } else {
3277
- xc.length = ni + 1;
3278
- k = pows10[LOG_BASE - i];
3279
- xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
3280
- }
3281
- if (r) {
3282
- for (; ; ) {
3283
- if (ni == 0) {
3284
- for (i = 1, j = xc[0]; j >= 10; j /= 10, i++)
3285
- ;
3286
- j = xc[0] += k;
3287
- for (k = 1; j >= 10; j /= 10, k++)
3288
- ;
3289
- if (i != k) {
3290
- x.e++;
3291
- if (xc[0] == BASE)
3292
- xc[0] = 1;
3293
- }
3294
- break;
3295
- } else {
3296
- xc[ni] += k;
3297
- if (xc[ni] != BASE)
3298
- break;
3299
- xc[ni--] = 0;
3300
- k = 1;
3301
- }
3302
- }
3303
- }
3304
- for (i = xc.length; xc[--i] === 0; xc.pop())
3305
- ;
3306
- }
3307
- if (x.e > MAX_EXP) {
3308
- x.c = x.e = null;
3309
- } else if (x.e < MIN_EXP) {
3310
- x.c = [x.e = 0];
3311
- }
3312
- }
3313
- return x;
3314
- }
3315
- function valueOf(n) {
3316
- var str, e = n.e;
3317
- if (e === null)
3318
- return n.toString();
3319
- str = coeffToString(n.c);
3320
- str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
3321
- return n.s < 0 ? "-" + str : str;
3322
- }
3323
- P.absoluteValue = P.abs = function() {
3324
- var x = new BigNumber2(this);
3325
- if (x.s < 0)
3326
- x.s = 1;
3327
- return x;
3328
- };
3329
- P.comparedTo = function(y, b) {
3330
- return compare(this, new BigNumber2(y, b));
3331
- };
3332
- P.decimalPlaces = P.dp = function(dp, rm) {
3333
- var c, n, v, x = this;
3334
- if (dp != null) {
3335
- intCheck(dp, 0, MAX);
3336
- if (rm == null)
3337
- rm = ROUNDING_MODE;
3338
- else
3339
- intCheck(rm, 0, 8);
3340
- return round(new BigNumber2(x), dp + x.e + 1, rm);
3341
- }
3342
- if (!(c = x.c))
3343
- return null;
3344
- n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
3345
- if (v = c[v])
3346
- for (; v % 10 == 0; v /= 10, n--)
3347
- ;
3348
- if (n < 0)
3349
- n = 0;
3350
- return n;
3351
- };
3352
- P.dividedBy = P.div = function(y, b) {
3353
- return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
3354
- };
3355
- P.dividedToIntegerBy = P.idiv = function(y, b) {
3356
- return div(this, new BigNumber2(y, b), 0, 1);
3357
- };
3358
- P.exponentiatedBy = P.pow = function(n, m) {
3359
- var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
3360
- n = new BigNumber2(n);
3361
- if (n.c && !n.isInteger()) {
3362
- throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
3363
- }
3364
- if (m != null)
3365
- m = new BigNumber2(m);
3366
- nIsBig = n.e > 14;
3367
- if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
3368
- y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
3369
- return m ? y.mod(m) : y;
3370
- }
3371
- nIsNeg = n.s < 0;
3372
- if (m) {
3373
- if (m.c ? !m.c[0] : !m.s)
3374
- return new BigNumber2(NaN);
3375
- isModExp = !nIsNeg && x.isInteger() && m.isInteger();
3376
- if (isModExp)
3377
- x = x.mod(m);
3378
- } 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))) {
3379
- k = x.s < 0 && isOdd(n) ? -0 : 0;
3380
- if (x.e > -1)
3381
- k = 1 / k;
3382
- return new BigNumber2(nIsNeg ? 1 / k : k);
3383
- } else if (POW_PRECISION) {
3384
- k = mathceil(POW_PRECISION / LOG_BASE + 2);
3385
- }
3386
- if (nIsBig) {
3387
- half = new BigNumber2(0.5);
3388
- if (nIsNeg)
3389
- n.s = 1;
3390
- nIsOdd = isOdd(n);
3391
- } else {
3392
- i = Math.abs(+valueOf(n));
3393
- nIsOdd = i % 2;
3394
- }
3395
- y = new BigNumber2(ONE);
3396
- for (; ; ) {
3397
- if (nIsOdd) {
3398
- y = y.times(x);
3399
- if (!y.c)
3400
- break;
3401
- if (k) {
3402
- if (y.c.length > k)
3403
- y.c.length = k;
3404
- } else if (isModExp) {
3405
- y = y.mod(m);
3406
- }
3407
- }
3408
- if (i) {
3409
- i = mathfloor(i / 2);
3410
- if (i === 0)
3411
- break;
3412
- nIsOdd = i % 2;
3413
- } else {
3414
- n = n.times(half);
3415
- round(n, n.e + 1, 1);
3416
- if (n.e > 14) {
3417
- nIsOdd = isOdd(n);
3418
- } else {
3419
- i = +valueOf(n);
3420
- if (i === 0)
3421
- break;
3422
- nIsOdd = i % 2;
3423
- }
3424
- }
3425
- x = x.times(x);
3426
- if (k) {
3427
- if (x.c && x.c.length > k)
3428
- x.c.length = k;
3429
- } else if (isModExp) {
3430
- x = x.mod(m);
3431
- }
3432
- }
3433
- if (isModExp)
3434
- return y;
3435
- if (nIsNeg)
3436
- y = ONE.div(y);
3437
- return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
3438
- };
3439
- P.integerValue = function(rm) {
3440
- var n = new BigNumber2(this);
3441
- if (rm == null)
3442
- rm = ROUNDING_MODE;
3443
- else
3444
- intCheck(rm, 0, 8);
3445
- return round(n, n.e + 1, rm);
3446
- };
3447
- P.isEqualTo = P.eq = function(y, b) {
3448
- return compare(this, new BigNumber2(y, b)) === 0;
3449
- };
3450
- P.isFinite = function() {
3451
- return !!this.c;
3452
- };
3453
- P.isGreaterThan = P.gt = function(y, b) {
3454
- return compare(this, new BigNumber2(y, b)) > 0;
3455
- };
3456
- P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
3457
- return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
3458
- };
3459
- P.isInteger = function() {
3460
- return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
3461
- };
3462
- P.isLessThan = P.lt = function(y, b) {
3463
- return compare(this, new BigNumber2(y, b)) < 0;
3464
- };
3465
- P.isLessThanOrEqualTo = P.lte = function(y, b) {
3466
- return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
3467
- };
3468
- P.isNaN = function() {
3469
- return !this.s;
3470
- };
3471
- P.isNegative = function() {
3472
- return this.s < 0;
3473
- };
3474
- P.isPositive = function() {
3475
- return this.s > 0;
3476
- };
3477
- P.isZero = function() {
3478
- return !!this.c && this.c[0] == 0;
3479
- };
3480
- P.minus = function(y, b) {
3481
- var i, j, t, xLTy, x = this, a = x.s;
3482
- y = new BigNumber2(y, b);
3483
- b = y.s;
3484
- if (!a || !b)
3485
- return new BigNumber2(NaN);
3486
- if (a != b) {
3487
- y.s = -b;
3488
- return x.plus(y);
3489
- }
3490
- var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
3491
- if (!xe || !ye) {
3492
- if (!xc || !yc)
3493
- return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
3494
- if (!xc[0] || !yc[0]) {
3495
- return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : (
3496
- // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
3497
- ROUNDING_MODE == 3 ? -0 : 0
3498
- ));
3499
- }
3500
- }
3501
- xe = bitFloor(xe);
3502
- ye = bitFloor(ye);
3503
- xc = xc.slice();
3504
- if (a = xe - ye) {
3505
- if (xLTy = a < 0) {
3506
- a = -a;
3507
- t = xc;
3508
- } else {
3509
- ye = xe;
3510
- t = yc;
3511
- }
3512
- t.reverse();
3513
- for (b = a; b--; t.push(0))
3514
- ;
3515
- t.reverse();
3516
- } else {
3517
- j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
3518
- for (a = b = 0; b < j; b++) {
3519
- if (xc[b] != yc[b]) {
3520
- xLTy = xc[b] < yc[b];
3521
- break;
3522
- }
3523
- }
3524
- }
3525
- if (xLTy) {
3526
- t = xc;
3527
- xc = yc;
3528
- yc = t;
3529
- y.s = -y.s;
3530
- }
3531
- b = (j = yc.length) - (i = xc.length);
3532
- if (b > 0)
3533
- for (; b--; xc[i++] = 0)
3534
- ;
3535
- b = BASE - 1;
3536
- for (; j > a; ) {
3537
- if (xc[--j] < yc[j]) {
3538
- for (i = j; i && !xc[--i]; xc[i] = b)
3539
- ;
3540
- --xc[i];
3541
- xc[j] += BASE;
3542
- }
3543
- xc[j] -= yc[j];
3544
- }
3545
- for (; xc[0] == 0; xc.splice(0, 1), --ye)
3546
- ;
3547
- if (!xc[0]) {
3548
- y.s = ROUNDING_MODE == 3 ? -1 : 1;
3549
- y.c = [y.e = 0];
3550
- return y;
3551
- }
3552
- return normalise(y, xc, ye);
3553
- };
3554
- P.modulo = P.mod = function(y, b) {
3555
- var q, s, x = this;
3556
- y = new BigNumber2(y, b);
3557
- if (!x.c || !y.s || y.c && !y.c[0]) {
3558
- return new BigNumber2(NaN);
3559
- } else if (!y.c || x.c && !x.c[0]) {
3560
- return new BigNumber2(x);
3561
- }
3562
- if (MODULO_MODE == 9) {
3563
- s = y.s;
3564
- y.s = 1;
3565
- q = div(x, y, 0, 3);
3566
- y.s = s;
3567
- q.s *= s;
3568
- } else {
3569
- q = div(x, y, 0, MODULO_MODE);
3570
- }
3571
- y = x.minus(q.times(y));
3572
- if (!y.c[0] && MODULO_MODE == 1)
3573
- y.s = x.s;
3574
- return y;
3575
- };
3576
- P.multipliedBy = P.times = function(y, b) {
3577
- 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;
3578
- if (!xc || !yc || !xc[0] || !yc[0]) {
3579
- if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
3580
- y.c = y.e = y.s = null;
3581
- } else {
3582
- y.s *= x.s;
3583
- if (!xc || !yc) {
3584
- y.c = y.e = null;
3585
- } else {
3586
- y.c = [0];
3587
- y.e = 0;
3588
- }
3589
- }
3590
- return y;
3591
- }
3592
- e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
3593
- y.s *= x.s;
3594
- xcL = xc.length;
3595
- ycL = yc.length;
3596
- if (xcL < ycL) {
3597
- zc = xc;
3598
- xc = yc;
3599
- yc = zc;
3600
- i = xcL;
3601
- xcL = ycL;
3602
- ycL = i;
3603
- }
3604
- for (i = xcL + ycL, zc = []; i--; zc.push(0))
3605
- ;
3606
- base = BASE;
3607
- sqrtBase = SQRT_BASE;
3608
- for (i = ycL; --i >= 0; ) {
3609
- c = 0;
3610
- ylo = yc[i] % sqrtBase;
3611
- yhi = yc[i] / sqrtBase | 0;
3612
- for (k = xcL, j = i + k; j > i; ) {
3613
- xlo = xc[--k] % sqrtBase;
3614
- xhi = xc[k] / sqrtBase | 0;
3615
- m = yhi * xlo + xhi * ylo;
3616
- xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
3617
- c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
3618
- zc[j--] = xlo % base;
3619
- }
3620
- zc[j] = c;
3621
- }
3622
- if (c) {
3623
- ++e;
3624
- } else {
3625
- zc.splice(0, 1);
3626
- }
3627
- return normalise(y, zc, e);
3628
- };
3629
- P.negated = function() {
3630
- var x = new BigNumber2(this);
3631
- x.s = -x.s || null;
3632
- return x;
3633
- };
3634
- P.plus = function(y, b) {
3635
- var t, x = this, a = x.s;
3636
- y = new BigNumber2(y, b);
3637
- b = y.s;
3638
- if (!a || !b)
3639
- return new BigNumber2(NaN);
3640
- if (a != b) {
3641
- y.s = -b;
3642
- return x.minus(y);
3643
- }
3644
- var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
3645
- if (!xe || !ye) {
3646
- if (!xc || !yc)
3647
- return new BigNumber2(a / 0);
3648
- if (!xc[0] || !yc[0])
3649
- return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
3650
- }
3651
- xe = bitFloor(xe);
3652
- ye = bitFloor(ye);
3653
- xc = xc.slice();
3654
- if (a = xe - ye) {
3655
- if (a > 0) {
3656
- ye = xe;
3657
- t = yc;
3658
- } else {
3659
- a = -a;
3660
- t = xc;
3661
- }
3662
- t.reverse();
3663
- for (; a--; t.push(0))
3664
- ;
3665
- t.reverse();
3666
- }
3667
- a = xc.length;
3668
- b = yc.length;
3669
- if (a - b < 0) {
3670
- t = yc;
3671
- yc = xc;
3672
- xc = t;
3673
- b = a;
3674
- }
3675
- for (a = 0; b; ) {
3676
- a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
3677
- xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
3678
- }
3679
- if (a) {
3680
- xc = [a].concat(xc);
3681
- ++ye;
3682
- }
3683
- return normalise(y, xc, ye);
3684
- };
3685
- P.precision = P.sd = function(sd, rm) {
3686
- var c, n, v, x = this;
3687
- if (sd != null && sd !== !!sd) {
3688
- intCheck(sd, 1, MAX);
3689
- if (rm == null)
3690
- rm = ROUNDING_MODE;
3691
- else
3692
- intCheck(rm, 0, 8);
3693
- return round(new BigNumber2(x), sd, rm);
3694
- }
3695
- if (!(c = x.c))
3696
- return null;
3697
- v = c.length - 1;
3698
- n = v * LOG_BASE + 1;
3699
- if (v = c[v]) {
3700
- for (; v % 10 == 0; v /= 10, n--)
3701
- ;
3702
- for (v = c[0]; v >= 10; v /= 10, n++)
3703
- ;
3704
- }
3705
- if (sd && x.e + 1 > n)
3706
- n = x.e + 1;
3707
- return n;
3708
- };
3709
- P.shiftedBy = function(k) {
3710
- intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
3711
- return this.times("1e" + k);
3712
- };
3713
- P.squareRoot = P.sqrt = function() {
3714
- 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");
3715
- if (s !== 1 || !c || !c[0]) {
3716
- return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
3717
- }
3718
- s = Math.sqrt(+valueOf(x));
3719
- if (s == 0 || s == 1 / 0) {
3720
- n = coeffToString(c);
3721
- if ((n.length + e) % 2 == 0)
3722
- n += "0";
3723
- s = Math.sqrt(+n);
3724
- e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
3725
- if (s == 1 / 0) {
3726
- n = "5e" + e;
3727
- } else {
3728
- n = s.toExponential();
3729
- n = n.slice(0, n.indexOf("e") + 1) + e;
3730
- }
3731
- r = new BigNumber2(n);
3732
- } else {
3733
- r = new BigNumber2(s + "");
3734
- }
3735
- if (r.c[0]) {
3736
- e = r.e;
3737
- s = e + dp;
3738
- if (s < 3)
3739
- s = 0;
3740
- for (; ; ) {
3741
- t = r;
3742
- r = half.times(t.plus(div(x, t, dp, 1)));
3743
- if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
3744
- if (r.e < e)
3745
- --s;
3746
- n = n.slice(s - 3, s + 1);
3747
- if (n == "9999" || !rep && n == "4999") {
3748
- if (!rep) {
3749
- round(t, t.e + DECIMAL_PLACES + 2, 0);
3750
- if (t.times(t).eq(x)) {
3751
- r = t;
3752
- break;
3753
- }
3754
- }
3755
- dp += 4;
3756
- s += 4;
3757
- rep = 1;
3758
- } else {
3759
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
3760
- round(r, r.e + DECIMAL_PLACES + 2, 1);
3761
- m = !r.times(r).eq(x);
3762
- }
3763
- break;
3764
- }
3765
- }
3766
- }
3767
- }
3768
- return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
3769
- };
3770
- P.toExponential = function(dp, rm) {
3771
- if (dp != null) {
3772
- intCheck(dp, 0, MAX);
3773
- dp++;
3774
- }
3775
- return format(this, dp, rm, 1);
3776
- };
3777
- P.toFixed = function(dp, rm) {
3778
- if (dp != null) {
3779
- intCheck(dp, 0, MAX);
3780
- dp = dp + this.e + 1;
3781
- }
3782
- return format(this, dp, rm);
3783
- };
3784
- P.toFormat = function(dp, rm, format2) {
3785
- var str, x = this;
3786
- if (format2 == null) {
3787
- if (dp != null && rm && typeof rm == "object") {
3788
- format2 = rm;
3789
- rm = null;
3790
- } else if (dp && typeof dp == "object") {
3791
- format2 = dp;
3792
- dp = rm = null;
3793
- } else {
3794
- format2 = FORMAT;
3795
- }
3796
- } else if (typeof format2 != "object") {
3797
- throw Error(bignumberError + "Argument not an object: " + format2);
3798
- }
3799
- str = x.toFixed(dp, rm);
3800
- if (x.c) {
3801
- 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;
3802
- if (g2) {
3803
- i = g1;
3804
- g1 = g2;
3805
- g2 = i;
3806
- len -= i;
3807
- }
3808
- if (g1 > 0 && len > 0) {
3809
- i = len % g1 || g1;
3810
- intPart = intDigits.substr(0, i);
3811
- for (; i < len; i += g1)
3812
- intPart += groupSeparator + intDigits.substr(i, g1);
3813
- if (g2 > 0)
3814
- intPart += groupSeparator + intDigits.slice(i);
3815
- if (isNeg)
3816
- intPart = "-" + intPart;
3817
- }
3818
- str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
3819
- new RegExp("\\d{" + g2 + "}\\B", "g"),
3820
- "$&" + (format2.fractionGroupSeparator || "")
3821
- ) : fractionPart) : intPart;
3822
- }
3823
- return (format2.prefix || "") + str + (format2.suffix || "");
3824
- };
3825
- P.toFraction = function(md) {
3826
- var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
3827
- if (md != null) {
3828
- n = new BigNumber2(md);
3829
- if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
3830
- throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
3831
- }
3832
- }
3833
- if (!xc)
3834
- return new BigNumber2(x);
3835
- d = new BigNumber2(ONE);
3836
- n1 = d0 = new BigNumber2(ONE);
3837
- d1 = n0 = new BigNumber2(ONE);
3838
- s = coeffToString(xc);
3839
- e = d.e = s.length - x.e - 1;
3840
- d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
3841
- md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
3842
- exp = MAX_EXP;
3843
- MAX_EXP = 1 / 0;
3844
- n = new BigNumber2(s);
3845
- n0.c[0] = 0;
3846
- for (; ; ) {
3847
- q = div(n, d, 0, 1);
3848
- d2 = d0.plus(q.times(d1));
3849
- if (d2.comparedTo(md) == 1)
3850
- break;
3851
- d0 = d1;
3852
- d1 = d2;
3853
- n1 = n0.plus(q.times(d2 = n1));
3854
- n0 = d2;
3855
- d = n.minus(q.times(d2 = d));
3856
- n = d2;
3857
- }
3858
- d2 = div(md.minus(d0), d1, 0, 1);
3859
- n0 = n0.plus(d2.times(n1));
3860
- d0 = d0.plus(d2.times(d1));
3861
- n0.s = n1.s = x.s;
3862
- e = e * 2;
3863
- r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
3864
- div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
3865
- ) < 1 ? [n1, d1] : [n0, d0];
3866
- MAX_EXP = exp;
3867
- return r;
3868
- };
3869
- P.toNumber = function() {
3870
- return +valueOf(this);
3871
- };
3872
- P.toPrecision = function(sd, rm) {
3873
- if (sd != null)
3874
- intCheck(sd, 1, MAX);
3875
- return format(this, sd, rm, 2);
3876
- };
3877
- P.toString = function(b) {
3878
- var str, n = this, s = n.s, e = n.e;
3879
- if (e === null) {
3880
- if (s) {
3881
- str = "Infinity";
3882
- if (s < 0)
3883
- str = "-" + str;
3884
- } else {
3885
- str = "NaN";
3886
- }
3887
- } else {
3888
- if (b == null) {
3889
- str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
3890
- } else if (b === 10 && alphabetHasNormalDecimalDigits) {
3891
- n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
3892
- str = toFixedPoint(coeffToString(n.c), n.e, "0");
3893
- } else {
3894
- intCheck(b, 2, ALPHABET.length, "Base");
3895
- str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
3896
- }
3897
- if (s < 0 && n.c[0])
3898
- str = "-" + str;
3899
- }
3900
- return str;
3901
- };
3902
- P.valueOf = P.toJSON = function() {
3903
- return valueOf(this);
3904
- };
3905
- P._isBigNumber = true;
3906
- P[Symbol.toStringTag] = "BigNumber";
3907
- P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
3908
- if (configObject != null)
3909
- BigNumber2.set(configObject);
3910
- return BigNumber2;
3911
- }
3912
- function bitFloor(n) {
3913
- var i = n | 0;
3914
- return n > 0 || n === i ? i : i - 1;
3915
- }
3916
- function coeffToString(a) {
3917
- var s, z13, i = 1, j = a.length, r = a[0] + "";
3918
- for (; i < j; ) {
3919
- s = a[i++] + "";
3920
- z13 = LOG_BASE - s.length;
3921
- for (; z13--; s = "0" + s)
3922
- ;
3923
- r += s;
3924
- }
3925
- for (j = r.length; r.charCodeAt(--j) === 48; )
3926
- ;
3927
- return r.slice(0, j + 1 || 1);
3928
- }
3929
- function compare(x, y) {
3930
- var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
3931
- if (!i || !j)
3932
- return null;
3933
- a = xc && !xc[0];
3934
- b = yc && !yc[0];
3935
- if (a || b)
3936
- return a ? b ? 0 : -j : i;
3937
- if (i != j)
3938
- return i;
3939
- a = i < 0;
3940
- b = k == l;
3941
- if (!xc || !yc)
3942
- return b ? 0 : !xc ^ a ? 1 : -1;
3943
- if (!b)
3944
- return k > l ^ a ? 1 : -1;
3945
- j = (k = xc.length) < (l = yc.length) ? k : l;
3946
- for (i = 0; i < j; i++)
3947
- if (xc[i] != yc[i])
3948
- return xc[i] > yc[i] ^ a ? 1 : -1;
3949
- return k == l ? 0 : k > l ^ a ? 1 : -1;
3950
- }
3951
- function intCheck(n, min, max, name) {
3952
- if (n < min || n > max || n !== mathfloor(n)) {
3953
- throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
3954
- }
3955
- }
3956
- function isOdd(n) {
3957
- var k = n.c.length - 1;
3958
- return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
3959
- }
3960
- function toExponential(str, e) {
3961
- return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
3962
- }
3963
- function toFixedPoint(str, e, z13) {
3964
- var len, zs;
3965
- if (e < 0) {
3966
- for (zs = z13 + "."; ++e; zs += z13)
3967
- ;
3968
- str = zs + str;
3969
- } else {
3970
- len = str.length;
3971
- if (++e > len) {
3972
- for (zs = z13, e -= len; --e; zs += z13)
3973
- ;
3974
- str += zs;
3975
- } else if (e < len) {
3976
- str = str.slice(0, e) + "." + str.slice(e);
3977
- }
3978
- }
3979
- return str;
3980
- }
3981
- var BigNumber = clone();
3982
- var bignumber_default = BigNumber;
3983
-
3984
2509
  // src/math.ts
2510
+ import BN from "bignumber.js";
3985
2511
  var compute_transfer = (pool1, pool2, swap, exchange_fee, precision) => {
3986
2512
  const term1 = pool2;
3987
2513
  const term2over = pool1.times(pool2);
3988
2514
  const term2under = pool1.plus(swap);
3989
- const term2 = term2over.div(term2under).integerValue(bignumber_default.ROUND_DOWN);
2515
+ const term2 = term2over.div(term2under).integerValue(BN.ROUND_DOWN);
3990
2516
  const term = term1.minus(term2);
3991
- const fee = new bignumber_default(exchange_fee).div(FEE_FACTOR);
2517
+ const fee = new BN(exchange_fee).div(FEE_FACTOR);
3992
2518
  const result = term.minus(term.times(fee));
3993
- return result.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
2519
+ return result.integerValue(BN.ROUND_DOWN).shiftedBy(-precision);
3994
2520
  };
3995
2521
  var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee, precision, amplifier) => {
3996
2522
  if (amplifier === 0) {
3997
2523
  return compute_transfer(
3998
- new bignumber_default(reserve_in),
3999
- new bignumber_default(reserve_out),
4000
- new bignumber_default(amount_in),
2524
+ new BN(reserve_in),
2525
+ new BN(reserve_out),
2526
+ new BN(amount_in),
4001
2527
  exchange_fee,
4002
2528
  precision
4003
2529
  );
@@ -4025,21 +2551,21 @@ var compute_transfer_curve = (reserve_in, reserve_out, amount_in, exchange_fee,
4025
2551
  i = MAX_ITERATIONS;
4026
2552
  while (x != x_prev && i--) {
4027
2553
  x_prev = F(x);
4028
- x = +new bignumber_default(x * x + c).div(2 * x + b).toFixed(0, bignumber_default.ROUND_DOWN);
2554
+ x = +new BN(x * x + c).div(2 * x + b).toFixed(0, BN.ROUND_DOWN);
4029
2555
  }
4030
2556
  if (reserve_out <= x) {
4031
2557
  throw new Error("curve: insufficient reserve out");
4032
2558
  }
4033
- const amount_out_with_fee = new bignumber_default(reserve_out - x);
4034
- const fee = amount_out_with_fee.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0, bignumber_default.ROUND_DOWN);
2559
+ const amount_out_with_fee = new BN(reserve_out - x);
2560
+ const fee = amount_out_with_fee.times(exchange_fee).div(FEE_FACTOR).plus(1).toFixed(0, BN.ROUND_DOWN);
4035
2561
  const amount_out = amount_out_with_fee.minus(fee);
4036
- return amount_out.integerValue(bignumber_default.ROUND_DOWN).shiftedBy(-precision);
2562
+ return amount_out.integerValue(BN.ROUND_DOWN).shiftedBy(-precision);
4037
2563
  };
4038
2564
  var compute_liquidity = (amount_lt, pool, lt_supply, precision) => {
4039
2565
  const over = amount_lt.times(pool);
4040
2566
  const under = lt_supply;
4041
- const result = over.div(under).integerValue(bignumber_default.ROUND_DOWN);
4042
- return +result.shiftedBy(-precision).toFixed(precision, bignumber_default.ROUND_DOWN);
2567
+ const result = over.div(under).integerValue(BN.ROUND_DOWN);
2568
+ return +result.shiftedBy(-precision).toFixed(precision, BN.ROUND_DOWN);
4043
2569
  };
4044
2570
  var isInputInvalid = (data, value, pool) => {
4045
2571
  value = String(value);