Skip to content

Commit

Permalink
fix: some corrections to totalDelegatedTokens and totalUnstakedTokens…
Browse files Browse the repository at this point in the history
…Locked
  • Loading branch information
pcarranzav authored and juanmardefago committed Feb 6, 2024
1 parent 7d79bc7 commit 936efd0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/mappings/rewardsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/mappings/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ 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)
indexer = calculateCapacities(indexer as Indexer)
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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 936efd0

Please sign in to comment.