From b020292b15717681720399c23b510cb0b4c1cb0a Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Mon, 29 Jan 2024 12:44:56 -0300 Subject: [PATCH 1/2] fix: track total delegated tokens changes when rewards or fees are collected --- src/mappings/rewardsManager.ts | 1 + src/mappings/staking.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/mappings/rewardsManager.ts b/src/mappings/rewardsManager.ts index a83eee3d..443b127d 100644 --- a/src/mappings/rewardsManager.ts +++ b/src/mappings/rewardsManager.ts @@ -85,6 +85,7 @@ export function handleRewardsAssigned(event: RewardsAssigned): void { graphNetwork.totalIndexingDelegatorRewards = graphNetwork.totalIndexingDelegatorRewards.plus( delegatorIndexingRewards, ) + graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.plus(delegatorIndexingRewards) graphNetwork.save() } diff --git a/src/mappings/staking.ts b/src/mappings/staking.ts index ce70b653..1cd7d5e9 100644 --- a/src/mappings/staking.ts +++ b/src/mappings/staking.ts @@ -659,6 +659,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() } @@ -742,6 +743,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() } From b9001b3d7e135e82101e65369629e8913009e6ba Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Mon, 29 Jan 2024 16:47:00 -0300 Subject: [PATCH 2/2] fix: subtract previously locked tokens when computing total unstaked locked --- src/mappings/staking.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mappings/staking.ts b/src/mappings/staking.ts index 1cd7d5e9..7fff1bdf 100644 --- a/src/mappings/staking.ts +++ b/src/mappings/staking.ts @@ -103,6 +103,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) @@ -110,9 +111,11 @@ export function handleStakeLocked(event: StakeLocked): void { indexer.save() // update graph network + // the tokens from the event replace the previously locked tokens + // from this indexer graphNetwork.totalUnstakedTokensLocked = graphNetwork.totalUnstakedTokensLocked.plus( event.params.tokens, - ) + ).minus(oldLockedTokens) if (indexer.stakedTokens == indexer.lockedTokens) { graphNetwork.stakedIndexersCount = graphNetwork.stakedIndexersCount - 1 }