diff --git a/deployment/deployment.json b/deployment/deployment.json index 03db2ff0d6..12b7af3790 100644 --- a/deployment/deployment.json +++ b/deployment/deployment.json @@ -9796,7 +9796,7 @@ "status": "prod", "versions": { "schema": "2.1.1", - "subgraph": "1.0.0", + "subgraph": "1.1.0", "methodology": "1.0.0" }, "files": { diff --git a/subgraphs/eigenlayer/schema.graphql b/subgraphs/eigenlayer/schema.graphql index 6af13e489a..508242df4f 100644 --- a/subgraphs/eigenlayer/schema.graphql +++ b/subgraphs/eigenlayer/schema.graphql @@ -771,6 +771,7 @@ type Withdraw implements Event @entity @transaction { " Block number of this event " blockNumber: BigInt! + blockNumberCompleted: BigInt " Timestamp of this event " timestamp: BigInt! diff --git a/subgraphs/eigenlayer/src/common/events.ts b/subgraphs/eigenlayer/src/common/events.ts index e8da7ef812..fdc8212ebe 100644 --- a/subgraphs/eigenlayer/src/common/events.ts +++ b/subgraphs/eigenlayer/src/common/events.ts @@ -137,6 +137,7 @@ export function updateWithdraw( ); withdrawEvent.hashCompleted = event.transaction.hash; withdrawEvent.completed = true; + withdrawEvent.blockNumberCompleted = event.block.number; withdrawEvent.save(); const account = getOrCreateAccount(accountAddress); diff --git a/subgraphs/eigenlayer/src/common/getters.ts b/subgraphs/eigenlayer/src/common/getters.ts index 04a0eba8af..200fc5519b 100644 --- a/subgraphs/eigenlayer/src/common/getters.ts +++ b/subgraphs/eigenlayer/src/common/getters.ts @@ -1,4 +1,4 @@ -import { Address, Bytes, ethereum } from "@graphprotocol/graph-ts"; +import { Address, BigInt, Bytes, ethereum, log } from "@graphprotocol/graph-ts"; import { BIGDECIMAL_ZERO, @@ -30,6 +30,7 @@ import { UsageMetricsDailySnapshot, UsageMetricsHourlySnapshot, } from "../../generated/schema"; +import { Strategy } from "../../generated/StrategyManager/Strategy"; export function getOrCreateToken( tokenAddress: Address, @@ -375,3 +376,26 @@ export function getOrCreateActiveAccount(id: Bytes): ActiveAccount { } return account; } + +export function getPoolBalance(poolAddress: Address): BigInt { + const strategyContract = Strategy.bind(poolAddress); + const totalSharesResult = strategyContract.try_totalShares(); + if (totalSharesResult.reverted) { + log.error( + "[getPoolBalance] strategyContract.try_totalShares() reverted for strategy: {}", + [poolAddress.toHexString()] + ); + return BIGINT_ZERO; + } + const sharesToUnderlyingResult = strategyContract.try_sharesToUnderlying( + totalSharesResult.value + ); + if (sharesToUnderlyingResult.reverted) { + log.error( + "[getPoolBalance] strategyContract.try_sharesToUnderlying() reverted for strategy: {} and value: {}", + [poolAddress.toHexString(), totalSharesResult.value.toString()] + ); + return BIGINT_ZERO; + } + return sharesToUnderlyingResult.value; +} diff --git a/subgraphs/eigenlayer/src/common/metrics.ts b/subgraphs/eigenlayer/src/common/metrics.ts index e857f8f526..c45edacb7a 100644 --- a/subgraphs/eigenlayer/src/common/metrics.ts +++ b/subgraphs/eigenlayer/src/common/metrics.ts @@ -26,19 +26,14 @@ export function updatePoolIsActive( export function updateTVL( poolAddress: Address, tokenAddress: Address, - isDeposit: boolean, - amount: BigInt, + balance: BigInt, event: ethereum.Event ): void { const protocol = getOrCreateProtocol(); const pool = getPool(poolAddress); const token = getOrCreateToken(tokenAddress, event); - if (isDeposit) { - pool.inputTokenBalances = [pool.inputTokenBalances[0].plus(amount)]; - } else { - pool.inputTokenBalances = [pool.inputTokenBalances[0].minus(amount)]; - } + pool.inputTokenBalances = [balance]; pool.inputTokenBalancesUSD = [ bigIntToBigDecimal(pool.inputTokenBalances[0]).times(token.lastPriceUSD!), ]; diff --git a/subgraphs/eigenlayer/src/mappings/handlers.ts b/subgraphs/eigenlayer/src/mappings/handlers.ts index ee693b3190..31511fbf42 100644 --- a/subgraphs/eigenlayer/src/mappings/handlers.ts +++ b/subgraphs/eigenlayer/src/mappings/handlers.ts @@ -4,6 +4,7 @@ import { BIGINT_ZERO, ETH_ADDRESS, INT_FOUR, + INT_ONE, INT_THREE, INT_TWO, INT_ZERO, @@ -19,6 +20,7 @@ import { getOrCreateAccount, getOrCreateToken, getPool, + getPoolBalance, } from "../common/getters"; import { updatePoolIsActive, @@ -163,12 +165,18 @@ export function handleDeposit(event: Deposit): void { const logTopicSignature = thisLog.topics.at(INT_ZERO); if (logTopicSignature.equals(TRANSFER_SIGNATURE)) { - const decoded = ethereum.decode(TRANSFER_DATA_TYPE, thisLog.data); - if (!decoded) continue; - - const logData = decoded.toTuple(); - amount = logData[INT_ZERO].toBigInt(); - break; + const logTopicTo = ethereum + .decode("address", thisLog.topics.at(INT_TWO))! + .toAddress(); + + if (logTopicTo.equals(Address.fromBytes(pool.id))) { + const decoded = ethereum.decode(TRANSFER_DATA_TYPE, thisLog.data); + if (!decoded) continue; + + const logData = decoded.toTuple(); + amount = logData[INT_ZERO].toBigInt(); + break; + } } } @@ -189,11 +197,13 @@ export function handleDeposit(event: Deposit): void { depositID, event ); + + const poolBalance = getPoolBalance(Address.fromBytes(pool.id)); + updateTVL( Address.fromBytes(pool.id), Address.fromBytes(token.id), - true, - amount, + poolBalance, event ); updateVolume( @@ -323,12 +333,18 @@ export function handleWithdrawalCompleted(event: WithdrawalCompleted): void { const logTopicSignature = thisLog.topics.at(INT_ZERO); if (logTopicSignature.equals(TRANSFER_SIGNATURE)) { - const decoded = ethereum.decode(TRANSFER_DATA_TYPE, thisLog.data); - if (!decoded) continue; - - const logData = decoded.toTuple(); - amount = logData[INT_ZERO].toBigInt(); - break; + const logTopicFrom = ethereum + .decode("address", thisLog.topics.at(INT_ONE))! + .toAddress(); + + if (logTopicFrom.equals(Address.fromBytes(poolID))) { + const decoded = ethereum.decode(TRANSFER_DATA_TYPE, thisLog.data); + if (!decoded) continue; + + const logData = decoded.toTuple(); + amount = logData[INT_ZERO].toBigInt(); + break; + } } } @@ -341,11 +357,13 @@ export function handleWithdrawalCompleted(event: WithdrawalCompleted): void { withdrawID, event ); + + const poolBalance = getPoolBalance(Address.fromBytes(poolID)); + updateTVL( Address.fromBytes(poolID), Address.fromBytes(tokenID), - false, - amount, + poolBalance, event ); updateVolume(