@uniswap/router-sdk 1.6.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.
@@ -1,6 +1,9 @@
1
+ import { Percent } from '@uniswap/sdk-core';
1
2
  import JSBI from 'jsbi';
2
3
  export declare const MSG_SENDER = "0x0000000000000000000000000000000000000001";
3
4
  export declare const ADDRESS_THIS = "0x0000000000000000000000000000000000000002";
4
5
  export declare const ZERO: JSBI;
5
6
  export declare const ONE: JSBI;
6
7
  export declare const V2_FEE_PATH_PLACEHOLDER = 8388608;
8
+ export declare const ZERO_PERCENT: Percent;
9
+ export declare const ONE_HUNDRED_PERCENT: Percent;
@@ -42,13 +42,23 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
42
42
  * The price expressed in terms of output amount/input amount.
43
43
  */
44
44
  get executionPrice(): Price<TInput, TOutput>;
45
+ /**
46
+ * Returns the sell tax of the input token
47
+ */
48
+ get inputTax(): Percent;
49
+ /**
50
+ * Returns the buy tax of the output token
51
+ */
52
+ get outputTax(): Percent;
45
53
  /**
46
54
  * The cached result of the price impact computation
47
55
  * @private
48
56
  */
49
57
  private _priceImpact;
50
58
  /**
51
- * Returns the percent difference between the route's mid price and the price impact
59
+ * Returns the percent difference between the route's mid price and the expected execution price
60
+ * In order to exclude token taxes from the price impact calculation, the spot price is calculated
61
+ * using a ratio of values that go into the pools, which are the post-tax input amount and pre-tax output amount.
52
62
  */
53
63
  get priceImpact(): Percent;
54
64
  /**
@@ -4,13 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
+ var sdkCore = require('@uniswap/sdk-core');
7
8
  var JSBI = _interopDefault(require('jsbi'));
8
9
  var abi = require('@ethersproject/abi');
9
10
  var invariant = _interopDefault(require('tiny-invariant'));
10
11
  var IApproveAndCall_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json');
11
12
  var v3Sdk = require('@uniswap/v3-sdk');
12
13
  var IMulticallExtended_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json');
13
- var sdkCore = require('@uniswap/sdk-core');
14
14
  var IPeripheryPaymentsWithFeeExtended_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json');
15
15
  var ISwapRouter02_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json');
16
16
  var v2Sdk = require('@uniswap/v2-sdk');
@@ -22,6 +22,8 @@ var ZERO = /*#__PURE__*/JSBI.BigInt(0);
22
22
  var ONE = /*#__PURE__*/JSBI.BigInt(1); // = 1 << 23 or 100000000000000000000000
23
23
 
24
24
  var V2_FEE_PATH_PLACEHOLDER = 8388608;
25
+ var ZERO_PERCENT = /*#__PURE__*/new sdkCore.Percent(ZERO);
26
+ var ONE_HUNDRED_PERCENT = /*#__PURE__*/new sdkCore.Percent(100, 100);
25
27
 
26
28
  (function (ApprovalTypes) {
27
29
  ApprovalTypes[ApprovalTypes["NOT_REQUIRED"] = 0] = "NOT_REQUIRED";
@@ -1904,6 +1906,10 @@ var Trade = /*#__PURE__*/function () {
1904
1906
  }
1905
1907
  }
1906
1908
 
1909
+ if (this.swaps.length === 0) {
1910
+ throw new Error('No routes provided when calling Trade constructor');
1911
+ }
1912
+
1907
1913
  this.tradeType = tradeType; // each route must have the same input and output currency
1908
1914
 
1909
1915
  var inputCurrency = this.swaps[0].inputAmount.currency;
@@ -2239,7 +2245,31 @@ var Trade = /*#__PURE__*/function () {
2239
2245
  return (_this$_executionPrice = this._executionPrice) != null ? _this$_executionPrice : this._executionPrice = new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient);
2240
2246
  }
