Skip to content

Commit

Permalink
refactor getChainblocks code
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Oct 8, 2022
1 parent 5bc64bd commit b861b7f
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env node
const path = require("path");
require("dotenv").config();
//const { default: computeTVL } = require("@defillama/sdk/build/computeTVL");
const { chainsForBlocks } = require("@defillama/sdk/build/computeTVL/blocks");
const { getLatestBlock } = require("@defillama/sdk/build/util/index");
const { getCurrentBlocks } = require("@defillama/sdk/build/computeTVL/blocks");
const {
humanizeNumber,
} = require("@defillama/sdk/build/computeTVL/humanizeNumber");
Expand All @@ -15,16 +13,6 @@ const handleError = require('./utils/handleError')
const { log, diplayUnknownTable, sliceIntoChunks } = require('./projects/helper/utils')
const { PromisePool } = require('@supercharge/promise-pool')

async function getLatestBlockRetry(chain) {
for (let i = 0; i < 5; i++) {
try {
return await getLatestBlock(chain);
} catch (e) {
throw new Error(`Couln't get block height for chain "${chain}"`, e);
}
}
}

const locks = [];
function getCoingeckoLock() {
return new Promise((resolve) => {
Expand Down Expand Up @@ -127,19 +115,7 @@ sdk.api.abi.call = async (...args) => {
const chains = Object.keys(module).filter(item => typeof module[item] === 'object' && !Array.isArray(module[item]));
checkExportKeys(module, passedFile, chains)
const unixTimestamp = Math.round(Date.now() / 1000) - 60;
const chainBlocks = {};

if (!chains.includes("ethereum")) {
chains.push("ethereum");
}
await Promise.all(
chains.map(async (chainRaw) => {
const chain = chainRaw === "avalanche" ? "avax" : chainRaw
if (chainsForBlocks.includes(chain) || chain === "ethereum") {
chainBlocks[chain] = (await getLatestBlockRetry(chain)).number - 10;
}
})
);
const { chainBlocks } = await getCurrentBlocks(chains);
const ethBlock = chainBlocks.ethereum;
const usdTvls = {};
const tokensBalances = {};
Expand Down

0 comments on commit b861b7f

Please sign in to comment.