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/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,