Skip to content

Commit

Permalink
Merge pull request #257 from dappradar/eigen-layer
Browse files Browse the repository at this point in the history
eigen fix
  • Loading branch information
mantasfam authored Feb 20, 2024
2 parents 7e3ee2f + 96bf401 commit bb3a06f
Showing 1 changed file with 9 additions and 43 deletions.
52 changes: 9 additions & 43 deletions src/factory/providers/ethereum/eigenlayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -34,44 +30,14 @@ async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> {
}
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(
Expand Down

0 comments on commit bb3a06f

Please sign in to comment.