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

Support running local graph instance for local-ovm environment #107

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
network=$1
subgraph=$2
networks='mainnet optimism kovan optimism-kovan'
networks='mainnet optimism kovan optimism-kovan optimism-local'

GRAPH=${GRAPH:-graph}

Expand Down
4 changes: 2 additions & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
network=$1
subgraph=$2
token=$THEGRAPH_SNX_ACCESS_TOKEN
networks='mainnet optimism kovan optimism-kovan'
networks='mainnet optimism kovan optimism-kovan optimism-local'

GRAPH=${GRAPH:-graph}

Expand All @@ -12,5 +12,5 @@ if [ "all" == $network ]; then
SNX_NETWORK=$i $GRAPH deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ --access-token $THEGRAPH_SNX_ACCESS_TOKEN synthetixio-team/$i-$subgraph subgraphs/$subgraph.js
done
else
SNX_NETWORK=$network $GRAPH deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ --access-token $token synthetixio-team/$network-$subgraph subgraphs/$subgraph.js
SNX_NETWORK=$network npx $GRAPH deploy --node $GRAPH_NODE_URL --ipfs $IPFS_NODE_URL --access-token $token synthetixio-team/$network-$subgraph subgraphs/$subgraph.js
fi
17 changes: 10 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"**/*": "prettier --write --ignore-unknown"
},
"dependencies": {
"@graphprotocol/graph-cli": "git://github.com/graphprotocol/graph-cli.git#14fb300393a72645a879f9c0af78b2a67c0e448a",
"@graphprotocol/graph-cli": "0.20.1",
"@graphprotocol/graph-ts": "0.18.1",
"chalk": "2.4.2",
"commander": "2.20.0",
Expand Down
48 changes: 44 additions & 4 deletions subgraphs/utils/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@ function getCurrentSubgraph() {
return process.env['SUBGRAPH'];
}

function mockVersions(network = undefined) {
if (network !== 'local-ovm') throw new Error('versions.json mock unimplemented for ' + network);

// versions.json doesn't exist for the local environments, as it
// doesn't make sense. Here we mock it.
const versionName = 'latest';
const deployment = require(`synthetix/publish/deployed/${network}/deployment.json`);

const contracts = Object.entries(deployment.targets)
.map(([contractName, target]) => {
const { address } = target;
return {
[contractName]: {
address,
status: 'current',
keccak256: '',
},
};
})
.reduce((prev, curr) => Object.assign(prev, curr), {});

return {
[versionName]: {
tag: '',
fulltag: '',
release: '',
network: network,
date: new Date().toISOString(),
commit: '',
contracts,
},
};
}

function getReleaseInfo(file, network = undefined) {
const net = network || getCurrentNetwork() || 'mainnet';

Expand All @@ -20,18 +54,24 @@ function getReleaseInfo(file, network = undefined) {
return require('synthetix/publish/deployed/mainnet-ovm/' + file);
} else if (net === 'optimism-kovan') {
return require('synthetix/publish/deployed/kovan-ovm/' + file);
} else if (net === 'optimism-local') {
if (file === 'versions') {
return mockVersions('local-ovm');
} else {
return require('synthetix/publish/deployed/local-ovm/' + file);
}
}

return info;
}

function estimateBlock(date) {
const blockInfo = values(getReleaseInfo('versions'))
.filter(v => v.block && v.date)
.map(v => [v.block, v.date]);
.filter((v) => v.block && v.date)
.map((v) => [v.block, v.date]);

// find the release immediately after the specified time
const idx = sortedIndexBy(blockInfo, [0, date], v => v[1]);
const idx = sortedIndexBy(blockInfo, [0, date], (v) => v[1]);

const numDate = new Date(date).getTime();

Expand Down Expand Up @@ -124,7 +164,7 @@ function getContractDeployments(contractName, startBlock = 0, endBlock = Number.
return addressInfo;
}

const NETWORKS = ['mainnet', 'kovan', 'optimism-kovan', 'optimism'];
const NETWORKS = ['mainnet', 'kovan', 'optimism-kovan', 'optimism', 'optimism-local'];

module.exports = {
getCurrentNetwork,
Expand Down