diff --git a/subgraph/package.json b/subgraph/package.json index 304dd86e..c4f4686b 100644 --- a/subgraph/package.json +++ b/subgraph/package.json @@ -43,7 +43,7 @@ "create:arbitrum-one": "source .env && graph create --node $DEPLOY_ENDPOINT_ARBITRUM_GOERLI Consensys/verax-arbitrum", "deploy:linea-mainnet": "source .env && cp subgraph.linea-mainnet.yaml subgraph.yaml && graph deploy --studio $SUBGRAPH_NAME_LINEA_MAINNET", "deploy:linea-goerli": "source .env && cp subgraph.linea-goerli.yaml subgraph.yaml && graph deploy --studio $SUBGRAPH_NAME_LINEA_GOERLI", - "deploy:linea-sepolia": "source .env && cp subgraph.linea-sepolia.yaml subgraph.yaml && graph deploy --studio $SUBGRAPH_NAME_LINEA_SEPOLIA", + "deploy:linea-sepolia": "source .env && cp subgraph.linea-sepolia.yaml subgraph.yaml && graph deploy --headers \"{\\\"Authorization\\\": \\\"Basic $IPFS_IDENTIFIERS\\\"}\" --ipfs $IPFS_ENDPOINT --version-label v0.0.1 --studio $SUBGRAPH_NAME_LINEA_SEPOLIA", "deploy:base-sepolia": "source .env && cp subgraph.base-sepolia.yaml subgraph.yaml && graph deploy --studio $SUBGRAPH_NAME_BASE_SEPOLIA", "deploy:base": "source .env && cp subgraph.base.yaml subgraph.yaml && graph deploy --studio $SUBGRAPH_NAME_BASE", "deploy:arbitrum-goerli": "source .env && cp subgraph.arbitrum-goerli.yaml subgraph.yaml && graph deploy --network arbitrum-goerli --node $DEPLOY_ENDPOINT_ARBITRUM_GOERLI --headers \"{\\\"Authorization\\\": \\\"Basic $IPFS_IDENTIFIERS\\\"}\" --ipfs $IPFS_ENDPOINT --version-label v0.0.5 Consensys/verax-arbitrum-goerli", diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index c7c47963..3f2f98f5 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -1,9 +1,9 @@ type Attestation @entity { id: ID! - schema: Schema! + schemaId: Bytes! replacedBy: Bytes! attester: Bytes! - portal: Portal! + portal: Bytes! attestedDate: BigInt! expirationDate: BigInt! revocationDate: BigInt! @@ -12,8 +12,8 @@ type Attestation @entity { subject: Bytes! encodedSubject: Bytes! attestationData: Bytes! + schemaString: String decodedData: [String!] - auditInformation: AuditInformation! } type Module @entity { @@ -21,7 +21,6 @@ type Module @entity { moduleAddress: Bytes! name: String! description: String! - auditInformation: AuditInformation! } type Portal @entity { @@ -33,7 +32,6 @@ type Portal @entity { description: String! ownerName: String! attestationCounter: Int - auditInformation: AuditInformation! } type Schema @entity { @@ -43,7 +41,6 @@ type Schema @entity { context: String! schema: String! attestationCounter: Int - auditInformation: AuditInformation! } type Counter @entity { @@ -56,30 +53,10 @@ type Counter @entity { type Issuer @entity { id: ID! - auditInformation: AuditInformation! } type RegistryVersion @entity { id: ID! versionNumber: Int timestamp: BigInt - auditInformation: AuditInformation! -} - -type AuditInformation @entity { - id: ID! - creation: Audit! - lastModification: Audit! - modifications: [Audit!]! -} - -type Audit @entity { - id: ID! - blockNumber: BigInt! - transactionHash: Bytes! - transactionTimestamp: BigInt! - fromAddress: Bytes! - toAddress: Bytes - valueTransferred: BigInt - gasPrice: BigInt } diff --git a/subgraph/src/attestation-registry.ts b/subgraph/src/attestation-registry.ts index 9efa75d3..56c07b44 100644 --- a/subgraph/src/attestation-registry.ts +++ b/subgraph/src/attestation-registry.ts @@ -5,38 +5,20 @@ import { AttestationRevoked, VersionUpdated, } from "../generated/AttestationRegistry/AttestationRegistry"; -import { Attestation, Audit, AuditInformation, Counter, Portal, RegistryVersion, Schema } from "../generated/schema"; +import { Attestation, Counter, Portal, RegistryVersion, Schema } from "../generated/schema"; import { BigInt, ByteArray, Bytes, ethereum } from "@graphprotocol/graph-ts"; export function handleAttestationRegistered(event: AttestationRegisteredEvent): void { const attestationRegistryContract = AttestationRegistry.bind(event.address); const attestationData = attestationRegistryContract.getAttestation(event.params.attestationId); - const attestation = new Attestation(event.params.attestationId.toHexString().toLowerCase()); + const attestation = new Attestation(event.params.attestationId.toHex()); - const audit = new Audit(event.transaction.hash.toHexString().toLowerCase()); - audit.blockNumber = event.block.number; - audit.transactionHash = event.transaction.hash; - audit.transactionTimestamp = event.block.timestamp; - audit.fromAddress = event.transaction.from; - audit.toAddress = event.transaction.to; - audit.valueTransferred = event.transaction.value; - audit.gasPrice = event.transaction.gasPrice; - - audit.save(); - - const auditInformation = new AuditInformation(attestation.id); - auditInformation.creation = audit.id.toLowerCase(); - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications = [audit.id.toLowerCase()]; - - auditInformation.save(); - - attestation.auditInformation = auditInformation.id.toLowerCase(); - - incrementAttestationCount(attestationData.portal.toHexString(), attestationData.schemaId.toHexString()); + incrementAttestationCount(attestationData.portal.toHexString(), attestationData.schemaId.toHex()); + attestation.schemaId = attestationData.schemaId; attestation.replacedBy = attestationData.replacedBy; attestation.attester = attestationData.attester; + attestation.portal = attestationData.portal; attestation.attestedDate = attestationData.attestedDate; attestation.expirationDate = attestationData.expirationDate; attestation.revocationDate = attestationData.revocationDate; @@ -44,15 +26,13 @@ export function handleAttestationRegistered(event: AttestationRegisteredEvent): attestation.revoked = attestationData.revoked; attestation.encodedSubject = attestationData.subject; attestation.attestationData = attestationData.attestationData; - attestation.schema = attestationData.schemaId.toHexString().toLowerCase(); - attestation.portal = attestationData.portal.toHexString().toLowerCase(); // If the subject looks like an encoded address, decode it to an address const tempSubject = ethereum.decode("address", attestationData.subject); attestation.subject = tempSubject ? tempSubject.toAddress() : attestationData.subject; - // Get matching Schemax - const schema = Schema.load(attestation.schema); + // Get matching Schema + const schema = Schema.load(attestationData.schemaId.toHex()); if (schema) { // Split Schema into a "type fieldName" array @@ -64,6 +44,9 @@ export function handleAttestationRegistered(event: AttestationRegisteredEvent): // Join the types in a single coma-separated string const schemaString = schemaTypes.toString(); + // Add this Schema string to the Attestation Entity + attestation.schemaString = schemaString; + const encodedData = attestationData.attestationData; // Initiate the decoded data in case it's not decoded at all @@ -110,64 +93,20 @@ export function handleAttestationRegistered(event: AttestationRegisteredEvent): export function handleAttestationRevoked(event: AttestationRevoked): void { const attestationRegistryContract = AttestationRegistry.bind(event.address); const attestationData = attestationRegistryContract.getAttestation(event.params.attestationId); - const attestation = Attestation.load(event.params.attestationId.toHexString().toLowerCase()); + const attestation = Attestation.load(event.params.attestationId.toHex()); if (attestation) { attestation.revoked = true; attestation.revocationDate = attestationData.revocationDate; - - const audit = new Audit(event.transaction.hash.toHexString().toLowerCase()); - audit.blockNumber = event.block.number; - audit.transactionHash = event.transaction.hash; - audit.transactionTimestamp = event.block.timestamp; - audit.fromAddress = event.transaction.from; - audit.toAddress = event.transaction.to; - audit.valueTransferred = event.transaction.value; - audit.gasPrice = event.transaction.gasPrice; - - audit.save(); - - const auditInformation = AuditInformation.load(attestation.id); - if (auditInformation !== null) { - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications.push(audit.id.toLowerCase()); - - auditInformation.save(); - - attestation.auditInformation = auditInformation.id.toLowerCase(); - } - attestation.save(); } } export function handleAttestationReplaced(event: AttestationReplaced): void { - const attestation = Attestation.load(event.params.attestationId.toHexString().toLowerCase()); + const attestation = Attestation.load(event.params.attestationId.toHex()); if (attestation) { attestation.replacedBy = event.params.replacedBy; - - const audit = new Audit(event.transaction.hash.toHexString().toLowerCase()); - audit.blockNumber = event.block.number; - audit.transactionHash = event.transaction.hash; - audit.transactionTimestamp = event.block.timestamp; - audit.fromAddress = event.transaction.from; - audit.toAddress = event.transaction.to; - audit.valueTransferred = event.transaction.value; - audit.gasPrice = event.transaction.gasPrice; - - audit.save(); - - const auditInformation = AuditInformation.load(attestation.id); - if (auditInformation !== null) { - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications.push(audit.id.toLowerCase()); - - auditInformation.save(); - - attestation.auditInformation = auditInformation.id.toLowerCase(); - } - attestation.save(); } } @@ -179,32 +118,6 @@ export function handleVersionUpdated(event: VersionUpdated): void { registryVersion = new RegistryVersion("registry-version"); } - const audit = new Audit(event.transaction.hash.toHexString().toLowerCase()); - audit.blockNumber = event.block.number; - audit.transactionHash = event.transaction.hash; - audit.transactionTimestamp = event.block.timestamp; - audit.fromAddress = event.transaction.from; - audit.toAddress = event.transaction.to; - audit.valueTransferred = event.transaction.value; - audit.gasPrice = event.transaction.gasPrice; - - audit.save(); - - let auditInformation = AuditInformation.load(registryVersion.id); - if (auditInformation === null) { - auditInformation = new AuditInformation(registryVersion.id); - auditInformation.creation = audit.id.toLowerCase(); - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications = [audit.id.toLowerCase()]; - } else { - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications.push(audit.id.toLowerCase()); - } - - auditInformation.save(); - - registryVersion.auditInformation = auditInformation.id.toLowerCase(); - registryVersion.versionNumber = event.params.version; registryVersion.timestamp = event.block.timestamp; @@ -216,7 +129,7 @@ function valueToString(value: ethereum.Value): string { case ethereum.ValueKind.ADDRESS: return value.toAddress().toHexString(); case ethereum.ValueKind.FIXED_BYTES: - return value.toBytes().toHexString().toLowerCase(); + return value.toBytes().toHex(); case ethereum.ValueKind.BYTES: return value.toString(); case ethereum.ValueKind.INT: diff --git a/subgraph/src/module-registry.ts b/subgraph/src/module-registry.ts index fe97f9b9..612dd9f6 100644 --- a/subgraph/src/module-registry.ts +++ b/subgraph/src/module-registry.ts @@ -1,28 +1,8 @@ import { ModuleRegistered as ModuleRegisteredEvent } from "../generated/ModuleRegistry/ModuleRegistry"; -import { Audit, AuditInformation, Counter, Module } from "../generated/schema"; +import { Counter, Module } from "../generated/schema"; export function handleModuleRegistered(event: ModuleRegisteredEvent): void { - const module = new Module(event.params.moduleAddress.toHexString().toLowerCase()); - - const audit = new Audit(event.transaction.hash.toHexString().toLowerCase()); - audit.blockNumber = event.block.number; - audit.transactionHash = event.transaction.hash; - audit.transactionTimestamp = event.block.timestamp; - audit.fromAddress = event.transaction.from; - audit.toAddress = event.transaction.to; - audit.valueTransferred = event.transaction.value; - audit.gasPrice = event.transaction.gasPrice; - - audit.save(); - - const auditInformation = new AuditInformation(module.id); - auditInformation.creation = audit.id.toLowerCase(); - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications = [audit.id.toLowerCase()]; - - auditInformation.save(); - - module.auditInformation = auditInformation.id.toLowerCase(); + const module = new Module(event.params.moduleAddress.toHexString()); incrementModulesCount(); diff --git a/subgraph/src/portal-registry.ts b/subgraph/src/portal-registry.ts index 45e162b0..445bbd72 100644 --- a/subgraph/src/portal-registry.ts +++ b/subgraph/src/portal-registry.ts @@ -4,34 +4,13 @@ import { IssuerRemoved, PortalRegistered as PortalRegisteredEvent, PortalRegistry, - PortalRevoked as PortalRevokedEvent, } from "../generated/PortalRegistry/PortalRegistry"; -import { Audit, AuditInformation, Counter, Issuer, Portal } from "../generated/schema"; +import { Counter, Issuer, 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.toHexString().toLowerCase()); - - const audit = new Audit(event.transaction.hash.toHexString().toLowerCase()); - audit.blockNumber = event.block.number; - audit.transactionHash = event.transaction.hash; - audit.transactionTimestamp = event.block.timestamp; - audit.fromAddress = event.transaction.from; - audit.toAddress = event.transaction.to; - audit.valueTransferred = event.transaction.value; - audit.gasPrice = event.transaction.gasPrice; - - audit.save(); - - const auditInformation = new AuditInformation(portal.id); - auditInformation.creation = audit.id.toLowerCase(); - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications = [audit.id.toLowerCase()]; - - auditInformation.save(); - - portal.auditInformation = auditInformation.id.toLowerCase(); + const portal = new Portal(event.params.portalAddress.toHexString()); incrementPortalsCount(); @@ -46,46 +25,8 @@ export function handlePortalRegistered(event: PortalRegisteredEvent): void { portal.save(); } -export function handlePortalRevoked(event: PortalRevokedEvent): void { - const portalId = event.params.portalAddress.toHexString(); - const portal = Portal.load(portalId); - - if (portal != null) { - // Delete the Portal entity - store.remove("Portal", portalId); - } - - const auditInformation = AuditInformation.load(portalId); - - if (auditInformation != null) { - // Delete the AuditInformation entity - store.remove("AuditInformation", portalId); - } -} - export function handleIssuerAdded(event: IssuerAdded): void { const issuer = new Issuer(event.params.issuerAddress.toHexString()); - - const audit = new Audit(event.transaction.hash.toHexString().toLowerCase()); - audit.blockNumber = event.block.number; - audit.transactionHash = event.transaction.hash; - audit.transactionTimestamp = event.block.timestamp; - audit.fromAddress = event.transaction.from; - audit.toAddress = event.transaction.to; - audit.valueTransferred = event.transaction.value; - audit.gasPrice = event.transaction.gasPrice; - - audit.save(); - - const auditInformation = new AuditInformation(issuer.id); - auditInformation.creation = audit.id.toLowerCase(); - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications = [audit.id.toLowerCase()]; - - auditInformation.save(); - - issuer.auditInformation = auditInformation.id.toLowerCase(); - issuer.save(); } @@ -97,13 +38,6 @@ export function handleIssuerRemoved(event: IssuerRemoved): void { // Delete the Issuer entity store.remove("Issuer", issuerId); } - - const auditInformation = AuditInformation.load(issuerId); - - if (auditInformation != null) { - // Delete the AuditInformation entity - store.remove("AuditInformation", issuerId); - } } function incrementPortalsCount(): void { diff --git a/subgraph/src/schema-registry.ts b/subgraph/src/schema-registry.ts index 0fc27cdd..6b93c4b4 100644 --- a/subgraph/src/schema-registry.ts +++ b/subgraph/src/schema-registry.ts @@ -3,31 +3,11 @@ import { SchemaCreated as SchemaCreatedEvent, SchemaRegistry, } from "../generated/SchemaRegistry/SchemaRegistry"; -import { Audit, AuditInformation, Counter, Schema } from "../generated/schema"; +import { Counter, Schema } from "../generated/schema"; export function handleSchemaCreated(event: SchemaCreatedEvent): void { const schema = new Schema(event.params.id.toHexString()); - const audit = new Audit(event.transaction.hash.toHexString().toLowerCase()); - audit.blockNumber = event.block.number; - audit.transactionHash = event.transaction.hash; - audit.transactionTimestamp = event.block.timestamp; - audit.fromAddress = event.transaction.from; - audit.toAddress = event.transaction.to; - audit.valueTransferred = event.transaction.value; - audit.gasPrice = event.transaction.gasPrice; - - audit.save(); - - const auditInformation = new AuditInformation(schema.id); - auditInformation.creation = audit.id.toLowerCase(); - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications = [audit.id.toLowerCase()]; - - auditInformation.save(); - - schema.auditInformation = auditInformation.id.toLowerCase(); - incrementSchemasCount(); schema.name = event.params.name; @@ -46,27 +26,6 @@ export function handleSchemaContextUpdated(event: SchemaContextUpdated): void { const schema = Schema.load(event.params.id.toHexString()); if (schema !== null) { - const audit = new Audit(event.transaction.hash.toHexString().toLowerCase()); - audit.blockNumber = event.block.number; - audit.transactionHash = event.transaction.hash; - audit.transactionTimestamp = event.block.timestamp; - audit.fromAddress = event.transaction.from; - audit.toAddress = event.transaction.to; - audit.valueTransferred = event.transaction.value; - audit.gasPrice = event.transaction.gasPrice; - - audit.save(); - - const auditInformation = AuditInformation.load(schema.id); - if (auditInformation !== null) { - auditInformation.lastModification = audit.id.toLowerCase(); - auditInformation.modifications.push(audit.id.toLowerCase()); - - auditInformation.save(); - - schema.auditInformation = auditInformation.id.toLowerCase(); - } - schema.context = newContext; schema.save(); } diff --git a/subgraph/subgraph.base-sepolia.yaml b/subgraph/subgraph.base-sepolia.yaml index 7a7878d7..edc3953c 100644 --- a/subgraph/subgraph.base-sepolia.yaml +++ b/subgraph/subgraph.base-sepolia.yaml @@ -67,8 +67,6 @@ dataSources: eventHandlers: - event: PortalRegistered(string,string,address) handler: handlePortalRegistered - - event: PortalRevoked(address) - handler: handlePortalRevoked - event: IssuerAdded(address) handler: handleIssuerAdded - event: IssuerRemoved(address) diff --git a/subgraph/subgraph.base.yaml b/subgraph/subgraph.base.yaml index f8a60a1d..154c6a41 100644 --- a/subgraph/subgraph.base.yaml +++ b/subgraph/subgraph.base.yaml @@ -67,8 +67,6 @@ dataSources: eventHandlers: - event: PortalRegistered(string,string,address) handler: handlePortalRegistered - - event: PortalRevoked(address) - handler: handlePortalRevoked - event: IssuerAdded(address) handler: handleIssuerAdded - event: IssuerRemoved(address) diff --git a/subgraph/subgraph.linea-sepolia.yaml b/subgraph/subgraph.linea-sepolia.yaml index 4c21d5b7..7b5cc92d 100644 --- a/subgraph/subgraph.linea-sepolia.yaml +++ b/subgraph/subgraph.linea-sepolia.yaml @@ -67,8 +67,6 @@ dataSources: eventHandlers: - event: PortalRegistered(string,string,address) handler: handlePortalRegistered - - event: PortalRevoked(address) - handler: handlePortalRevoked - event: IssuerAdded(address) handler: handleIssuerAdded - event: IssuerRemoved(address)