@curvefi/api 2.23.0 → 2.24.1
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/constants/abis/factory-v2/MetaSbtc2.json +1011 -0
- package/lib/constants/abis/factory-v2/MetaSbtc2Balance.json +1024 -0
- package/lib/constants/abis/sbtc2/meta_zap.json +164 -0
- package/lib/constants/abis/sbtc2/swap.json +829 -0
- package/lib/constants/pools/ethereum.js +25 -0
- package/lib/factory/constants.js +49 -38
- package/lib/factory/factory-api.d.ts +2 -1
- package/lib/factory/factory-api.js +55 -31
- package/lib/factory/factory.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/interfaces.d.ts +1 -0
- package/lib/pools/PoolTemplate.d.ts +2 -2
- package/lib/pools/PoolTemplate.js +69 -59
- package/lib/router.js +48 -48
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +32 -1
- package/package.json +1 -1
|
@@ -279,64 +279,74 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
279
279
|
}
|
|
280
280
|
});
|
|
281
281
|
}); };
|
|
282
|
-
this.statsTokenApy = function () {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return [
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
]
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
282
|
+
this.statsTokenApy = function (useApi) {
|
|
283
|
+
if (useApi === void 0) { useApi = true; }
|
|
284
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
285
|
+
var crvAPYs, poolCrvApy, totalLiquidityUSD, inflationRateBN, workingSupplyBN, totalSupplyBN, gaugeContract, lpTokenContract, crvContract, currentWeek, _c, gaugeContract, lpTokenContract, gaugeControllerContract, weightBN, rateBN, crvPrice, baseApyBN, boostedApyBN;
|
|
286
|
+
var _d, _e;
|
|
287
|
+
var _f;
|
|
288
|
+
return __generator(this, function (_g) {
|
|
289
|
+
switch (_g.label) {
|
|
290
|
+
case 0:
|
|
291
|
+
if (this.rewardsOnly())
|
|
292
|
+
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use getRewardsApy instead"));
|
|
293
|
+
if (!(useApi && curve_1.curve.chainId === 1)) return [3 /*break*/, 2];
|
|
294
|
+
return [4 /*yield*/, (0, utils_1._getCrvApyFromApi)()];
|
|
295
|
+
case 1:
|
|
296
|
+
crvAPYs = _g.sent();
|
|
297
|
+
poolCrvApy = (_f = crvAPYs[this.gauge]) !== null && _f !== void 0 ? _f : [0, 0];
|
|
298
|
+
return [2 /*return*/, [poolCrvApy[0], poolCrvApy[1]]];
|
|
299
|
+
case 2: return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
300
|
+
case 3:
|
|
301
|
+
totalLiquidityUSD = _g.sent();
|
|
302
|
+
if (Number(totalLiquidityUSD) === 0)
|
|
303
|
+
return [2 /*return*/, [0, 0]];
|
|
304
|
+
if (!(curve_1.curve.chainId !== 1)) return [3 /*break*/, 7];
|
|
305
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
306
|
+
lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
307
|
+
crvContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.crv].contract;
|
|
308
|
+
currentWeek = Math.floor(Date.now() / 1000 / WEEK);
|
|
309
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
310
|
+
gaugeContract.inflation_rate(currentWeek),
|
|
311
|
+
gaugeContract.working_supply(),
|
|
312
|
+
lpTokenContract.totalSupply(),
|
|
313
|
+
])];
|
|
314
|
+
case 4:
|
|
315
|
+
_d = (_g.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _d[0], workingSupplyBN = _d[1], totalSupplyBN = _d[2];
|
|
316
|
+
if (!inflationRateBN.eq(0)) return [3 /*break*/, 6];
|
|
317
|
+
_c = utils_1.toBN;
|
|
318
|
+
return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve_1.curve.constantOptions)];
|
|
319
|
+
case 5:
|
|
320
|
+
inflationRateBN = _c.apply(void 0, [_g.sent()]).div(WEEK);
|
|
321
|
+
_g.label = 6;
|
|
322
|
+
case 6: return [3 /*break*/, 9];
|
|
323
|
+
case 7:
|
|
324
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
325
|
+
lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
326
|
+
gaugeControllerContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
327
|
+
weightBN = void 0;
|
|
328
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
329
|
+
gaugeContract.inflation_rate(),
|
|
330
|
+
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
331
|
+
gaugeContract.working_supply(),
|
|
332
|
+
lpTokenContract.totalSupply(),
|
|
333
|
+
])];
|
|
334
|
+
case 8:
|
|
335
|
+
_e = (_g.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _e[0], weightBN = _e[1], workingSupplyBN = _e[2], totalSupplyBN = _e[3];
|
|
336
|
+
inflationRateBN = inflationRateBN.times(weightBN);
|
|
337
|
+
_g.label = 9;
|
|
338
|
+
case 9:
|
|
339
|
+
rateBN = inflationRateBN.times(31536000).times(0.4).div(workingSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD));
|
|
340
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
|
|
341
|
+
case 10:
|
|
342
|
+
crvPrice = _g.sent();
|
|
343
|
+
baseApyBN = rateBN.times(crvPrice);
|
|
344
|
+
boostedApyBN = baseApyBN.times(2.5);
|
|
345
|
+
return [2 /*return*/, [baseApyBN.times(100).toNumber(), boostedApyBN.times(100).toNumber()]];
|
|
346
|
+
}
|
|
347
|
+
});
|
|
338
348
|
});
|
|
339
|
-
}
|
|
349
|
+
};
|
|
340
350
|
this.statsRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
341
351
|
var apy, rewardTokens, _i, rewardTokens_1, rewardToken, contract, totalLiquidityUSD, rewardRate, rewardData, periodFinish, inflation, baseApy, network, promises, _c, mainPoolsRewards, allTypesExtendedPoolData, rewards, _d, _e, extendedPoolData, _f, _g, pool;
|
|
342
352
|
var _h;
|
|
@@ -648,8 +658,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
648
658
|
if (boost == "2.5")
|
|
649
659
|
return [2 /*return*/, maxApy];
|
|
650
660
|
if (boost === "NaN")
|
|
651
|
-
return [2 /*return*/,
|
|
652
|
-
return [2 /*return*/, (0, utils_1.BN)(baseApy).times((0, utils_1.BN)(boost)).
|
|
661
|
+
return [2 /*return*/, NaN];
|
|
662
|
+
return [2 /*return*/, (0, utils_1.BN)(baseApy).times((0, utils_1.BN)(boost)).toNumber()];
|
|
653
663
|
}
|
|
654
664
|
});
|
|
655
665
|
});
|
package/lib/router.js
CHANGED
|
@@ -319,16 +319,16 @@ var sortByLength = function (a, b) { return a.steps.length - b.steps.length || b
|
|
|
319
319
|
var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
320
320
|
var ALL_POOLS, amplificationCoefficientDict, curCoins, nextCoins, routesByTvl, routesByLength, step, _loop_1, _i, curCoins_2, inCoin, routes;
|
|
321
321
|
var _a, _b;
|
|
322
|
-
var _c, _d, _e, _f, _h, _j, _k, _l, _m, _o, _p, _q, _r
|
|
323
|
-
return __generator(this, function (
|
|
324
|
-
switch (
|
|
322
|
+
var _c, _d, _e, _f, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
323
|
+
return __generator(this, function (_s) {
|
|
324
|
+
switch (_s.label) {
|
|
325
325
|
case 0:
|
|
326
326
|
inputCoinAddress = inputCoinAddress.toLowerCase();
|
|
327
327
|
outputCoinAddress = outputCoinAddress.toLowerCase();
|
|
328
328
|
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));
|
|
329
329
|
return [4 /*yield*/, (0, utils_2._getAmplificationCoefficientsFromApi)()];
|
|
330
330
|
case 1:
|
|
331
|
-
amplificationCoefficientDict =
|
|
331
|
+
amplificationCoefficientDict = _s.sent();
|
|
332
332
|
curCoins = [inputCoinAddress];
|
|
333
333
|
nextCoins = new Set();
|
|
334
334
|
routesByTvl = (_a = {},
|
|
@@ -338,15 +338,15 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
338
338
|
_b[inputCoinAddress] = [{ steps: [], minTvl: Infinity, totalTvl: 0 }],
|
|
339
339
|
_b);
|
|
340
340
|
step = 0;
|
|
341
|
-
|
|
341
|
+
_s.label = 2;
|
|
342
342
|
case 2:
|
|
343
343
|
if (!(step < 4)) return [3 /*break*/, 8];
|
|
344
344
|
_loop_1 = function (inCoin) {
|
|
345
|
-
var outCoin_1, newRoutesByTvl, newRoutesByLength, _loop_2,
|
|
346
|
-
return __generator(this, function (
|
|
347
|
-
switch (
|
|
345
|
+
var outCoin_1, newRoutesByTvl, newRoutesByLength, _loop_2, _t, ALL_POOLS_3, _u, poolId, poolData;
|
|
346
|
+
return __generator(this, function (_v) {
|
|
347
|
+
switch (_v.label) {
|
|
348
348
|
case 0:
|
|
349
|
-
if ([curve_1.curve.constants.NATIVE_TOKEN.address, curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress].includes(inCoin)) {
|
|
349
|
+
if (curve_1.curve.chainId !== 42220 && [curve_1.curve.constants.NATIVE_TOKEN.address, curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress].includes(inCoin)) { // Exclude Celo
|
|
350
350
|
outCoin_1 = inCoin === curve_1.curve.constants.NATIVE_TOKEN.address ? curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress : curve_1.curve.constants.NATIVE_TOKEN.address;
|
|
351
351
|
newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, "wrapper", curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress, inCoin, outCoin_1, 0, 0, 15, ethers_1.ethers.constants.AddressZero, Infinity); });
|
|
352
352
|
newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, "wrapper", curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress, inCoin, outCoin_1, 0, 0, 15, ethers_1.ethers.constants.AddressZero, Infinity); });
|
|
@@ -357,17 +357,17 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
357
357
|
nextCoins.add(outCoin_1);
|
|
358
358
|
}
|
|
359
359
|
_loop_2 = function (poolId, poolData) {
|
|
360
|
-
var wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address,
|
|
361
|
-
return __generator(this, function (
|
|
362
|
-
switch (
|
|
360
|
+
var wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address, is_aave_like_lending, tvlMultiplier, inCoinIndexes, tvl, _w, poolAddress, coin_addresses, _loop_3, j, inCoinIndex, swapType_1, newRoutesByTvl, newRoutesByLength, _loop_4, j, _loop_5, j;
|
|
361
|
+
return __generator(this, function (_x) {
|
|
362
|
+
switch (_x.label) {
|
|
363
363
|
case 0:
|
|
364
364
|
wrapped_coin_addresses = poolData.wrapped_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
365
365
|
underlying_coin_addresses = poolData.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
366
366
|
base_pool = poolData.is_meta ? curve_1.curve.constants.POOLS_DATA[poolData.base_pool] : null;
|
|
367
367
|
meta_coin_addresses = base_pool ? base_pool.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); }) : [];
|
|
368
368
|
token_address = poolData.token_address.toLowerCase();
|
|
369
|
-
|
|
370
|
-
tvlMultiplier = poolData.is_crypto ? 1 : ((
|
|
369
|
+
is_aave_like_lending = poolData.is_lending && wrapped_coin_addresses.length === 3 && !poolData.deposit_address;
|
|
370
|
+
tvlMultiplier = poolData.is_crypto ? 1 : ((_e = amplificationCoefficientDict[poolData.swap_address]) !== null && _e !== void 0 ? _e : 1);
|
|
371
371
|
inCoinIndexes = {
|
|
372
372
|
wrapped_coin: wrapped_coin_addresses.indexOf(inCoin),
|
|
373
373
|
underlying_coin: underlying_coin_addresses.indexOf(inCoin),
|
|
@@ -376,15 +376,15 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
376
376
|
// Skip pools which don't contain inCoin
|
|
377
377
|
if (inCoinIndexes.wrapped_coin === -1 && inCoinIndexes.underlying_coin === -1 && inCoinIndexes.meta_coin === -1 && inCoin !== token_address)
|
|
378
378
|
return [2 /*return*/, "continue"];
|
|
379
|
-
|
|
379
|
+
_w = Number;
|
|
380
380
|
return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
|
|
381
381
|
case 1:
|
|
382
|
-
tvl =
|
|
382
|
+
tvl = _w.apply(void 0, [_x.sent()]) * tvlMultiplier;
|
|
383
383
|
// Skip empty pools
|
|
384
384
|
if (tvl === 0)
|
|
385
385
|
return [2 /*return*/, "continue"];
|
|
386
386
|
poolAddress = poolData.is_fake ? poolData.deposit_address : poolData.swap_address;
|
|
387
|
-
coin_addresses = (
|
|
387
|
+
coin_addresses = (is_aave_like_lending || poolData.is_fake) ? underlying_coin_addresses : wrapped_coin_addresses;
|
|
388
388
|
// LP -> wrapped coin (underlying for lending or fake pool) "swaps" (actually remove_liquidity_one_coin)
|
|
389
389
|
if (coin_addresses.length < 6 && inCoin === token_address) {
|
|
390
390
|
_loop_3 = function (j) {
|
|
@@ -395,12 +395,12 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
395
395
|
var outputCoinIdx = coin_addresses.indexOf(outputCoinAddress);
|
|
396
396
|
if (outputCoinIdx >= 0 && j !== outputCoinIdx)
|
|
397
397
|
return "continue";
|
|
398
|
-
var swapType = poolData.is_crypto ? 14 :
|
|
398
|
+
var swapType = poolData.is_crypto ? 14 : is_aave_like_lending ? 13 : 12;
|
|
399
399
|
var newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, coin_addresses[j], 0, j, swapType, ethers_1.ethers.constants.AddressZero, tvl); });
|
|
400
400
|
var newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, coin_addresses[j], 0, j, swapType, ethers_1.ethers.constants.AddressZero, tvl); });
|
|
401
|
-
routesByTvl[coin_addresses[j]] = __spreadArray(__spreadArray([], ((
|
|
401
|
+
routesByTvl[coin_addresses[j]] = __spreadArray(__spreadArray([], ((_f = routesByTvl[coin_addresses[j]]) !== null && _f !== void 0 ? _f : []), true), newRoutesByTvl, true);
|
|
402
402
|
routesByTvl[coin_addresses[j]] = filterRoutes(routesByTvl[coin_addresses[j]], inputCoinAddress, sortByTvl);
|
|
403
|
-
routesByLength[coin_addresses[j]] = __spreadArray(__spreadArray([], ((
|
|
403
|
+
routesByLength[coin_addresses[j]] = __spreadArray(__spreadArray([], ((_h = routesByLength[coin_addresses[j]]) !== null && _h !== void 0 ? _h : []), true), newRoutesByLength, true);
|
|
404
404
|
routesByLength[coin_addresses[j]] = filterRoutes(routesByLength[coin_addresses[j]], inputCoinAddress, sortByLength);
|
|
405
405
|
nextCoins.add(coin_addresses[j]);
|
|
406
406
|
};
|
|
@@ -408,19 +408,19 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
408
408
|
_loop_3(j);
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
|
-
inCoinIndex = (
|
|
411
|
+
inCoinIndex = (is_aave_like_lending || poolData.is_fake) ? inCoinIndexes.underlying_coin : inCoinIndexes.wrapped_coin;
|
|
412
412
|
if (coin_addresses.length < 6 && inCoinIndex >= 0) {
|
|
413
413
|
// Looking for outputCoinAddress only on the final step
|
|
414
414
|
if (!(step === 3 && token_address !== outputCoinAddress)) {
|
|
415
|
-
swapType_1 =
|
|
415
|
+
swapType_1 = is_aave_like_lending ? 9
|
|
416
416
|
: coin_addresses.length === 2 ? 7
|
|
417
417
|
: coin_addresses.length === 3 ? 8
|
|
418
418
|
: coin_addresses.length === 4 ? 10 : 11;
|
|
419
419
|
newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, token_address, coin_addresses.indexOf(inCoin), 0, swapType_1, ethers_1.ethers.constants.AddressZero, tvl); });
|
|
420
420
|
newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, token_address, coin_addresses.indexOf(inCoin), 0, swapType_1, ethers_1.ethers.constants.AddressZero, tvl); });
|
|
421
|
-
routesByTvl[token_address] = __spreadArray(__spreadArray([], ((
|
|
421
|
+
routesByTvl[token_address] = __spreadArray(__spreadArray([], ((_j = routesByTvl[token_address]) !== null && _j !== void 0 ? _j : []), true), newRoutesByTvl, true);
|
|
422
422
|
routesByTvl[token_address] = filterRoutes(routesByTvl[token_address], inputCoinAddress, sortByTvl);
|
|
423
|
-
routesByLength[token_address] = __spreadArray(__spreadArray([], ((
|
|
423
|
+
routesByLength[token_address] = __spreadArray(__spreadArray([], ((_k = routesByLength[token_address]) !== null && _k !== void 0 ? _k : []), true), newRoutesByLength, true);
|
|
424
424
|
routesByLength[token_address] = filterRoutes(routesByLength[token_address], inputCoinAddress, sortByLength);
|
|
425
425
|
nextCoins.add(token_address);
|
|
426
426
|
}
|
|
@@ -443,9 +443,9 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
443
443
|
var swapType = poolData.is_crypto ? 3 : 1;
|
|
444
444
|
var newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolData.swap_address, inCoin, wrapped_coin_addresses[j], inCoinIndexes.wrapped_coin, j, swapType, ethers_1.ethers.constants.AddressZero, tvl); });
|
|
445
445
|
var newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, poolId, poolData.swap_address, inCoin, wrapped_coin_addresses[j], inCoinIndexes.wrapped_coin, j, swapType, ethers_1.ethers.constants.AddressZero, tvl); });
|
|
446
|
-
routesByTvl[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((
|
|
446
|
+
routesByTvl[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_l = routesByTvl[wrapped_coin_addresses[j]]) !== null && _l !== void 0 ? _l : []), true), newRoutesByTvl, true);
|
|
447
447
|
routesByTvl[wrapped_coin_addresses[j]] = filterRoutes(routesByTvl[wrapped_coin_addresses[j]], inputCoinAddress, sortByTvl);
|
|
448
|
-
routesByLength[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((
|
|
448
|
+
routesByLength[wrapped_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_m = routesByLength[wrapped_coin_addresses[j]]) !== null && _m !== void 0 ? _m : []), true), newRoutesByLength, true);
|
|
449
449
|
routesByLength[wrapped_coin_addresses[j]] = filterRoutes(routesByLength[wrapped_coin_addresses[j]], inputCoinAddress, sortByLength);
|
|
450
450
|
nextCoins.add(wrapped_coin_addresses[j]);
|
|
451
451
|
};
|
|
@@ -458,9 +458,9 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
458
458
|
poolData.deposit_address : poolData.swap_address;
|
|
459
459
|
if (!(!poolData.is_plain && inCoinIndexes.underlying_coin >= 0)) return [3 /*break*/, 5];
|
|
460
460
|
_loop_5 = function (j) {
|
|
461
|
-
var outputCoinIdx, tvl_1,
|
|
462
|
-
return __generator(this, function (
|
|
463
|
-
switch (
|
|
461
|
+
var outputCoinIdx, tvl_1, _y, hasEth, swapType, newRoutesByTvl, newRoutesByLength;
|
|
462
|
+
return __generator(this, function (_z) {
|
|
463
|
+
switch (_z.label) {
|
|
464
464
|
case 0:
|
|
465
465
|
if (j === inCoinIndexes.underlying_coin)
|
|
466
466
|
return [2 /*return*/, "continue"];
|
|
@@ -473,10 +473,10 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
473
473
|
outputCoinIdx = underlying_coin_addresses.indexOf(outputCoinAddress);
|
|
474
474
|
if (outputCoinIdx >= 0 && j !== outputCoinIdx)
|
|
475
475
|
return [2 /*return*/, "continue"];
|
|
476
|
-
|
|
476
|
+
_y = Number;
|
|
477
477
|
return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
|
|
478
478
|
case 1:
|
|
479
|
-
tvl_1 =
|
|
479
|
+
tvl_1 = _y.apply(void 0, [_z.sent()]);
|
|
480
480
|
if (tvl_1 === 0)
|
|
481
481
|
return [2 /*return*/, "continue"];
|
|
482
482
|
hasEth = (inCoin === curve_1.curve.constants.NATIVE_TOKEN.address || underlying_coin_addresses[j] === curve_1.curve.constants.NATIVE_TOKEN.address);
|
|
@@ -487,9 +487,9 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
487
487
|
: 2;
|
|
488
488
|
newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, underlying_coin_addresses[j], inCoinIndexes.underlying_coin, j, swapType, (swapType === 5 || swapType === 6) ? poolData.swap_address : ethers_1.ethers.constants.AddressZero, tvl_1); });
|
|
489
489
|
newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, underlying_coin_addresses[j], inCoinIndexes.underlying_coin, j, swapType, (swapType === 5 || swapType === 6) ? poolData.swap_address : ethers_1.ethers.constants.AddressZero, tvl_1); });
|
|
490
|
-
routesByTvl[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((
|
|
490
|
+
routesByTvl[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_o = routesByTvl[underlying_coin_addresses[j]]) !== null && _o !== void 0 ? _o : []), true), newRoutesByTvl, true);
|
|
491
491
|
routesByTvl[underlying_coin_addresses[j]] = filterRoutes(routesByTvl[underlying_coin_addresses[j]], inputCoinAddress, sortByTvl);
|
|
492
|
-
routesByLength[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((
|
|
492
|
+
routesByLength[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_p = routesByLength[underlying_coin_addresses[j]]) !== null && _p !== void 0 ? _p : []), true), newRoutesByLength, true);
|
|
493
493
|
routesByLength[underlying_coin_addresses[j]] = filterRoutes(routesByLength[underlying_coin_addresses[j]], inputCoinAddress, sortByLength);
|
|
494
494
|
nextCoins.add(underlying_coin_addresses[j]);
|
|
495
495
|
return [2 /*return*/];
|
|
@@ -497,13 +497,13 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
497
497
|
});
|
|
498
498
|
};
|
|
499
499
|
j = 0;
|
|
500
|
-
|
|
500
|
+
_x.label = 2;
|
|
501
501
|
case 2:
|
|
502
502
|
if (!(j < underlying_coin_addresses.length)) return [3 /*break*/, 5];
|
|
503
503
|
return [5 /*yield**/, _loop_5(j)];
|
|
504
504
|
case 3:
|
|
505
|
-
|
|
506
|
-
|
|
505
|
+
_x.sent();
|
|
506
|
+
_x.label = 4;
|
|
507
507
|
case 4:
|
|
508
508
|
j++;
|
|
509
509
|
return [3 /*break*/, 2];
|
|
@@ -511,43 +511,43 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
511
511
|
}
|
|
512
512
|
});
|
|
513
513
|
};
|
|
514
|
-
|
|
515
|
-
|
|
514
|
+
_t = 0, ALL_POOLS_3 = ALL_POOLS;
|
|
515
|
+
_v.label = 1;
|
|
516
516
|
case 1:
|
|
517
|
-
if (!(
|
|
518
|
-
|
|
517
|
+
if (!(_t < ALL_POOLS_3.length)) return [3 /*break*/, 4];
|
|
518
|
+
_u = ALL_POOLS_3[_t], poolId = _u[0], poolData = _u[1];
|
|
519
519
|
return [5 /*yield**/, _loop_2(poolId, poolData)];
|
|
520
520
|
case 2:
|
|
521
|
-
|
|
522
|
-
|
|
521
|
+
_v.sent();
|
|
522
|
+
_v.label = 3;
|
|
523
523
|
case 3:
|
|
524
|
-
|
|
524
|
+
_t++;
|
|
525
525
|
return [3 /*break*/, 1];
|
|
526
526
|
case 4: return [2 /*return*/];
|
|
527
527
|
}
|
|
528
528
|
});
|
|
529
529
|
};
|
|
530
530
|
_i = 0, curCoins_2 = curCoins;
|
|
531
|
-
|
|
531
|
+
_s.label = 3;
|
|
532
532
|
case 3:
|
|
533
533
|
if (!(_i < curCoins_2.length)) return [3 /*break*/, 6];
|
|
534
534
|
inCoin = curCoins_2[_i];
|
|
535
535
|
return [5 /*yield**/, _loop_1(inCoin)];
|
|
536
536
|
case 4:
|
|
537
|
-
|
|
538
|
-
|
|
537
|
+
_s.sent();
|
|
538
|
+
_s.label = 5;
|
|
539
539
|
case 5:
|
|
540
540
|
_i++;
|
|
541
541
|
return [3 /*break*/, 3];
|
|
542
542
|
case 6:
|
|
543
543
|
curCoins = Array.from(nextCoins);
|
|
544
544
|
nextCoins = new Set();
|
|
545
|
-
|
|
545
|
+
_s.label = 7;
|
|
546
546
|
case 7:
|
|
547
547
|
step++;
|
|
548
548
|
return [3 /*break*/, 2];
|
|
549
549
|
case 8:
|
|
550
|
-
routes = __spreadArray(__spreadArray([], ((
|
|
550
|
+
routes = __spreadArray(__spreadArray([], ((_q = routesByTvl[outputCoinAddress]) !== null && _q !== void 0 ? _q : []), true), ((_r = routesByLength[outputCoinAddress]) !== null && _r !== void 0 ? _r : []), true);
|
|
551
551
|
return [2 /*return*/, routes.map(function (r) { return r.steps; })];
|
|
552
552
|
}
|
|
553
553
|
});
|
package/lib/utils.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (num
|
|
|
27
27
|
export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string) => Promise<string[]>;
|
|
28
28
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
29
29
|
export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
|
|
30
|
+
export declare const _getCrvApyFromApi: () => Promise<IDict<[number, number]>>;
|
|
30
31
|
export declare const _getUsdRate: (assetId: string) => Promise<number>;
|
|
31
32
|
export declare const getUsdRate: (coin: string) => Promise<number>;
|
|
32
33
|
export declare const getTVL: (chainId?: number) => Promise<number>;
|
package/lib/utils.js
CHANGED
|
@@ -59,7 +59,7 @@ 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.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
62
|
+
exports.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getCrvApyFromApi = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
63
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
64
|
var ethers_1 = require("ethers");
|
|
65
65
|
var ethcall_1 = require("ethcall");
|
|
@@ -449,6 +449,37 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
|
|
|
449
449
|
});
|
|
450
450
|
}); };
|
|
451
451
|
exports._getUsdPricesFromApi = _getUsdPricesFromApi;
|
|
452
|
+
var _getCrvApyFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
453
|
+
var network, promises, allTypesExtendedPoolData, apyDict, _i, allTypesExtendedPoolData_2, extendedPoolData, _a, _b, pool;
|
|
454
|
+
var _c, _d;
|
|
455
|
+
return __generator(this, function (_e) {
|
|
456
|
+
switch (_e.label) {
|
|
457
|
+
case 0:
|
|
458
|
+
network = curve_1.curve.constants.NETWORK_NAME;
|
|
459
|
+
promises = [
|
|
460
|
+
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
461
|
+
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
462
|
+
(0, external_api_1._getPoolsFromApi)(network, "factory"),
|
|
463
|
+
(0, external_api_1._getPoolsFromApi)(network, "factory-crypto"),
|
|
464
|
+
];
|
|
465
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
466
|
+
case 1:
|
|
467
|
+
allTypesExtendedPoolData = _e.sent();
|
|
468
|
+
apyDict = {};
|
|
469
|
+
for (_i = 0, allTypesExtendedPoolData_2 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_2.length; _i++) {
|
|
470
|
+
extendedPoolData = allTypesExtendedPoolData_2[_i];
|
|
471
|
+
for (_a = 0, _b = extendedPoolData.poolData; _a < _b.length; _a++) {
|
|
472
|
+
pool = _b[_a];
|
|
473
|
+
if (pool.gaugeAddress) {
|
|
474
|
+
apyDict[pool.gaugeAddress] = [(_c = pool.gaugeCrvApy[0]) !== null && _c !== void 0 ? _c : 0, (_d = pool.gaugeCrvApy[1]) !== null && _d !== void 0 ? _d : 0];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return [2 /*return*/, apyDict];
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}); };
|
|
482
|
+
exports._getCrvApyFromApi = _getCrvApyFromApi;
|
|
452
483
|
var _usdRatesCache = {};
|
|
453
484
|
var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
454
485
|
var pricesFromApi, chainName, nativeTokenName, url, response;
|