@uniswap/router-sdk 1.9.3 → 1.11.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.
@@ -14,8 +14,10 @@ var IMulticallExtended_json = require('@uniswap/swap-router-contracts/artifacts/
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');
17
+ var v4Sdk = require('@uniswap/v4-sdk');
17
18
  var solidity = require('@ethersproject/solidity');
18
19
 
20
+ var ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
19
21
  var MSG_SENDER = '0x0000000000000000000000000000000000000001';
20
22
  var ADDRESS_THIS = '0x0000000000000000000000000000000000000002';
21
23
  var ZERO = /*#__PURE__*/JSBI.BigInt(0);
@@ -640,13 +642,22 @@ var MixedRouteSDK = /*#__PURE__*/function () {
640
642
  return pool.chainId === chainId;
641
643
  });
642
644
  !allOnSameChain ? invariant(false, 'CHAIN_IDS') : void 0;
643
- var wrappedInput = input.wrapped;
644
- !pools[0].involvesToken(wrappedInput) ? invariant(false, 'INPUT') : void 0;
645
- !pools[pools.length - 1].involvesToken(output.wrapped) ? invariant(false, 'OUTPUT') : void 0;
645
+ if (pools[0] instanceof v4Sdk.Pool) {
646
+ this.adjustedInput = pools[0].involvesToken(input) ? input : input.wrapped;
647
+ } else {
648
+ this.adjustedInput = input.wrapped; // no native currencies in v2/v3
649
+ }
650
+ !pools[0].involvesToken(this.adjustedInput) ? invariant(false, 'INPUT') : void 0;
651
+ var lastPool = pools[pools.length - 1];
652
+ if (lastPool instanceof v4Sdk.Pool) {
653
+ !(lastPool.involvesToken(output) || lastPool.involvesToken(output.wrapped)) ? invariant(false, 'OUTPUT') : void 0;
654
+ } else {
655
+ !lastPool.involvesToken(output.wrapped) ? invariant(false, 'OUTPUT') : void 0;
656
+ }
646
657
  /**
647
658
  * Normalizes token0-token1 order and selects the next token/fee step to add to the path
648
659
  * */
649
- var tokenPath = [wrappedInput];
660
+ var tokenPath = [this.adjustedInput];
650
661
  for (var _iterator = _createForOfIteratorHelperLoose(pools.entries()), _step; !(_step = _iterator()).done;) {
651
662
  var _step$value = _step.value,
652
663
  i = _step$value[0],
@@ -678,17 +689,17 @@ var MixedRouteSDK = /*#__PURE__*/function () {
678
689
  price = _ref.price;
679
690
  return nextInput.equals(pool.token0) ? {
680
691
  nextInput: pool.token1,
681
- price: price.multiply(pool.token0Price)
692
+ price: price.multiply(pool.token0Price.asFraction)
682
693
  } : {
683
694
  nextInput: pool.token0,
684
- price: price.multiply(pool.token1Price)
695
+ price: price.multiply(pool.token1Price.asFraction)
685
696
  };
686
- }, this.pools[0].token0.equals(this.input.wrapped) ? {
697
+ }, this.pools[0].token0.equals(this.adjustedInput) ? {
687
698
  nextInput: this.pools[0].token1,
688
- price: this.pools[0].token0Price
699
+ price: this.pools[0].token0Price.asFraction
689
700
  } : {
690
701
  nextInput: this.pools[0].token0,
691
- price: this.pools[0].token1Price
702
+ price: this.pools[0].token1Price.asFraction
692
703
  }).price;
693
704
  return this._midPrice = new sdkCore.Price(this.input, this.output, price.denominator, price.numerator);
694
705
  }
@@ -696,6 +707,49 @@ var MixedRouteSDK = /*#__PURE__*/function () {
696
707
  return MixedRouteSDK;
697
708
  }();
698
709
 
710
+ function getOutputAmount(_x, _x2) {
711
+ return _getOutputAmount.apply(this, arguments);
712
+ }
713
+ function _getOutputAmount() {
714
+ _getOutputAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(pool, amountIn) {
715
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
716
+ while (1) switch (_context.prev = _context.next) {
717
+ case 0:
718
+ if (!(pool instanceof v4Sdk.Pool)) {
719
+ _context.next = 11;
720
+ break;
721
+ }
722
+ if (!pool.involvesCurrency(amountIn.currency)) {
723
+ _context.next = 7;
724
+ break;
725
+ }
726
+ _context.next = 4;
727
+ return pool.getOutputAmount(amountIn);
728
+ case 4:
729
+ return _context.abrupt("return", _context.sent);
730
+ case 7:
731
+ if (!pool.involvesCurrency(amountIn.currency.wrapped)) {
732
+ _context.next = 11;
733
+ break;
734
+ }
735
+ _context.next = 10;
736
+ return pool.getOutputAmount(amountIn.wrapped);
737
+ case 10:
738
+ return _context.abrupt("return", _context.sent);
739
+ case 11:
740
+ _context.next = 13;
741
+ return pool.getOutputAmount(amountIn.wrapped);
742
+ case 13:
743
+ return _context.abrupt("return", _context.sent);
744
+ case 14:
745
+ case "end":
746
+ return _context.stop();
747
+ }
748
+ }, _callee);
749
+ }));
750
+ return _getOutputAmount.apply(this, arguments);
751
+ }
752
+
699
753
  /**
700
754
  * Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
701
755
  * @template TInput The input token, either Ether or an ERC-20
@@ -773,15 +827,24 @@ var MixedRouteTrade = /*#__PURE__*/function () {
773
827
  }).reduce(function (total, cur) {
774
828
  return total + cur;
775
829
  }, 0);
776
- var poolAddressSet = new Set();
830
+ var poolIdentifierSet = new Set();
777
831
  for (var _iterator = _createForOfIteratorHelperLoose(routes), _step; !(_step = _iterator()).done;) {
778
832
  var route = _step.value.route;
779
833
  for (var _iterator2 = _createForOfIteratorHelperLoose(route.pools), _step2; !(_step2 = _iterator2()).done;) {
780
834
  var pool = _step2.value;
781
- pool instanceof v3Sdk.Pool ? poolAddressSet.add(v3Sdk.Pool.getAddress(pool.token0, pool.token1, pool.fee)) : poolAddressSet.add(v2Sdk.Pair.getAddress(pool.token0, pool.token1));
835
+ if (pool instanceof v4Sdk.Pool) {
836
+ poolIdentifierSet.add(pool.poolId);
837
+ } else if (pool instanceof v3Sdk.Pool) {
838
+ poolIdentifierSet.add(v3Sdk.Pool.getAddress(pool.token0, pool.token1, pool.fee));
839
+ } else if (pool instanceof v2Sdk.Pair) {
840
+ var pair = pool;
841
+ poolIdentifierSet.add(v2Sdk.Pair.getAddress(pair.token0, pair.token1));
842
+ } else {
843
+ throw new Error('Unexpected pool type in route when constructing trade object');
844
+ }
782
845
  }
783
846
  }
