Skip to content

Commit

Permalink
Merge pull request #6 from graphprotocol/juanmardefago/file-data-sour…
Browse files Browse the repository at this point in the history
…ces-refactor

feat: FDS refactor
  • Loading branch information
juanmardefago authored Jan 23, 2024
2 parents ea74680 + 874d1f5 commit 0905cfb
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 116 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/deploy-arbitrum-goerli-subgraph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Production Subgraph (Arbitrum-Goerli)

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

# Install commands
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
- name: yarn install
run: yarn
env:
NODE_AUTH_TOKEN: ${{secrets.graphprotocol_npm_token}}

# Run scripts
- name: Prepare addresses testnet
run: ./node_modules/.bin/ts-node ./config/arbitrumGoerliAddressScript.ts && ./node_modules/.bin/mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts
- name: Prepare testnet
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/run codegen --output-dir src/types/
- name: Deploy to testnet
run: ./node_modules/@graphprotocol/graph-cli/bin/run deploy graphprotocol/graph-activity-arbitrum-goerli --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
4 changes: 2 additions & 2 deletions .github/workflows/deploy-arbitrum-sepolia-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
- name: Prepare addresses testnet
run: ./node_modules/.bin/ts-node ./config/arbitrumSepoliaAddressScript.ts && ./node_modules/.bin/mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts
- name: Prepare testnet
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/graph codegen --output-dir src/types/
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/run codegen --output-dir src/types/
- name: Deploy to testnet
run: ./node_modules/@graphprotocol/graph-cli/bin/graph deploy graphprotocol/graph-activity-arb-sepolia --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
run: ./node_modules/@graphprotocol/graph-cli/bin/run deploy graphprotocol/graph-activity-arb-sepolia --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
35 changes: 35 additions & 0 deletions .github/workflows/deploy-arbitrum-subgraph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Production Subgraph (Arbitrum)

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

# Install commands
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
- name: yarn install
run: yarn
env:
NODE_AUTH_TOKEN: ${{secrets.graphprotocol_npm_token}}

# Run scripts
- name: Prepare addresses mainnet
run: ./node_modules/.bin/ts-node ./config/mainnetArbitrumAddressScript.ts && ./node_modules/.bin/mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts
- name: Prepare mainnet
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/run codegen --output-dir src/types/
- name: Deploy to mainnet production
run: ./node_modules/@graphprotocol/graph-cli/bin/run deploy graphprotocol/graph-activity-arbitrum --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
6 changes: 3 additions & 3 deletions .github/workflows/deploy-goerli-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
Expand All @@ -30,6 +30,6 @@ jobs:
- name: Prepare addresses testnet
run: ./node_modules/.bin/ts-node ./config/goerliAddressScript.ts && ./node_modules/.bin/mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts
- name: Prepare testnet
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/graph codegen --output-dir src/types/
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/run codegen --output-dir src/types/
- name: Deploy to testnet
run: ./node_modules/@graphprotocol/graph-cli/bin/graph deploy graphprotocol/graph-network-activity-testnet --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
run: ./node_modules/@graphprotocol/graph-cli/bin/run deploy graphprotocol/graph-network-activity-testnet --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
Expand All @@ -30,6 +30,6 @@ jobs:
- name: Prepare addresses mainnet
run: ./node_modules/.bin/ts-node ./config/mainnetAddressScript.ts && ./node_modules/.bin/mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts
- name: Prepare mainnet
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/graph codegen --output-dir src/types/
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/run codegen --output-dir src/types/
- name: Deploy to mainnet production
run: ./node_modules/@graphprotocol/graph-cli/bin/graph deploy graphprotocol/graph-network-activity --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
run: ./node_modules/@graphprotocol/graph-cli/bin/run deploy graphprotocol/graph-network-activity --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
4 changes: 2 additions & 2 deletions .github/workflows/deploy-sepolia-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
- name: Prepare addresses testnet
run: ./node_modules/.bin/ts-node ./config/sepoliaddressScript.ts && ./node_modules/.bin/mustache ./config/generatedAddresses.json ./config/addresses.template.ts > ./config/addresses.ts
- name: Prepare testnet
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/graph codegen --output-dir src/types/
run: ./node_modules/.bin/mustache ./config/generatedAddresses.json subgraph.template.yaml > subgraph.yaml && ./node_modules/@graphprotocol/graph-cli/bin/run codegen --output-dir src/types/
- name: Deploy to testnet
run: ./node_modules/@graphprotocol/graph-cli/bin/graph deploy graphprotocol/graph-activity-sepolia --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
run: ./node_modules/@graphprotocol/graph-cli/bin/run deploy graphprotocol/graph-activity-sepolia --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --access-token ${{secrets.access_token}}
2 changes: 1 addition & 1 deletion config/arbitrumSepoliaAddressScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export let addresses: Addresses = {
subgraphNFT: '{{arbsep.SubgraphNFT.address}}',
l1GraphTokenGateway: '',
l2GraphTokenGateway: '{{arbsep.L2GraphTokenGateway.address}}',
ethereumDIDRegistry: '{{arbsep.IEthereumDIDRegistry.address}}',
ethereumDIDRegistry: '{{arbsep.EthereumDIDRegistry.address}}',
isL1: false,
}

