From 27750ccddac98314bcca82471093a271415c4a91 Mon Sep 17 00:00:00 2001 From: Pablo Date: Wed, 15 Sep 2021 17:20:06 -0300 Subject: [PATCH] generate different subgraph yml file based on network selection --- package.json | 2 + subgraph/.gitignore | 2 +- subgraph/config/hardhat.json | 5 + subgraph/config/xdai.json | 5 + subgraph/package.json | 5 +- subgraph/subgraph.template.yaml | 156 ++++++++++++++++++++++++++++++++ subgraph/subgraph.yaml | 6 +- yarn.lock | 5 + 8 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 subgraph/config/hardhat.json create mode 100644 subgraph/config/xdai.json create mode 100644 subgraph/subgraph.template.yaml diff --git a/package.json b/package.json index 8442eb0e9..8ca74ba63 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "start:node": "yarn workspace @clrfund/contracts run node", "start:web": "yarn workspace @clrfund/vue-app run serve", "start:gun": "yarn workspace @clrfund/vue-app run gun", + "start:subgraph": "yarn workspace @clrfund/subgraph run prepare:hardhat && yarn build:subgraph && yarn deploy:local-subgraph", "codegen": "graphql-codegen --config codegen.yml", "test": "yarn workspace @clrfund/contracts run test && yarn workspace @clrfund/vue-app run test", "test:contracts": "yarn workspace @clrfund/contracts run test", @@ -37,6 +38,7 @@ "deploy:local": "yarn deploy:local-registry && yarn deploy:local-round", "deploy:local-registry": "yarn workspace @clrfund/contracts run deploy:local", "deploy:local-round": "yarn workspace @clrfund/contracts run deployTestRound:local", + "deploy:local-subgraph": "yarn workspace @clrfund/subgraph run create-local && yarn workspace @clrfund/subgraph run deploy-local", "upgrade:local": "yarn workspace @clrfund/contracts run upgrade:local", "lint": "yarn workspaces run lint", "lint:contracts": "yarn workspace @clrfund/contracts run lint", diff --git a/subgraph/.gitignore b/subgraph/.gitignore index c56e0e8b2..c9eccc402 100644 --- a/subgraph/.gitignore +++ b/subgraph/.gitignore @@ -1,4 +1,4 @@ /node_modules /build /packages/*/node_modules -.DS_Store +.DS_Store \ No newline at end of file diff --git a/subgraph/config/hardhat.json b/subgraph/config/hardhat.json new file mode 100644 index 000000000..0bf8c7bf3 --- /dev/null +++ b/subgraph/config/hardhat.json @@ -0,0 +1,5 @@ +{ + "network": "hardhat", + "address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", + "startBlock": 0 +} diff --git a/subgraph/config/xdai.json b/subgraph/config/xdai.json new file mode 100644 index 000000000..6d59183d3 --- /dev/null +++ b/subgraph/config/xdai.json @@ -0,0 +1,5 @@ +{ + "network": "xdai", + "address": "0x549F91A93c94358C5f5380D7ABF23E1340CfF2db", + "startBlock": 15217676 +} diff --git a/subgraph/package.json b/subgraph/package.json index fce212109..70c331d94 100644 --- a/subgraph/package.json +++ b/subgraph/package.json @@ -14,6 +14,8 @@ "author": "daodesigner", "private": true, "scripts": { + "prepare:hardhat": "mustache config/hardhat.json subgraph.template.yaml > subgraph.yaml", + "prepare:xdai": "mustache config/xdai.json subgraph.template.yaml > subgraph.yaml", "codegen": "graph codegen", "lint:js": "eslint 'src/*.ts'", "lint": "yarn lint:js", @@ -32,6 +34,7 @@ "@typescript-eslint/parser": "^2.34.0", "chai": "^4.2.0", "eslint": "^6.8.0", - "eslint-config-prettier": "^8.3.0" + "eslint-config-prettier": "^8.3.0", + "mustache": "^4.2.0" } } diff --git a/subgraph/subgraph.template.yaml b/subgraph/subgraph.template.yaml new file mode 100644 index 000000000..9d8cd82b8 --- /dev/null +++ b/subgraph/subgraph.template.yaml @@ -0,0 +1,156 @@ +specVersion: 0.0.2 +description: clr.fund sandbox +repository: https://github.com/daodesigner/clrfund-deployer +schema: + file: ./schema.graphql +dataSources: + - kind: ethereum/contract + name: FundingRoundFactory + network: {{network}} + source: + address: '{{address}}' + abi: FundingRoundFactory + startBlock: {{startBlock}} + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + entities: + - FundingRoundFactory + - RecipientRegistry + - ContributorRegistry + - FundingRound + abis: + - name: FundingRoundFactory + file: ./abis/FundingRoundFactory.json + - name: FundingRound + file: ./abis/FundingRound.json + - name: MACIFactory + file: ./abis/MACIFactory.json + - name: OptimisticRecipientRegistry + file: ./abis/OptimisticRecipientRegistry.json + - name: BrightIdUserRegistry + file: ./abis/BrightIdUserRegistry.json + eventHandlers: + - event: CoordinatorChanged(address) + handler: handleCoordinatorChanged + - event: FundingSourceAdded(address) + handler: handleFundingSourceAdded + - event: FundingSourceRemoved(address) + handler: handleFundingSourceRemoved + - event: OwnershipTransferred(indexed address,indexed address) + handler: handleOwnershipTransferred + - event: RoundFinalized(address) + handler: handleRoundFinalized + - event: RoundStarted(address) + handler: handleRoundStarted + - event: TokenChanged(address) + handler: handleTokenChanged + file: ./src/FundingRoundFactoryMapping.ts + - kind: ethereum/contract + name: OptimisticRecipientRegistry + network: {{network}} + source: + abi: OptimisticRecipientRegistry + startBlock: 0 + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + entities: + - RecipientRegistry + - Recipient + abis: + - name: OptimisticRecipientRegistry + file: ./abis/OptimisticRecipientRegistry.json + eventHandlers: + - event: OwnershipTransferred(indexed address,indexed address) + handler: handleOwnershipTransferred + - event: RequestResolved(indexed bytes32,indexed uint8,indexed bool,uint256,uint256) + handler: handleRequestResolved + - event: RequestSubmitted(indexed bytes32,indexed uint8,address,string,uint256) + handler: handleRequestSubmitted + file: ./src/OptimisticRecipientRegistryMapping.ts +templates: + - name: FundingRound + kind: ethereum/contract + network: {{network}} + source: + abi: FundingRound + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + entities: + - FundingRound + - Contribution + - Donation + - Recipient + - Contributor + abis: + - name: FundingRound + file: ./abis/FundingRound.json + - name: OptimisticRecipientRegistry + file: ./abis/OptimisticRecipientRegistry.json + - name: BrightIdUserRegistry + file: ./abis/BrightIdUserRegistry.json + eventHandlers: + - event: Contribution(indexed address,uint256) + handler: handleContribution + - event: ContributionWithdrawn(indexed address) + handler: handleContributionWithdrawn + - event: FundsClaimed(indexed uint256,indexed address,uint256) + handler: handleFundsClaimed + - event: OwnershipTransferred(indexed address,indexed address) + handler: handleOwnershipTransferred + - event: TallyPublished(string) + handler: handleTallyPublished + - event: Voted(indexed address) + handler: handleVoted + file: ./src/FundingRoundMapping.ts + - name: OptimisticRecipientRegistry + kind: ethereum/contract + network: {{network}} + source: + abi: OptimisticRecipientRegistry + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + entities: + - RecipientRegistry + - Recipient + abis: + - name: OptimisticRecipientRegistry + file: ./abis/OptimisticRecipientRegistry.json + eventHandlers: + - event: OwnershipTransferred(indexed address,indexed address) + handler: handleOwnershipTransferred + - event: RequestResolved(indexed bytes32,indexed uint8,indexed bool,uint256,uint256) + handler: handleRequestResolved + - event: RequestSubmitted(indexed bytes32,indexed uint8,address,string,uint256) + handler: handleRequestSubmitted + file: ./src/OptimisticRecipientRegistryMapping.ts + - name: BrightIdUserRegistry + kind: ethereum/contract + network: {{network}} + source: + abi: BrightIdUserRegistry + mapping: + kind: ethereum/events + apiVersion: 0.0.4 + language: wasm/assemblyscript + entities: + - ContributorRegistry + - Contributor + abis: + - name: BrightIdUserRegistry + file: ./abis/BrightIdUserRegistry.json + eventHandlers: + - event: OwnershipTransferred(indexed address,indexed address) + handler: handleOwnershipTransferred + - event: SetBrightIdSettings(bytes32,address) + handler: handleSetBrightIdSettings + - event: Sponsor(indexed address) + handler: handleSponsor + file: ./src/BrightIdUserRegistryMapping.ts diff --git a/subgraph/subgraph.yaml b/subgraph/subgraph.yaml index 0b9bf5a2d..6e938b5dd 100644 --- a/subgraph/subgraph.yaml +++ b/subgraph/subgraph.yaml @@ -8,7 +8,7 @@ dataSources: name: FundingRoundFactory network: xdai source: - address: "0x549F91A93c94358C5f5380D7ABF23E1340CfF2db" + address: '0x549F91A93c94358C5f5380D7ABF23E1340CfF2db' abi: FundingRoundFactory startBlock: 15217676 mapping: @@ -52,7 +52,7 @@ dataSources: network: xdai source: abi: OptimisticRecipientRegistry - startBlock: 16105387 + startBlock: 0 mapping: kind: ethereum/events apiVersion: 0.0.4 @@ -105,6 +105,8 @@ templates: handler: handleOwnershipTransferred - event: TallyPublished(string) handler: handleTallyPublished + - event: Voted(indexed address) + handler: handleVoted file: ./src/FundingRoundMapping.ts - name: OptimisticRecipientRegistry kind: ethereum/contract diff --git a/yarn.lock b/yarn.lock index 581cb3fa5..dbc8896c5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14578,6 +14578,11 @@ murmurhash3js@^3.0.1: resolved "https://registry.yarnpkg.com/murmurhash3js/-/murmurhash3js-3.0.1.tgz#3e983e5b47c2a06f43a713174e7e435ca044b998" integrity sha1-Ppg+W0fCoG9DpxMXTn5DXKBEuZg= +mustache@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/mustache/-/mustache-4.2.0.tgz#e5892324d60a12ec9c2a73359edca52972bf6f64" + integrity sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ== + mute-stream@0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"