2241
2247
  /**
2242
- * Returns the percent difference between the route's mid price and the price impact
2248
+ * Returns the sell tax of the input token
2249
+ */
2250
+
2251
+ }, {
2252
+ key: "inputTax",
2253
+ get: function get() {
2254
+ var inputCurrency = this.inputAmount.currency;
2255
+ if (inputCurrency.isNative || !inputCurrency.wrapped.sellFeeBps) return ZERO_PERCENT;
2256
+ return new sdkCore.Percent(inputCurrency.wrapped.sellFeeBps.toNumber(), 10000);
2257
+ }
2258
+ /**
2259
+ * Returns the buy tax of the output token
2260
+ */
2261
+
2262
+ }, {
2263
+ key: "outputTax",
2264
+ get: function get() {
2265
+ var outputCurrency = this.outputAmount.currency;
2266
+ if (outputCurrency.isNative || !outputCurrency.wrapped.buyFeeBps) return ZERO_PERCENT;
2267
+ return new sdkCore.Percent(outputCurrency.wrapped.buyFeeBps.toNumber(), 10000);
2268
+ }
2269
+ /**
2270
+ * Returns the percent difference between the route's mid price and the expected execution price
2271
+ * In order to exclude token taxes from the price impact calculation, the spot price is calculated
2272
+ * using a ratio of values that go into the pools, which are the post-tax input amount and pre-tax output amount.
2243
2273
  */
2244
2274
 
2245
2275
  }, {
@@ -2247,8 +2277,11 @@ var Trade = /*#__PURE__*/function () {
2247
2277
  get: function get() {
2248
2278
  if (this._priceImpact) {
2249
2279
  return this._priceImpact;
2250
- }
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.
2251
2282
 
2283
+
2284
+ if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT;
2252
2285
  var spotOutputAmount = sdkCore.CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
2253
2286
 
2254
2287
  for (var _iterator9 = _createForOfIteratorHelperLoose(this.swaps), _step9; !(_step9 = _iterator9()).done;) {
@@ -2256,10 +2289,15 @@ var Trade = /*#__PURE__*/function () {
2256
2289
  route = _step9$value.route,
2257
2290
  inputAmount = _step9$value.inputAmount;
2258
2291
  var midPrice = route.midPrice;
2259
- spotOutputAmount = spotOutputAmount.add(midPrice.quote(inputAmount));
2260
- }
2292
+ var postTaxInputAmount = inputAmount.multiply(new sdkCore.Fraction(ONE).subtract(this.inputTax));
2293
+ spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount));
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
2261
2296
 
2262
- var priceImpact = spotOutputAmount.subtract(this.outputAmount).divide(spotOutputAmount);
2297
+
2298
+ if (spotOutputAmount.equalTo(ZERO)) return ZERO_PERCENT;
2299
+ var preTaxOutputAmount = this.outputAmount.divide(new sdkCore.Fraction(ONE).subtract(this.outputTax));
2300
+ var priceImpact = spotOutputAmount.subtract(preTaxOutputAmount).divide(spotOutputAmount);
2263
2301
  this._priceImpact = new sdkCore.Percent(priceImpact.numerator, priceImpact.denominator);
2264
2302
  return this._priceImpact;
2265
2303
  }
@@ -2847,6 +2885,7 @@ exports.MixedRouteSDK = MixedRouteSDK;
2847
2885
  exports.MixedRouteTrade = MixedRouteTrade;
2848
2886
  exports.MulticallExtended = MulticallExtended;
2849
2887
  exports.ONE = ONE;
2888
+ exports.ONE_HUNDRED_PERCENT = ONE_HUNDRED_PERCENT;
2850
2889
  exports.PaymentsExtended = PaymentsExtended;
2851
2890
  exports.RouteV2 = RouteV2;
2852
2891
  exports.RouteV3 = RouteV3;
@@ -2854,6 +2893,7 @@ exports.SwapRouter = SwapRouter;
2854
2893
  exports.Trade = Trade;
2855
2894
  exports.V2_FEE_PATH_PLACEHOLDER = V2_FEE_PATH_PLACEHOLDER;
2856
2895
  exports.ZERO = ZERO;
2896
+ exports.ZERO_PERCENT = ZERO_PERCENT;
2857
2897
  exports.encodeMixedRouteToPath = encodeMixedRouteToPath;
2858
2898
  exports.getOutputOfPools = getOutputOfPools;
2859
2899
  exports.isMint = isMint;