@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.
@@ -6,3 +6,4 @@ export declare const ZERO: JSBI;
6
6
  export declare const ONE: JSBI;
7
7
  export declare const V2_FEE_PATH_PLACEHOLDER = 8388608;
8
8
  export declare const ZERO_PERCENT: Percent;
9
+ export declare const ONE_HUNDRED_PERCENT: Percent;
@@ -23,6 +23,7 @@ var ONE = /*#__PURE__*/JSBI.BigInt(1); // = 1 << 23 or 100000000000000000000000
23
23
 
24
24
  var V2_FEE_PATH_PLACEHOLDER = 8388608;
25
25
  var ZERO_PERCENT = /*#__PURE__*/new sdkCore.Percent(ZERO);
26
+ var ONE_HUNDRED_PERCENT = /*#__PURE__*/new sdkCore.Percent(100, 100);
26
27
 
27
28
  (function (ApprovalTypes) {
28
29
  ApprovalTypes[ApprovalTypes["NOT_REQUIRED"] = 0] = "NOT_REQUIRED";
@@ -1905,6 +1906,10 @@ var Trade = /*#__PURE__*/function () {
1905
1906
  }
1906
1907
  }
1907
1908
 
1909
+ if (this.swaps.length === 0) {
1910
+ throw new Error('No routes provided when calling Trade constructor');
1911
+ }
1912
+
1908
1913
  this.tradeType = tradeType; // each route must have the same input and output currency
1909
1914
 
1910
1915
  var inputCurrency = this.swaps[0].inputAmount.currency;
@@ -2272,8 +2277,11 @@ var Trade = /*#__PURE__*/function () {
2272
2277
  get: function get() {
2273
2278
  if (this._priceImpact) {
2274
2279
  return this._priceImpact;
2275
- }
2280
+ } // returns 0% price impact even though this may be inaccurate as a swap may have occured.
2281
+ // because we're unable to derive the pre-buy-tax amount, use 0% as a placeholder.
2276
2282
 
2283
+
2284
+ if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT;
2277
2285
  var spotOutputAmount = sdkCore.CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
2278
2286
 
2279
2287
  for (var _iterator9 = _createForOfIteratorHelperLoose(this.swaps), _step9; !(_step9 = _iterator9()).done;) {
@@ -2283,8 +2291,11 @@ var Trade = /*#__PURE__*/function () {
2283
2291
  var midPrice = route.midPrice;
2284
2292
  var postTaxInputAmount = inputAmount.multiply(new sdkCore.Fraction(ONE).subtract(this.inputTax));
2285
2293
  spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount));
2286
- }
2294
+ } // if the total output of this trade is 0, then most likely the post-tax input was also 0, and therefore this swap
2295
+ // does not move the pools' market price
2296
+
2287
2297
 
2298
+ if (spotOutputAmount.equalTo(ZERO)) return ZERO_PERCENT;
2288
2299
  var preTaxOutputAmount = this.outputAmount.divide(new sdkCore.Fraction(ONE).subtract(this.outputTax));
2289
2300
  var priceImpact = spotOutputAmount.subtract(preTaxOutputAmount).divide(spotOutputAmount);
2290
2301
  this._priceImpact = new sdkCore.Percent(priceImpact.numerator, priceImpact.denominator);
@@ -2874,6 +2885,7 @@ exports.MixedRouteSDK = MixedRouteSDK;
2874
2885
  exports.MixedRouteTrade = MixedRouteTrade;
2875
2886
  exports.MulticallExtended = MulticallExtended;
2876
2887
  exports.ONE = ONE;
2888
+ exports.ONE_HUNDRED_PERCENT = ONE_HUNDRED_PERCENT;
2877
2889
  exports.PaymentsExtended = PaymentsExtended;
2878
2890
  exports.RouteV2 = RouteV2;
2879
2891
  exports.RouteV3 = RouteV3;