From a3801989e423ed7be7b6d2d35f7778875fa4e00b Mon Sep 17 00:00:00 2001 From: LeTamanoir Date: Tue, 20 Feb 2024 11:46:26 +0100 Subject: [PATCH] fix: index multiple completed withdrawals --- subgraphs/eigenlayer/src/common/events.ts | 6 +- subgraphs/eigenlayer/src/mappings/handlers.ts | 180 ++++++++++-------- 2 files changed, 97 insertions(+), 89 deletions(-) diff --git a/subgraphs/eigenlayer/src/common/events.ts b/subgraphs/eigenlayer/src/common/events.ts index fdc8212ebe..b98308f4bd 100644 --- a/subgraphs/eigenlayer/src/common/events.ts +++ b/subgraphs/eigenlayer/src/common/events.ts @@ -1,4 +1,4 @@ -import { Address, BigInt, Bytes, ethereum, log } from "@graphprotocol/graph-ts"; +import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts"; import { BIGDECIMAL_ZERO, BIGINT_ZERO, ZERO_ADDRESS } from "./constants"; import { getOrCreateAccount, getOrCreateToken } from "./getters"; @@ -114,10 +114,6 @@ export function getWithdraw( } } - log.warning( - "[getWithdraw] queued withdraw transaction not found for depositor: {} and withdrawalRoot: {}", - [accountAddress.toHexString(), withdrawalRoot.toHexString()] - ); return null; } diff --git a/subgraphs/eigenlayer/src/mappings/handlers.ts b/subgraphs/eigenlayer/src/mappings/handlers.ts index 31511fbf42..1678a55270 100644 --- a/subgraphs/eigenlayer/src/mappings/handlers.ts +++ b/subgraphs/eigenlayer/src/mappings/handlers.ts @@ -304,101 +304,113 @@ export function handleWithdrawalCompleted(event: WithdrawalCompleted): void { const depositorAddress = event.params.depositor; const withdrawalRoot = event.params.withdrawalRoot; - const withdraw = getWithdraw(depositorAddress, withdrawalRoot); - if (!withdraw) return; + let withdraw = getWithdraw(depositorAddress, withdrawalRoot); - const withdrawID = withdraw.id; - const poolID = withdraw.pool; - const tokenID = withdraw.token; - const accountID = withdraw.depositor; + if (!withdraw) { + log.warning( + "[getWithdraw] queued withdraw transaction not found for depositor: {} and withdrawalRoot: {}", + [depositorAddress.toHexString(), withdrawalRoot.toHexString()] + ); - let amount = BIGINT_ZERO; - const receipt = event.receipt; - if (!receipt) { - log.error("[handleWithdrawalCompleted] No event receipt. Tx: {}", [ - event.transaction.hash.toHexString(), - ]); - return; - } - const logs = receipt.logs; - if (!logs) { - log.error("[handleWithdrawalCompleted] No logs for event receipt. Tx: {}", [ - event.transaction.hash.toHexString(), - ]); return; } - for (let i = 0; i < logs.length; i++) { - const thisLog = logs.at(i); - const logTopicSignature = thisLog.topics.at(INT_ZERO); + do { + const withdrawID = withdraw!.id; + const poolID = withdraw!.pool; + const tokenID = withdraw!.token; + const accountID = withdraw!.depositor; + + const receipt = event.receipt; + if (!receipt) { + log.error("[handleWithdrawalCompleted] No event receipt. Tx: {}", [ + event.transaction.hash.toHexString(), + ]); + return; + } + const logs = receipt.logs; + if (!logs) { + log.error( + "[handleWithdrawalCompleted] No logs for event receipt. Tx: {}", + [event.transaction.hash.toHexString()] + ); + return; + } - if (logTopicSignature.equals(TRANSFER_SIGNATURE)) { - const logTopicFrom = ethereum - .decode("address", thisLog.topics.at(INT_ONE))! - .toAddress(); + let amount = BIGINT_ZERO; - if (logTopicFrom.equals(Address.fromBytes(poolID))) { - const decoded = ethereum.decode(TRANSFER_DATA_TYPE, thisLog.data); - if (!decoded) continue; + for (let i = 0; i < logs.length; i++) { + const thisLog = logs.at(i); + const logTopicSignature = thisLog.topics.at(INT_ZERO); - const logData = decoded.toTuple(); - amount = logData[INT_ZERO].toBigInt(); - break; + if (logTopicSignature.equals(TRANSFER_SIGNATURE)) { + 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; + } } } - } - updateUsage( - Address.fromBytes(poolID), - Address.fromBytes(tokenID), - Address.fromBytes(accountID), - false, - amount, - withdrawID, - event - ); + updateUsage( + Address.fromBytes(poolID), + Address.fromBytes(tokenID), + Address.fromBytes(accountID), + false, + amount, + withdrawID, + event + ); - const poolBalance = getPoolBalance(Address.fromBytes(poolID)); + const poolBalance = getPoolBalance(Address.fromBytes(poolID)); - updateTVL( - Address.fromBytes(poolID), - Address.fromBytes(tokenID), - poolBalance, - event - ); - updateVolume( - Address.fromBytes(poolID), - Address.fromBytes(tokenID), - false, - amount, - event - ); - updatePoolHourlySnapshot(Address.fromBytes(poolID), event); - updatePoolDailySnapshot( - Address.fromBytes(poolID), - Address.fromBytes(tokenID), - false, - amount, - event - ); - updateUsageMetricsHourlySnapshot(Address.fromBytes(accountID), event); - updateUsageMetricsDailySnapshot( - Address.fromBytes(accountID), - false, - withdrawID, - event - ); - updateFinancialsDailySnapshot( - Address.fromBytes(tokenID), - false, - amount, - event - ); - updateWithdraw( - Address.fromBytes(accountID), - Address.fromBytes(tokenID), - withdrawID, - amount, - event - ); + updateTVL( + Address.fromBytes(poolID), + Address.fromBytes(tokenID), + poolBalance, + event + ); + updateVolume( + Address.fromBytes(poolID), + Address.fromBytes(tokenID), + false, + amount, + event + ); + updatePoolHourlySnapshot(Address.fromBytes(poolID), event); + updatePoolDailySnapshot( + Address.fromBytes(poolID), + Address.fromBytes(tokenID), + false, + amount, + event + ); + updateUsageMetricsHourlySnapshot(Address.fromBytes(accountID), event); + updateUsageMetricsDailySnapshot( + Address.fromBytes(accountID), + false, + withdrawID, + event + ); + updateFinancialsDailySnapshot( + Address.fromBytes(tokenID), + false, + amount, + event + ); + updateWithdraw( + Address.fromBytes(accountID), + Address.fromBytes(tokenID), + withdrawID, + amount, + event + ); + } while ((withdraw = getWithdraw(depositorAddress, withdrawalRoot))); }