From 96bf401ea7e5727456ddef6a66ec90e042ce0521 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Tue, 20 Feb 2024 13:56:07 +0700 Subject: [PATCH] Update index.ts --- .../providers/ethereum/eigenlayer/index.ts | 52 ++++--------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/src/factory/providers/ethereum/eigenlayer/index.ts b/src/factory/providers/ethereum/eigenlayer/index.ts index 42e169e7..471937ec 100644 --- a/src/factory/providers/ethereum/eigenlayer/index.ts +++ b/src/factory/providers/ethereum/eigenlayer/index.ts @@ -2,22 +2,18 @@ import BigNumber from 'bignumber.js'; import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; import { request, gql } from 'graphql-request'; import formatter from '../../../../util/formatter'; -import util from '../../../../util/blockchainUtil'; -import basicUtil from '../../../../util/basicUtil'; const START_BLOCK = 17445564; -const BLOCK_LIMIT = 10000; const SWETH = '0xf951e335afb289353dc249e82926178eac7ded78'; -const EIGEN_POD_MANAGER = '0x91E677b07F7AF907ec9a428aafA9fc14a0d3A338'; -const POD_DEPLOYED_TOPIC = - '0x21c99d0db02213c32fff5b05cf0a718ab5f858802b91498f80d82270289d856a'; - const SUBGRAPH_ENDPOINT = 'https://api.thegraph.com/subgraphs/name/messari/eigenlayer-ethereum'; const STRATEGY_POOLS = gql` query getPools($block: Int!) { - pools(where: { type: STRATEGY }) { + protocols(block: { number: $block }) { + totalEigenPodCount + } + pools(block: { number: $block }, where: { type: STRATEGY }) { inputTokens { id } @@ -34,44 +30,14 @@ async function tvl(params: ITvlParams): Promise> { } const balances = {}; - let cache: { - start: number; - pods: { block: number; address: string }[]; - } = { start: START_BLOCK, pods: [] }; - try { - cache = await basicUtil.readFromCache('cache.json', chain, provider); - } catch {} - for ( - let i = Math.max(cache.start, START_BLOCK); - i < block; - i += BLOCK_LIMIT - ) { - const logs = await util.getLogs( - i, - Math.min(i + BLOCK_LIMIT, block), - POD_DEPLOYED_TOPIC, - EIGEN_POD_MANAGER, - web3, - ); - logs.output.forEach((log) => { - cache.pods.push({ - address: `0x${log.topics[1].substring(26, 66)}`, - block: log.blockNumber, - }); - }); - } - - cache.start = block; - await basicUtil.saveIntoCache(cache, 'cache.json', chain, provider); - - const filteredPodsCount = cache.pods.filter( - (pod) => pod.block <= block, - ).length; - balances['eth'] = BigNumber(filteredPodsCount * 38).shiftedBy(18); - const requestResult = await request(SUBGRAPH_ENDPOINT, STRATEGY_POOLS, { block: block, }); + + balances['eth'] = BigNumber( + requestResult.protocols[0].totalEigenPodCount * 38, + ).shiftedBy(18); + for (const pool of requestResult.pools) { for (let i = 0; i < pool.inputTokens.length; i++) { balances[pool.inputTokens[i].id.toLowerCase()] = BigNumber(