Expand Down
4 changes: 2 additions & 2 deletions config/mainnetAddressScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export let addresses: Addresses = {
graphToken: '{{mainnet.GraphToken.address}}',
epochManager: '{{mainnet.EpochManager.address}}',
disputeManager: '{{mainnet.DisputeManager.address}}',
staking: '{{mainnet.Staking.address}}',
staking: '{{mainnet.L1Staking.address}}',
curation: '{{mainnet.Curation.address}}',
rewardsManager: '{{mainnet.RewardsManager.address}}',
serviceRegistry: '{{mainnet.ServiceRegistry.address}}',
gns: '{{mainnet.GNS.address}}',
gns: '{{mainnet.L1GNS.address}}',
ens: '{{mainnet.IENS.address}}',
ensPublicResolver: '{{mainnet.IPublicResolver.address}}',
blockNumber: '',
Expand Down
6 changes: 3 additions & 3 deletions config/mainnetArbitrumAddressScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export let addresses: Addresses = {
graphToken: '{{arbitrum.L2GraphToken.address}}',
epochManager: '{{arbitrum.EpochManager.address}}',
disputeManager: '{{arbitrum.DisputeManager.address}}',
staking: '{{arbitrum.Staking.address}}',
curation: '{{arbitrum.Curation.address}}',
staking: '{{arbitrum.L2Staking.address}}',
curation: '{{arbitrum.L2Curation.address}}',
rewardsManager: '{{arbitrum.RewardsManager.address}}',
serviceRegistry: '{{arbitrum.ServiceRegistry.address}}',
gns: '{{arbitrum.GNS.address}}',
gns: '{{arbitrum.L2GNS.address}}',
ens: '{{arbitrum.IENS.address}}',
ensPublicResolver: '{{arbitrum.IPublicResolver.address}}',
blockNumber: '',
Expand Down
2 changes: 1 addition & 1 deletion config/sepoliaAddressScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export let addresses: Addresses = {
subgraphNFT: '{{sepolia.SubgraphNFT.address}}',
l1GraphTokenGateway: '{{sepolia.L1GraphTokenGateway.address}}',
l2GraphTokenGateway: '',
ethereumDIDRegistry: '{{sepolia.IEthereumDIDRegistry.address}}',
ethereumDIDRegistry: '{{sepolia.EthereumDIDRegistry.address}}',
isL1: true,
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"test": "graph test -v 0.2.0"
},
"devDependencies": {
"@graphprotocol/contracts": "^5.3.0",
"@graphprotocol/contracts": "^5.3.3",
"@graphprotocol/graph-cli": "0.48.0",
"@graphprotocol/graph-ts": "0.29.3",
"@types/node": "^14.0.13",
Expand Down
52 changes: 38 additions & 14 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,7 @@ type SubgraphMetadataUpdatedEvent implements SubgraphEvent & Event @entity {

ipfsFileHash: String!

description: String!

displayName: String!

codeRepository: String!

website: String!

nftImage: String!

image: String!
metadata: SubgraphMetadata

tx_gasLimit: BigInt!

Expand All @@ -380,6 +370,29 @@ type SubgraphMetadataUpdatedEvent implements SubgraphEvent & Event @entity {
tx_cumulativeGasUsed: BigInt!
}

type SubgraphMetadata @entity(immutable:true) {
"Subgraph metadata ipfs hash"
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"
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."
categories: [String!]
}

type SubgraphVersionMetadataUpdatedEvent implements SubgraphEvent & SubgraphDeploymentEvent & Event
@entity {
"Generic ID only for uniqueness purposes."
Expand All @@ -402,9 +415,7 @@ type SubgraphVersionMetadataUpdatedEvent implements SubgraphEvent & SubgraphDepl

ipfsFileHash: String!

description: String!

label: String!
metadata: SubgraphVersionMetadata

tx_gasLimit: BigInt!

Expand All @@ -415,6 +426,19 @@ type SubgraphVersionMetadataUpdatedEvent implements SubgraphEvent & SubgraphDepl
tx_cumulativeGasUsed: BigInt!
}

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
}

type SubgraphDeprecatedEvent implements SubgraphEvent & Event @entity {
"Generic ID only for uniqueness purposes."
id: ID!
Expand Down
36 changes: 26 additions & 10 deletions src/mappings/gns.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt, BigDecimal, Bytes, json } from '@graphprotocol/graph-ts'
import { BigInt, BigDecimal, Bytes, json, DataSourceContext } from '@graphprotocol/graph-ts'
import {
SubgraphPublished,
SubgraphDeprecated,
Expand Down Expand Up @@ -43,7 +43,11 @@ import {
SubgraphVersionMetadataUpdatedEvent,
} from '../types/schema'

import { zeroBD } from './utils'
import {
SubgraphVersionMetadata as SubgraphVersionMetadataTemplate,
SubgraphMetadata as SubgraphMetadataTemplate
} from '../types/templates'

import {
createOrLoadSubgraphDeployment,
createOrLoadGraphAccount,
Expand All @@ -54,10 +58,7 @@ import {
joinID,
convertBigIntSubgraphIDToBase58,
getSubgraphID,
fetchSubgraphMetadata,
fetchSubgraphVersionMetadata,
getCounter,
BIGINT_ZERO,
BIGINT_ONE,
} from './helpers'

Expand Down Expand Up @@ -119,6 +120,7 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v

let hexHash = changetype<Bytes>(addQm(event.params.subgraphMetadata))
let base58Hash = hexHash.toBase58()
let metadataId = subgraph.id.concat('-').concat(base58Hash)

let eventEntity = new SubgraphMetadataUpdatedEvent(eventId)
eventEntity.timestamp = event.block.timestamp
Expand All @@ -132,7 +134,7 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v
eventEntity.subgraph = subgraph.id
eventEntity.accounts = accounts
eventEntity.ipfsFileHash = base58Hash
eventEntity = fetchSubgraphMetadata(eventEntity, base58Hash)
eventEntity.metadata = metadataId
eventEntity.save()

let counter = getCounter()
Expand All @@ -142,6 +144,10 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v
counter.graphAccountEventCount = counter.graphAccountEventCount.plus(BIGINT_ONE)
counter.eventCount = counter.eventCount.plus(BIGINT_ONE)
counter.save()

let context = new DataSourceContext()
context.setString('id', metadataId)
SubgraphMetadataTemplate.createWithContext(base58Hash, context)
}

/**
Expand Down Expand Up @@ -600,6 +606,7 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1)

let hexHash = changetype<Bytes>(addQm(event.params.subgraphMetadata))
let base58Hash = hexHash.toBase58()
let metadataId = subgraph.id.concat('-').concat(base58Hash)

let eventEntity = new SubgraphMetadataUpdatedEvent(eventId)
eventEntity.timestamp = event.block.timestamp
Expand All @@ -613,7 +620,7 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1)
eventEntity.subgraph = subgraph.id
eventEntity.accounts = accounts
eventEntity.ipfsFileHash = base58Hash
eventEntity = fetchSubgraphMetadata(eventEntity, base58Hash)
eventEntity.metadata = metadataId
eventEntity.save()

let counter = getCounter()
Expand All @@ -622,6 +629,10 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1)
counter.subgraphMetadataUpdatedEventCount =
counter.subgraphMetadataUpdatedEventCount.plus(BIGINT_ONE)
counter.save()

let context = new DataSourceContext()
context.setString('id', metadataId)
SubgraphMetadataTemplate.createWithContext(base58Hash, context)
}

// - event: SignalMinted(indexed uint256,indexed address,uint256,uint256,uint256)
Expand Down Expand Up @@ -791,13 +802,14 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
counter.subgraphVersionMetadataUpdatedEventCount =
counter.subgraphVersionMetadataUpdatedEventCount.plus(BIGINT_ONE)

versionID = joinID([subgraphID, subgraph.versionCount.toString()])

if (subgraph.initializing) {
subgraph.initializing = false
subgraph.save()

// attach
} else {
versionID = joinID([subgraphID, subgraph.versionCount.toString()])
subgraph.currentVersion = versionID
subgraph.versionCount = subgraph.versionCount.plus(BigInt.fromI32(1))
subgraph.save()
Expand Down Expand Up @@ -835,6 +847,7 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi

let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
let base58Hash = hexHash.toBase58()
let metadataId = versionID.concat('-').concat(base58Hash)

let otherEventEntity = new SubgraphVersionMetadataUpdatedEvent(eventId.concat('0'))
otherEventEntity.timestamp = event.block.timestamp
Expand All @@ -849,10 +862,13 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
otherEventEntity.deployment = deployment.id
otherEventEntity.accounts = accounts
otherEventEntity.ipfsFileHash = base58Hash
otherEventEntity = fetchSubgraphVersionMetadata(otherEventEntity, base58Hash)
otherEventEntity.metadata = metadataId
otherEventEntity.save()

counter.save()

let context = new DataSourceContext()
context.setString('id', metadataId)
SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context)
}

// - event: LegacySubgraphClaimed(indexed address,uint256)
Expand Down
Loading

0 comments on commit 0905cfb

Please sign in to comment.