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