@depay/widgets 7.16.2 → 7.16.3

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/umd/index.js CHANGED
@@ -1622,11 +1622,11 @@
1622
1622
 
1623
1623
  var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'up';
1624
1624
  var inputAsFloat = parseFloat(input);
1625
- var digitsAfterDecimal = inputAsFloat.toString().match(/\d+\.0*(\d{5})/);
1625
+ var digitsAfterDecimal = inputAsFloat.toString().match(/\d+\.0*(\d{4})/);
1626
1626
 
1627
1627
  if ((_digitsAfterDecimal = digitsAfterDecimal) !== null && _digitsAfterDecimal !== void 0 && _digitsAfterDecimal.length) {
1628
1628
  digitsAfterDecimal = digitsAfterDecimal[0];
1629
- var focus = digitsAfterDecimal.match(/\d{5}$/)[0];
1629
+ var focus = digitsAfterDecimal.match(/\d{4}$/)[0];
1630
1630
 
1631
1631
  var _float;
1632
1632
 
@@ -1634,35 +1634,35 @@
1634
1634
 
1635
1635
  if (focus.match(/^0/)) {
1636
1636
  if (direction == 'up') {
1637
- _float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]).concat(focus[4]));
1637
+ _float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]));
1638
1638
  } else {
1639
- _float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]).concat(focus[4]));
1639
+ _float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]));
1640
1640
  }
1641
1641
 
1642
- focusToFixed = parseFloat(_float).toFixed(3);
1642
+ focusToFixed = parseFloat(_float).toFixed(2);
1643
1643
  focusToFixed = "0".concat(focusToFixed).replace('.', '');
1644
1644
  } else {
1645
1645
  if (direction == 'up') {
1646
- _float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2]).concat(focus[3], "9"));
1646
+ _float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2], "9"));
1647
1647
  } else {
1648
- _float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2]).concat(focus[3], "1"));
1648
+ _float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2], "1"));
1649
1649
  }
1650
1650
 
1651
- focusToFixed = parseFloat(_float).toFixed(3).replace('.', '');
1651
+ focusToFixed = parseFloat(_float).toFixed(2).replace('.', '');
1652
1652
  }
1653
1653
 
1654
- if (focusToFixed == '09999' && parseInt(inputAsFloat.toFixed(0)) == 0) {
1655
- focusToFixed = direction == 'up' ? '10000' : '09999';
1654
+ if (focusToFixed == '0999' && parseInt(inputAsFloat.toFixed(0)) == 0) {
1655
+ focusToFixed = direction == 'up' ? '1000' : '0999';
1656
+ return parseFloat(digitsAfterDecimal.replace(/\d{4}$/, focusToFixed));
1657
+ } else if (focusToFixed == '1000' && parseInt(inputAsFloat.toFixed(0)) == 0) {
1656
1658
  return parseFloat(digitsAfterDecimal.replace(/\d{5}$/, focusToFixed));
1657
- } else if (focusToFixed == '10000' && parseInt(inputAsFloat.toFixed(0)) == 0) {
1658
- return parseFloat(digitsAfterDecimal.replace(/\d{6}$/, focusToFixed));
1659
- } else if (focusToFixed.toString()[0] != "0" && focusToFixed.toString().length > 4) {
1659
+ } else if (focusToFixed.toString()[0] != "0" && focusToFixed.toString().length > 3) {
1660
1660
  return parseInt(inputAsFloat.toFixed(0));
1661
1661
  } else {
1662
- return parseFloat(digitsAfterDecimal.replace(/\d{5}$/, focusToFixed));
1662
+ return parseFloat(digitsAfterDecimal.replace(/\d{4}$/, focusToFixed));
1663
1663
  }
1664
1664
  } else {
1665
- return parseFloat(inputAsFloat.toFixed(4));
1665
+ return parseFloat(inputAsFloat.toFixed(3));
1666
1666
  }
1667
1667
  });
