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