@uniswap/router-sdk 1.1.0 → 1.2.0

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.
@@ -1463,6 +1463,7 @@ var Trade = /*#__PURE__*/function () {
1463
1463
  }();
1464
1464
 
1465
1465
  var ZERO$1 = /*#__PURE__*/JSBI.BigInt(0);
1466
+ var REFUND_ETH_PRICE_IMPACT_THRESHOLD = /*#__PURE__*/new Percent( /*#__PURE__*/JSBI.BigInt(50), /*#__PURE__*/JSBI.BigInt(100));
1466
1467
  /**
1467
1468
  * Represents the Uniswap V2 + V3 SwapRouter02, and has static methods for helping execute trades.
1468
1469
  */
@@ -1680,10 +1681,11 @@ var SwapRouter = /*#__PURE__*/function () {
1680
1681
  } else {
1681
1682
  calldatas.push(PaymentsExtended.encodeSweepToken(sampleTrade.outputAmount.currency.wrapped, minimumAmountOut.quotient, options.recipient, options.fee));
1682
1683
  }
1683
- } // must refund when paying in ETH, but with an uncertain input amount
1684
+ } // must refund when paying in ETH: either with an uncertain input amount OR if there's a chance of a partial fill.
1685
+ // unlike ERC20's, the full ETH value must be sent in the transaction, so the rest must be refunded.
1684
1686
 
1685
1687
 
1686
- if (inputIsNative && sampleTrade.tradeType === TradeType.EXACT_OUTPUT) {
1688
+ if (inputIsNative && (sampleTrade.tradeType === TradeType.EXACT_OUTPUT || SwapRouter.riskOfPartialFill(trades))) {
1687
1689
  calldatas.push(Payments.encodeRefundETH());
1688
1690
  }
1689
1691
 
@@ -1768,6 +1770,21 @@ var SwapRouter = /*#__PURE__*/function () {
1768
1770
  calldata: MulticallExtended.encodeMulticall(calldatas, options.deadlineOrPreviousBlockhash),
1769
1771
  value: value.toString()
1770
1772
  };
1773
+ } // if price impact is very high, there's a chance of hitting max/min prices resulting in a partial fill of the swap
1774
+ ;
1775
+
1776
+ SwapRouter.riskOfPartialFill = function riskOfPartialFill(trades) {
1777
+ if (Array.isArray(trades)) {
1778
+ return trades.some(function (trade) {
1779
+ return SwapRouter.v3TradeWithHighPriceImpact(trade);
1780
+ });
1781
+ } else {
1782
+ return SwapRouter.v3TradeWithHighPriceImpact(trades);
1783
+ }
1784
+ };
1785
+
1786
+ SwapRouter.v3TradeWithHighPriceImpact = function v3TradeWithHighPriceImpact(trade) {
1787
+ return !(trade instanceof Trade$2) && trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
1771
1788
  };
1772
1789
 
1773
1790
  SwapRouter.getPositionAmounts = function getPositionAmounts(position, zeroForOne) {