@uniswap/router-sdk 1.21.3 → 1.22.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.
@@ -688,7 +688,7 @@ var MixedRouteSDK = /*#__PURE__*/function () {
688
688
  !pools[0].involvesToken(this.pathInput) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0;
689
689
  var lastPool = pools[pools.length - 1];
690
690
  if (lastPool instanceof Pool) {
691
- !(lastPool.involvesToken(output) || lastPool.involvesToken(output.wrapped)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
691
+ !(lastPool.v4InvolvesToken(output) || lastPool.v4InvolvesToken(output.wrapped)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
692
692
  } else {
693
693
  !lastPool.involvesToken(output.wrapped) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
694
694
  }
@@ -1281,6 +1281,17 @@ var Protocol;
1281
1281
  Protocol["MIXED"] = "MIXED";
1282
1282
  })(Protocol || (Protocol = {}));
1283
1283
 
1284
+ // Helper function to get the pathInput and pathOutput for a V2 / V3 route
1285
+ // currency could be native so we check against the wrapped version as they don't support native ETH in path
1286
+ function getPathToken(currency, pool) {
1287
+ if (pool.token0.wrapped.equals(currency.wrapped)) {
1288
+ return pool.token0;
1289
+ } else if (pool.token1.wrapped.equals(currency.wrapped)) {
1290
+ return pool.token1;
1291
+ } else {
1292
+ throw new Error("Expected token " + currency.symbol + " to be either " + pool.token0.symbol + " or " + pool.token1.symbol);
1293
+ }
1294
+ }
1284
1295
  // V2 route wrapper
1285
1296
  var RouteV2 = /*#__PURE__*/function (_V2RouteSDK) {
1286
1297
  _inheritsLoose(RouteV2, _V2RouteSDK);
@@ -1289,6 +1300,8 @@ var RouteV2 = /*#__PURE__*/function (_V2RouteSDK) {
1289
1300
  _this = _V2RouteSDK.call(this, v2Route.pairs, v2Route.input, v2Route.output) || this;
1290
1301
  _this.protocol = Protocol.V2;
1291
1302
  _this.pools = _this.pairs;
1303
+ _this.pathInput = getPathToken(v2Route.input, _this.pairs[0]);
1304
+ _this.pathOutput = getPathToken(v2Route.output, _this.pairs[_this.pairs.length - 1]);
1292
1305
  return _this;
1293
1306
  }
1294
1307
  return RouteV2;
@@ -1301,6 +1314,8 @@ var RouteV3 = /*#__PURE__*/function (_V3RouteSDK) {
1301
1314
  _this2 = _V3RouteSDK.call(this, v3Route.pools, v3Route.input, v3Route.output) || this;
1302
1315
  _this2.protocol = Protocol.V3;
1303
1316
  _this2.path = v3Route.tokenPath;
1317
+ _this2.pathInput = getPathToken(v3Route.input, _this2.pools[0]);
1318
+ _this2.pathOutput = getPathToken(v3Route.output, _this2.pools[_this2.pools.length - 1]);
1304
1319
  return _this2;
1305
1320
  }
1306
1321
  return RouteV3;
@@ -1692,13 +1707,13 @@ var Trade = /*#__PURE__*/function () {
1692
1707
  if (this._inputAmount) {
1693
1708
  return this._inputAmount;
1694
1709
  }
1695
- var inputCurrency = this.swaps[0].inputAmount.currency;
1710
+ var inputAmountCurrency = this.swaps[0].inputAmount.currency;
1696
1711
  var totalInputFromRoutes = this.swaps.map(function (_ref5) {
1697
- var inputAmount = _ref5.inputAmount;
1698
- return inputAmount;
1712
+ var routeInputAmount = _ref5.inputAmount;
1713
+ return routeInputAmount;
1699
1714
  }).reduce(function (total, cur) {
1700
1715
  return total.add(cur);
1701
- }, CurrencyAmount.fromRawAmount(inputCurrency, 0));
1716
+ }, CurrencyAmount.fromRawAmount(inputAmountCurrency, 0));
1702
1717
  this._inputAmount = totalInputFromRoutes;
1703
1718
  return this._inputAmount;
1704
1719
  }
@@ -1710,14 +1725,50 @@ var Trade = /*#__PURE__*/function () {
1710
1725
  }
1711
1726
  var outputCurrency = this.swaps[0].outputAmount.currency;
