Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: totalDelegatedTokens and totalUnstakedLockedTokens #260

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mappings/rewardsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function handleRewardsAssigned(event: RewardsAssigned): void {
graphNetwork.totalIndexingDelegatorRewards = graphNetwork.totalIndexingDelegatorRewards.plus(
delegatorIndexingRewards,
)
graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.plus(delegatorIndexingRewards)
graphNetwork.save()
}

Expand Down
7 changes: 6 additions & 1 deletion src/mappings/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,19 @@ 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
graphNetwork.totalUnstakedTokensLocked = graphNetwork.totalUnstakedTokensLocked.plus(
event.params.tokens,
)
).minus(oldLockedTokens)
if (indexer.stakedTokens == indexer.lockedTokens) {
graphNetwork.stakedIndexersCount = graphNetwork.stakedIndexersCount - 1
}
Expand Down Expand Up @@ -659,6 +662,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()
}

Expand Down Expand Up @@ -742,6 +746,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()
}

Expand Down
Loading