From aea274a1b453cfc777e3d0354775f0008edccaf7 Mon Sep 17 00:00:00 2001 From: jordaniza Date: Thu, 14 Mar 2024 15:35:51 +0400 Subject: [PATCH] feat: added the improved import logic manually from the hh template --- packages/subgraph/manifest/data/goerli.json | 13 ------ .../subgraph/manifest/data/localhost.json | 7 ++- packages/subgraph/manifest/data/mainnet.json | 7 ++- packages/subgraph/manifest/data/polygon.json | 7 ++- packages/subgraph/manifest/data/sepolia.json | 7 ++- packages/subgraph/scripts/deploy-subgraph.sh | 32 ++++++++------ .../subgraph/scripts/import-plugin-repo.ts | 44 ++++++++++++------- 7 files changed, 71 insertions(+), 46 deletions(-) delete mode 100644 packages/subgraph/manifest/data/goerli.json diff --git a/packages/subgraph/manifest/data/goerli.json b/packages/subgraph/manifest/data/goerli.json deleted file mode 100644 index 5f82e606..00000000 --- a/packages/subgraph/manifest/data/goerli.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "info": "# Do not edit subgraph.yaml,this is a generated file. \n# Instead, edit subgraph.placeholder.yaml and run: yarn manifest", - "network": "goerli", - "dataSources": { - "PluginSetupProcessors": [ - { - "name": "PluginSetupProcessor", - "address": "0xE8B5d8D66a02CD1b9Bd32a4064D7ABa45F51305e", - "startBlock": 8548226 - } - ] - } -} diff --git a/packages/subgraph/manifest/data/localhost.json b/packages/subgraph/manifest/data/localhost.json index fc78a36a..dd021130 100644 --- a/packages/subgraph/manifest/data/localhost.json +++ b/packages/subgraph/manifest/data/localhost.json @@ -8,6 +8,11 @@ "address": "0x2B8C4DD137104d1E869105cd0106e7D9EF955BfE", "startBlock": 7727664 } - ] + ], + "Plugin": { + "name": "TokenVotingPlugin", + "address": null, + "startBlock": 7727664 + } } } diff --git a/packages/subgraph/manifest/data/mainnet.json b/packages/subgraph/manifest/data/mainnet.json index b7969f87..af3e3021 100644 --- a/packages/subgraph/manifest/data/mainnet.json +++ b/packages/subgraph/manifest/data/mainnet.json @@ -8,6 +8,11 @@ "address": "0xE978942c691e43f65c1B7c7F8f1dc8cDF061B13f", "startBlock": 16721812 } - ] + ], + "Plugin": { + "name": "TokenVotingPlugin", + "address": null, + "startBlock": 16721812 + } } } diff --git a/packages/subgraph/manifest/data/polygon.json b/packages/subgraph/manifest/data/polygon.json index 7675c9ba..c2180c20 100644 --- a/packages/subgraph/manifest/data/polygon.json +++ b/packages/subgraph/manifest/data/polygon.json @@ -8,6 +8,11 @@ "address": "0x879D9dfe3F36d7684BeC1a2bB4Aa8E8871A7245B", "startBlock": 40817440 } - ] + ], + "Plugin": { + "name": "TokenVotingPlugin", + "address": null, + "startBlock": 40817440 + } } } diff --git a/packages/subgraph/manifest/data/sepolia.json b/packages/subgraph/manifest/data/sepolia.json index 18a9af1e..9d43a242 100644 --- a/packages/subgraph/manifest/data/sepolia.json +++ b/packages/subgraph/manifest/data/sepolia.json @@ -8,6 +8,11 @@ "address": "0xC24188a73dc09aA7C721f96Ad8857B469C01dC9f", "startBlock": 4415294 } - ] + ], + "Plugin": { + "name": "TokenVotingPlugin", + "address": null, + "startBlock": 4415294 + } } } diff --git a/packages/subgraph/scripts/deploy-subgraph.sh b/packages/subgraph/scripts/deploy-subgraph.sh index fd15a08c..a89c2005 100755 --- a/packages/subgraph/scripts/deploy-subgraph.sh +++ b/packages/subgraph/scripts/deploy-subgraph.sh @@ -1,12 +1,10 @@ #!/usr/bin/env bash -if [ -f ../../.env ] -then - export $(cat ../../.env | sed 's/#.*//g' | xargs) +if [ -f ../../.env ]; then + export $(cat ../../.env | sed 's/#.*//g' | xargs) fi -if [ -z "$SUBGRAPH_NETWORK_NAME" ] || [ -z "$SUBGRAPH_NAME" ] || [ -z "$GRAPH_KEY" ] || [ -z "$SUBGRAPH_VERSION" ] -then +if [ -z "$SUBGRAPH_NETWORK_NAME" ] || [ -z "$SUBGRAPH_NAME" ] || [ -z "$GRAPH_KEY" ] || [ -z "$SUBGRAPH_VERSION" ]; then echo "env variables are not set properly, exiting..." exit -1 fi @@ -24,23 +22,31 @@ echo '' echo '> Building subgraph' ./scripts/build-subgraph.sh -if [ "$SUBGRAPH_NETWORK_NAME" == 'localhost' ] -then - SUBGRAPH_NETWORK_NAME='goerli' +if [ "$SUBGRAPH_NETWORK_NAME" == 'localhost' ]; then + SUBGRAPH_NETWORK_NAME='goerli' fi # Prepare subgraph name FULLNAME=$SUBGRAPH_NAME-$SUBGRAPH_NETWORK_NAME if [ "$STAGING" ]; then - FULLNAME=$FULLNAME-staging + FULLNAME=$FULLNAME-staging fi echo '' echo '> Deploying subgraph: '$FULLNAME echo '> Subgraph version: '$SUBGRAPH_VERSION +# check if the repo address is null or zero address +FILE=manifest/data/$SUBGRAPH_NETWORK_NAME'.json' + +address=$(jq -r '.dataSources.Plugin.address' "$FILE") + +if [ "$address" = "null" ] || [ "$address" = "0x0000000000000000000000000000000000000000" ]; then + echo "Repo address is not set properly, exiting..." + exit -1 +fi + # Deploy subgraph -if [ "$LOCAL" ] -then +if [ "$LOCAL" ]; then graph deploy $FULLNAME \ --ipfs http://localhost:5001 \ --node http://localhost:8020 @@ -48,10 +54,10 @@ else graph deploy $FULLNAME \ --version-label $SUBGRAPH_VERSION \ --node https://subgraphs.alchemy.com/api/subgraphs/deploy \ - --deploy-key $GRAPH_KEY > deploy-output.txt + --deploy-key $GRAPH_KEY >deploy-output.txt SUBGRAPH_ID=$(grep "Build completed:" deploy-output.txt | grep -oE "Qm[a-zA-Z0-9]{44}") rm deploy-output.txt echo "The Graph deployment complete: ${SUBGRAPH_ID}" -fi \ No newline at end of file +fi diff --git a/packages/subgraph/scripts/import-plugin-repo.ts b/packages/subgraph/scripts/import-plugin-repo.ts index 8f9d655c..59bad356 100644 --- a/packages/subgraph/scripts/import-plugin-repo.ts +++ b/packages/subgraph/scripts/import-plugin-repo.ts @@ -1,29 +1,45 @@ +import {SupportedNetworks} from '@aragon/osx-commons-configs'; import dotenv from 'dotenv'; import fs from 'fs'; import path from 'path'; +const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; + // Specify the path to the .env file at the root const rootDir = path.join(__dirname, '../../../'); // Adjust the path as necessary dotenv.config({path: path.join(rootDir, '.env')}); +// path to the networks manifests +const manifestsPath = path.join(__dirname, '../manifest/data'); -// Extract Repo address from the production-network-deployments.json -function extractAndWriteAddressToTS(jsonPath: string): void { - // Read the production-network-deployments.json file - const aragonDeploymentsInfo = JSON.parse(fs.readFileSync(jsonPath, 'utf8')); - +function extractAndWriteAddressToTS(): void { // Get the network from environment variables const network = process.env.SUBGRAPH_NETWORK_NAME; - // Check if the network is defined in aragonDeploymentsInfo - if (!network || !aragonDeploymentsInfo[network]) { - throw new Error( - `Network '${network}' not found in production-network-deployments.json` + // Check if the network is provided and supported + if ( + !network || + !Object.values(SupportedNetworks).includes(network as SupportedNetworks) + ) { + throw new Error(`Network '${network}' invalid or not Supported.`); + } + + // get the plugin address from the network manifest + const networkManifestPath = path.join(manifestsPath, `${network}.json`); + let networkRepoAddress = JSON.parse( + fs.readFileSync(networkManifestPath, 'utf8') + ).dataSources.Plugin.address; + + // check if address is null and throw warning and continue with zero address + if (!networkRepoAddress) { + console.warn( + '\x1b[33m%s\x1b[0m', + `WARNING: Plugin address for network '${network}' is null. Using zero address.` ); + networkRepoAddress = ZERO_ADDRESS; } - // Start the Map creation code with the specific network address const tsContent: string[] = [ - `export const PLUGIN_REPO_ADDRESS = '${aragonDeploymentsInfo[network].address}';`, + `export const PLUGIN_REPO_ADDRESS = '${networkRepoAddress}';`, ]; const outputDir = path.join(__dirname, '../imported'); @@ -42,8 +58,4 @@ function extractAndWriteAddressToTS(jsonPath: string): void { ); } -const aragonDeploymentsInfoPath = path.join( - rootDir, - 'production-network-deployments.json' -); -extractAndWriteAddressToTS(aragonDeploymentsInfoPath); +extractAndWriteAddressToTS();