1668
1668
 
@@ -19606,7 +19606,7 @@
19606
19606
 
19607
19607
  var calculateAmountInWithSlippage = /*#__PURE__*/function () {
19608
19608
  var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(route) {
19609
- var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, difference1, difference2, slippage, newAmountBN, readableAmount, roundedAmountBN, _difference, _difference2, _slippage, highestAmountBN, _newAmountBN, _readableAmount, _roundedAmountBN;
19609
+ var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, defaultSlippage, defaultSlippageNewAmountBN, defaultReadableAmount, defaultSlippageRoundedAmountBN, newAmountBN, readableAmount, roundedAmountBN, difference1, difference2, slippage, _difference, _difference2, _slippage, highestAmountBN;
19610
19610
 
19611
19611
  return regenerator.wrap(function _callee2$(_context2) {
19612
19612
  while (1) {
@@ -19687,12 +19687,31 @@
19687
19687
  return _context2.abrupt("return");
19688
19688
 
19689
19689
  case 15:
19690
+ defaultSlippage = '0.5'; // %
19691
+
19692
+ if (ethers.ethers.BigNumber.from(route.fromAmount).mul(10000).div(ethers.ethers.BigNumber.from(route.toAmount).add(ethers.ethers.BigNumber.from(route.feeAmount || '0'))).sub(10000).toString() <= 100) {
19693
+ // stable coin swap
19694
+ defaultSlippage = '0.1'; // %
19695
+ }
19696
+
19697
+ defaultSlippageNewAmountBN = lastAmountsIn[2].add(lastAmountsIn[2].mul(parseFloat(defaultSlippage) * 100).div(10000));
19698
+ _context2.next = 20;
19699
+ return route.fromToken.readable(defaultSlippageNewAmountBN);
19700
+
19701
+ case 20:
19702
+ defaultReadableAmount = _context2.sent;
19703
+ _context2.next = 23;
19704
+ return route.fromToken.BigNumber(round(defaultReadableAmount));
19705
+
19706
+ case 23:
19707
+ defaultSlippageRoundedAmountBN = _context2.sent;
19708
+
19690
19709
  if (!(lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[1].gt(lastAmountsIn[2]))) {
19691
- _context2.next = 31;
19710
+ _context2.next = 41;
19692
19711
  break;
19693
19712
  }
19694
19713
 
19695
- // directional slippage
19714
+ // EXTREME DIRETIONAL SLIPPAGE
19696
19715
  difference1 = lastAmountsIn[0].sub(lastAmountsIn[1]);
19697
19716
  difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]);
19698
19717
 
@@ -19703,34 +19722,43 @@
19703
19722
  }
19704
19723
 
19705
19724
  newAmountBN = lastAmountsIn[0].add(slippage);
19706
- _context2.next = 22;
19725
+ _context2.next = 31;
19707
19726
  return route.fromToken.readable(newAmountBN);
19708
19727
 
19709
- case 22:
19728
+ case 31:
19710
19729
  readableAmount = _context2.sent;
19711
- _context2.next = 25;
19730
+ _context2.next = 34;
19712
19731
  return route.fromToken.BigNumber(round(readableAmount));
19713
19732
 
19714
- case 25:
19733
+ case 34:
19715
19734
  roundedAmountBN = _context2.sent;
19716
19735
 
19736
+ if (!roundedAmountBN.gt(defaultSlippageRoundedAmountBN)) {
19737
+ _context2.next = 39;
19738
+ break;
19739
+ }
19740
+
19717
19741
  if (!(route.fromAmount == roundedAmountBN.toString())) {
19718
- _context2.next = 28;
19742
+ _context2.next = 38;
19719
19743
  break;
19720
19744
  }
19721
19745
 
19722
19746
  return _context2.abrupt("return");
19723
19747
 
19724
- case 28:
19725
- return _context2.abrupt("return", newAmountBN);
19748
+ case 38:
19749
+ return _context2.abrupt("return", roundedAmountBN);
19726
19750
 
19727
- case 31:
19751
+ case 39:
19752
+ _context2.next = 57;
19753
+ break;
19754
+
19755
+ case 41:
19728
19756
  if (lastAmountsIn[0].eq(lastAmountsIn[1]) && lastAmountsIn[1].eq(lastAmountsIn[2])) {
19729
- _context2.next = 46;
19757
+ _context2.next = 57;
19730
19758
  break;
19731
19759
  }
19732
19760
 
19733
- // base slippage
19761
+ // BASE NOISE SLIPPAGE
19734
19762
  _difference = lastAmountsIn[0].sub(lastAmountsIn[1]).abs();
19735
19763
  _difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]).abs();
