@uniswap/router-sdk 1.9.2 → 1.10.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.
@@ -3,13 +3,15 @@ import JSBI from 'jsbi';
3
3
  import { Interface } from '@ethersproject/abi';
4
4
  import invariant from 'tiny-invariant';
5
5
  import { abi } from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json';
6
- import { NonfungiblePositionManager, toHex, Multicall, Payments, Pool, Route as Route$1, Trade as Trade$1, encodeRouteToPath, SelfPermit, Position } from '@uniswap/v3-sdk';
6
+ import { NonfungiblePositionManager, toHex, Multicall, Payments, Pool as Pool$1, Route as Route$1, Trade as Trade$2, encodeRouteToPath, SelfPermit, Position } from '@uniswap/v3-sdk';
7
7
  import { abi as abi$1 } from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json';
8
8
  import { abi as abi$2 } from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json';
9
9
  import { abi as abi$3 } from '@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json';
10
- import { Pair, Route, Trade as Trade$2 } from '@uniswap/v2-sdk';
10
+ import { Pair, Route, Trade as Trade$3 } from '@uniswap/v2-sdk';
11
+ import { Pool, Route as Route$2, Trade as Trade$1 } from '@uniswap/v4-sdk';
11
12
  import { pack } from '@ethersproject/solidity';
12
13
 
14
+ var ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
13
15
  var MSG_SENDER = '0x0000000000000000000000000000000000000001';
14
16
  var ADDRESS_THIS = '0x0000000000000000000000000000000000000002';
15
17
  var ZERO = /*#__PURE__*/JSBI.BigInt(0);
@@ -635,13 +637,22 @@ var MixedRouteSDK = /*#__PURE__*/function () {
635
637
  return pool.chainId === chainId;
636
638
  });
637
639
  !allOnSameChain ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_IDS') : invariant(false) : void 0;
638
- var wrappedInput = input.wrapped;
639
- !pools[0].involvesToken(wrappedInput) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0;
640
- !pools[pools.length - 1].involvesToken(output.wrapped) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
640
+ if (pools[0] instanceof Pool) {
641
+ this.adjustedInput = pools[0].involvesToken(input) ? input : input.wrapped;
642
+ } else {
643
+ this.adjustedInput = input.wrapped; // no native currencies in v2/v3
644
+ }
645
+ !pools[0].involvesToken(this.adjustedInput) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0;
646
+ var lastPool = pools[pools.length - 1];
647
+ if (lastPool instanceof Pool) {
648
+ !(lastPool.involvesToken(output) || lastPool.involvesToken(output.wrapped)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
649
+ } else {
650
+ !lastPool.involvesToken(output.wrapped) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
651
+ }
641
652
  /**
642
653
  * Normalizes token0-token1 order and selects the next token/fee step to add to the path
643
654
  * */
644
- var tokenPath = [wrappedInput];
655
+ var tokenPath = [this.adjustedInput];
645
656
  for (var _iterator = _createForOfIteratorHelperLoose(pools.entries()), _step; !(_step = _iterator()).done;) {
646
657
  var _step$value = _step.value,
647
658
  i = _step$value[0],
@@ -673,17 +684,17 @@ var MixedRouteSDK = /*#__PURE__*/function () {
673
684
  price = _ref.price;
674
685
  return nextInput.equals(pool.token0) ? {
675
686
  nextInput: pool.token1,
676
- price: price.multiply(pool.token0Price)
687
+ price: price.multiply(pool.token0Price.asFraction)
677
688
  } : {
678
689
  nextInput: pool.token0,
679
- price: price.multiply(pool.token1Price)
690
+ price: price.multiply(pool.token1Price.asFraction)
680
691
  };
681
- }, this.pools[0].token0.equals(this.input.wrapped) ? {
692
+ }, this.pools[0].token0.equals(this.adjustedInput) ? {
682
693
  nextInput: this.pools[0].token1,
683
- price: this.pools[0].token0Price
694
+ price: this.pools[0].token0Price.asFraction
684
695
  } : {
685
696
  nextInput: this.pools[0].token0,
686
- price: this.pools[0].token1Price
697
+ price: this.pools[0].token1Price.asFraction
687
698
  }).price;
688
699
  return this._midPrice = new Price(this.input, this.output, price.denominator, price.numerator);
689
700
  }
@@ -691,6 +702,49 @@ var MixedRouteSDK = /*#__PURE__*/function () {
691
702
  return MixedRouteSDK;
692
703
  }();
693
704
 
705
+ function getOutputAmount(_x, _x2) {
706
+ return _getOutputAmount.apply(this, arguments);
707
+ }
708
+ function _getOutputAmount() {
709
+ _getOutputAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(pool, amountIn) {
710
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
711
+ while (1) switch (_context.prev = _context.next) {
712
+ case 0:
713
+ if (!(pool instanceof Pool)) {
714
+ _context.next = 11;
715
+ break;
716
+ }
717
+ if (!pool.involvesCurrency(amountIn.currency)) {
718
+ _context.next = 7;
719
+ break;
720
+ }
721
+ _context.next = 4;
722
+ return pool.getOutputAmount(amountIn);
723
+ case 4:
724
+ return _context.abrupt("return", _context.sent);
725
+ case 7:
726
+ if (!pool.involvesCurrency(amountIn.currency.wrapped)) {
727
+ _context.next = 11;
728
+ break;
729
+ }
730
+ _context.next = 10;
731
+ return pool.getOutputAmount(amountIn.wrapped);
732
+ case 10:
733
+ return _context.abrupt("return", _context.sent);
734
+ case 11:
735
+ _context.next = 13;
736
+ return pool.getOutputAmount(amountIn.wrapped);
737
+ case 13:
738
+ return _context.abrupt("return", _context.sent);
739
+ case 14:
740
+ case "end":
741
+ return _context.stop();
742
+ }
743
+ }, _callee);
744
+ }));
745
+ return _getOutputAmount.apply(this, arguments);
746
+ }
747
+
694
748
  /**
695
749
  * Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
696
750
  * @template TInput The input token, either Ether or an ERC-20
@@ -768,15 +822,24 @@ var MixedRouteTrade = /*#__PURE__*/function () {
768
822
  }).reduce(function (total, cur) {
769
823
  return total + cur;
770
824
  }, 0);
