@defillama/sdk 2.3.22 → 2.3.23
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/build/computeTVL/index.js +28 -33
- package/package.json +1 -1
|
@@ -235,11 +235,11 @@ function default_1(rawBalances, timestamp, verbose, knownTokenPrices, getCoingec
|
|
|
235
235
|
chainIds.coingecko.push(normalizedAddressOrName);
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
-
|
|
239
|
-
if (!(timestamp === "now")) return [3 /*break*/, 5];
|
|
240
|
-
return [4 /*yield*/, symbolsAndDecimals];
|
|
238
|
+
return [4 /*yield*/, getChainSymbolsAndDecimals(chainIds)];
|
|
241
239
|
case 4:
|
|
242
|
-
|
|
240
|
+
symbolsAndDecimals = _c.sent();
|
|
241
|
+
if (!(timestamp === "now")) return [3 /*break*/, 5];
|
|
242
|
+
allChainTokenPrices = symbolsAndDecimals.reduce(function (prices, item) {
|
|
243
243
|
var chain, address;
|
|
244
244
|
if (item.coin.includes(":")) {
|
|
245
245
|
chain = item.coin.split(':')[0];
|
|
@@ -266,13 +266,11 @@ function default_1(rawBalances, timestamp, verbose, knownTokenPrices, getCoingec
|
|
|
266
266
|
usdAmounts = Object.entries(normalizedBalances).map(function (_a) {
|
|
267
267
|
var address = _a[0], balance = _a[1];
|
|
268
268
|
return __awaiter(_this, void 0, void 0, function () {
|
|
269
|
-
var amount, price, tokenSymbol, normalizedAddress_1, chainSelector_1, chainTokenPrices, chainAddress_1, coinData, tokenDecimals, usdAmount
|
|
269
|
+
var amount, price, tokenSymbol, normalizedAddress_1, chainSelector_1, chainTokenPrices, chainAddress_1, coinData, tokenDecimals, usdAmount;
|
|
270
270
|
var _b, _c, _d, _e;
|
|
271
271
|
return __generator(this, function (_f) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
_f.trys.push([0, 4, , 5]);
|
|
275
|
-
if (!(address.startsWith("0x") || address.includes(":"))) return [3 /*break*/, 2];
|
|
272
|
+
try {
|
|
273
|
+
if (address.startsWith("0x") || address.includes(":")) {
|
|
276
274
|
normalizedAddress_1 = address;
|
|
277
275
|
chainSelector_1 = "ethereum";
|
|
278
276
|
chains.forEach(function (chain) {
|
|
@@ -283,9 +281,7 @@ function default_1(rawBalances, timestamp, verbose, knownTokenPrices, getCoingec
|
|
|
283
281
|
});
|
|
284
282
|
chainTokenPrices = (_b = allChainTokenPrices[chainSelector_1]) !== null && _b !== void 0 ? _b : {};
|
|
285
283
|
chainAddress_1 = chainSelector_1 + ":" + normalizedAddress_1.toLowerCase();
|
|
286
|
-
return
|
|
287
|
-
case 1:
|
|
288
|
-
coinData = (_f.sent()).find(function (coin) { return coin.coin === chainAddress_1; });
|
|
284
|
+
coinData = symbolsAndDecimals.find(function (coin) { return coin.coin === chainAddress_1; });
|
|
289
285
|
tokenSymbol = (_c = coinData === null || coinData === void 0 ? void 0 : coinData.symbol) === null || _c === void 0 ? void 0 : _c.toUpperCase();
|
|
290
286
|
if (tokenSymbol === undefined || tokenSymbol === null) {
|
|
291
287
|
tokenSymbol = "UNKNOWN (" + address + ")";
|
|
@@ -298,32 +294,31 @@ function default_1(rawBalances, timestamp, verbose, knownTokenPrices, getCoingec
|
|
|
298
294
|
amount = Number(balance) / Math.pow(10, Number(tokenDecimals));
|
|
299
295
|
}
|
|
300
296
|
price = (_d = chainTokenPrices[normalizedAddress_1.toLowerCase()]) === null || _d === void 0 ? void 0 : _d.usd;
|
|
301
|
-
|
|
302
|
-
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
303
299
|
tokenSymbol = address;
|
|
304
300
|
price = (_e = allChainTokenPrices["coingecko"][address.toLowerCase()]) === null || _e === void 0 ? void 0 : _e.usd;
|
|
305
301
|
amount = Number(balance);
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
if (
|
|
309
|
-
|
|
310
|
-
console.log("Token " + address + " is not on coingecko, it'll be ignored");
|
|
311
|
-
}
|
|
312
|
-
price = 0;
|
|
302
|
+
}
|
|
303
|
+
if (price === undefined) {
|
|
304
|
+
if (verbose) {
|
|
305
|
+
console.log("Token " + address + " is not on coingecko, it'll be ignored");
|
|
313
306
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
307
|
+
price = 0;
|
|
308
|
+
}
|
|
309
|
+
addTokenBalance(tokenBalances, tokenSymbol, amount);
|
|
310
|
+
usdAmount = amount * price;
|
|
311
|
+
addTokenBalance(usdTokenBalances, tokenSymbol, usdAmount);
|
|
312
|
+
return [2 /*return*/, { usdAmount: usdAmount, tokenSymbol: tokenSymbol }];
|
|
313
|
+
}
|
|
314
|
+
catch (e) {
|
|
315
|
+
console.error("Error on token " + address + ", we'll just assume it's price is 0...", e);
|
|
316
|
+
return [2 /*return*/, {
|
|
317
|
+
usdAmount: 0,
|
|
318
|
+
tokenSymbol: "ERROR " + address,
|
|
319
|
+
}];
|
|
326
320
|
}
|
|
321
|
+
return [2 /*return*/];
|
|
327
322
|
});
|
|
328
323
|
});
|
|
329
324
|
});
|