Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added the improved import logic manually from the hh template #11

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions packages/subgraph/manifest/data/goerli.json

This file was deleted.

7 changes: 6 additions & 1 deletion packages/subgraph/manifest/data/localhost.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"address": "0x2B8C4DD137104d1E869105cd0106e7D9EF955BfE",
"startBlock": 7727664
}
]
],
"Plugin": {
"name": "TokenVotingPlugin",
"address": null,
"startBlock": 7727664
}
}
}
7 changes: 6 additions & 1 deletion packages/subgraph/manifest/data/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"address": "0xE978942c691e43f65c1B7c7F8f1dc8cDF061B13f",
"startBlock": 16721812
}
]
],
"Plugin": {
"name": "TokenVotingPlugin",
"address": null,
"startBlock": 16721812
}
}
}
7 changes: 6 additions & 1 deletion packages/subgraph/manifest/data/polygon.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"address": "0x879D9dfe3F36d7684BeC1a2bB4Aa8E8871A7245B",
"startBlock": 40817440
}
]
],
"Plugin": {
"name": "TokenVotingPlugin",
"address": null,
"startBlock": 40817440
}
}
}
7 changes: 6 additions & 1 deletion packages/subgraph/manifest/data/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"address": "0xC24188a73dc09aA7C721f96Ad8857B469C01dC9f",
"startBlock": 4415294
}
]
],
"Plugin": {
"name": "TokenVotingPlugin",
"address": null,
"startBlock": 4415294
}
}
}
32 changes: 19 additions & 13 deletions packages/subgraph/scripts/deploy-subgraph.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,34 +22,42 @@ 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
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
fi
44 changes: 28 additions & 16 deletions packages/subgraph/scripts/import-plugin-repo.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -42,8 +58,4 @@ function extractAndWriteAddressToTS(jsonPath: string): void {
);
}

const aragonDeploymentsInfoPath = path.join(
rootDir,
'production-network-deployments.json'
);
extractAndWriteAddressToTS(aragonDeploymentsInfoPath);
extractAndWriteAddressToTS();
Loading