771
- var poolAddressSet = new Set();
825
+ var poolIdentifierSet = new Set();
772
826
  for (var _iterator = _createForOfIteratorHelperLoose(routes), _step; !(_step = _iterator()).done;) {
773
827
  var route = _step.value.route;
774
828
  for (var _iterator2 = _createForOfIteratorHelperLoose(route.pools), _step2; !(_step2 = _iterator2()).done;) {
775
829
  var pool = _step2.value;
776
- pool instanceof Pool ? poolAddressSet.add(Pool.getAddress(pool.token0, pool.token1, pool.fee)) : poolAddressSet.add(Pair.getAddress(pool.token0, pool.token1));
830
+ if (pool instanceof Pool) {
831
+ poolIdentifierSet.add(pool.poolId);
832
+ } else if (pool instanceof Pool$1) {
833
+ poolIdentifierSet.add(Pool$1.getAddress(pool.token0, pool.token1, pool.fee));
834
+ } else if (pool instanceof Pair) {
835
+ var pair = pool;
836
+ poolIdentifierSet.add(Pair.getAddress(pair.token0, pair.token1));
837
+ } else {
838
+ throw new Error('Unexpected pool type in route when constructing trade object');
839
+ }
777
840
  }
778
841
  }
779
- !(numPools === poolAddressSet.size) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS_DUPLICATED') : invariant(false) : void 0;
842
+ !(numPools === poolIdentifierSet.size) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS_DUPLICATED') : invariant(false) : void 0;
780
843
  !(tradeType === TradeType.EXACT_INPUT) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TRADE_TYPE') : invariant(false) : void 0;
781
844
  this.swaps = routes;
782
845
  this.tradeType = tradeType;
