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 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 9973f257..21e75307 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", @@ -47,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", diff --git a/schema.graphql b/schema.graphql index 6a953a60..9059fbaf 100644 --- a/schema.graphql +++ b/schema.graphql @@ -243,21 +243,8 @@ type GraphAccount @entity { "Default display name is the current default name. Used for filtered queries in the explorer" 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 + # IPFS Metadata. + metadata: GraphAccountMetadata # Operator info "Operator of other Graph Accounts" @@ -310,6 +297,27 @@ type GraphAccount @entity { tokenLockWallets: [TokenLockWallet!]! } +type GraphAccountMetadata @entity(immutable:true) { + "IPFS hash with account metadata details" + id: ID! + "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" + 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 @@ -394,7 +402,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 @@ -423,9 +431,21 @@ type Subgraph @entity { # Metadata from IPFS linked in GNS "Subgraph metadata" - metadataHash: Bytes! + metadataHash: Bytes + "Subgraph metadata ipfs hash and entity" + metadata: SubgraphMetadata + + # Auxiliary fields + currentVersionRelationEntity: CurrentSubgraphDeploymentRelation +} + +type SubgraphMetadata @entity(immutable:true) { "Subgraph metadata ipfs hash" - ipfsMetadataHash: String + id: ID! + "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" @@ -438,11 +458,8 @@ 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 + "Categories that the subgraph belongs to." + categories: [String!] } type CurrentSubgraphDeploymentRelation @entity { @@ -457,25 +474,6 @@ type CurrentSubgraphDeploymentRelation @entity { active: Boolean! } -type Network @entity { - id: ID! - - deployments: [SubgraphDeployment!]! @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 @@ -497,16 +495,26 @@ type SubgraphVersion @entity { "Creation timestamp" createdAt: Int! - # Metadata from IPFS linked in GNS - "Subgraph version metadata content address" metadataHash: Bytes + # Metadata from IPFS linked in GNS + metadata: SubgraphVersionMetadata + + entityVersion: Int! + "[DEPRECATED] Used for duplicate entities to enable old IDs from before the subgraph NFT update" + linkedEntity: SubgraphVersion +} + +type SubgraphVersionMetadata @entity(immutable:true) { + "Subgraph version metadata ipfs hash" + id: ID! + "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" label: String - - entityVersion: Int! - linkedEntity: SubgraphVersion } """ @@ -566,16 +574,8 @@ 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 # Counters for currentSignalledTokens tracking on Subgraph "Total amount of Subgraph entities that used this deployment at some point. subgraphCount >= activeSubgraphCount + deprecatedSubgraphCount" @@ -599,6 +599,34 @@ type SubgraphDeployment @entity { signalledTokensReceivedOnL2: BigInt! } +type SubgraphDeploymentSchema @entity(immutable:true) { + "IPFS Hash" + id: ID! + "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 +} + +type SubgraphDeploymentManifest @entity(immutable:true) { + "IPFS Hash" + id: ID! + "Link to SubgraphDeployment entity" + deployment: SubgraphDeployment @derivedFrom(field:"manifest") + "Schema entity" + schema: SubgraphDeploymentSchema + "Schema ipfs hash" + schemaIpfsHash: String + "Contents of the Manifest file" + manifest: String + "Network where the contracts that the subgraph indexes are located" + network: String + "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 { @@ -1081,6 +1109,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 } @@ -1416,10 +1445,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 0d015017..25bc015c 100644 --- a/src/mappings/ethereumDIDRegistry.ts +++ b/src/mappings/ethereumDIDRegistry.ts @@ -1,8 +1,9 @@ -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' 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,21 @@ 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 + 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() - 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 = metadataId + tlw.save() + } + + 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 ece70d13..b1a1c9c3 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, @@ -24,6 +24,11 @@ import { GNSStitched as GNS, } from '../types/GNS/GNSStitched' +import { + SubgraphMetadata as SubgraphMetadataTemplate, + SubgraphVersionMetadata as SubgraphVersionMetadataTemplate +} from '../types/templates' + import { Subgraph, SubgraphVersion, @@ -51,12 +56,8 @@ import { updateCurrentDeploymentLinks, getSubgraphID, convertBigIntSubgraphIDToBase58, - duplicateOrUpdateSubgraphWithNewID, - duplicateOrUpdateSubgraphVersionWithNewID, - duplicateOrUpdateNameSignalWithNewID, createOrLoadGraphNetwork } from './helpers/helpers' -import { fetchSubgraphMetadata, fetchSubgraphVersionMetadata } from './helpers/metadata' import { addresses } from '../../config/addresses' export function handleSetDefaultName(event: SetDefaultName): void { @@ -171,10 +172,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 @@ -182,15 +179,16 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v let hexHash = changetype(addQm(event.params.subgraphMetadata)) let base58Hash = hexHash.toBase58() - + 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.ipfsMetadataHash = addQm(subgraph.metadataHash).toBase58() - subgraph = fetchSubgraphMetadata(subgraph, base58Hash) + subgraph.metadata = metadataId subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) - subgraphDuplicate.save() + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphMetadataTemplate.createWithContext(base58Hash, context) } /** @@ -202,10 +200,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 @@ -215,8 +209,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([ @@ -226,13 +219,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) @@ -242,7 +230,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 @@ -250,26 +238,22 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { subgraphVersion.createdAt = event.block.timestamp.toI32() let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() + 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 = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) - - let subgraphVersionDuplicate = duplicateOrUpdateSubgraphVersionWithNewID( - subgraphVersion, - versionIDOld, - 1, - ) - subgraphVersionDuplicate.subgraph = subgraphDuplicate.id - subgraphVersion.linkedEntity = subgraphVersionDuplicate.id - subgraphVersionDuplicate.save() + subgraphVersion.metadata = metadataId subgraphVersion.save() + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context) + let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { let oldVersion = SubgraphVersion.load(oldVersionID!)! 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) } /** @@ -278,10 +262,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)! @@ -290,9 +270,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() @@ -301,34 +278,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)! @@ -338,9 +303,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 @@ -409,14 +371,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) { @@ -449,10 +405,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)! @@ -462,9 +414,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, @@ -521,14 +470,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()) @@ -570,10 +513,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)! @@ -587,9 +526,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++) { @@ -632,15 +568,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() - } } } } @@ -648,26 +575,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)! @@ -676,9 +592,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, @@ -697,15 +610,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() @@ -790,11 +696,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 @@ -805,9 +706,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) - } } } @@ -821,17 +719,16 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) let hexHash = changetype(addQm(event.params.subgraphMetadata)) let base58Hash = hexHash.toBase58() - + 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.ipfsMetadataHash = addQm(subgraph.metadataHash).toBase58() - subgraph = fetchSubgraphMetadata(subgraph, base58Hash) + subgraph.metadata = metadataId; subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - if (subgraph.linkedEntity != null) { - let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, subgraph.linkedEntity!, 1) - subgraphDuplicate.save() - } + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphMetadataTemplate.createWithContext(base58Hash, context) } // - event: SignalMinted(indexed uint256,indexed address,uint256,uint256,uint256) @@ -849,11 +746,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 @@ -924,16 +816,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) { @@ -977,11 +859,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, @@ -1040,16 +917,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()) @@ -1102,11 +969,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, @@ -1128,16 +990,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() @@ -1160,11 +1012,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() @@ -1209,15 +1056,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() - } } } } @@ -1248,9 +1086,15 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let subgraphVersion = SubgraphVersion.load(versionID)! let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() + 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 = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) + subgraphVersion.metadata = metadataId subgraphVersion.save() + + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context) } else { let oldVersionID = subgraph.currentVersion @@ -1274,8 +1118,10 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi subgraphVersion.createdAt = event.block.timestamp.toI32() let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() + 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 = fetchSubgraphVersionMetadata(subgraphVersion, base58Hash) + subgraphVersion.metadata = metadataId let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { @@ -1284,29 +1130,11 @@ 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() + + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context) } } @@ -1320,9 +1148,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) @@ -1340,9 +1165,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 673fc14e..454e2c45 100644 --- a/src/mappings/helpers/helpers.ts +++ b/src/mappings/helpers/helpers.ts @@ -22,18 +22,18 @@ import { NameSignal, Delegator, DelegatedStake, - Network, - SubgraphCategory, - SubgraphCategoryRelation, 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, @@ -89,10 +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) @@ -118,6 +115,8 @@ export function createOrLoadSubgraphDeployment( deployment.deprecatedSubgraphCount = 0 deployment.save() + SubgraphDeploymentManifestTemplate.create(deployment.ipfsHash) + graphNetwork.subgraphDeploymentCount = graphNetwork.subgraphDeploymentCount + 1 graphNetwork.save() } @@ -739,7 +738,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() @@ -856,41 +855,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, @@ -951,7 +950,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(), ]) @@ -971,120 +970,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) 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..d237e003 --- /dev/null +++ b/src/mappings/ipfs.ts @@ -0,0 +1,138 @@ +import { json, Bytes, dataSource, JSONValueKind, log, DataSourceContext } from '@graphprotocol/graph-ts' +import { + SubgraphMetadata, + SubgraphVersionMetadata, + GraphAccountMetadata, + SubgraphDeploymentSchema, + SubgraphDeploymentManifest, +} from '../types/schema' +import { + SubgraphDeploymentSchema as SubgraphDeploymentSchemaTemplate +} from '../types/templates' +import { jsonToString } from './utils' + +export function handleSubgraphMetadata(content: Bytes): void { + 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() + 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().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) + } else { + subgraphMetadata.image = image + } + subgraphMetadata.save() + } +} + +export function handleSubgraphVersionMetadata(content: Bytes): void { + 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() + subgraphVersionMetadata.description = jsonToString(data.get('description')) + subgraphVersionMetadata.label = jsonToString(data.get('label')) + } + subgraphVersionMetadata.save() +} + +export function handleGraphAccountMetadata(content: Bytes): void { + 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() + 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 id = dataSource.context().getString("id") + let subgraphDeploymentSchema = new SubgraphDeploymentSchema(id) + if (content !== null) { + subgraphDeploymentSchema.schema = content.toString() + } + subgraphDeploymentSchema.save() +} + +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() + + 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] + let schemaId = subgraphDeploymentManifest.id.concat('-').concat(schemaIpfsHash) + subgraphDeploymentManifest.schema = schemaId + subgraphDeploymentManifest.schemaIpfsHash = schemaIpfsHash + + let context = new DataSourceContext() + 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()]) + } + } 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()]) + } + let substreamsSplitTry = manifest.split('- kind: substreams', 2) + subgraphDeploymentManifest.poweredBySubstreams = substreamsSplitTry.length > 1 + } + subgraphDeploymentManifest.save() +} \ No newline at end of file diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 002a8ea4..a68da6f8 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 (FDS version) repository: https://github.com/graphprotocol/graph-network-subgraph schema: file: ./schema.graphql features: - - ipfsOnEthereumContracts - fullTextSearch dataSources: - kind: ethereum/contract @@ -695,3 +694,63 @@ templates: handler: handleApproveTokenDestinations - event: RevokeTokenDestinations() handler: handleRevokeTokenDestinations + - name: SubgraphDeploymentManifest + kind: file/ipfs + mapping: + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/mappings/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/mappings/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/mappings/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/mappings/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/mappings/ipfs.ts + handler: handleGraphAccountMetadata + entities: + - GraphAccountMetadata + abis: + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json