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