@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/umd/index.js
CHANGED
|
@@ -1622,15 +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{
|
|
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{
|
|
1630
|
-
|
|
1631
|
-
if (focus.match(/^00/)) {
|
|
1632
|
-
return inputAsFloat;
|
|
1633
|
-
}
|
|
1629
|
+
var focus = digitsAfterDecimal.match(/\d{4}$/)[0];
|
|
1634
1630
|
|
|
1635
1631
|
var _float;
|
|
1636
1632
|
|
|
@@ -1638,35 +1634,35 @@
|
|
|
1638
1634
|
|
|
1639
1635
|
if (focus.match(/^0/)) {
|
|
1640
1636
|
if (direction == 'up') {
|
|
1641
|
-
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]));
|
|
1637
|
+
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]));
|
|
1642
1638
|
} else {
|
|
1643
|
-
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]));
|
|
1639
|
+
_float = parseFloat("".concat(focus[1], ".").concat(focus[2]).concat(focus[3]));
|
|
1644
1640
|
}
|
|
1645
1641
|
|
|
1646
|
-
focusToFixed = parseFloat(_float).toFixed(
|
|
1642
|
+
focusToFixed = parseFloat(_float).toFixed(2);
|
|
1647
1643
|
focusToFixed = "0".concat(focusToFixed).replace('.', '');
|
|
1648
1644
|
} else {
|
|
1649
1645
|
if (direction == 'up') {
|
|
1650
|
-
_float = parseFloat("".concat(focus[0], ".").concat(focus[1], "9"));
|
|
1646
|
+
_float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2], "9"));
|
|
1651
1647
|
} else {
|
|
1652
|
-
_float = parseFloat("".concat(focus[0], ".").concat(focus[1], "1"));
|
|
1648
|
+
_float = parseFloat("".concat(focus[0], ".").concat(focus[1]).concat(focus[2], "1"));
|
|
1653
1649
|
}
|
|
1654
1650
|
|
|
1655
|
-
focusToFixed = parseFloat(_float).toFixed(
|
|
1651
|
+
focusToFixed = parseFloat(_float).toFixed(2).replace('.', '');
|
|
1656
1652
|
}
|
|
1657
1653
|
|
|
1658
|
-
if (focusToFixed == '
|
|
1659
|
-
focusToFixed = direction == 'up' ? '
|
|
1660
|
-
return parseFloat(digitsAfterDecimal.replace(/\d{3}$/, focusToFixed));
|
|
1661
|
-
} else if (focusToFixed == '100' && parseInt(inputAsFloat.toFixed(0)) == 0) {
|
|
1654
|
+
if (focusToFixed == '0999' && parseInt(inputAsFloat.toFixed(0)) == 0) {
|
|
1655
|
+
focusToFixed = direction == 'up' ? '1000' : '0999';
|
|
1662
1656
|
return parseFloat(digitsAfterDecimal.replace(/\d{4}$/, focusToFixed));
|
|
1663
|
-
} else if (focusToFixed
|
|
1657
|
+
} else if (focusToFixed == '1000' && parseInt(inputAsFloat.toFixed(0)) == 0) {
|
|
1658
|
+
return parseFloat(digitsAfterDecimal.replace(/\d{5}$/, focusToFixed));
|
|
1659
|
+
} else if (focusToFixed.toString()[0] != "0" && focusToFixed.toString().length > 3) {
|
|
1664
1660
|
return parseInt(inputAsFloat.toFixed(0));
|
|
1665
1661
|
} else {
|
|
1666
|
-
return parseFloat(digitsAfterDecimal.replace(/\d{
|
|
1662
|
+
return parseFloat(digitsAfterDecimal.replace(/\d{4}$/, focusToFixed));
|
|
1667
1663
|
}
|
|
1668
1664
|
} else {
|
|
1669
|
-
return parseFloat(inputAsFloat.toFixed(
|
|
1665
|
+
return parseFloat(inputAsFloat.toFixed(3));
|
|
1670
1666
|
}
|
|
1671
1667
|
});
|
|
1672
1668
|
|
|
@@ -19610,7 +19606,7 @@
|
|
|
19610
19606
|
|
|
19611
19607
|
var calculateAmountInWithSlippage = /*#__PURE__*/function () {
|
|
19612
19608
|
var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(route) {
|
|
19613
|
-
var currentBlock, blocks, i, exchangeRoute, lastAmountsIn,
|
|
19609
|
+
var currentBlock, blocks, i, exchangeRoute, lastAmountsIn, defaultSlippage, defaultSlippageNewAmountBN, defaultReadableAmount, defaultSlippageRoundedAmountBN, newAmountBN, readableAmount, roundedAmountBN, difference1, difference2, slippage, _difference, _difference2, _slippage, highestAmountBN;
|
|
19614
19610
|
|
|
19615
19611
|
return regenerator.wrap(function _callee2$(_context2) {
|
|
19616
19612
|
while (1) {
|
|
@@ -19691,12 +19687,31 @@
|
|
|
19691
19687
|
return _context2.abrupt("return");
|
|
19692
19688
|
|
|
19693
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
|
+
|
|
19694
19709
|
if (!(lastAmountsIn[0].gt(lastAmountsIn[1]) && lastAmountsIn[1].gt(lastAmountsIn[2]))) {
|
|
19695
|
-
_context2.next =
|
|
19710
|
+
_context2.next = 41;
|
|
19696
19711
|
break;
|
|
19697
19712
|
}
|
|
19698
19713
|
|
|
19699
|
-
//
|
|
19714
|
+
// EXTREME DIRETIONAL SLIPPAGE
|
|
19700
19715
|
difference1 = lastAmountsIn[0].sub(lastAmountsIn[1]);
|
|
19701
19716
|
difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]);
|
|
19702
19717
|
|
|
@@ -19707,34 +19722,43 @@
|
|
|
19707
19722
|
}
|
|
19708
19723
|
|
|
19709
19724
|
newAmountBN = lastAmountsIn[0].add(slippage);
|
|
19710
|
-
_context2.next =
|
|
19725
|
+
_context2.next = 31;
|
|
19711
19726
|
return route.fromToken.readable(newAmountBN);
|
|
19712
19727
|
|
|
19713
|
-
case
|
|
19728
|
+
case 31:
|
|
19714
19729
|
readableAmount = _context2.sent;
|
|
19715
|
-
_context2.next =
|
|
19730
|
+
_context2.next = 34;
|
|
19716
19731
|
return route.fromToken.BigNumber(round(readableAmount));
|
|
19717
19732
|
|
|
19718
|
-
case
|
|
19733
|
+
case 34:
|
|
19719
19734
|
roundedAmountBN = _context2.sent;
|
|
19720
19735
|
|
|
19736
|
+
if (!roundedAmountBN.gt(defaultSlippageRoundedAmountBN)) {
|
|
19737
|
+
_context2.next = 39;
|
|
19738
|
+
break;
|
|
19739
|
+
}
|
|
19740
|
+
|
|
19721
19741
|
if (!(route.fromAmount == roundedAmountBN.toString())) {
|
|
19722
|
-
_context2.next =
|
|
19742
|
+
_context2.next = 38;
|
|
19723
19743
|
break;
|
|
19724
19744
|
}
|
|
19725
19745
|
|
|
19726
19746
|
return _context2.abrupt("return");
|
|
19727
19747
|
|
|
19728
|
-
case
|
|
19729
|
-
return _context2.abrupt("return",
|
|
19748
|
+
case 38:
|
|
19749
|
+
return _context2.abrupt("return", roundedAmountBN);
|
|
19730
19750
|
|
|
19731
|
-
case
|
|
19751
|
+
case 39:
|
|
19752
|
+
_context2.next = 57;
|
|
19753
|
+
break;
|
|
19754
|
+
|
|
19755
|
+
case 41:
|
|
19732
19756
|
if (lastAmountsIn[0].eq(lastAmountsIn[1]) && lastAmountsIn[1].eq(lastAmountsIn[2])) {
|
|
19733
|
-
_context2.next =
|
|
19757
|
+
_context2.next = 57;
|
|
19734
19758
|
break;
|
|
19735
19759
|
}
|
|
19736
19760
|
|
|
19737
|
-
//
|
|
19761
|
+
// BASE NOISE SLIPPAGE
|
|
19738
19762
|
_difference = lastAmountsIn[0].sub(lastAmountsIn[1]).abs();
|
|
19739
19763
|
_difference2 = lastAmountsIn[1].sub(lastAmountsIn[2]).abs();
|
|
19740
19764
|
|
|
@@ -19752,29 +19776,45 @@
|
|
|
19752
19776
|
highestAmountBN = lastAmountsIn[2];
|
|
19753
19777
|
}
|
|
19754
19778
|
|
|
19755
|
-
|
|
19756
|
-
_context2.next =
|
|
19757
|
-
return route.fromToken.readable(
|
|
19779
|
+
newAmountBN = highestAmountBN.add(_slippage);
|
|
19780
|
+
_context2.next = 49;
|
|
19781
|
+
return route.fromToken.readable(newAmountBN);
|
|
19758
19782
|
|
|
19759
|
-
case
|
|
19760
|
-
|
|
19761
|
-
_context2.next =
|
|
19762
|
-
return route.fromToken.BigNumber(round(
|
|
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");
|
|
19763
19802
|
|
|
19764
|
-
case
|
|
19765
|
-
|
|
19803
|
+
case 56:
|
|
19804
|
+
return _context2.abrupt("return", roundedAmountBN);
|
|
19766
19805
|
|
|
19767
|
-
|
|
19768
|
-
|
|
19806
|
+
case 57:
|
|
19807
|
+
if (!(route.fromAmount == defaultSlippageRoundedAmountBN.toString())) {
|
|
19808
|
+
_context2.next = 59;
|
|
19769
19809
|
break;
|
|
19770
19810
|
}
|
|
19771
19811
|
|
|
19772
19812
|
return _context2.abrupt("return");
|
|
19773
19813
|
|
|
19774
|
-
case
|
|
19775
|
-
return _context2.abrupt("return",
|
|
19814
|
+
case 59:
|
|
19815
|
+
return _context2.abrupt("return", defaultSlippageRoundedAmountBN);
|
|
19776
19816
|
|
|
19777
|
-
case
|
|
19817
|
+
case 60:
|
|
19778
19818
|
case "end":
|
|
19779
19819
|
return _context2.stop();
|
|
19780
19820
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depay/widgets",
|
|
3
3
|
"moduleName": "DePayWidgets",
|
|
4
|
-
"version": "7.16.
|
|
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",
|