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