@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.
- package/dist/constants.d.ts +1 -0
- package/dist/entities/mixedRoute/route.d.ts +6 -4
- package/dist/entities/mixedRoute/trade.d.ts +5 -2
- package/dist/entities/protocol.d.ts +1 -0
- package/dist/entities/route.d.ts +11 -5
- package/dist/entities/trade.d.ts +17 -8
- package/dist/router-sdk.cjs.development.js +343 -184
- package/dist/router-sdk.cjs.development.js.map +1 -1
- package/dist/router-sdk.cjs.production.min.js +1 -1
- package/dist/router-sdk.cjs.production.min.js.map +1 -1
- package/dist/router-sdk.esm.js +353 -196
- package/dist/router-sdk.esm.js.map +1 -1
- package/dist/utils/getOutputAmount.d.ts +7 -0
- package/dist/utils/index.d.ts +7 -4
- package/package.json +5 -3
package/dist/router-sdk.esm.js
CHANGED
|
@@ -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$
|
|
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$
|
|
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
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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 = [
|
|
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.
|
|
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
|
|
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
|
|
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 ===
|
|
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$
|
|
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
|
|
884
|
+
return getOutputAmount(pool, amounts[i]);
|
|
822
885
|
case 9:
|
|
823
|
-
_yield$
|
|
824
|
-
_outputAmount = _yield$
|
|
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$
|
|
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.
|
|
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
|
|
957
|
+
return getOutputAmount(pool, amounts[i]);
|
|
895
958
|
case 16:
|
|
896
|
-
_yield$
|
|
897
|
-
_outputAmount2 = _yield$
|
|
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,
|
|
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
|
|
1035
|
-
tokenOut = currencyOut.wrapped;
|
|
1097
|
+
amountIn = nextAmountIn;
|
|
1036
1098
|
i = 0;
|
|
1037
|
-
case
|
|
1099
|
+
case 9:
|
|
1038
1100
|
if (!(i < pools.length)) {
|
|
1039
|
-
_context3.next =
|
|
1101
|
+
_context3.next = 56;
|
|
1040
1102
|
break;
|
|
1041
1103
|
}
|
|
1042
|
-
pool = pools[i];
|
|
1043
|
-
|
|
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",
|
|
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",
|
|
1120
|
+
return _context3.abrupt("continue", 53);
|
|
1058
1121
|
case 17:
|
|
1059
1122
|
amountOut = void 0;
|
|
1060
1123
|
_context3.prev = 18;
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
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.
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
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",
|
|
1076
|
-
case
|
|
1077
|
-
throw _context3.
|
|
1078
|
-
case
|
|
1079
|
-
if (!
|
|
1080
|
-
_context3.next =
|
|
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.
|
|
1084
|
-
_context3.
|
|
1085
|
-
_context3.next =
|
|
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
|
|
1088
|
-
_context3.
|
|
1089
|
-
_context3.
|
|
1090
|
-
_context3.
|
|
1091
|
-
(0, _context3.
|
|
1092
|
-
_context3.next =
|
|
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
|
|
1170
|
+
case 49:
|
|
1095
1171
|
if (!(maxHops > 1 && pools.length > 1)) {
|
|
1096
|
-
_context3.next =
|
|
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 =
|
|
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
|
|
1181
|
+
case 53:
|
|
1106
1182
|
i++;
|
|
1107
|
-
_context3.next =
|
|
1183
|
+
_context3.next = 9;
|
|
1108
1184
|
break;
|
|
1109
|
-
case
|
|
1185
|
+
case 56:
|
|
1110
1186
|
return _context3.abrupt("return", bestTrades);
|
|
1111
|
-
case
|
|
1187
|
+
case 57:
|
|
1112
1188
|
case "end":
|
|
1113
1189
|
return _context3.stop();
|
|
1114
1190
|
}
|
|
1115
|
-
}, _callee3, null, [[18,
|
|
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 (
|
|
1139
|
-
var 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 (
|
|
1158
|
-
var 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
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
return
|
|
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);
|
|
@@ -1243,33 +1332,52 @@ var MixedRoute = /*#__PURE__*/function (_MixedRouteSDK) {
|
|
|
1243
1332
|
var Trade = /*#__PURE__*/function () {
|
|
1244
1333
|
// construct a trade across v2 and v3 routes from pre-computed amounts
|
|
1245
1334
|
function Trade(_ref) {
|
|
1246
|
-
var v2Routes = _ref.v2Routes,
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1335
|
+
var _ref$v2Routes = _ref.v2Routes,
|
|
1336
|
+
v2Routes = _ref$v2Routes === void 0 ? [] : _ref$v2Routes,
|
|
1337
|
+
_ref$v3Routes = _ref.v3Routes,
|
|
1338
|
+
v3Routes = _ref$v3Routes === void 0 ? [] : _ref$v3Routes,
|
|
1339
|
+
_ref$v4Routes = _ref.v4Routes,
|
|
1340
|
+
v4Routes = _ref$v4Routes === void 0 ? [] : _ref$v4Routes,
|
|
1341
|
+
_ref$mixedRoutes = _ref.mixedRoutes,
|
|
1342
|
+
mixedRoutes = _ref$mixedRoutes === void 0 ? [] : _ref$mixedRoutes,
|
|
1343
|
+
tradeType = _ref.tradeType;
|
|
1250
1344
|
this.swaps = [];
|
|
1251
1345
|
this.routes = [];
|
|
1252
1346
|
// wrap v2 routes
|
|
1253
1347
|
for (var _iterator = _createForOfIteratorHelperLoose(v2Routes), _step; !(_step = _iterator()).done;) {
|
|
1254
1348
|
var _step$value = _step.value,
|
|
1255
1349
|
routev2 = _step$value.routev2,
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
var
|
|
1259
|
-
this.routes.push(
|
|
1350
|
+
inputAmount = _step$value.inputAmount,
|
|
1351
|
+
outputAmount = _step$value.outputAmount;
|
|
1352
|
+
var route = new RouteV2(routev2);
|
|
1353
|
+
this.routes.push(route);
|
|
1260
1354
|
this.swaps.push({
|
|
1261
|
-
route:
|
|
1262
|
-
inputAmount:
|
|
1263
|
-
outputAmount:
|
|
1355
|
+
route: route,
|
|
1356
|
+
inputAmount: inputAmount,
|
|
1357
|
+
outputAmount: outputAmount
|
|
1264
1358
|
});
|
|
1265
1359
|
}
|
|
1266
1360
|
// wrap v3 routes
|
|
1267
1361
|
for (var _iterator2 = _createForOfIteratorHelperLoose(v3Routes), _step2; !(_step2 = _iterator2()).done;) {
|
|
1268
1362
|
var _step2$value = _step2.value,
|
|
1269
1363
|
routev3 = _step2$value.routev3,
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
var
|
|
1364
|
+
_inputAmount = _step2$value.inputAmount,
|
|
1365
|
+
_outputAmount = _step2$value.outputAmount;
|
|
1366
|
+
var _route = new RouteV3(routev3);
|
|
1367
|
+
this.routes.push(_route);
|
|
1368
|
+
this.swaps.push({
|
|
1369
|
+
route: _route,
|
|
1370
|
+
inputAmount: _inputAmount,
|
|
1371
|
+
outputAmount: _outputAmount
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
// wrap v4 routes
|
|
1375
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(v4Routes), _step3; !(_step3 = _iterator3()).done;) {
|
|
1376
|
+
var _step3$value = _step3.value,
|
|
1377
|
+
routev4 = _step3$value.routev4,
|
|
1378
|
+
_inputAmount2 = _step3$value.inputAmount,
|
|
1379
|
+
_outputAmount2 = _step3$value.outputAmount;
|
|
1380
|
+
var _route2 = new RouteV4(routev4);
|
|
1273
1381
|
this.routes.push(_route2);
|
|
1274
1382
|
this.swaps.push({
|
|
1275
1383
|
route: _route2,
|
|
@@ -1277,21 +1385,18 @@ var Trade = /*#__PURE__*/function () {
|
|
|
1277
1385
|
outputAmount: _outputAmount2
|
|
1278
1386
|
});
|
|
1279
1387
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
outputAmount: outputAmount
|
|
1293
|
-
});
|
|
1294
|
-
}
|
|
1388
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(mixedRoutes), _step4; !(_step4 = _iterator4()).done;) {
|
|
1389
|
+
var _step4$value = _step4.value,
|
|
1390
|
+
mixedRoute = _step4$value.mixedRoute,
|
|
1391
|
+
_inputAmount3 = _step4$value.inputAmount,
|
|
1392
|
+
_outputAmount3 = _step4$value.outputAmount;
|
|
1393
|
+
var _route3 = new MixedRoute(mixedRoute);
|
|
1394
|
+
this.routes.push(_route3);
|
|
1395
|
+
this.swaps.push({
|
|
1396
|
+
route: _route3,
|
|
1397
|
+
inputAmount: _inputAmount3,
|
|
1398
|
+
outputAmount: _outputAmount3
|
|
1399
|
+
});
|
|
1295
1400
|
}
|
|
1296
1401
|
if (this.swaps.length === 0) {
|
|
1297
1402
|
throw new Error('No routes provided when calling Trade constructor');
|
|
@@ -1315,22 +1420,24 @@ var Trade = /*#__PURE__*/function () {
|
|
|
1315
1420
|
}).reduce(function (total, cur) {
|
|
1316
1421
|
return total + cur;
|
|
1317
1422
|
}, 0);
|
|
1318
|
-
var
|
|
1319
|
-
for (var
|
|
1320
|
-
var
|
|
1321
|
-
for (var
|
|
1322
|
-
var pool =
|
|
1423
|
+
var poolIdentifierSet = new Set();
|
|
1424
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(this.swaps), _step5; !(_step5 = _iterator5()).done;) {
|
|
1425
|
+
var _route4 = _step5.value.route;
|
|
1426
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(_route4.pools), _step6; !(_step6 = _iterator6()).done;) {
|
|
1427
|
+
var pool = _step6.value;
|
|
1323
1428
|
if (pool instanceof Pool) {
|
|
1324
|
-
|
|
1429
|
+
poolIdentifierSet.add(pool.poolId);
|
|
1430
|
+
} else if (pool instanceof Pool$1) {
|
|
1431
|
+
poolIdentifierSet.add(Pool$1.getAddress(pool.token0, pool.token1, pool.fee));
|
|
1325
1432
|
} else if (pool instanceof Pair) {
|
|
1326
1433
|
var pair = pool;
|
|
1327
|
-
|
|
1434
|
+
poolIdentifierSet.add(Pair.getAddress(pair.token0, pair.token1));
|
|
1328
1435
|
} else {
|
|
1329
1436
|
throw new Error('Unexpected pool type in route when constructing trade object');
|
|
1330
1437
|
}
|
|
1331
1438
|
}
|
|
1332
1439
|
}
|
|
1333
|
-
!(numPools ===
|
|
1440
|
+
!(numPools === poolIdentifierSet.size) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS_DUPLICATED') : invariant(false) : void 0;
|
|
1334
1441
|
}
|
|
1335
1442
|
var _proto = Trade.prototype;
|
|
1336
1443
|
/**
|
|
@@ -1376,159 +1483,205 @@ var Trade = /*#__PURE__*/function () {
|
|
|
1376
1483
|
return new Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
|
|
1377
1484
|
};
|
|
1378
1485
|
Trade.fromRoutes = /*#__PURE__*/function () {
|
|
1379
|
-
var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(v2Routes, v3Routes, tradeType, mixedRoutes) {
|
|
1380
|
-
var populatedV2Routes, populatedV3Routes, populatedMixedRoutes,
|
|
1486
|
+
var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(v2Routes, v3Routes, tradeType, mixedRoutes, v4Routes) {
|
|
1487
|
+
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;
|
|
1381
1488
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1382
1489
|
while (1) switch (_context.prev = _context.next) {
|
|
1383
1490
|
case 0:
|
|
1384
1491
|
populatedV2Routes = [];
|
|
1385
1492
|
populatedV3Routes = [];
|
|
1493
|
+
populatedV4Routes = [];
|
|
1386
1494
|
populatedMixedRoutes = [];
|
|
1387
|
-
for (
|
|
1388
|
-
|
|
1389
|
-
v2Trade = new Trade$
|
|
1390
|
-
|
|
1495
|
+
for (_iterator7 = _createForOfIteratorHelperLoose(v2Routes); !(_step7 = _iterator7()).done;) {
|
|
1496
|
+
_step7$value = _step7.value, routev2 = _step7$value.routev2, _amount2 = _step7$value.amount;
|
|
1497
|
+
v2Trade = new Trade$3(routev2, _amount2, tradeType);
|
|
1498
|
+
_inputAmount5 = v2Trade.inputAmount, _outputAmount5 = v2Trade.outputAmount;
|
|
1391
1499
|
populatedV2Routes.push({
|
|
1392
1500
|
routev2: routev2,
|
|
1393
|
-
inputAmount:
|
|
1394
|
-
outputAmount:
|
|
1501
|
+
inputAmount: _inputAmount5,
|
|
1502
|
+
outputAmount: _outputAmount5
|
|
1395
1503
|
});
|
|
1396
1504
|
}
|
|
1397
|
-
|
|
1398
|
-
case
|
|
1399
|
-
if ((
|
|
1400
|
-
_context.next =
|
|
1505
|
+
_iterator8 = _createForOfIteratorHelperLoose(v3Routes);
|
|
1506
|
+
case 6:
|
|
1507
|
+
if ((_step8 = _iterator8()).done) {
|
|
1508
|
+
_context.next = 15;
|
|
1401
1509
|
break;
|
|
1402
1510
|
}
|
|
1403
|
-
|
|
1404
|
-
_context.next =
|
|
1405
|
-
return Trade$
|
|
1406
|
-
case
|
|
1511
|
+
_step8$value = _step8.value, routev3 = _step8$value.routev3, _amount3 = _step8$value.amount;
|
|
1512
|
+
_context.next = 10;
|
|
1513
|
+
return Trade$2.fromRoute(routev3, _amount3, tradeType);
|
|
1514
|
+
case 10:
|
|
1407
1515
|
v3Trade = _context.sent;
|
|
1408
|
-
|
|
1516
|
+
_inputAmount6 = v3Trade.inputAmount, _outputAmount6 = v3Trade.outputAmount;
|
|
1409
1517
|
populatedV3Routes.push({
|
|
1410
1518
|
routev3: routev3,
|
|
1411
|
-
inputAmount:
|
|
1412
|
-
outputAmount:
|
|
1519
|
+
inputAmount: _inputAmount6,
|
|
1520
|
+
outputAmount: _outputAmount6
|
|
1413
1521
|
});
|
|
1414
|
-
case
|
|
1415
|
-
_context.next =
|
|
1522
|
+
case 13:
|
|
1523
|
+
_context.next = 6;
|
|
1416
1524
|
break;
|
|
1417
|
-
case
|
|
1525
|
+
case 15:
|
|
1526
|
+
if (!v4Routes) {
|
|
1527
|
+
_context.next = 26;
|
|
1528
|
+
break;
|
|
1529
|
+
}
|
|
1530
|
+
_iterator9 = _createForOfIteratorHelperLoose(v4Routes);
|
|
1531
|
+
case 17:
|
|
1532
|
+
if ((_step9 = _iterator9()).done) {
|
|
1533
|
+
_context.next = 26;
|
|
1534
|
+
break;
|
|
1535
|
+
}
|
|
1536
|
+
_step9$value = _step9.value, routev4 = _step9$value.routev4, amount = _step9$value.amount;
|
|
1537
|
+
_context.next = 21;
|
|
1538
|
+
return Trade$1.fromRoute(routev4, amount, tradeType);
|
|
1539
|
+
case 21:
|
|
1540
|
+
v4Trade = _context.sent;
|
|
1541
|
+
inputAmount = v4Trade.inputAmount, outputAmount = v4Trade.outputAmount;
|
|
1542
|
+
populatedV4Routes.push({
|
|
1543
|
+
routev4: routev4,
|
|
1544
|
+
inputAmount: inputAmount,
|
|
1545
|
+
outputAmount: outputAmount
|
|
1546
|
+
});
|
|
1547
|
+
case 24:
|
|
1548
|
+
_context.next = 17;
|
|
1549
|
+
break;
|
|
1550
|
+
case 26:
|
|
1418
1551
|
if (!mixedRoutes) {
|
|
1419
|
-
_context.next =
|
|
1552
|
+
_context.next = 37;
|
|
1420
1553
|
break;
|
|
1421
1554
|
}
|
|
1422
|
-
|
|
1423
|
-
case
|
|
1424
|
-
if ((
|
|
1425
|
-
_context.next =
|
|
1555
|
+
_iterator10 = _createForOfIteratorHelperLoose(mixedRoutes);
|
|
1556
|
+
case 28:
|
|
1557
|
+
if ((_step10 = _iterator10()).done) {
|
|
1558
|
+
_context.next = 37;
|
|
1426
1559
|
break;
|
|
1427
1560
|
}
|
|
1428
|
-
|
|
1429
|
-
_context.next =
|
|
1430
|
-
return MixedRouteTrade.fromRoute(mixedRoute,
|
|
1431
|
-
case
|
|
1561
|
+
_step10$value = _step10.value, mixedRoute = _step10$value.mixedRoute, _amount = _step10$value.amount;
|
|
1562
|
+
_context.next = 32;
|
|
1563
|
+
return MixedRouteTrade.fromRoute(mixedRoute, _amount, tradeType);
|
|
1564
|
+
case 32:
|
|
1432
1565
|
mixedRouteTrade = _context.sent;
|
|
1433
|
-
|
|
1566
|
+
_inputAmount4 = mixedRouteTrade.inputAmount, _outputAmount4 = mixedRouteTrade.outputAmount;
|
|
1434
1567
|
populatedMixedRoutes.push({
|
|
1435
1568
|
mixedRoute: mixedRoute,
|
|
1436
|
-
inputAmount:
|
|
1437
|
-
outputAmount:
|
|
1569
|
+
inputAmount: _inputAmount4,
|
|
1570
|
+
outputAmount: _outputAmount4
|
|
1438
1571
|
});
|
|
1439
|
-
case
|
|
1440
|
-
_context.next =
|
|
1572
|
+
case 35:
|
|
1573
|
+
_context.next = 28;
|
|
1441
1574
|
break;
|
|
1442
|
-
case
|
|
1575
|
+
case 37:
|
|
1443
1576
|
return _context.abrupt("return", new Trade({
|
|
1444
1577
|
v2Routes: populatedV2Routes,
|
|
1445
1578
|
v3Routes: populatedV3Routes,
|
|
1579
|
+
v4Routes: populatedV4Routes,
|
|
1446
1580
|
mixedRoutes: populatedMixedRoutes,
|
|
1447
1581
|
tradeType: tradeType
|
|
1448
1582
|
}));
|
|
1449
|
-
case
|
|
1583
|
+
case 38:
|
|
1450
1584
|
case "end":
|
|
1451
1585
|
return _context.stop();
|
|
1452
1586
|
}
|
|
1453
1587
|
}, _callee);
|
|
1454
1588
|
}));
|
|
1455
|
-
function fromRoutes(_x, _x2, _x3, _x4) {
|
|
1589
|
+
function fromRoutes(_x, _x2, _x3, _x4, _x5) {
|
|
1456
1590
|
return _fromRoutes.apply(this, arguments);
|
|
1457
1591
|
}
|
|
1458
1592
|
return fromRoutes;
|
|
1459
1593
|
}();
|
|
1460
1594
|
Trade.fromRoute = /*#__PURE__*/function () {
|
|
1461
1595
|
var _fromRoute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(route, amount, tradeType) {
|
|
1462
|
-
var v2Routes, v3Routes, mixedRoutes, v2Trade, inputAmount, outputAmount, v3Trade,
|
|
1596
|
+
var v2Routes, v3Routes, v4Routes, mixedRoutes, v2Trade, inputAmount, outputAmount, v3Trade, _inputAmount7, _outputAmount7, v4Trade, _inputAmount8, _outputAmount8, mixedRouteTrade, _inputAmount9, _outputAmount9;
|
|
1463
1597
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1464
1598
|
while (1) switch (_context2.prev = _context2.next) {
|
|
1465
1599
|
case 0:
|
|
1466
1600
|
v2Routes = [];
|
|
1467
1601
|
v3Routes = [];
|
|
1602
|
+
v4Routes = [];
|
|
1468
1603
|
mixedRoutes = [];
|
|
1469
1604
|
if (!(route instanceof Route)) {
|
|
1470
|
-
_context2.next =
|
|
1605
|
+
_context2.next = 10;
|
|
1471
1606
|
break;
|
|
1472
1607
|
}
|
|
1473
|
-
v2Trade = new Trade$
|
|
1608
|
+
v2Trade = new Trade$3(route, amount, tradeType);
|
|
1474
1609
|
inputAmount = v2Trade.inputAmount, outputAmount = v2Trade.outputAmount;
|
|
1475
1610
|
v2Routes = [{
|
|
1476
1611
|
routev2: route,
|
|
1477
1612
|
inputAmount: inputAmount,
|
|
1478
1613
|
outputAmount: outputAmount
|
|
1479
1614
|
}];
|
|
1480
|
-
_context2.next =
|
|
1615
|
+
_context2.next = 35;
|
|
1481
1616
|
break;
|
|
1482
|
-
case
|
|
1617
|
+
case 10:
|
|
1483
1618
|
if (!(route instanceof Route$1)) {
|
|
1484
|
-
_context2.next =
|
|
1619
|
+
_context2.next = 18;
|
|
1485
1620
|
break;
|
|
1486
1621
|
}
|
|
1487
|
-
_context2.next =
|
|
1488
|
-
return Trade$
|
|
1489
|
-
case
|
|
1622
|
+
_context2.next = 13;
|
|
1623
|
+
return Trade$2.fromRoute(route, amount, tradeType);
|
|
1624
|
+
case 13:
|
|
1490
1625
|
v3Trade = _context2.sent;
|
|
1491
|
-
|
|
1626
|
+
_inputAmount7 = v3Trade.inputAmount, _outputAmount7 = v3Trade.outputAmount;
|
|
1492
1627
|
v3Routes = [{
|
|
1493
1628
|
routev3: route,
|
|
1494
|
-
inputAmount:
|
|
1495
|
-
outputAmount:
|
|
1629
|
+
inputAmount: _inputAmount7,
|
|
1630
|
+
outputAmount: _outputAmount7
|
|
1496
1631
|
}];
|
|
1497
|
-
_context2.next =
|
|
1632
|
+
_context2.next = 35;
|
|
1498
1633
|
break;
|
|
1499
|
-
case
|
|
1634
|
+
case 18:
|
|
1635
|
+
if (!(route instanceof Route$2)) {
|
|
1636
|
+
_context2.next = 26;
|
|
1637
|
+
break;
|
|
1638
|
+
}
|
|
1639
|
+
_context2.next = 21;
|
|
1640
|
+
return Trade$1.fromRoute(route, amount, tradeType);
|
|
1641
|
+
case 21:
|
|
1642
|
+
v4Trade = _context2.sent;
|
|
1643
|
+
_inputAmount8 = v4Trade.inputAmount, _outputAmount8 = v4Trade.outputAmount;
|
|
1644
|
+
v4Routes = [{
|
|
1645
|
+
routev4: route,
|
|
1646
|
+
inputAmount: _inputAmount8,
|
|
1647
|
+
outputAmount: _outputAmount8
|
|
1648
|
+
}];
|
|
1649
|
+
_context2.next = 35;
|
|
1650
|
+
break;
|
|
1651
|
+
case 26:
|
|
1500
1652
|
if (!(route instanceof MixedRouteSDK)) {
|
|
1501
|
-
_context2.next =
|
|
1653
|
+
_context2.next = 34;
|
|
1502
1654
|
break;
|
|
1503
1655
|
}
|
|
1504
|
-
_context2.next =
|
|
1656
|
+
_context2.next = 29;
|
|
1505
1657
|
return MixedRouteTrade.fromRoute(route, amount, tradeType);
|
|
1506
|
-
case
|
|
1658
|
+
case 29:
|
|
1507
1659
|
mixedRouteTrade = _context2.sent;
|
|
1508
|
-
|
|
1660
|
+
_inputAmount9 = mixedRouteTrade.inputAmount, _outputAmount9 = mixedRouteTrade.outputAmount;
|
|
1509
1661
|
mixedRoutes = [{
|
|
1510
1662
|
mixedRoute: route,
|
|
1511
|
-
inputAmount:
|
|
1512
|
-
outputAmount:
|
|
1663
|
+
inputAmount: _inputAmount9,
|
|
1664
|
+
outputAmount: _outputAmount9
|
|
1513
1665
|
}];
|
|
1514
|
-
_context2.next =
|
|
1666
|
+
_context2.next = 35;
|
|
1515
1667
|
break;
|
|
1516
|
-
case
|
|
1668
|
+
case 34:
|
|
1517
1669
|
throw new Error('Invalid route type');
|
|
1518
|
-
case
|
|
1670
|
+
case 35:
|
|
1519
1671
|
return _context2.abrupt("return", new Trade({
|
|
1520
1672
|
v2Routes: v2Routes,
|
|
1521
1673
|
v3Routes: v3Routes,
|
|
1674
|
+
v4Routes: v4Routes,
|
|
1522
1675
|
mixedRoutes: mixedRoutes,
|
|
1523
1676
|
tradeType: tradeType
|
|
1524
1677
|
}));
|
|
1525
|
-
case
|
|
1678
|
+
case 36:
|
|
1526
1679
|
case "end":
|
|
1527
1680
|
return _context2.stop();
|
|
1528
1681
|
}
|
|
1529
1682
|
}, _callee2);
|
|
1530
1683
|
}));
|
|
1531
|
-
function fromRoute(
|
|
1684
|
+
function fromRoute(_x6, _x7, _x8) {
|
|
1532
1685
|
return _fromRoute.apply(this, arguments);
|
|
1533
1686
|
}
|
|
1534
1687
|
return fromRoute;
|
|
@@ -1609,10 +1762,10 @@ var Trade = /*#__PURE__*/function () {
|
|
|
1609
1762
|
// because we're unable to derive the pre-buy-tax amount, use 0% as a placeholder.
|
|
1610
1763
|
if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT;
|
|
1611
1764
|
var spotOutputAmount = CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
|
|
1612
|
-
for (var
|
|
1613
|
-
var
|
|
1614
|
-
route =
|
|
1615
|
-
inputAmount =
|
|
1765
|
+
for (var _iterator11 = _createForOfIteratorHelperLoose(this.swaps), _step11; !(_step11 = _iterator11()).done;) {
|
|
1766
|
+
var _step11$value = _step11.value,
|
|
1767
|
+
route = _step11$value.route,
|
|
1768
|
+
inputAmount = _step11$value.inputAmount;
|
|
1616
1769
|
var midPrice = route.midPrice;
|
|
1617
1770
|
var postTaxInputAmount = inputAmount.multiply(new Fraction(ONE).subtract(this.inputTax));
|
|
1618
1771
|
spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount));
|
|
@@ -1641,18 +1794,19 @@ function encodeMixedRouteToPath(route) {
|
|
|
1641
1794
|
var inputToken = _ref.inputToken,
|
|
1642
1795
|
path = _ref.path,
|
|
1643
1796
|
types = _ref.types;
|
|
1797
|
+
if (pool instanceof Pool) throw 'Encoding mixed routes with V4 not supported';
|
|
1644
1798
|
var outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
|
|
1645
1799
|
if (index === 0) {
|
|
1646
1800
|
return {
|
|
1647
1801
|
inputToken: outputToken,
|
|
1648
1802
|
types: ['address', 'uint24', 'address'],
|
|
1649
|
-
path: [inputToken.address, pool instanceof Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address]
|
|
1803
|
+
path: [inputToken.wrapped.address, pool instanceof Pool$1 ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.wrapped.address]
|
|
1650
1804
|
};
|
|
1651
1805
|
} else {
|
|
1652
1806
|
return {
|
|
1653
1807
|
inputToken: outputToken,
|
|
1654
1808
|
types: [].concat(types, ['uint24', 'address']),
|
|
1655
|
-
path: [].concat(path, [pool instanceof Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address])
|
|
1809
|
+
path: [].concat(path, [pool instanceof Pool$1 ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.wrapped.address])
|
|
1656
1810
|
};
|
|
1657
1811
|
}
|
|
1658
1812
|
}, {
|
|
@@ -1675,7 +1829,7 @@ var partitionMixedRouteByProtocol = function partitionMixedRouteByProtocol(route
|
|
|
1675
1829
|
var left = 0;
|
|
1676
1830
|
var right = 0;
|
|
1677
1831
|
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) {
|
|
1832
|
+
if (route.pools[left] instanceof Pool$1 && route.pools[right] instanceof Pair || route.pools[left] instanceof Pair && route.pools[right] instanceof Pool$1) {
|
|
1679
1833
|
acc.push(route.pools.slice(left, right));
|
|
1680
1834
|
left = right;
|
|
1681
1835
|
}
|
|
@@ -1826,6 +1980,9 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1826
1980
|
route = _step2$value.route,
|
|
1827
1981
|
inputAmount = _step2$value.inputAmount,
|
|
1828
1982
|
outputAmount = _step2$value.outputAmount;
|
|
1983
|
+
if (route.pools.some(function (pool) {
|
|
1984
|
+
return pool instanceof Pool;
|
|
1985
|
+
})) throw 'Encoding mixed routes with V4 not supported';
|
|
1829
1986
|
var amountIn = toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
|
|
1830
1987
|
var amountOut = toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
|
|
1831
1988
|
// flag for whether the trade is single hop or not
|
|
@@ -1833,7 +1990,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1833
1990
|
var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : validateAndParseAddress(options.recipient);
|
|
1834
1991
|
var mixedRouteIsAllV3 = function mixedRouteIsAllV3(route) {
|
|
1835
1992
|
return route.pools.every(function (pool) {
|
|
1836
|
-
return pool instanceof Pool;
|
|
1993
|
+
return pool instanceof Pool$1;
|
|
1837
1994
|
});
|
|
1838
1995
|
};
|
|
1839
1996
|
if (singleHop) {
|
|
@@ -1841,8 +1998,8 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1841
1998
|
/// We don't use encodeV3Swap() or encodeV2Swap() because casting the trade to a V3Trade or V2Trade is overcomplex
|
|
1842
1999
|
if (mixedRouteIsAllV3(route)) {
|
|
1843
2000
|
var exactInputSingleParams = {
|
|
1844
|
-
tokenIn: route.path[0].address,
|
|
1845
|
-
tokenOut: route.path[1].address,
|
|
2001
|
+
tokenIn: route.path[0].wrapped.address,
|
|
2002
|
+
tokenOut: route.path[1].wrapped.address,
|
|
1846
2003
|
fee: route.pools[0].fee,
|
|
1847
2004
|
recipient: recipient,
|
|
1848
2005
|
amountIn: amountIn,
|
|
@@ -1852,7 +2009,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1852
2009
|
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]));
|
|
1853
2010
|
} else {
|
|
1854
2011
|
var path = route.path.map(function (token) {
|
|
1855
|
-
return token.address;
|
|
2012
|
+
return token.wrapped.address;
|
|
1856
2013
|
});
|
|
1857
2014
|
var exactInputParams = [amountIn, performAggregatedSlippageCheck ? 0 : amountOut, path, recipient];
|
|
1858
2015
|
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams));
|
|
@@ -1871,7 +2028,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1871
2028
|
var newRouteOriginal = new MixedRouteSDK([].concat(section), section[0].token0.equals(inputToken) ? section[0].token0 : section[0].token1, outputToken);
|
|
1872
2029
|
var newRoute = new MixedRoute(newRouteOriginal);
|
|
1873
2030
|
/// Previous output is now input
|
|
1874
|
-
inputToken = outputToken;
|
|
2031
|
+
inputToken = outputToken.wrapped;
|
|
1875
2032
|
if (mixedRouteIsAllV3(newRoute)) {
|
|
1876
2033
|
var _path = encodeMixedRouteToPath(newRoute);
|
|
1877
2034
|
var _exactInputParams = {
|
|
@@ -1886,7 +2043,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1886
2043
|
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [_exactInputParams]));
|
|
1887
2044
|
} else {
|
|
1888
2045
|
var _exactInputParams2 = [i === 0 ? amountIn : 0, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (token) {
|
|
1889
|
-
return token.address;
|
|
2046
|
+
return token.wrapped.address;
|
|
1890
2047
|
}), isLastSectionInRoute(i) ? recipient : ADDRESS_THIS];
|
|
1891
2048
|
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', _exactInputParams2));
|
|
1892
2049
|
}
|
|
@@ -1903,7 +2060,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1903
2060
|
if (trades instanceof Trade) {
|
|
1904
2061
|
!trades.swaps.every(function (swap) {
|
|
1905
2062
|
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;
|
|
2063
|
+
}) ? process.env.NODE_ENV !== "production" ? invariant(false, 'UNSUPPORTED_PROTOCOL (encoding routes with v4 not supported)') : invariant(false) : void 0;
|
|
1907
2064
|
var individualTrades = [];
|
|
1908
2065
|
for (var _iterator3 = _createForOfIteratorHelperLoose(trades.swaps), _step3; !(_step3 = _iterator3()).done;) {
|
|
1909
2066
|
var _step3$value = _step3.value,
|
|
@@ -1911,9 +2068,9 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1911
2068
|
inputAmount = _step3$value.inputAmount,
|
|
1912
2069
|
outputAmount = _step3$value.outputAmount;
|
|
1913
2070
|
if (route.protocol === Protocol.V2) {
|
|
1914
|
-
individualTrades.push(new Trade$
|
|
2071
|
+
individualTrades.push(new Trade$3(route, trades.tradeType === TradeType.EXACT_INPUT ? inputAmount : outputAmount, trades.tradeType));
|
|
1915
2072
|
} else if (route.protocol === Protocol.V3) {
|
|
1916
|
-
individualTrades.push(Trade$
|
|
2073
|
+
individualTrades.push(Trade$2.createUncheckedTrade({
|
|
1917
2074
|
route: route,
|
|
1918
2075
|
inputAmount: inputAmount,
|
|
1919
2076
|
outputAmount: outputAmount,
|
|
@@ -1938,7 +2095,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1938
2095
|
trades = [trades];
|
|
1939
2096
|
}
|
|
1940
2097
|
var numberOfTrades = trades.reduce(function (numberOfTrades, trade) {
|
|
1941
|
-
return numberOfTrades + (trade instanceof Trade$
|
|
2098
|
+
return numberOfTrades + (trade instanceof Trade$2 || trade instanceof MixedRouteTrade ? trade.swaps.length : 1);
|
|
1942
2099
|
}, 0);
|
|
1943
2100
|
var sampleTrade = trades[0];
|
|
1944
2101
|
// All trades should have the same starting/ending currency and trade type
|
|
@@ -1972,9 +2129,9 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1972
2129
|
}
|
|
1973
2130
|
for (var _iterator4 = _createForOfIteratorHelperLoose(trades), _step4; !(_step4 = _iterator4()).done;) {
|
|
1974
2131
|
var trade = _step4.value;
|
|
1975
|
-
if (trade instanceof Trade$
|
|
2132
|
+
if (trade instanceof Trade$3) {
|
|
1976
2133
|
calldatas.push(SwapRouter.encodeV2Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck));
|
|
1977
|
-
} else if (trade instanceof Trade$
|
|
2134
|
+
} else if (trade instanceof Trade$2) {
|
|
1978
2135
|
for (var _iterator5 = _createForOfIteratorHelperLoose(SwapRouter.encodeV3Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck)), _step5; !(_step5 = _iterator5()).done;) {
|
|
1979
2136
|
var calldata = _step5.value;
|
|
1980
2137
|
calldatas.push(calldata);
|
|
@@ -2121,7 +2278,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
2121
2278
|
}
|
|
2122
2279
|
};
|
|
2123
2280
|
SwapRouter.v3TradeWithHighPriceImpact = function v3TradeWithHighPriceImpact(trade) {
|
|
2124
|
-
return !(trade instanceof Trade$
|
|
2281
|
+
return !(trade instanceof Trade$3) && trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
|
|
2125
2282
|
};
|
|
2126
2283
|
SwapRouter.getPositionAmounts = function getPositionAmounts(position, zeroForOne) {
|
|
2127
2284
|
var _position$mintAmounts = position.mintAmounts,
|
|
@@ -2141,5 +2298,5 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
2141
2298
|
}();
|
|
2142
2299
|
SwapRouter.INTERFACE = /*#__PURE__*/new Interface(abi$3);
|
|
2143
2300
|
|
|
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 };
|
|
2301
|
+
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
2302
|
//# sourceMappingURL=router-sdk.esm.js.map
|