@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/esm/index.bundle.js +6 -6
- package/dist/esm/index.js +117 -78
- package/dist/umd/index.bundle.js +6 -6
- package/dist/umd/index.js +117 -78
- package/package.json +2 -1
package/dist/esm/index.js
CHANGED
|
@@ -1627,11 +1627,11 @@ var round = (function (input) {
|
|
|
1627
1627
|
|
|
1628
1628
|
var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'up';
|
|
1629
1629
|
var inputAsFloat = parseFloat(input);
|
|
1630
|
-
var digitsAfterDecimal = inputAsFloat.toString().match(/\d+\.0*(\d{
|
|
1630
|
+
var digitsAfterDecimal = inputAsFloat.toString().match(/\d+\.0*(\d{4})/);
|
|
1631
1631
|
|
|
1632
1632
|
if ((_digitsAfterDecimal = digitsAfterDecimal) !== null && _digitsAfterDecimal !== void 0 && _digitsAfterDecimal.length) {
|
|
1633
1633
|
digitsAfterDecimal = digitsAfterDecimal[0];
|
|
1634
|
-
var focus = digitsAfterDecimal.match(/\d{
|
|
1634
|
+
var focus = digitsAfterDecimal.match(/\d{4}$/)[0];
|
|
1635
1635
|
|
|
1636
1636
|
var _float;
|
|
1637
1637
|
|
|
@@ -1639,35 +1639,35 @@ var round = (function (input) {
|
|
|
1639
1639
|
|
|
1640
1640
|
if (focus.match(/^0/)) {
|
|
1641
1641
|
if (direction == 'up') {
|
|
1642
|
-
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3])
|
|
1642
|
+
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]));
|
|
1643
1643
|
} else {
|
|
1644
|
-
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3])
|
|
1644
|
+
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]));
|
|
1645
1645
|
}
|
|
1646
1646
|
|
|
1647
|
-
focusToFixed = parseFloat(_float).toFixed(
|
|
1647
|
+
focusToFixed = parseFloat(_float).toFixed(2);
|
|
1648
1648
|
focusToFixed = "0".concat(focusToFixed).replace('.', '');
|
|
1649
1649
|
} else {
|
|
1650
1650
|
if (direction == 'up') {
|
|
1651
|
-
_float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2]
|
|
1651
|
+
_float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2], "9"));
|
|
1652
1652
|
} else {
|
|
1653
|
-
_float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2]
|
|
1653
|
+
_float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2], "1"));
|
|
1654
1654
|
}
|
|
1655
1655
|
|
|
1656
|
-
focusToFixed = parseFloat(_float).toFixed(
|
|
1656
|
+
focusToFixed = parseFloat(_float).toFixed(2).replace('.', '');
|
|
1657
1657
|
}
|
|
1658
1658
|
|
|
1659
|
-
if (focusToFixed == '
|
|
1660
|
-
focusToFixed = direction == 'up' ? '
|
|
1659
|
+
if (focusToFixed == '0999' && parseInt(inputAsFloat.toFixed(0)) == 0) {
|
|
1660
|
+
focusToFixed = direction == 'up' ? '1000' : '0999';
|
|
1661
|
+
return parseFloat(digitsAfterDecimal.replace(/\d{4}$/, focusToFixed));
|
|
1662
|
+
} else if (focusToFixed == '1000' && parseInt(inputAsFloat.toFixed(0)) == 0) {
|
|
1661
1663
|
return parseFloat(digitsAfterDecimal.replace(/\d{5}$/, focusToFixed));
|
|
1662
|
-
} else if (focusToFixed
|
|
1663
|
-
return parseFloat(digitsAfterDecimal.replace(/\d{6}$/, focusToFixed));
|
|
1664
|
-
} else if (focusToFixed.toString()[0] != "0" && focusToFixed.toString().length > 4) {
|
|
1664
|
+
} else if (focusToFixed.toString()[0] != "0" && focusToFixed.toString().length > 3) {
|
|
1665
1665
|
return parseInt(inputAsFloat.toFixed(0));
|
|
1666
1666
|
} else {
|
|
1667
|
-
return parseFloat(digitsAfterDecimal.replace(/\d{
|
|
1667
|
+
return parseFloat(digitsAfterDecimal.replace(/\d{4}$/, focusToFixed));
|
|
1668
1668
|
}
|
|
1669
1669
|
} else {
|
|
1670
|
-
return parseFloat(inputAsFloat.toFixed(
|
|
1670
|
+
return parseFloat(inputAsFloat.toFixed(3));
|
|
1671
1671
|
}
|
|
1672
1672
|
});
|
|
1673
1673
|
|
|
@@ -19611,7 +19611,7 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19611
19611
|
|
|
19612
19612
|
var calculateAmountInWithSlippage = /*#__PURE__*/function () {
|
|
19613
19613
|
var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(route) {
|
|
19614
|
-
var currentBlock, blocks, i, exchangeRoute, lastAmountsIn,
|
|
19614
|
+
var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, defaultSlippage, defaultSlippageNewAmountBN, defaultReadableAmount, defaultSlippageRoundedAmountBN, newAmountBN, readableAmount, roundedAmountBN, difference1, difference2, slippage, _difference, _difference2, _slippage, highestAmountBN;
|
|
19615
19615
|
|
|
19616
19616
|
return regenerator.wrap(function _callee2$(_context2) {
|
|
19617
19617
|
while (1) {
|
|
@@ -19692,12 +19692,31 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19692
19692
|
return _context2.abrupt("return");
|
|
19693
19693
|
|
|
19694
19694
|
case 15:
|
|
19695
|
+
defaultSlippage = '0.5'; // %
|
|
19696
|
+
|
|
19697
|
+
if (ethers.BigNumber.from(route.fromAmount).mul(10000).div(ethers.BigNumber.from(route.toAmount).add(ethers.BigNumber.from(route.feeAmount || '0'))).sub(10000).toString() <= 100) {
|
|
19698
|
+
// stable coin swap
|
|
19699
|
+
defaultSlippage = '0.1'; // %
|
|
19700
|
+
}
|
|
19701
|
+
|
|
19702
|
+
defaultSlippageNewAmountBN = lastAmountsIn[2].add(lastAmountsIn[2].mul(parseFloat(defaultSlippage) * 100).div(10000));
|
|
19703
|
+
_context2.next = 20;
|
|
19704
|
+
return route.fromToken.readable(defaultSlippageNewAmountBN);
|
|
19705
|
+
|
|
19706
|
+
case 20:
|
|
19707
|
+
defaultReadableAmount = _context2.sent;
|
|
19708
|
+
_context2.next = 23;
|
|
19709
|
+
return route.fromToken.BigNumber(round(defaultReadableAmount));
|
|
19710
|
+
|
|
19711
|
+
case 23:
|
|
19712
|
+
defaultSlippageRoundedAmountBN = _context2.sent;
|
|
19713
|
+
|
|
19695
19714
|
if (!(lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[1].gt(lastAmountsIn[2]))) {
|
|
19696
|
-
_context2.next =
|
|
19715
|
+
_context2.next = 41;
|
|
19697
19716
|
break;
|
|
19698
19717
|
}
|
|
19699
19718
|
|
|
19700
|
-
//
|
|
19719
|
+
// EXTREME DIRETIONAL SLIPPAGE
|
|
19701
19720
|
difference1 = lastAmountsIn[0].sub(lastAmountsIn[1]);
|
|
19702
19721
|
difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]);
|
|
19703
19722
|
|
|
@@ -19708,34 +19727,43 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19708
19727
|
}
|
|
19709
19728
|
|
|
19710
19729
|
newAmountBN = lastAmountsIn[0].add(slippage);
|
|
19711
|
-
_context2.next =
|
|
19730
|
+
_context2.next = 31;
|
|
19712
19731
|
return route.fromToken.readable(newAmountBN);
|
|
19713
19732
|
|
|
19714
|
-
case
|
|
19733
|
+
case 31:
|
|
19715
19734
|
readableAmount = _context2.sent;
|
|
19716
|
-
_context2.next =
|
|
19735
|
+
_context2.next = 34;
|
|
19717
19736
|
return route.fromToken.BigNumber(round(readableAmount));
|
|
19718
19737
|
|
|
19719
|
-
case
|
|
19738
|
+
case 34:
|
|
19720
19739
|
roundedAmountBN = _context2.sent;
|
|
19721
19740
|
|
|
19741
|
+
if (!roundedAmountBN.gt(defaultSlippageRoundedAmountBN)) {
|
|
19742
|
+
_context2.next = 39;
|
|
19743
|
+
break;
|
|
19744
|
+
}
|
|
19745
|
+
|
|
19722
19746
|
if (!(route.fromAmount == roundedAmountBN.toString())) {
|
|
19723
|
-
_context2.next =
|
|
19747
|
+
_context2.next = 38;
|
|
19724
19748
|
break;
|
|
19725
19749
|
}
|
|
19726
19750
|
|
|
19727
19751
|
return _context2.abrupt("return");
|
|
19728
19752
|
|
|
19729
|
-
case
|
|
19730
|
-
return _context2.abrupt("return",
|
|
19753
|
+
case 38:
|
|
19754
|
+
return _context2.abrupt("return", roundedAmountBN);
|
|
19731
19755
|
|
|
19732
|
-
case
|
|
19756
|
+
case 39:
|
|
19757
|
+
_context2.next = 57;
|
|
19758
|
+
break;
|
|
19759
|
+
|
|
19760
|
+
case 41:
|
|
19733
19761
|
if (lastAmountsIn[0].eq(lastAmountsIn[1]) && lastAmountsIn[1].eq(lastAmountsIn[2])) {
|
|
19734
|
-
_context2.next =
|
|
19762
|
+
_context2.next = 57;
|
|
19735
19763
|
break;
|
|
19736
19764
|
}
|
|
19737
19765
|
|
|
19738
|
-
//
|
|
19766
|
+
// BASE NOISE SLIPPAGE
|
|
19739
19767
|
_difference = lastAmountsIn[0].sub(lastAmountsIn[1]).abs();
|
|
19740
19768
|
_difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]).abs();
|
|
19741
19769
|
|
|
@@ -19753,29 +19781,45 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19753
19781
|
highestAmountBN = lastAmountsIn[2];
|
|
19754
19782
|
}
|
|
19755
19783
|
|
|
19756
|
-
|
|
19757
|
-
_context2.next =
|
|
19758
|
-
return route.fromToken.readable(
|
|
19784
|
+
newAmountBN = highestAmountBN.add(_slippage);
|
|
19785
|
+
_context2.next = 49;
|
|
19786
|
+
return route.fromToken.readable(newAmountBN);
|
|
19759
19787
|
|
|
19760
|
-
case
|
|
19761
|
-
|
|
19762
|
-
_context2.next =
|
|
19763
|
-
return route.fromToken.BigNumber(round(
|
|
19788
|
+
case 49:
|
|
19789
|
+
readableAmount = _context2.sent;
|
|
19790
|
+
_context2.next = 52;
|
|
19791
|
+
return route.fromToken.BigNumber(round(readableAmount));
|
|
19764
19792
|
|
|
19765
|
-
case
|
|
19766
|
-
|
|
19793
|
+
case 52:
|
|
19794
|
+
roundedAmountBN = _context2.sent;
|
|
19795
|
+
|
|
19796
|
+
if (!roundedAmountBN.gt(defaultSlippageRoundedAmountBN)) {
|
|
19797
|
+
_context2.next = 57;
|
|
19798
|
+
break;
|
|
19799
|
+
}
|
|
19767
19800
|
|
|
19768
|
-
if (!(route.fromAmount ==
|
|
19769
|
-
_context2.next =
|
|
19801
|
+
if (!(route.fromAmount == roundedAmountBN.toString())) {
|
|
19802
|
+
_context2.next = 56;
|
|
19770
19803
|
break;
|
|
19771
19804
|
}
|
|
19772
19805
|
|
|
19773
19806
|
return _context2.abrupt("return");
|
|
19774
19807
|
|
|
19775
|
-
case
|
|
19776
|
-
return _context2.abrupt("return",
|
|
19808
|
+
case 56:
|
|
19809
|
+
return _context2.abrupt("return", roundedAmountBN);
|
|
19810
|
+
|
|
19811
|
+
case 57:
|
|
19812
|
+
if (!(route.fromAmount == defaultSlippageRoundedAmountBN.toString())) {
|
|
19813
|
+
_context2.next = 59;
|
|
19814
|
+
break;
|
|
19815
|
+
}
|
|
19816
|
+
|
|
19817
|
+
return _context2.abrupt("return");
|
|
19777
19818
|
|
|
19778
|
-
case
|
|
19819
|
+
case 59:
|
|
19820
|
+
return _context2.abrupt("return", defaultSlippageRoundedAmountBN);
|
|
19821
|
+
|
|
19822
|
+
case 60:
|
|
19779
19823
|
case "end":
|
|
19780
19824
|
return _context2.stop();
|
|
19781
19825
|
}
|
|
@@ -19803,73 +19847,68 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19803
19847
|
} else {
|
|
19804
19848
|
roundAmounts(routes).then( /*#__PURE__*/function () {
|
|
19805
19849
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(roundedRoutes) {
|
|
19806
|
-
var selectRoute,
|
|
19850
|
+
var selectRoute, amountInWithSlippage, newSelectRoute, _amountInWithSlippage;
|
|
19807
19851
|
|
|
19808
19852
|
return regenerator.wrap(function _callee4$(_context4) {
|
|
19809
19853
|
while (1) {
|
|
19810
19854
|
switch (_context4.prev = _context4.next) {
|
|
19811
19855
|
case 0:
|
|
19812
19856
|
if (!(typeof selectedRoute == 'undefined')) {
|
|
19813
|
-
_context4.next =
|
|
19857
|
+
_context4.next = 11;
|
|
19814
19858
|
break;
|
|
19815
19859
|
}
|
|
19816
19860
|
|
|
19817
19861
|
selectRoute = roundedRoutes[0];
|
|
19818
|
-
_context4.next =
|
|
19819
|
-
|
|
19862
|
+
_context4.next = 4;
|
|
19863
|
+
return calculateAmountInWithSlippage(selectRoute);
|
|
19820
19864
|
|
|
19821
19865
|
case 4:
|
|
19822
|
-
|
|
19823
|
-
return route.fromToken == selectedRoute.fromToken && route.blockchain == selectedRoute.blockchain;
|
|
19824
|
-
})];
|
|
19866
|
+
amountInWithSlippage = _context4.sent;
|
|
19825
19867
|
|
|
19826
|
-
if (!
|
|
19827
|
-
_context4.next =
|
|
19868
|
+
if (!amountInWithSlippage) {
|
|
19869
|
+
_context4.next = 8;
|
|
19828
19870
|
break;
|
|
19829
19871
|
}
|
|
19830
19872
|
|
|
19831
19873
|
_context4.next = 8;
|
|
19832
|
-
return
|
|
19874
|
+
return roundAmount(selectRoute, amountInWithSlippage);
|
|
19833
19875
|
|
|
19834
19876
|
case 8:
|
|
19835
|
-
|
|
19836
|
-
|
|
19837
|
-
|
|
19838
|
-
_context4.next = 12;
|
|
19839
|
-
break;
|
|
19840
|
-
}
|
|
19841
|
-
|
|
19842
|
-
_context4.next = 12;
|
|
19843
|
-
return roundAmount(newSelectRoute, amountInWithSlippage);
|
|
19877
|
+
setSelectedRoute(selectRoute);
|
|
19878
|
+
_context4.next = 20;
|
|
19879
|
+
break;
|
|
19844
19880
|
|
|
19845
|
-
case
|
|
19846
|
-
|
|
19881
|
+
case 11:
|
|
19882
|
+
newSelectRoute = roundedRoutes[roundedRoutes.findIndex(function (route) {
|
|
19883
|
+
return route.fromToken.address == selectedRoute.fromToken.address && route.blockchain == selectedRoute.blockchain;
|
|
19884
|
+
})];
|
|
19847
19885
|
|
|
19848
|
-
|
|
19849
|
-
|
|
19850
|
-
_context4.next = 21;
|
|
19886
|
+
if (!newSelectRoute) {
|
|
19887
|
+
_context4.next = 20;
|
|
19851
19888
|
break;
|
|
19852
19889
|
}
|
|
19853
19890
|
|
|
19854
|
-
_context4.next =
|
|
19855
|
-
return calculateAmountInWithSlippage(
|
|
19891
|
+
_context4.next = 15;
|
|
19892
|
+
return calculateAmountInWithSlippage(newSelectRoute);
|
|
19856
19893
|
|
|
19857
|
-
case
|
|
19894
|
+
case 15:
|
|
19858
19895
|
_amountInWithSlippage = _context4.sent;
|
|
19859
19896
|
|
|
19860
19897
|
if (!_amountInWithSlippage) {
|
|
19861
|
-
_context4.next =
|
|
19898
|
+
_context4.next = 19;
|
|
19862
19899
|
break;
|
|
19863
19900
|
}
|
|
19864
19901
|
|
|
19865
|
-
_context4.next =
|
|
19866
|
-
return roundAmount(
|
|
19902
|
+
_context4.next = 19;
|
|
19903
|
+
return roundAmount(newSelectRoute, _amountInWithSlippage);
|
|
19867
19904
|
|
|
19868
|
-
case
|
|
19869
|
-
|
|
19905
|
+
case 19:
|
|
19906
|
+
if (_amountInWithSlippage == undefined || selectedRoute.fromAmount != _amountInWithSlippage.toString()) {
|
|
19907
|
+
setUpdatedRouteWithNewPrice(newSelectRoute);
|
|
19908
|
+
}
|
|
19870
19909
|
|
|
19871
|
-
case
|
|
19872
|
-
_context4.next =
|
|
19910
|
+
case 20:
|
|
19911
|
+
_context4.next = 22;
|
|
19873
19912
|
return Promise.all(roundedRoutes.map( /*#__PURE__*/function () {
|
|
19874
19913
|
var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(route, index) {
|
|
19875
19914
|
var amountInWithSlippage;
|
|
@@ -19907,12 +19946,12 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19907
19946
|
};
|
|
19908
19947
|
}())).then(setAllRoutes);
|
|
19909
19948
|
|
|
19910
|
-
case
|
|
19949
|
+
case 22:
|
|
19911
19950
|
if (props.setMaxRoute) {
|
|
19912
19951
|
props.setMaxRoute(findMaxRoute(roundedRoutes));
|
|
19913
19952
|
}
|
|
19914
19953
|
|
|
19915
|
-
case
|
|
19954
|
+
case 23:
|
|
19916
19955
|
case "end":
|
|
19917
19956
|
return _context4.stop();
|
|
19918
19957
|
}
|