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