From c6de852f79f25e4a7340bcdcfbcfda48f06808e5 Mon Sep 17 00:00:00 2001 From: Gabriel Fournier Date: Fri, 5 Jul 2024 15:50:46 +0200 Subject: [PATCH] create template tot automate network deployment --- README.md | 45 +++++++ config.json | 58 ++++++++ generate_subgraph.sh | 69 ++++++++++ subgraph.bellecour.template.yaml | 221 +++++++++++++++++++++++++++++++ 4 files changed, 393 insertions(+) create mode 100644 config.json create mode 100755 generate_subgraph.sh create mode 100644 subgraph.bellecour.template.yaml diff --git a/README.md b/README.md index e8aaae0..7861274 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,51 @@ debugging: _NB_: other blockchains setups are availables in [docker/README.md](./docker/README.md). +Sure, here's a summarized version for your README: + +--- + +## Generating Subgraph and Jenkins Configuration Files + +This project includes a bash script, `generate_subgraph.sh`, to automate the creation of subgraph YAML configuration files and Jenkinsfiles based on the network settings in `config.json`. + + +**Run the script with the network name**: +```bash +./generate_subgraph.sh +``` + +### Configuration + +Ensure `config.json` is populated with the required values. Example: + +```json +{ + "bellecour": { + "STARTBLOCK": 4543300, + "ERC1538_ADDRESS": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "IEXECE_INTERFACE_TOKEN_CORE_ADDRESS": "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "APP_REGISTRY_ADDRESS": "0xB1C52075b276f87b1834919167312221d50c9D16", + "DATATSET_REGISTRY_ADDRESS": "0x799DAa22654128d0C64d5b79eac9283008158730", + "WORKERPOOL_REGISTRY_ADDRESS": "0xC76A18c78B7e530A165c5683CB1aB134E21938B4" + } +} +``` + +### Files Generated + +- **subgraph..yaml**: Subgraph configuration with placeholders replaced. +- **Jenkinsfile.**: Jenkinsfile for deploying the subgraph. + +#### Example Command + +```bash +./generate_subgraph.sh bellecour +``` + +This command generates `subgraph.bellecour.yaml` and `Jenkinsfile.bellecour`. + + ## Resources - [thegraph docs](https://thegraph.com/docs/en/) diff --git a/config.json b/config.json new file mode 100644 index 0000000..00baa63 --- /dev/null +++ b/config.json @@ -0,0 +1,58 @@ +{ + "bellecour": { + "STARTBLOCK": 4543300, + "ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16", + "DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730", + "WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4" + }, + "c13": { + "STARTBLOCK": 4543300, + "ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16", + "DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730", + "WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4" + }, + "goerli": { + "STARTBLOCK": 2564000, + "ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16", + "DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730", + "WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4" + }, + "mainnet": { + "STARTBLOCK": 9917600, + "ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16", + "DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730", + "WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4" + }, + "rinkeby": { + "STARTBLOCK": 6355862, + "ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16", + "DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730", + "WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4" + }, + "viviani": { + "STARTBLOCK": 5556000, + "ERC1538_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f", + "APP_REGISTRY_ADDRESS" : "0xB1C52075b276f87b1834919167312221d50c9D16", + "DATATSET_REGISTRY_ADDRESS" : "0x799DAa22654128d0C64d5b79eac9283008158730", + "WORKERPOOL_REGISTRY_ADDRESS" : "0xC76A18c78B7e530A165c5683CB1aB134E21938B4" + }, + "test": { + "STARTBLOCK": 0, + "ERC1538_ADDRESS" : "0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca", + "IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" : "0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca", + "APP_REGISTRY_ADDRESS" : "0xbB66c75dc79D21E8A5b9EF5DE346021082469892", + "DATATSET_REGISTRY_ADDRESS" : "0xe325907A7E0E320A4dcBfAC0cBCda120e7788A0D", + "WORKERPOOL_REGISTRY_ADDRESS" : "0xDaecE9E92C2414D1F4AFcf6B79d76A2491dfd6A6" + } +} \ No newline at end of file diff --git a/generate_subgraph.sh b/generate_subgraph.sh new file mode 100755 index 0000000..0d08c00 --- /dev/null +++ b/generate_subgraph.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# Check if jq is installed +if ! command -v jq &> /dev/null; then + echo "jq is required but not installed. Please install jq to proceed." + exit 1 +fi + +# Function to replace placeholders in the template +generate_yaml() { + local network=$1 + local config_file="config.json" + local template_file="subgraph.bellecour.template.yaml" + local output_file="subgraph.${network}.yaml" + + # Read values from config.json + local start_block=$(jq -r ".${network}.STARTBLOCK" ${config_file}) + local erc1538_address=$(jq -r ".${network}.ERC1538_ADDRESS" ${config_file}) + local core_address=$(jq -r ".${network}.IEXECE_INTERFACE_TOKEN_CORE_ADDRESS" ${config_file}) + local app_registry_address=$(jq -r ".${network}.APP_REGISTRY_ADDRESS" ${config_file}) + local dataset_registry_address=$(jq -r ".${network}.DATATSET_REGISTRY_ADDRESS" ${config_file}) + local workerpool_registry_address=$(jq -r ".${network}.WORKERPOOL_REGISTRY_ADDRESS" ${config_file}) + + # Replace placeholders in the template and create the output file + sed -e "s/#NETWORK_NAME#/network: ${network}/g" \ + -e "s/#STARTBLOCK#/startBlock: ${start_block}/g" \ + -e "s|#ERC1538_ADDRESS#|address: \"${erc1538_address}\"|g" \ + -e "s|#IEXECE_INTERFACE_TOKEN_CORE_ADDRESS#|address: \"${core_address}\"|g" \ + -e "s|#APP_REGISTRY_ADDRESS#|address: \"${app_registry_address}\"|g" \ + -e "s|#DATATSET_REGISTRY_ADDRESS#|address: \"${dataset_registry_address}\"|g" \ + -e "s|#WORKERPOOL_REGISTRY_ADDRESS#|address: \"${workerpool_registry_address}\"|g" \ + ${template_file} > ${output_file} + + echo "Generated ${output_file}" +} + + +# Function to create the Jenkinsfile +generate_jenkinsfile() { + local network=$1 + local jenkinsfile="Jenkinsfile_Subgraph_${network}" + + cat < ${jenkinsfile} +//Readme @ http://gitlab.iex.ec:30000/iexec/jenkins-library + +@Library('global-jenkins-library@2.7.7') _ +deploySubGraph( + targetRemoteHost : 'azubgrpvx-thegraph-${network}.public.az2.internal', + subgraphFolder: './', + subgraphFilename: 'subgraph.${network}.yaml', + subgraphVersionLabel: 'v1.0.0-rc.1', + subgraphLabel: '${network}/poco-v5' +) +EOL + + echo "Generated ${jenkinsfile}" +} + +# Check if the user provided a network name +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +network_name=$1 + +# Generate the YAML file for the specified network +generate_yaml ${network_name} +generate_jenkinsfile ${network_name} diff --git a/subgraph.bellecour.template.yaml b/subgraph.bellecour.template.yaml new file mode 100644 index 0000000..e3e1bab --- /dev/null +++ b/subgraph.bellecour.template.yaml @@ -0,0 +1,221 @@ +# Copyright 2024 IEXEC BLOCKCHAIN TECH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +specVersion: 0.0.4 +description: iExecPoCoV5 +repository: https://github.com/iExecBlockchainComputing/PoCo-subgraph +schema: + file: ./schema.graphql +dataSources: + - name: ERC1538 + kind: ethereum/contract + #NETWORK_NAME# + source: + #ERC1538_ADDRESS# + abi: ERC1538 + #STARTBLOCK# + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - ERC1538Module + - ERC1538Function + - ERC1538FunctionUpdateEvent + - ERC1538CommitMessageEvent + abis: + - name: ERC1538 + file: node_modules/@iexec/solidity/build/contracts/IERC1538.json + eventHandlers: + - event: CommitMessage(string) + handler: handleCommitMessage + - event: FunctionUpdate(indexed bytes4,indexed address,indexed address,string) + handler: handleFunctionUpdate + file: ./src/ERC1538/ERC1538.ts + + - name: Core + kind: ethereum/contract + #NETWORK_NAME# + source: + #IEXECE_INTERFACE_TOKEN_CORE_ADDRESS# + abi: IexecInterfaceToken + #STARTBLOCK# + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Category + - Account + - AppOrder + - DatasetOrder + - WorkerpoolOrder + - RequesterOrder + - Deal + - SchedulerNotice + - Task + - Contribution + - TaskInitialize + - TaskContribute + - TaskConsensus + - TaskReveal + - TaskReopen + - TaskFinalize + - TaskClaimed + - AccurateContribution + - FaultyContribution + - Transfer + - Reward + - Seize + - Lock + - Unlock + abis: + - name: IexecInterfaceToken + file: node_modules/@iexec/poco/build/contracts/IexecInterfaceNative.json + eventHandlers: + - event: CreateCategory(uint256,string,string,uint256) + handler: handleCreateCategory + - event: OrdersMatched(bytes32,bytes32,bytes32,bytes32,bytes32,uint256) + handler: handleOrdersMatched + - event: SchedulerNotice(indexed address,bytes32) + handler: handleSchedulerNotice + - event: TaskInitialize(indexed bytes32,indexed address) + handler: handleTaskInitialize + - event: TaskContribute(indexed bytes32,indexed address,bytes32) + handler: handleTaskContribute + - event: TaskConsensus(indexed bytes32,bytes32) + handler: handleTaskConsensus + - event: TaskReveal(indexed bytes32,indexed address,bytes32) + handler: handleTaskReveal + - event: TaskReopen(indexed bytes32) + handler: handleTaskReopen + - event: TaskFinalize(indexed bytes32,bytes) + handler: handleTaskFinalize + - event: TaskClaimed(indexed bytes32) + handler: handleTaskClaimed + - event: AccurateContribution(indexed address,indexed bytes32) + handler: handleAccurateContribution + - event: FaultyContribution(indexed address,indexed bytes32) + handler: handleFaultyContribution + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransfer + - event: Reward(address,uint256,bytes32) + handler: handleReward + - event: Seize(address,uint256,bytes32) + handler: handleSeize + - event: Lock(address,uint256) + handler: handleLock + - event: Unlock(address,uint256) + handler: handleUnlock + callHandlers: + - function: matchOrders((address,uint256,uint256,bytes32,address,address,address,bytes32,bytes),(address,uint256,uint256,bytes32,address,address,address,bytes32,bytes),(address,uint256,uint256,bytes32,uint256,uint256,address,address,address,bytes32,bytes),(address,uint256,address,uint256,address,uint256,address,uint256,bytes32,uint256,uint256,address,address,string,bytes32,bytes)) + handler: handleMatchOrders + file: ./src/Modules/index.ts + + # =============================== App registry ================================ + - name: AppRegistry + kind: ethereum/contract + #NETWORK_NAME# + source: + #APP_REGISTRY_ADDRESS# + abi: AppRegistry + #STARTBLOCK# + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - App + - AppTransfer + abis: + - name: App + file: node_modules/@iexec/poco/build/contracts/App.json + - name: AppRegistry + file: node_modules/@iexec/poco/build/contracts/AppRegistry.json + eventHandlers: + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransferApp + file: ./src/Registries/index.ts + + # ============================= Dataset registry ============================== + - name: DatasetRegistry + kind: ethereum/contract + #NETWORK_NAME# + source: + #DATATSET_REGISTRY_ADDRESS# + abi: DatasetRegistry + #STARTBLOCK# + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Dataset + - DatasetTransfer + abis: + - name: Dataset + file: node_modules/@iexec/poco/build/contracts/Dataset.json + - name: DatasetRegistry + file: node_modules/@iexec/poco/build/contracts/DatasetRegistry.json + eventHandlers: + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransferDataset + file: ./src/Registries/index.ts + + # ============================ Workerpool registry ============================ + - name: WorkerpoolRegistry + kind: ethereum/contract + #NETWORK_NAME# + source: + #WORKERPOOL_REGISTRY_ADDRESS# + abi: WorkerpoolRegistry + #STARTBLOCK# + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Workerpool + - WorkerpoolTransfer + abis: + - name: Workerpool + file: node_modules/@iexec/poco/build/contracts/Workerpool.json + - name: WorkerpoolRegistry + file: node_modules/@iexec/poco/build/contracts/WorkerpoolRegistry.json + eventHandlers: + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransferWorkerpool + file: ./src/Registries/index.ts + +# ============================ Workerpool template ============================ +templates: + - name: Workerpool + kind: ethereum/contract + #NETWORK_NAME# + source: + abi: Workerpool + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Workerpool + - PolicyChange + abis: + - name: Workerpool + file: node_modules/@iexec/poco/build/contracts/Workerpool.json + eventHandlers: + - event: PolicyUpdate(uint256,uint256,uint256,uint256) + handler: handlePolicyUpdate + file: ./src/Registries/index.ts