From 15ae3d992cdac612ca0106fa2b1cfb15756d4968 Mon Sep 17 00:00:00 2001 From: Ilya Date: Sun, 18 Jun 2023 18:32:30 +0200 Subject: [PATCH 01/17] Fix ownstakeration calculation with locked tokens --- src/mappings/helpers/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mappings/helpers/helpers.ts b/src/mappings/helpers/helpers.ts index 673fc14e..ee0dd4a2 100644 --- a/src/mappings/helpers/helpers.ts +++ b/src/mappings/helpers/helpers.ts @@ -739,7 +739,7 @@ function max(a: BigDecimal, b: BigDecimal): BigDecimal { } export function calculateOwnStakeRatio(indexer: Indexer): BigDecimal { - let stakedTokensBD = indexer.stakedTokens.toBigDecimal() + let stakedTokensBD = indexer.stakedTokens.minus(indexer.lockedTokens).toBigDecimal() let delegatedTokensBD = indexer.delegatedTokens.toBigDecimal() let graphNetwork = GraphNetwork.load('1')! let delegationRatioBD = BigInt.fromI32(graphNetwork.delegationRatio).toBigDecimal() From fbad64e03c3ee4455e4d59a949387911638b896f Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Mon, 29 May 2023 12:58:11 -0300 Subject: [PATCH 02/17] feat: first refactor steps --- schema.graphql | 105 ++++++++++----- src/mappings/ethereumDIDRegistry.ts | 19 ++- src/mappings/gns.ts | 18 ++- src/mappings/helpers/metadata.template.ts | 156 ---------------------- src/mappings/ipfs.ts | 88 ++++++++++++ subgraph.template.yaml | 60 +++++++++ 6 files changed, 246 insertions(+), 200 deletions(-) delete mode 100644 src/mappings/helpers/metadata.template.ts create mode 100644 src/mappings/ipfs.ts diff --git a/schema.graphql b/schema.graphql index 6a953a60..485dd255 100644 --- a/schema.graphql +++ b/schema.graphql @@ -244,20 +244,7 @@ type GraphAccount @entity { defaultDisplayName: String # IPFS Metadata - "True if it is an organization. False if it is an individual" - isOrganization: Boolean - "IPFS hash with account metadata details" - metadataHash: Bytes - "Main repository of code for the graph account" - codeRepository: String - "Description of the graph account" - description: String - "Image URL" - image: String - "Website URL" - website: String - "Display name. Not unique" - displayName: String + metadata: GraphAccountMetadata! # Operator info "Operator of other Graph Accounts" @@ -310,6 +297,25 @@ type GraphAccount @entity { tokenLockWallets: [TokenLockWallet!]! } +type GraphAccountMetadata @entity { + "IPFS hash with account metadata details" + id: ID! + "Original graph account that created it" + graphAccount: GraphAccount! + "True if it is an organization. False if it is an individual" + isOrganization: Boolean + "Main repository of code for the graph account" + codeRepository: String + "Description of the graph account" + description: String + "Image URL" + image: String + "Website URL" + website: String + "Display name. Not unique" + displayName: String +} + """ A name chosen by a Graph Account from a Name System such as ENS. This allows Graph Accounts to be recognized by name, rather than just an Ethereum address @@ -425,7 +431,19 @@ type Subgraph @entity { "Subgraph metadata" metadataHash: Bytes! "Subgraph metadata ipfs hash" - ipfsMetadataHash: String + metadata: SubgraphMetadata! + "Categories that the subgraph belongs to. Modelled with a relation to allow for many-to-many relationship querying" + categories: [SubgraphCategoryRelation!]! @derivedFrom(field: "subgraph") + + # Auxiliary fields + currentVersionRelationEntity: CurrentSubgraphDeploymentRelation +} + +type SubgraphMetadata @entity { + "Subgraph metadata ipfs hash" + id: ID! + "Subgraph entity" + subgraph: Subgraph! "Short description of the subgraph" description: String "Image in string format" @@ -438,11 +456,7 @@ type Subgraph @entity { website: String "Display name" displayName: String - "Categories that the subgraph belongs to. Modelled with a relation to allow for many-to-many relationship querying" - categories: [SubgraphCategoryRelation!]! @derivedFrom(field: "subgraph") - - # Auxiliary fields - currentVersionRelationEntity: CurrentSubgraphDeploymentRelation + #maybe add categories here too? } type CurrentSubgraphDeploymentRelation @entity { @@ -460,7 +474,7 @@ type CurrentSubgraphDeploymentRelation @entity { type Network @entity { id: ID! - deployments: [SubgraphDeployment!]! @derivedFrom(field: "network") + deployments: [SubgraphDeploymentManifest!]! @derivedFrom(field: "network") } type SubgraphCategoryRelation @entity { @@ -498,15 +512,21 @@ type SubgraphVersion @entity { createdAt: Int! # Metadata from IPFS linked in GNS - "Subgraph version metadata content address" - metadataHash: Bytes + metadata: SubgraphVersionMedatada! + + entityVersion: Int! + linkedEntity: SubgraphVersion +} + +type SubgraphVersionMedatada @entity { + "Subgraph version metadata ipfs hash" + id: ID! + "Subgraph version entity" + subgraphVersion: SubgraphVersion! "Short description of the version" description: String "Semantic versioning label" label: String - - entityVersion: Int! - linkedEntity: SubgraphVersion } """ @@ -566,16 +586,11 @@ type SubgraphDeployment @entity { # From Subgraph Manifest # dataSources: [DataSource!] - "Manifest file for this subgraph deployment" - manifest: String - "Network where the contracts that the subgraph indexes are located" - network: Network - "Whether the subgraph is a SpS/SbS. Null if we can't parse it" - poweredBySubstreams: Boolean - "Schema file for this subgraph deployment" - schema: String - "IPFS hash of the schema file" - schemaIpfsHash: String + "Entity that represents the manifest of the deployment. Filled by File Data Sources" + manifest: SubgraphDeploymentManifest + + "Entity that represents the schema of the deployment. Filled by File Data Sources" + schema: SubgraphDeploymentSchema # Counters for currentSignalledTokens tracking on Subgraph "Total amount of Subgraph entities that used this deployment at some point. subgraphCount >= activeSubgraphCount + deprecatedSubgraphCount" @@ -599,6 +614,24 @@ type SubgraphDeployment @entity { signalledTokensReceivedOnL2: BigInt! } +type SubgraphDeploymentSchema @entity { + "IPFS Hash" + id: ID! + "Contents of the Schema file" + schema: String +} + +type SubgraphDeploymentManifest @entity { + "IPFS Hash" + id: ID! + "Contents of the Manifest file" + manifest: String + "Network where the contracts that the subgraph indexes are located" + network: Network + "Whether the subgraph is a SpS/SbS. Null if we can't parse it" + poweredBySubstreams: Boolean +} + # TODO - add when we have the ability to parse data sources # """Data source obtained from the subgraph manifest""" # type DataSource @entity { diff --git a/src/mappings/ethereumDIDRegistry.ts b/src/mappings/ethereumDIDRegistry.ts index 0d015017..3b54a4f0 100644 --- a/src/mappings/ethereumDIDRegistry.ts +++ b/src/mappings/ethereumDIDRegistry.ts @@ -1,8 +1,9 @@ import { Bytes } from '@graphprotocol/graph-ts' import { DIDAttributeChanged } from '../types/EthereumDIDRegistry/EthereumDIDRegistry' +import { GraphAccountMetadata as GraphAccountMetadataTemplate } from '../types/templates' +import { GraphAccount, GraphAccountMetadata } from '../types/schema' import { addQm, createOrLoadGraphAccount } from './helpers/helpers' -import { fetchGraphAccountMetadata } from './helpers/metadata' export function handleDIDAttributeChanged(event: DIDAttributeChanged): void { let graphAccount = createOrLoadGraphAccount(event.params.identity, event.block.timestamp) @@ -16,8 +17,20 @@ export function handleDIDAttributeChanged(event: DIDAttributeChanged): void { // called it directly, it could crash the subgraph let hexHash = changetype(addQm(event.params.value)) let base58Hash = hexHash.toBase58() - graphAccount.metadataHash = event.params.value + graphAccount.metadata = base58Hash + graphAccount.save() - fetchGraphAccountMetadata(graphAccount, base58Hash) + // Update all associated vesting contract addresses + let tlws = graphAccount.tokenLockWallets + for (let i = 0; i < tlws.length; i++) { + let tlw = GraphAccount.load(tlws[i])! + tlw.metadata = base58Hash + tlw.save() + } + + let metadata = new GraphAccountMetadata(base58Hash) + metadata.graphAccount = graphAccount.id; + metadata.save() + GraphAccountMetadataTemplate.create(base58Hash) } } diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index ece70d13..965d76ec 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -24,6 +24,10 @@ import { GNSStitched as GNS, } from '../types/GNS/GNSStitched' +import { + SubgraphMetadata as SubgraphMetadataTemplate +} from '../types/templates' + import { Subgraph, SubgraphVersion, @@ -56,7 +60,6 @@ import { duplicateOrUpdateNameSignalWithNewID, createOrLoadGraphNetwork } from './helpers/helpers' -import { fetchSubgraphMetadata, fetchSubgraphVersionMetadata } from './helpers/metadata' import { addresses } from '../../config/addresses' export function handleSetDefaultName(event: SetDefaultName): void { @@ -184,12 +187,15 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v let base58Hash = hexHash.toBase58() subgraph.metadataHash = event.params.subgraphMetadata - subgraph.ipfsMetadataHash = addQm(subgraph.metadataHash).toBase58() - subgraph = fetchSubgraphMetadata(subgraph, base58Hash) + subgraph.metadata = base58Hash subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() + // ToDo create template + + // Might need to remove duplicates and always use the new IDs to make the code cleaner let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) + subgraphDuplicate.metadata = base58Hash; subgraphDuplicate.save() } @@ -823,13 +829,15 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) let base58Hash = hexHash.toBase58() subgraph.metadataHash = event.params.subgraphMetadata - subgraph.ipfsMetadataHash = addQm(subgraph.metadataHash).toBase58() - subgraph = fetchSubgraphMetadata(subgraph, base58Hash) + subgraph.metadata = base58Hash; subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() + // ToDo create template + if (subgraph.linkedEntity != null) { let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) + subgraphDuplicate.metadata = base58Hash; subgraphDuplicate.save() } } diff --git a/src/mappings/helpers/metadata.template.ts b/src/mappings/helpers/metadata.template.ts deleted file mode 100644 index 443bd00e..00000000 --- a/src/mappings/helpers/metadata.template.ts +++ /dev/null @@ -1,156 +0,0 @@ -import { json, ipfs, Bytes, JSONValueKind, log } from '@graphprotocol/graph-ts' -import { GraphAccount, Subgraph, SubgraphVersion, SubgraphDeployment } from '../../types/schema' -import { jsonToString } from '../utils' -import { createOrLoadSubgraphCategory, createOrLoadSubgraphCategoryRelation, createOrLoadNetwork } from './helpers' - -export function fetchGraphAccountMetadata(graphAccount: GraphAccount, ipfsHash: string): void { - {{#ipfs}} - let ipfsData = ipfs.cat(ipfsHash) - if (ipfsData !== null) { - let tryData = json.try_fromBytes(ipfsData as Bytes) - if(tryData.isOk) { - let data = tryData.value.toObject() - graphAccount.codeRepository = jsonToString(data.get('codeRepository')) - graphAccount.description = jsonToString(data.get('description')) - graphAccount.image = jsonToString(data.get('image')) - graphAccount.displayName = jsonToString(data.get('displayName')) - let isOrganization = data.get('isOrganization') - if (isOrganization != null && isOrganization.kind === JSONValueKind.BOOL) { - graphAccount.isOrganization = isOrganization.toBool() - } - graphAccount.website = jsonToString(data.get('website')) - graphAccount.save() - - // Update all associated vesting contract addresses - let tlws = graphAccount.tokenLockWallets - for (let i = 0; i < tlws.length; i++) { - let tlw = GraphAccount.load(tlws[i])! - tlw.codeRepository = graphAccount.codeRepository - tlw.description = graphAccount.description - tlw.image = graphAccount.image - tlw.displayName = graphAccount.displayName - if (isOrganization != null && isOrganization.kind === JSONValueKind.BOOL) { - tlw.isOrganization = isOrganization.toBool() - } - tlw.website = graphAccount.website - tlw.save() - } - } - } - {{/ipfs}} -} - -export function fetchSubgraphMetadata(subgraph: Subgraph, ipfsHash: string): Subgraph { - {{#ipfs}} - let metadata = ipfs.cat(ipfsHash) - if (metadata !== null) { - let tryData = json.try_fromBytes(metadata as Bytes) - if (tryData.isOk) { - let data = tryData.value.toObject() - subgraph.description = jsonToString(data.get('description')) - subgraph.displayName = jsonToString(data.get('displayName')) - subgraph.codeRepository = jsonToString(data.get('codeRepository')) - subgraph.website = jsonToString(data.get('website')) - let categories = data.get('categories') - - if(categories != null && !categories.isNull()) { - let categoriesArray = categories.toArray() - - for(let i = 0; i < categoriesArray.length; i++) { - let categoryId = jsonToString(categoriesArray[i]) - createOrLoadSubgraphCategory(categoryId) - createOrLoadSubgraphCategoryRelation(categoryId, subgraph.id) - if(subgraph.linkedEntity != null) { - createOrLoadSubgraphCategoryRelation(categoryId, subgraph.linkedEntity!) - } - } - } - let image = jsonToString(data.get('image')) - let subgraphImage = data.get('subgraphImage') - if (subgraphImage != null && subgraphImage.kind === JSONValueKind.STRING) { - subgraph.nftImage = image - subgraph.image = jsonToString(subgraphImage) - } else { - subgraph.image = image - } - } - } - {{/ipfs}} - return subgraph -} - -export function fetchSubgraphVersionMetadata(subgraphVersion: SubgraphVersion, ipfsHash: string): SubgraphVersion { - {{#ipfs}} - let getVersionDataFromIPFS = ipfs.cat(ipfsHash) - if (getVersionDataFromIPFS !== null) { - let tryData = json.try_fromBytes(getVersionDataFromIPFS as Bytes) - if (tryData.isOk) { - let data = tryData.value.toObject() - subgraphVersion.description = jsonToString(data.get('description')) - subgraphVersion.label = jsonToString(data.get('label')) - } else { - subgraphVersion.description = '' - subgraphVersion.label = '' - } - } - {{/ipfs}} - return subgraphVersion -} - -export function fetchSubgraphDeploymentManifest(deployment: SubgraphDeployment, ipfsHash: string): SubgraphDeployment { - {{#ipfs}} - let getManifestFromIPFS = ipfs.cat(ipfsHash) - if (getManifestFromIPFS !== null) { - deployment.manifest = getManifestFromIPFS.toString() - - let manifest = deployment.manifest! - // we take the right side of the split, since it's the one which will have the schema ipfs hash - let schemaSplitTry = manifest.split('schema:\n', 2) - if (schemaSplitTry.length == 2) { - let schemaSplit = schemaSplitTry[1] - - let schemaFileSplitTry = schemaSplit.split('/ipfs/', 2) - if (schemaFileSplitTry.length == 2) { - let schemaFileSplit = schemaFileSplitTry[1] - - let schemaIpfsHashTry = schemaFileSplit.split('\n', 2) - if (schemaIpfsHashTry.length == 2) { - let schemaIpfsHash = schemaIpfsHashTry[0] - deployment.schemaIpfsHash = schemaIpfsHash - - let getSchemaFromIPFS = ipfs.cat(schemaIpfsHash) - if (getSchemaFromIPFS !== null) { - deployment.schema = getSchemaFromIPFS.toString() - } - } else { - log.warning("[MANIFEST PARSING FAIL] Deployment: {}, schema file hash can't be retrieved. Error: schemaIpfsHashTry.length isn't 2, actual length: {}", [ipfsHash, schemaIpfsHashTry.length.toString()]) - } - } else { - log.warning("[MANIFEST PARSING FAIL] Deployment: {}, schema file hash can't be retrieved. Error: schemaFileSplitTry.length isn't 2, actual length: {}", [ipfsHash, schemaFileSplitTry.length.toString()]) - } - } else { - log.warning("[MANIFEST PARSING FAIL] Deployment: {}, schema file hash can't be retrieved. Error: schemaSplitTry.length isn't 2, actual length: {}", [ipfsHash, schemaSplitTry.length.toString()]) - } - - // We get the first occurrence of `network` since subgraphs can only have data sources for the same network - let networkSplitTry = manifest.split('network: ', 2) - if (networkSplitTry.length == 2) { - let networkSplit = networkSplitTry[1] - let networkTry = networkSplit.split('\n', 2) - if (networkTry.length == 2) { - let network = networkTry[0] - - createOrLoadNetwork(network) - deployment.network = network - } else { - log.warning("[MANIFEST PARSING FAIL] Deployment: {}, network can't be parsed. Error: networkTry.length isn't 2, actual length: {}", [ipfsHash, networkTry.length.toString()]) - } - } else { - log.warning("[MANIFEST PARSING FAIL] Deployment: {}, network can't be parsed. Error: networkSplitTry.length isn't 2, actual length: {}", [ipfsHash, networkSplitTry.length.toString()]) - } - let substreamsSplitTry = manifest.split('- kind: substreams', 2) - deployment.poweredBySubstreams = substreamsSplitTry.length > 1 - } - {{/ipfs}} - return deployment as SubgraphDeployment -} diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts new file mode 100644 index 00000000..fa74c18c --- /dev/null +++ b/src/mappings/ipfs.ts @@ -0,0 +1,88 @@ +import { json, Bytes, dataSource, JSONValueKind } from '@graphprotocol/graph-ts' +import { + SubgraphMetadata, + SubgraphVersionMetadata, + GraphAccountMetadata, + SubgraphDeploymentSchema, + SubgraphDeploymentManifest, + Subgraph +} from '../types/schema' +import { jsonToString } from './utils' +import { createOrLoadSubgraphCategory, createOrLoadSubgraphCategoryRelation } from './helpers/helpers' + +export function handleSubgraphMetadata(content: Bytes): void { + let subgraphMetadata = SubgraphMetadata.load(dataSource.stringParam()) + let subgraph = Subgraph.load(SubgraphMetadata.subgraph) + let tryData = json.try_fromBytes(content) + if (tryData.isOk) { + let data = tryData.value.toObject() + subgraphMetadata.description = jsonToString(data.get('description')) + subgraphMetadata.displayName = jsonToString(data.get('displayName')) + subgraphMetadata.codeRepository = jsonToString(data.get('codeRepository')) + subgraphMetadata.website = jsonToString(data.get('website')) + let categories = data.get('categories') + + if (categories != null && !categories.isNull()) { + let categoriesArray = categories.toArray() + + for (let i = 0; i < categoriesArray.length; i++) { + let categoryId = jsonToString(categoriesArray[i]) + createOrLoadSubgraphCategory(categoryId) + createOrLoadSubgraphCategoryRelation(categoryId, subgraph.id) + if (subgraph.linkedEntity != null) { + createOrLoadSubgraphCategoryRelation(categoryId, subgraph.linkedEntity!) + } + } + } + let image = jsonToString(data.get('image')) + let subgraphImage = data.get('subgraphImage') + if (subgraphImage != null && subgraphImage.kind === JSONValueKind.STRING) { + subgraphMetadata.nftImage = image + subgraphMetadata.image = jsonToString(subgraphImage) + } else { + subgraphMetadata.image = image + } + } +} + +export function handleSubgraphVersionMetadata(content: Bytes): void { + let subgraphVersionMetadata = SubgraphVersionMetadata.load(dataSource.stringParam()) + const value = json.fromBytes(content).toObject() + if (value) { + subgraphMetadata.save() + } +} + +export function handleGraphAccountMetadata(content: Bytes): void { + let graphAccountMetadata = GraphAccountMetadata.load(dataSource.stringParam()) + let tryData = json.try_fromBytes(content) + if (tryData.isOk) { + let data = tryData.value.toObject() + graphAccountMetadata.codeRepository = jsonToString(data.get('codeRepository')) + graphAccountMetadata.description = jsonToString(data.get('description')) + graphAccountMetadata.image = jsonToString(data.get('image')) + graphAccountMetadata.displayName = jsonToString(data.get('displayName')) + let isOrganization = data.get('isOrganization') + if (isOrganization != null && isOrganization.kind === JSONValueKind.BOOL) { + graphAccountMetadata.isOrganization = isOrganization.toBool() + } + graphAccountMetadata.website = jsonToString(data.get('website')) + graphAccountMetadata.save() + } +} + +export function handleSubgraphDeploymentSchema(content: Bytes): void { + let subgraphDeploymentSchema = new SubgraphDeploymentSchema(dataSource.stringParam()) + const value = json.fromBytes(content).toObject() + if (value) { + subgraphMetadata.save() + } +} + +export function handleSubgraphDeploymentManifest(content: Bytes): void { + let subgraphDeploymentManifest = new SubgraphDeploymentManifest(dataSource.stringParam()) + const value = json.fromBytes(content).toObject() + if (value) { + subgraphMetadata.save() + } +} diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 002a8ea4..2237f279 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -695,3 +695,63 @@ templates: handler: handleApproveTokenDestinations - event: RevokeTokenDestinations() handler: handleRevokeTokenDestinations + - name: SubgraphDeploymentManifest + kind: file/ipfs + mapping: + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/mapping/ipfs.ts + handler: handleSubgraphDeploymentManifest + entities: + - SubgraphDeploymentManifest + abis: + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json + - name: SubgraphDeploymentSchema + kind: file/ipfs + mapping: + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/mapping/ipfs.ts + handler: handleSubgraphDeploymentSchema + entities: + - SubgraphDeploymentSchema + abis: + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json + - name: SubgraphMetadata + kind: file/ipfs + mapping: + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/mapping/ipfs.ts + handler: handleSubgraphMetadata + entities: + - SubgraphMetadata + abis: + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json + - name: SubgraphVersionMetadata + kind: file/ipfs + mapping: + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/mapping/ipfs.ts + handler: handleSubgraphVersionMetadata + entities: + - SubgraphVersionMetadata + abis: + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json + - name: GraphAccountMetadata + kind: file/ipfs + mapping: + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/mapping/ipfs.ts + handler: handleGraphAccountMetadata + entities: + - GraphAccountMetadata + abis: + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json From 6102c7422bad6f2517fce652fbda26486dea56cf Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Wed, 7 Jun 2023 18:41:49 -0300 Subject: [PATCH 03/17] feat: removed all duplication of entities --- schema.graphql | 4 +- src/mappings/gns.ts | 220 +------------------------------- src/mappings/helpers/helpers.ts | 114 ----------------- 3 files changed, 7 insertions(+), 331 deletions(-) diff --git a/schema.graphql b/schema.graphql index 485dd255..bb43ff6c 100644 --- a/schema.graphql +++ b/schema.graphql @@ -400,7 +400,7 @@ type Subgraph @entity { initializing: Boolean! "Version of the entity. Subgraph entities are changing the way their ID is generated when the new GNS v2 rolls out so we need to differnetiate them" entityVersion: Int! - "Subgraph entities might have 'duplicate' entities so that old IDs can be persisted and still queried properly. If that happens we have to link both duplicate entities to be able to update them properly." + "[DEPRECATED] Used for duplicate entities to enable old IDs from before the subgraph NFT update" linkedEntity: Subgraph # Name curation data for bonding curve @@ -515,6 +515,7 @@ type SubgraphVersion @entity { metadata: SubgraphVersionMedatada! entityVersion: Int! + "[DEPRECATED] Used for duplicate entities to enable old IDs from before the subgraph NFT update" linkedEntity: SubgraphVersion } @@ -1114,6 +1115,7 @@ type NameSignal @entity { signalAverageCostBasisPerSignal: BigDecimal! entityVersion: Int! + "[DEPRECATED] Used for duplicate entities to enable old IDs from before the subgraph NFT update" linkedEntity: NameSignal } diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index 965d76ec..bc150444 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -55,9 +55,6 @@ import { updateCurrentDeploymentLinks, getSubgraphID, convertBigIntSubgraphIDToBase58, - duplicateOrUpdateSubgraphWithNewID, - duplicateOrUpdateSubgraphVersionWithNewID, - duplicateOrUpdateNameSignalWithNewID, createOrLoadGraphNetwork } from './helpers/helpers' import { addresses } from '../../config/addresses' @@ -174,10 +171,6 @@ function addDefaultNameTokenLockWallets(graphAccount: GraphAccount): void { } export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): void { - let oldID = joinID([ - event.params.graphAccount.toHexString(), - event.params.subgraphNumber.toString(), - ]) let subgraphID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber) // Create subgraph @@ -192,11 +185,6 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v subgraph.save() // ToDo create template - - // Might need to remove duplicates and always use the new IDs to make the code cleaner - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - subgraphDuplicate.metadata = base58Hash; - subgraphDuplicate.save() } /** @@ -208,10 +196,6 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v * - creates graph account, if needed */ export function handleSubgraphPublished(event: SubgraphPublished): void { - let oldID = joinID([ - event.params.graphAccount.toHexString(), - event.params.subgraphNumber.toString(), - ]) let subgraphID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber) let versionNumber: BigInt @@ -221,8 +205,7 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { let oldVersionID = subgraph.currentVersion versionNumber = subgraph.versionCount - let versionIDOld = joinID([oldID, subgraph.versionCount.toString()]) - let versionIDNew = joinID([subgraph.id, subgraph.versionCount.toString()]) + let versionID = joinID([subgraph.id, subgraph.versionCount.toString()]) subgraph.creatorAddress = changetype(event.params.graphAccount) subgraph.subgraphNumber = event.params.subgraphNumber subgraph.oldID = joinID([ @@ -232,13 +215,8 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { subgraph.versionCount = versionNumber.plus(BigInt.fromI32(1)) subgraph.updatedAt = event.block.timestamp.toI32() - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - - subgraph.currentVersion = versionIDNew - subgraphDuplicate.currentVersion = versionIDOld - subgraph.linkedEntity = subgraphDuplicate.id + subgraph.currentVersion = versionID subgraph.save() - subgraphDuplicate.save() // Creates Graph Account, if needed createOrLoadGraphAccount(event.params.graphAccount, event.block.timestamp) @@ -248,7 +226,7 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { let deployment = createOrLoadSubgraphDeployment(subgraphDeploymentID, event.block.timestamp) // Create subgraph version - let subgraphVersion = new SubgraphVersion(versionIDNew) + let subgraphVersion = new SubgraphVersion(versionID) subgraphVersion.entityVersion = 2 subgraphVersion.subgraph = subgraph.id subgraphVersion.subgraphDeployment = subgraphDeploymentID @@ -257,16 +235,8 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() subgraphVersion.metadataHash = event.params.versionMetadata - subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) + //subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) - let subgraphVersionDuplicate = duplicateOrUpdateSubgraphVersionWithNewID( - subgraphVersion, - versionIDOld, - 1, - ) - subgraphVersionDuplicate.subgraph = subgraphDuplicate.id - subgraphVersion.linkedEntity = subgraphVersionDuplicate.id - subgraphVersionDuplicate.save() subgraphVersion.save() let oldDeployment: SubgraphDeployment | null = null @@ -275,7 +245,6 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { oldDeployment = SubgraphDeployment.load(oldVersion.subgraphDeployment)! } // create deployment - named subgraph relationship, and update the old one - updateCurrentDeploymentLinks(oldDeployment, deployment, subgraphDuplicate as Subgraph) updateCurrentDeploymentLinks(oldDeployment, deployment, subgraph as Subgraph) } /** @@ -284,10 +253,6 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { * - deprecates subgraph version */ export function handleSubgraphDeprecated(event: SubgraphDeprecated): void { - let oldID = joinID([ - event.params.graphAccount.toHexString(), - event.params.subgraphNumber.toString(), - ]) let bigIntID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber) let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID) let subgraph = Subgraph.load(subgraphID)! @@ -296,9 +261,6 @@ export function handleSubgraphDeprecated(event: SubgraphDeprecated): void { subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - subgraphDuplicate.save() - let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.activeSubgraphCount = graphNetwork.activeSubgraphCount - 1 graphNetwork.save() @@ -307,34 +269,22 @@ export function handleSubgraphDeprecated(event: SubgraphDeprecated): void { if (version != null) { let deployment = SubgraphDeployment.load(version.subgraphDeployment) - updateCurrentDeploymentLinks(deployment, null, subgraphDuplicate as Subgraph, true) updateCurrentDeploymentLinks(deployment, null, subgraph as Subgraph, true) } } export function handleNameSignalEnabled(event: NameSignalEnabled): void { - let oldID = joinID([ - event.params.graphAccount.toHexString(), - event.params.subgraphNumber.toString(), - ]) let bigIntID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber) let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID) let subgraph = Subgraph.load(subgraphID)! subgraph.reserveRatio = event.params.reserveRatio.toI32() subgraph.save() - - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - subgraphDuplicate.save() } export function handleNSignalMinted(event: NSignalMinted): void { let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let curatorID = event.params.nameCurator.toHexString() - let oldID = joinID([ - event.params.graphAccount.toHexString(), - event.params.subgraphNumber.toString(), - ]) let bigIntID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber) let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID) let subgraph = Subgraph.load(subgraphID)! @@ -344,9 +294,6 @@ export function handleNSignalMinted(event: NSignalMinted): void { subgraph.signalledTokens = subgraph.signalledTokens.plus(event.params.tokensDeposited) subgraph.save() - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - subgraphDuplicate.save() - // Update the curator let curator = createOrLoadCurator(event.params.nameCurator, event.block.timestamp) // nSignal @@ -415,14 +362,8 @@ export function handleNSignalMinted(event: NSignalMinted): void { .div(nameSignal.signal) .truncate(18) } - let nsDuplicateID = joinID([curatorID, oldID]) - nameSignal.linkedEntity = nsDuplicateID nameSignal.save() - let nameSignalDuplicate = duplicateOrUpdateNameSignalWithNewID(nameSignal, nsDuplicateID, 1) - nameSignalDuplicate.subgraph = oldID - nameSignalDuplicate.save() - // reload curator, since it might update counters in another context and we don't want to overwrite it curator = Curator.load(curatorID) as Curator if (isNameSignalBecomingActive) { @@ -455,10 +396,6 @@ export function handleNSignalMinted(event: NSignalMinted): void { export function handleNSignalBurned(event: NSignalBurned): void { let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let curatorID = event.params.nameCurator.toHexString() - let oldID = joinID([ - event.params.graphAccount.toHexString(), - event.params.subgraphNumber.toString(), - ]) let bigIntID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber) let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID) let subgraph = Subgraph.load(subgraphID)! @@ -468,9 +405,6 @@ export function handleNSignalBurned(event: NSignalBurned): void { subgraph.unsignalledTokens = subgraph.unsignalledTokens.plus(event.params.tokensReceived) subgraph.save() - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - subgraphDuplicate.save() - // update name signal let nameSignal = createOrLoadNameSignal( event.params.nameCurator, @@ -527,14 +461,8 @@ export function handleNSignalBurned(event: NSignalBurned): void { if (nameSignal.signalAverageCostBasis == zeroBD) { nameSignal.signalAverageCostBasisPerSignal = zeroBD } - let nsDuplicateID = joinID([curatorID, oldID]) - nameSignal.linkedEntity = nsDuplicateID nameSignal.save() - let nameSignalDuplicate = duplicateOrUpdateNameSignalWithNewID(nameSignal, nsDuplicateID, 1) - nameSignalDuplicate.subgraph = oldID - nameSignalDuplicate.save() - // Update curator curator.totalUnsignalledTokens = curator.totalUnsignalledTokens.plus(event.params.tokensReceived) curator.totalSignal = curator.totalSignal.minus(event.params.vSignalBurnt.toBigDecimal()) @@ -576,10 +504,6 @@ export function handleNSignalBurned(event: NSignalBurned): void { } export function handleNameSignalUpgrade(event: NameSignalUpgrade): void { - let oldID = joinID([ - event.params.graphAccount.toHexString(), - event.params.subgraphNumber.toString(), - ]) let bigIntID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber) let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID) let subgraph = Subgraph.load(subgraphID)! @@ -593,9 +517,6 @@ export function handleNameSignalUpgrade(event: NameSignalUpgrade): void { subgraph.signalledTokens = subgraph.signalledTokens.plus(event.params.tokensSignalled) subgraph.save() - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - subgraphDuplicate.save() - let signalRatio = subgraph.signalAmount.toBigDecimal() / subgraph.nameSignalAmount.toBigDecimal() for (let i = 0; i < subgraph.nameSignalCount; i++) { @@ -638,15 +559,6 @@ export function handleNameSignalUpgrade(event: NameSignalUpgrade): void { } nameSignal.save() curator.save() - - if (subgraph.linkedEntity != null && nameSignal.linkedEntity) { - let nameSignalDuplicate = duplicateOrUpdateNameSignalWithNewID( - nameSignal, - nameSignal.linkedEntity!, - 1, - ) - nameSignalDuplicate.save() - } } } } @@ -654,26 +566,15 @@ export function handleNameSignalUpgrade(event: NameSignalUpgrade): void { // Only need to upgrade withdrawable tokens. Everything else handled from // curation events, or handleGRTWithdrawn export function handleNameSignalDisabled(event: NameSignalDisabled): void { - let oldID = joinID([ - event.params.graphAccount.toHexString(), - event.params.subgraphNumber.toString(), - ]) let bigIntID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber) let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID) let subgraph = Subgraph.load(subgraphID)! subgraph.withdrawableTokens = event.params.withdrawableGRT subgraph.signalAmount = BigInt.fromI32(0) subgraph.save() - - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - subgraphDuplicate.save() } export function handleGRTWithdrawn(event: GRTWithdrawn): void { - let oldID = joinID([ - event.params.graphAccount.toHexString(), - event.params.subgraphNumber.toString(), - ]) let bigIntID = getSubgraphID(event.params.graphAccount, event.params.subgraphNumber) let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID) let subgraph = Subgraph.load(subgraphID)! @@ -682,9 +583,6 @@ export function handleGRTWithdrawn(event: GRTWithdrawn): void { subgraph.nameSignalAmount = subgraph.nameSignalAmount.minus(event.params.nSignalBurnt) subgraph.save() - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - subgraphDuplicate.save() - let nameSignal = createOrLoadNameSignal( event.params.nameCurator, subgraphID, @@ -703,15 +601,8 @@ export function handleGRTWithdrawn(event: GRTWithdrawn): void { nameSignal.nameSignalAverageCostBasisPerSignal = BigDecimal.fromString('0') nameSignal.signalAverageCostBasis = BigDecimal.fromString('0') nameSignal.signalAverageCostBasisPerSignal = BigDecimal.fromString('0') - - let nsDuplicateID = joinID([event.params.nameCurator.toHexString(), oldID]) - nameSignal.linkedEntity = nsDuplicateID nameSignal.save() - let nameSignalDuplicate = duplicateOrUpdateNameSignalWithNewID(nameSignal, nsDuplicateID, 1) - nameSignalDuplicate.subgraph = oldID - nameSignalDuplicate.save() - let curator = Curator.load(event.params.nameCurator.toHexString())! curator.totalWithdrawnTokens = curator.totalWithdrawnTokens.plus(event.params.withdrawnGRT) curator.save() @@ -796,11 +687,6 @@ export function handleSubgraphDeprecatedV2(event: SubgraphDeprecated1): void { subgraph.withdrawableTokens = event.params.withdrawableGRT subgraph.signalAmount = BigInt.fromI32(0) subgraph.save() - let subgraphDuplicate: Subgraph | null = null - if (subgraph.linkedEntity != null) { - subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) - subgraphDuplicate.save() - } let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.activeSubgraphCount = graphNetwork.activeSubgraphCount - 1 @@ -811,9 +697,6 @@ export function handleSubgraphDeprecatedV2(event: SubgraphDeprecated1): void { let deployment = SubgraphDeployment.load(version.subgraphDeployment) updateCurrentDeploymentLinks(deployment, null, subgraph as Subgraph, true) - if (subgraphDuplicate != null) { - updateCurrentDeploymentLinks(deployment, null, subgraphDuplicate as Subgraph, true) - } } } @@ -834,12 +717,6 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) subgraph.save() // ToDo create template - - if (subgraph.linkedEntity != null) { - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) - subgraphDuplicate.metadata = base58Hash; - subgraphDuplicate.save() - } } // - event: SignalMinted(indexed uint256,indexed address,uint256,uint256,uint256) @@ -857,11 +734,6 @@ export function handleNSignalMintedV2(event: SignalMinted): void { subgraph.signalledTokens = subgraph.signalledTokens.plus(event.params.tokensDeposited) subgraph.save() - if (subgraph.linkedEntity != null) { - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) - subgraphDuplicate.save() - } - // Update the curator let curator = createOrLoadCurator(event.params.curator, event.block.timestamp) // nSignal @@ -932,16 +804,6 @@ export function handleNSignalMintedV2(event: SignalMinted): void { } nameSignal.save() - if (subgraph.linkedEntity != null && nameSignal.linkedEntity != null) { - let nameSignalDuplicate = duplicateOrUpdateNameSignalWithNewID( - nameSignal, - nameSignal.linkedEntity!, - 1, - ) - nameSignalDuplicate.subgraph = subgraph.linkedEntity! - nameSignalDuplicate.save() - } - // reload curator, since it might update counters in another context and we don't want to overwrite it curator = Curator.load(curatorID) as Curator if (isNameSignalBecomingActive) { @@ -985,11 +847,6 @@ export function handleNSignalBurnedV2(event: SignalBurned): void { subgraph.unsignalledTokens = subgraph.unsignalledTokens.plus(event.params.tokensReceived) subgraph.save() - if (subgraph.linkedEntity != null) { - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) - subgraphDuplicate.save() - } - // update name signal let nameSignal = createOrLoadNameSignal( event.params.curator, @@ -1048,16 +905,6 @@ export function handleNSignalBurnedV2(event: SignalBurned): void { } nameSignal.save() - if (subgraph.linkedEntity != null && nameSignal.linkedEntity != null) { - let nameSignalDuplicate = duplicateOrUpdateNameSignalWithNewID( - nameSignal, - nameSignal.linkedEntity!, - 1, - ) - nameSignalDuplicate.subgraph = subgraph.linkedEntity! - nameSignalDuplicate.save() - } - // Update curator curator.totalUnsignalledTokens = curator.totalUnsignalledTokens.plus(event.params.tokensReceived) curator.totalSignal = curator.totalSignal.minus(event.params.vSignalBurnt.toBigDecimal()) @@ -1110,11 +957,6 @@ export function handleGRTWithdrawnV2(event: GRTWithdrawn1): void { subgraph.nameSignalAmount = subgraph.nameSignalAmount.minus(event.params.nSignalBurnt) subgraph.save() - if (subgraph.linkedEntity != null) { - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) - subgraphDuplicate.save() - } - let nameSignal = createOrLoadNameSignal( event.params.curator, subgraphID, @@ -1136,16 +978,6 @@ export function handleGRTWithdrawnV2(event: GRTWithdrawn1): void { nameSignal.save() - if (subgraph.linkedEntity != null && nameSignal.linkedEntity) { - let nameSignalDuplicate = duplicateOrUpdateNameSignalWithNewID( - nameSignal, - nameSignal.linkedEntity!, - 1, - ) - nameSignalDuplicate.subgraph = subgraph.linkedEntity! - nameSignalDuplicate.save() - } - let curator = Curator.load(event.params.curator.toHexString())! curator.totalWithdrawnTokens = curator.totalWithdrawnTokens.plus(event.params.withdrawnGRT) curator.save() @@ -1168,11 +1000,6 @@ export function handleSubgraphUpgraded(event: SubgraphUpgraded): void { subgraph.signalledTokens = subgraph.signalledTokens.plus(event.params.tokensSignalled) subgraph.save() - if (subgraph.linkedEntity != null) { - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) - subgraphDuplicate.save() - } - if (!subgraph.nameSignalAmount.isZero()) { let signalRatio = subgraph.signalAmount.toBigDecimal() / subgraph.nameSignalAmount.toBigDecimal() @@ -1217,15 +1044,6 @@ export function handleSubgraphUpgraded(event: SubgraphUpgraded): void { } nameSignal.save() curator.save() - - if (subgraph.linkedEntity != null && nameSignal.linkedEntity) { - let nameSignalDuplicate = duplicateOrUpdateNameSignalWithNewID( - nameSignal, - nameSignal.linkedEntity!, - 1, - ) - nameSignalDuplicate.save() - } } } } @@ -1292,28 +1110,6 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi } // create deployment - named subgraph relationship, and update the old one updateCurrentDeploymentLinks(oldDeployment, deployment, subgraph as Subgraph) - - if (subgraph.linkedEntity != null) { - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID( - subgraph, - subgraph.linkedEntity!, - 1, - ) - let duplicateVersionID = joinID([subgraphDuplicate.id, versionNumber.toString()]) - subgraphDuplicate.currentVersion = duplicateVersionID - subgraphDuplicate.save() - - let subgraphVersionDuplicate = duplicateOrUpdateSubgraphVersionWithNewID( - subgraphVersion, - duplicateVersionID, - 1, - ) - subgraphVersionDuplicate.subgraph = subgraphDuplicate.id - subgraphVersion.linkedEntity = subgraphVersionDuplicate.id - subgraphVersionDuplicate.save() - - updateCurrentDeploymentLinks(oldDeployment, deployment, subgraphDuplicate as Subgraph) - } subgraphVersion.save() } } @@ -1328,9 +1124,6 @@ export function handleLegacySubgraphClaimed(event: LegacySubgraphClaimed): void let subgraph = createOrLoadSubgraph(subgraphID, event.params.graphAccount, event.block.timestamp) subgraph.migrated = true subgraph.save() - - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) - subgraphDuplicate.save() } // - event: Transfer(indexed address,indexed address,indexed uint256) @@ -1348,9 +1141,4 @@ export function handleTransfer(event: Transfer): void { subgraph.updatedAt = event.block.timestamp.toI32() subgraph.owner = newOwner.id subgraph.save() - - if (subgraph.linkedEntity != null) { - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) - subgraphDuplicate.save() - } } diff --git a/src/mappings/helpers/helpers.ts b/src/mappings/helpers/helpers.ts index ee0dd4a2..509a6f69 100644 --- a/src/mappings/helpers/helpers.ts +++ b/src/mappings/helpers/helpers.ts @@ -971,120 +971,6 @@ export function getSubgraphID(graphAccount: Address, subgraphNumber: BigInt): Bi return bigIntRepresentation } -export function duplicateOrUpdateSubgraphWithNewID( - entity: Subgraph, - newID: String, - newEntityVersion: i32, -): Subgraph { - let subgraph = Subgraph.load(newID) - if (subgraph == null) { - subgraph = new Subgraph(newID) - } - - subgraph.owner = entity.owner - //subgraph.currentVersion = entity.currentVersion // currentVersion will have to be updated to be the duplicated SubgraphVersion entity afterwards - subgraph.versionCount = entity.versionCount - subgraph.createdAt = entity.createdAt - subgraph.updatedAt = entity.updatedAt - subgraph.active = entity.active - subgraph.migrated = entity.migrated - subgraph.nftID = entity.nftID - subgraph.oldID = entity.oldID - subgraph.creatorAddress = entity.creatorAddress - subgraph.subgraphNumber = entity.subgraphNumber - subgraph.initializing = entity.initializing - subgraph.signalledTokens = entity.signalledTokens - subgraph.unsignalledTokens = entity.unsignalledTokens - subgraph.currentSignalledTokens = entity.currentSignalledTokens - subgraph.nameSignalAmount = entity.nameSignalAmount - subgraph.signalAmount = entity.signalAmount - subgraph.reserveRatio = entity.reserveRatio - subgraph.withdrawableTokens = entity.withdrawableTokens - subgraph.withdrawnTokens = entity.withdrawnTokens - subgraph.nameSignalCount = entity.nameSignalCount - subgraph.metadataHash = entity.metadataHash - subgraph.ipfsMetadataHash = entity.ipfsMetadataHash - subgraph.description = entity.description - subgraph.image = entity.image - subgraph.codeRepository = entity.codeRepository - subgraph.website = entity.website - subgraph.displayName = entity.displayName - - subgraph.startedTransferToL2 = entity.startedTransferToL2 - subgraph.transferredToL2 = entity.transferredToL2 - subgraph.signalledTokensSentToL2 = entity.signalledTokensSentToL2 - subgraph.signalledTokensReceivedOnL2 = entity.signalledTokensReceivedOnL2 - // subgraph.pastVersions = entity.pastVersions This is a derived field, we won't copy, but need to make sure NameSignals are duplicated too. - // subgraph.versions = entity.versions This is a derived field, we won't copy, but need to make sure NameSignals are duplicated too. - // subgraph.nameSignals = entity.nameSignals This is a derived field, we won't copy, but need to make sure NameSignals are duplicated too. - // subgraph.categories = entity.categories This is a derived field, we wont' copy, but need to make sure Categories auxiliary entities are properly duplicated too. - - subgraph.entityVersion = newEntityVersion - subgraph.linkedEntity = entity.id // this is the entity id, since for the entity, this value will be this particular entity. - - return subgraph as Subgraph -} - -export function duplicateOrUpdateSubgraphVersionWithNewID( - entity: SubgraphVersion, - newID: String, - newEntityVersion: i32, -): SubgraphVersion { - let version = SubgraphVersion.load(newID) - if (version == null) { - version = new SubgraphVersion(newID) - } - - version.subgraphDeployment = entity.subgraphDeployment - version.version = entity.version - version.createdAt = entity.createdAt - version.metadataHash = entity.metadataHash - version.description = entity.description - version.label = entity.label - //version.subgraph = entity.subgraph - - version.entityVersion = newEntityVersion - version.linkedEntity = entity.id - - return version as SubgraphVersion -} - -export function duplicateOrUpdateNameSignalWithNewID( - entity: NameSignal, - newID: String, - newEntityVersion: i32, -): NameSignal { - let signal = NameSignal.load(newID) - if (signal == null) { - signal = new NameSignal(newID) - } - - signal.curator = entity.curator - //signal.subgraph = entity.subgraph - signal.signalledTokens = entity.signalledTokens - signal.unsignalledTokens = entity.unsignalledTokens - signal.withdrawnTokens = entity.withdrawnTokens - signal.nameSignal = entity.nameSignal - signal.signal = entity.signal - signal.lastNameSignalChange = entity.lastNameSignalChange - signal.realizedRewards = entity.realizedRewards - signal.averageCostBasis = entity.averageCostBasis - signal.averageCostBasisPerSignal = entity.averageCostBasisPerSignal - signal.nameSignalAverageCostBasis = entity.nameSignalAverageCostBasis - signal.nameSignalAverageCostBasisPerSignal = entity.nameSignalAverageCostBasisPerSignal - signal.signalAverageCostBasis = entity.signalAverageCostBasis - signal.signalAverageCostBasisPerSignal = entity.signalAverageCostBasisPerSignal - - signal.signalledTokensSentToL2 = entity.signalledTokensSentToL2 - signal.signalledTokensReceivedOnL2 = entity.signalledTokensReceivedOnL2 - signal.transferredToL2 = entity.transferredToL2 - - signal.entityVersion = newEntityVersion - signal.linkedEntity = entity.id - - return signal as NameSignal -} - export function updateL1BlockNumber(graphNetwork: GraphNetwork): GraphNetwork { let epochManagerAddress = Address.fromString(addresses.epochManager) let contract = EpochManager.bind(epochManagerAddress) From 20a82fe071ada96fb4311f391e5b8b06135c7223 Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Wed, 7 Jun 2023 19:32:20 -0300 Subject: [PATCH 04/17] feat: backwards compatibility, SubgraphMetadata and other fixes --- package.json | 19 ++++++---------- schema.graphql | 51 +++++++++++++++++++++++++++++++++++------- src/mappings/gns.ts | 11 +++++++-- src/mappings/ipfs.ts | 25 +++++++++++++++++++-- subgraph.template.yaml | 5 +++++ 5 files changed, 87 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 9973f257..72743540 100644 --- a/package.json +++ b/package.json @@ -12,18 +12,13 @@ "scripts": { "prepublishOnly": "yarn & yarn build:ipfs", "build": "graph build", - "build:ipfs:mainnet": "yarn && yarn prep:ipfs && yarn prepare:mainnet && graph build --ipfs https://ipfs.network.thegraph.com", - "build:ipfs:mainnet-no-ipfs": "yarn && yarn prep:no-ipfs && yarn prepare:mainnet && graph build --ipfs https://ipfs.network.thegraph.com", - "deploy-mainnet-staging": "yarn && yarn prep:ipfs && yarn prepare:mainnet && graph deploy graphprotocol/graph-network-mainnet-staging --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy-mainnet": "yarn && yarn prep:ipfs && yarn prepare:mainnet && graph deploy graphprotocol/graph-network-mainnet --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy-mainnet-no-ipfs": "yarn && yarn prep:no-ipfs && yarn prepare:mainnet && graph deploy graphprotocol/no-ipfs-network-ethereum --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy-arbitrum": "yarn && yarn prep:ipfs && yarn prepare:arbitrum && graph deploy graphprotocol/graph-network-arbitrum --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy-arbitrum-no-ipfs": "yarn && yarn prep:no-ipfs && yarn prepare:arbitrum && graph deploy graphprotocol/no-ipfs-network-arbitrum --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy-goerli": "yarn && yarn prep:ipfs && yarn prepare:goerli && graph deploy graphprotocol/graph-network-goerli --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy-goerli-no-ipfs": "yarn && yarn prep:no-ipfs && yarn prepare:goerli && graph deploy graphprotocol/no-ipfs-network-goerli --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy-arbitrum-goerli": "yarn && yarn prep:ipfs && yarn prepare:arbitrum-goerli && graph deploy graphprotocol/graph-network-arbitrum-goerli --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy-arbitrum-goerli-no-ipfs": "yarn && yarn prep:no-ipfs && yarn prepare:arbitrum-goerli && graph deploy graphprotocol/no-ipfs-network-arb-goerli --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy-testing": "yarn && yarn prep: && yarn prepare: && graph deploy --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "build:ipfs:mainnet": "yarn && yarn prepare:mainnet && graph build --ipfs https://ipfs.network.thegraph.com", + "deploy-mainnet-staging": "yarn && yarn prepare:mainnet && graph deploy graphprotocol/graph-network-mainnet-staging --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy-mainnet": "yarn && yarn prepare:mainnet && graph deploy graphprotocol/graph-network-mainnet --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy-arbitrum": "yarn && yarn prepare:arbitrum && graph deploy graphprotocol/graph-network-arbitrum --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy-goerli": "yarn && yarn prepare:goerli && graph deploy graphprotocol/graph-network-goerli --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy-arbitrum-goerli": "yarn && yarn prepare:arbitrum-goerli && graph deploy graphprotocol/graph-network-arbitrum-goerli --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy-testing": "yarn && yarn prepare: && graph deploy --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", "prep:addresses:goerli": "ts-node config/goerliAddressScript.ts && mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts", "prepare:goerli": "yarn prep:addresses:goerli && mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && graph codegen --output-dir src/types/", "prep:addresses:sepolia": "ts-node config/sepoliaAddressScript.ts && mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts", diff --git a/schema.graphql b/schema.graphql index bb43ff6c..6e47ad0e 100644 --- a/schema.graphql +++ b/schema.graphql @@ -243,8 +243,20 @@ type GraphAccount @entity { "Default display name is the current default name. Used for filtered queries in the explorer" defaultDisplayName: String - # IPFS Metadata + # IPFS Metadata. Duplicated for backwards compatibility metadata: GraphAccountMetadata! + "True if it is an organization. False if it is an individual" + isOrganization: Boolean + "Main repository of code for the graph account" + codeRepository: String + "Description of the graph account" + description: String + "Image URL" + image: String + "Website URL" + website: String + "Display name. Not unique" + displayName: String # Operator info "Operator of other Graph Accounts" @@ -427,11 +439,23 @@ type Subgraph @entity { "Total amount of NameSignal entities" nameSignalCount: Int! - # Metadata from IPFS linked in GNS + # Metadata from IPFS linked in GNS. For backwards compatibility we duplicate it "Subgraph metadata" metadataHash: Bytes! - "Subgraph metadata ipfs hash" + "Subgraph metadata ipfs hash and entity" metadata: SubgraphMetadata! + "Short description of the subgraph" + description: String + "Image in string format" + image: String + "NFT Image representation" + nftImage: String + "Location of the code for this project" + codeRepository: String + "Projects website" + website: String + "Display name" + displayName: String "Categories that the subgraph belongs to. Modelled with a relation to allow for many-to-many relationship querying" categories: [SubgraphCategoryRelation!]! @derivedFrom(field: "subgraph") @@ -512,14 +536,18 @@ type SubgraphVersion @entity { createdAt: Int! # Metadata from IPFS linked in GNS - metadata: SubgraphVersionMedatada! + metadata: SubgraphVersionMetadata! + "Short description of the version" + description: String + "Semantic versioning label" + label: String entityVersion: Int! "[DEPRECATED] Used for duplicate entities to enable old IDs from before the subgraph NFT update" linkedEntity: SubgraphVersion } -type SubgraphVersionMedatada @entity { +type SubgraphVersionMetadata @entity { "Subgraph version metadata ipfs hash" id: ID! "Subgraph version entity" @@ -588,10 +616,17 @@ type SubgraphDeployment @entity { # From Subgraph Manifest # dataSources: [DataSource!] "Entity that represents the manifest of the deployment. Filled by File Data Sources" - manifest: SubgraphDeploymentManifest - + manifestEntity: SubgraphDeploymentManifest "Entity that represents the schema of the deployment. Filled by File Data Sources" - schema: SubgraphDeploymentSchema + schemaEntity: SubgraphDeploymentSchema + "Contents of the Schema file" + schema: String + "Contents of the Manifest file" + manifest: String + "Network where the contracts that the subgraph indexes are located" + network: Network + "Whether the subgraph is a SpS/SbS. Null if we can't parse it" + poweredBySubstreams: Boolean # Counters for currentSignalledTokens tracking on Subgraph "Total amount of Subgraph entities that used this deployment at some point. subgraphCount >= activeSubgraphCount + deprecatedSubgraphCount" diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index bc150444..0e0c514c 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -40,6 +40,7 @@ import { GraphAccount, NameSignalSubgraphRelation, NameSignal, + SubgraphMetadata, } from '../types/schema' import { zeroBD } from './utils' @@ -184,7 +185,10 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - // ToDo create template + let metadata = new SubgraphMetadata(base58Hash) + metadata.subgraph = subgraph.id; + metadata.save() + SubgraphMetadataTemplate.create(base58Hash) } /** @@ -716,7 +720,10 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - // ToDo create template + let metadata = new SubgraphMetadata(base58Hash) + metadata.subgraph = subgraph.id; + metadata.save() + SubgraphMetadataTemplate.create(base58Hash) } // - event: SignalMinted(indexed uint256,indexed address,uint256,uint256,uint256) diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index fa74c18c..e403dbab 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -5,21 +5,28 @@ import { GraphAccountMetadata, SubgraphDeploymentSchema, SubgraphDeploymentManifest, - Subgraph + Subgraph, + GraphAccount } from '../types/schema' import { jsonToString } from './utils' import { createOrLoadSubgraphCategory, createOrLoadSubgraphCategoryRelation } from './helpers/helpers' export function handleSubgraphMetadata(content: Bytes): void { let subgraphMetadata = SubgraphMetadata.load(dataSource.stringParam()) - let subgraph = Subgraph.load(SubgraphMetadata.subgraph) + let subgraph = Subgraph.load(subgraphMetadata.subgraph) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() + // Duplicating the fields for backwards compatibility subgraphMetadata.description = jsonToString(data.get('description')) subgraphMetadata.displayName = jsonToString(data.get('displayName')) subgraphMetadata.codeRepository = jsonToString(data.get('codeRepository')) subgraphMetadata.website = jsonToString(data.get('website')) + + subgraph.description = subgraphMetadata.description + subgraph.displayName = subgraphMetadata.displayName + subgraph.codeRepository = subgraphMetadata.codeRepository + subgraph.website = subgraphMetadata.website let categories = data.get('categories') if (categories != null && !categories.isNull()) { @@ -39,9 +46,14 @@ export function handleSubgraphMetadata(content: Bytes): void { if (subgraphImage != null && subgraphImage.kind === JSONValueKind.STRING) { subgraphMetadata.nftImage = image subgraphMetadata.image = jsonToString(subgraphImage) + subgraph.nftImage = subgraphMetadata.nftImage + subgraph.image = subgraphMetadata.image } else { subgraphMetadata.image = image + subgraph.image = subgraphMetadata.image } + subgraphMetadata.save() + subgraph.save() } } @@ -55,6 +67,7 @@ export function handleSubgraphVersionMetadata(content: Bytes): void { export function handleGraphAccountMetadata(content: Bytes): void { let graphAccountMetadata = GraphAccountMetadata.load(dataSource.stringParam()) + let graphAccount = GraphAccount.load(graphAccountMetadata.graphAccount)! let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -62,12 +75,20 @@ export function handleGraphAccountMetadata(content: Bytes): void { graphAccountMetadata.description = jsonToString(data.get('description')) graphAccountMetadata.image = jsonToString(data.get('image')) graphAccountMetadata.displayName = jsonToString(data.get('displayName')) + graphAccount.codeRepository = graphAccountMetadata.codeRepository + graphAccount.description = graphAccountMetadata.description + graphAccount.image = graphAccountMetadata.image + graphAccount.displayName = graphAccountMetadata.displayName let isOrganization = data.get('isOrganization') if (isOrganization != null && isOrganization.kind === JSONValueKind.BOOL) { graphAccountMetadata.isOrganization = isOrganization.toBool() + graphAccount.isOrganization = graphAccountMetadata.isOrganization } graphAccountMetadata.website = jsonToString(data.get('website')) + graphAccount.website = graphAccountMetadata.website + graphAccountMetadata.save() + graphAccount.save() } } diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 2237f279..8f627d70 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -704,6 +704,7 @@ templates: handler: handleSubgraphDeploymentManifest entities: - SubgraphDeploymentManifest + - SubgraphDeployment abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -716,6 +717,7 @@ templates: handler: handleSubgraphDeploymentSchema entities: - SubgraphDeploymentSchema + - SubgraphDeployment abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -728,6 +730,7 @@ templates: handler: handleSubgraphMetadata entities: - SubgraphMetadata + - Subgraph abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -740,6 +743,7 @@ templates: handler: handleSubgraphVersionMetadata entities: - SubgraphVersionMetadata + - SubgraphVersion abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -752,6 +756,7 @@ templates: handler: handleGraphAccountMetadata entities: - GraphAccountMetadata + - GraphAccount abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json From deee95fb45e79e0a3313f0afe892fcfc7422a256 Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Wed, 7 Jun 2023 19:42:01 -0300 Subject: [PATCH 05/17] fix: multiple minor issues --- schema.graphql | 3 +++ src/mappings/gns.ts | 4 ++-- src/mappings/helpers/helpers.ts | 3 ++- src/mappings/ipfs.ts | 36 ++++++++++++++++----------------- subgraph.template.yaml | 10 ++++----- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/schema.graphql b/schema.graphql index 6e47ad0e..873fb0e7 100644 --- a/schema.graphql +++ b/schema.graphql @@ -535,6 +535,7 @@ type SubgraphVersion @entity { "Creation timestamp" createdAt: Int! + metadataHash: Bytes! # Metadata from IPFS linked in GNS metadata: SubgraphVersionMetadata! "Short description of the version" @@ -619,6 +620,8 @@ type SubgraphDeployment @entity { manifestEntity: SubgraphDeploymentManifest "Entity that represents the schema of the deployment. Filled by File Data Sources" schemaEntity: SubgraphDeploymentSchema + "Entity that represents the schema of the deployment. Filled by File Data Sources" + schemaIpfsHash: String "Contents of the Schema file" schema: String "Contents of the Manifest file" diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index 0e0c514c..6fdc0941 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -1082,7 +1082,7 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() subgraphVersion.metadataHash = event.params.versionMetadata - subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) + //subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) subgraphVersion.save() } else { let oldVersionID = subgraph.currentVersion @@ -1108,7 +1108,7 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() subgraphVersion.metadataHash = event.params.versionMetadata - subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) + //subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { diff --git a/src/mappings/helpers/helpers.ts b/src/mappings/helpers/helpers.ts index 509a6f69..16572d37 100644 --- a/src/mappings/helpers/helpers.ts +++ b/src/mappings/helpers/helpers.ts @@ -89,10 +89,11 @@ export function createOrLoadSubgraphDeployment( let prefix = '1220' deployment = new SubgraphDeployment(subgraphID) deployment.ipfsHash = Bytes.fromHexString(prefix.concat(subgraphID.slice(2))).toBase58() + /* deployment = fetchSubgraphDeploymentManifest( deployment as SubgraphDeployment, deployment.ipfsHash, - ) + )*/ deployment.createdAt = timestamp.toI32() deployment.stakedTokens = BigInt.fromI32(0) deployment.indexingRewardAmount = BigInt.fromI32(0) diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index e403dbab..d6460eae 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -12,8 +12,8 @@ import { jsonToString } from './utils' import { createOrLoadSubgraphCategory, createOrLoadSubgraphCategoryRelation } from './helpers/helpers' export function handleSubgraphMetadata(content: Bytes): void { - let subgraphMetadata = SubgraphMetadata.load(dataSource.stringParam()) - let subgraph = Subgraph.load(subgraphMetadata.subgraph) + let subgraphMetadata = SubgraphMetadata.load(dataSource.stringParam())! + let subgraph = Subgraph.load(subgraphMetadata.subgraph)! let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -58,15 +58,15 @@ export function handleSubgraphMetadata(content: Bytes): void { } export function handleSubgraphVersionMetadata(content: Bytes): void { - let subgraphVersionMetadata = SubgraphVersionMetadata.load(dataSource.stringParam()) - const value = json.fromBytes(content).toObject() - if (value) { - subgraphMetadata.save() - } + // let subgraphVersionMetadata = SubgraphVersionMetadata.load(dataSource.stringParam()) + // const value = json.fromBytes(content).toObject() + // if (value) { + // subgraphVersionMetadata.save() + // } } export function handleGraphAccountMetadata(content: Bytes): void { - let graphAccountMetadata = GraphAccountMetadata.load(dataSource.stringParam()) + let graphAccountMetadata = GraphAccountMetadata.load(dataSource.stringParam())! let graphAccount = GraphAccount.load(graphAccountMetadata.graphAccount)! let tryData = json.try_fromBytes(content) if (tryData.isOk) { @@ -93,17 +93,17 @@ export function handleGraphAccountMetadata(content: Bytes): void { } export function handleSubgraphDeploymentSchema(content: Bytes): void { - let subgraphDeploymentSchema = new SubgraphDeploymentSchema(dataSource.stringParam()) - const value = json.fromBytes(content).toObject() - if (value) { - subgraphMetadata.save() - } + // let subgraphDeploymentSchema = new SubgraphDeploymentSchema(dataSource.stringParam()) + // const value = json.fromBytes(content).toObject() + // if (value) { + // subgraphDeploymentSchema.save() + // } } export function handleSubgraphDeploymentManifest(content: Bytes): void { - let subgraphDeploymentManifest = new SubgraphDeploymentManifest(dataSource.stringParam()) - const value = json.fromBytes(content).toObject() - if (value) { - subgraphMetadata.save() - } + // let subgraphDeploymentManifest = new SubgraphDeploymentManifest(dataSource.stringParam()) + // const value = json.fromBytes(content).toObject() + // if (value) { + // subgraphDeploymentManifest.save() + // } } diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 8f627d70..784c0137 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -700,7 +700,7 @@ templates: mapping: apiVersion: 0.0.7 language: wasm/assemblyscript - file: ./src/mapping/ipfs.ts + file: ./src/mappings/ipfs.ts handler: handleSubgraphDeploymentManifest entities: - SubgraphDeploymentManifest @@ -713,7 +713,7 @@ templates: mapping: apiVersion: 0.0.7 language: wasm/assemblyscript - file: ./src/mapping/ipfs.ts + file: ./src/mappings/ipfs.ts handler: handleSubgraphDeploymentSchema entities: - SubgraphDeploymentSchema @@ -726,7 +726,7 @@ templates: mapping: apiVersion: 0.0.7 language: wasm/assemblyscript - file: ./src/mapping/ipfs.ts + file: ./src/mappings/ipfs.ts handler: handleSubgraphMetadata entities: - SubgraphMetadata @@ -739,7 +739,7 @@ templates: mapping: apiVersion: 0.0.7 language: wasm/assemblyscript - file: ./src/mapping/ipfs.ts + file: ./src/mappings/ipfs.ts handler: handleSubgraphVersionMetadata entities: - SubgraphVersionMetadata @@ -752,7 +752,7 @@ templates: mapping: apiVersion: 0.0.7 language: wasm/assemblyscript - file: ./src/mapping/ipfs.ts + file: ./src/mappings/ipfs.ts handler: handleGraphAccountMetadata entities: - GraphAccountMetadata From 19564b686b21d155af082077b98c408f2ab2aede Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Wed, 7 Jun 2023 19:45:17 -0300 Subject: [PATCH 06/17] fix: make metadata fields nullable --- schema.graphql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/schema.graphql b/schema.graphql index 873fb0e7..5750db17 100644 --- a/schema.graphql +++ b/schema.graphql @@ -244,7 +244,7 @@ type GraphAccount @entity { defaultDisplayName: String # IPFS Metadata. Duplicated for backwards compatibility - metadata: GraphAccountMetadata! + metadata: GraphAccountMetadata "True if it is an organization. False if it is an individual" isOrganization: Boolean "Main repository of code for the graph account" @@ -443,7 +443,7 @@ type Subgraph @entity { "Subgraph metadata" metadataHash: Bytes! "Subgraph metadata ipfs hash and entity" - metadata: SubgraphMetadata! + metadata: SubgraphMetadata "Short description of the subgraph" description: String "Image in string format" @@ -537,7 +537,7 @@ type SubgraphVersion @entity { metadataHash: Bytes! # Metadata from IPFS linked in GNS - metadata: SubgraphVersionMetadata! + metadata: SubgraphVersionMetadata "Short description of the version" description: String "Semantic versioning label" From 3ef4e488045e25fb0c1510c577f213a7cf27fe1b Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Wed, 7 Jun 2023 19:48:29 -0300 Subject: [PATCH 07/17] fix: nullable metadataHash --- schema.graphql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schema.graphql b/schema.graphql index 5750db17..dbf194ca 100644 --- a/schema.graphql +++ b/schema.graphql @@ -441,7 +441,7 @@ type Subgraph @entity { # Metadata from IPFS linked in GNS. For backwards compatibility we duplicate it "Subgraph metadata" - metadataHash: Bytes! + metadataHash: Bytes "Subgraph metadata ipfs hash and entity" metadata: SubgraphMetadata "Short description of the subgraph" @@ -535,7 +535,7 @@ type SubgraphVersion @entity { "Creation timestamp" createdAt: Int! - metadataHash: Bytes! + metadataHash: Bytes # Metadata from IPFS linked in GNS metadata: SubgraphVersionMetadata "Short description of the version" From 553bf80d398f9202d92cdaeaf2c2cf8d17436c74 Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Fri, 16 Jun 2023 14:35:29 -0300 Subject: [PATCH 08/17] fix: lots of minor fixes to make Subgraph/GraphAccount metadata work --- schema.graphql | 96 +++++++---------------------- src/mappings/ethereumDIDRegistry.ts | 5 +- src/mappings/gns.ts | 7 --- src/mappings/helpers/helpers.ts | 75 +++++++++++----------- src/mappings/ipfs.ts | 39 ++---------- subgraph.template.yaml | 5 -- 6 files changed, 63 insertions(+), 164 deletions(-) diff --git a/schema.graphql b/schema.graphql index dbf194ca..0e8e9c7e 100644 --- a/schema.graphql +++ b/schema.graphql @@ -243,20 +243,8 @@ type GraphAccount @entity { "Default display name is the current default name. Used for filtered queries in the explorer" defaultDisplayName: String - # IPFS Metadata. Duplicated for backwards compatibility + # IPFS Metadata. metadata: GraphAccountMetadata - "True if it is an organization. False if it is an individual" - isOrganization: Boolean - "Main repository of code for the graph account" - codeRepository: String - "Description of the graph account" - description: String - "Image URL" - image: String - "Website URL" - website: String - "Display name. Not unique" - displayName: String # Operator info "Operator of other Graph Accounts" @@ -309,11 +297,11 @@ type GraphAccount @entity { tokenLockWallets: [TokenLockWallet!]! } -type GraphAccountMetadata @entity { +type GraphAccountMetadata @entity(immutable:true) { "IPFS hash with account metadata details" id: ID! "Original graph account that created it" - graphAccount: GraphAccount! + graphAccount: [GraphAccount!] @derivedFrom(field:"metadata") "True if it is an organization. False if it is an individual" isOrganization: Boolean "Main repository of code for the graph account" @@ -439,35 +427,21 @@ type Subgraph @entity { "Total amount of NameSignal entities" nameSignalCount: Int! - # Metadata from IPFS linked in GNS. For backwards compatibility we duplicate it + # Metadata from IPFS linked in GNS "Subgraph metadata" metadataHash: Bytes "Subgraph metadata ipfs hash and entity" metadata: SubgraphMetadata - "Short description of the subgraph" - description: String - "Image in string format" - image: String - "NFT Image representation" - nftImage: String - "Location of the code for this project" - codeRepository: String - "Projects website" - website: String - "Display name" - displayName: String - "Categories that the subgraph belongs to. Modelled with a relation to allow for many-to-many relationship querying" - categories: [SubgraphCategoryRelation!]! @derivedFrom(field: "subgraph") # Auxiliary fields currentVersionRelationEntity: CurrentSubgraphDeploymentRelation } -type SubgraphMetadata @entity { +type SubgraphMetadata @entity(immutable:true) { "Subgraph metadata ipfs hash" id: ID! "Subgraph entity" - subgraph: Subgraph! + subgraph: Subgraph @derivedFrom(field:"metadata") "Short description of the subgraph" description: String "Image in string format" @@ -480,7 +454,8 @@ type SubgraphMetadata @entity { website: String "Display name" displayName: String - #maybe add categories here too? + "Categories that the subgraph belongs to." + categories: [String!] } type CurrentSubgraphDeploymentRelation @entity { @@ -495,25 +470,6 @@ type CurrentSubgraphDeploymentRelation @entity { active: Boolean! } -type Network @entity { - id: ID! - - deployments: [SubgraphDeploymentManifest!]! @derivedFrom(field: "network") -} - -type SubgraphCategoryRelation @entity { - id: ID! - - subgraph: Subgraph! - - category: SubgraphCategory! -} - -type SubgraphCategory @entity { - id: ID! - - subgraphs: [SubgraphCategoryRelation!]! @derivedFrom(field: "category") -} """ The SubgraphVersion entity represents a version of the Subgraph. A new SubgraphVersion is created @@ -538,21 +494,17 @@ type SubgraphVersion @entity { metadataHash: Bytes # Metadata from IPFS linked in GNS metadata: SubgraphVersionMetadata - "Short description of the version" - description: String - "Semantic versioning label" - label: String entityVersion: Int! "[DEPRECATED] Used for duplicate entities to enable old IDs from before the subgraph NFT update" linkedEntity: SubgraphVersion } -type SubgraphVersionMetadata @entity { +type SubgraphVersionMetadata @entity(immutable:true) { "Subgraph version metadata ipfs hash" id: ID! "Subgraph version entity" - subgraphVersion: SubgraphVersion! + subgraphVersion: SubgraphVersion @derivedFrom(field:"metadata") "Short description of the version" description: String "Semantic versioning label" @@ -617,19 +569,11 @@ type SubgraphDeployment @entity { # From Subgraph Manifest # dataSources: [DataSource!] "Entity that represents the manifest of the deployment. Filled by File Data Sources" - manifestEntity: SubgraphDeploymentManifest - "Entity that represents the schema of the deployment. Filled by File Data Sources" - schemaEntity: SubgraphDeploymentSchema + manifest: SubgraphDeploymentManifest "Entity that represents the schema of the deployment. Filled by File Data Sources" + schema: SubgraphDeploymentSchema + "shcema ipfs hash string" schemaIpfsHash: String - "Contents of the Schema file" - schema: String - "Contents of the Manifest file" - manifest: String - "Network where the contracts that the subgraph indexes are located" - network: Network - "Whether the subgraph is a SpS/SbS. Null if we can't parse it" - poweredBySubstreams: Boolean # Counters for currentSignalledTokens tracking on Subgraph "Total amount of Subgraph entities that used this deployment at some point. subgraphCount >= activeSubgraphCount + deprecatedSubgraphCount" @@ -653,20 +597,24 @@ type SubgraphDeployment @entity { signalledTokensReceivedOnL2: BigInt! } -type SubgraphDeploymentSchema @entity { +type SubgraphDeploymentSchema @entity(immutable:true) { "IPFS Hash" id: ID! + "Link to SubgraphDeployment entity" + deployment: SubgraphDeployment @derivedFrom(field:"schema") "Contents of the Schema file" schema: String } -type SubgraphDeploymentManifest @entity { +type SubgraphDeploymentManifest @entity(immutable:true) { "IPFS Hash" id: ID! + "Link to SubgraphDeployment entity" + deployment: SubgraphDeployment @derivedFrom(field:"manifest") "Contents of the Manifest file" manifest: String "Network where the contracts that the subgraph indexes are located" - network: Network + network: String "Whether the subgraph is a SpS/SbS. Null if we can't parse it" poweredBySubstreams: Boolean } @@ -1489,10 +1437,10 @@ Full test search for displayName and description on the Subgraph Entity """ type _Schema_ @fulltext( - name: "subgraphSearch" + name: "subgraphMetadataSearch" language: en algorithm: rank - include: [{ entity: "Subgraph", fields: [{ name: "displayName" }, { name: "description" }] }] + include: [{ entity: "SubgraphMetadata", fields: [{ name: "displayName" }, { name: "description" }] }] ) @fulltext( name: "curatorSearch" diff --git a/src/mappings/ethereumDIDRegistry.ts b/src/mappings/ethereumDIDRegistry.ts index 3b54a4f0..b7536c06 100644 --- a/src/mappings/ethereumDIDRegistry.ts +++ b/src/mappings/ethereumDIDRegistry.ts @@ -1,7 +1,7 @@ import { Bytes } from '@graphprotocol/graph-ts' import { DIDAttributeChanged } from '../types/EthereumDIDRegistry/EthereumDIDRegistry' import { GraphAccountMetadata as GraphAccountMetadataTemplate } from '../types/templates' -import { GraphAccount, GraphAccountMetadata } from '../types/schema' +import { GraphAccount } from '../types/schema' import { addQm, createOrLoadGraphAccount } from './helpers/helpers' @@ -28,9 +28,6 @@ export function handleDIDAttributeChanged(event: DIDAttributeChanged): void { tlw.save() } - let metadata = new GraphAccountMetadata(base58Hash) - metadata.graphAccount = graphAccount.id; - metadata.save() GraphAccountMetadataTemplate.create(base58Hash) } } diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index 6fdc0941..7f4dbdcb 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -40,7 +40,6 @@ import { GraphAccount, NameSignalSubgraphRelation, NameSignal, - SubgraphMetadata, } from '../types/schema' import { zeroBD } from './utils' @@ -185,9 +184,6 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - let metadata = new SubgraphMetadata(base58Hash) - metadata.subgraph = subgraph.id; - metadata.save() SubgraphMetadataTemplate.create(base58Hash) } @@ -720,9 +716,6 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - let metadata = new SubgraphMetadata(base58Hash) - metadata.subgraph = subgraph.id; - metadata.save() SubgraphMetadataTemplate.create(base58Hash) } diff --git a/src/mappings/helpers/helpers.ts b/src/mappings/helpers/helpers.ts index 16572d37..2ab443f9 100644 --- a/src/mappings/helpers/helpers.ts +++ b/src/mappings/helpers/helpers.ts @@ -22,9 +22,6 @@ import { NameSignal, Delegator, DelegatedStake, - Network, - SubgraphCategory, - SubgraphCategoryRelation, NameSignalSubgraphRelation, CurrentSubgraphDeploymentRelation, } from '../../types/schema' @@ -857,41 +854,41 @@ export function calculatePricePerShare(deployment: SubgraphDeployment): BigDecim return pricePerShare } -export function createOrLoadNetwork(id: string): Network { - let network = Network.load(id) - if (network == null) { - network = new Network(id) - - network.save() - } - return network as Network -} - -export function createOrLoadSubgraphCategory(id: string): SubgraphCategory { - let category = SubgraphCategory.load(id) - if (category == null) { - category = new SubgraphCategory(id) - - category.save() - } - return category as SubgraphCategory -} - -export function createOrLoadSubgraphCategoryRelation( - categoryId: string, - subgraphId: string, -): SubgraphCategoryRelation { - let id = joinID([categoryId, subgraphId]) - let relation = SubgraphCategoryRelation.load(id) - if (relation == null) { - relation = new SubgraphCategoryRelation(id) - relation.subgraph = subgraphId - relation.category = categoryId - - relation.save() - } - return relation as SubgraphCategoryRelation -} +// export function createOrLoadNetwork(id: string): Network { +// let network = Network.load(id) +// if (network == null) { +// network = new Network(id) + +// network.save() +// } +// return network as Network +// } + +// export function createOrLoadSubgraphCategory(id: string): SubgraphCategory { +// let category = SubgraphCategory.load(id) +// if (category == null) { +// category = new SubgraphCategory(id) + +// category.save() +// } +// return category as SubgraphCategory +// } + +// export function createOrLoadSubgraphCategoryRelation( +// categoryId: string, +// subgraphMetadataId: string, +// ): SubgraphCategoryRelation { +// let id = joinID([categoryId, subgraphMetadataId]) +// let relation = SubgraphCategoryRelation.load(id) +// if (relation == null) { +// relation = new SubgraphCategoryRelation(id) +// relation.metadata = subgraphMetadataId +// relation.category = categoryId + +// relation.save() +// } +// return relation as SubgraphCategoryRelation +// } export function updateCurrentDeploymentLinks( oldDeployment: SubgraphDeployment | null, @@ -952,7 +949,7 @@ export function convertBigIntSubgraphIDToBase58(bigIntRepresentation: BigInt): S // Although for the events where the uint256 is provided, we probably don't need to unpad. let hexString = bigIntRepresentation.toHexString() if (hexString.length % 2 != 0) { - log.error('Hex string not even, hex: {}, original: {}. Padding it to even length', [ + log.warning('Hex string not even, hex: {}, original: {}. Padding it to even length', [ hexString, bigIntRepresentation.toString(), ]) diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index d6460eae..b79fc315 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -5,55 +5,33 @@ import { GraphAccountMetadata, SubgraphDeploymentSchema, SubgraphDeploymentManifest, - Subgraph, - GraphAccount } from '../types/schema' import { jsonToString } from './utils' -import { createOrLoadSubgraphCategory, createOrLoadSubgraphCategoryRelation } from './helpers/helpers' export function handleSubgraphMetadata(content: Bytes): void { - let subgraphMetadata = SubgraphMetadata.load(dataSource.stringParam())! - let subgraph = Subgraph.load(subgraphMetadata.subgraph)! + let subgraphMetadata = new SubgraphMetadata(dataSource.stringParam()) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() - // Duplicating the fields for backwards compatibility subgraphMetadata.description = jsonToString(data.get('description')) subgraphMetadata.displayName = jsonToString(data.get('displayName')) subgraphMetadata.codeRepository = jsonToString(data.get('codeRepository')) subgraphMetadata.website = jsonToString(data.get('website')) - - subgraph.description = subgraphMetadata.description - subgraph.displayName = subgraphMetadata.displayName - subgraph.codeRepository = subgraphMetadata.codeRepository - subgraph.website = subgraphMetadata.website let categories = data.get('categories') if (categories != null && !categories.isNull()) { - let categoriesArray = categories.toArray() - - for (let i = 0; i < categoriesArray.length; i++) { - let categoryId = jsonToString(categoriesArray[i]) - createOrLoadSubgraphCategory(categoryId) - createOrLoadSubgraphCategoryRelation(categoryId, subgraph.id) - if (subgraph.linkedEntity != null) { - createOrLoadSubgraphCategoryRelation(categoryId, subgraph.linkedEntity!) - } - } + let categoriesArray = categories.toArray().map((element) => jsonToString(element)) + subgraphMetadata.categories = categoriesArray } let image = jsonToString(data.get('image')) let subgraphImage = data.get('subgraphImage') if (subgraphImage != null && subgraphImage.kind === JSONValueKind.STRING) { subgraphMetadata.nftImage = image subgraphMetadata.image = jsonToString(subgraphImage) - subgraph.nftImage = subgraphMetadata.nftImage - subgraph.image = subgraphMetadata.image } else { subgraphMetadata.image = image - subgraph.image = subgraphMetadata.image } subgraphMetadata.save() - subgraph.save() } } @@ -66,8 +44,7 @@ export function handleSubgraphVersionMetadata(content: Bytes): void { } export function handleGraphAccountMetadata(content: Bytes): void { - let graphAccountMetadata = GraphAccountMetadata.load(dataSource.stringParam())! - let graphAccount = GraphAccount.load(graphAccountMetadata.graphAccount)! + let graphAccountMetadata = new GraphAccountMetadata(dataSource.stringParam()) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -75,20 +52,12 @@ export function handleGraphAccountMetadata(content: Bytes): void { graphAccountMetadata.description = jsonToString(data.get('description')) graphAccountMetadata.image = jsonToString(data.get('image')) graphAccountMetadata.displayName = jsonToString(data.get('displayName')) - graphAccount.codeRepository = graphAccountMetadata.codeRepository - graphAccount.description = graphAccountMetadata.description - graphAccount.image = graphAccountMetadata.image - graphAccount.displayName = graphAccountMetadata.displayName let isOrganization = data.get('isOrganization') if (isOrganization != null && isOrganization.kind === JSONValueKind.BOOL) { graphAccountMetadata.isOrganization = isOrganization.toBool() - graphAccount.isOrganization = graphAccountMetadata.isOrganization } graphAccountMetadata.website = jsonToString(data.get('website')) - graphAccount.website = graphAccountMetadata.website - graphAccountMetadata.save() - graphAccount.save() } } diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 784c0137..cd87fa2f 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -704,7 +704,6 @@ templates: handler: handleSubgraphDeploymentManifest entities: - SubgraphDeploymentManifest - - SubgraphDeployment abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -717,7 +716,6 @@ templates: handler: handleSubgraphDeploymentSchema entities: - SubgraphDeploymentSchema - - SubgraphDeployment abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -730,7 +728,6 @@ templates: handler: handleSubgraphMetadata entities: - SubgraphMetadata - - Subgraph abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -743,7 +740,6 @@ templates: handler: handleSubgraphVersionMetadata entities: - SubgraphVersionMetadata - - SubgraphVersion abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -756,7 +752,6 @@ templates: handler: handleGraphAccountMetadata entities: - GraphAccountMetadata - - GraphAccount abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json From 982879b94859e1e968e5f5783b66996363abfb3a Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Mon, 19 Jun 2023 13:03:58 -0300 Subject: [PATCH 09/17] feat: add manifest FDS handler, schema scaffolding for once FDS offchain creation is ready --- schema.graphql | 10 ++-- src/mappings/gns.ts | 13 ++++-- src/mappings/helpers/helpers.ts | 13 +++--- src/mappings/ipfs.ts | 83 ++++++++++++++++++++++++++------- 4 files changed, 86 insertions(+), 33 deletions(-) diff --git a/schema.graphql b/schema.graphql index 0e8e9c7e..3381a54f 100644 --- a/schema.graphql +++ b/schema.graphql @@ -570,10 +570,6 @@ type SubgraphDeployment @entity { # dataSources: [DataSource!] "Entity that represents the manifest of the deployment. Filled by File Data Sources" manifest: SubgraphDeploymentManifest - "Entity that represents the schema of the deployment. Filled by File Data Sources" - schema: SubgraphDeploymentSchema - "shcema ipfs hash string" - schemaIpfsHash: String # Counters for currentSignalledTokens tracking on Subgraph "Total amount of Subgraph entities that used this deployment at some point. subgraphCount >= activeSubgraphCount + deprecatedSubgraphCount" @@ -601,7 +597,7 @@ type SubgraphDeploymentSchema @entity(immutable:true) { "IPFS Hash" id: ID! "Link to SubgraphDeployment entity" - deployment: SubgraphDeployment @derivedFrom(field:"schema") + manifest: SubgraphDeploymentManifest @derivedFrom(field:"schema") "Contents of the Schema file" schema: String } @@ -611,6 +607,10 @@ type SubgraphDeploymentManifest @entity(immutable:true) { id: ID! "Link to SubgraphDeployment entity" deployment: SubgraphDeployment @derivedFrom(field:"manifest") + "Schema entity. Not yet working due to limitations with File Data Sources" + schema: SubgraphDeploymentSchema + "Schema ipfs hash" + schemaIpfsHash: String "Contents of the Manifest file" manifest: String "Network where the contracts that the subgraph indexes are located" diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index 7f4dbdcb..3ecb1873 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -25,7 +25,8 @@ import { } from '../types/GNS/GNSStitched' import { - SubgraphMetadata as SubgraphMetadataTemplate + SubgraphMetadata as SubgraphMetadataTemplate, + SubgraphVersionMetadata as SubgraphVersionMetadataTemplate } from '../types/templates' import { @@ -235,10 +236,10 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() subgraphVersion.metadataHash = event.params.versionMetadata - //subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) - subgraphVersion.save() + SubgraphVersionMetadataTemplate.create(base58Hash) + let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { let oldVersion = SubgraphVersion.load(oldVersionID!)! @@ -1075,8 +1076,9 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() subgraphVersion.metadataHash = event.params.versionMetadata - //subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) subgraphVersion.save() + + SubgraphVersionMetadataTemplate.create(base58Hash) } else { let oldVersionID = subgraph.currentVersion @@ -1101,7 +1103,6 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() subgraphVersion.metadataHash = event.params.versionMetadata - //subgraphVersion = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { @@ -1111,6 +1112,8 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi // create deployment - named subgraph relationship, and update the old one updateCurrentDeploymentLinks(oldDeployment, deployment, subgraph as Subgraph) subgraphVersion.save() + + SubgraphVersionMetadataTemplate.create(base58Hash) } } diff --git a/src/mappings/helpers/helpers.ts b/src/mappings/helpers/helpers.ts index 2ab443f9..454e2c45 100644 --- a/src/mappings/helpers/helpers.ts +++ b/src/mappings/helpers/helpers.ts @@ -25,12 +25,15 @@ import { NameSignalSubgraphRelation, CurrentSubgraphDeploymentRelation, } from '../../types/schema' +import { + SubgraphDeploymentManifest as SubgraphDeploymentManifestTemplate +} from '../../types/templates' import { ENS } from '../../types/GNS/ENS' import { Controller } from '../../types/Controller/Controller' import { EpochManager } from '../../types/EpochManager/EpochManager' -import { fetchSubgraphDeploymentManifest } from './metadata' import { addresses } from '../../../config/addresses' + export function createOrLoadSubgraph( bigIntID: BigInt, owner: Address, @@ -86,11 +89,7 @@ export function createOrLoadSubgraphDeployment( let prefix = '1220' deployment = new SubgraphDeployment(subgraphID) deployment.ipfsHash = Bytes.fromHexString(prefix.concat(subgraphID.slice(2))).toBase58() - /* - deployment = fetchSubgraphDeploymentManifest( - deployment as SubgraphDeployment, - deployment.ipfsHash, - )*/ + deployment.manifest = deployment.ipfsHash deployment.createdAt = timestamp.toI32() deployment.stakedTokens = BigInt.fromI32(0) deployment.indexingRewardAmount = BigInt.fromI32(0) @@ -116,6 +115,8 @@ export function createOrLoadSubgraphDeployment( deployment.deprecatedSubgraphCount = 0 deployment.save() + SubgraphDeploymentManifestTemplate.create(deployment.ipfsHash) + graphNetwork.subgraphDeploymentCount = graphNetwork.subgraphDeploymentCount + 1 graphNetwork.save() } diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index b79fc315..b933cf1a 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -1,4 +1,4 @@ -import { json, Bytes, dataSource, JSONValueKind } from '@graphprotocol/graph-ts' +import { json, Bytes, dataSource, JSONValueKind, log } from '@graphprotocol/graph-ts' import { SubgraphMetadata, SubgraphVersionMetadata, @@ -6,6 +6,9 @@ import { SubgraphDeploymentSchema, SubgraphDeploymentManifest, } from '../types/schema' +import { + SubgraphDeploymentSchema as SubgraphDeploymentSchemaTemplate +} from '../types/templates' import { jsonToString } from './utils' export function handleSubgraphMetadata(content: Bytes): void { @@ -36,11 +39,14 @@ export function handleSubgraphMetadata(content: Bytes): void { } export function handleSubgraphVersionMetadata(content: Bytes): void { - // let subgraphVersionMetadata = SubgraphVersionMetadata.load(dataSource.stringParam()) - // const value = json.fromBytes(content).toObject() - // if (value) { - // subgraphVersionMetadata.save() - // } + let subgraphVersionMetadata = new SubgraphVersionMetadata(dataSource.stringParam()) + let tryData = json.try_fromBytes(content) + if (tryData.isOk) { + let data = tryData.value.toObject() + subgraphVersionMetadata.description = jsonToString(data.get('description')) + subgraphVersionMetadata.label = jsonToString(data.get('label')) + } + subgraphVersionMetadata.save() } export function handleGraphAccountMetadata(content: Bytes): void { @@ -61,18 +67,61 @@ export function handleGraphAccountMetadata(content: Bytes): void { } } + export function handleSubgraphDeploymentSchema(content: Bytes): void { - // let subgraphDeploymentSchema = new SubgraphDeploymentSchema(dataSource.stringParam()) - // const value = json.fromBytes(content).toObject() - // if (value) { - // subgraphDeploymentSchema.save() - // } + let subgraphDeploymentSchema = new SubgraphDeploymentSchema(dataSource.stringParam()) + if (content !== null) { + subgraphDeploymentSchema.schema = content.toString() + } } export function handleSubgraphDeploymentManifest(content: Bytes): void { - // let subgraphDeploymentManifest = new SubgraphDeploymentManifest(dataSource.stringParam()) - // const value = json.fromBytes(content).toObject() - // if (value) { - // subgraphDeploymentManifest.save() - // } -} + let subgraphDeploymentManifest = new SubgraphDeploymentManifest(dataSource.stringParam()) + if (content !== null) { + subgraphDeploymentManifest.manifest = content.toString() + + let manifest = subgraphDeploymentManifest.manifest! + // we take the right side of the split, since it's the one which will have the schema ipfs hash + let schemaSplitTry = manifest.split('schema:\n', 2) + if (schemaSplitTry.length == 2) { + let schemaSplit = schemaSplitTry[1] + + let schemaFileSplitTry = schemaSplit.split('/ipfs/', 2) + if (schemaFileSplitTry.length == 2) { + let schemaFileSplit = schemaFileSplitTry[1] + + let schemaIpfsHashTry = schemaFileSplit.split('\n', 2) + if (schemaIpfsHashTry.length == 2) { + let schemaIpfsHash = schemaIpfsHashTry[0] + subgraphDeploymentManifest.schema = schemaIpfsHash + subgraphDeploymentManifest.schemaIpfsHash = schemaIpfsHash + + // Can't create this template here yet (due to current implementation limitations on File Data Sources, but once that's sorted out, this should work.) + //SubgraphDeploymentSchemaTemplate.create(schemaIpfsHash) + } else { + log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, schema file hash can't be retrieved. Error: schemaIpfsHashTry.length isn't 2, actual length: {}", [dataSource.stringParam(), schemaIpfsHashTry.length.toString()]) + } + } else { + log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, schema file hash can't be retrieved. Error: schemaFileSplitTry.length isn't 2, actual length: {}", [dataSource.stringParam(), schemaFileSplitTry.length.toString()]) + } + } else { + log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, schema file hash can't be retrieved. Error: schemaSplitTry.length isn't 2, actual length: {}", [dataSource.stringParam(), schemaSplitTry.length.toString()]) + } + + // We get the first occurrence of `network` since subgraphs can only have data sources for the same network + let networkSplitTry = manifest.split('network: ', 2) + if (networkSplitTry.length == 2) { + let networkSplit = networkSplitTry[1] + let networkTry = networkSplit.split('\n', 2) + if (networkTry.length == 2) { + let network = networkTry[0] + + subgraphDeploymentManifest.network = network + } else { + log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, network can't be parsed. Error: networkTry.length isn't 2, actual length: {}", [dataSource.stringParam(), networkTry.length.toString()]) + } + } else { + log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, network can't be parsed. Error: networkSplitTry.length isn't 2, actual length: {}", [dataSource.stringParam(), networkSplitTry.length.toString()]) + } + } +} \ No newline at end of file From 3e5f942be35c26b24cbc84c6664ee7dbd175f761 Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Mon, 11 Sep 2023 16:21:10 -0300 Subject: [PATCH 10/17] fix: removed no-ipfs/ipfs workflow differentiation --- ...eploy-goerli-arbitrum-subgraph-no-ipfs.yml | 20 ------------ .../deploy-goerli-subgraph-no-ipfs.yml | 20 ------------ ...-production-arbitrum-subgraph-no-ipfs.yaml | 20 ------------ .../deploy-production-subgraph-no-ipfs.yaml | 20 ------------ .github/workflows/template-deploy.yaml | 32 ------------------- 5 files changed, 112 deletions(-) delete mode 100644 .github/workflows/deploy-goerli-arbitrum-subgraph-no-ipfs.yml delete mode 100644 .github/workflows/deploy-goerli-subgraph-no-ipfs.yml delete mode 100644 .github/workflows/deploy-production-arbitrum-subgraph-no-ipfs.yaml delete mode 100644 .github/workflows/deploy-production-subgraph-no-ipfs.yaml diff --git a/.github/workflows/deploy-goerli-arbitrum-subgraph-no-ipfs.yml b/.github/workflows/deploy-goerli-arbitrum-subgraph-no-ipfs.yml deleted file mode 100644 index 574e35b1..00000000 --- a/.github/workflows/deploy-goerli-arbitrum-subgraph-no-ipfs.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Production Subgraph Non-IPFS (Arbitrum Goerli) - -on: - push: - tags: - - v* - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: false - -jobs: - deploy: - uses: ./.github/workflows/template-deploy.yaml - with: - ENVIRONMENT: production-arbitrum-goerli-no-ipfs - CONFIG: arbitrumGoerliAddressScript.ts - secrets: - NODE_AUTH_TOKEN: ${{ secrets.graphprotocol_npm_token }} - ACCESS_TOKEN: ${{ secrets.access_token }} diff --git a/.github/workflows/deploy-goerli-subgraph-no-ipfs.yml b/.github/workflows/deploy-goerli-subgraph-no-ipfs.yml deleted file mode 100644 index ad943796..00000000 --- a/.github/workflows/deploy-goerli-subgraph-no-ipfs.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Production Subgraph Non-IPFS (Goerli) - -on: - push: - tags: - - v* - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: false - -jobs: - deploy: - uses: ./.github/workflows/template-deploy.yaml - with: - ENVIRONMENT: production-goerli-no-ipfs - CONFIG: goerliAddressScript.ts - secrets: - NODE_AUTH_TOKEN: ${{ secrets.graphprotocol_npm_token }} - ACCESS_TOKEN: ${{ secrets.access_token }} diff --git a/.github/workflows/deploy-production-arbitrum-subgraph-no-ipfs.yaml b/.github/workflows/deploy-production-arbitrum-subgraph-no-ipfs.yaml deleted file mode 100644 index c979ba31..00000000 --- a/.github/workflows/deploy-production-arbitrum-subgraph-no-ipfs.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: Production Subgraph Non-IPFS (Arbitrum) - -on: - push: - tags: - - v* - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: false - -jobs: - deploy: - uses: ./.github/workflows/template-deploy.yaml - with: - ENVIRONMENT: production-arbitrum-no-ipfs - CONFIG: mainnetArbitrumAddressScript.ts - secrets: - NODE_AUTH_TOKEN: ${{ secrets.graphprotocol_npm_token }} - ACCESS_TOKEN: ${{ secrets.access_token }} diff --git a/.github/workflows/deploy-production-subgraph-no-ipfs.yaml b/.github/workflows/deploy-production-subgraph-no-ipfs.yaml deleted file mode 100644 index c934342e..00000000 --- a/.github/workflows/deploy-production-subgraph-no-ipfs.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: Production Subgraph Non-IPFS (Mainnet) - -on: - push: - tags: - - v* - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: false - -jobs: - deploy: - uses: ./.github/workflows/template-deploy.yaml - with: - ENVIRONMENT: production-no-ipfs - CONFIG: mainnetAddressScript.ts - secrets: - NODE_AUTH_TOKEN: ${{ secrets.graphprotocol_npm_token }} - ACCESS_TOKEN: ${{ secrets.access_token }} diff --git a/.github/workflows/template-deploy.yaml b/.github/workflows/template-deploy.yaml index 68cd87ee..bc9d9955 100644 --- a/.github/workflows/template-deploy.yaml +++ b/.github/workflows/template-deploy.yaml @@ -26,31 +26,26 @@ jobs: if: ${{ inputs.ENVIRONMENT == 'staging-arbitrum' }} run: | echo "ENV_SUFFIX=graph-network-arbitrum-staging" >> $GITHUB_ENV - echo "IPFS_SUFFIX=" >> $GITHUB_ENV - name: Set mainnet staging environment variables if: ${{ inputs.ENVIRONMENT == 'staging-mainnet' }} run: | echo "ENV_SUFFIX=graph-network-mainnet-staging" >> $GITHUB_ENV - echo "IPFS_SUFFIX=" >> $GITHUB_ENV - name: Set mainnet environment variables if: ${{ inputs.ENVIRONMENT == 'production' }} run: | echo "ENV_SUFFIX=graph-network-mainnet" >> $GITHUB_ENV - echo "IPFS_SUFFIX=" >> $GITHUB_ENV - name: Set arbitrum environment variables if: ${{ inputs.ENVIRONMENT == 'production-arbitrum' }} run: | echo "ENV_SUFFIX=graph-network-arbitrum" >> $GITHUB_ENV - echo "IPFS_SUFFIX=" >> $GITHUB_ENV - name: Set goerli production environment variables if: ${{ inputs.ENVIRONMENT == 'production-goerli' }} run: | echo "ENV_SUFFIX=graph-network-goerli" >> $GITHUB_ENV - echo "IPFS_SUFFIX=" >> $GITHUB_ENV - name: Set arbitrum goerli production environment variables if: ${{ inputs.ENVIRONMENT == 'production-arbitrum-goerli' }} @@ -70,30 +65,6 @@ jobs: echo "ENV_SUFFIX=graph-network-arbitrum-sepolia" >> $GITHUB_ENV echo "IPFS_SUFFIX=" >> $GITHUB_ENV - - name: Set mainnet environment variables no ipfs - if: ${{ inputs.ENVIRONMENT == 'production-no-ipfs' }} - run: | - echo "ENV_SUFFIX=no-ipfs-network-ethereum" >> $GITHUB_ENV - echo "IPFS_SUFFIX=no-" >> $GITHUB_ENV - - - name: Set arbitrum environment variables no ipfs - if: ${{ inputs.ENVIRONMENT == 'production-arbitrum-no-ipfs' }} - run: | - echo "ENV_SUFFIX=no-ipfs-network-arbitrum" >> $GITHUB_ENV - echo "IPFS_SUFFIX=no-" >> $GITHUB_ENV - - - name: Set goerli production environment variables no ipfs - if: ${{ inputs.ENVIRONMENT == 'production-goerli-no-ipfs' }} - run: | - echo "ENV_SUFFIX=no-ipfs-network-goerli" >> $GITHUB_ENV - echo "IPFS_SUFFIX=no-" >> $GITHUB_ENV - - - name: Set arbitrum goerli production environment variables no ipfs - if: ${{ inputs.ENVIRONMENT == 'production-arbitrum-goerli-no-ipfs' }} - run: | - echo "ENV_SUFFIX=no-ipfs-network-arb-goerli" >> $GITHUB_ENV - echo "IPFS_SUFFIX=no-" >> $GITHUB_ENV - - name: Checkout uses: actions/checkout@v3 @@ -111,9 +82,6 @@ jobs: NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} # Run scripts - - name: Prepare IPFS enabled/disabled files - run: ./node_modules/.bin/mustache ./config/${{ env.IPFS_SUFFIX }}ipfs.json ./src/mappings/helpers/metadata.template.ts > ./src/mappings/helpers/metadata.ts - - name: Prepare addresses ${{ inputs.ENVIRONMENT }} run: ./node_modules/.bin/ts-node config/${{ inputs.CONFIG }} && ./node_modules/.bin/mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts From 56b59f82f566f99e1065fd28857be2198ccc1f44 Mon Sep 17 00:00:00 2001 From: juanmardefago Date: Mon, 2 Oct 2023 18:15:35 -0300 Subject: [PATCH 11/17] fix: broken tests due to ipfs requirements --- .github/workflows/tests-l1.yaml | 2 -- package.json | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests-l1.yaml b/.github/workflows/tests-l1.yaml index b6bce9ff..02fdc0b9 100644 --- a/.github/workflows/tests-l1.yaml +++ b/.github/workflows/tests-l1.yaml @@ -24,8 +24,6 @@ jobs: run: yarn install # Run scripts - - name: Prep NO IPFS - run: ./node_modules/.bin/mustache ./config/no-ipfs.json ./src/mappings/helpers/metadata.template.ts > ./src/mappings/helpers/metadata.ts - name: Prep addressess run: ./node_modules/.bin/ts-node config/testAddressesL1.ts && ./node_modules/.bin/mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts - name: Prep test L1 diff --git a/package.json b/package.json index 72743540..21e75307 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "test-l2": "yarn prepare:test-l2 && yarn test", "prep:addresses:test:l1": "ts-node config/testAddressesL1.ts && mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts", "prep:addresses:test:l2": "ts-node config/testAddressesL2.ts && mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts", - "prepare:test-l1": "yarn prep:no-ipfs && yarn prep:addresses:test:l1 && mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && graph codegen --output-dir src/types/", - "prepare:test-l2": "yarn prep:no-ipfs && yarn prep:addresses:test:l2 && mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && graph codegen --output-dir src/types/" + "prepare:test-l1": "yarn && yarn prep:addresses:test:l1 && mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && graph codegen --output-dir src/types/", + "prepare:test-l2": "yarn && yarn prep:addresses:test:l2 && mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && graph codegen --output-dir src/types/" }, "devDependencies": { "@graphprotocol/contracts": "5.3.3", From a9dcc6b1b5c10e5d25d8cbf0d176698ce598a890 Mon Sep 17 00:00:00 2001 From: juanmardefago Date: Mon, 16 Oct 2023 18:00:48 -0300 Subject: [PATCH 12/17] fix: manifest and schema FDS --- src/mappings/ipfs.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index b933cf1a..378e5f43 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -73,6 +73,7 @@ export function handleSubgraphDeploymentSchema(content: Bytes): void { if (content !== null) { subgraphDeploymentSchema.schema = content.toString() } + subgraphDeploymentSchema.save() } export function handleSubgraphDeploymentManifest(content: Bytes): void { @@ -97,7 +98,7 @@ export function handleSubgraphDeploymentManifest(content: Bytes): void { subgraphDeploymentManifest.schemaIpfsHash = schemaIpfsHash // Can't create this template here yet (due to current implementation limitations on File Data Sources, but once that's sorted out, this should work.) - //SubgraphDeploymentSchemaTemplate.create(schemaIpfsHash) + SubgraphDeploymentSchemaTemplate.create(schemaIpfsHash) } else { log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, schema file hash can't be retrieved. Error: schemaIpfsHashTry.length isn't 2, actual length: {}", [dataSource.stringParam(), schemaIpfsHashTry.length.toString()]) } @@ -123,5 +124,8 @@ export function handleSubgraphDeploymentManifest(content: Bytes): void { } else { log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, network can't be parsed. Error: networkSplitTry.length isn't 2, actual length: {}", [dataSource.stringParam(), networkSplitTry.length.toString()]) } + let substreamsSplitTry = manifest.split('- kind: substreams', 2) + subgraphDeploymentManifest.poweredBySubstreams = substreamsSplitTry.length > 1 } + subgraphDeploymentManifest.save() } \ No newline at end of file From d613a85fd5d02afd2fdae3ecc7214e79099525cc Mon Sep 17 00:00:00 2001 From: juanmardefago Date: Thu, 26 Oct 2023 13:54:18 -0300 Subject: [PATCH 13/17] fix: description and feature list --- subgraph.template.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subgraph.template.yaml b/subgraph.template.yaml index cd87fa2f..36382c05 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -1,10 +1,9 @@ specVersion: 0.0.5 -description: The Graph Network Smart Contracts on Ethereum +description: Core Graph Network subgraph repository: https://github.com/graphprotocol/graph-network-subgraph schema: file: ./schema.graphql features: - - ipfsOnEthereumContracts - fullTextSearch dataSources: - kind: ethereum/contract From 7f18f5f52e491e46252b75ee6c5c69e69eae08ba Mon Sep 17 00:00:00 2001 From: juanmardefago Date: Tue, 21 Nov 2023 20:19:06 -0300 Subject: [PATCH 14/17] fix: missing link for metadata on SubgraphVersioN --- src/mappings/gns.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index 3ecb1873..c91899e6 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -236,6 +236,7 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() subgraphVersion.metadataHash = event.params.versionMetadata + subgraphVersion.metadata = base58Hash subgraphVersion.save() SubgraphVersionMetadataTemplate.create(base58Hash) @@ -1076,6 +1077,7 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() subgraphVersion.metadataHash = event.params.versionMetadata + subgraphVersion.metadata = base58Hash subgraphVersion.save() SubgraphVersionMetadataTemplate.create(base58Hash) @@ -1103,6 +1105,7 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() subgraphVersion.metadataHash = event.params.versionMetadata + subgraphVersion.metadata = base58Hash let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { From 5ac1b0ab16513b349a3f4bd356a67914c160616e Mon Sep 17 00:00:00 2001 From: juanmardefago Date: Tue, 28 Nov 2023 19:58:48 -0300 Subject: [PATCH 15/17] chore: change description to trigger resync --- subgraph.template.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 36382c05..a68da6f8 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -1,5 +1,5 @@ specVersion: 0.0.5 -description: Core Graph Network subgraph +description: Core Graph Network subgraph (FDS version) repository: https://github.com/graphprotocol/graph-network-subgraph schema: file: ./schema.graphql From ae7b8ba44118ce4f687c523a290dcef94b049504 Mon Sep 17 00:00:00 2001 From: juanmardefago Date: Fri, 22 Dec 2023 12:47:58 -0300 Subject: [PATCH 16/17] fix: duplicate entities FDS --- schema.graphql | 20 ++++++++++----- src/mappings/ethereumDIDRegistry.ts | 11 +++++--- src/mappings/gns.ts | 39 +++++++++++++++++++---------- src/mappings/ipfs.ts | 19 ++++++++------ 4 files changed, 59 insertions(+), 30 deletions(-) diff --git a/schema.graphql b/schema.graphql index 3381a54f..9059fbaf 100644 --- a/schema.graphql +++ b/schema.graphql @@ -300,8 +300,10 @@ type GraphAccount @entity { type GraphAccountMetadata @entity(immutable:true) { "IPFS hash with account metadata details" id: ID! - "Original graph account that created it" - graphAccount: [GraphAccount!] @derivedFrom(field:"metadata") + "Account that reference this metadata file. For compatibility purposes. For the full list use graphAccounts" + graphAccount: GraphAccount @derivedFrom(field:"metadata") + "Accounts that reference this metadata file" + graphAccounts: [GraphAccount!]! @derivedFrom(field:"metadata") "True if it is an organization. False if it is an individual" isOrganization: Boolean "Main repository of code for the graph account" @@ -440,8 +442,10 @@ type Subgraph @entity { type SubgraphMetadata @entity(immutable:true) { "Subgraph metadata ipfs hash" id: ID! - "Subgraph entity" + "Subgraph that reference this metadata. For compatibility purposes. For the full list use subgraphs" subgraph: Subgraph @derivedFrom(field:"metadata") + "Subgraphs that reference this metadata" + subgraphs: [Subgraph!]! @derivedFrom(field:"metadata") "Short description of the subgraph" description: String "Image in string format" @@ -503,8 +507,10 @@ type SubgraphVersion @entity { type SubgraphVersionMetadata @entity(immutable:true) { "Subgraph version metadata ipfs hash" id: ID! - "Subgraph version entity" + "SubgraphVersion entity that references this metadata. For compatibility purposes. For the full list use subgraphVersions" subgraphVersion: SubgraphVersion @derivedFrom(field:"metadata") + "SubgraphVersion entities that reference this metadata" + subgraphVersions: [SubgraphVersion!]! @derivedFrom(field:"metadata") "Short description of the version" description: String "Semantic versioning label" @@ -596,8 +602,10 @@ type SubgraphDeployment @entity { type SubgraphDeploymentSchema @entity(immutable:true) { "IPFS Hash" id: ID! - "Link to SubgraphDeployment entity" + "Link to a SubgraphDeploymentManifest entity that references this schema. For backwards compatibility purposes only, for the full list of manifests use manifests" manifest: SubgraphDeploymentManifest @derivedFrom(field:"schema") + "Links to SubgraphDeploymentManifest entities that reference this schema" + manifests: [SubgraphDeploymentManifest!]! @derivedFrom(field:"schema") "Contents of the Schema file" schema: String } @@ -607,7 +615,7 @@ type SubgraphDeploymentManifest @entity(immutable:true) { id: ID! "Link to SubgraphDeployment entity" deployment: SubgraphDeployment @derivedFrom(field:"manifest") - "Schema entity. Not yet working due to limitations with File Data Sources" + "Schema entity" schema: SubgraphDeploymentSchema "Schema ipfs hash" schemaIpfsHash: String diff --git a/src/mappings/ethereumDIDRegistry.ts b/src/mappings/ethereumDIDRegistry.ts index b7536c06..ba856e4b 100644 --- a/src/mappings/ethereumDIDRegistry.ts +++ b/src/mappings/ethereumDIDRegistry.ts @@ -1,4 +1,4 @@ -import { Bytes } from '@graphprotocol/graph-ts' +import { Bytes, DataSourceContext } from '@graphprotocol/graph-ts' import { DIDAttributeChanged } from '../types/EthereumDIDRegistry/EthereumDIDRegistry' import { GraphAccountMetadata as GraphAccountMetadataTemplate } from '../types/templates' import { GraphAccount } from '../types/schema' @@ -17,17 +17,20 @@ export function handleDIDAttributeChanged(event: DIDAttributeChanged): void { // called it directly, it could crash the subgraph let hexHash = changetype(addQm(event.params.value)) let base58Hash = hexHash.toBase58() - graphAccount.metadata = base58Hash + let metadataId = graphAccount.id.concat('-').concat(base58Hash) + graphAccount.metadata = metadataId graphAccount.save() // Update all associated vesting contract addresses let tlws = graphAccount.tokenLockWallets for (let i = 0; i < tlws.length; i++) { let tlw = GraphAccount.load(tlws[i])! - tlw.metadata = base58Hash + tlw.metadata = metadataId tlw.save() } - GraphAccountMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + GraphAccountMetadataTemplate.createWithContext(base58Hash, context) } } diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index c91899e6..a7b32260 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -1,4 +1,4 @@ -import { BigInt, BigDecimal, Bytes, log } from '@graphprotocol/graph-ts' +import { BigInt, BigDecimal, Bytes, log, DataSourceContext } from '@graphprotocol/graph-ts' import { SubgraphPublished, SubgraphPublished1, @@ -179,13 +179,15 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v let hexHash = changetype(addQm(event.params.subgraphMetadata)) let base58Hash = hexHash.toBase58() - + let metadataId = subgraph.id.concat('-').concat(base58Hash) subgraph.metadataHash = event.params.subgraphMetadata - subgraph.metadata = base58Hash + subgraph.metadata = metadataId subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - SubgraphMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphMetadataTemplate.createWithContext(base58Hash, context) } /** @@ -235,11 +237,14 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { subgraphVersion.createdAt = event.block.timestamp.toI32() let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() + let metadataId = subgraphVersion.id.concat('-').concat(base58Hash) subgraphVersion.metadataHash = event.params.versionMetadata - subgraphVersion.metadata = base58Hash + subgraphVersion.metadata = metadataId subgraphVersion.save() - SubgraphVersionMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context) let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { @@ -712,13 +717,15 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) let hexHash = changetype(addQm(event.params.subgraphMetadata)) let base58Hash = hexHash.toBase58() - + let metadataId = subgraph.id.concat('-').concat(base58Hash) subgraph.metadataHash = event.params.subgraphMetadata - subgraph.metadata = base58Hash; + subgraph.metadata = metadataId; subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - SubgraphMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphMetadataTemplate.createWithContext(base58Hash, context) } // - event: SignalMinted(indexed uint256,indexed address,uint256,uint256,uint256) @@ -1076,11 +1083,14 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let subgraphVersion = SubgraphVersion.load(versionID)! let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() + let metadataId = subgraphVersion.id.concat('-').concat(base58Hash) subgraphVersion.metadataHash = event.params.versionMetadata - subgraphVersion.metadata = base58Hash + subgraphVersion.metadata = metadataId subgraphVersion.save() - SubgraphVersionMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context) } else { let oldVersionID = subgraph.currentVersion @@ -1104,8 +1114,9 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi subgraphVersion.createdAt = event.block.timestamp.toI32() let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() + let metadataId = subgraphVersion.id.concat('-').concat(base58Hash) subgraphVersion.metadataHash = event.params.versionMetadata - subgraphVersion.metadata = base58Hash + subgraphVersion.metadata = metadataId let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { @@ -1116,7 +1127,9 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi updateCurrentDeploymentLinks(oldDeployment, deployment, subgraph as Subgraph) subgraphVersion.save() - SubgraphVersionMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context) } } diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index 378e5f43..e71b0814 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -1,4 +1,4 @@ -import { json, Bytes, dataSource, JSONValueKind, log } from '@graphprotocol/graph-ts' +import { json, Bytes, dataSource, JSONValueKind, log, DataSourceContext } from '@graphprotocol/graph-ts' import { SubgraphMetadata, SubgraphVersionMetadata, @@ -12,7 +12,8 @@ import { import { jsonToString } from './utils' export function handleSubgraphMetadata(content: Bytes): void { - let subgraphMetadata = new SubgraphMetadata(dataSource.stringParam()) + let id = dataSource.context().getString("id") + let subgraphMetadata = new SubgraphMetadata(id) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -39,7 +40,8 @@ export function handleSubgraphMetadata(content: Bytes): void { } export function handleSubgraphVersionMetadata(content: Bytes): void { - let subgraphVersionMetadata = new SubgraphVersionMetadata(dataSource.stringParam()) + let id = dataSource.context().getString("id") + let subgraphVersionMetadata = new SubgraphVersionMetadata(id) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -50,7 +52,8 @@ export function handleSubgraphVersionMetadata(content: Bytes): void { } export function handleGraphAccountMetadata(content: Bytes): void { - let graphAccountMetadata = new GraphAccountMetadata(dataSource.stringParam()) + let id = dataSource.context().getString("id") + let graphAccountMetadata = new GraphAccountMetadata(id) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -69,7 +72,8 @@ export function handleGraphAccountMetadata(content: Bytes): void { export function handleSubgraphDeploymentSchema(content: Bytes): void { - let subgraphDeploymentSchema = new SubgraphDeploymentSchema(dataSource.stringParam()) + let id = dataSource.context().getString("id") + let subgraphDeploymentSchema = new SubgraphDeploymentSchema(id) if (content !== null) { subgraphDeploymentSchema.schema = content.toString() } @@ -97,8 +101,9 @@ export function handleSubgraphDeploymentManifest(content: Bytes): void { subgraphDeploymentManifest.schema = schemaIpfsHash subgraphDeploymentManifest.schemaIpfsHash = schemaIpfsHash - // Can't create this template here yet (due to current implementation limitations on File Data Sources, but once that's sorted out, this should work.) - SubgraphDeploymentSchemaTemplate.create(schemaIpfsHash) + let context = new DataSourceContext() + context.setString('id', subgraphDeploymentManifest.id.concat('-').concat(schemaIpfsHash)) + SubgraphDeploymentSchemaTemplate.createWithContext(schemaIpfsHash, context) } else { log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, schema file hash can't be retrieved. Error: schemaIpfsHashTry.length isn't 2, actual length: {}", [dataSource.stringParam(), schemaIpfsHashTry.length.toString()]) } From a34c33ee291c47f261b4bee32cad1a3df250ea14 Mon Sep 17 00:00:00 2001 From: juanmardefago Date: Thu, 18 Jan 2024 16:57:05 -0300 Subject: [PATCH 17/17] fix: schema metadata not linked and potential id collisions --- src/mappings/ethereumDIDRegistry.ts | 3 ++- src/mappings/gns.ts | 15 ++++++++++----- src/mappings/ipfs.ts | 6 ++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/mappings/ethereumDIDRegistry.ts b/src/mappings/ethereumDIDRegistry.ts index ba856e4b..25bc015c 100644 --- a/src/mappings/ethereumDIDRegistry.ts +++ b/src/mappings/ethereumDIDRegistry.ts @@ -17,7 +17,8 @@ export function handleDIDAttributeChanged(event: DIDAttributeChanged): void { // called it directly, it could crash the subgraph let hexHash = changetype(addQm(event.params.value)) let base58Hash = hexHash.toBase58() - let metadataId = graphAccount.id.concat('-').concat(base58Hash) + let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) + let metadataId = uniqueTxID.concat('-').concat(graphAccount.id.concat('-').concat(base58Hash)) graphAccount.metadata = metadataId graphAccount.save() diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index a7b32260..b1a1c9c3 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -179,7 +179,8 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v let hexHash = changetype(addQm(event.params.subgraphMetadata)) let base58Hash = hexHash.toBase58() - let metadataId = subgraph.id.concat('-').concat(base58Hash) + let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) + let metadataId = uniqueTxID.concat('-').concat(subgraph.id.concat('-').concat(base58Hash)) subgraph.metadataHash = event.params.subgraphMetadata subgraph.metadata = metadataId subgraph.updatedAt = event.block.timestamp.toI32() @@ -237,7 +238,8 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { subgraphVersion.createdAt = event.block.timestamp.toI32() let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() - let metadataId = subgraphVersion.id.concat('-').concat(base58Hash) + let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) + let metadataId = uniqueTxID.concat('-').concat(subgraphVersion.id.concat('-').concat(base58Hash)) subgraphVersion.metadataHash = event.params.versionMetadata subgraphVersion.metadata = metadataId subgraphVersion.save() @@ -717,7 +719,8 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) let hexHash = changetype(addQm(event.params.subgraphMetadata)) let base58Hash = hexHash.toBase58() - let metadataId = subgraph.id.concat('-').concat(base58Hash) + let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) + let metadataId = uniqueTxID.concat('-').concat(subgraph.id.concat('-').concat(base58Hash)) subgraph.metadataHash = event.params.subgraphMetadata subgraph.metadata = metadataId; subgraph.updatedAt = event.block.timestamp.toI32() @@ -1083,7 +1086,8 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let subgraphVersion = SubgraphVersion.load(versionID)! let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() - let metadataId = subgraphVersion.id.concat('-').concat(base58Hash) + let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) + let metadataId = uniqueTxID.concat('-').concat(subgraphVersion.id.concat('-').concat(base58Hash)) subgraphVersion.metadataHash = event.params.versionMetadata subgraphVersion.metadata = metadataId subgraphVersion.save() @@ -1114,7 +1118,8 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi subgraphVersion.createdAt = event.block.timestamp.toI32() let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() - let metadataId = subgraphVersion.id.concat('-').concat(base58Hash) + let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) + let metadataId = uniqueTxID.concat('-').concat(subgraphVersion.id.concat('-').concat(base58Hash)) subgraphVersion.metadataHash = event.params.versionMetadata subgraphVersion.metadata = metadataId diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index e71b0814..d237e003 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -81,6 +81,7 @@ export function handleSubgraphDeploymentSchema(content: Bytes): void { } export function handleSubgraphDeploymentManifest(content: Bytes): void { + // Shouldn't need ID since the handler isn't gonna be called more than once, given that it's only on deployment creation. let subgraphDeploymentManifest = new SubgraphDeploymentManifest(dataSource.stringParam()) if (content !== null) { subgraphDeploymentManifest.manifest = content.toString() @@ -98,11 +99,12 @@ export function handleSubgraphDeploymentManifest(content: Bytes): void { let schemaIpfsHashTry = schemaFileSplit.split('\n', 2) if (schemaIpfsHashTry.length == 2) { let schemaIpfsHash = schemaIpfsHashTry[0] - subgraphDeploymentManifest.schema = schemaIpfsHash + let schemaId = subgraphDeploymentManifest.id.concat('-').concat(schemaIpfsHash) + subgraphDeploymentManifest.schema = schemaId subgraphDeploymentManifest.schemaIpfsHash = schemaIpfsHash let context = new DataSourceContext() - context.setString('id', subgraphDeploymentManifest.id.concat('-').concat(schemaIpfsHash)) + context.setString('id', schemaId) SubgraphDeploymentSchemaTemplate.createWithContext(schemaIpfsHash, context) } else { log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, schema file hash can't be retrieved. Error: schemaIpfsHashTry.length isn't 2, actual length: {}", [dataSource.stringParam(), schemaIpfsHashTry.length.toString()])