Skip to content

Commit f3b501b

Browse files
authored
Feature/fix scripts (#331)
* fix scripts
1 parent 11b1408 commit f3b501b

11 files changed

+46
-1135
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
6565
- name: create and deploy subgraph
6666
run: |
67-
npm run quickstart:development
67+
npm run quickstart:barge
6868
sleep 20
6969
env:
7070
ADDRESS_FILE: /home/runner/.ocean/ocean-contracts/artifacts/address.json

README.md

+28-47
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
- [🏄 Get Started](#-get-started)
2020
- [⛵ Example Queries](#-example-queries)
21-
- [🏊 Development](#-development)
2221
- [🏊 Development on barge](#-development-on-barge)
22+
- [🏊 Deploying graphs for live networks](#-Deploying-graphs-for-live-networks)
2323
- [🔍 Testing](#-testing)
2424
- [✨ Code Style](#-code-style)
2525
- [🛳 Releases](#️-releases)
@@ -30,11 +30,10 @@
3030

3131
This subgraph is deployed under `/subgraphs/name/oceanprotocol/ocean-subgraph/` namespace for all networks the Ocean Protocol contracts are deployed to:
3232

33-
- [subgraph.mainnet.oceanprotocol.com](https://subgraph.mainnet.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql)
34-
- [subgraph.ropsten.oceanprotocol.com](https://subgraph.ropsten.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql)
35-
- [subgraph.rinkeby.oceanprotocol.com](https://subgraph.rinkeby.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql)
36-
- [subgraph.polygon.oceanprotocol.com](https://subgraph.polygon.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql)
37-
- [subgraph.bsc.oceanprotocol.com](https://subgraph.bsc.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql)
33+
- [subgraphv4.ropsten.oceanprotocol.com](https://subgraphv4.ropsten.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql)
34+
- [subgraphv4.rinkeby.oceanprotocol.com](https://subgraphv4.rinkeby.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql)
35+
- [subgraphv4.mumbai.oceanprotocol.com](https://subgraphv4.mumbai.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql)
36+
- [subgraphv4.moonbase.oceanprotocol.com](https://subgraphv4.moonbase.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql)
3837

3938
## ⛵ Example Queries
4039

@@ -85,35 +84,6 @@ This subgraph is deployed under `/subgraphs/name/oceanprotocol/ocean-subgraph/`
8584

8685
> Note: all ETH addresses like `$userAddress` in above example need to be passed in lowercase.
8786
88-
## 🏊 Development
89-
90-
First, clone the repo and install dependencies:
91-
92-
```bash
93-
git clone https://github.com/oceanprotocol/ocean-subgraph/
94-
cd ocean-subgraph
95-
npm i
96-
```
97-
98-
Developing and testing any change requires them to be deployed against a locally running graph-node and some other components running in Docker. Make sure you have Docker and Docker Compose installed on your machine, then prepare the Docker setup:
99-
100-
```bash
101-
cd docker
102-
./setup.sh
103-
```
104-
105-
Then add your Infura key as environment variable with a `.env` file, and start everything up with Docker Compose:
106-
107-
```bash
108-
# create .env and modify
109-
cp .env.example .env
110-
111-
docker-compose --env-file .env up
112-
```
113-
114-
The default network for development is set to Rinkeby. If you want to switch to another network you have to modify the `docker/docker-compose.yml` file within `environment.ethereum`.
115-
116-
You now have a local graph-node running and can start deploying your changes to it. To do so, follow the [Deployment instructions](#️-deployment).
11787

11888

11989
## 🏊 Development on Barge
@@ -137,37 +107,48 @@ cd ocean-subgraph
137107
npm i
138108
```
139109

140-
3. If you use barge, then let the components know where to pickup the smart contract addresses. For production networks, skip this step
110+
3. Let the components know where to pickup the smart contract addresses.
141111
```
142112
export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json"
143113
```
144114

145115
4. Generate the subgraphs
146116
```bash
147-
node ./scripts/generatenetworkssubgraphs.js
117+
node ./scripts/generatenetworkssubgraphs.js barge
148118
npm run codegen
149119
```
150120

151-
To generate subgraph for just one network, add the network name as parameter
152-
```bash
153-
node ./scripts/generatenetworkssubgraphs.js rinkeby
154-
```
155-
156121
5. To deploy a subgraph use:
157122

158-
npm run create:local-[network]
159-
npm run deploy:local-[network]
123+
npm run create:local-barge
124+
npm run deploy:local-barge
160125

161126
```bash
162-
npm run create:local-development
163-
npm run deploy:local-development
127+
npm run create:local
128+
npm run deploy:local
164129
```
165130

166-
- Alternatively, if you want to get the sub-graph quickly running on barge, you can run `npm run quickstart:barge` which combines steps 3-5 above.
131+
- Alternatively, if you want to get the sub-graph quickly running on barge, you can run `npm run quickstart:barge` which combines steps 4-5 above.
167132

168133
You now have a local graph-node running on http://127.0.0.1:9000/subgraphs/name/oceanprotocol/ocean-subgraph/graphql
169134

170135

136+
## 🏊 Deploying graphs for live networks
137+
138+
139+
1. Clone the repo and install dependencies:
140+
141+
```bash
142+
git clone https://github.com/oceanprotocol/ocean-subgraph/
143+
cd ocean-subgraph
144+
npm i
145+
```
146+
147+
2. Generate & deploy on rinkeby
148+
```bash
149+
npm run quickstart:rinkeby
150+
```
151+
171152

172153
## 🔍 Testing
173154

docker-entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ then
1111
sleep 2
1212
done
1313
export ADDRESS_FILE="/ocean-contracts/artifacts/address.json"
14-
/usr/src/app/
14+
cd /usr/src/app/
1515
npm run quickstart:barge
1616
fi
1717
tail -f /dev/null

package.json

+7-29
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,20 @@
33
"version": "1.2.0",
44
"scripts": {
55
"start": "",
6-
"quickstart:development": "node ./scripts/generatenetworkssubgraphs.js development && npm run codegen && npm run create:local-development && npm run deploy:local-development",
6+
"quickstart:development": "node ./scripts/generatenetworkssubgraphs.js development && npm run codegen && npm run create:local && npm run deploy:local",
77
"quickstart:barge": "node ./scripts/generatenetworkssubgraphs.js development && npm run codegen && npm run create:local-barge && npm run deploy:local-barge",
8-
"create": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
8+
"quickstart:rinkeby": "node ./scripts/generatenetworkssubgraphs.js rinkeby && npm run codegen && npm run create:local && npm run deploy:local",
9+
"quickstart:ropsten": "node ./scripts/generatenetworkssubgraphs.js ropsten && npm run codegen && npm run create:local && npm run deploy:local",
10+
"quickstart:mumbai": "node ./scripts/generatenetworkssubgraphs.js mumbai && npm run codegen && npm run create:local && npm run deploy:local",
11+
"quickstart:moonbase": "node ./scripts/generatenetworkssubgraphs.js moonbase && npm run codegen && npm run create:local && npm run deploy:local",
12+
"create:thegraph": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
913
"create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
10-
"create:local-development": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:9020",
1114
"create:local-barge": "graph create oceanprotocol/ocean-subgraph --node http://172.15.0.15:8020",
12-
"create:local-rinkeby": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
13-
"create:local-ropsten": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
14-
"create:local-polygon": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
15-
"create:local-moonbeamalpha": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
16-
"create:local-gaiaxtestnet": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
17-
"create:local-catenaxtestnet": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
18-
"create:local-mumbai": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
19-
"create:local-bsc": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
20-
"create:local-celoalfajores": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
21-
"create:local-energyweb": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
22-
"create:local-moonriver": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
2315
"codegen": "graph codegen --output-dir src/@types",
2416
"build": "graph build",
25-
"xx": "graph deploy --help",
26-
"deploy": "graph deploy oceanprotocol/ocean-subgraph -l $npm_package_version --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
27-
"deploy:beta": "graph deploy oceanprotocol/ocean-subgraph-beta -l $npm_package_version --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
17+
"deploy:thegraph": "graph deploy oceanprotocol/ocean-subgraph -l $npm_package_version --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
2818
"deploy:local": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
29-
"deploy:local-development": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:9020",
3019
"deploy:local-barge": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml -l $npm_package_version --debug --ipfs http://172.15.0.16:5001 --node http://172.15.0.15:8020",
31-
"deploy:local-rinkeby": "graph deploy oceanprotocol/ocean-subgraph subgraph.rinkeby.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
32-
"deploy:local-ropsten": "graph deploy oceanprotocol/ocean-subgraph subgraph.ropsten.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
33-
"deploy:local-polygon": "graph deploy oceanprotocol/ocean-subgraph subgraph.polygon.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
34-
"deploy:local-moonbeamalpha": "graph deploy oceanprotocol/ocean-subgraph subgraph.moonbeamalpha.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
35-
"deploy:local-gaiaxtestnet": "graph deploy oceanprotocol/ocean-subgraph subgraph.gaiaxtestnet.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
36-
"deploy:local-catenaxtestnet": "graph deploy oceanprotocol/ocean-subgraph subgraph.catenaxtestnet.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
37-
"deploy:local-mumbai": "graph deploy oceanprotocol/ocean-subgraph subgraph.mumbai.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
38-
"deploy:local-bsc": "graph deploy oceanprotocol/ocean-subgraph subgraph.bsc.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
39-
"deploy:local-celoalfajores": "graph deploy oceanprotocol/ocean-subgraph subgraph.celoalfajores.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
40-
"deploy:local-energyweb": "graph deploy oceanprotocol/ocean-subgraph subgraph.energyweb.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
41-
"deploy:local-moonriver": "graph deploy oceanprotocol/ocean-subgraph subgraph.moonriver.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020",
4220
"test": "npm run codegen && npm run lint && npm run type-check",
4321
"test-integration": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/**/*.test.ts'",
4422
"lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .",

scripts/generatenetworkssubgraphs.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ var addresses = require('@oceanprotocol/contracts/addresses/address.json')
44

55
async function replaceContractAddresses() {
66
// load addresses file first
7+
if (!process.argv[2]) {
8+
console.error('Missing network..')
9+
return
10+
}
711
if (process.env.ADDRESS_FILE) {
812
console.log('Using custom ADDRESS_FILE instead of ocean-contracts npm dep')
913
addresses = JSON.parse(fs.readFileSync(process.env.ADDRESS_FILE, 'utf8'))
1014
}
11-
console.log(process.argv)
15+
1216
for (const network in addresses) {
13-
if (process.argv[2] && process.argv[2] != network) {
17+
if (process.argv[2] != network) {
1418
console.log('Skipping ' + network)
1519
continue
1620
}
17-
console.log('Creating subgraph.' + network + '.yaml')
18-
let subgraph = fs.readFileSync('./scripts/subgraph.yaml', 'utf8')
21+
console.log('Creating subgraph.yaml for ' + network)
22+
let subgraph = fs.readFileSync('./subgraph.template.yaml', 'utf8')
1923

2024
subgraph = subgraph.replace(/__NETWORK__/g, network)
2125
subgraph = subgraph.replace(
@@ -38,9 +42,7 @@ async function replaceContractAddresses() {
3842
/__FACTORYROUTERADDRESS__/g,
3943
"'" + addresses[network].Router + "'"
4044
)
41-
if (network != 'development')
42-
fs.writeFileSync('subgraph.' + network + '.yaml', subgraph, 'utf8')
43-
else fs.writeFileSync('subgraph.yaml', subgraph, 'utf8')
45+
fs.writeFileSync('subgraph.yaml', subgraph, 'utf8')
4446
}
4547
}
4648

0 commit comments

Comments
 (0)