19736
19764
 
@@ -19748,29 +19776,45 @@
19748
19776
  highestAmountBN = lastAmountsIn[2];
19749
19777
  }
19750
19778
 
19751
- _newAmountBN = highestAmountBN.add(_slippage);
19752
- _context2.next = 39;
19753
- return route.fromToken.readable(_newAmountBN);
19779
+ newAmountBN = highestAmountBN.add(_slippage);
19780
+ _context2.next = 49;
19781
+ return route.fromToken.readable(newAmountBN);
19754
19782
 
19755
- case 39:
19756
- _readableAmount = _context2.sent;
19757
- _context2.next = 42;
19758
- return route.fromToken.BigNumber(round(_readableAmount));
19783
+ case 49:
19784
+ readableAmount = _context2.sent;
19785
+ _context2.next = 52;
19786
+ return route.fromToken.BigNumber(round(readableAmount));
19787
+
19788
+ case 52:
19789
+ roundedAmountBN = _context2.sent;
19790
+
19791
+ if (!roundedAmountBN.gt(defaultSlippageRoundedAmountBN)) {
19792
+ _context2.next = 57;
19793
+ break;
19794
+ }
19795
+
19796
+ if (!(route.fromAmount == roundedAmountBN.toString())) {
19797
+ _context2.next = 56;
19798
+ break;
19799
+ }
19800
+
19801
+ return _context2.abrupt("return");
19759
19802
 
19760
- case 42:
19761
- _roundedAmountBN = _context2.sent;
19803
+ case 56:
19804
+ return _context2.abrupt("return", roundedAmountBN);
19762
19805
 
19763
- if (!(route.fromAmount == _roundedAmountBN.toString())) {
19764
- _context2.next = 45;
19806
+ case 57:
19807
+ if (!(route.fromAmount == defaultSlippageRoundedAmountBN.toString())) {
19808
+ _context2.next = 59;
19765
19809
  break;
19766
19810
  }
19767
19811
 
19768
19812
  return _context2.abrupt("return");
19769
19813
 
19770
- case 45:
19771
- return _context2.abrupt("return", _newAmountBN);
19814
+ case 59:
19815
+ return _context2.abrupt("return", defaultSlippageRoundedAmountBN);
19772
19816
 
19773
- case 46:
19817
+ case 60:
19774
19818
  case "end":
19775
19819
  return _context2.stop();
19776
19820
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/widgets",
3
3
  "moduleName": "DePayWidgets",
4
- "version": "7.16.2",
4
+ "version": "7.16.3",
5
5
  "description": "Web3 Payments with any token. DePay simplifies and improves Web3 Payments with the power of DeFi. Accept any token with on-the-fly conversion.",
6
6
  "main": "./dist/umd/index.js",
7
7
  "module": "./dist/esm/index.js",
@@ -19,6 +19,7 @@
19
19
  "cryptocurrencies"
20
20
  ],
21
21
  "author": "depay.com",
22
+ "homepage": "https://depay.com",
22
23
  "license": "MIT",
23
24
  "scripts": {
24
25
  "build": "rm -rf dist && npx rollup --config rollup.module.config.js && npx rollup --config rollup.bundle.config.js",