1712
1727
  var totalOutputFromRoutes = this.swaps.map(function (_ref6) {
1713
- var outputAmount = _ref6.outputAmount;
1714
- return outputAmount;
1728
+ var routeOutputAmount = _ref6.outputAmount;
1729
+ return routeOutputAmount;
1715
1730
  }).reduce(function (total, cur) {
1716
1731
  return total.add(cur);
1717
1732
  }, CurrencyAmount.fromRawAmount(outputCurrency, 0));
1718
1733
  this._outputAmount = totalOutputFromRoutes;
1719
1734
  return this._outputAmount;
1720
1735
  }
1736
+ /**
1737
+ * Returns the sum of all swaps within the trade
1738
+ * @returns
1739
+ * inputAmount: total input amount
1740
+ * inputAmountNative: total amount of native currency required for ETH input paths
1741
+ * - 0 if inputAmount is native but no native input paths
1742
+ * - undefined if inputAmount is not native
1743
+ * outputAmount: total output amount
1744
+ * outputAmountNative: total amount of native currency returned from ETH output paths
1745
+ * - 0 if outputAmount is native but no native output paths
1746
+ * - undefined if outputAmount is not native
1747
+ */
1748
+ }, {
1749
+ key: "amounts",
1750
+ get: function get() {
1751
+ var _this$swaps$find, _this$swaps$find2;
1752
+ // Find native currencies for reduce below
1753
+ var inputNativeCurrency = (_this$swaps$find = this.swaps.find(function (_ref7) {
1754
+ var inputAmount = _ref7.inputAmount;
1755
+ return inputAmount.currency.isNative;
1756
+ })) == null ? void 0 : _this$swaps$find.inputAmount.currency;
1757
+ var outputNativeCurrency = (_this$swaps$find2 = this.swaps.find(function (_ref8) {
1758
+ var outputAmount = _ref8.outputAmount;
1759
+ return outputAmount.currency.isNative;
1760
+ })) == null ? void 0 : _this$swaps$find2.outputAmount.currency;
1761
+ return {
1762
+ inputAmount: this.inputAmount,
1763
+ inputAmountNative: inputNativeCurrency ? this.swaps.reduce(function (total, swap) {
1764
+ return swap.route.pathInput.isNative ? total.add(swap.inputAmount) : total;
1765
+ }, CurrencyAmount.fromRawAmount(inputNativeCurrency, 0)) : undefined,
1766
+ outputAmount: this.outputAmount,
1767
+ outputAmountNative: outputNativeCurrency ? this.swaps.reduce(function (total, swap) {
1768
+ return swap.route.pathOutput.isNative ? total.add(swap.outputAmount) : total;
1769
+ }, CurrencyAmount.fromRawAmount(outputNativeCurrency, 0)) : undefined
1770
+ };
1771
+ }
1721
1772
  /**
1722
1773
  * The price expressed in terms of output amount/input amount.
1723
1774
  */
@@ -2338,5 +2389,5 @@ var SwapRouter = /*#__PURE__*/function () {
2338
2389
  }();
2339
2390
  SwapRouter.INTERFACE = /*#__PURE__*/new Interface(abi$3);
2340
2391
 
2341
- export { ADDRESS_THIS, ADDRESS_ZERO, ApprovalTypes, ApproveAndCall, MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER, MSG_SENDER, MixedRoute, MixedRouteSDK, MixedRouteTrade, MulticallExtended, ONE, ONE_HUNDRED_PERCENT, PaymentsExtended, Protocol, RouteV2, RouteV3, RouteV4, SwapRouter, Trade, ZERO, ZERO_PERCENT, amountWithPathCurrency, encodeMixedRouteToPath, getOutputOfPools, getPathCurrency, isMint, isValidTokenPath, partitionMixedRouteByProtocol, tradeComparator };
2392
+ export { ADDRESS_THIS, ADDRESS_ZERO, ApprovalTypes, ApproveAndCall, MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER, MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER, MSG_SENDER, MixedRoute, MixedRouteSDK, MixedRouteTrade, MulticallExtended, ONE, ONE_HUNDRED_PERCENT, PaymentsExtended, Protocol, RouteV2, RouteV3, RouteV4, SwapRouter, Trade, ZERO, ZERO_PERCENT, amountWithPathCurrency, encodeMixedRouteToPath, getOutputOfPools, getPathCurrency, getPathToken, isMint, isValidTokenPath, partitionMixedRouteByProtocol, tradeComparator };
2342
2393
  //# sourceMappingURL=router-sdk.esm.js.map