From c15980779c2a62dc8ba46484e3ffee7983294919 Mon Sep 17 00:00:00 2001 From: juanmardefago Date: Wed, 31 Jan 2024 19:32:47 -0300 Subject: [PATCH] feat: added allocationCount and activeAllocationCount --- schema.graphql | 4 ++++ src/mappings/helpers/helpers.ts | 2 ++ src/mappings/staking.ts | 3 +++ 3 files changed, 9 insertions(+) diff --git a/schema.graphql b/schema.graphql index 9059fbaf..3f59a528 100644 --- a/schema.graphql +++ b/schema.graphql @@ -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" diff --git a/src/mappings/helpers/helpers.ts b/src/mappings/helpers/helpers.ts index 454e2c45..f40b8752 100644 --- a/src/mappings/helpers/helpers.ts +++ b/src/mappings/helpers/helpers.ts @@ -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 diff --git a/src/mappings/staking.ts b/src/mappings/staking.ts index 7fff1bdf..d72faaf7 100644 --- a/src/mappings/staking.ts +++ b/src/mappings/staking.ts @@ -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 @@ -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() }