@@ -802,14 +865,14 @@ var MixedRouteTrade = /*#__PURE__*/function () {
802
865
  /*#__PURE__*/
803
866
  function () {
804
867
  var _fromRoute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(route, amount, tradeType) {
805
- var amounts, inputAmount, outputAmount, i, pool, _yield$pool$getOutput, _outputAmount;
868
+ var amounts, inputAmount, outputAmount, i, pool, _yield$getOutputAmoun, _outputAmount;
806
869
  return _regeneratorRuntime().wrap(function _callee$(_context) {
807
870
  while (1) switch (_context.prev = _context.next) {
808
871
  case 0:
809
872
  amounts = new Array(route.path.length);
810
873
  !(tradeType === TradeType.EXACT_INPUT) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TRADE_TYPE') : invariant(false) : void 0;
811
874
  !amount.currency.equals(route.input) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0;
812
- amounts[0] = amount.wrapped;
875
+ amounts[0] = route.pools[0] instanceof Pool ? amount : amount.wrapped;
813
876
  i = 0;
814
877
  case 5:
815
878
  if (!(i < route.path.length - 1)) {
@@ -818,10 +881,10 @@ var MixedRouteTrade = /*#__PURE__*/function () {
818
881
  }
819
882
  pool = route.pools[i];
820
883
  _context.next = 9;
821
- return pool.getOutputAmount(amounts[i]);
884
+ return getOutputAmount(pool, amounts[i]);
822
885
  case 9:
823
- _yield$pool$getOutput = _context.sent;
824
- _outputAmount = _yield$pool$getOutput[0];
886
+ _yield$getOutputAmoun = _context.sent;
887
+ _outputAmount = _yield$getOutputAmoun[0];
825
888
  amounts[i + 1] = _outputAmount;
826
889
  case 12:
827
890
  i++;
@@ -864,7 +927,7 @@ var MixedRouteTrade = /*#__PURE__*/function () {
864
927
  /*#__PURE__*/
865
928
  function () {
866
929
  var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(routes, tradeType) {
867
- var populatedRoutes, _iterator3, _step3, _step3$value, route, amount, amounts, inputAmount, outputAmount, i, pool, _yield$pool$getOutput2, _outputAmount2;
930
+ var populatedRoutes, _iterator3, _step3, _step3$value, route, amount, amounts, inputAmount, outputAmount, i, pool, _yield$getOutputAmoun2, _outputAmount2;
868
931
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
869
932
  while (1) switch (_context2.prev = _context2.next) {
870
933
  case 0:
@@ -882,7 +945,7 @@ var MixedRouteTrade = /*#__PURE__*/function () {
882
945
  outputAmount = void 0;
883
946
  !amount.currency.equals(route.input) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0;
884
947
  inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
885
- amounts[0] = CurrencyAmount.fromFractionalAmount(route.input.wrapped, amount.numerator, amount.denominator);
948
+ amounts[0] = CurrencyAmount.fromFractionalAmount(route.adjustedInput, amount.numerator, amount.denominator);
886
949
  i = 0;
887
950
  case 12:
888
951
  if (!(i < route.path.length - 1)) {
@@ -891,10 +954,10 @@ var MixedRouteTrade = /*#__PURE__*/function () {
891
954
  }
892
955
  pool = route.pools[i];
893
956
  _context2.next = 16;
894
- return pool.getOutputAmount(amounts[i]);
957
+ return getOutputAmount(pool, amounts[i]);
895
958
  case 16:
896
- _yield$pool$getOutput2 = _context2.sent;
897
- _outputAmount2 = _yield$pool$getOutput2[0];
959
+ _yield$getOutputAmoun2 = _context2.sent;
960
+ _outputAmount2 = _yield$getOutputAmoun2[0];
898
961
  amounts[i + 1] = _outputAmount2;
899
962
  case 19:
900
963
  i++;
@@ -1014,7 +1077,7 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1014
1077
  var _bestTradeExactIn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(pools, currencyAmountIn, currencyOut, _temp,
1015
1078
  // used in recursion.
1016
1079
  currentPools, nextAmountIn, bestTrades) {
1017
- var _ref5, _ref5$maxNumResults, maxNumResults, _ref5$maxHops, maxHops, amountIn, tokenOut, i, pool, amountOut, _yield$pool$getOutput3, poolsExcludingThisPool;
1080
+ var _ref5, _ref5$maxNumResults, maxNumResults, _ref5$maxHops, maxHops, amountIn, i, pool, amountInAdjusted, amountOut, _ref6, poolsExcludingThisPool;
1018
1081
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1019
1082
  while (1) switch (_context3.prev = _context3.next) {
1020
1083
  case 0:
@@ -1031,20 +1094,20 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1031
1094
  !(pools.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS') : invariant(false) : void 0;
1032
1095
  !(maxHops > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_HOPS') : invariant(false) : void 0;
1033
1096
  !(currencyAmountIn === nextAmountIn || currentPools.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_RECURSION') : invariant(false) : void 0;
1034
- amountIn = nextAmountIn.wrapped;
1035
- tokenOut = currencyOut.wrapped;
1097
+ amountIn = nextAmountIn;
1036
1098
  i = 0;
1037
- case 10:
1099
+ case 9:
1038
1100
  if (!(i < pools.length)) {
1039
- _context3.next = 49;
1101
+ _context3.next = 56;
1040
1102
  break;
1041
1103
  }
1042
- pool = pools[i]; // pool irrelevant
1043
- if (!(!pool.token0.equals(amountIn.currency) && !pool.token1.equals(amountIn.currency))) {
1104
+ pool = pools[i];
1105
+ amountInAdjusted = pool instanceof Pool ? amountIn : amountIn.wrapped; // pool irrelevant
1106
+ if (!(!pool.token0.equals(amountInAdjusted.currency) && !pool.token1.equals(amountInAdjusted.currency))) {
1044
1107
  _context3.next = 14;
1045
1108
  break;
1046
1109
  }
1047
- return _context3.abrupt("continue", 46);
1110
+ return _context3.abrupt("continue", 53);
1048
1111
  case 14:
1049
1112
  if (!(pool instanceof Pair)) {
1050
1113
  _context3.next = 17;
@@ -1054,65 +1117,78 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1054
1117
  _context3.next = 17;
1055
1118
  break;
1056
1119
  }
1057
- return _context3.abrupt("continue", 46);
1120
+ return _context3.abrupt("continue", 53);
1058
1121
  case 17:
1059
1122
  amountOut = void 0;
1060
1123
  _context3.prev = 18;
1061
- _context3.next = 22;
1062
- return pool.getOutputAmount(amountIn);
1063
- case 22:
1064
- _yield$pool$getOutput3 = _context3.sent;
1065
- amountOut = _yield$pool$getOutput3[0];
1066
- _context3.next = 31;
1124
+ if (!(pool instanceof Pool)) {
1125
+ _context3.next = 26;
1126
+ break;
1127
+ }
1128
+ _context3.next = 23;
1129
+ return pool.getOutputAmount(amountInAdjusted);
1130
+ case 23:
1131
+ _context3.t0 = _context3.sent;
1132
+ _context3.next = 29;
1067
1133
  break;
1068
1134
  case 26:
1069
- _context3.prev = 26;
1070
- _context3.t0 = _context3["catch"](18);
1071
- if (!_context3.t0.isInsufficientInputAmountError) {
1072
- _context3.next = 30;
1135
+ _context3.next = 28;
1136
+ return pool.getOutputAmount(amountInAdjusted.wrapped);
1137
+ case 28:
1138
+ _context3.t0 = _context3.sent;
1139
+ case 29:
1140
+ _ref6 = _context3.t0;
1141
+ amountOut = _ref6[0];
1142
+ _context3.next = 38;
1143
+ break;
1144
+ case 33:
1145
+ _context3.prev = 33;
1146
+ _context3.t1 = _context3["catch"](18);
1147
+ if (!_context3.t1.isInsufficientInputAmountError) {
1148
+ _context3.next = 37;
1073
1149
  break;
1074
1150
  }
1075
- return _context3.abrupt("continue", 46);
1076
- case 30:
1077
- throw _context3.t0;
1078
- case 31:
1079
- if (!(amountOut.currency.isToken && amountOut.currency.equals(tokenOut))) {
1080
- _context3.next = 42;
1151
+ return _context3.abrupt("continue", 53);
1152
+ case 37:
1153
+ throw _context3.t1;
1154
+ case 38:
1155
+ if (!amountOut.currency.wrapped.equals(currencyOut.wrapped)) {
1156
+ _context3.next = 49;
1081
1157
  break;
1082
1158
  }
1083
- _context3.t1 = sortedInsert;
1084
- _context3.t2 = bestTrades;
1085
- _context3.next = 36;
1159
+ _context3.t2 = sortedInsert;
1160
+ _context3.t3 = bestTrades;
1161
+ _context3.next = 43;
1086
1162
  return MixedRouteTrade.fromRoute(new MixedRouteSDK([].concat(currentPools, [pool]), currencyAmountIn.currency, currencyOut), currencyAmountIn, TradeType.EXACT_INPUT);
1087
- case 36:
1088
- _context3.t3 = _context3.sent;
1089
- _context3.t4 = maxNumResults;
1090
- _context3.t5 = tradeComparator;
1091
- (0, _context3.t1)(_context3.t2, _context3.t3, _context3.t4, _context3.t5);
1092
- _context3.next = 46;
1163
+ case 43:
1164
+ _context3.t4 = _context3.sent;
1165
+ _context3.t5 = maxNumResults;
1166
+ _context3.t6 = tradeComparator;
1167
+ (0, _context3.t2)(_context3.t3, _context3.t4, _context3.t5, _context3.t6);
1168
+ _context3.next = 53;
1093
1169
  break;
1094
- case 42:
1170
+ case 49:
1095
1171
  if (!(maxHops > 1 && pools.length > 1)) {
1096
- _context3.next = 46;
1172
+ _context3.next = 53;
1097
1173
  break;
1098
1174
  }
1099
1175
  poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length)); // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops
1100
- _context3.next = 46;
1176
+ _context3.next = 53;
1101
1177
  return MixedRouteTrade.bestTradeExactIn(poolsExcludingThisPool, currencyAmountIn, currencyOut, {
1102
1178
  maxNumResults: maxNumResults,
1103
1179
  maxHops: maxHops - 1
1104
1180
  }, [].concat(currentPools, [pool]), amountOut, bestTrades);
1105
- case 46:
1181
+ case 53:
1106
1182
  i++;
1107
- _context3.next = 10;
1183
+ _context3.next = 9;
1108
1184
  break;
1109
- case 49:
1185
+ case 56:
1110
1186
  return _context3.abrupt("return", bestTrades);
1111
- case 50:
1187
+ case 57:
1112
1188
  case "end":
1113
1189
  return _context3.stop();
1114
1190
  }
1115
- }, _callee3, null, [[18, 26]]);
1191
+ }, _callee3, null, [[18, 33]]);
1116
1192
  }));
1117
1193
  function bestTradeExactIn(_x6, _x7, _x8, _x9, _x10, _x11, _x12) {
1118
1194
  return _bestTradeExactIn.apply(this, arguments);
@@ -1135,8 +1211,8 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1135
1211
  return this._inputAmount;
1136
1212
  }
1137
1213
  var inputCurrency = this.swaps[0].inputAmount.currency;
1138
- var totalInputFromRoutes = this.swaps.map(function (_ref6) {
1139
- var inputAmount = _ref6.inputAmount;
1214
+ var totalInputFromRoutes = this.swaps.map(function (_ref7) {
1215
+ var inputAmount = _ref7.inputAmount;
1140
1216
  return inputAmount;
1141
1217
  }).reduce(function (total, cur) {
1142
1218
  return total.add(cur);
@@ -1154,8 +1230,8 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1154
1230
  return this._outputAmount;
1155
1231
  }
1156
1232
  var outputCurrency = this.swaps[0].outputAmount.currency;
1157
- var totalOutputFromRoutes = this.swaps.map(function (_ref7) {
1158
- var outputAmount = _ref7.outputAmount;
1233
+ var totalOutputFromRoutes = this.swaps.map(function (_ref8) {
1234
+ var outputAmount = _ref8.outputAmount;
1159
1235
  return outputAmount;
1160
1236
  }).reduce(function (total, cur) {
1161
1237
  return total.add(cur);
@@ -1201,6 +1277,7 @@ var Protocol;
1201
1277
  (function (Protocol) {
1202
1278
  Protocol["V2"] = "V2";
1203
1279
  Protocol["V3"] = "V3";
1280
+ Protocol["V4"] = "V4";
1204
1281
  Protocol["MIXED"] = "MIXED";
1205
1282
  })(Protocol || (Protocol = {}));
1206
1283
 
@@ -1228,14 +1305,26 @@ var RouteV3 = /*#__PURE__*/function (_V3RouteSDK) {
1228
1305
  }
1229
1306
  return RouteV3;
1230
1307
  }(Route$1);
1308
+ // V4 route wrapper
1309
+ var RouteV4 = /*#__PURE__*/function (_V4RouteSDK) {
1310
+ _inheritsLoose(RouteV4, _V4RouteSDK);
1311
+ function RouteV4(v4Route) {
1312
+ var _this3;
1313
+ _this3 = _V4RouteSDK.call(this, v4Route.pools, v4Route.input, v4Route.output) || this;
1314
+ _this3.protocol = Protocol.V4;
1315
+ _this3.path = v4Route.currencyPath;
1316
+ return _this3;
1317
+ }
1318
+ return RouteV4;
1319
+ }(Route$2);
1231
1320
  // Mixed route wrapper
1232
1321
  var MixedRoute = /*#__PURE__*/function (_MixedRouteSDK) {
1233
1322
  _inheritsLoose(MixedRoute, _MixedRouteSDK);
1234
1323
  function MixedRoute(mixedRoute) {
1235
- var _this3;
1236
- _this3 = _MixedRouteSDK.call(this, mixedRoute.pools, mixedRoute.input, mixedRoute.output) || this;
1237
- _this3.protocol = Protocol.MIXED;
1238
- return _this3;
1324
+ var _this4;
1325
+ _this4 = _MixedRouteSDK.call(this, mixedRoute.pools, mixedRoute.input, mixedRoute.output) || this;
1326
+ _this4.protocol = Protocol.MIXED;
1327
+ return _this4;
1239
1328
  }
1240
1329
  return MixedRoute;
1241
1330
  }(MixedRouteSDK);
@@ -1245,6 +1334,7 @@ var Trade = /*#__PURE__*/function () {
1245
1334
  function Trade(_ref) {
1246
1335
  var v2Routes = _ref.v2Routes,
1247
1336
  v3Routes = _ref.v3Routes,
1337
+ v4Routes = _ref.v4Routes,
1248
1338
  tradeType = _ref.tradeType,
1249
1339
  mixedRoutes = _ref.mixedRoutes;
1250
1340
  this.swaps = [];
@@ -1277,13 +1367,27 @@ var Trade = /*#__PURE__*/function () {
1277
1367
  outputAmount: _outputAmount2
1278
1368
  });
1279
1369
  }
1370
+ // wrap v4 routes
1371
+ for (var _iterator3 = _createForOfIteratorHelperLoose(v4Routes), _step3; !(_step3 = _iterator3()).done;) {
1372
+ var _step3$value = _step3.value,
1373
+ routev4 = _step3$value.routev4,
1374
+ _inputAmount3 = _step3$value.inputAmount,
1375
+ _outputAmount3 = _step3$value.outputAmount;
1376
+ var _route3 = new RouteV4(routev4);
1377
+ this.routes.push(_route3);
1378
+ this.swaps.push({
1379
+ route: _route3,
1380
+ inputAmount: _inputAmount3,
1381
+ outputAmount: _outputAmount3
1382
+ });
1383
+ }
1280
1384
  // wrap mixedRoutes
1281
1385
  if (mixedRoutes) {
1282
- for (var _iterator3 = _createForOfIteratorHelperLoose(mixedRoutes), _step3; !(_step3 = _iterator3()).done;) {
1283
- var _step3$value = _step3.value,
1284
- mixedRoute = _step3$value.mixedRoute,
1285
- inputAmount = _step3$value.inputAmount,
1286
- outputAmount = _step3$value.outputAmount;
1386
+ for (var _iterator4 = _createForOfIteratorHelperLoose(mixedRoutes), _step4; !(_step4 = _iterator4()).done;) {
1387
+ var _step4$value = _step4.value,
1388
+ mixedRoute = _step4$value.mixedRoute,
1389
+ inputAmount = _step4$value.inputAmount,
1390
+ outputAmount = _step4$value.outputAmount;
1287
1391
  var route = new MixedRoute(mixedRoute);
1288
1392
  this.routes.push(route);
1289
1393
  this.swaps.push({
@@ -1315,22 +1419,24 @@ var Trade = /*#__PURE__*/function () {
1315
1419
  }).reduce(function (total, cur) {
1316
1420
  return total + cur;
1317
1421
  }, 0);
1318
- var poolAddressSet = new Set();
1319
- for (var _iterator4 = _createForOfIteratorHelperLoose(this.swaps), _step4; !(_step4 = _iterator4()).done;) {
1320
- var _route3 = _step4.value.route;
1321
- for (var _iterator5 = _createForOfIteratorHelperLoose(_route3.pools), _step5; !(_step5 = _iterator5()).done;) {
1322
- var pool = _step5.value;
1422
+ var poolIdentifierSet = new Set();
1423
+ for (var _iterator5 = _createForOfIteratorHelperLoose(this.swaps), _step5; !(_step5 = _iterator5()).done;) {
1424
+ var _route4 = _step5.value.route;
1425
+ for (var _iterator6 = _createForOfIteratorHelperLoose(_route4.pools), _step6; !(_step6 = _iterator6()).done;) {
1426
+ var pool = _step6.value;
1323
1427
  if (pool instanceof Pool) {
1324
- poolAddressSet.add(Pool.getAddress(pool.token0, pool.token1, pool.fee));
1428
+ poolIdentifierSet.add(pool.poolId);
1429
+ } else if (pool instanceof Pool$1) {
1430
+ poolIdentifierSet.add(Pool$1.getAddress(pool.token0, pool.token1, pool.fee));
1325
1431
  } else if (pool instanceof Pair) {
1326
1432
  var pair = pool;
1327
- poolAddressSet.add(Pair.getAddress(pair.token0, pair.token1));
1433
+ poolIdentifierSet.add(Pair.getAddress(pair.token0, pair.token1));
1328
1434
  } else {
1329
1435
  throw new Error('Unexpected pool type in route when constructing trade object');
1330
1436
  }
1331
1437
  }
1332
1438
  }
1333
- !(numPools === poolAddressSet.size) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS_DUPLICATED') : invariant(false) : void 0;
1439
+ !(numPools === poolIdentifierSet.size) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS_DUPLICATED') : invariant(false) : void 0;
1334
1440
  }
1335
1441
  var _proto = Trade.prototype;
1336
1442
  /**
@@ -1376,59 +1482,81 @@ var Trade = /*#__PURE__*/function () {
1376
1482
  return new Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
1377
1483
  };
1378
1484
  Trade.fromRoutes = /*#__PURE__*/function () {
1379
- var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(v2Routes, v3Routes, tradeType, mixedRoutes) {
1380
- var populatedV2Routes, populatedV3Routes, populatedMixedRoutes, _iterator6, _step6, _step6$value, routev2, _amount, v2Trade, _inputAmount3, _outputAmount3, _iterator7, _step7, _step7$value, routev3, _amount2, v3Trade, _inputAmount4, _outputAmount4, _iterator8, _step8, _step8$value, mixedRoute, amount, mixedRouteTrade, inputAmount, outputAmount;
1485
+ var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(v2Routes, v3Routes, v4Routes, tradeType, mixedRoutes) {
1486
+ var populatedV2Routes, populatedV3Routes, populatedV4Routes, populatedMixedRoutes, _iterator7, _step7, _step7$value, routev2, _amount, v2Trade, _inputAmount4, _outputAmount4, _iterator8, _step8, _step8$value, routev3, _amount2, v3Trade, _inputAmount5, _outputAmount5, _iterator9, _step9, _step9$value, routev4, _amount3, v4Trade, _inputAmount6, _outputAmount6, _iterator10, _step10, _step10$value, mixedRoute, amount, mixedRouteTrade, inputAmount, outputAmount;
1381
1487
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1382
1488
  while (1) switch (_context.prev = _context.next) {
1383
1489
  case 0:
1384
1490
  populatedV2Routes = [];
1385
1491
  populatedV3Routes = [];
1492
+ populatedV4Routes = [];
1386
1493
  populatedMixedRoutes = [];
1387
- for (_iterator6 = _createForOfIteratorHelperLoose(v2Routes); !(_step6 = _iterator6()).done;) {
1388
- _step6$value = _step6.value, routev2 = _step6$value.routev2, _amount = _step6$value.amount;
1389
- v2Trade = new Trade$2(routev2, _amount, tradeType);
1390
- _inputAmount3 = v2Trade.inputAmount, _outputAmount3 = v2Trade.outputAmount;
1494
+ for (_iterator7 = _createForOfIteratorHelperLoose(v2Routes); !(_step7 = _iterator7()).done;) {
1495
+ _step7$value = _step7.value, routev2 = _step7$value.routev2, _amount = _step7$value.amount;
1496
+ v2Trade = new Trade$3(routev2, _amount, tradeType);
1497
+ _inputAmount4 = v2Trade.inputAmount, _outputAmount4 = v2Trade.outputAmount;
1391
1498
  populatedV2Routes.push({
1392
1499
  routev2: routev2,
1393
- inputAmount: _inputAmount3,
1394
- outputAmount: _outputAmount3
1500
+ inputAmount: _inputAmount4,
1501
+ outputAmount: _outputAmount4
1395
1502
  });
1396
1503
  }
1397
- _iterator7 = _createForOfIteratorHelperLoose(v3Routes);
1398
- case 5:
1399
- if ((_step7 = _iterator7()).done) {
1400
- _context.next = 14;
1504
+ _iterator8 = _createForOfIteratorHelperLoose(v3Routes);
1505
+ case 6:
1506
+ if ((_step8 = _iterator8()).done) {
1507
+ _context.next = 15;
1401
1508
  break;
1402
1509
  }
1403
- _step7$value = _step7.value, routev3 = _step7$value.routev3, _amount2 = _step7$value.amount;
1404
- _context.next = 9;
1405
- return Trade$1.fromRoute(routev3, _amount2, tradeType);
1406
- case 9:
1510
+ _step8$value = _step8.value, routev3 = _step8$value.routev3, _amount2 = _step8$value.amount;
1511
+ _context.next = 10;
1512
+ return Trade$2.fromRoute(routev3, _amount2, tradeType);
1513
+ case 10:
1407
1514
  v3Trade = _context.sent;
1408
- _inputAmount4 = v3Trade.inputAmount, _outputAmount4 = v3Trade.outputAmount;
1515
+ _inputAmount5 = v3Trade.inputAmount, _outputAmount5 = v3Trade.outputAmount;
1409
1516
  populatedV3Routes.push({
1410
1517
  routev3: routev3,
1411
- inputAmount: _inputAmount4,
1412
- outputAmount: _outputAmount4
1518
+ inputAmount: _inputAmount5,
1519
+ outputAmount: _outputAmount5
1413
1520
  });
1414
- case 12:
1415
- _context.next = 5;
1521
+ case 13:
1522
+ _context.next = 6;
1416
1523
  break;
1417
- case 14:
1418
- if (!mixedRoutes) {
1419
- _context.next = 25;
1420
- break;
1421
- }
1422
- _iterator8 = _createForOfIteratorHelperLoose(mixedRoutes);
1524
+ case 15:
1525
+ _iterator9 = _createForOfIteratorHelperLoose(v4Routes);
1423
1526
  case 16:
1424
- if ((_step8 = _iterator8()).done) {
1527
+ if ((_step9 = _iterator9()).done) {
1425
1528
  _context.next = 25;
1426
1529
  break;
1427
1530
  }
1428
- _step8$value = _step8.value, mixedRoute = _step8$value.mixedRoute, amount = _step8$value.amount;
1531
+ _step9$value = _step9.value, routev4 = _step9$value.routev4, _amount3 = _step9$value.amount;
1429
1532
  _context.next = 20;
1430
- return MixedRouteTrade.fromRoute(mixedRoute, amount, tradeType);
1533
+ return Trade$1.fromRoute(routev4, _amount3, tradeType);
1431
1534
  case 20:
1535
+ v4Trade = _context.sent;
1536
+ _inputAmount6 = v4Trade.inputAmount, _outputAmount6 = v4Trade.outputAmount;
1537
+ populatedV4Routes.push({
1538
+ routev4: routev4,
1539
+ inputAmount: _inputAmount6,
1540
+ outputAmount: _outputAmount6
1541
+ });
1542
+ case 23:
1543
+ _context.next = 16;
1544
+ break;
1545
+ case 25:
1546
+ if (!mixedRoutes) {
1547
+ _context.next = 36;
1548
+ break;
1549
+ }
1550
+ _iterator10 = _createForOfIteratorHelperLoose(mixedRoutes);
1551
+ case 27:
1552
+ if ((_step10 = _iterator10()).done) {
1553
+ _context.next = 36;
1554
+ break;
1555
+ }
1556
+ _step10$value = _step10.value, mixedRoute = _step10$value.mixedRoute, amount = _step10$value.amount;
1557
+ _context.next = 31;
1558
+ return MixedRouteTrade.fromRoute(mixedRoute, amount, tradeType);
1559
+ case 31:
1432
1560
  mixedRouteTrade = _context.sent;
1433
1561
  inputAmount = mixedRouteTrade.inputAmount, outputAmount = mixedRouteTrade.outputAmount;
1434
1562
  populatedMixedRoutes.push({
@@ -1436,99 +1564,119 @@ var Trade = /*#__PURE__*/function () {
1436
1564
  inputAmount: inputAmount,
1437
1565
  outputAmount: outputAmount
1438
1566
  });
1439
- case 23:
1440
- _context.next = 16;
1567
+ case 34:
1568
+ _context.next = 27;
1441
1569
  break;
1442
- case 25:
1570
+ case 36:
1443
1571
  return _context.abrupt("return", new Trade({
1444
1572
  v2Routes: populatedV2Routes,
1445
1573
  v3Routes: populatedV3Routes,
1574
+ v4Routes: populatedV4Routes,
1446
1575
  mixedRoutes: populatedMixedRoutes,
1447
1576
  tradeType: tradeType
1448
1577
  }));
1449
- case 26:
1578
+ case 37:
1450
1579
  case "end":
1451
1580
  return _context.stop();
1452
1581
  }
1453
1582
  }, _callee);
1454
1583
  }));
1455
- function fromRoutes(_x, _x2, _x3, _x4) {
1584
+ function fromRoutes(_x, _x2, _x3, _x4, _x5) {
1456
1585
  return _fromRoutes.apply(this, arguments);
1457
1586
  }
1458
1587
  return fromRoutes;
1459
1588
  }();
1460
1589
  Trade.fromRoute = /*#__PURE__*/function () {
1461
1590
  var _fromRoute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(route, amount, tradeType) {
1462
- var v2Routes, v3Routes, mixedRoutes, v2Trade, inputAmount, outputAmount, v3Trade, _inputAmount5, _outputAmount5, mixedRouteTrade, _inputAmount6, _outputAmount6;
1591
+ var v2Routes, v3Routes, v4Routes, mixedRoutes, v2Trade, inputAmount, outputAmount, v3Trade, _inputAmount7, _outputAmount7, v4Trade, _inputAmount8, _outputAmount8, mixedRouteTrade, _inputAmount9, _outputAmount9;
1463
1592
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1464
1593
  while (1) switch (_context2.prev = _context2.next) {
1465
1594
  case 0:
1466
1595
  v2Routes = [];
1467
1596
  v3Routes = [];
1597
+ v4Routes = [];
1468
1598
  mixedRoutes = [];
1469
1599
  if (!(route instanceof Route)) {
1470
- _context2.next = 9;
1600
+ _context2.next = 10;
1471
1601
  break;
1472
1602
  }
1473
- v2Trade = new Trade$2(route, amount, tradeType);
1603
+ v2Trade = new Trade$3(route, amount, tradeType);
1474
1604
  inputAmount = v2Trade.inputAmount, outputAmount = v2Trade.outputAmount;
1475
1605
  v2Routes = [{
1476
1606
  routev2: route,
1477
1607
  inputAmount: inputAmount,
1478
1608
  outputAmount: outputAmount
1479
1609
  }];
1480
- _context2.next = 26;
1610
+ _context2.next = 35;
1481
1611
  break;
1482
- case 9:
1612
+ case 10:
1483
1613
  if (!(route instanceof Route$1)) {
1484
- _context2.next = 17;
1614
+ _context2.next = 18;
1485
1615
  break;
1486
1616
  }
1487
- _context2.next = 12;
1488
- return Trade$1.fromRoute(route, amount, tradeType);
1489
- case 12:
1617
+ _context2.next = 13;
1618
+ return Trade$2.fromRoute(route, amount, tradeType);
1619
+ case 13:
1490
1620
  v3Trade = _context2.sent;
1491
- _inputAmount5 = v3Trade.inputAmount, _outputAmount5 = v3Trade.outputAmount;
1621
+ _inputAmount7 = v3Trade.inputAmount, _outputAmount7 = v3Trade.outputAmount;
1492
1622
  v3Routes = [{
1493
1623
  routev3: route,
1494
- inputAmount: _inputAmount5,
1495
- outputAmount: _outputAmount5
1624
+ inputAmount: _inputAmount7,
1625
+ outputAmount: _outputAmount7
1496
1626
  }];
1497
- _context2.next = 26;
1627
+ _context2.next = 35;
1498
1628
  break;
1499
- case 17:
1629
+ case 18:
1630
+ if (!(route instanceof Route$2)) {
1631
+ _context2.next = 26;
1632
+ break;
1633
+ }
1634
+ _context2.next = 21;
1635
+ return Trade$1.fromRoute(route, amount, tradeType);
1636
+ case 21:
1637
+ v4Trade = _context2.sent;
1638
+ _inputAmount8 = v4Trade.inputAmount, _outputAmount8 = v4Trade.outputAmount;
1639
+ v4Routes = [{
1640
+ routev4: route,
1641
+ inputAmount: _inputAmount8,
1642
+ outputAmount: _outputAmount8
1643
+ }];
1644
+ _context2.next = 35;
1645
+ break;
1646
+ case 26:
1500
1647
  if (!(route instanceof MixedRouteSDK)) {
1501
- _context2.next = 25;
1648
+ _context2.next = 34;
1502
1649
  break;
1503
1650
  }
1504
- _context2.next = 20;
1651
+ _context2.next = 29;
1505
1652
  return MixedRouteTrade.fromRoute(route, amount, tradeType);
1506
- case 20:
1653
+ case 29:
1507
1654
  mixedRouteTrade = _context2.sent;
1508
- _inputAmount6 = mixedRouteTrade.inputAmount, _outputAmount6 = mixedRouteTrade.outputAmount;
1655
+ _inputAmount9 = mixedRouteTrade.inputAmount, _outputAmount9 = mixedRouteTrade.outputAmount;
1509
1656
  mixedRoutes = [{
1510
1657
  mixedRoute: route,
1511
- inputAmount: _inputAmount6,
1512
- outputAmount: _outputAmount6
1658
+ inputAmount: _inputAmount9,
1659
+ outputAmount: _outputAmount9
1513
1660
  }];
1514
- _context2.next = 26;
1661
+ _context2.next = 35;
1515
1662
  break;
1516
- case 25:
1663
+ case 34:
1517
1664
  throw new Error('Invalid route type');
1518
- case 26:
1665
+ case 35:
1519
1666
  return _context2.abrupt("return", new Trade({
1520
1667
  v2Routes: v2Routes,
1521
1668
  v3Routes: v3Routes,
1669
+ v4Routes: v4Routes,
1522
1670
  mixedRoutes: mixedRoutes,
1523
1671
  tradeType: tradeType
1524
1672
  }));
1525
- case 27:
1673
+ case 36:
1526
1674
  case "end":
1527
1675
  return _context2.stop();
1528
1676
  }
1529
1677
  }, _callee2);
1530
1678
  }));
1531
- function fromRoute(_x5, _x6, _x7) {
1679
+ function fromRoute(_x6, _x7, _x8) {
1532
1680
  return _fromRoute.apply(this, arguments);
1533
1681
  }
1534
1682
  return fromRoute;
@@ -1609,10 +1757,10 @@ var Trade = /*#__PURE__*/function () {
1609
1757
  // because we're unable to derive the pre-buy-tax amount, use 0% as a placeholder.
1610
1758
  if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT;
1611
1759
  var spotOutputAmount = CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
1612
- for (var _iterator9 = _createForOfIteratorHelperLoose(this.swaps), _step9; !(_step9 = _iterator9()).done;) {
1613
- var _step9$value = _step9.value,
1614
- route = _step9$value.route,
1615
- inputAmount = _step9$value.inputAmount;
1760
+ for (var _iterator11 = _createForOfIteratorHelperLoose(this.swaps), _step11; !(_step11 = _iterator11()).done;) {
1761
+ var _step11$value = _step11.value,
1762
+ route = _step11$value.route,
1763
+ inputAmount = _step11$value.inputAmount;
1616
1764
  var midPrice = route.midPrice;
1617
1765
  var postTaxInputAmount = inputAmount.multiply(new Fraction(ONE).subtract(this.inputTax));
1618
1766
  spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount));
@@ -1641,18 +1789,19 @@ function encodeMixedRouteToPath(route) {
1641
1789
  var inputToken = _ref.inputToken,
1642
1790
  path = _ref.path,
1643
1791
  types = _ref.types;
1792
+ if (pool instanceof Pool) throw 'Encoding mixed routes with V4 not supported';
1644
1793
  var outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
1645
1794
  if (index === 0) {
1646
1795
  return {
1647
1796
  inputToken: outputToken,
1648
1797
  types: ['address', 'uint24', 'address'],
1649
- path: [inputToken.address, pool instanceof Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address]
1798
+ path: [inputToken.wrapped.address, pool instanceof Pool$1 ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.wrapped.address]
1650
1799
  };
1651
1800
  } else {
1652
1801
  return {
1653
1802
  inputToken: outputToken,
1654
1803
  types: [].concat(types, ['uint24', 'address']),
1655
- path: [].concat(path, [pool instanceof Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address])
1804
+ path: [].concat(path, [pool instanceof Pool$1 ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.wrapped.address])
1656
1805
  };
1657
1806
  }
1658
1807
  }, {
@@ -1675,7 +1824,7 @@ var partitionMixedRouteByProtocol = function partitionMixedRouteByProtocol(route
1675
1824
  var left = 0;
1676
1825
  var right = 0;
1677
1826
  while (right < route.pools.length) {
1678
- if (route.pools[left] instanceof Pool && route.pools[right] instanceof Pair || route.pools[left] instanceof Pair && route.pools[right] instanceof Pool) {
1827
+ if (route.pools[left] instanceof Pool$1 && route.pools[right] instanceof Pair || route.pools[left] instanceof Pair && route.pools[right] instanceof Pool$1) {
1679
1828
  acc.push(route.pools.slice(left, right));
1680
1829
  left = right;
1681
1830
  }
@@ -1826,6 +1975,9 @@ var SwapRouter = /*#__PURE__*/function () {
1826
1975
  route = _step2$value.route,
1827
1976
  inputAmount = _step2$value.inputAmount,
1828
1977
  outputAmount = _step2$value.outputAmount;
1978
+ if (route.pools.some(function (pool) {
1979
+ return pool instanceof Pool;
1980
+ })) throw 'Encoding mixed routes with V4 not supported';
1829
1981
  var amountIn = toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
1830
1982
  var amountOut = toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
1831
1983
  // flag for whether the trade is single hop or not
@@ -1833,7 +1985,7 @@ var SwapRouter = /*#__PURE__*/function () {
1833
1985
  var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : validateAndParseAddress(options.recipient);
1834
1986
  var mixedRouteIsAllV3 = function mixedRouteIsAllV3(route) {
1835
1987
  return route.pools.every(function (pool) {
1836
- return pool instanceof Pool;
1988
+ return pool instanceof Pool$1;
1837
1989
  });
1838
1990
  };
1839
1991
  if (singleHop) {
@@ -1841,8 +1993,8 @@ var SwapRouter = /*#__PURE__*/function () {
1841
1993
  /// We don't use encodeV3Swap() or encodeV2Swap() because casting the trade to a V3Trade or V2Trade is overcomplex
1842
1994
  if (mixedRouteIsAllV3(route)) {
1843
1995
  var exactInputSingleParams = {
1844
- tokenIn: route.path[0].address,
1845
- tokenOut: route.path[1].address,
1996
+ tokenIn: route.path[0].wrapped.address,
1997
+ tokenOut: route.path[1].wrapped.address,
1846
1998
  fee: route.pools[0].fee,
1847
1999
  recipient: recipient,
1848
2000
  amountIn: amountIn,
@@ -1852,7 +2004,7 @@ var SwapRouter = /*#__PURE__*/function () {
1852
2004
  calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]));
1853
2005
  } else {
1854
2006
  var path = route.path.map(function (token) {
1855
- return token.address;
2007
+ return token.wrapped.address;
1856
2008
  });
1857
2009
  var exactInputParams = [amountIn, performAggregatedSlippageCheck ? 0 : amountOut, path, recipient];
1858
2010
  calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams));
@@ -1871,7 +2023,7 @@ var SwapRouter = /*#__PURE__*/function () {
1871
2023
  var newRouteOriginal = new MixedRouteSDK([].concat(section), section[0].token0.equals(inputToken) ? section[0].token0 : section[0].token1, outputToken);
1872
2024
  var newRoute = new MixedRoute(newRouteOriginal);
1873
2025
  /// Previous output is now input
1874
- inputToken = outputToken;
2026
+ inputToken = outputToken.wrapped;
1875
2027
  if (mixedRouteIsAllV3(newRoute)) {
1876
2028
  var _path = encodeMixedRouteToPath(newRoute);
1877
2029
  var _exactInputParams = {
@@ -1886,7 +2038,7 @@ var SwapRouter = /*#__PURE__*/function () {
1886
2038
  calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [_exactInputParams]));
1887
2039
  } else {
1888
2040
  var _exactInputParams2 = [i === 0 ? amountIn : 0, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (token) {
1889
- return token.address;
2041
+ return token.wrapped.address;
1890
2042
  }), isLastSectionInRoute(i) ? recipient : ADDRESS_THIS];
1891
2043
  calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', _exactInputParams2));
1892
2044
  }
@@ -1903,7 +2055,7 @@ var SwapRouter = /*#__PURE__*/function () {
1903
2055
  if (trades instanceof Trade) {
1904
2056
  !trades.swaps.every(function (swap) {
1905
2057
  return swap.route.protocol === Protocol.V3 || swap.route.protocol === Protocol.V2 || swap.route.protocol === Protocol.MIXED;
1906
- }) ? process.env.NODE_ENV !== "production" ? invariant(false, 'UNSUPPORTED_PROTOCOL') : invariant(false) : void 0;
2058
+ }) ? process.env.NODE_ENV !== "production" ? invariant(false, 'UNSUPPORTED_PROTOCOL (encoding routes with v4 not supported)') : invariant(false) : void 0;
1907
2059
  var individualTrades = [];
1908
2060
  for (var _iterator3 = _createForOfIteratorHelperLoose(trades.swaps), _step3; !(_step3 = _iterator3()).done;) {
1909
2061
  var _step3$value = _step3.value,
@@ -1911,9 +2063,9 @@ var SwapRouter = /*#__PURE__*/function () {
1911
2063
  inputAmount = _step3$value.inputAmount,
1912
2064
  outputAmount = _step3$value.outputAmount;
1913
2065
  if (route.protocol === Protocol.V2) {
1914
- individualTrades.push(new Trade$2(route, trades.tradeType === TradeType.EXACT_INPUT ? inputAmount : outputAmount, trades.tradeType));
2066
+ individualTrades.push(new Trade$3(route, trades.tradeType === TradeType.EXACT_INPUT ? inputAmount : outputAmount, trades.tradeType));
1915
2067
  } else if (route.protocol === Protocol.V3) {
1916
- individualTrades.push(Trade$1.createUncheckedTrade({
2068
+ individualTrades.push(Trade$2.createUncheckedTrade({
1917
2069
  route: route,
1918
2070
  inputAmount: inputAmount,
1919
2071
  outputAmount: outputAmount,
@@ -1938,7 +2090,7 @@ var SwapRouter = /*#__PURE__*/function () {
1938
2090
  trades = [trades];
1939
2091
  }
1940
2092
  var numberOfTrades = trades.reduce(function (numberOfTrades, trade) {
1941
- return numberOfTrades + (trade instanceof Trade$1 || trade instanceof MixedRouteTrade ? trade.swaps.length : 1);
2093
+ return numberOfTrades + (trade instanceof Trade$2 || trade instanceof MixedRouteTrade ? trade.swaps.length : 1);
1942
2094
  }, 0);
1943
2095
  var sampleTrade = trades[0];
1944
2096
  // All trades should have the same starting/ending currency and trade type
@@ -1972,9 +2124,9 @@ var SwapRouter = /*#__PURE__*/function () {
1972
2124
  }
1973
2125
  for (var _iterator4 = _createForOfIteratorHelperLoose(trades), _step4; !(_step4 = _iterator4()).done;) {
1974
2126
  var trade = _step4.value;
1975
- if (trade instanceof Trade$2) {
2127
+ if (trade instanceof Trade$3) {
1976
2128
  calldatas.push(SwapRouter.encodeV2Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck));
1977
- } else if (trade instanceof Trade$1) {
2129
+ } else if (trade instanceof Trade$2) {
1978
2130
  for (var _iterator5 = _createForOfIteratorHelperLoose(SwapRouter.encodeV3Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck)), _step5; !(_step5 = _iterator5()).done;) {
1979
2131
  var calldata = _step5.value;
1980
2132
  calldatas.push(calldata);
@@ -2121,7 +2273,7 @@ var SwapRouter = /*#__PURE__*/function () {
2121
2273
  }
2122
2274
  };
2123
2275
  SwapRouter.v3TradeWithHighPriceImpact = function v3TradeWithHighPriceImpact(trade) {
2124
- return !(trade instanceof Trade$2) && trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
2276
+ return !(trade instanceof Trade$3) && trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
2125
2277
  };
2126
2278
  SwapRouter.getPositionAmounts = function getPositionAmounts(position, zeroForOne) {
2127
2279
  var _position$mintAmounts = position.mintAmounts,
@@ -2141,5 +2293,5 @@ var SwapRouter = /*#__PURE__*/function () {
2141
2293
  }();
2142
2294
  SwapRouter.INTERFACE = /*#__PURE__*/new Interface(abi$3);
2143
2295
 
2144
- 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 };
2296
+ export { ADDRESS_THIS, ADDRESS_ZERO, ApprovalTypes, ApproveAndCall, MSG_SENDER, MixedRoute, MixedRouteSDK, MixedRouteTrade, MulticallExtended, ONE, ONE_HUNDRED_PERCENT, PaymentsExtended, Protocol, RouteV2, RouteV3, RouteV4, SwapRouter, Trade, V2_FEE_PATH_PLACEHOLDER, ZERO, ZERO_PERCENT, encodeMixedRouteToPath, getOutputOfPools, isMint, partitionMixedRouteByProtocol, tradeComparator };
2145
2297
  //# sourceMappingURL=router-sdk.esm.js.map