@uniswap/router-sdk 1.10.0 → 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.
@@ -18,28 +18,28 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
18
18
  inputAmount: CurrencyAmount<TInput>;
19
19
  outputAmount: CurrencyAmount<TOutput>;
20
20
  }[];
21
- constructor({ v2Routes, v3Routes, v4Routes, tradeType, mixedRoutes, }: {
22
- v2Routes: {
21
+ constructor({ v2Routes, v3Routes, v4Routes, mixedRoutes, tradeType, }: {
22
+ v2Routes?: {
23
23
  routev2: V2RouteSDK<TInput, TOutput>;
24
24
  inputAmount: CurrencyAmount<TInput>;
25
25
  outputAmount: CurrencyAmount<TOutput>;
26
26
  }[];
27
- v3Routes: {
27
+ v3Routes?: {
28
28
  routev3: V3RouteSDK<TInput, TOutput>;
29
29
  inputAmount: CurrencyAmount<TInput>;
30
30
  outputAmount: CurrencyAmount<TOutput>;
31
31
  }[];
32
- v4Routes: {
32
+ v4Routes?: {
33
33
  routev4: V4RouteSDK<TInput, TOutput>;
34
34
  inputAmount: CurrencyAmount<TInput>;
35
35
  outputAmount: CurrencyAmount<TOutput>;
36
36
  }[];
37
- tradeType: TTradeType;
38
37
  mixedRoutes?: {
39
38
  mixedRoute: MixedRouteSDK<TInput, TOutput>;
40
39
  inputAmount: CurrencyAmount<TInput>;
41
40
  outputAmount: CurrencyAmount<TOutput>;
42
41
  }[];
42
+ tradeType: TTradeType;
43
43
  });
44
44
  get inputAmount(): CurrencyAmount<TInput>;
45
45
  get outputAmount(): CurrencyAmount<TOutput>;
@@ -91,12 +91,12 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
91
91
  }[], v3Routes: {
92
92
  routev3: V3RouteSDK<TInput, TOutput>;
93
93
  amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
94
- }[], v4Routes: {
95
- routev4: V4RouteSDK<TInput, TOutput>;
96
- amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
97
94
  }[], tradeType: TTradeType, mixedRoutes?: {
98
95
  mixedRoute: MixedRouteSDK<TInput, TOutput>;
99
96
  amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
97
+ }[], v4Routes?: {
98
+ routev4: V4RouteSDK<TInput, TOutput>;
99
+ amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
100
100
  }[]): Promise<Trade<TInput, TOutput, TTradeType>>;
101
- static fromRoute<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(route: V2RouteSDK<TInput, TOutput> | V3RouteSDK<TInput, TOutput> | MixedRouteSDK<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>;
101
+ static fromRoute<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(route: V2RouteSDK<TInput, TOutput> | V3RouteSDK<TInput, TOutput> | V4RouteSDK<TInput, TOutput> | MixedRouteSDK<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>;
102
102
  }
@@ -1336,48 +1336,65 @@ var MixedRoute = /*#__PURE__*/function (_MixedRouteSDK) {
1336
1336
  var Trade = /*#__PURE__*/function () {
1337
1337
  // construct a trade across v2 and v3 routes from pre-computed amounts
1338
1338
  function Trade(_ref) {
1339
- var v2Routes = _ref.v2Routes,
1340
- v3Routes = _ref.v3Routes,
1341
- v4Routes = _ref.v4Routes,
1342
- tradeType = _ref.tradeType,
1343
- 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;
1344
1348
  this.swaps = [];
1345
1349
  this.routes = [];
1346
1350
  // wrap v2 routes
1347
1351
  for (var _iterator = _createForOfIteratorHelperLoose(v2Routes), _step; !(_step = _iterator()).done;) {
1348
1352
  var _step$value = _step.value,
1349
1353
  routev2 = _step$value.routev2,
1350
- _inputAmount = _step$value.inputAmount,
1351
- _outputAmount = _step$value.outputAmount;
1352
- var _route = new RouteV2(routev2);
1353
- 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);
1354
1358
  this.swaps.push({
1355
- route: _route,
1356
- inputAmount: _inputAmount,
1357
- outputAmount: _outputAmount
1359
+ route: route,
1360
+ inputAmount: inputAmount,
1361
+ outputAmount: outputAmount
1358
1362
  });
1359
1363
  }
1360
1364
  // wrap v3 routes
1361
1365
  for (var _iterator2 = _createForOfIteratorHelperLoose(v3Routes), _step2; !(_step2 = _iterator2()).done;) {
1362
1366
  var _step2$value = _step2.value,
1363
1367
  routev3 = _step2$value.routev3,
1364
- _inputAmount2 = _step2$value.inputAmount,
1365
- _outputAmount2 = _step2$value.outputAmount;
1366
- var _route2 = new RouteV3(routev3);
1367
- this.routes.push(_route2);
1368
+ _inputAmount = _step2$value.inputAmount,
1369
+ _outputAmount = _step2$value.outputAmount;
1370
+ var _route = new RouteV3(routev3);
1371
+ this.routes.push(_route);
1368
1372
  this.swaps.push({
1369
- route: _route2,
1370
- inputAmount: _inputAmount2,
1371
- outputAmount: _outputAmount2
1373
+ route: _route,
1374
+ inputAmount: _inputAmount,
1375
+ outputAmount: _outputAmount
1372
1376
  });
1373
1377
  }
1374
1378
  // wrap v4 routes
1375
1379
  for (var _iterator3 = _createForOfIteratorHelperLoose(v4Routes), _step3; !(_step3 = _iterator3()).done;) {
1376
1380
  var _step3$value = _step3.value,
1377
1381
  routev4 = _step3$value.routev4,
1378
- _inputAmount3 = _step3$value.inputAmount,
1379
- _outputAmount3 = _step3$value.outputAmount;
1380
- var _route3 = new RouteV4(routev4);
1382
+ _inputAmount2 = _step3$value.inputAmount,
1383
+ _outputAmount2 = _step3$value.outputAmount;
1384
+ var _route2 = new RouteV4(routev4);
1385
+ this.routes.push(_route2);
1386
+ this.swaps.push({
1387
+ route: _route2,
1388
+ inputAmount: _inputAmount2,
1389
+ outputAmount: _outputAmount2
1390
+ });
1391
+ }
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);
1381
1398
  this.routes.push(_route3);
1382
1399
  this.swaps.push({
1383
1400
  route: _route3,
@@ -1385,22 +1402,6 @@ var Trade = /*#__PURE__*/function () {
1385
1402
  outputAmount: _outputAmount3
1386
1403
  });
1387
1404
  }
1388
- // wrap mixedRoutes
1389
- if (mixedRoutes) {
1390
- for (var _iterator4 = _createForOfIteratorHelperLoose(mixedRoutes), _step4; !(_step4 = _iterator4()).done;) {
1391
- var _step4$value = _step4.value,
1392
- mixedRoute = _step4$value.mixedRoute,
1393
- inputAmount = _step4$value.inputAmount,
1394
- outputAmount = _step4$value.outputAmount;
1395
- var route = new MixedRoute(mixedRoute);
1396
- this.routes.push(route);
1397
- this.swaps.push({
1398
- route: route,
1399
- inputAmount: inputAmount,
1400
- outputAmount: outputAmount
1401
- });
1402
- }
1403
- }
1404
1405
  if (this.swaps.length === 0) {
1405
1406
  throw new Error('No routes provided when calling Trade constructor');
1406
1407
  }
@@ -1486,8 +1487,8 @@ var Trade = /*#__PURE__*/function () {
1486
1487
  return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
1487
1488
  };
1488
1489
  Trade.fromRoutes = /*#__PURE__*/function () {
1489
- var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(v2Routes, v3Routes, v4Routes, tradeType, mixedRoutes) {
1490
- 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;
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;
1491
1492
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1492
1493
  while (1) switch (_context.prev = _context.next) {
1493
1494
  case 0:
@@ -1496,13 +1497,13 @@ var Trade = /*#__PURE__*/function () {
1496
1497
  populatedV4Routes = [];
1497
1498
  populatedMixedRoutes = [];
1498
1499
  for (_iterator7 = _createForOfIteratorHelperLoose(v2Routes); !(_step7 = _iterator7()).done;) {
1499
- _step7$value = _step7.value, routev2 = _step7$value.routev2, _amount = _step7$value.amount;
1500
- v2Trade = new v2Sdk.Trade(routev2, _amount, tradeType);
1501
- _inputAmount4 = v2Trade.inputAmount, _outputAmount4 = v2Trade.outputAmount;
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;
1502
1503
  populatedV2Routes.push({
1503
1504
  routev2: routev2,
1504
- inputAmount: _inputAmount4,
1505
- outputAmount: _outputAmount4
1505
+ inputAmount: _inputAmount5,
1506
+ outputAmount: _outputAmount5
1506
1507
  });
1507
1508
  }
1508
1509
  _iterator8 = _createForOfIteratorHelperLoose(v3Routes);
@@ -1511,67 +1512,71 @@ var Trade = /*#__PURE__*/function () {
1511
1512
  _context.next = 15;
1512
1513
  break;
1513
1514
  }
1514
- _step8$value = _step8.value, routev3 = _step8$value.routev3, _amount2 = _step8$value.amount;
1515
+ _step8$value = _step8.value, routev3 = _step8$value.routev3, _amount3 = _step8$value.amount;
1515
1516
  _context.next = 10;
1516
- return v3Sdk.Trade.fromRoute(routev3, _amount2, tradeType);
1517
+ return v3Sdk.Trade.fromRoute(routev3, _amount3, tradeType);
1517
1518
  case 10:
1518
1519
  v3Trade = _context.sent;
1519
- _inputAmount5 = v3Trade.inputAmount, _outputAmount5 = v3Trade.outputAmount;
1520
+ _inputAmount6 = v3Trade.inputAmount, _outputAmount6 = v3Trade.outputAmount;
1520
1521
  populatedV3Routes.push({
1521
1522
  routev3: routev3,
1522
- inputAmount: _inputAmount5,
1523
- outputAmount: _outputAmount5
1523
+ inputAmount: _inputAmount6,
1524
+ outputAmount: _outputAmount6
1524
1525
  });
1525
1526
  case 13:
1526
1527
  _context.next = 6;
1527
1528
  break;
1528
1529
  case 15:
1530
+ if (!v4Routes) {
1531
+ _context.next = 26;
1532
+ break;
1533
+ }
1529
1534
  _iterator9 = _createForOfIteratorHelperLoose(v4Routes);
1530
- case 16:
1535
+ case 17:
1531
1536
  if ((_step9 = _iterator9()).done) {
1532
- _context.next = 25;
1537
+ _context.next = 26;
1533
1538
  break;
1534
1539
  }
1535
- _step9$value = _step9.value, routev4 = _step9$value.routev4, _amount3 = _step9$value.amount;
1536
- _context.next = 20;
1537
- return v4Sdk.Trade.fromRoute(routev4, _amount3, tradeType);
1538
- case 20:
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:
1539
1544
  v4Trade = _context.sent;
1540
- _inputAmount6 = v4Trade.inputAmount, _outputAmount6 = v4Trade.outputAmount;
1545
+ inputAmount = v4Trade.inputAmount, outputAmount = v4Trade.outputAmount;
1541
1546
  populatedV4Routes.push({
1542
1547
  routev4: routev4,
1543
- inputAmount: _inputAmount6,
1544
- outputAmount: _outputAmount6
1548
+ inputAmount: inputAmount,
1549
+ outputAmount: outputAmount
1545
1550
  });
1546
- case 23:
1547
- _context.next = 16;
1551
+ case 24:
1552
+ _context.next = 17;
1548
1553
  break;
1549
- case 25:
1554
+ case 26:
1550
1555
  if (!mixedRoutes) {
1551
- _context.next = 36;
1556
+ _context.next = 37;
1552
1557
  break;
1553
1558
  }
1554
1559
  _iterator10 = _createForOfIteratorHelperLoose(mixedRoutes);
1555
- case 27:
1560
+ case 28:
1556
1561
  if ((_step10 = _iterator10()).done) {
1557
- _context.next = 36;
1562
+ _context.next = 37;
1558
1563
  break;
1559
1564
  }
1560
- _step10$value = _step10.value, mixedRoute = _step10$value.mixedRoute, amount = _step10$value.amount;
1561
- _context.next = 31;
1562
- return MixedRouteTrade.fromRoute(mixedRoute, amount, tradeType);
1563
- case 31:
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:
1564
1569
  mixedRouteTrade = _context.sent;
1565
- inputAmount = mixedRouteTrade.inputAmount, outputAmount = mixedRouteTrade.outputAmount;
1570
+ _inputAmount4 = mixedRouteTrade.inputAmount, _outputAmount4 = mixedRouteTrade.outputAmount;
1566
1571
  populatedMixedRoutes.push({
1567
1572
  mixedRoute: mixedRoute,
1568
- inputAmount: inputAmount,
1569
- outputAmount: outputAmount
1573
+ inputAmount: _inputAmount4,
1574
+ outputAmount: _outputAmount4
1570
1575
  });
1571
- case 34:
1572
- _context.next = 27;
1576
+ case 35:
1577
+ _context.next = 28;
1573
1578
  break;
1574
- case 36:
1579
+ case 37:
1575
1580
  return _context.abrupt("return", new Trade({
1576
1581
  v2Routes: populatedV2Routes,
1577
1582
  v3Routes: populatedV3Routes,
@@ -1579,7 +1584,7 @@ var Trade = /*#__PURE__*/function () {
1579
1584
  mixedRoutes: populatedMixedRoutes,
1580
1585
  tradeType: tradeType
1581
1586
  }));
1582
- case 37:
1587
+ case 38:
1583
1588
  case "end":
1584
1589
  return _context.stop();
1585
1590
  }