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