@curvefi/api 2.18.1 → 2.19.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/lib/interfaces.d.ts +1 -0
- package/lib/pools/utils.d.ts +2 -0
- package/lib/pools/utils.js +38 -11
- package/lib/router.js +90 -84
- package/package.json +1 -1
package/lib/interfaces.d.ts
CHANGED
package/lib/pools/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IDict } from "../interfaces";
|
|
1
2
|
export declare const getPoolList: () => string[];
|
|
2
3
|
export declare const getFactoryPoolList: () => string[];
|
|
3
4
|
export declare const getCryptoFactoryPoolList: () => string[];
|
|
@@ -11,3 +12,4 @@ export declare const getUserClaimable: (pools: string[], address?: string) => Pr
|
|
|
11
12
|
price: number;
|
|
12
13
|
}[][]>;
|
|
13
14
|
export declare const getUserPoolList: (address?: string) => Promise<string[]>;
|
|
15
|
+
export declare const _getAmplificationCoefficientsFromApi: () => Promise<IDict<number>>;
|
package/lib/pools/utils.js
CHANGED
|
@@ -59,11 +59,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.getUserPoolList = exports.getUserClaimable = exports.getUserPoolListByClaimable = exports.getUserLiquidityUSD = exports.getUserPoolListByLiquidity = exports.getCryptoFactoryPoolList = exports.getFactoryPoolList = exports.getPoolList = void 0;
|
|
62
|
+
exports._getAmplificationCoefficientsFromApi = exports.getUserPoolList = exports.getUserClaimable = exports.getUserPoolListByClaimable = exports.getUserLiquidityUSD = exports.getUserPoolListByLiquidity = exports.getCryptoFactoryPoolList = exports.getFactoryPoolList = exports.getPoolList = void 0;
|
|
63
63
|
var ethers_1 = require("ethers");
|
|
64
64
|
var poolConstructor_1 = require("./poolConstructor");
|
|
65
65
|
var curve_1 = require("../curve");
|
|
66
66
|
var utils_1 = require("../utils");
|
|
67
|
+
var external_api_1 = require("../external-api");
|
|
67
68
|
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
68
69
|
var getPoolList = function () { return Object.keys(curve_1.curve.constants.POOLS_DATA); };
|
|
69
70
|
exports.getPoolList = getPoolList;
|
|
@@ -172,9 +173,8 @@ var _isUserClaimableCacheExpired = function (address, poolId) { var _a, _b; retu
|
|
|
172
173
|
var _getUserClaimable = function (pools, address, useCache) { return __awaiter(void 0, void 0, void 0, function () {
|
|
173
174
|
var poolsToFetch, hasCrvReward, _i, poolsToFetch_3, poolId, pool, gaugeContract, rewardCount, _a, poolsToFetch_4, poolId, pool, gaugeContract, rewardTokenCalls, i, pool, count, gaugeContract, rewardContract, rewardMulticallContract, method, rawRewardTokens, rewardTokens, i, j, rewardAddress, rewardInfoCalls, i, poolId, pool, gaugeContract, gaugeMulticallContract, _b, _c, token, tokenMulticallContract, rawRewardInfo, i, poolId, pool, gaugeContract, token, symbol, decimals, _amount, amount, _d, _e, token, symbol, decimals, _amount, _claimedAmount, amount, _claimable, _f, pools_2, poolId;
|
|
174
175
|
var _g;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
switch (_j.label) {
|
|
176
|
+
return __generator(this, function (_h) {
|
|
177
|
+
switch (_h.label) {
|
|
178
178
|
case 0:
|
|
179
179
|
poolsToFetch = useCache ? pools.filter(function (poolId) { return _isUserClaimableCacheExpired(address, poolId); }) : pools;
|
|
180
180
|
if (!(poolsToFetch.length > 0)) return [3 /*break*/, 3];
|
|
@@ -228,7 +228,7 @@ var _getUserClaimable = function (pools, address, useCache) { return __awaiter(v
|
|
|
228
228
|
}
|
|
229
229
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(rewardTokenCalls)];
|
|
230
230
|
case 1:
|
|
231
|
-
rawRewardTokens = (
|
|
231
|
+
rawRewardTokens = (_h.sent()).map(function (t) { return t.toLowerCase(); });
|
|
232
232
|
rewardTokens = {};
|
|
233
233
|
for (i = 0; i < poolsToFetch.length; i++) {
|
|
234
234
|
rewardTokens[poolsToFetch[i]] = [];
|
|
@@ -265,14 +265,13 @@ var _getUserClaimable = function (pools, address, useCache) { return __awaiter(v
|
|
|
265
265
|
}
|
|
266
266
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(rewardInfoCalls)];
|
|
267
267
|
case 2:
|
|
268
|
-
rawRewardInfo =
|
|
268
|
+
rawRewardInfo = _h.sent();
|
|
269
269
|
for (i = 0; i < poolsToFetch.length; i++) {
|
|
270
270
|
poolId = poolsToFetch[i];
|
|
271
271
|
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
272
272
|
if (!_userClaimableCache[address])
|
|
273
|
-
_userClaimableCache[address] =
|
|
274
|
-
|
|
275
|
-
_userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
|
|
273
|
+
_userClaimableCache[address] = {};
|
|
274
|
+
_userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
|
|
276
275
|
if (pool.gauge === ethers_1.ethers.constants.AddressZero)
|
|
277
276
|
continue;
|
|
278
277
|
gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
|
|
@@ -299,12 +298,12 @@ var _getUserClaimable = function (pools, address, useCache) { return __awaiter(v
|
|
|
299
298
|
_userClaimableCache[address][poolId].rewards.push({ token: token, symbol: symbol, amount: amount });
|
|
300
299
|
}
|
|
301
300
|
}
|
|
302
|
-
|
|
301
|
+
_h.label = 3;
|
|
303
302
|
case 3:
|
|
304
303
|
_claimable = [];
|
|
305
304
|
for (_f = 0, pools_2 = pools; _f < pools_2.length; _f++) {
|
|
306
305
|
poolId = pools_2[_f];
|
|
307
|
-
_claimable.push((
|
|
306
|
+
_claimable.push((_g = _userClaimableCache[address]) === null || _g === void 0 ? void 0 : _g[poolId].rewards);
|
|
308
307
|
}
|
|
309
308
|
return [2 /*return*/, _claimable];
|
|
310
309
|
}
|
|
@@ -396,3 +395,31 @@ var getUserPoolList = function (address) {
|
|
|
396
395
|
});
|
|
397
396
|
};
|
|
398
397
|
exports.getUserPoolList = getUserPoolList;
|
|
398
|
+
var _getAmplificationCoefficientsFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
399
|
+
var network, promises, allTypesExtendedPoolData, amplificationCoefficientDict, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool;
|
|
400
|
+
return __generator(this, function (_c) {
|
|
401
|
+
switch (_c.label) {
|
|
402
|
+
case 0:
|
|
403
|
+
network = curve_1.curve.constants.NETWORK_NAME;
|
|
404
|
+
promises = [
|
|
405
|
+
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
406
|
+
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
407
|
+
(0, external_api_1._getPoolsFromApi)(network, "factory"),
|
|
408
|
+
(0, external_api_1._getPoolsFromApi)(network, "factory-crypto"),
|
|
409
|
+
];
|
|
410
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
411
|
+
case 1:
|
|
412
|
+
allTypesExtendedPoolData = _c.sent();
|
|
413
|
+
amplificationCoefficientDict = {};
|
|
414
|
+
for (_i = 0, allTypesExtendedPoolData_1 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_1.length; _i++) {
|
|
415
|
+
extendedPoolData = allTypesExtendedPoolData_1[_i];
|
|
416
|
+
for (_a = 0, _b = extendedPoolData.poolData; _a < _b.length; _a++) {
|
|
417
|
+
pool = _b[_a];
|
|
418
|
+
amplificationCoefficientDict[pool.address] = Number(pool.amplificationCoefficient);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return [2 /*return*/, amplificationCoefficientDict];
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}); };
|
|
425
|
+
exports._getAmplificationCoefficientsFromApi = _getAmplificationCoefficientsFromApi;
|
package/lib/router.js
CHANGED
|
@@ -66,7 +66,9 @@ var ethers_1 = require("ethers");
|
|
|
66
66
|
var curve_1 = require("./curve");
|
|
67
67
|
var utils_1 = require("./utils");
|
|
68
68
|
var pools_1 = require("./pools");
|
|
69
|
+
var utils_2 = require("./pools/utils");
|
|
69
70
|
var MAX_ROUTES_FOR_ONE_COIN = 3;
|
|
71
|
+
var MIN_TVL_THRESHOLD = 5000000;
|
|
70
72
|
// Inspired by Dijkstra's algorithm
|
|
71
73
|
var _findAllRoutesTheShorterTheBetter = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
74
|
var ALL_POOLS, basePoolsSet, _i, ALL_POOLS_1, pool, basePoolIds, markedCoins, curCoins, nextCoins, routes, step, _a, curCoins_1, inCoin, _b, ALL_POOLS_2, _c, poolId, poolData, wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address, is_lending, inCoinIndexes, j, swapType, _d, _e, inCoinRoute, swapType, _f, _h, inCoinRoute, j, tvl, _j, swapType, _k, _l, inCoinRoute, poolAddress, j, tvl, _m, hasEth, swapType, _o, _p, inCoinRoute;
|
|
@@ -81,8 +83,8 @@ var _findAllRoutesTheShorterTheBetter = function (inputCoinAddress, outputCoinAd
|
|
|
81
83
|
basePoolsSet = new Set();
|
|
82
84
|
for (_i = 0, ALL_POOLS_1 = ALL_POOLS; _i < ALL_POOLS_1.length; _i++) {
|
|
83
85
|
pool = ALL_POOLS_1[_i];
|
|
84
|
-
if (pool[1].
|
|
85
|
-
basePoolsSet.add(pool[
|
|
86
|
+
if (pool[1].wrapped_coin_addresses.length < 4)
|
|
87
|
+
basePoolsSet.add(pool[0]);
|
|
86
88
|
}
|
|
87
89
|
basePoolIds = Array.from(basePoolsSet);
|
|
88
90
|
markedCoins = [];
|
|
@@ -116,24 +118,24 @@ var _findAllRoutesTheShorterTheBetter = function (inputCoinAddress, outputCoinAd
|
|
|
116
118
|
underlying_coin: underlying_coin_addresses.indexOf(inCoin),
|
|
117
119
|
meta_coin: meta_coin_addresses ? meta_coin_addresses.indexOf(inCoin) : -1,
|
|
118
120
|
};
|
|
119
|
-
// LP ->
|
|
121
|
+
// LP -> wrapped coin "swaps" (actually remove_liquidity_one_coin)
|
|
120
122
|
if (basePoolIds.includes(poolId) && inCoin === token_address) {
|
|
121
|
-
for (j = 0; j <
|
|
123
|
+
for (j = 0; j < wrapped_coin_addresses.length; j++) {
|
|
122
124
|
// If this coin already marked or will be marked on the current step, no need to consider it on the next step
|
|
123
|
-
if (markedCoins.includes(
|
|
125
|
+
if (markedCoins.includes(wrapped_coin_addresses[j]) || curCoins.includes(wrapped_coin_addresses[j]))
|
|
124
126
|
continue;
|
|
125
127
|
// Looking for outputCoinAddress only on the final step
|
|
126
|
-
if (step === 3 &&
|
|
128
|
+
if (step === 3 && wrapped_coin_addresses[j] !== outputCoinAddress)
|
|
127
129
|
continue;
|
|
128
130
|
swapType = poolId === 'aave' ? 11 : 10;
|
|
129
131
|
for (_d = 0, _e = routes[inCoin]; _d < _e.length; _d++) {
|
|
130
132
|
inCoinRoute = _e[_d];
|
|
131
|
-
routes[
|
|
133
|
+
routes[wrapped_coin_addresses[j]] = ((_s = routes[wrapped_coin_addresses[j]]) !== null && _s !== void 0 ? _s : []).concat([__spreadArray(__spreadArray([], inCoinRoute, true), [
|
|
132
134
|
{
|
|
133
135
|
poolId: poolId,
|
|
134
136
|
poolAddress: poolData.swap_address,
|
|
135
137
|
inputCoinAddress: inCoin,
|
|
136
|
-
outputCoinAddress:
|
|
138
|
+
outputCoinAddress: wrapped_coin_addresses[j],
|
|
137
139
|
i: 0,
|
|
138
140
|
j: j,
|
|
139
141
|
swapType: swapType,
|
|
@@ -141,18 +143,18 @@ var _findAllRoutesTheShorterTheBetter = function (inputCoinAddress, outputCoinAd
|
|
|
141
143
|
},
|
|
142
144
|
], false)]);
|
|
143
145
|
}
|
|
144
|
-
nextCoins.add(
|
|
146
|
+
nextCoins.add(wrapped_coin_addresses[j]);
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
|
-
//
|
|
148
|
-
if (basePoolIds.includes(poolId) &&
|
|
149
|
+
// Wrapped coin -> LP "swaps" (actually add_liquidity)
|
|
150
|
+
if (basePoolIds.includes(poolId) && wrapped_coin_addresses.includes(inCoin)) {
|
|
149
151
|
// If this coin already marked or will be marked on the current step, no need to consider it on the next step
|
|
150
152
|
if (markedCoins.includes(token_address) || curCoins.includes(token_address))
|
|
151
153
|
return [3 /*break*/, 11];
|
|
152
154
|
// Looking for outputCoinAddress only on the final step
|
|
153
155
|
if (step === 3 && token_address !== outputCoinAddress)
|
|
154
156
|
return [3 /*break*/, 11];
|
|
155
|
-
swapType = is_lending ? 9 :
|
|
157
|
+
swapType = is_lending ? 9 : wrapped_coin_addresses.length === 2 ? 7 : 8;
|
|
156
158
|
for (_f = 0, _h = routes[inCoin]; _f < _h.length; _f++) {
|
|
157
159
|
inCoinRoute = _h[_f];
|
|
158
160
|
routes[token_address] = ((_t = routes[token_address]) !== null && _t !== void 0 ? _t : []).concat([__spreadArray(__spreadArray([], inCoinRoute, true), [
|
|
@@ -161,7 +163,7 @@ var _findAllRoutesTheShorterTheBetter = function (inputCoinAddress, outputCoinAd
|
|
|
161
163
|
poolAddress: poolData.swap_address,
|
|
162
164
|
inputCoinAddress: inCoin,
|
|
163
165
|
outputCoinAddress: token_address,
|
|
164
|
-
i:
|
|
166
|
+
i: wrapped_coin_addresses.indexOf(inCoin),
|
|
165
167
|
j: 0,
|
|
166
168
|
swapType: swapType,
|
|
167
169
|
swapAddress: ethers_1.ethers.constants.AddressZero,
|
|
@@ -287,15 +289,18 @@ var _findAllRoutesTheShorterTheBetter = function (inputCoinAddress, outputCoinAd
|
|
|
287
289
|
exports._findAllRoutesTheShorterTheBetter = _findAllRoutesTheShorterTheBetter;
|
|
288
290
|
// Inspired by Dijkstra's algorithm
|
|
289
291
|
var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
290
|
-
var ALL_POOLS, basePoolsSet, _i, ALL_POOLS_3, pool, basePoolIds, curCoins, nextCoins, routes, step, _loop_1, _a, curCoins_2, inCoin;
|
|
292
|
+
var ALL_POOLS, amplificationCoefficientDict, basePoolsSet, _i, ALL_POOLS_3, pool, basePoolIds, curCoins, nextCoins, routes, step, _loop_1, _a, curCoins_2, inCoin;
|
|
291
293
|
var _b;
|
|
292
|
-
var _c, _d, _e, _f, _h;
|
|
293
|
-
return __generator(this, function (
|
|
294
|
-
switch (
|
|
294
|
+
var _c, _d, _e, _f, _h, _j;
|
|
295
|
+
return __generator(this, function (_k) {
|
|
296
|
+
switch (_k.label) {
|
|
295
297
|
case 0:
|
|
296
298
|
inputCoinAddress = inputCoinAddress.toLowerCase();
|
|
297
299
|
outputCoinAddress = outputCoinAddress.toLowerCase();
|
|
298
300
|
ALL_POOLS = Object.entries(__assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA));
|
|
301
|
+
return [4 /*yield*/, (0, utils_2._getAmplificationCoefficientsFromApi)()];
|
|
302
|
+
case 1:
|
|
303
|
+
amplificationCoefficientDict = _k.sent();
|
|
299
304
|
basePoolsSet = new Set();
|
|
300
305
|
for (_i = 0, ALL_POOLS_3 = ALL_POOLS; _i < ALL_POOLS_3.length; _i++) {
|
|
301
306
|
pool = ALL_POOLS_3[_i];
|
|
@@ -309,18 +314,18 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
309
314
|
_b[inputCoinAddress] = [{ steps: [], minTvl: Infinity }],
|
|
310
315
|
_b);
|
|
311
316
|
step = 0;
|
|
312
|
-
|
|
313
|
-
case
|
|
314
|
-
if (!(step < 4)) return [3 /*break*/,
|
|
317
|
+
_k.label = 2;
|
|
318
|
+
case 2:
|
|
319
|
+
if (!(step < 4)) return [3 /*break*/, 8];
|
|
315
320
|
_loop_1 = function (inCoin) {
|
|
316
|
-
var _loop_2,
|
|
317
|
-
return __generator(this, function (
|
|
318
|
-
switch (
|
|
321
|
+
var _loop_2, _l, ALL_POOLS_4, _m, poolId, poolData;
|
|
322
|
+
return __generator(this, function (_o) {
|
|
323
|
+
switch (_o.label) {
|
|
319
324
|
case 0:
|
|
320
325
|
_loop_2 = function (poolId, poolData) {
|
|
321
|
-
var wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address, is_lending, inCoinIndexes, _loop_3, j, tvl_1,
|
|
322
|
-
return __generator(this, function (
|
|
323
|
-
switch (
|
|
326
|
+
var wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address, is_lending, minTvlMultiplier, inCoinIndexes, _loop_3, j, tvl_1, _p, swapType_1, newRoutes, routesByPoolIds_1, _loop_4, j, poolAddress, _loop_5, j;
|
|
327
|
+
return __generator(this, function (_q) {
|
|
328
|
+
switch (_q.label) {
|
|
324
329
|
case 0:
|
|
325
330
|
wrapped_coin_addresses = poolData.wrapped_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
326
331
|
underlying_coin_addresses = poolData.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
@@ -328,6 +333,7 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
328
333
|
meta_coin_addresses = base_pool ? base_pool.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); }) : [];
|
|
329
334
|
token_address = poolData.token_address.toLowerCase();
|
|
330
335
|
is_lending = (_c = poolData.is_lending) !== null && _c !== void 0 ? _c : false;
|
|
336
|
+
minTvlMultiplier = poolData.is_crypto ? 1 : ((_d = amplificationCoefficientDict[poolData.swap_address]) !== null && _d !== void 0 ? _d : 1);
|
|
331
337
|
inCoinIndexes = {
|
|
332
338
|
wrapped_coin: wrapped_coin_addresses.indexOf(inCoin),
|
|
333
339
|
underlying_coin: underlying_coin_addresses.indexOf(inCoin),
|
|
@@ -338,9 +344,9 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
338
344
|
return [2 /*return*/, "continue"];
|
|
339
345
|
if (!(basePoolIds.includes(poolId) && inCoin === token_address)) return [3 /*break*/, 4];
|
|
340
346
|
_loop_3 = function (j) {
|
|
341
|
-
var outputCoinIdx, tvl,
|
|
342
|
-
return __generator(this, function (
|
|
343
|
-
switch (
|
|
347
|
+
var outputCoinIdx, tvl, _r, swapType, newRoutes, routesByPoolIds;
|
|
348
|
+
return __generator(this, function (_s) {
|
|
349
|
+
switch (_s.label) {
|
|
344
350
|
case 0:
|
|
345
351
|
// Looking for outputCoinAddress only on the final step
|
|
346
352
|
if (step === 3 && underlying_coin_addresses[j] !== outputCoinAddress)
|
|
@@ -348,10 +354,10 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
348
354
|
outputCoinIdx = underlying_coin_addresses.indexOf(outputCoinAddress);
|
|
349
355
|
if (outputCoinIdx >= 0 && j !== outputCoinIdx)
|
|
350
356
|
return [2 /*return*/, "continue"];
|
|
351
|
-
|
|
357
|
+
_r = Number;
|
|
352
358
|
return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
|
|
353
359
|
case 1:
|
|
354
|
-
tvl =
|
|
360
|
+
tvl = _r.apply(void 0, [_s.sent()]);
|
|
355
361
|
swapType = poolId === 'aave' ? 11 : 10;
|
|
356
362
|
newRoutes = routes[inCoin].map(function (route) {
|
|
357
363
|
var routePoolIds = route.steps.map(function (s) { return s.poolId; });
|
|
@@ -374,29 +380,29 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
374
380
|
swapAddress: ethers_1.ethers.constants.AddressZero,
|
|
375
381
|
},
|
|
376
382
|
], false),
|
|
377
|
-
minTvl: Math.min(tvl, route.minTvl),
|
|
383
|
+
minTvl: Math.min(tvl, route.minTvl * minTvlMultiplier),
|
|
378
384
|
};
|
|
379
385
|
});
|
|
380
|
-
routes[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((
|
|
386
|
+
routes[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_e = routes[underlying_coin_addresses[j]]) !== null && _e !== void 0 ? _e : []), true), newRoutes, true);
|
|
381
387
|
routesByPoolIds = routes[underlying_coin_addresses[j]].map(function (r) { return r.steps.map(function (s) { return s.poolId; }).toString(); });
|
|
382
388
|
routes[underlying_coin_addresses[j]] = routes[underlying_coin_addresses[j]]
|
|
383
389
|
.filter(function (r) { return r.steps.length > 0; })
|
|
384
390
|
.filter(function (r) { return r.steps[0].inputCoinAddress === inputCoinAddress; }) // Truncated routes
|
|
385
391
|
.filter(function (r, i) { return routesByPoolIds.indexOf(r.steps.map(function (s) { return s.poolId; }).toString()) === i; }) // Route duplications
|
|
386
|
-
.sort(function (a, b) { return b.minTvl - a.minTvl || a.steps.length - b.steps.length; }).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
392
|
+
.sort(function (a, b) { return Math.min(b.minTvl, MIN_TVL_THRESHOLD) - Math.min(a.minTvl, MIN_TVL_THRESHOLD) || a.steps.length - b.steps.length; }).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
387
393
|
nextCoins.add(underlying_coin_addresses[j]);
|
|
388
394
|
return [2 /*return*/];
|
|
389
395
|
}
|
|
390
396
|
});
|
|
391
397
|
};
|
|
392
398
|
j = 0;
|
|
393
|
-
|
|
399
|
+
_q.label = 1;
|
|
394
400
|
case 1:
|
|
395
401
|
if (!(j < underlying_coin_addresses.length)) return [3 /*break*/, 4];
|
|
396
402
|
return [5 /*yield**/, _loop_3(j)];
|
|
397
403
|
case 2:
|
|
398
|
-
|
|
399
|
-
|
|
404
|
+
_q.sent();
|
|
405
|
+
_q.label = 3;
|
|
400
406
|
case 3:
|
|
401
407
|
j++;
|
|
402
408
|
return [3 /*break*/, 1];
|
|
@@ -405,10 +411,10 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
405
411
|
// Looking for outputCoinAddress only on the final step
|
|
406
412
|
if (step === 3 && token_address !== outputCoinAddress)
|
|
407
413
|
return [2 /*return*/, "continue"];
|
|
408
|
-
|
|
414
|
+
_p = Number;
|
|
409
415
|
return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
|
|
410
416
|
case 5:
|
|
411
|
-
tvl_1 =
|
|
417
|
+
tvl_1 = _p.apply(void 0, [_q.sent()]);
|
|
412
418
|
swapType_1 = is_lending ? 9 : underlying_coin_addresses.length === 2 ? 7 : 8;
|
|
413
419
|
newRoutes = routes[inCoin].map(function (route) {
|
|
414
420
|
var routePoolIds = route.steps.map(function (s) { return s.poolId; });
|
|
@@ -431,24 +437,24 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
431
437
|
swapAddress: ethers_1.ethers.constants.AddressZero,
|
|
432
438
|
},
|
|
433
439
|
], false),
|
|
434
|
-
minTvl: Math.min(tvl_1, route.minTvl),
|
|
440
|
+
minTvl: Math.min(tvl_1, route.minTvl * minTvlMultiplier),
|
|
435
441
|
};
|
|
436
442
|
});
|
|
437
|
-
routes[token_address] = __spreadArray(__spreadArray([], ((
|
|
443
|
+
routes[token_address] = __spreadArray(__spreadArray([], ((_f = routes[token_address]) !== null && _f !== void 0 ? _f : []), true), newRoutes, true);
|
|
438
444
|
routesByPoolIds_1 = routes[token_address].map(function (r) { return r.steps.map(function (s) { return s.poolId; }).toString(); });
|
|
439
445
|
routes[token_address] = routes[token_address]
|
|
440
446
|
.filter(function (r) { return r.steps.length > 0; })
|
|
441
447
|
.filter(function (r) { return r.steps[0].inputCoinAddress === inputCoinAddress; }) // Truncated routes
|
|
442
448
|
.filter(function (r, i) { return routesByPoolIds_1.indexOf(r.steps.map(function (s) { return s.poolId; }).toString()) === i; }) // Route duplications
|
|
443
|
-
.sort(function (a, b) { return b.minTvl - a.minTvl || a.steps.length - b.steps.length; }).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
449
|
+
.sort(function (a, b) { return Math.min(b.minTvl, MIN_TVL_THRESHOLD) - Math.min(a.minTvl, MIN_TVL_THRESHOLD) || a.steps.length - b.steps.length; }).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
444
450
|
nextCoins.add(token_address);
|
|
445
|
-
|
|
451
|
+
_q.label = 6;
|
|
446
452
|
case 6:
|
|
447
453
|
if (!(inCoinIndexes.wrapped_coin >= 0 && !poolData.is_fake)) return [3 /*break*/, 10];
|
|
448
454
|
_loop_4 = function (j) {
|
|
449
|
-
var outputCoinIdx, tvl,
|
|
450
|
-
return __generator(this, function (
|
|
451
|
-
switch (
|
|
455
|
+
var outputCoinIdx, tvl, _t, swapType, newRoutes, routesByPoolIds;
|
|
456
|
+
return __generator(this, function (_u) {
|
|
457
|
+
switch (_u.label) {
|
|
452
458
|
case 0:
|
|
453
459
|
if (j === inCoinIndexes.wrapped_coin)
|
|
454
460
|
return [2 /*return*/, "continue"];
|
|
@@ -461,10 +467,10 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
461
467
|
outputCoinIdx = wrapped_coin_addresses.indexOf(outputCoinAddress);
|
|
462
468
|
if (outputCoinIdx >= 0 && j !== outputCoinIdx)
|
|
463
469
|
return [2 /*return*/, "continue"];
|
|
464
|
-
|
|
470
|
+
_t = Number;
|
|
465
471
|
return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
|
|
466
472
|
case 1:
|
|
467
|
-
tvl =
|
|
473
|
+
tvl = _t.apply(void 0, [_u.sent()]);
|
|
468
474
|
// Skip empty pools
|
|
469
475
|
if (tvl === 0)
|
|
470
476
|
return [2 /*return*/, "continue"];
|
|
@@ -490,29 +496,29 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
490
496
|
swapAddress: ethers_1.ethers.constants.AddressZero,
|
|
491
497
|
},
|
|
492
498
|
], false),
|
|
493
|
-
minTvl: Math.min(tvl, route.minTvl),
|
|
499
|
+
minTvl: Math.min(tvl, route.minTvl * minTvlMultiplier),
|
|
494
500
|
};
|
|
495
501
|
});
|
|
496
|
-
routes[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((
|
|
502
|
+
routes[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_h = routes[wrapped_coin_addresses[j]]) !== null && _h !== void 0 ? _h : []), true), newRoutes, true);
|
|
497
503
|
routesByPoolIds = routes[wrapped_coin_addresses[j]].map(function (r) { return r.steps.map(function (s) { return s.poolId; }).toString(); });
|
|
498
504
|
routes[wrapped_coin_addresses[j]] = routes[wrapped_coin_addresses[j]]
|
|
499
505
|
.filter(function (r) { return r.steps.length > 0; })
|
|
500
506
|
.filter(function (r) { return r.steps[0].inputCoinAddress === inputCoinAddress; }) // Truncated routes
|
|
501
507
|
.filter(function (r, i) { return routesByPoolIds.indexOf(r.steps.map(function (s) { return s.poolId; }).toString()) === i; }) // Route duplications
|
|
502
|
-
.sort(function (a, b) { return b.minTvl - a.minTvl || a.steps.length - b.steps.length; }).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
508
|
+
.sort(function (a, b) { return Math.min(b.minTvl, MIN_TVL_THRESHOLD) - Math.min(a.minTvl, MIN_TVL_THRESHOLD) || a.steps.length - b.steps.length; }).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
503
509
|
nextCoins.add(wrapped_coin_addresses[j]);
|
|
504
510
|
return [2 /*return*/];
|
|
505
511
|
}
|
|
506
512
|
});
|
|
507
513
|
};
|
|
508
514
|
j = 0;
|
|
509
|
-
|
|
515
|
+
_q.label = 7;
|
|
510
516
|
case 7:
|
|
511
517
|
if (!(j < wrapped_coin_addresses.length)) return [3 /*break*/, 10];
|
|
512
518
|
return [5 /*yield**/, _loop_4(j)];
|
|
513
519
|
case 8:
|
|
514
|
-
|
|
515
|
-
|
|
520
|
+
_q.sent();
|
|
521
|
+
_q.label = 9;
|
|
516
522
|
case 9:
|
|
517
523
|
j++;
|
|
518
524
|
return [3 /*break*/, 7];
|
|
@@ -521,9 +527,9 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
521
527
|
poolData.deposit_address : poolData.swap_address;
|
|
522
528
|
if (!(!poolData.is_plain && inCoinIndexes.underlying_coin >= 0)) return [3 /*break*/, 14];
|
|
523
529
|
_loop_5 = function (j) {
|
|
524
|
-
var outputCoinIdx, tvl,
|
|
525
|
-
return __generator(this, function (
|
|
526
|
-
switch (
|
|
530
|
+
var outputCoinIdx, tvl, _v, hasEth, swapType, newRoutes, routesByPoolIds;
|
|
531
|
+
return __generator(this, function (_w) {
|
|
532
|
+
switch (_w.label) {
|
|
527
533
|
case 0:
|
|
528
534
|
if (j === inCoinIndexes.underlying_coin)
|
|
529
535
|
return [2 /*return*/, "continue"];
|
|
@@ -536,10 +542,10 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
536
542
|
outputCoinIdx = underlying_coin_addresses.indexOf(outputCoinAddress);
|
|
537
543
|
if (outputCoinIdx >= 0 && j !== outputCoinIdx)
|
|
538
544
|
return [2 /*return*/, "continue"];
|
|
539
|
-
|
|
545
|
+
_v = Number;
|
|
540
546
|
return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
|
|
541
547
|
case 1:
|
|
542
|
-
tvl =
|
|
548
|
+
tvl = _v.apply(void 0, [_w.sent()]);
|
|
543
549
|
if (tvl === 0)
|
|
544
550
|
return [2 /*return*/, "continue"];
|
|
545
551
|
hasEth = (inCoin === curve_1.curve.constants.NATIVE_TOKEN.address || underlying_coin_addresses[j] === curve_1.curve.constants.NATIVE_TOKEN.address);
|
|
@@ -569,29 +575,29 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
569
575
|
swapAddress: (swapType === 5 || swapType === 6) ? poolData.swap_address : ethers_1.ethers.constants.AddressZero,
|
|
570
576
|
},
|
|
571
577
|
], false),
|
|
572
|
-
minTvl: Math.min(tvl, route.minTvl),
|
|
578
|
+
minTvl: Math.min(tvl, route.minTvl * minTvlMultiplier),
|
|
573
579
|
};
|
|
574
580
|
});
|
|
575
|
-
routes[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((
|
|
581
|
+
routes[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_j = routes[underlying_coin_addresses[j]]) !== null && _j !== void 0 ? _j : []), true), newRoutes, true);
|
|
576
582
|
routesByPoolIds = routes[underlying_coin_addresses[j]].map(function (r) { return r.steps.map(function (s) { return s.poolId; }).toString(); });
|
|
577
583
|
routes[underlying_coin_addresses[j]] = routes[underlying_coin_addresses[j]]
|
|
578
584
|
.filter(function (r) { return r.steps.length > 0; })
|
|
579
585
|
.filter(function (r) { return r.steps[0].inputCoinAddress === inputCoinAddress; }) // Truncated routes
|
|
580
586
|
.filter(function (r, i) { return routesByPoolIds.indexOf(r.steps.map(function (s) { return s.poolId; }).toString()) === i; }) // Route duplications
|
|
581
|
-
.sort(function (a, b) { return b.minTvl - a.minTvl || a.steps.length - b.steps.length; }).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
587
|
+
.sort(function (a, b) { return Math.min(b.minTvl, MIN_TVL_THRESHOLD) - Math.min(a.minTvl, MIN_TVL_THRESHOLD) || a.steps.length - b.steps.length; }).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
582
588
|
nextCoins.add(underlying_coin_addresses[j]);
|
|
583
589
|
return [2 /*return*/];
|
|
584
590
|
}
|
|
585
591
|
});
|
|
586
592
|
};
|
|
587
593
|
j = 0;
|
|
588
|
-
|
|
594
|
+
_q.label = 11;
|
|
589
595
|
case 11:
|
|
590
596
|
if (!(j < underlying_coin_addresses.length)) return [3 /*break*/, 14];
|
|
591
597
|
return [5 /*yield**/, _loop_5(j)];
|
|
592
598
|
case 12:
|
|
593
|
-
|
|
594
|
-
|
|
599
|
+
_q.sent();
|
|
600
|
+
_q.label = 13;
|
|
595
601
|
case 13:
|
|
596
602
|
j++;
|
|
597
603
|
return [3 /*break*/, 11];
|
|
@@ -599,42 +605,42 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
599
605
|
}
|
|
600
606
|
});
|
|
601
607
|
};
|
|
602
|
-
|
|
603
|
-
|
|
608
|
+
_l = 0, ALL_POOLS_4 = ALL_POOLS;
|
|
609
|
+
_o.label = 1;
|
|
604
610
|
case 1:
|
|
605
|
-
if (!(
|
|
606
|
-
|
|
611
|
+
if (!(_l < ALL_POOLS_4.length)) return [3 /*break*/, 4];
|
|
612
|
+
_m = ALL_POOLS_4[_l], poolId = _m[0], poolData = _m[1];
|
|
607
613
|
return [5 /*yield**/, _loop_2(poolId, poolData)];
|
|
608
614
|
case 2:
|
|
609
|
-
|
|
610
|
-
|
|
615
|
+
_o.sent();
|
|
616
|
+
_o.label = 3;
|
|
611
617
|
case 3:
|
|
612
|
-
|
|
618
|
+
_l++;
|
|
613
619
|
return [3 /*break*/, 1];
|
|
614
620
|
case 4: return [2 /*return*/];
|
|
615
621
|
}
|
|
616
622
|
});
|
|
617
623
|
};
|
|
618
624
|
_a = 0, curCoins_2 = curCoins;
|
|
619
|
-
|
|
620
|
-
case
|
|
621
|
-
if (!(_a < curCoins_2.length)) return [3 /*break*/,
|
|
625
|
+
_k.label = 3;
|
|
626
|
+
case 3:
|
|
627
|
+
if (!(_a < curCoins_2.length)) return [3 /*break*/, 6];
|
|
622
628
|
inCoin = curCoins_2[_a];
|
|
623
629
|
return [5 /*yield**/, _loop_1(inCoin)];
|
|
624
|
-
case 3:
|
|
625
|
-
_j.sent();
|
|
626
|
-
_j.label = 4;
|
|
627
630
|
case 4:
|
|
628
|
-
|
|
629
|
-
|
|
631
|
+
_k.sent();
|
|
632
|
+
_k.label = 5;
|
|
630
633
|
case 5:
|
|
634
|
+
_a++;
|
|
635
|
+
return [3 /*break*/, 3];
|
|
636
|
+
case 6:
|
|
631
637
|
curCoins = Array.from(nextCoins);
|
|
632
638
|
nextCoins = new Set();
|
|
633
|
-
|
|
634
|
-
case
|
|
639
|
+
_k.label = 7;
|
|
640
|
+
case 7:
|
|
635
641
|
step++;
|
|
636
|
-
return [3 /*break*/,
|
|
637
|
-
case
|
|
642
|
+
return [3 /*break*/, 2];
|
|
643
|
+
case 8: return [2 /*return*/, routes[outputCoinAddress] ? routes[outputCoinAddress].map(function (r) { return r.steps; }) : []];
|
|
638
644
|
}
|
|
639
645
|
});
|
|
640
646
|
}); };
|