Skip to content

Commit

Permalink
Move to graph studio (cowprotocol#70)
Browse files Browse the repository at this point in the history
* Update cli version

* Update deploy script to use new approach

* Update example .env

* Remove removal of ABIs for UniswapV2

* Update scripts to use npm package version

* Update example env file

* Fix gnosis naming and subgraph

* Update README.md

* Remove rinkeby

* Add additional scripts to deploy all

* Remove usesUniV2
  • Loading branch information
tukantje authored Jan 11, 2024
1 parent e8dc1f6 commit d48bf1d
Show file tree
Hide file tree
Showing 11 changed files with 2,061 additions and 1,034 deletions.
7 changes: 4 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# SUBGRAPH=YourGithubUser/YourSubgraph
# NETWORK=mainnet

# Rinkeby
SUBGRAPH=YourGithubUser/YourSubgraph
NETWORK=rinkeby
# Goerli
AUTH_TOKEN=YourAuthTokenFromTheGraph
SUBGRAPH=NameOfYourSubgraph
NETWORK=goerli

# Gnosis Chain
# SUBGRAPH=YourGithubUser/YourSubgraph
Expand Down
28 changes: 11 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

Implements a subgraph for the [CoW Protocol](https://github.com/cowprotocol/contracts)

*This is a work in progress*
_This is a work in progress_

- [Subgraph on mainnet](https://thegraph.com/hosted-service/subgraph/cowprotocol/cow)
- [Subgraph on rinkeby (will be deprecated)](https://thegraph.com/hosted-service/subgraph/cowprotocol/cow-rinkeby)
- [Subgraph on goerli](https://thegraph.com/hosted-service/subgraph/cowprotocol/cow-goerli)
- [Subgraph on gnosis chain network](https://thegraph.com/hosted-service/subgraph/cowprotocol/cow-gc)
- [Subgraph on mainnet](https://thegraph.com/studio/subgraph/cow/)
- [Subgraph on goerli](https://thegraph.com/studio/subgraph/cow-goerli/)
- [Subgraph on gnosis chain network](https://thegraph.com/studio/subgraph/cow-gc/)

For more information about:

Expand All @@ -17,37 +16,32 @@ The Graph: https://thegraph.com/docs/en/

There is also a GP v1 subgraph here: https://github.com/gnosis/dex-subgraph

## Model
## Model

Further information about the model [here](./model.md)

## Setup of your own test subgraph

*Requisites:* You must have access to a console and have yarn installed. More info about [yarn](https://classic.yarnpkg.com/lang/en/docs/)
_Requisites:_ You must have access to a console and have yarn installed. More info about [yarn](https://classic.yarnpkg.com/lang/en/docs/)

1. Install the dependencies by executing:

```bash
$ yarn
```

2. Go to The Graph [hosted service](https://thegraph.com/hosted-service/dashboard) and log in using your github credentials.
2. Go to The Graph [Studio](https://thegraph.com/studio/dashboard) and log in using your github credentials.

3. Copy your access token and run the following:
3. In your browser, create a new subgraph in the dashboard by clicking "Add Subgraph" button. Complete the form.

```bash
$ graph auth --product hosted-service <YourAccessToken>
```

5. In your browser, create a new subgraph in the dashboard by clicking "Add Subgraph" button. Complete the form. Notice your subgraph will be named: `YourGithubAccount/SubgraphName`

6. Create your own environment and edit so it points to your testing subgraph:
4. Create your own environment and edit so it points to your testing subgraph:

```bash
cp .env.example .env
```

7. Deploy:
5. Deploy:

```bash
yarn deploy
```
Expand Down
5 changes: 0 additions & 5 deletions config/gc.json

This file was deleted.

4 changes: 4 additions & 0 deletions config/gnosis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"network": "gnosis",
"startBlock": 16465100
}
3 changes: 1 addition & 2 deletions config/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"network": "goerli",
"startBlock": 7020473,
"uniV3Factory": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"uniV3StartBlock": 4734394,
"usesUniV2": false
"uniV3StartBlock": 4734394
}
3 changes: 1 addition & 2 deletions config/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"network": "mainnet",
"startBlock": 12593264,
"uniV3Factory": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"uniV3StartBlock": 12369621,
"usesUniV2": false
"uniV3StartBlock": 12369621
}
7 changes: 0 additions & 7 deletions config/rinkeby.json

This file was deleted.

13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"name": "gpv2poc",
"license": "UNLICENSED",
"version": "0.0.1",
"scripts": {
"codegen": "graph codegen",
"build": "graph build",
"deploy": "node src/scripts/deploy.js",
"deploy:mainnet": "cross-env NETWORK=mainnet SUBGRAPH=gnosis/cow yarn deploy",
"deploy:rinkeby": "cross-env NETWORK=rinkeby SUBGRAPH=gnosis/cow-rinkeby yarn deploy",
"deploy:gc": "cross-env NETWORK=gc SUBGRAPH=gnosis/cow-gc yarn deploy"
"deploy:all": "run-s deploy:mainnet deploy:goerli deploy:gc",
"deploy:mainnet": "cross-env NETWORK=mainnet SUBGRAPH=cow yarn deploy",
"deploy:goerli": "cross-env NETWORK=goerli SUBGRAPH=cow-goerli yarn deploy",
"deploy:gc": "cross-env NETWORK=gnosis SUBGRAPH=cow-gc yarn deploy"
},
"dependencies": {
"@graphprotocol/graph-cli": "^0.31.0",
"@graphprotocol/graph-cli": "^0.48.0",
"@graphprotocol/graph-ts": "^0.27.0",
"mustache": "^4.2.0"
"mustache": "^4.2.0",
"yarn-run-all": "^3.1.1"
},
"devDependencies": {
"chalk": "^2.4.1",
Expand Down
133 changes: 85 additions & 48 deletions src/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,93 @@
const assert = require('assert')
const { series } = require('async')
const { default: chalk } = require('chalk')
const { exec } = require('child_process')
const { confirm } = require('./utils')
const assert = require("assert");
const { series } = require("async");
const { default: chalk } = require("chalk");
const { exec } = require("child_process");
const { confirm } = require("./utils");

require('dotenv').config()
require("dotenv").config();

const NETWORK = process.env.NETWORK
assert(NETWORK, 'NETWORK env var is required')
const NETWORK = process.env.NETWORK;
assert(NETWORK, "NETWORK env var is required");

const SUBGRAPH = process.env.SUBGRAPH
assert(SUBGRAPH, 'SUBGRAPH env var is required')
const SUBGRAPH = process.env.SUBGRAPH;
assert(SUBGRAPH, "SUBGRAPH env var is required");

console.log(`Prepare subgraph config for network ${NETWORK}`)
console.log(` Generate subgraph.yaml`)
const AUTH_TOKEN = process.env.AUTH_TOKEN;
assert(AUTH_TOKEN, "AUTH_TOKEN env var is required");

series([
(callback) => exec(`mustache config/${NETWORK}.json subgraph.yaml.mustache > subgraph.yaml`, null, callback),
const VERSION = process.env.npm_package_version;
assert(
VERSION,
"npm_package_version env var is required. This is defined by npm when version field is defined in the package.json file."
);

(callback) => {
console.log('\n📝 Generate code from your GraphQL schema')
return exec('yarn codegen', undefined, callback)
},
console.log(`Prepare subgraph config for network ${NETWORK}`);
console.log(` Generate subgraph.yaml`);

(callback) => {
console.log(`\n⬆️ Deploying graph:
${chalk.blue('Subgraph')}: ${SUBGRAPH}
${chalk.blue('Network')}: ${NETWORK}
`)
confirm({
message: chalk.red('Are you sure you want to deploy?'),
callbackYes() {
exec(`graph deploy ${SUBGRAPH} --product hosted-service`, (error) => {
if (error) {
console.log(`${chalk.red('\n\n🚩 There was an error deploying the subgraph 🚩')} \n\n`)
console.error(`${error}`)
return
}
})
console.log(`\n🚀 Deploy graph to https://thegraph.com/hosted-service/subgraph/${SUBGRAPH}`)
callback()
},
callbackNo() {
console.log('\n🤗 Ok, not deploying then'); callback()
}
})
series(
[
(callback) => {
return exec(
`mustache config/${NETWORK}.json subgraph.yaml.mustache > subgraph.yaml`,
callback
);
},
(callback) => {
console.log("\n📝 Generate code from your GraphQL schema");
return exec("yarn codegen", callback);
},
(callback) => {
console.log("\n📝 Build subgraph");
return exec("yarn build", callback);
},
(callback) => {
console.log("\n📝 Authenticate with the Graph Studio");
return exec(`graph auth --studio ${AUTH_TOKEN}`, callback);
},
(callback) => {
console.log(`\n⬆️ Deploying graph:
${chalk.blue("Subgraph")}: ${SUBGRAPH}
${chalk.blue("Network")}: ${NETWORK}
`);
confirm({
message: chalk.red("Are you sure you want to deploy?"),
callbackYes() {
exec(
`graph deploy --studio ${SUBGRAPH} --version-label ${VERSION}`,
(error) => {
if (error) {
console.log(
`${chalk.red(
"\n\n🚩 There was an error deploying the subgraph 🚩"
)} \n\n`
);
console.error(`${error}`);
return;
}
}
);
console.log(
`\n🚀 Deploy graph to https://thegraph.com/studio/subgraph/${SUBGRAPH}`
);
callback();
},
callbackNo() {
console.log("\n🤗 Ok, not deploying then");
callback();
},
});
},
],
(error) => {
if (error) {
console.log(
`${chalk.red(
"\n\n🚩 There was an error preparing the subgraph 🚩"
)} \n\n`
);
console.error(`${error}`);
return;
}
return;
}
], (error) => {
if (error) {
console.log(`${chalk.red('\n\n🚩 There was an error preparing the subgraph 🚩')} \n\n`)
console.error(`${error}`)
return
}
return
});
);
2 changes: 0 additions & 2 deletions subgraph.yaml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ dataSources:
file: ./abis/GPV2Settlement.json
- name: ERC20
file: ./abis/ERC20.json
{{#usesUniV2}}
- name: UniswapV2Factory
file: ./abis/UniswapV2Factory.json
- name: UniswapV2Pair
file: ./abis/UniswapV2Pair.json
{{/usesUniV2}}
eventHandlers:
- event: Interaction(indexed address,uint256,bytes4)
handler: handleInteraction
Expand Down
Loading

0 comments on commit d48bf1d

Please sign in to comment.