diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index 9ceb0218..ebd79b9b 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -39,3 +39,11 @@ type Schema @entity { context: String! schema: String! } + +type Counter @entity{ + id: ID! + attestations: Int + modules: Int + portals: Int + schemas: Int +} diff --git a/subgraph/src/attestation-registry.ts b/subgraph/src/attestation-registry.ts index 2670be2d..c9cdef20 100644 --- a/subgraph/src/attestation-registry.ts +++ b/subgraph/src/attestation-registry.ts @@ -2,7 +2,7 @@ import { AttestationRegistered as AttestationRegisteredEvent, AttestationRegistry, } from "../generated/AttestationRegistry/AttestationRegistry"; -import { Attestation, Schema } from "../generated/schema"; +import { Attestation, Counter, Schema } from "../generated/schema"; import { BigInt, ByteArray, Bytes, ethereum } from "@graphprotocol/graph-ts"; export function handleAttestationRegistered(event: AttestationRegisteredEvent): void { @@ -10,6 +10,8 @@ export function handleAttestationRegistered(event: AttestationRegisteredEvent): const attestationData = attestationRegistryContract.getAttestation(event.params.attestationId); const attestation = new Attestation(event.params.attestationId.toHex()); + incrementAttestationCount(); + attestation.schemaId = attestationData.schemaId; attestation.replacedBy = attestationData.replacedBy; attestation.attester = attestationData.attester; @@ -110,3 +112,19 @@ function valueToString(value: ethereum.Value): string { return "UNKNOWN TYPE"; } } + +function incrementAttestationCount(): void { + let counter = Counter.load("counter"); + + if (!counter) { + counter = new Counter("counter"); + } + + if (!counter.attestations) { + counter.attestations = 1; + } else { + counter.attestations += 1; + } + + counter.save(); +} diff --git a/subgraph/src/module-registry.ts b/subgraph/src/module-registry.ts index 448b7cb9..2b87823b 100644 --- a/subgraph/src/module-registry.ts +++ b/subgraph/src/module-registry.ts @@ -1,14 +1,32 @@ import { ModuleRegistered as ModuleRegisteredEvent, ModuleRegistry } from "../generated/ModuleRegistry/ModuleRegistry"; -import { Module } from "../generated/schema"; +import { Counter, Module } from "../generated/schema"; export function handleModuleRegistered(event: ModuleRegisteredEvent): void { const contract = ModuleRegistry.bind(event.address); const moduleData = contract.modules(event.params.moduleAddress); const module = new Module(event.params.moduleAddress.toHex()); + incrementModulesCount(); + module.moduleAddress = moduleData.getModuleAddress(); module.name = moduleData.getName(); module.description = moduleData.getDescription(); module.save(); } + +function incrementModulesCount(): void { + let counter = Counter.load("counter"); + + if (!counter) { + counter = new Counter("counter"); + } + + if (!counter.modules) { + counter.modules = 1; + } else { + counter.modules += 1; + } + + counter.save(); +} diff --git a/subgraph/src/portal-registry.ts b/subgraph/src/portal-registry.ts index fc2beb0c..f8b3ae22 100644 --- a/subgraph/src/portal-registry.ts +++ b/subgraph/src/portal-registry.ts @@ -1,12 +1,14 @@ import { Bytes } from "@graphprotocol/graph-ts"; import { PortalRegistered as PortalRegisteredEvent, PortalRegistry } from "../generated/PortalRegistry/PortalRegistry"; -import { Portal } from "../generated/schema"; +import { Counter, Portal } from "../generated/schema"; export function handlePortalRegistered(event: PortalRegisteredEvent): void { const contract = PortalRegistry.bind(event.address); const portalData = contract.getPortalByAddress(event.params.portalAddress); const portal = new Portal(event.params.portalAddress.toHex()); + incrementPortalsCount(); + portal.ownerAddress = portalData.ownerAddress; portal.modules = changetype(portalData.modules); portal.isRevocable = portalData.isRevocable; @@ -16,3 +18,19 @@ export function handlePortalRegistered(event: PortalRegisteredEvent): void { portal.save(); } + +function incrementPortalsCount(): void { + let counter = Counter.load("counter"); + + if (!counter) { + counter = new Counter("counter"); + } + + if (!counter.portals) { + counter.portals = 1; + } else { + counter.portals += 1; + } + + counter.save(); +} diff --git a/subgraph/src/schema-registry.ts b/subgraph/src/schema-registry.ts index 780f7c1b..816e5e6a 100644 --- a/subgraph/src/schema-registry.ts +++ b/subgraph/src/schema-registry.ts @@ -1,11 +1,13 @@ import { SchemaCreated as SchemaCreatedEvent, SchemaRegistry } from "../generated/SchemaRegistry/SchemaRegistry"; -import { Schema } from "../generated/schema"; +import { Counter, Schema } from "../generated/schema"; export function handleSchemaCreated(event: SchemaCreatedEvent): void { const contract = SchemaRegistry.bind(event.address); const schemaData = contract.getSchema(event.params.id); const schema = new Schema(event.params.id.toHex()); + incrementSchemasCount(); + schema.name = schemaData.name; schema.description = schemaData.description; schema.context = schemaData.context; @@ -13,3 +15,19 @@ export function handleSchemaCreated(event: SchemaCreatedEvent): void { schema.save(); } + +function incrementSchemasCount(): void { + let counter = Counter.load("counter"); + + if (!counter) { + counter = new Counter("counter"); + } + + if (!counter.schemas) { + counter.schemas = 1; + } else { + counter.schemas += 1; + } + + counter.save(); +}