From 936efd01c11cc48986ac2c7d25451d8ccceaa96d Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Tue, 6 Feb 2024 12:34:53 -0300 Subject: [PATCH] fix: some corrections to totalDelegatedTokens and totalUnstakedTokensLocked --- src/mappings/rewardsManager.ts | 1 + src/mappings/staking.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mappings/rewardsManager.ts b/src/mappings/rewardsManager.ts index d835038..beaebba 100644 --- a/src/mappings/rewardsManager.ts +++ b/src/mappings/rewardsManager.ts @@ -80,6 +80,7 @@ export function handleRewardsAssigned(event: RewardsAssigned): void { graphNetwork.totalIndexingDelegatorRewards = graphNetwork.totalIndexingDelegatorRewards.plus( delegatorIndexingRewards, ) + graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.plus(delegatorIndexingRewards) graphNetwork.save() batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp) diff --git a/src/mappings/staking.ts b/src/mappings/staking.ts index 03803d8..3ac9cbb 100644 --- a/src/mappings/staking.ts +++ b/src/mappings/staking.ts @@ -105,6 +105,7 @@ export function handleStakeLocked(event: StakeLocked): void { // update indexer let id = event.params.indexer.toHexString() let indexer = Indexer.load(id)! + let oldLockedTokens = indexer.lockedTokens indexer.lockedTokens = event.params.tokens indexer.tokensLockedUntil = event.params.until.toI32() indexer = updateAdvancedIndexerMetrics(indexer as Indexer) @@ -112,10 +113,12 @@ export function handleStakeLocked(event: StakeLocked): void { indexer.save() // update graph network + // the tokens from the event replace the previously locked tokens + // from this indexer let graphNetwork = createOrLoadGraphNetwork() graphNetwork.totalUnstakedTokensLocked = graphNetwork.totalUnstakedTokensLocked.plus( event.params.tokens, - ) + ).minus(oldLockedTokens) if (indexer.stakedTokens == indexer.lockedTokens) { graphNetwork.stakedIndexersCount = graphNetwork.stakedIndexersCount - 1 } @@ -710,6 +713,7 @@ export function handleRebateClaimed(event: RebateClaimed): void { graphNetwork.totalUnclaimedQueryFeeRebates = graphNetwork.totalUnclaimedQueryFeeRebates.minus( event.params.delegationFees.plus(event.params.tokens), ) + graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.plus(event.params.delegationFees) graphNetwork.save() batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp) @@ -817,6 +821,7 @@ export function handleRebateCollected(event: RebateCollected): void { graphNetwork.totalUnclaimedQueryFeeRebates = graphNetwork.totalUnclaimedQueryFeeRebates.minus( event.params.delegationRewards.plus(event.params.queryRebates), ) + graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.plus(event.params.delegationRewards) graphNetwork.save() batchUpdateDelegatorsForIndexer(indexer.id, event.block.timestamp)