@curvefi/api 2.46.6 → 2.46.7
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/utils.js +62 -7
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -408,7 +408,7 @@ var _getTokenAddressBySwapAddress = function (swapAddress) {
|
|
|
408
408
|
return res[0][1].token_address;
|
|
409
409
|
};
|
|
410
410
|
export var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
411
|
-
var network, allTypesExtendedPoolData, priceDict, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool, lpTokenAddress, totalSupply, _c, _d, coin, _e, _f, coin;
|
|
411
|
+
var network, allTypesExtendedPoolData, priceDict, priceDictByMaxTvl, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool, lpTokenAddress, totalSupply, _c, _d, coin, _e, _f, coin, address, maxTvlItem;
|
|
412
412
|
var _g, _h;
|
|
413
413
|
return __generator(this, function (_j) {
|
|
414
414
|
switch (_j.label) {
|
|
@@ -418,26 +418,81 @@ export var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0,
|
|
|
418
418
|
case 1:
|
|
419
419
|
allTypesExtendedPoolData = _j.sent();
|
|
420
420
|
priceDict = {};
|
|
421
|
+
priceDictByMaxTvl = {};
|
|
421
422
|
for (_i = 0, allTypesExtendedPoolData_1 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_1.length; _i++) {
|
|
422
423
|
extendedPoolData = allTypesExtendedPoolData_1[_i];
|
|
423
424
|
for (_a = 0, _b = extendedPoolData.poolData; _a < _b.length; _a++) {
|
|
424
425
|
pool = _b[_a];
|
|
425
426
|
lpTokenAddress = (_g = pool.lpTokenAddress) !== null && _g !== void 0 ? _g : pool.address;
|
|
426
427
|
totalSupply = pool.totalSupply / (Math.pow(10, 18));
|
|
427
|
-
|
|
428
|
+
if (lpTokenAddress.toLowerCase() in priceDict) {
|
|
429
|
+
priceDict[lpTokenAddress.toLowerCase()].push({
|
|
430
|
+
price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
|
|
431
|
+
tvl: pool.usdTotal
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
priceDict[lpTokenAddress.toLowerCase()] = [];
|
|
436
|
+
priceDict[lpTokenAddress.toLowerCase()].push({
|
|
437
|
+
price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
|
|
438
|
+
tvl: pool.usdTotal
|
|
439
|
+
});
|
|
440
|
+
}
|
|
428
441
|
for (_c = 0, _d = pool.coins; _c < _d.length; _c++) {
|
|
429
442
|
coin = _d[_c];
|
|
430
|
-
if (typeof coin.usdPrice === "number")
|
|
431
|
-
|
|
443
|
+
if (typeof coin.usdPrice === "number") {
|
|
444
|
+
if (coin.address.toLowerCase() in priceDict) {
|
|
445
|
+
priceDict[coin.address.toLowerCase()].push({
|
|
446
|
+
price: coin.usdPrice,
|
|
447
|
+
tvl: pool.usdTotal
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
priceDict[coin.address.toLowerCase()] = [];
|
|
452
|
+
priceDict[coin.address.toLowerCase()].push({
|
|
453
|
+
price: coin.usdPrice,
|
|
454
|
+
tvl: pool.usdTotal
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
432
458
|
}
|
|
433
459
|
for (_e = 0, _f = (_h = pool.gaugeRewards) !== null && _h !== void 0 ? _h : []; _e < _f.length; _e++) {
|
|
434
460
|
coin = _f[_e];
|
|
435
|
-
if (typeof coin.tokenPrice === "number")
|
|
436
|
-
|
|
461
|
+
if (typeof coin.tokenPrice === "number") {
|
|
462
|
+
if (coin.tokenAddress.toLowerCase() in priceDict) {
|
|
463
|
+
priceDict[coin.tokenAddress.toLowerCase()].push({
|
|
464
|
+
price: coin.tokenPrice,
|
|
465
|
+
tvl: pool.usdTotal
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
priceDict[coin.tokenAddress.toLowerCase()] = [];
|
|
470
|
+
priceDict[coin.tokenAddress.toLowerCase()].push({
|
|
471
|
+
price: coin.tokenPrice,
|
|
472
|
+
tvl: pool.usdTotal
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
437
476
|
}
|
|
438
477
|
}
|
|
439
478
|
}
|
|
440
|
-
|
|
479
|
+
for (address in priceDict) {
|
|
480
|
+
if (priceDict[address].length > 0) {
|
|
481
|
+
maxTvlItem = priceDict[address].reduce(function (prev, current) {
|
|
482
|
+
if (+current.tvl > +prev.tvl) {
|
|
483
|
+
return current;
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
return prev;
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
priceDictByMaxTvl[address] = maxTvlItem.price;
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
priceDictByMaxTvl[address] = 0;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return [2 /*return*/, priceDictByMaxTvl];
|
|
441
496
|
}
|
|
442
497
|
});
|
|
443
498
|
}); };
|