784
- !(numPools === poolAddressSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
847
+ !(numPools === poolIdentifierSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
785
848
  !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
786
849
  this.swaps = routes;
787
850
  this.tradeType = tradeType;
@@ -807,14 +870,14 @@ var MixedRouteTrade = /*#__PURE__*/function () {
807
870
  /*#__PURE__*/
808
871
  function () {
809
872
  var _fromRoute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(route, amount, tradeType) {
810
- var amounts, inputAmount, outputAmount, i, pool, _yield$pool$getOutput, _outputAmount;
873
+ var amounts, inputAmount, outputAmount, i, pool, _yield$getOutputAmoun, _outputAmount;
811
874
  return _regeneratorRuntime().wrap(function _callee$(_context) {
812
875
  while (1) switch (_context.prev = _context.next) {
813
876
  case 0:
814
877
  amounts = new Array(route.path.length);
815
878
  !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
816
879
  !amount.currency.equals(route.input) ? invariant(false, 'INPUT') : void 0;
817
- amounts[0] = amount.wrapped;
880
+ amounts[0] = route.pools[0] instanceof v4Sdk.Pool ? amount : amount.wrapped;
818
881
  i = 0;
819
882
  case 5:
820
883
  if (!(i < route.path.length - 1)) {
@@ -823,10 +886,10 @@ var MixedRouteTrade = /*#__PURE__*/function () {
823
886
  }
824
887
  pool = route.pools[i];
825
888
  _context.next = 9;
826
- return pool.getOutputAmount(amounts[i]);
889
+ return getOutputAmount(pool, amounts[i]);
827
890
  case 9:
828
- _yield$pool$getOutput = _context.sent;
829
- _outputAmount = _yield$pool$getOutput[0];
891
+ _yield$getOutputAmoun = _context.sent;
892
+ _outputAmount = _yield$getOutputAmoun[0];
830
893
  amounts[i + 1] = _outputAmount;
831
894
  case 12:
832
895
  i++;
@@ -869,7 +932,7 @@ var MixedRouteTrade = /*#__PURE__*/function () {
869
932
  /*#__PURE__*/
870
933
  function () {
871
934
  var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(routes, tradeType) {
872
- var populatedRoutes, _iterator3, _step3, _step3$value, route, amount, amounts, inputAmount, outputAmount, i, pool, _yield$pool$getOutput2, _outputAmount2;
935
+ var populatedRoutes, _iterator3, _step3, _step3$value, route, amount, amounts, inputAmount, outputAmount, i, pool, _yield$getOutputAmoun2, _outputAmount2;
873
936
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
874
937
  while (1) switch (_context2.prev = _context2.next) {
875
938
  case 0:
@@ -887,7 +950,7 @@ var MixedRouteTrade = /*#__PURE__*/function () {
887
950
  outputAmount = void 0;
888
951
  !amount.currency.equals(route.input) ? invariant(false, 'INPUT') : void 0;
889
952
  inputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
890
- amounts[0] = sdkCore.CurrencyAmount.fromFractionalAmount(route.input.wrapped, amount.numerator, amount.denominator);
953
+ amounts[0] = sdkCore.CurrencyAmount.fromFractionalAmount(route.adjustedInput, amount.numerator, amount.denominator);
891
954
  i = 0;
892
955
  case 12:
893
956
  if (!(i < route.path.length - 1)) {
@@ -896,10 +959,10 @@ var MixedRouteTrade = /*#__PURE__*/function () {
896
959
  }
897
960
  pool = route.pools[i];
898
961
  _context2.next = 16;
899
- return pool.getOutputAmount(amounts[i]);
962
+ return getOutputAmount(pool, amounts[i]);
900
963
  case 16:
901
- _yield$pool$getOutput2 = _context2.sent;
902
- _outputAmount2 = _yield$pool$getOutput2[0];
964
+ _yield$getOutputAmoun2 = _context2.sent;
965
+ _outputAmount2 = _yield$getOutputAmoun2[0];
903
966
  amounts[i + 1] = _outputAmount2;
904
967
  case 19:
905
968
  i++;
@@ -1019,7 +1082,7 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1019
1082
  var _bestTradeExactIn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(pools, currencyAmountIn, currencyOut, _temp,
1020
1083
  // used in recursion.
1021
1084
  currentPools, nextAmountIn, bestTrades) {
1022
- var _ref5, _ref5$maxNumResults, maxNumResults, _ref5$maxHops, maxHops, amountIn, tokenOut, i, pool, amountOut, _yield$pool$getOutput3, poolsExcludingThisPool;
1085
+ var _ref5, _ref5$maxNumResults, maxNumResults, _ref5$maxHops, maxHops, amountIn, i, pool, amountInAdjusted, amountOut, _ref6, poolsExcludingThisPool;
1023
1086
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1024
1087
  while (1) switch (_context3.prev = _context3.next) {
1025
1088
  case 0:
@@ -1036,20 +1099,20 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1036
1099
  !(pools.length > 0) ? invariant(false, 'POOLS') : void 0;
1037
1100
  !(maxHops > 0) ? invariant(false, 'MAX_HOPS') : void 0;
1038
1101
  !(currencyAmountIn === nextAmountIn || currentPools.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0;
1039
- amountIn = nextAmountIn.wrapped;
1040
- tokenOut = currencyOut.wrapped;
1102
+ amountIn = nextAmountIn;
1041
1103
  i = 0;
1042
- case 10:
1104
+ case 9:
1043
1105
  if (!(i < pools.length)) {
1044
- _context3.next = 49;
1106
+ _context3.next = 56;
1045
1107
  break;
1046
1108
  }
1047
- pool = pools[i]; // pool irrelevant
1048
- if (!(!pool.token0.equals(amountIn.currency) && !pool.token1.equals(amountIn.currency))) {
1109
+ pool = pools[i];
1110
+ amountInAdjusted = pool instanceof v4Sdk.Pool ? amountIn : amountIn.wrapped; // pool irrelevant
1111
+ if (!(!pool.token0.equals(amountInAdjusted.currency) && !pool.token1.equals(amountInAdjusted.currency))) {
1049
1112
  _context3.next = 14;
1050
1113
  break;
1051
1114
  }
1052
- return _context3.abrupt("continue", 46);
1115
+ return _context3.abrupt("continue", 53);
1053
1116
  case 14:
1054
1117
  if (!(pool instanceof v2Sdk.Pair)) {
1055
1118
  _context3.next = 17;
@@ -1059,65 +1122,78 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1059
1122
  _context3.next = 17;
1060
1123
  break;
1061
1124
  }
1062
- return _context3.abrupt("continue", 46);
1125
+ return _context3.abrupt("continue", 53);
1063
1126
  case 17:
1064
1127
  amountOut = void 0;
1065
1128
  _context3.prev = 18;
1066
- _context3.next = 22;
1067
- return pool.getOutputAmount(amountIn);
1068
- case 22:
1069
- _yield$pool$getOutput3 = _context3.sent;
1070
- amountOut = _yield$pool$getOutput3[0];
1071
- _context3.next = 31;
1129
+ if (!(pool instanceof v4Sdk.Pool)) {
1130
+ _context3.next = 26;
1131
+ break;
1132
+ }
1133
+ _context3.next = 23;
1134
+ return pool.getOutputAmount(amountInAdjusted);
1135
+ case 23:
1136
+ _context3.t0 = _context3.sent;
1137
+ _context3.next = 29;
1072
1138
  break;
1073
1139
  case 26:
1074
- _context3.prev = 26;
1075
- _context3.t0 = _context3["catch"](18);
1076
- if (!_context3.t0.isInsufficientInputAmountError) {
1077
- _context3.next = 30;
1140
+ _context3.next = 28;
1141
+ return pool.getOutputAmount(amountInAdjusted.wrapped);
1142
+ case 28:
1143
+ _context3.t0 = _context3.sent;
1144
+ case 29:
1145
+ _ref6 = _context3.t0;
1146
+ amountOut = _ref6[0];
1147
+ _context3.next = 38;
1148
+ break;
1149
+ case 33:
1150
+ _context3.prev = 33;
1151
+ _context3.t1 = _context3["catch"](18);
1152
+ if (!_context3.t1.isInsufficientInputAmountError) {
1153
+ _context3.next = 37;
1078
1154
  break;
1079
1155
  }
1080
- return _context3.abrupt("continue", 46);
1081
- case 30:
1082
- throw _context3.t0;
1083
- case 31:
1084
- if (!(amountOut.currency.isToken && amountOut.currency.equals(tokenOut))) {
1085
- _context3.next = 42;
1156
+ return _context3.abrupt("continue", 53);
1157
+ case 37:
1158
+ throw _context3.t1;
1159
+ case 38:
1160
+ if (!amountOut.currency.wrapped.equals(currencyOut.wrapped)) {
1161
+ _context3.next = 49;
1086
1162
  break;
1087
1163
  }
1088
- _context3.t1 = sdkCore.sortedInsert;
1089
- _context3.t2 = bestTrades;
1090
- _context3.next = 36;
1164
+ _context3.t2 = sdkCore.sortedInsert;
1165
+ _context3.t3 = bestTrades;
1166
+ _context3.next = 43;
1091
1167
  return MixedRouteTrade.fromRoute(new MixedRouteSDK([].concat(currentPools, [pool]), currencyAmountIn.currency, currencyOut), currencyAmountIn, sdkCore.TradeType.EXACT_INPUT);
1092
- case 36:
1093
- _context3.t3 = _context3.sent;
1094
- _context3.t4 = maxNumResults;
1095
- _context3.t5 = tradeComparator;
1096
- (0, _context3.t1)(_context3.t2, _context3.t3, _context3.t4, _context3.t5);
1097
- _context3.next = 46;
1168
+ case 43:
1169
+ _context3.t4 = _context3.sent;
1170
+ _context3.t5 = maxNumResults;
1171
+ _context3.t6 = tradeComparator;
1172
+ (0, _context3.t2)(_context3.t3, _context3.t4, _context3.t5, _context3.t6);
1173
+ _context3.next = 53;
1098
1174
  break;
1099
- case 42:
1175
+ case 49:
1100
1176
  if (!(maxHops > 1 && pools.length > 1)) {
1101
- _context3.next = 46;
1177
+ _context3.next = 53;
1102
1178
  break;
1103
1179
  }
1104
1180
  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
1105
- _context3.next = 46;
1181
+ _context3.next = 53;
1106
1182
  return MixedRouteTrade.bestTradeExactIn(poolsExcludingThisPool, currencyAmountIn, currencyOut, {
1107
1183
  maxNumResults: maxNumResults,
1108
1184
  maxHops: maxHops - 1
1109
1185
  }, [].concat(currentPools, [pool]), amountOut, bestTrades);
1110
- case 46:
1186
+ case 53:
1111
1187
  i++;
1112
- _context3.next = 10;
1188
+ _context3.next = 9;
1113
1189
  break;
1114
- case 49:
1190
+ case 56:
1115
1191
  return _context3.abrupt("return", bestTrades);
1116
- case 50:
1192
+ case 57:
1117
1193
  case "end":
1118
1194
  return _context3.stop();
1119
1195
  }
1120
- }, _callee3, null, [[18, 26]]);
1196
+ }, _callee3, null, [[18, 33]]);
1121
1197
  }));
1122
1198
  function bestTradeExactIn(_x6, _x7, _x8, _x9, _x10, _x11, _x12) {
1123
1199
  return _bestTradeExactIn.apply(this, arguments);
@@ -1140,8 +1216,8 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1140
1216
  return this._inputAmount;
1141
1217
  }
1142
1218
  var inputCurrency = this.swaps[0].inputAmount.currency;
1143
- var totalInputFromRoutes = this.swaps.map(function (_ref6) {
1144
- var inputAmount = _ref6.inputAmount;
1219
+ var totalInputFromRoutes = this.swaps.map(function (_ref7) {
1220
+ var inputAmount = _ref7.inputAmount;
1145
1221
  return inputAmount;
1146
1222
  }).reduce(function (total, cur) {
1147
1223
  return total.add(cur);
@@ -1159,8 +1235,8 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1159
1235
  return this._outputAmount;
1160
1236
  }
1161
1237
  var outputCurrency = this.swaps[0].outputAmount.currency;
1162
- var totalOutputFromRoutes = this.swaps.map(function (_ref7) {
1163
- var outputAmount = _ref7.outputAmount;
1238
+ var totalOutputFromRoutes = this.swaps.map(function (_ref8) {
1239
+ var outputAmount = _ref8.outputAmount;
1164
1240
  return outputAmount;
1165
1241
  }).reduce(function (total, cur) {
1166
1242
  return total.add(cur);
@@ -1205,6 +1281,7 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1205
1281
  (function (Protocol) {
1206
1282
  Protocol["V2"] = "V2";
1207
1283
  Protocol["V3"] = "V3";
1284
+ Protocol["V4"] = "V4";
1208
1285
  Protocol["MIXED"] = "MIXED";
1209
1286
  })(exports.Protocol || (exports.Protocol = {}));
1210
1287
 
@@ -1232,14 +1309,26 @@ var RouteV3 = /*#__PURE__*/function (_V3RouteSDK) {
1232
1309
  }
1233
1310
  return RouteV3;
1234
1311
  }(v3Sdk.Route);
1312
+ // V4 route wrapper
1313
+ var RouteV4 = /*#__PURE__*/function (_V4RouteSDK) {
1314
+ _inheritsLoose(RouteV4, _V4RouteSDK);
1315
+ function RouteV4(v4Route) {
1316
+ var _this3;
1317
+ _this3 = _V4RouteSDK.call(this, v4Route.pools, v4Route.input, v4Route.output) || this;
1318
+ _this3.protocol = exports.Protocol.V4;
1319
+ _this3.path = v4Route.currencyPath;
1320
+ return _this3;
1321
+ }
1322
+ return RouteV4;
1323
+ }(v4Sdk.Route);
1235
1324
  // Mixed route wrapper
1236
1325
  var MixedRoute = /*#__PURE__*/function (_MixedRouteSDK) {
1237
1326
  _inheritsLoose(MixedRoute, _MixedRouteSDK);
1238
1327
  function MixedRoute(mixedRoute) {
1239
- var _this3;
1240
- _this3 = _MixedRouteSDK.call(this, mixedRoute.pools, mixedRoute.input, mixedRoute.output) || this;
1241
- _this3.protocol = exports.Protocol.MIXED;
1242
- return _this3;
1328
+ var _this4;
1329
+ _this4 = _MixedRouteSDK.call(this, mixedRoute.pools, mixedRoute.input, mixedRoute.output) || this;
1330
+ _this4.protocol = exports.Protocol.MIXED;
1331
+ return _this4;
1243
1332
  }
1244
1333
  return MixedRoute;
1245
1334
  }(MixedRouteSDK);
@@ -1247,33 +1336,52 @@ var MixedRoute = /*#__PURE__*/function (_MixedRouteSDK) {
1247
1336
  var Trade = /*#__PURE__*/function () {
1248
1337
  // construct a trade across v2 and v3 routes from pre-computed amounts
1249
1338
  function Trade(_ref) {
1250
- var v2Routes = _ref.v2Routes,
1251
- v3Routes = _ref.v3Routes,
1252
- tradeType = _ref.tradeType,
1253
- mixedRoutes = _ref.mixedRoutes;
1339
+ var _ref$v2Routes = _ref.v2Routes,
1340
+ v2Routes = _ref$v2Routes === void 0 ? [] : _ref$v2Routes,
1341
+ _ref$v3Routes = _ref.v3Routes,
1342
+ v3Routes = _ref$v3Routes === void 0 ? [] : _ref$v3Routes,
1343
+ _ref$v4Routes = _ref.v4Routes,
1344
+ v4Routes = _ref$v4Routes === void 0 ? [] : _ref$v4Routes,
1345
+ _ref$mixedRoutes = _ref.mixedRoutes,
1346
+ mixedRoutes = _ref$mixedRoutes === void 0 ? [] : _ref$mixedRoutes,
1347
+ tradeType = _ref.tradeType;
1254
1348
  this.swaps = [];
1255
1349
  this.routes = [];
1256
1350
  // wrap v2 routes
1257
1351
  for (var _iterator = _createForOfIteratorHelperLoose(v2Routes), _step; !(_step = _iterator()).done;) {
1258
1352
  var _step$value = _step.value,
1259
1353
  routev2 = _step$value.routev2,
1260
- _inputAmount = _step$value.inputAmount,
1261
- _outputAmount = _step$value.outputAmount;
1262
- var _route = new RouteV2(routev2);
1263
- this.routes.push(_route);
1354
+ inputAmount = _step$value.inputAmount,
1355
+ outputAmount = _step$value.outputAmount;
1356
+ var route = new RouteV2(routev2);
1357
+ this.routes.push(route);
1264
1358
  this.swaps.push({
1265
- route: _route,
1266
- inputAmount: _inputAmount,
1267
- outputAmount: _outputAmount
1359
+ route: route,
1360
+ inputAmount: inputAmount,
1361
+ outputAmount: outputAmount
1268
1362
  });
1269
1363
  }
1270
1364
  // wrap v3 routes
1271
1365
  for (var _iterator2 = _createForOfIteratorHelperLoose(v3Routes), _step2; !(_step2 = _iterator2()).done;) {
1272
1366
  var _step2$value = _step2.value,
1273
1367
  routev3 = _step2$value.routev3,
1274
- _inputAmount2 = _step2$value.inputAmount,
1275
- _outputAmount2 = _step2$value.outputAmount;
1276
- var _route2 = new RouteV3(routev3);
1368
+ _inputAmount = _step2$value.inputAmount,
1369
+ _outputAmount = _step2$value.outputAmount;
1370
+ var _route = new RouteV3(routev3);
1371
+ this.routes.push(_route);
1372
+ this.swaps.push({
1373
+ route: _route,
1374
+ inputAmount: _inputAmount,
1375
+ outputAmount: _outputAmount
1376
+ });
1377
+ }
1378
+ // wrap v4 routes
1379
+ for (var _iterator3 = _createForOfIteratorHelperLoose(v4Routes), _step3; !(_step3 = _iterator3()).done;) {
1380
+ var _step3$value = _step3.value,
1381
+ routev4 = _step3$value.routev4,
1382
+ _inputAmount2 = _step3$value.inputAmount,
1383
+ _outputAmount2 = _step3$value.outputAmount;
1384
+ var _route2 = new RouteV4(routev4);
1277
1385
  this.routes.push(_route2);
1278
1386
  this.swaps.push({
1279
1387
  route: _route2,
@@ -1281,21 +1389,18 @@ var Trade = /*#__PURE__*/function () {
1281
1389
  outputAmount: _outputAmount2
1282
1390
  });
1283
1391
  }
1284
- // wrap mixedRoutes
1285
- if (mixedRoutes) {
1286
- for (var _iterator3 = _createForOfIteratorHelperLoose(mixedRoutes), _step3; !(_step3 = _iterator3()).done;) {
1287
- var _step3$value = _step3.value,
1288
- mixedRoute = _step3$value.mixedRoute,
1289
- inputAmount = _step3$value.inputAmount,
1290
- outputAmount = _step3$value.outputAmount;
1291
- var route = new MixedRoute(mixedRoute);
1292
- this.routes.push(route);
1293
- this.swaps.push({
1294
- route: route,
1295
- inputAmount: inputAmount,
1296
- outputAmount: outputAmount
1297
- });
1298
- }
1392
+ for (var _iterator4 = _createForOfIteratorHelperLoose(mixedRoutes), _step4; !(_step4 = _iterator4()).done;) {
1393
+ var _step4$value = _step4.value,
1394
+ mixedRoute = _step4$value.mixedRoute,
1395
+ _inputAmount3 = _step4$value.inputAmount,
1396
+ _outputAmount3 = _step4$value.outputAmount;
1397
+ var _route3 = new MixedRoute(mixedRoute);
1398
+ this.routes.push(_route3);
1399
+ this.swaps.push({
1400
+ route: _route3,
1401
+ inputAmount: _inputAmount3,
1402
+ outputAmount: _outputAmount3
1403
+ });
1299
1404
  }
1300
1405
  if (this.swaps.length === 0) {
1301
1406
  throw new Error('No routes provided when calling Trade constructor');
@@ -1319,22 +1424,24 @@ var Trade = /*#__PURE__*/function () {
1319
1424
  }).reduce(function (total, cur) {
1320
1425
  return total + cur;
1321
1426
  }, 0);
1322
- var poolAddressSet = new Set();
1323
- for (var _iterator4 = _createForOfIteratorHelperLoose(this.swaps), _step4; !(_step4 = _iterator4()).done;) {
1324
- var _route3 = _step4.value.route;
1325
- for (var _iterator5 = _createForOfIteratorHelperLoose(_route3.pools), _step5; !(_step5 = _iterator5()).done;) {
1326
- var pool = _step5.value;
1327
- if (pool instanceof v3Sdk.Pool) {
1328
- poolAddressSet.add(v3Sdk.Pool.getAddress(pool.token0, pool.token1, pool.fee));
1427
+ var poolIdentifierSet = new Set();
1428
+ for (var _iterator5 = _createForOfIteratorHelperLoose(this.swaps), _step5; !(_step5 = _iterator5()).done;) {
1429
+ var _route4 = _step5.value.route;
1430
+ for (var _iterator6 = _createForOfIteratorHelperLoose(_route4.pools), _step6; !(_step6 = _iterator6()).done;) {
1431
+ var pool = _step6.value;
1432
+ if (pool instanceof v4Sdk.Pool) {
1433
+ poolIdentifierSet.add(pool.poolId);
1434
+ } else if (pool instanceof v3Sdk.Pool) {
1435
+ poolIdentifierSet.add(v3Sdk.Pool.getAddress(pool.token0, pool.token1, pool.fee));
1329
1436
  } else if (pool instanceof v2Sdk.Pair) {
1330
1437
  var pair = pool;
1331
- poolAddressSet.add(v2Sdk.Pair.getAddress(pair.token0, pair.token1));
1438
+ poolIdentifierSet.add(v2Sdk.Pair.getAddress(pair.token0, pair.token1));
1332
1439
  } else {
1333
1440
  throw new Error('Unexpected pool type in route when constructing trade object');
1334
1441
  }
1335
1442
  }
1336
1443
  }
1337
- !(numPools === poolAddressSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
1444
+ !(numPools === poolIdentifierSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
1338
1445
  }
1339
1446
  var _proto = Trade.prototype;
1340
1447
  /**
@@ -1380,98 +1487,126 @@ var Trade = /*#__PURE__*/function () {
1380
1487
  return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
1381
1488
  };
1382
1489
  Trade.fromRoutes = /*#__PURE__*/function () {
1383
- var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(v2Routes, v3Routes, tradeType, mixedRoutes) {
1384
- 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;
1490
+ var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(v2Routes, v3Routes, tradeType, mixedRoutes, v4Routes) {
1491
+ var populatedV2Routes, populatedV3Routes, populatedV4Routes, populatedMixedRoutes, _iterator7, _step7, _step7$value, routev2, _amount2, v2Trade, _inputAmount5, _outputAmount5, _iterator8, _step8, _step8$value, routev3, _amount3, v3Trade, _inputAmount6, _outputAmount6, _iterator9, _step9, _step9$value, routev4, amount, v4Trade, inputAmount, outputAmount, _iterator10, _step10, _step10$value, mixedRoute, _amount, mixedRouteTrade, _inputAmount4, _outputAmount4;
1385
1492
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1386
1493
  while (1) switch (_context.prev = _context.next) {
1387
1494
  case 0:
1388
1495
  populatedV2Routes = [];
1389
1496
  populatedV3Routes = [];
1497
+ populatedV4Routes = [];
1390
1498
  populatedMixedRoutes = [];
1391
- for (_iterator6 = _createForOfIteratorHelperLoose(v2Routes); !(_step6 = _iterator6()).done;) {
1392
- _step6$value = _step6.value, routev2 = _step6$value.routev2, _amount = _step6$value.amount;
1393
- v2Trade = new v2Sdk.Trade(routev2, _amount, tradeType);
1394
- _inputAmount3 = v2Trade.inputAmount, _outputAmount3 = v2Trade.outputAmount;
1499
+ for (_iterator7 = _createForOfIteratorHelperLoose(v2Routes); !(_step7 = _iterator7()).done;) {
1500
+ _step7$value = _step7.value, routev2 = _step7$value.routev2, _amount2 = _step7$value.amount;
1501
+ v2Trade = new v2Sdk.Trade(routev2, _amount2, tradeType);
1502
+ _inputAmount5 = v2Trade.inputAmount, _outputAmount5 = v2Trade.outputAmount;
1395
1503
  populatedV2Routes.push({
1396
1504
  routev2: routev2,
1397
- inputAmount: _inputAmount3,
1398
- outputAmount: _outputAmount3
1505
+ inputAmount: _inputAmount5,
1506
+ outputAmount: _outputAmount5
1399
1507
  });
1400
1508
  }
1401
- _iterator7 = _createForOfIteratorHelperLoose(v3Routes);
1402
- case 5:
1403
- if ((_step7 = _iterator7()).done) {
1404
- _context.next = 14;
1509
+ _iterator8 = _createForOfIteratorHelperLoose(v3Routes);
1510
+ case 6:
1511
+ if ((_step8 = _iterator8()).done) {
1512
+ _context.next = 15;
1405
1513
  break;
1406
1514
  }
1407
- _step7$value = _step7.value, routev3 = _step7$value.routev3, _amount2 = _step7$value.amount;
1408
- _context.next = 9;
1409
- return v3Sdk.Trade.fromRoute(routev3, _amount2, tradeType);
1410
- case 9:
1515
+ _step8$value = _step8.value, routev3 = _step8$value.routev3, _amount3 = _step8$value.amount;
1516
+ _context.next = 10;
1517
+ return v3Sdk.Trade.fromRoute(routev3, _amount3, tradeType);
1518
+ case 10:
1411
1519
  v3Trade = _context.sent;
1412
- _inputAmount4 = v3Trade.inputAmount, _outputAmount4 = v3Trade.outputAmount;
1520
+ _inputAmount6 = v3Trade.inputAmount, _outputAmount6 = v3Trade.outputAmount;
1413
1521
  populatedV3Routes.push({
1414
1522
  routev3: routev3,
1415
- inputAmount: _inputAmount4,
1416
- outputAmount: _outputAmount4
1523
+ inputAmount: _inputAmount6,
1524
+ outputAmount: _outputAmount6
1417
1525
  });
1418
- case 12:
1419
- _context.next = 5;
1526
+ case 13:
1527
+ _context.next = 6;
1420
1528
  break;
1421
- case 14:
1529
+ case 15:
1530
+ if (!v4Routes) {
1531
+ _context.next = 26;
1532
+ break;
1533
+ }
1534
+ _iterator9 = _createForOfIteratorHelperLoose(v4Routes);
1535
+ case 17:
1536
+ if ((_step9 = _iterator9()).done) {
1537
+ _context.next = 26;
1538
+ break;
1539
+ }
1540
+ _step9$value = _step9.value, routev4 = _step9$value.routev4, amount = _step9$value.amount;
1541
+ _context.next = 21;
1542
+ return v4Sdk.Trade.fromRoute(routev4, amount, tradeType);
1543
+ case 21:
1544
+ v4Trade = _context.sent;
1545
+ inputAmount = v4Trade.inputAmount, outputAmount = v4Trade.outputAmount;
1546
+ populatedV4Routes.push({
1547
+ routev4: routev4,
1548
+ inputAmount: inputAmount,
1549
+ outputAmount: outputAmount
1550
+ });
1551
+ case 24:
1552
+ _context.next = 17;
1553
+ break;
1554
+ case 26:
1422
1555
  if (!mixedRoutes) {
1423
- _context.next = 25;
1556
+ _context.next = 37;
1424
1557
  break;
1425
1558
  }
1426
- _iterator8 = _createForOfIteratorHelperLoose(mixedRoutes);
1427
- case 16:
1428
- if ((_step8 = _iterator8()).done) {
1429
- _context.next = 25;
1559
+ _iterator10 = _createForOfIteratorHelperLoose(mixedRoutes);
1560
+ case 28:
1561
+ if ((_step10 = _iterator10()).done) {
1562
+ _context.next = 37;
1430
1563
  break;
1431
1564
  }
1432
- _step8$value = _step8.value, mixedRoute = _step8$value.mixedRoute, amount = _step8$value.amount;
1433
- _context.next = 20;
1434
- return MixedRouteTrade.fromRoute(mixedRoute, amount, tradeType);
1435
- case 20:
1565
+ _step10$value = _step10.value, mixedRoute = _step10$value.mixedRoute, _amount = _step10$value.amount;
1566
+ _context.next = 32;
1567
+ return MixedRouteTrade.fromRoute(mixedRoute, _amount, tradeType);
1568
+ case 32:
1436
1569
  mixedRouteTrade = _context.sent;
1437
- inputAmount = mixedRouteTrade.inputAmount, outputAmount = mixedRouteTrade.outputAmount;
1570
+ _inputAmount4 = mixedRouteTrade.inputAmount, _outputAmount4 = mixedRouteTrade.outputAmount;
1438
1571
  populatedMixedRoutes.push({
1439
1572
  mixedRoute: mixedRoute,
1440
- inputAmount: inputAmount,
1441
- outputAmount: outputAmount
1573
+ inputAmount: _inputAmount4,
1574
+ outputAmount: _outputAmount4
1442
1575
  });
1443
- case 23:
1444
- _context.next = 16;
1576
+ case 35:
1577
+ _context.next = 28;
1445
1578
  break;
1446
- case 25:
1579
+ case 37:
1447
1580
  return _context.abrupt("return", new Trade({
1448
1581
  v2Routes: populatedV2Routes,
1449
1582
  v3Routes: populatedV3Routes,
1583
+ v4Routes: populatedV4Routes,
1450
1584
  mixedRoutes: populatedMixedRoutes,
1451
1585
  tradeType: tradeType
1452
1586
  }));
1453
- case 26:
1587
+ case 38:
1454
1588
  case "end":
1455
1589
  return _context.stop();
1456
1590
  }
1457
1591
  }, _callee);
1458
1592
  }));
1459
- function fromRoutes(_x, _x2, _x3, _x4) {
1593
+ function fromRoutes(_x, _x2, _x3, _x4, _x5) {
1460
1594
  return _fromRoutes.apply(this, arguments);
1461
1595
  }
1462
1596
  return fromRoutes;
1463
1597
  }();
1464
1598
  Trade.fromRoute = /*#__PURE__*/function () {
1465
1599
  var _fromRoute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(route, amount, tradeType) {
1466
- var v2Routes, v3Routes, mixedRoutes, v2Trade, inputAmount, outputAmount, v3Trade, _inputAmount5, _outputAmount5, mixedRouteTrade, _inputAmount6, _outputAmount6;
1600
+ var v2Routes, v3Routes, v4Routes, mixedRoutes, v2Trade, inputAmount, outputAmount, v3Trade, _inputAmount7, _outputAmount7, v4Trade, _inputAmount8, _outputAmount8, mixedRouteTrade, _inputAmount9, _outputAmount9;
1467
1601
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1468
1602
  while (1) switch (_context2.prev = _context2.next) {
1469
1603
  case 0:
1470
1604
  v2Routes = [];
1471
1605
  v3Routes = [];
1606
+ v4Routes = [];
1472
1607
  mixedRoutes = [];
1473
1608
  if (!(route instanceof v2Sdk.Route)) {
1474
- _context2.next = 9;
1609
+ _context2.next = 10;
1475
1610
  break;
1476
1611
  }
1477
1612
  v2Trade = new v2Sdk.Trade(route, amount, tradeType);
@@ -1481,58 +1616,76 @@ var Trade = /*#__PURE__*/function () {
1481
1616
  inputAmount: inputAmount,
1482
1617
  outputAmount: outputAmount
1483
1618
  }];
1484
- _context2.next = 26;
1619
+ _context2.next = 35;
1485
1620
  break;
1486
- case 9:
1621
+ case 10:
1487
1622
  if (!(route instanceof v3Sdk.Route)) {
1488
- _context2.next = 17;
1623
+ _context2.next = 18;
1489
1624
  break;
1490
1625
  }
1491
- _context2.next = 12;
1626
+ _context2.next = 13;
1492
1627
  return v3Sdk.Trade.fromRoute(route, amount, tradeType);
1493
- case 12:
1628
+ case 13:
1494
1629
  v3Trade = _context2.sent;
1495
- _inputAmount5 = v3Trade.inputAmount, _outputAmount5 = v3Trade.outputAmount;
1630
+ _inputAmount7 = v3Trade.inputAmount, _outputAmount7 = v3Trade.outputAmount;
1496
1631
  v3Routes = [{
1497
1632
  routev3: route,
1498
- inputAmount: _inputAmount5,
1499
- outputAmount: _outputAmount5
1633
+ inputAmount: _inputAmount7,
1634
+ outputAmount: _outputAmount7
1500
1635
  }];
1501
- _context2.next = 26;
1636
+ _context2.next = 35;
1502
1637
  break;
1503
- case 17:
1638
+ case 18:
1639
+ if (!(route instanceof v4Sdk.Route)) {
1640
+ _context2.next = 26;
1641
+ break;
1642
+ }
1643
+ _context2.next = 21;
1644
+ return v4Sdk.Trade.fromRoute(route, amount, tradeType);
1645
+ case 21:
1646
+ v4Trade = _context2.sent;
1647
+ _inputAmount8 = v4Trade.inputAmount, _outputAmount8 = v4Trade.outputAmount;
1648
+ v4Routes = [{
1649
+ routev4: route,
1650
+ inputAmount: _inputAmount8,
1651
+ outputAmount: _outputAmount8
1652
+ }];
1653
+ _context2.next = 35;
1654
+ break;
1655
+ case 26:
1504
1656
  if (!(route instanceof MixedRouteSDK)) {
1505
- _context2.next = 25;
1657
+ _context2.next = 34;
1506
1658
  break;
1507
1659
  }
1508
- _context2.next = 20;
1660
+ _context2.next = 29;
1509
1661
  return MixedRouteTrade.fromRoute(route, amount, tradeType);
1510
- case 20:
1662
+ case 29:
1511
1663
  mixedRouteTrade = _context2.sent;
1512
- _inputAmount6 = mixedRouteTrade.inputAmount, _outputAmount6 = mixedRouteTrade.outputAmount;
1664
+ _inputAmount9 = mixedRouteTrade.inputAmount, _outputAmount9 = mixedRouteTrade.outputAmount;
1513
1665
  mixedRoutes = [{
1514
1666
  mixedRoute: route,
1515
- inputAmount: _inputAmount6,
1516
- outputAmount: _outputAmount6
1667
+ inputAmount: _inputAmount9,
1668
+ outputAmount: _outputAmount9
1517
1669
  }];
1518
- _context2.next = 26;
1670
+ _context2.next = 35;
1519
1671
  break;
1520
- case 25:
1672
+ case 34:
1521
1673
  throw new Error('Invalid route type');
1522
- case 26:
1674
+ case 35:
1523
1675
  return _context2.abrupt("return", new Trade({
1524
1676
  v2Routes: v2Routes,
1525
1677
  v3Routes: v3Routes,
1678
+ v4Routes: v4Routes,
1526
1679
  mixedRoutes: mixedRoutes,
1527
1680
  tradeType: tradeType
1528
1681
  }));
1529
- case 27:
1682
+ case 36:
1530
1683
  case "end":
1531
1684
  return _context2.stop();
1532
1685
  }
1533
1686
  }, _callee2);
1534
1687
  }));
1535
- function fromRoute(_x5, _x6, _x7) {
1688
+ function fromRoute(_x6, _x7, _x8) {
1536
1689
  return _fromRoute.apply(this, arguments);
1537
1690
  }
1538
1691
  return fromRoute;
@@ -1613,10 +1766,10 @@ var Trade = /*#__PURE__*/function () {
1613
1766
  // because we're unable to derive the pre-buy-tax amount, use 0% as a placeholder.
1614
1767
  if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT;
1615
1768
  var spotOutputAmount = sdkCore.CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
1616
- for (var _iterator9 = _createForOfIteratorHelperLoose(this.swaps), _step9; !(_step9 = _iterator9()).done;) {
1617
- var _step9$value = _step9.value,
1618
- route = _step9$value.route,
1619
- inputAmount = _step9$value.inputAmount;
1769
+ for (var _iterator11 = _createForOfIteratorHelperLoose(this.swaps), _step11; !(_step11 = _iterator11()).done;) {
1770
+ var _step11$value = _step11.value,
1771
+ route = _step11$value.route,
1772
+ inputAmount = _step11$value.inputAmount;
1620
1773
  var midPrice = route.midPrice;
1621
1774
  var postTaxInputAmount = inputAmount.multiply(new sdkCore.Fraction(ONE).subtract(this.inputTax));
1622
1775
  spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount));
@@ -1645,18 +1798,19 @@ function encodeMixedRouteToPath(route) {
1645
1798
  var inputToken = _ref.inputToken,
1646
1799
  path = _ref.path,
1647
1800
  types = _ref.types;
1801
+ if (pool instanceof v4Sdk.Pool) throw 'Encoding mixed routes with V4 not supported';
1648
1802
  var outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
1649
1803
  if (index === 0) {
1650
1804
  return {
1651
1805
  inputToken: outputToken,
1652
1806
  types: ['address', 'uint24', 'address'],
1653
- path: [inputToken.address, pool instanceof v3Sdk.Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address]
1807
+ path: [inputToken.wrapped.address, pool instanceof v3Sdk.Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.wrapped.address]
1654
1808
  };
1655
1809
  } else {
1656
1810
  return {
1657
1811
  inputToken: outputToken,
1658
1812
  types: [].concat(types, ['uint24', 'address']),
1659
- path: [].concat(path, [pool instanceof v3Sdk.Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address])
1813
+ path: [].concat(path, [pool instanceof v3Sdk.Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.wrapped.address])
1660
1814
  };
1661
1815
  }
1662
1816
  }, {
@@ -1830,6 +1984,9 @@ var SwapRouter = /*#__PURE__*/function () {
1830
1984
  route = _step2$value.route,
1831
1985
  inputAmount = _step2$value.inputAmount,
1832
1986
  outputAmount = _step2$value.outputAmount;
1987
+ if (route.pools.some(function (pool) {
1988
+ return pool instanceof v4Sdk.Pool;
1989
+ })) throw 'Encoding mixed routes with V4 not supported';
1833
1990
  var amountIn = v3Sdk.toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
1834
1991
  var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
1835
1992
  // flag for whether the trade is single hop or not
@@ -1845,8 +2002,8 @@ var SwapRouter = /*#__PURE__*/function () {
1845
2002
  /// We don't use encodeV3Swap() or encodeV2Swap() because casting the trade to a V3Trade or V2Trade is overcomplex
1846
2003
  if (mixedRouteIsAllV3(route)) {
1847
2004
  var exactInputSingleParams = {
1848
- tokenIn: route.path[0].address,
1849
- tokenOut: route.path[1].address,
2005
+ tokenIn: route.path[0].wrapped.address,
2006
+ tokenOut: route.path[1].wrapped.address,
1850
2007
  fee: route.pools[0].fee,
1851
2008
  recipient: recipient,
1852
2009
  amountIn: amountIn,
@@ -1856,7 +2013,7 @@ var SwapRouter = /*#__PURE__*/function () {
1856
2013
  calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]));
1857
2014
  } else {
1858
2015
  var path = route.path.map(function (token) {
1859
- return token.address;
2016
+ return token.wrapped.address;
1860
2017
  });
1861
2018
  var exactInputParams = [amountIn, performAggregatedSlippageCheck ? 0 : amountOut, path, recipient];
1862
2019
  calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams));
@@ -1875,7 +2032,7 @@ var SwapRouter = /*#__PURE__*/function () {
1875
2032
  var newRouteOriginal = new MixedRouteSDK([].concat(section), section[0].token0.equals(inputToken) ? section[0].token0 : section[0].token1, outputToken);
1876
2033
  var newRoute = new MixedRoute(newRouteOriginal);
1877
2034
  /// Previous output is now input
1878
- inputToken = outputToken;
2035
+ inputToken = outputToken.wrapped;
1879
2036
  if (mixedRouteIsAllV3(newRoute)) {
1880
2037
  var _path = encodeMixedRouteToPath(newRoute);
1881
2038
  var _exactInputParams = {
@@ -1890,7 +2047,7 @@ var SwapRouter = /*#__PURE__*/function () {
1890
2047
  calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [_exactInputParams]));
1891
2048
  } else {
1892
2049
  var _exactInputParams2 = [i === 0 ? amountIn : 0, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (token) {
1893
- return token.address;
2050
+ return token.wrapped.address;
1894
2051
  }), isLastSectionInRoute(i) ? recipient : ADDRESS_THIS];
1895
2052
  calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', _exactInputParams2));
1896
2053
  }
@@ -1907,7 +2064,7 @@ var SwapRouter = /*#__PURE__*/function () {
1907
2064
  if (trades instanceof Trade) {
1908
2065
  !trades.swaps.every(function (swap) {
1909
2066
  return swap.route.protocol === exports.Protocol.V3 || swap.route.protocol === exports.Protocol.V2 || swap.route.protocol === exports.Protocol.MIXED;
1910
- }) ? invariant(false, 'UNSUPPORTED_PROTOCOL') : void 0;
2067
+ }) ? invariant(false, 'UNSUPPORTED_PROTOCOL (encoding routes with v4 not supported)') : void 0;
1911
2068
  var individualTrades = [];
1912
2069
  for (var _iterator3 = _createForOfIteratorHelperLoose(trades.swaps), _step3; !(_step3 = _iterator3()).done;) {
1913
2070
  var _step3$value = _step3.value,
@@ -2146,6 +2303,7 @@ var SwapRouter = /*#__PURE__*/function () {
2146
2303
  SwapRouter.INTERFACE = /*#__PURE__*/new abi.Interface(ISwapRouter02_json.abi);
2147
2304
 
2148
2305
  exports.ADDRESS_THIS = ADDRESS_THIS;
2306
+ exports.ADDRESS_ZERO = ADDRESS_ZERO;
2149
2307
  exports.ApproveAndCall = ApproveAndCall;
2150
2308
  exports.MSG_SENDER = MSG_SENDER;
2151
2309
  exports.MixedRoute = MixedRoute;
@@ -2157,6 +2315,7 @@ exports.ONE_HUNDRED_PERCENT = ONE_HUNDRED_PERCENT;
2157
2315
  exports.PaymentsExtended = PaymentsExtended;
2158
2316
  exports.RouteV2 = RouteV2;
2159
2317
  exports.RouteV3 = RouteV3;
2318
+ exports.RouteV4 = RouteV4;
2160
2319
  exports.SwapRouter = SwapRouter;
2161
2320
  exports.Trade = Trade;
2162
2321
  exports.V2_FEE_PATH_PLACEHOLDER = V2_FEE_PATH_PLACEHOLDER;