@depay/widgets 7.16.1 → 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 -46
- package/dist/umd/index.bundle.js +6 -6
- package/dist/umd/index.js +86 -46
- package/package.json +2 -1
package/dist/esm/index.js
CHANGED
|
@@ -1627,15 +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{
|
|
1635
|
-
|
|
1636
|
-
if (focus.match(/^00/)) {
|
|
1637
|
-
return inputAsFloat;
|
|
1638
|
-
}
|
|
1634
|
+
var focus = digitsAfterDecimal.match(/\d{4}$/)[0];
|
|
1639
1635
|
|
|
1640
1636
|
var _float;
|
|
1641
1637
|
|
|
@@ -1643,35 +1639,35 @@ var round = (function (input) {
|
|
|
1643
1639
|
|
|
1644
1640
|
if (focus.match(/^0/)) {
|
|
1645
1641
|
if (direction == 'up') {
|
|
1646
|
-
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]));
|
|
1642
|
+
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]));
|
|
1647
1643
|
} else {
|
|
1648
|
-
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]));
|
|
1644
|
+
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]));
|
|
1649
1645
|
}
|
|
1650
1646
|
|
|
1651
|
-
focusToFixed = parseFloat(_float).toFixed(
|
|
1647
|
+
focusToFixed = parseFloat(_float).toFixed(2);
|
|
1652
1648
|
focusToFixed = "0".concat(focusToFixed).replace('.', '');
|
|
1653
1649
|
} else {
|
|
1654
1650
|
if (direction == 'up') {
|
|
1655
|
-
_float = parseFloat("".concat(focus[0], ".").concat(focus[1], "9"));
|
|
1651
|
+
_float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2], "9"));
|
|
1656
1652
|
} else {
|
|
1657
|
-
_float = parseFloat("".concat(focus[0], ".").concat(focus[1], "1"));
|
|
1653
|
+
_float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2], "1"));
|
|
1658
1654
|
}
|
|
1659
1655
|
|
|
1660
|
-
focusToFixed = parseFloat(_float).toFixed(
|
|
1656
|
+
focusToFixed = parseFloat(_float).toFixed(2).replace('.', '');
|
|
1661
1657
|
}
|
|
1662
1658
|
|
|
1663
|
-
if (focusToFixed == '
|
|
1664
|
-
focusToFixed = direction == 'up' ? '
|
|
1665
|
-
return parseFloat(digitsAfterDecimal.replace(/\d{3}$/, focusToFixed));
|
|
1666
|
-
} else if (focusToFixed == '100' && parseInt(inputAsFloat.toFixed(0)) == 0) {
|
|
1659
|
+
if (focusToFixed == '0999' && parseInt(inputAsFloat.toFixed(0)) == 0) {
|
|
1660
|
+
focusToFixed = direction == 'up' ? '1000' : '0999';
|
|
1667
1661
|
return parseFloat(digitsAfterDecimal.replace(/\d{4}$/, focusToFixed));
|
|
1668
|
-
} else if (focusToFixed
|
|
1662
|
+
} else if (focusToFixed == '1000' && parseInt(inputAsFloat.toFixed(0)) == 0) {
|
|
1663
|
+
return parseFloat(digitsAfterDecimal.replace(/\d{5}$/, focusToFixed));
|
|
1664
|
+
} else if (focusToFixed.toString()[0] != "0" && focusToFixed.toString().length > 3) {
|
|
1669
1665
|
return parseInt(inputAsFloat.toFixed(0));
|
|
1670
1666
|
} else {
|
|
1671
|
-
return parseFloat(digitsAfterDecimal.replace(/\d{
|
|
1667
|
+
return parseFloat(digitsAfterDecimal.replace(/\d{4}$/, focusToFixed));
|
|
1672
1668
|
}
|
|
1673
1669
|
} else {
|
|
1674
|
-
return parseFloat(inputAsFloat.toFixed(
|
|
1670
|
+
return parseFloat(inputAsFloat.toFixed(3));
|
|
1675
1671
|
}
|
|
1676
1672
|
});
|
|
1677
1673
|
|
|
@@ -19615,7 +19611,7 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19615
19611
|
|
|
19616
19612
|
var calculateAmountInWithSlippage = /*#__PURE__*/function () {
|
|
19617
19613
|
var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(route) {
|
|
19618
|
-
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;
|
|
19619
19615
|
|
|
19620
19616
|
return regenerator.wrap(function _callee2$(_context2) {
|
|
19621
19617
|
while (1) {
|
|
@@ -19696,12 +19692,31 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19696
19692
|
return _context2.abrupt("return");
|
|
19697
19693
|
|
|
19698
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
|
+
|
|
19699
19714
|
if (!(lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[1].gt(lastAmountsIn[2]))) {
|
|
19700
|
-
_context2.next =
|
|
19715
|
+
_context2.next = 41;
|
|
19701
19716
|
break;
|
|
19702
19717
|
}
|
|
19703
19718
|
|
|
19704
|
-
//
|
|
19719
|
+
// EXTREME DIRETIONAL SLIPPAGE
|
|
19705
19720
|
difference1 = lastAmountsIn[0].sub(lastAmountsIn[1]);
|
|
19706
19721
|
difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]);
|
|
19707
19722
|
|
|
@@ -19712,34 +19727,43 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19712
19727
|
}
|
|
19713
19728
|
|
|
19714
19729
|
newAmountBN = lastAmountsIn[0].add(slippage);
|
|
19715
|
-
_context2.next =
|
|
19730
|
+
_context2.next = 31;
|
|
19716
19731
|
return route.fromToken.readable(newAmountBN);
|
|
19717
19732
|
|
|
19718
|
-
case
|
|
19733
|
+
case 31:
|
|
19719
19734
|
readableAmount = _context2.sent;
|
|
19720
|
-
_context2.next =
|
|
19735
|
+
_context2.next = 34;
|
|
19721
19736
|
return route.fromToken.BigNumber(round(readableAmount));
|
|
19722
19737
|
|
|
19723
|
-
case
|
|
19738
|
+
case 34:
|
|
19724
19739
|
roundedAmountBN = _context2.sent;
|
|
19725
19740
|
|
|
19741
|
+
if (!roundedAmountBN.gt(defaultSlippageRoundedAmountBN)) {
|
|
19742
|
+
_context2.next = 39;
|
|
19743
|
+
break;
|
|
19744
|
+
}
|
|
19745
|
+
|
|
19726
19746
|
if (!(route.fromAmount == roundedAmountBN.toString())) {
|
|
19727
|
-
_context2.next =
|
|
19747
|
+
_context2.next = 38;
|
|
19728
19748
|
break;
|
|
19729
19749
|
}
|
|
19730
19750
|
|
|
19731
19751
|
return _context2.abrupt("return");
|
|
19732
19752
|
|
|
19733
|
-
case
|
|
19734
|
-
return _context2.abrupt("return",
|
|
19753
|
+
case 38:
|
|
19754
|
+
return _context2.abrupt("return", roundedAmountBN);
|
|
19735
19755
|
|
|
19736
|
-
case
|
|
19756
|
+
case 39:
|
|
19757
|
+
_context2.next = 57;
|
|
19758
|
+
break;
|
|
19759
|
+
|
|
19760
|
+
case 41:
|
|
19737
19761
|
if (lastAmountsIn[0].eq(lastAmountsIn[1]) && lastAmountsIn[1].eq(lastAmountsIn[2])) {
|
|
19738
|
-
_context2.next =
|
|
19762
|
+
_context2.next = 57;
|
|
19739
19763
|
break;
|
|
19740
19764
|
}
|
|
19741
19765
|
|
|
19742
|
-
//
|
|
19766
|
+
// BASE NOISE SLIPPAGE
|
|
19743
19767
|
_difference = lastAmountsIn[0].sub(lastAmountsIn[1]).abs();
|
|
19744
19768
|
_difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]).abs();
|
|
19745
19769
|
|
|
@@ -19757,29 +19781,45 @@ var PaymentRoutingProvider = (function (props) {
|
|
|
19757
19781
|
highestAmountBN = lastAmountsIn[2];
|
|
19758
19782
|
}
|
|
19759
19783
|
|
|
19760
|
-
|
|
19761
|
-
_context2.next =
|
|
19762
|
-
return route.fromToken.readable(
|
|
19784
|
+
newAmountBN = highestAmountBN.add(_slippage);
|
|
19785
|
+
_context2.next = 49;
|
|
19786
|
+
return route.fromToken.readable(newAmountBN);
|
|
19763
19787
|
|
|
19764
|
-
case
|
|
19765
|
-
|
|
19766
|
-
_context2.next =
|
|
19767
|
-
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");
|
|
19768
19807
|
|
|
19769
|
-
case
|
|
19770
|
-
|
|
19808
|
+
case 56:
|
|
19809
|
+
return _context2.abrupt("return", roundedAmountBN);
|
|
19771
19810
|
|
|
19772
|
-
|
|
19773
|
-
|
|
19811
|
+
case 57:
|
|
19812
|
+
if (!(route.fromAmount == defaultSlippageRoundedAmountBN.toString())) {
|
|
19813
|
+
_context2.next = 59;
|
|
19774
19814
|
break;
|
|
19775
19815
|
}
|
|
19776
19816
|
|
|
19777
19817
|
return _context2.abrupt("return");
|
|
19778
19818
|
|
|
19779
|
-
case
|
|
19780
|
-
return _context2.abrupt("return",
|
|
19819
|
+
case 59:
|
|
19820
|
+
return _context2.abrupt("return", defaultSlippageRoundedAmountBN);
|
|
19781
19821
|
|
|
19782
|
-
case
|
|
19822
|
+
case 60:
|
|
19783
19823
|
case "end":
|
|
19784
19824
|
return _context2.stop();
|
|
19785
19825
|
}
|