Skip to content

Commit

Permalink
feat: added allocationCount and activeAllocationCount
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed Feb 5, 2024
1 parent 9229a49 commit c159807
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ type GraphNetwork @entity {
subgraphDeploymentCount: Int!
"Total epochs"
epochCount: Int!
"Total amount of allocations opened"
allocationCount: Int!
"Total amount of allocations currently active"
activeAllocationCount: Int!

# Dispute Manager global variables
"Dispute arbitrator"
Expand Down
2 changes: 2 additions & 0 deletions src/mappings/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ export function createOrLoadGraphNetwork(
graphNetwork.subgraphCount = 0
graphNetwork.subgraphDeploymentCount = 0
graphNetwork.activeSubgraphCount = 0
graphNetwork.allocationCount = 0
graphNetwork.activeAllocationCount = 0

graphNetwork.arbitrator = Address.fromString('0x0000000000000000000000000000000000000000')
graphNetwork.querySlashingPercentage = 0
Expand Down
3 changes: 3 additions & 0 deletions src/mappings/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ export function handleAllocationCreated(event: AllocationCreated): void {

// update graph network
graphNetwork.totalTokensAllocated = graphNetwork.totalTokensAllocated.plus(event.params.tokens)
graphNetwork.allocationCount = graphNetwork.allocationCount + 1
graphNetwork.activeAllocationCount = graphNetwork.activeAllocationCount + 1
graphNetwork.save()

// update subgraph deployment
Expand Down Expand Up @@ -519,6 +521,7 @@ export function handleAllocationClosed(event: AllocationClosed): void {
deployment.save()

// update graph network
graphNetwork.activeAllocationCount = graphNetwork.activeAllocationCount - 1
graphNetwork.totalTokensAllocated = graphNetwork.totalTokensAllocated.minus(event.params.tokens)
graphNetwork.save()
}
Expand Down

0 comments on commit c159807

Please sign in to comment.