@ring-protocol/router-sdk 0.1.0 → 0.1.7

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.
@@ -15,6 +15,7 @@ var IPeripheryPaymentsWithFeeExtended = _interopDefault(require('@uniswap/swap-r
15
15
  var ISwapRouter02 = _interopDefault(require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json'));
16
16
  var v2Sdk = require('@ring-protocol/v2-sdk');
17
17
  var v4Sdk = require('@ring-protocol/v4-sdk');
18
+ var fewV2Sdk = require('@ring-protocol/few-v2-sdk');
18
19
  var solidity = require('@ethersproject/solidity');
19
20
 
20
21
  var ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
@@ -24,6 +25,8 @@ var ZERO = /*#__PURE__*/JSBI.BigInt(0);
24
25
  var ONE = /*#__PURE__*/JSBI.BigInt(1);
25
26
  // = 1 << 23 or 0b0100000000000000000000000
26
27
  var MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER = 1 << 23;
28
+ // = 1 << 22 or 010000000000000000000000
29
+ var RING_FEE_PATH_PLACEHOLDER = 4194304;
27
30
  // = 10 << 4 or 0b00100000
28
31
  var MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER = 2 << 4;
29
32
  // = 11 << 20 or 0b001100000000000000000000
@@ -1069,18 +1072,38 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1069
1072
  Protocol["V2"] = "V2";
1070
1073
  Protocol["V3"] = "V3";
1071
1074
  Protocol["V4"] = "V4";
1075
+ Protocol["FEWV2"] = "FEWV2";
1072
1076
  Protocol["MIXED"] = "MIXED";
1073
1077
  })(exports.Protocol || (exports.Protocol = {}));
1074
1078
 
1075
1079
  // Helper function to get the pathInput and pathOutput for a V2 / V3 route
1076
1080
  // currency could be native so we check against the wrapped version as they don't support native ETH in path
1077
1081
  function getPathToken(currency, pool) {
1078
- if (pool.token0.wrapped.equals(currency.wrapped)) {
1079
- return pool.token0;
1080
- } else if (pool.token1.wrapped.equals(currency.wrapped)) {
1081
- return pool.token1;
1082
+ var fewToken = fewV2Sdk.getFewTokenFromOriginalToken(currency.wrapped, currency.chainId);
1083
+ if (pool instanceof fewV2Sdk.Pair || pool instanceof v2Sdk.Pair) {
1084
+ if (pool.token0.wrapped.equals(fewToken)) {
1085
+ return pool.token0;
1086
+ } else if (pool.token1.wrapped.equals(fewToken)) {
1087
+ return pool.token1;
1088
+ } else if (pool.token0.wrapped.equals(currency.wrapped)) {
1089
+ return pool.token0;
1090
+ } else if (pool.token1.wrapped.equals(currency.wrapped)) {
1091
+ return pool.token1;
1092
+ } else {
1093
+ throw new Error("Expected fewToken " + currency.symbol + " to be either " + pool.token0.symbol + " or " + pool.token1.symbol);
1094
+ }
1082
1095
  } else {
1083
- throw new Error("Expected token " + currency.symbol + " to be either " + pool.token0.symbol + " or " + pool.token1.symbol);
1096
+ if (pool.token0.wrapped.equals(currency.wrapped)) {
1097
+ return pool.token0;
1098
+ } else if (pool.token1.wrapped.equals(currency.wrapped)) {
1099
+ return pool.token1;
1100
+ } else if (pool.token0.wrapped.equals(fewToken)) {
1101
+ return pool.token0;
1102
+ } else if (pool.token1.wrapped.equals(fewToken)) {
1103
+ return pool.token1;
1104
+ } else {
1105
+ throw new Error("Expected token " + currency.symbol + " to be either " + pool.token0.symbol + " or " + pool.token1.symbol);
1106
+ }
1084
1107
  }
1085
1108
  }
1086
1109
  // V2 route wrapper
@@ -1097,16 +1120,30 @@ var RouteV2 = /*#__PURE__*/function (_V2RouteSDK) {
1097
1120
  _inheritsLoose(RouteV2, _V2RouteSDK);
1098
1121
  return RouteV2;
1099
1122
  }(v2Sdk.Route);
1123
+ // Few V2 route wrapper
1124
+ var FewRouteV2 = /*#__PURE__*/function (_FewV2RouteSDK) {
1125
+ function FewRouteV2(fewV2Route) {
1126
+ var _this2;
1127
+ _this2 = _FewV2RouteSDK.call(this, fewV2Route.pairs, fewV2Route.input, fewV2Route.output) || this;
1128
+ _this2.protocol = exports.Protocol.FEWV2;
1129
+ _this2.pools = _this2.pairs;
1130
+ _this2.pathInput = getPathToken(fewV2Route.input, _this2.pairs[0]);
1131
+ _this2.pathOutput = getPathToken(fewV2Route.output, _this2.pairs[_this2.pairs.length - 1]);
1132
+ return _this2;
1133
+ }
1134
+ _inheritsLoose(FewRouteV2, _FewV2RouteSDK);
1135
+ return FewRouteV2;
1136
+ }(fewV2Sdk.Route);
1100
1137
  // V3 route wrapper
1101
1138
  var RouteV3 = /*#__PURE__*/function (_V3RouteSDK) {
1102
1139
  function RouteV3(v3Route) {
1103
- var _this2;
1104
- _this2 = _V3RouteSDK.call(this, v3Route.pools, v3Route.input, v3Route.output) || this;
1105
- _this2.protocol = exports.Protocol.V3;
1106
- _this2.path = v3Route.tokenPath;
1107
- _this2.pathInput = getPathToken(v3Route.input, _this2.pools[0]);
1108
- _this2.pathOutput = getPathToken(v3Route.output, _this2.pools[_this2.pools.length - 1]);
1109
- return _this2;
1140
+ var _this3;
1141
+ _this3 = _V3RouteSDK.call(this, v3Route.pools, v3Route.input, v3Route.output) || this;
1142
+ _this3.protocol = exports.Protocol.V3;
1143
+ _this3.path = v3Route.tokenPath;
1144
+ _this3.pathInput = getPathToken(v3Route.input, _this3.pools[0]);
1145
+ _this3.pathOutput = getPathToken(v3Route.output, _this3.pools[_this3.pools.length - 1]);
1146
+ return _this3;
1110
1147
  }
1111
1148
  _inheritsLoose(RouteV3, _V3RouteSDK);
1112
1149
  return RouteV3;
@@ -1114,11 +1151,11 @@ var RouteV3 = /*#__PURE__*/function (_V3RouteSDK) {
1114
1151
  // V4 route wrapper
1115
1152
  var RouteV4 = /*#__PURE__*/function (_V4RouteSDK) {
1116
1153
  function RouteV4(v4Route) {
1117
- var _this3;
1118
- _this3 = _V4RouteSDK.call(this, v4Route.pools, v4Route.input, v4Route.output) || this;
1119
- _this3.protocol = exports.Protocol.V4;
1120
- _this3.path = v4Route.currencyPath;
1121
- return _this3;
1154
+ var _this4;
1155
+ _this4 = _V4RouteSDK.call(this, v4Route.pools, v4Route.input, v4Route.output) || this;
1156
+ _this4.protocol = exports.Protocol.V4;
1157
+ _this4.path = v4Route.currencyPath;
1158
+ return _this4;
1122
1159
  }
1123
1160
  _inheritsLoose(RouteV4, _V4RouteSDK);
1124
1161
  return RouteV4;
@@ -1126,10 +1163,10 @@ var RouteV4 = /*#__PURE__*/function (_V4RouteSDK) {
1126
1163
  // Mixed route wrapper
1127
1164
  var MixedRoute = /*#__PURE__*/function (_MixedRouteSDK) {
1128
1165
  function MixedRoute(mixedRoute) {
1129
- var _this4;
1130
- _this4 = _MixedRouteSDK.call(this, mixedRoute.pools, mixedRoute.input, mixedRoute.output) || this;
1131
- _this4.protocol = exports.Protocol.MIXED;
1132
- return _this4;
1166
+ var _this5;
1167
+ _this5 = _MixedRouteSDK.call(this, mixedRoute.pools, mixedRoute.input, mixedRoute.output) || this;
1168
+ _this5.protocol = exports.Protocol.MIXED;
1169
+ return _this5;
1133
1170
  }
1134
1171
  _inheritsLoose(MixedRoute, _MixedRouteSDK);
1135
1172
  return MixedRoute;
@@ -1138,7 +1175,9 @@ var MixedRoute = /*#__PURE__*/function (_MixedRouteSDK) {
1138
1175
  var Trade = /*#__PURE__*/function () {
1139
1176
  // construct a trade across v2 and v3 routes from pre-computed amounts
1140
1177
  function Trade(_ref) {
1141
- var _ref$v2Routes = _ref.v2Routes,
1178
+ var _ref$fewV2Routes = _ref.fewV2Routes,
1179
+ fewV2Routes = _ref$fewV2Routes === void 0 ? [] : _ref$fewV2Routes,
1180
+ _ref$v2Routes = _ref.v2Routes,
1142
1181
  v2Routes = _ref$v2Routes === void 0 ? [] : _ref$v2Routes,
1143
1182
  _ref$v3Routes = _ref.v3Routes,
1144
1183
  v3Routes = _ref$v3Routes === void 0 ? [] : _ref$v3Routes,
@@ -1149,13 +1188,13 @@ var Trade = /*#__PURE__*/function () {
1149
1188
  tradeType = _ref.tradeType;
1150
1189
  this.swaps = [];
1151
1190
  this.routes = [];
1152
- // wrap v2 routes
1153
- for (var _iterator = _createForOfIteratorHelperLoose(v2Routes), _step; !(_step = _iterator()).done;) {
1191
+ // wrap few v2 routes
1192
+ for (var _iterator = _createForOfIteratorHelperLoose(fewV2Routes), _step; !(_step = _iterator()).done;) {
1154
1193
  var _step$value = _step.value,
1155
- routev2 = _step$value.routev2,
1194
+ fewRouteV2 = _step$value.fewRouteV2,
1156
1195
  inputAmount = _step$value.inputAmount,
1157
1196
  outputAmount = _step$value.outputAmount;
1158
- var route = new RouteV2(routev2);
1197
+ var route = new FewRouteV2(fewRouteV2);
1159
1198
  this.routes.push(route);
1160
1199
  this.swaps.push({
1161
1200
  route: route,
@@ -1163,13 +1202,13 @@ var Trade = /*#__PURE__*/function () {
1163
1202
  outputAmount: outputAmount
1164
1203
  });
1165
1204
  }
1166
- // wrap v3 routes
1167
- for (var _iterator2 = _createForOfIteratorHelperLoose(v3Routes), _step2; !(_step2 = _iterator2()).done;) {
1205
+ // wrap v2 routes
1206
+ for (var _iterator2 = _createForOfIteratorHelperLoose(v2Routes), _step2; !(_step2 = _iterator2()).done;) {
1168
1207
  var _step2$value = _step2.value,
1169
- routev3 = _step2$value.routev3,
1208
+ routev2 = _step2$value.routev2,
1170
1209
  _inputAmount = _step2$value.inputAmount,
1171
1210
  _outputAmount = _step2$value.outputAmount;
1172
- var _route = new RouteV3(routev3);
1211
+ var _route = new RouteV2(routev2);
1173
1212
  this.routes.push(_route);
1174
1213
  this.swaps.push({
1175
1214
  route: _route,
@@ -1177,13 +1216,13 @@ var Trade = /*#__PURE__*/function () {
1177
1216
  outputAmount: _outputAmount
1178
1217
  });
1179
1218
  }
1180
- // wrap v4 routes
1181
- for (var _iterator3 = _createForOfIteratorHelperLoose(v4Routes), _step3; !(_step3 = _iterator3()).done;) {
1219
+ // wrap v3 routes
1220
+ for (var _iterator3 = _createForOfIteratorHelperLoose(v3Routes), _step3; !(_step3 = _iterator3()).done;) {
1182
1221
  var _step3$value = _step3.value,
1183
- routev4 = _step3$value.routev4,
1222
+ routev3 = _step3$value.routev3,
1184
1223
  _inputAmount2 = _step3$value.inputAmount,
1185
1224
  _outputAmount2 = _step3$value.outputAmount;
1186
- var _route2 = new RouteV4(routev4);
1225
+ var _route2 = new RouteV3(routev3);
1187
1226
  this.routes.push(_route2);
1188
1227
  this.swaps.push({
1189
1228
  route: _route2,
@@ -1191,12 +1230,13 @@ var Trade = /*#__PURE__*/function () {
1191
1230
  outputAmount: _outputAmount2
1192
1231
  });
1193
1232
  }
1194
- for (var _iterator4 = _createForOfIteratorHelperLoose(mixedRoutes), _step4; !(_step4 = _iterator4()).done;) {
1233
+ // wrap v4 routes
1234
+ for (var _iterator4 = _createForOfIteratorHelperLoose(v4Routes), _step4; !(_step4 = _iterator4()).done;) {
1195
1235
  var _step4$value = _step4.value,
1196
- mixedRoute = _step4$value.mixedRoute,
1236
+ routev4 = _step4$value.routev4,
1197
1237
  _inputAmount3 = _step4$value.inputAmount,
1198
1238
  _outputAmount3 = _step4$value.outputAmount;
1199
- var _route3 = new MixedRoute(mixedRoute);
1239
+ var _route3 = new RouteV4(routev4);
1200
1240
  this.routes.push(_route3);
1201
1241
  this.swaps.push({
1202
1242
  route: _route3,
@@ -1204,33 +1244,46 @@ var Trade = /*#__PURE__*/function () {
1204
1244
  outputAmount: _outputAmount3
1205
1245
  });
1206
1246
  }
1247
+ for (var _iterator5 = _createForOfIteratorHelperLoose(mixedRoutes), _step5; !(_step5 = _iterator5()).done;) {
1248
+ var _step5$value = _step5.value,
1249
+ mixedRoute = _step5$value.mixedRoute,
1250
+ _inputAmount4 = _step5$value.inputAmount,
1251
+ _outputAmount4 = _step5$value.outputAmount;
1252
+ var _route4 = new MixedRoute(mixedRoute);
1253
+ this.routes.push(_route4);
1254
+ this.swaps.push({
1255
+ route: _route4,
1256
+ inputAmount: _inputAmount4,
1257
+ outputAmount: _outputAmount4
1258
+ });
1259
+ }
1207
1260
  if (this.swaps.length === 0) {
1208
1261
  throw new Error('No routes provided when calling Trade constructor');
1209
1262
  }
1210
1263
  this.tradeType = tradeType;
1211
1264
  // each route must have the same input and output currency
1212
- var inputCurrency = this.swaps[0].inputAmount.currency;
1213
- var outputCurrency = this.swaps[0].outputAmount.currency;
1214
- !this.swaps.every(function (_ref2) {
1215
- var route = _ref2.route;
1216
- return inputCurrency.wrapped.equals(route.input.wrapped);
1217
- }) ? invariant(false, 'INPUT_CURRENCY_MATCH') : void 0;
1218
- !this.swaps.every(function (_ref3) {
1219
- var route = _ref3.route;
1220
- return outputCurrency.wrapped.equals(route.output.wrapped);
1221
- }) ? invariant(false, 'OUTPUT_CURRENCY_MATCH') : void 0;
1265
+ // const inputCurrency = this.swaps[0].inputAmount.currency
1266
+ // const outputCurrency = this.swaps[0].outputAmount.currency
1267
+ // invariant(
1268
+ // this.swaps.every(({ route }) => inputCurrency.wrapped.equals(route.input.wrapped)),
1269
+ // 'INPUT_CURRENCY_MATCH'
1270
+ // )
1271
+ // invariant(
1272
+ // this.swaps.every(({ route }) => outputCurrency.wrapped.equals(route.output.wrapped)),
1273
+ // 'OUTPUT_CURRENCY_MATCH'
1274
+ // )
1222
1275
  // pools must be unique inter protocols
1223
- var numPools = this.swaps.map(function (_ref4) {
1224
- var route = _ref4.route;
1276
+ var numPools = this.swaps.map(function (_ref2) {
1277
+ var route = _ref2.route;
1225
1278
  return route.pools.length;
1226
1279
  }).reduce(function (total, cur) {
1227
1280
  return total + cur;
1228
1281
  }, 0);
1229
1282
  var poolIdentifierSet = new Set();
1230
- for (var _iterator5 = _createForOfIteratorHelperLoose(this.swaps), _step5; !(_step5 = _iterator5()).done;) {
1231
- var _route4 = _step5.value.route;
1232
- for (var _iterator6 = _createForOfIteratorHelperLoose(_route4.pools), _step6; !(_step6 = _iterator6()).done;) {
1233
- var pool = _step6.value;
1283
+ for (var _iterator6 = _createForOfIteratorHelperLoose(this.swaps), _step6; !(_step6 = _iterator6()).done;) {
1284
+ var _route5 = _step6.value.route;
1285
+ for (var _iterator7 = _createForOfIteratorHelperLoose(_route5.pools), _step7; !(_step7 = _iterator7()).done;) {
1286
+ var pool = _step7.value;
1234
1287
  if (pool instanceof v4Sdk.Pool) {
1235
1288
  poolIdentifierSet.add(pool.poolId);
1236
1289
  } else if (pool instanceof v3Sdk.Pool) {
@@ -1238,6 +1291,9 @@ var Trade = /*#__PURE__*/function () {
1238
1291
  } else if (pool instanceof v2Sdk.Pair) {
1239
1292
  var pair = pool;
1240
1293
  poolIdentifierSet.add(v2Sdk.Pair.getAddress(pair.token0, pair.token1));
1294
+ } else if (pool instanceof fewV2Sdk.Pair) {
1295
+ var _pair = pool;
1296
+ poolIdentifierSet.add(fewV2Sdk.Pair.getAddress(_pair.token0, _pair.token1));
1241
1297
  } else {
1242
1298
  throw new Error('Unexpected pool type in route when constructing trade object');
1243
1299
  }
@@ -1298,41 +1354,52 @@ var Trade = /*#__PURE__*/function () {
1298
1354
  return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
1299
1355
  };
1300
1356
  Trade.fromRoutes = /*#__PURE__*/function () {
1301
- var _fromRoutes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(v2Routes, v3Routes, tradeType, mixedRoutes, v4Routes) {
1302
- 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, _iterator0, _step0, _step0$value, mixedRoute, _amount, mixedRouteTrade, _inputAmount4, _outputAmount4;
1357
+ var _fromRoutes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fewV2Routes, v2Routes, v3Routes, tradeType, mixedRoutes, v4Routes) {
1358
+ var populatedFewV2Routes, populatedV2Routes, populatedV3Routes, populatedV4Routes, populatedMixedRoutes, _iterator8, _step8, _step8$value, fewRouteV2, _amount2, fewV2Trade, _inputAmount6, _outputAmount6, _iterator9, _step9, _step9$value, routev2, _amount3, v2Trade, _inputAmount7, _outputAmount7, _iterator0, _step0, _step0$value, routev3, _amount4, v3Trade, _inputAmount8, _outputAmount8, _iterator1, _step1, _step1$value, routev4, amount, v4Trade, inputAmount, outputAmount, _iterator10, _step10, _step10$value, mixedRoute, _amount, mixedRouteTrade, _inputAmount5, _outputAmount5;
1303
1359
  return _regenerator().w(function (_context) {
1304
1360
  while (1) switch (_context.n) {
1305
1361
  case 0:
1362
+ populatedFewV2Routes = [];
1306
1363
  populatedV2Routes = [];
1307
1364
  populatedV3Routes = [];
1308
1365
  populatedV4Routes = [];
1309
1366
  populatedMixedRoutes = [];
1310
- for (_iterator7 = _createForOfIteratorHelperLoose(v2Routes); !(_step7 = _iterator7()).done;) {
1311
- _step7$value = _step7.value, routev2 = _step7$value.routev2, _amount2 = _step7$value.amount;
1312
- v2Trade = new v2Sdk.Trade(routev2, _amount2, tradeType);
1313
- _inputAmount5 = v2Trade.inputAmount, _outputAmount5 = v2Trade.outputAmount;
1367
+ for (_iterator8 = _createForOfIteratorHelperLoose(fewV2Routes); !(_step8 = _iterator8()).done;) {
1368
+ _step8$value = _step8.value, fewRouteV2 = _step8$value.fewRouteV2, _amount2 = _step8$value.amount;
1369
+ fewV2Trade = new fewV2Sdk.Trade(fewRouteV2, _amount2, tradeType);
1370
+ _inputAmount6 = fewV2Trade.inputAmount, _outputAmount6 = fewV2Trade.outputAmount;
1371
+ populatedFewV2Routes.push({
1372
+ fewRouteV2: fewRouteV2,
1373
+ inputAmount: _inputAmount6,
1374
+ outputAmount: _outputAmount6
1375
+ });
1376
+ }
1377
+ for (_iterator9 = _createForOfIteratorHelperLoose(v2Routes); !(_step9 = _iterator9()).done;) {
1378
+ _step9$value = _step9.value, routev2 = _step9$value.routev2, _amount3 = _step9$value.amount;
1379
+ v2Trade = new v2Sdk.Trade(routev2, _amount3, tradeType);
1380
+ _inputAmount7 = v2Trade.inputAmount, _outputAmount7 = v2Trade.outputAmount;
1314
1381
  populatedV2Routes.push({
1315
1382
  routev2: routev2,
1316
- inputAmount: _inputAmount5,
1317
- outputAmount: _outputAmount5
1383
+ inputAmount: _inputAmount7,
1384
+ outputAmount: _outputAmount7
1318
1385
  });
1319
1386
  }
1320
- _iterator8 = _createForOfIteratorHelperLoose(v3Routes);
1387
+ _iterator0 = _createForOfIteratorHelperLoose(v3Routes);
1321
1388
  case 1:
1322
- if ((_step8 = _iterator8()).done) {
1389
+ if ((_step0 = _iterator0()).done) {
1323
1390
  _context.n = 4;
1324
1391
  break;
1325
1392
  }
1326
- _step8$value = _step8.value, routev3 = _step8$value.routev3, _amount3 = _step8$value.amount;
1393
+ _step0$value = _step0.value, routev3 = _step0$value.routev3, _amount4 = _step0$value.amount;
1327
1394
  _context.n = 2;
1328
- return v3Sdk.Trade.fromRoute(routev3, _amount3, tradeType);
1395
+ return v3Sdk.Trade.fromRoute(routev3, _amount4, tradeType);
1329
1396
  case 2:
1330
1397
  v3Trade = _context.v;
1331
- _inputAmount6 = v3Trade.inputAmount, _outputAmount6 = v3Trade.outputAmount;
1398
+ _inputAmount8 = v3Trade.inputAmount, _outputAmount8 = v3Trade.outputAmount;
1332
1399
  populatedV3Routes.push({
1333
1400
  routev3: routev3,
1334
- inputAmount: _inputAmount6,
1335
- outputAmount: _outputAmount6
1401
+ inputAmount: _inputAmount8,
1402
+ outputAmount: _outputAmount8
1336
1403
  });
1337
1404
  case 3:
1338
1405
  _context.n = 1;
@@ -1342,13 +1409,13 @@ var Trade = /*#__PURE__*/function () {
1342
1409
  _context.n = 8;
1343
1410
  break;
1344
1411
  }
1345
- _iterator9 = _createForOfIteratorHelperLoose(v4Routes);
1412
+ _iterator1 = _createForOfIteratorHelperLoose(v4Routes);
1346
1413
  case 5:
1347
- if ((_step9 = _iterator9()).done) {
1414
+ if ((_step1 = _iterator1()).done) {
1348
1415
  _context.n = 8;
1349
1416
  break;
1350
1417
  }
1351
- _step9$value = _step9.value, routev4 = _step9$value.routev4, amount = _step9$value.amount;
1418
+ _step1$value = _step1.value, routev4 = _step1$value.routev4, amount = _step1$value.amount;
1352
1419
  _context.n = 6;
1353
1420
  return v4Sdk.Trade.fromRoute(routev4, amount, tradeType);
1354
1421
  case 6:
@@ -1367,28 +1434,29 @@ var Trade = /*#__PURE__*/function () {
1367
1434
  _context.n = 12;
1368
1435
  break;
1369
1436
  }
1370
- _iterator0 = _createForOfIteratorHelperLoose(mixedRoutes);
1437
+ _iterator10 = _createForOfIteratorHelperLoose(mixedRoutes);
1371
1438
  case 9:
1372
- if ((_step0 = _iterator0()).done) {
1439
+ if ((_step10 = _iterator10()).done) {
1373
1440
  _context.n = 12;
1374
1441
  break;
1375
1442
  }
1376
- _step0$value = _step0.value, mixedRoute = _step0$value.mixedRoute, _amount = _step0$value.amount;
1443
+ _step10$value = _step10.value, mixedRoute = _step10$value.mixedRoute, _amount = _step10$value.amount;
1377
1444
  _context.n = 10;
1378
1445
  return MixedRouteTrade.fromRoute(mixedRoute, _amount, tradeType);
1379
1446
  case 10:
1380
1447
  mixedRouteTrade = _context.v;
1381
- _inputAmount4 = mixedRouteTrade.inputAmount, _outputAmount4 = mixedRouteTrade.outputAmount;
1448
+ _inputAmount5 = mixedRouteTrade.inputAmount, _outputAmount5 = mixedRouteTrade.outputAmount;
1382
1449
  populatedMixedRoutes.push({
1383
1450
  mixedRoute: mixedRoute,
1384
- inputAmount: _inputAmount4,
1385
- outputAmount: _outputAmount4
1451
+ inputAmount: _inputAmount5,
1452
+ outputAmount: _outputAmount5
1386
1453
  });
1387
1454
  case 11:
1388
1455
  _context.n = 9;
1389
1456
  break;
1390
1457
  case 12:
1391
1458
  return _context.a(2, new Trade({
1459
+ fewV2Routes: populatedFewV2Routes,
1392
1460
  v2Routes: populatedV2Routes,
1393
1461
  v3Routes: populatedV3Routes,
1394
1462
  v4Routes: populatedV4Routes,
@@ -1398,89 +1466,105 @@ var Trade = /*#__PURE__*/function () {
1398
1466
  }
1399
1467
  }, _callee);
1400
1468
  }));
1401
- function fromRoutes(_x, _x2, _x3, _x4, _x5) {
1469
+ function fromRoutes(_x, _x2, _x3, _x4, _x5, _x6) {
1402
1470
  return _fromRoutes.apply(this, arguments);
1403
1471
  }
1404
1472
  return fromRoutes;
1405
1473
  }();
1406
1474
  Trade.fromRoute = /*#__PURE__*/function () {
1407
1475
  var _fromRoute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(route, amount, tradeType) {
1408
- var v2Routes, v3Routes, v4Routes, mixedRoutes, v2Trade, inputAmount, outputAmount, v3Trade, _inputAmount7, _outputAmount7, v4Trade, _inputAmount8, _outputAmount8, mixedRouteTrade, _inputAmount9, _outputAmount9;
1476
+ var fewV2Routes, v2Routes, v3Routes, v4Routes, mixedRoutes, fewV2Trade, inputAmount, outputAmount, v2Trade, _inputAmount9, _outputAmount9, v3Trade, _inputAmount0, _outputAmount0, v4Trade, _inputAmount1, _outputAmount1, mixedRouteTrade, _inputAmount10, _outputAmount10;
1409
1477
  return _regenerator().w(function (_context2) {
1410
1478
  while (1) switch (_context2.n) {
1411
1479
  case 0:
1480
+ fewV2Routes = [];
1412
1481
  v2Routes = [];
1413
1482
  v3Routes = [];
1414
1483
  v4Routes = [];
1415
1484
  mixedRoutes = [];
1416
- if (!(route instanceof v2Sdk.Route)) {
1485
+ if (!(route instanceof fewV2Sdk.Route)) {
1417
1486
  _context2.n = 1;
1418
1487
  break;
1419
1488
  }
1420
- v2Trade = new v2Sdk.Trade(route, amount, tradeType);
1421
- inputAmount = v2Trade.inputAmount, outputAmount = v2Trade.outputAmount;
1422
- v2Routes = [{
1423
- routev2: route,
1489
+ fewV2Trade = new fewV2Sdk.Trade(route, amount, tradeType);
1490
+ inputAmount = fewV2Trade.inputAmount, outputAmount = fewV2Trade.outputAmount;
1491
+ fewV2Routes = [{
1492
+ fewRouteV2: route,
1424
1493
  inputAmount: inputAmount,
1425
1494
  outputAmount: outputAmount
1426
1495
  }];
1427
- _context2.n = 8;
1496
+ _context2.n = 9;
1428
1497
  break;
1429
1498
  case 1:
1499
+ if (!(route instanceof v2Sdk.Route)) {
1500
+ _context2.n = 2;
1501
+ break;
1502
+ }
1503
+ v2Trade = new v2Sdk.Trade(route, amount, tradeType);
1504
+ _inputAmount9 = v2Trade.inputAmount, _outputAmount9 = v2Trade.outputAmount;
1505
+ v2Routes = [{
1506
+ routev2: route,
1507
+ inputAmount: _inputAmount9,
1508
+ outputAmount: _outputAmount9
1509
+ }];
1510
+ _context2.n = 9;
1511
+ break;
1512
+ case 2:
1430
1513
  if (!(route instanceof v3Sdk.Route)) {
1431
- _context2.n = 3;
1514
+ _context2.n = 4;
1432
1515
  break;
1433
1516
  }
1434
- _context2.n = 2;
1517
+ _context2.n = 3;
1435
1518
  return v3Sdk.Trade.fromRoute(route, amount, tradeType);
1436
- case 2:
1519
+ case 3:
1437
1520
  v3Trade = _context2.v;
1438
- _inputAmount7 = v3Trade.inputAmount, _outputAmount7 = v3Trade.outputAmount;
1521
+ _inputAmount0 = v3Trade.inputAmount, _outputAmount0 = v3Trade.outputAmount;
1439
1522
  v3Routes = [{
1440
1523
  routev3: route,
1441
- inputAmount: _inputAmount7,
1442
- outputAmount: _outputAmount7
1524
+ inputAmount: _inputAmount0,
1525
+ outputAmount: _outputAmount0
1443
1526
  }];
1444
- _context2.n = 8;
1527
+ _context2.n = 9;
1445
1528
  break;
1446
- case 3:
1529
+ case 4:
1447
1530
  if (!(route instanceof v4Sdk.Route)) {
1448
- _context2.n = 5;
1531
+ _context2.n = 6;
1449
1532
  break;
1450
1533
  }
1451
- _context2.n = 4;
1534
+ _context2.n = 5;
1452
1535
  return v4Sdk.Trade.fromRoute(route, amount, tradeType);
1453
- case 4:
1536
+ case 5:
1454
1537
  v4Trade = _context2.v;
1455
- _inputAmount8 = v4Trade.inputAmount, _outputAmount8 = v4Trade.outputAmount;
1538
+ _inputAmount1 = v4Trade.inputAmount, _outputAmount1 = v4Trade.outputAmount;
1456
1539
  v4Routes = [{
1457
1540
  routev4: route,
1458
- inputAmount: _inputAmount8,
1459
- outputAmount: _outputAmount8
1541
+ inputAmount: _inputAmount1,
1542
+ outputAmount: _outputAmount1
1460
1543
  }];
1461
- _context2.n = 8;
1544
+ _context2.n = 9;
1462
1545
  break;
1463
- case 5:
1546
+ case 6:
1464
1547
  if (!(route instanceof MixedRouteSDK)) {
1465
- _context2.n = 7;
1548
+ _context2.n = 8;
1466
1549
  break;
1467
1550
  }
1468
- _context2.n = 6;
1551
+ _context2.n = 7;
1469
1552
  return MixedRouteTrade.fromRoute(route, amount, tradeType);
1470
- case 6:
1553
+ case 7:
1471
1554
  mixedRouteTrade = _context2.v;
1472
- _inputAmount9 = mixedRouteTrade.inputAmount, _outputAmount9 = mixedRouteTrade.outputAmount;
1555
+ _inputAmount10 = mixedRouteTrade.inputAmount, _outputAmount10 = mixedRouteTrade.outputAmount;
1473
1556
  mixedRoutes = [{
1474
1557
  mixedRoute: route,
1475
- inputAmount: _inputAmount9,
1476
- outputAmount: _outputAmount9
1558
+ inputAmount: _inputAmount10,
1559
+ outputAmount: _outputAmount10
1477
1560
  }];
1478
- _context2.n = 8;
1561
+ _context2.n = 9;
1479
1562
  break;
1480
- case 7:
1481
- throw new Error('Invalid route type');
1482
1563
  case 8:
1564
+ throw new Error('Invalid route type');
1565
+ case 9:
1483
1566
  return _context2.a(2, new Trade({
1567
+ fewV2Routes: fewV2Routes,
1484
1568
  v2Routes: v2Routes,
1485
1569
  v3Routes: v3Routes,
1486
1570
  v4Routes: v4Routes,
@@ -1490,7 +1574,7 @@ var Trade = /*#__PURE__*/function () {
1490
1574
  }
1491
1575
  }, _callee2);
1492
1576
  }));
1493
- function fromRoute(_x6, _x7, _x8) {
1577
+ function fromRoute(_x7, _x8, _x9) {
1494
1578
  return _fromRoute.apply(this, arguments);
1495
1579
  }
1496
1580
  return fromRoute;
@@ -1502,8 +1586,8 @@ var Trade = /*#__PURE__*/function () {
1502
1586
  return this._inputAmount;
1503
1587
  }
1504
1588
  var inputAmountCurrency = this.swaps[0].inputAmount.currency;
1505
- var totalInputFromRoutes = this.swaps.map(function (_ref5) {
1506
- var routeInputAmount = _ref5.inputAmount;
1589
+ var totalInputFromRoutes = this.swaps.map(function (_ref3) {
1590
+ var routeInputAmount = _ref3.inputAmount;
1507
1591
  return routeInputAmount;
1508
1592
  }).reduce(function (total, cur) {
1509
1593
  return total.add(cur);
@@ -1518,8 +1602,8 @@ var Trade = /*#__PURE__*/function () {
1518
1602
  return this._outputAmount;
1519
1603
  }
1520
1604
  var outputCurrency = this.swaps[0].outputAmount.currency;
1521
- var totalOutputFromRoutes = this.swaps.map(function (_ref6) {
1522
- var routeOutputAmount = _ref6.outputAmount;
1605
+ var totalOutputFromRoutes = this.swaps.map(function (_ref4) {
1606
+ var routeOutputAmount = _ref4.outputAmount;
1523
1607
  return routeOutputAmount;
1524
1608
  }).reduce(function (total, cur) {
1525
1609
  return total.add(cur);
@@ -1544,12 +1628,12 @@ var Trade = /*#__PURE__*/function () {
1544
1628
  get: function get() {
1545
1629
  var _this$swaps$find, _this$swaps$find2;
1546
1630
  // Find native currencies for reduce below
1547
- var inputNativeCurrency = (_this$swaps$find = this.swaps.find(function (_ref7) {
1548
- var inputAmount = _ref7.inputAmount;
1631
+ var inputNativeCurrency = (_this$swaps$find = this.swaps.find(function (_ref5) {
1632
+ var inputAmount = _ref5.inputAmount;
1549
1633
  return inputAmount.currency.isNative;
1550
1634
  })) == null ? void 0 : _this$swaps$find.inputAmount.currency;
1551
- var outputNativeCurrency = (_this$swaps$find2 = this.swaps.find(function (_ref8) {
1552
- var outputAmount = _ref8.outputAmount;
1635
+ var outputNativeCurrency = (_this$swaps$find2 = this.swaps.find(function (_ref6) {
1636
+ var outputAmount = _ref6.outputAmount;
1553
1637
  return outputAmount.currency.isNative;
1554
1638
  })) == null ? void 0 : _this$swaps$find2.outputAmount.currency;
1555
1639
  return {
@@ -1641,10 +1725,10 @@ var Trade = /*#__PURE__*/function () {
1641
1725
  // because we're unable to derive the pre-buy-tax amount, use 0% as a placeholder.
1642
1726
  if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT;
1643
1727
  var spotOutputAmount = sdkCore.CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
1644
- for (var _iterator1 = _createForOfIteratorHelperLoose(this.swaps), _step1; !(_step1 = _iterator1()).done;) {
1645
- var _step1$value = _step1.value,
1646
- route = _step1$value.route,
1647
- inputAmount = _step1$value.inputAmount;
1728
+ for (var _iterator11 = _createForOfIteratorHelperLoose(this.swaps), _step11; !(_step11 = _iterator11()).done;) {
1729
+ var _step11$value = _step11.value,
1730
+ route = _step11$value.route,
1731
+ inputAmount = _step11$value.inputAmount;
1648
1732
  var midPrice = route.midPrice;
1649
1733
  var postTaxInputAmount = inputAmount.multiply(new sdkCore.Fraction(ONE).subtract(this.inputTax));
1650
1734
  spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount));
@@ -2220,6 +2304,7 @@ SwapRouter.INTERFACE = /*#__PURE__*/new abi.Interface(ISwapRouter02.abi);
2220
2304
  exports.ADDRESS_THIS = ADDRESS_THIS;
2221
2305
  exports.ADDRESS_ZERO = ADDRESS_ZERO;
2222
2306
  exports.ApproveAndCall = ApproveAndCall;
2307
+ exports.FewRouteV2 = FewRouteV2;
2223
2308
  exports.MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER = MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER;
2224
2309
  exports.MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER = MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER;
2225
2310
  exports.MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER = MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER;
@@ -2232,6 +2317,7 @@ exports.MulticallExtended = MulticallExtended;
2232
2317
  exports.ONE = ONE;
2233
2318
  exports.ONE_HUNDRED_PERCENT = ONE_HUNDRED_PERCENT;
2234
2319
  exports.PaymentsExtended = PaymentsExtended;
2320
+ exports.RING_FEE_PATH_PLACEHOLDER = RING_FEE_PATH_PLACEHOLDER;
2235
2321
  exports.RouteV2 = RouteV2;
2236
2322
  exports.RouteV3 = RouteV3;
2237
2323
  exports.RouteV4 = RouteV4;