From d2494c8bd4fad24056252eb8125ce6618b977706 Mon Sep 17 00:00:00 2001 From: Eduard Dumea Date: Mon, 18 Aug 2025 22:53:40 +0300 Subject: [PATCH 1/2] add support for DataRegistry.FileAddedV2 event --- abis/v3/DataRegistryImplementation.json | 322 ++++++++++++++++++ src/lib/contract/v3/data-registry.ts | 14 + src/lib/contract/v5/dlp-registry.ts | 142 -------- src/mapping.ts.template | 3 - subgraph.moksha.yaml | 13 +- subgraph.vana-moksha.yaml | 26 +- subgraph.vana.yaml | 13 +- tests/unit/contract/v3/data-registry.test.ts | 64 +++- .../contract/v3/utils/data-registry-events.ts | 30 +- 9 files changed, 438 insertions(+), 189 deletions(-) delete mode 100644 src/lib/contract/v5/dlp-registry.ts diff --git a/abis/v3/DataRegistryImplementation.json b/abis/v3/DataRegistryImplementation.json index 9c73834..8e228b3 100644 --- a/abis/v3/DataRegistryImplementation.json +++ b/abis/v3/DataRegistryImplementation.json @@ -67,6 +67,11 @@ "name": "FailedInnerCall", "type": "error" }, + { + "inputs": [], + "name": "FileNotFound", + "type": "error" + }, { "inputs": [], "name": "FileUrlAlreadyUsed", @@ -77,6 +82,27 @@ "name": "InvalidInitialization", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "schemaId", + "type": "uint256" + } + ], + "name": "InvalidSchemaId", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidUrl", + "type": "error" + }, + { + "inputs": [], + "name": "NoPermission", + "type": "error" + }, { "inputs": [], "name": "NotFileOwner", @@ -128,6 +154,37 @@ "name": "FileAdded", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "ownerAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "url", + "type": "string" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "schemaId", + "type": "uint256" + } + ], + "name": "FileAddedV2", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -216,6 +273,56 @@ "name": "ProofAdded", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "refinerId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "url", + "type": "string" + } + ], + "name": "RefinementAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "refinerId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "url", + "type": "string" + } + ], + "name": "RefinementUpdated", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -343,6 +450,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "REFINEMENT_SERVICE_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "UPGRADE_INTERFACE_VERSION", @@ -439,6 +559,76 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "string", + "name": "url", + "type": "string" + }, + { + "internalType": "address", + "name": "ownerAddress", + "type": "address" + }, + { + "components": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "string", + "name": "key", + "type": "string" + } + ], + "internalType": "struct IDataRegistry.Permission[]", + "name": "permissions", + "type": "tuple[]" + }, + { + "internalType": "uint256", + "name": "schemaId", + "type": "uint256" + } + ], + "name": "addFileWithPermissionsAndSchema", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "url", + "type": "string" + }, + { + "internalType": "uint256", + "name": "schemaId", + "type": "uint256" + } + ], + "name": "addFileWithSchema", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -496,6 +686,65 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "refinerId", + "type": "uint256" + }, + { + "internalType": "string", + "name": "url", + "type": "string" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "string", + "name": "key", + "type": "string" + } + ], + "name": "addRefinementWithPermission", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "dataRefinerRegistry", + "outputs": [ + { + "internalType": "contract IDataRefinerRegistry", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "emitLegacyEvents", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -602,6 +851,30 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fileId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "refinerId", + "type": "uint256" + } + ], + "name": "fileRefinements", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -629,6 +902,11 @@ "name": "url", "type": "string" }, + { + "internalType": "uint256", + "name": "schemaId", + "type": "uint256" + }, { "internalType": "uint256", "name": "addedAtBlock", @@ -842,6 +1120,24 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "adminRole", + "type": "bytes32" + } + ], + "name": "setRoleAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -881,6 +1177,32 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "contract IDataRefinerRegistry", + "name": "newDataRefinerRegistry", + "type": "address" + } + ], + "name": "updateDataRefinerRegistry", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "newEmitLegacyEvents", + "type": "bool" + } + ], + "name": "updateEmitLegacyEvents", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/src/lib/contract/v3/data-registry.ts b/src/lib/contract/v3/data-registry.ts index 0202080..132e6eb 100644 --- a/src/lib/contract/v3/data-registry.ts +++ b/src/lib/contract/v3/data-registry.ts @@ -4,6 +4,7 @@ import { Epoch, PerformanceDlpEpochUser } from "../../../../generated/schema"; import { FileAdded as FileAddedEvent, + FileAddedV2 as FileAddedV2Event, ProofAdded as FileProofAdded, } from "../../../../generated/DataRegistryImplementationV3/DataRegistryImplementationV3"; import { getOrCreateTotalsForDlpEpochPerformance } from "../../entity/totals"; @@ -36,6 +37,19 @@ export function handleFileAddedV3(event: FileAddedEvent): void { ); } +export function handleFileAddedV2V3(event: FileAddedV2Event): void { + logDataRegistryEvent("FileAddedV2", event.transaction.hash.toHex()); + + createFileFromEvent( + event.params.fileId.toString(), + event.params.ownerAddress.toHex(), + event.params.url, + event.block, + event.transaction, + event.params.schemaId, + ); +} + export function handleDataRegistryProofAddedV3(event: FileProofAdded): void { logDataRegistryEvent("ProofAdded", event.transaction.hash.toHex()); diff --git a/src/lib/contract/v5/dlp-registry.ts b/src/lib/contract/v5/dlp-registry.ts deleted file mode 100644 index cc532a8..0000000 --- a/src/lib/contract/v5/dlp-registry.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { BigInt as GraphBigInt, log } from "@graphprotocol/graph-ts"; -import { - DlpRegistered, - DlpUpdated, - DlpStatusUpdated, - DlpVerificationBlockUpdated, - DlpTokenUpdated, -} from "../../../../generated/DLPRegistryImplementationV5/DLPRegistryImplementationV5"; - -import { Dlp } from "../../../../generated/schema"; -import { getOrCreateDlpList } from "../../../../src/lib/entity/dlp-list"; -import { getOrCreateDlp, getOrCreateUser } from "../shared"; - -// Mirrored from DLPRegistry.IDLPRegistry.DlpStatus -enum dlpStatus { - NONE = 0, - REGISTERED = 1, - ELIGIBLE = 2, - DEREGISTERED = 3, -} - -export function handleDlpRegisteredV5(event: DlpRegistered): void { - log.info("Handling DlpRegistered with transaction hash: {}", [ - event.transaction.hash.toHexString(), - ]); - - const dlpId = event.params.dlpId.toString(); - - // Ensure User entities exist for creator and owner - getOrCreateUser(event.transaction.from.toHex()); - getOrCreateUser(event.params.ownerAddress.toHex()); - - const dlp = getOrCreateDlp(event.params.dlpId.toString()); - - dlp.creator = event.transaction.from; - dlp.owner = event.params.ownerAddress; - dlp.address = event.params.dlpAddress; - dlp.treasury = event.params.treasuryAddress; - dlp.name = event.params.name; - dlp.iconUrl = event.params.iconUrl; - dlp.website = event.params.website; - dlp.metadata = event.params.metadata; - dlp.createdAt = event.block.timestamp; - dlp.createdTxHash = event.transaction.hash; - dlp.createdAtBlock = event.block.number; - dlp.status = GraphBigInt.fromI32(dlpStatus.REGISTERED); - - // Keep staking fields for backward compatibility but set to zero - dlp.performanceRating = GraphBigInt.zero(); - - dlp.save(); - - // Add to DLP list - const dlpList = getOrCreateDlpList(); - const dlpIds = dlpList.dlpIds; - if (!dlpIds.includes(dlpId)) { - const newDlpIds = dlpIds; - newDlpIds.push(dlpId); - dlpList.dlpIds = newDlpIds; - dlpList.save(); - } -} - -export function handleDlpUpdatedV5(event: DlpUpdated): void { - log.info("Handling DlpUpdated with transaction hash: {}", [ - event.transaction.hash.toHexString(), - ]); - - const dlpId = event.params.dlpId.toString(); - const dlp = Dlp.load(dlpId); - - if (dlp != null) { - // Ensure User entity exists for the new owner - getOrCreateUser(event.params.ownerAddress.toHex()); - - dlp.owner = event.params.ownerAddress; - dlp.address = event.params.dlpAddress; - dlp.treasury = event.params.treasuryAddress; - dlp.name = event.params.name; - dlp.iconUrl = event.params.iconUrl; - dlp.website = event.params.website; - dlp.metadata = event.params.metadata; - dlp.save(); - } else { - log.error("DLP not found during update: {}", [dlpId]); - } -} - -export function handleDlpStatusUpdatedV5(event: DlpStatusUpdated): void { - log.info("Handling DlpStatusUpdated with transaction hash: {}", [ - event.transaction.hash.toHexString(), - ]); - - const dlpId = event.params.dlpId.toString(); - const dlp = Dlp.load(dlpId); - - if (dlp != null) { - const newStatus = event.params.newStatus; - dlp.status = GraphBigInt.fromI32(newStatus); - - dlp.save(); - } else { - log.error("DLP not found during status update: {}", [dlpId]); - } -} - -export function handleDlpVerificationBlockUpdatedV5( - event: DlpVerificationBlockUpdated, -): void { - log.info("Handling DlpVerificationBlockUpdated with transaction hash: {}", [ - event.transaction.hash.toHexString(), - ]); - - const dlpId = event.params.dlpId.toString(); - const dlp = Dlp.load(dlpId); - - if (dlp != null) { - dlp.verificationBlockNumber = event.params.verificationBlockNumber; - dlp.save(); - } else { - log.error("DLP not found during verification update: {}", [dlpId]); - } -} - -export function handleDlpTokenUpdatedV5(event: DlpTokenUpdated): void { - log.info("Handling DlpTokenUpdated with transaction hash: {}", [ - event.transaction.hash.toHexString(), - ]); - - // Load DLP instead of creating it to handle non-existent DLP case gracefully - const dlp = Dlp.load(event.params.dlpId.toString()); - - if (dlp == null) { - log.error("DLP not found for token update: {}", [ - event.params.dlpId.toString(), - ]); - return; - } - - dlp.token = event.params.tokenAddress; - dlp.save(); -} diff --git a/src/mapping.ts.template b/src/mapping.ts.template index 5bb4b9f..03e39b9 100644 --- a/src/mapping.ts.template +++ b/src/mapping.ts.template @@ -70,9 +70,6 @@ export * from "./lib/contract/v4/data-refiner-registry"; {{/includes.v4.dataRefinerRegistry}} // V5 -{{#includes.v5.dlpRegistry}} -export * from "./lib/contract/v5/dlp-registry"; -{{/includes.v5.dlpRegistry}} {{#includes.v5.vanaEpoch}} export * from "./lib/contract/v5/vana-epoch"; {{/includes.v5.vanaEpoch}} diff --git a/subgraph.moksha.yaml b/subgraph.moksha.yaml index 6fba950..85f36f5 100644 --- a/subgraph.moksha.yaml +++ b/subgraph.moksha.yaml @@ -6,12 +6,11 @@ schema: file: ./schema.graphql # Stub for grafting on existing subgraphs -# -#features: -# - grafting -#graft: -# base: -# block: +features: + - grafting +graft: + base: QmUKB4EiXUJRKVnR1pGHsULHw9WTGGmbzuCZ5EsvQQmsWe + block: 3980000 dataSources: - kind: ethereum/contract @@ -108,6 +107,8 @@ dataSources: eventHandlers: - event: FileAdded(indexed uint256,indexed address,string) handler: handleFileAddedV3 + - event: FileAddedV2(indexed uint256,indexed address,string,uint256) + handler: handleFileAddedV2V3 - event: ProofAdded(indexed uint256,indexed address,uint256,indexed uint256,uint256,string) handler: handleDataRegistryProofAddedV3 file: ./src/mapping.ts diff --git a/subgraph.vana-moksha.yaml b/subgraph.vana-moksha.yaml index 4aee99f..5f0c335 100644 --- a/subgraph.vana-moksha.yaml +++ b/subgraph.vana-moksha.yaml @@ -108,6 +108,8 @@ dataSources: eventHandlers: - event: FileAdded(indexed uint256,indexed address,string) handler: handleFileAddedV3 + - event: FileAddedV2(indexed uint256,indexed address,string,uint256) + handler: handleFileAddedV2V3 - event: ProofAdded(indexed uint256,indexed address,uint256,indexed uint256,uint256,string) handler: handleDataRegistryProofAddedV3 file: ./src/mapping.ts @@ -319,30 +321,6 @@ dataSources: handler: handleServerUntrusted file: ./src/mapping.ts - - kind: ethereum/contract - name: DataRegistryImplementationV5 - network: vana-moksha - source: - address: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C" - abi: DataRegistryImplementationV5 - startBlock: 3425120 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - EpochReference - - DataRegistryProof - abis: - - name: DataRegistryImplementationV5 - file: ./abis/v5/DataRegistryImplementation.json - eventHandlers: - - event: FileAdded(indexed uint256,indexed address,string) - handler: handleFileAddedV3 - - event: ProofAdded(indexed uint256,indexed address,uint256,indexed uint256,uint256,string) - handler: handleDataRegistryProofAddedV3 - file: ./src/mapping.ts - - kind: ethereum/contract name: DataRefinerRegistryImplementationV6 network: vana-moksha diff --git a/subgraph.vana.yaml b/subgraph.vana.yaml index a218c08..7a6ef61 100644 --- a/subgraph.vana.yaml +++ b/subgraph.vana.yaml @@ -6,12 +6,11 @@ schema: file: ./schema.graphql # Stub for grafting on existing subgraphs -# -#features: -# - grafting -#graft: -# base: -# block: +features: + - grafting +graft: + base: QmXerEfZuoYS7KaogbEacn4Ff996R2PSS8xdPwQpeRbtpD + block: 4450000 dataSources: - kind: ethereum/contract @@ -107,6 +106,8 @@ dataSources: eventHandlers: - event: FileAdded(indexed uint256,indexed address,string) handler: handleFileAddedV3 + - event: FileAddedV2(indexed uint256,indexed address,string,uint256) + handler: handleFileAddedV2V3 - event: ProofAdded(indexed uint256,indexed address,uint256,indexed uint256,uint256,string) handler: handleDataRegistryProofAddedV3 file: ./src/mapping.ts diff --git a/tests/unit/contract/v3/data-registry.test.ts b/tests/unit/contract/v3/data-registry.test.ts index f8feac5..e8ca50e 100644 --- a/tests/unit/contract/v3/data-registry.test.ts +++ b/tests/unit/contract/v3/data-registry.test.ts @@ -9,9 +9,11 @@ import { import { handleDataRegistryProofAddedV3, handleFileAddedV3, + handleFileAddedV2V3, } from "../../../../src/lib/contract/v3/data-registry"; import { createFileAddedEvent, + createFileAddedV2Event, createProofAddedEvent, } from "./utils/data-registry-events"; import { @@ -272,7 +274,7 @@ describe("handleDataRegistryProofAddedV3", () => { }); describe("handleFileAddedV3", () => { - test("creates file owner entity", () => { + test("creates file entity with default schema", () => { const fileAddedEvent = createFileAddedEvent( 1, "0x334e8bbf9c7822fc3f66b11cb0d8ef84c5a4b5ce", @@ -281,15 +283,63 @@ describe("handleFileAddedV3", () => { handleFileAddedV3(fileAddedEvent); - // FileOwner - assert.entityCount("FileOwner", 1); + // File entity + assert.entityCount("File", 1); - const fileOwnerId = "1"; + const fileId = "1"; assert.fieldEquals( - "FileOwner", - fileOwnerId, - "ownerAddress", + "File", + fileId, + "owner", "0x334e8bbf9c7822fc3f66b11cb0d8ef84c5a4b5ce", ); + assert.fieldEquals( + "File", + fileId, + "url", + "https://www.some.com/storage/url", + ); + assert.fieldEquals( + "File", + fileId, + "schemaId", + "0", + ); + }); +}); + +describe("handleFileAddedV2V3", () => { + test("creates file entity with specified schema", () => { + const fileAddedV2Event = createFileAddedV2Event( + 2, + "0x334e8bbf9c7822fc3f66b11cb0d8ef84c5a4b5ce", + "https://www.example.com/data", + 42, // schemaId + ); + + handleFileAddedV2V3(fileAddedV2Event); + + // File entity + assert.entityCount("File", 1); + + const fileId = "2"; + assert.fieldEquals( + "File", + fileId, + "owner", + "0x334e8bbf9c7822fc3f66b11cb0d8ef84c5a4b5ce", + ); + assert.fieldEquals( + "File", + fileId, + "url", + "https://www.example.com/data", + ); + assert.fieldEquals( + "File", + fileId, + "schemaId", + "42", + ); }); }); diff --git a/tests/unit/contract/v3/utils/data-registry-events.ts b/tests/unit/contract/v3/utils/data-registry-events.ts index 4a30097..99de2ac 100644 --- a/tests/unit/contract/v3/utils/data-registry-events.ts +++ b/tests/unit/contract/v3/utils/data-registry-events.ts @@ -1,7 +1,8 @@ -import { Address, ethereum } from "@graphprotocol/graph-ts"; +import { Address, ethereum, BigInt as GraphBigInt } from "@graphprotocol/graph-ts"; import { newMockEvent } from "matchstick-as/assembly/index"; import { FileAdded as FileAddedEvent, + FileAddedV2 as FileAddedV2Event, ProofAdded as FileProofAdded, } from "../../../../../generated/DataRegistryImplementationV3/DataRegistryImplementationV3"; @@ -28,6 +29,33 @@ export function createFileAddedEvent( return fileAddedEvent; } +export function createFileAddedV2Event( + fileId: number, + ownerAddress: string, + url: string, + schemaId: number, +): FileAddedV2Event { + const normalizedAddr = ownerAddress.toLowerCase(); + const fileAddedV2Event = changetype(newMockEvent()); + fileAddedV2Event.parameters = new Array(); + fileAddedV2Event.parameters.push( + new ethereum.EventParam("fileId", ethereum.Value.fromI32(fileId)), + ); + fileAddedV2Event.parameters.push( + new ethereum.EventParam( + "ownerAddress", + ethereum.Value.fromAddress(Address.fromString(normalizedAddr)), + ), + ); + fileAddedV2Event.parameters.push( + new ethereum.EventParam("url", ethereum.Value.fromString(url)), + ); + fileAddedV2Event.parameters.push( + new ethereum.EventParam("schemaId", ethereum.Value.fromUnsignedBigInt(GraphBigInt.fromI32(schemaId))), + ); + return fileAddedV2Event; +} + export function createProofAddedEvent( fileId: number, ownerAddress: string, From d3e7a396c73e14a54fde9a0279019692de5a8692 Mon Sep 17 00:00:00 2001 From: Eduard Dumea Date: Tue, 19 Aug 2025 14:25:58 +0300 Subject: [PATCH 2/2] revert dlp-registry --- src/lib/contract/v5/dlp-registry.ts | 142 ++++++++++++++++++++++++++++ src/mapping.ts.template | 3 + 2 files changed, 145 insertions(+) create mode 100644 src/lib/contract/v5/dlp-registry.ts diff --git a/src/lib/contract/v5/dlp-registry.ts b/src/lib/contract/v5/dlp-registry.ts new file mode 100644 index 0000000..cc532a8 --- /dev/null +++ b/src/lib/contract/v5/dlp-registry.ts @@ -0,0 +1,142 @@ +import { BigInt as GraphBigInt, log } from "@graphprotocol/graph-ts"; +import { + DlpRegistered, + DlpUpdated, + DlpStatusUpdated, + DlpVerificationBlockUpdated, + DlpTokenUpdated, +} from "../../../../generated/DLPRegistryImplementationV5/DLPRegistryImplementationV5"; + +import { Dlp } from "../../../../generated/schema"; +import { getOrCreateDlpList } from "../../../../src/lib/entity/dlp-list"; +import { getOrCreateDlp, getOrCreateUser } from "../shared"; + +// Mirrored from DLPRegistry.IDLPRegistry.DlpStatus +enum dlpStatus { + NONE = 0, + REGISTERED = 1, + ELIGIBLE = 2, + DEREGISTERED = 3, +} + +export function handleDlpRegisteredV5(event: DlpRegistered): void { + log.info("Handling DlpRegistered with transaction hash: {}", [ + event.transaction.hash.toHexString(), + ]); + + const dlpId = event.params.dlpId.toString(); + + // Ensure User entities exist for creator and owner + getOrCreateUser(event.transaction.from.toHex()); + getOrCreateUser(event.params.ownerAddress.toHex()); + + const dlp = getOrCreateDlp(event.params.dlpId.toString()); + + dlp.creator = event.transaction.from; + dlp.owner = event.params.ownerAddress; + dlp.address = event.params.dlpAddress; + dlp.treasury = event.params.treasuryAddress; + dlp.name = event.params.name; + dlp.iconUrl = event.params.iconUrl; + dlp.website = event.params.website; + dlp.metadata = event.params.metadata; + dlp.createdAt = event.block.timestamp; + dlp.createdTxHash = event.transaction.hash; + dlp.createdAtBlock = event.block.number; + dlp.status = GraphBigInt.fromI32(dlpStatus.REGISTERED); + + // Keep staking fields for backward compatibility but set to zero + dlp.performanceRating = GraphBigInt.zero(); + + dlp.save(); + + // Add to DLP list + const dlpList = getOrCreateDlpList(); + const dlpIds = dlpList.dlpIds; + if (!dlpIds.includes(dlpId)) { + const newDlpIds = dlpIds; + newDlpIds.push(dlpId); + dlpList.dlpIds = newDlpIds; + dlpList.save(); + } +} + +export function handleDlpUpdatedV5(event: DlpUpdated): void { + log.info("Handling DlpUpdated with transaction hash: {}", [ + event.transaction.hash.toHexString(), + ]); + + const dlpId = event.params.dlpId.toString(); + const dlp = Dlp.load(dlpId); + + if (dlp != null) { + // Ensure User entity exists for the new owner + getOrCreateUser(event.params.ownerAddress.toHex()); + + dlp.owner = event.params.ownerAddress; + dlp.address = event.params.dlpAddress; + dlp.treasury = event.params.treasuryAddress; + dlp.name = event.params.name; + dlp.iconUrl = event.params.iconUrl; + dlp.website = event.params.website; + dlp.metadata = event.params.metadata; + dlp.save(); + } else { + log.error("DLP not found during update: {}", [dlpId]); + } +} + +export function handleDlpStatusUpdatedV5(event: DlpStatusUpdated): void { + log.info("Handling DlpStatusUpdated with transaction hash: {}", [ + event.transaction.hash.toHexString(), + ]); + + const dlpId = event.params.dlpId.toString(); + const dlp = Dlp.load(dlpId); + + if (dlp != null) { + const newStatus = event.params.newStatus; + dlp.status = GraphBigInt.fromI32(newStatus); + + dlp.save(); + } else { + log.error("DLP not found during status update: {}", [dlpId]); + } +} + +export function handleDlpVerificationBlockUpdatedV5( + event: DlpVerificationBlockUpdated, +): void { + log.info("Handling DlpVerificationBlockUpdated with transaction hash: {}", [ + event.transaction.hash.toHexString(), + ]); + + const dlpId = event.params.dlpId.toString(); + const dlp = Dlp.load(dlpId); + + if (dlp != null) { + dlp.verificationBlockNumber = event.params.verificationBlockNumber; + dlp.save(); + } else { + log.error("DLP not found during verification update: {}", [dlpId]); + } +} + +export function handleDlpTokenUpdatedV5(event: DlpTokenUpdated): void { + log.info("Handling DlpTokenUpdated with transaction hash: {}", [ + event.transaction.hash.toHexString(), + ]); + + // Load DLP instead of creating it to handle non-existent DLP case gracefully + const dlp = Dlp.load(event.params.dlpId.toString()); + + if (dlp == null) { + log.error("DLP not found for token update: {}", [ + event.params.dlpId.toString(), + ]); + return; + } + + dlp.token = event.params.tokenAddress; + dlp.save(); +} diff --git a/src/mapping.ts.template b/src/mapping.ts.template index 03e39b9..5bb4b9f 100644 --- a/src/mapping.ts.template +++ b/src/mapping.ts.template @@ -70,6 +70,9 @@ export * from "./lib/contract/v4/data-refiner-registry"; {{/includes.v4.dataRefinerRegistry}} // V5 +{{#includes.v5.dlpRegistry}} +export * from "./lib/contract/v5/dlp-registry"; +{{/includes.v5.dlpRegistry}} {{#includes.v5.vanaEpoch}} export * from "./lib/contract/v5/vana-epoch"; {{/includes.v5.vanaEpoch}}