@depay/widgets 7.16.2 → 7.16.4

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));
19759
19787
 
19760
- case 42:
19761
- _roundedAmountBN = _context2.sent;
19788
+ case 52:
19789
+ roundedAmountBN = _context2.sent;
19790
+
19791
+ if (!roundedAmountBN.gt(defaultSlippageRoundedAmountBN)) {
19792
+ _context2.next = 57;
19793
+ break;
19794
+ }
19762
19795
 
19763
- if (!(route.fromAmount == _roundedAmountBN.toString())) {
19764
- _context2.next = 45;
19796
+ if (!(route.fromAmount == roundedAmountBN.toString())) {
19797
+ _context2.next = 56;
19765
19798
  break;
19766
19799
  }
19767
19800
 
19768
19801
  return _context2.abrupt("return");
19769
19802
 
19770
- case 45:
19771
- return _context2.abrupt("return", _newAmountBN);
19803
+ case 56:
19804
+ return _context2.abrupt("return", roundedAmountBN);
19805
+
19806
+ case 57:
19807
+ if (!(route.fromAmount == defaultSlippageRoundedAmountBN.toString())) {
19808
+ _context2.next = 59;
19809
+ break;
19810
+ }
19811
+
19812
+ return _context2.abrupt("return");
19772
19813
 
19773
- case 46:
19814
+ case 59:
19815
+ return _context2.abrupt("return", defaultSlippageRoundedAmountBN);
19816
+
19817
+ case 60:
19774
19818
  case "end":
19775
19819
  return _context2.stop();
19776
19820
  }
@@ -19798,73 +19842,68 @@
19798
19842
  } else {
19799
19843
  roundAmounts(routes).then( /*#__PURE__*/function () {
19800
19844
  var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(roundedRoutes) {
19801
- var selectRoute, newSelectRoute, amountInWithSlippage, _amountInWithSlippage;
19845
+ var selectRoute, amountInWithSlippage, newSelectRoute, _amountInWithSlippage;
19802
19846
 
19803
19847
  return regenerator.wrap(function _callee4$(_context4) {
19804
19848
  while (1) {
19805
19849
  switch (_context4.prev = _context4.next) {
19806
19850
  case 0:
19807
19851
  if (!(typeof selectedRoute == 'undefined')) {
19808
- _context4.next = 4;
19852
+ _context4.next = 11;
19809
19853
  break;
19810
19854
  }
19811
19855
 
19812
19856
  selectRoute = roundedRoutes[0];
19813
- _context4.next = 13;
19814
- break;
19857
+ _context4.next = 4;
19858
+ return calculateAmountInWithSlippage(selectRoute);
19815
19859
 
19816
19860
  case 4:
19817
- newSelectRoute = roundedRoutes[allRoutes.findIndex(function (route) {
19818
- return route.fromToken == selectedRoute.fromToken && route.blockchain == selectedRoute.blockchain;
19819
- })];
19861
+ amountInWithSlippage = _context4.sent;
19820
19862
 
19821
- if (!(newSelectRoute && selectedRoute.fromAmount !== newSelectRoute.fromAmount)) {
19822
- _context4.next = 13;
19863
+ if (!amountInWithSlippage) {
19864
+ _context4.next = 8;
19823
19865
  break;
19824
19866
  }
19825
19867
 
19826
19868
  _context4.next = 8;
19827
- return calculateAmountInWithSlippage(newSelectRoute);
19869
+ return roundAmount(selectRoute, amountInWithSlippage);
19828
19870
 
19829
19871
  case 8:
19830
- amountInWithSlippage = _context4.sent;
19831
-
19832
- if (!amountInWithSlippage) {
19833
- _context4.next = 12;
19834
- break;
19835
- }
19836
-
19837
- _context4.next = 12;
19838
- return roundAmount(newSelectRoute, amountInWithSlippage);
19872
+ setSelectedRoute(selectRoute);
19873
+ _context4.next = 20;
19874
+ break;
19839
19875
 
19840
- case 12:
19841
- setUpdatedRouteWithNewPrice(newSelectRoute);
19876
+ case 11:
19877
+ newSelectRoute = roundedRoutes[roundedRoutes.findIndex(function (route) {
19878
+ return route.fromToken.address == selectedRoute.fromToken.address && route.blockchain == selectedRoute.blockchain;
19879
+ })];
19842
19880
 
19843
- case 13:
19844
- if (!selectRoute) {
19845
- _context4.next = 21;
19881
+ if (!newSelectRoute) {
19882
+ _context4.next = 20;
19846
19883
  break;
19847
19884
  }
19848
19885
 
19849
- _context4.next = 16;
19850
- return calculateAmountInWithSlippage(selectRoute);
19886
+ _context4.next = 15;
19887
+ return calculateAmountInWithSlippage(newSelectRoute);
19851
19888
 
19852
- case 16:
19889
+ case 15:
19853
19890
  _amountInWithSlippage = _context4.sent;
19854
19891
 
19855
19892
  if (!_amountInWithSlippage) {
19856
- _context4.next = 20;
19893
+ _context4.next = 19;
19857
19894
  break;
19858
19895
  }
19859
19896
 
19860
- _context4.next = 20;
19861
- return roundAmount(selectRoute, _amountInWithSlippage);
19897
+ _context4.next = 19;
19898
+ return roundAmount(newSelectRoute, _amountInWithSlippage);
19862
19899
 
19863
- case 20:
19864
- setSelectedRoute(selectRoute);
19900
+ case 19:
19901
+ if (_amountInWithSlippage == undefined || selectedRoute.fromAmount != _amountInWithSlippage.toString()) {
19902
+ setUpdatedRouteWithNewPrice(newSelectRoute);
19903
+ }
19865
19904
 
19866
- case 21:
19867
- _context4.next = 23;
19905
+ case 20:
19906
+ _context4.next = 22;
19868
19907
  return Promise.all(roundedRoutes.map( /*#__PURE__*/function () {
19869
19908
  var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(route, index) {
19870
19909
  var amountInWithSlippage;
@@ -19902,12 +19941,12 @@
19902
19941
  };
19903
19942
  }())).then(setAllRoutes);
19904
19943
 
19905
- case 23:
19944
+ case 22:
19906
19945
  if (props.setMaxRoute) {
19907
19946
  props.setMaxRoute(findMaxRoute(roundedRoutes));
19908
19947
  }
19909
19948
 
19910
- case 24:
19949
+ case 23:
19911
19950
  case "end":
19912
19951
  return _context4.stop();
19913
19952
  }
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.4",
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",