Skip to content

Commit

Permalink
Deploy Subgraph V1
Browse files Browse the repository at this point in the history
  • Loading branch information
alainncls committed Apr 26, 2024
1 parent 01d701a commit 2655741
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 265 deletions.
2 changes: 1 addition & 1 deletion subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 3 additions & 26 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
@@ -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!
Expand All @@ -12,16 +12,15 @@ type Attestation @entity {
subject: Bytes!
encodedSubject: Bytes!
attestationData: Bytes!
schemaString: String
decodedData: [String!]
auditInformation: AuditInformation!
}

type Module @entity {
id: ID!
moduleAddress: Bytes!
name: String!
description: String!
auditInformation: AuditInformation!
}

type Portal @entity {
Expand All @@ -33,7 +32,6 @@ type Portal @entity {
description: String!
ownerName: String!
attestationCounter: Int
auditInformation: AuditInformation!
}

type Schema @entity {
Expand All @@ -43,7 +41,6 @@ type Schema @entity {
context: String!
schema: String!
attestationCounter: Int
auditInformation: AuditInformation!
}

type Counter @entity {
Expand All @@ -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
}
113 changes: 13 additions & 100 deletions subgraph/src/attestation-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,34 @@ 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;
attestation.version = BigInt.fromI32(attestationData.version);
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
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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;

Expand All @@ -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:
Expand Down
24 changes: 2 additions & 22 deletions subgraph/src/module-registry.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
70 changes: 2 additions & 68 deletions subgraph/src/portal-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();
}

Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 2655741

Please sign in to comment.