@uniswap/router-sdk 1.7.0 → 1.7.1

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.
@@ -17,6 +17,7 @@ var ONE = /*#__PURE__*/JSBI.BigInt(1); // = 1 << 23 or 100000000000000000000000
17
17
 
18
18
  var V2_FEE_PATH_PLACEHOLDER = 8388608;
19
19
  var ZERO_PERCENT = /*#__PURE__*/new Percent(ZERO);
20
+ var ONE_HUNDRED_PERCENT = /*#__PURE__*/new Percent(100, 100);
20
21
 
21
22
  var ApprovalTypes;
22
23
 
@@ -1903,6 +1904,10 @@ var Trade = /*#__PURE__*/function () {
1903
1904
  }
1904
1905
  }
1905
1906
 
1907
+ if (this.swaps.length === 0) {
1908
+ throw new Error('No routes provided when calling Trade constructor');
1909
+ }
1910
+
1906
1911
  this.tradeType = tradeType; // each route must have the same input and output currency
1907
1912
 
1908
1913
  var inputCurrency = this.swaps[0].inputAmount.currency;
@@ -2270,8 +2275,11 @@ var Trade = /*#__PURE__*/function () {
2270
2275
  get: function get() {
2271
2276
  if (this._priceImpact) {
2272
2277
  return this._priceImpact;
2273
- }
2278
+ } // returns 0% price impact even though this may be inaccurate as a swap may have occured.
2279
+ // because we're unable to derive the pre-buy-tax amount, use 0% as a placeholder.
2274
2280
 
2281
+
2282
+ if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT;
2275
2283
  var spotOutputAmount = CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
2276
2284
 
2277
2285
  for (var _iterator9 = _createForOfIteratorHelperLoose(this.swaps), _step9; !(_step9 = _iterator9()).done;) {
@@ -2281,8 +2289,11 @@ var Trade = /*#__PURE__*/function () {
2281
2289
  var midPrice = route.midPrice;
2282
2290
  var postTaxInputAmount = inputAmount.multiply(new Fraction(ONE).subtract(this.inputTax));
2283
2291
  spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount));
2284
- }
2292
+ } // if the total output of this trade is 0, then most likely the post-tax input was also 0, and therefore this swap
2293
+ // does not move the pools' market price
2294
+
2285
2295
 
2296
+ if (spotOutputAmount.equalTo(ZERO)) return ZERO_PERCENT;
2286
2297
  var preTaxOutputAmount = this.outputAmount.divide(new Fraction(ONE).subtract(this.outputTax));
2287
2298
  var priceImpact = spotOutputAmount.subtract(preTaxOutputAmount).divide(spotOutputAmount);
2288
2299
  this._priceImpact = new Percent(priceImpact.numerator, priceImpact.denominator);
@@ -2864,5 +2875,5 @@ var SwapRouter = /*#__PURE__*/function () {
2864
2875
  }();
2865
2876
  SwapRouter.INTERFACE = /*#__PURE__*/new Interface(abi$3);
2866
2877
 
2867
- export { ADDRESS_THIS, ApprovalTypes, ApproveAndCall, MSG_SENDER, MixedRoute, MixedRouteSDK, MixedRouteTrade, MulticallExtended, ONE, PaymentsExtended, Protocol, RouteV2, RouteV3, SwapRouter, Trade, V2_FEE_PATH_PLACEHOLDER, ZERO, ZERO_PERCENT, encodeMixedRouteToPath, getOutputOfPools, isMint, partitionMixedRouteByProtocol, tradeComparator };
2878
+ export { ADDRESS_THIS, ApprovalTypes, ApproveAndCall, MSG_SENDER, MixedRoute, MixedRouteSDK, MixedRouteTrade, MulticallExtended, ONE, ONE_HUNDRED_PERCENT, PaymentsExtended, Protocol, RouteV2, RouteV3, SwapRouter, Trade, V2_FEE_PATH_PLACEHOLDER, ZERO, ZERO_PERCENT, encodeMixedRouteToPath, getOutputOfPools, isMint, partitionMixedRouteByProtocol, tradeComparator };
2868
2879
  //# sourceMappingURL=router-sdk.esm.js.map