@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/esm/index.bundle.js +6 -6
- package/dist/esm/index.js +86 -42
- package/dist/umd/index.bundle.js +6 -6
- package/dist/umd/index.js +86 -42
- 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));
|
|
19792
|
+
|
|
19793
|
+
case 52:
|
|
19794
|
+
roundedAmountBN = _context2.sent;
|
|
19795
|
+
|
|
19796
|
+
if (!roundedAmountBN.gt(defaultSlippageRoundedAmountBN)) {
|
|
19797
|
+
_context2.next = 57;
|
|
19798
|
+
break;
|
|
19799
|
+
}
|
|
19800
|
+
|
|
19801
|
+
if (!(route.fromAmount == roundedAmountBN.toString())) {
|
|
19802
|
+
_context2.next = 56;
|
|
19803
|
+
break;
|
|
19804
|
+
}
|
|
19805
|
+
|
|
19806
|
+
return _context2.abrupt("return");
|
|
19764
19807
|
|
|
19765
|
-
case
|
|
19766
|
-
|
|
19808
|
+
case 56:
|
|
19809
|
+
return _context2.abrupt("return", roundedAmountBN);
|
|
19767
19810
|
|
|
19768
|
-
|
|
19769
|
-
|
|
19811
|
+
case 57:
|
|
19812
|
+
if (!(route.fromAmount == defaultSlippageRoundedAmountBN.toString())) {
|
|
19813
|
+
_context2.next = 59;
|
|
19770
19814
|
break;
|
|
19771
19815
|
}
|
|
19772
19816
|
|
|
19773
19817
|
return _context2.abrupt("return");
|
|
19774
19818
|
|
|
19775
|
-
case
|
|
19776
|
-
return _context2.abrupt("return",
|
|
19819
|
+
case 59:
|
|
19820
|
+
return _context2.abrupt("return", defaultSlippageRoundedAmountBN);
|
|
19777
19821
|
|
|
19778
|
-
case
|
|
19822
|
+
case 60:
|
|
19779
19823
|
case "end":
|
|
19780
19824
|
return _context2.stop();
|
|
19781
19825
|
}
|