Prerequisites
- graph-cli =>
sudo yarn global add @graphprotocol/graph-cli
- GraphQL Hosted Service Account
- Create by linking Github account
- Authenticate your local to deploy to your GraphQL account with
graph auth <PROVIDED_AUTH_KEY>
Steps
Change Vault and InvestmentPoolFactory addresses in the following files
-
./networks/yaml
- Need to fill in an address for 'WeightedPoolFactory' and 'WeightedPool2TokenFactory' fields, to support 'InvestmentPoolFactory'. But looks like these addresses don't need to correspond to an actual deployed WeightedPoolFactory or WeightedPool2TokenFactory.
-
src/mappings/helpers/constants.ts
- Add new network toAddressByNetwork
class, add network address forvaultAddressByNetwork
and...AddressByNetwork
classes, and add network toforNetwork
function
yarn codegen
=> Generates required development files including types for every Contract and object (the .ts files in src/mappings are not Typescript, but AssemblyScript which is more type-strict than Typescript. AssemblyScript is then compiled to Web Assembly in the build).
yarn build
=> Builds subgraph into ./dist
folder
graph deploy --product hosted-service <REPO_NAME/GRAPH_NAME> subgraph.<NETWORK>.yaml
=> Build and deploy subgraph to specified Hosted Service project
Debugging
Good old console.log is not compatible with AssemblyScript files. Use log
API - https://thegraph.com/docs/en/developer/assemblyscript-api/#logging-api
Documentation mentions forking your deployed subgraph, to a local Graph node, and speeding up the development process that way. Did not do this as it seemed bulky (mentions an 8GB RAM requirement somewhere) to do this.
Test GraphQL query (using Subgraph playground)
{
swaps(first: 100) {
tokenIn,
tokenOut,
tokenAmountIn,
tokenAmountOut,
tx,
timestamp,
userAddress {
id
}
}
}
{
balancers(first: 5) {
id
poolCount
totalLiquidity
}
pool(id: "0x8b021079eed6eea7a495369f70374272dc1a8311000100000000000000000013") {
totalLiquidity
}
}
Example code to build and send query to GraphQL API point in scripts/check_subgraph_health.ts
The graphql schema is still under heavy development and will likely have major breaking changes.
This repo tracks both the subgraph and a docker configuration that allows you to run the subgraph and frontend against the core v2 contracts.
- Global Yarn Packages
- truffle
- graph-cli
- Docker
Clone the pool-management-v2
repo and core
repo submodules
Docker compose can be started in various configurations to start a local etherem chain, a graph-node, and it's requisite services.
Start a parity chain and a graph node by running
yarn restart:parity
Then deploy V2 contracts, seed data and deploy subgraph
cd core && yarn redeploy:docker && popd
yarn codegen && yarn create:local && yarn deploy:local
now you should be able to interact with the graphql server at http://localhost:8000/subgraphs/name/balancer-labs/balancer-v2
Start the pool management frontend:
cd pool-management-v2 && yarn serve
Once setup, you can access the services at the addresses below
Service | address |
---|---|
JSON-RPC Server | http://localhost:8545 |
GraphQL HTTP server | http://localhost:8000 |
Graph Node JSON-RPC admin server | http://localhost:8020 |
Graph Node IndexNode server | http://localhost:8030 |
Graph Node Metrics server | http://localhost:8040 |
Graph Node WebSocket server | ws://localhost:8001 |
The docker-compose can be overridden to test contracts, subgraph, frontend against other networks. This is not generally recommended because the hardhat VM doesn't support call tracing which the subgraph uses to track contract calls. YMMV
Start a hardhat chain and a graph node by running
docker-compose -f docker-compose.yml -f docker-compose.hardhat.yml up
Start a ganache chain and a graph node by running
docker-compose -f docker-compose.yml -f docker-compose.ganache.yml up
To blow away graph-node settings
docker-compose kill && docker-compose rm -f && rm -rf data
Deploy balancer contracts using truffle. Using the yarn deploy
script in balancer-v2 also makes this easy to test out the subgraph using the frontend.
Clone the balancer subgraph
git clone [email protected]:balancer-labs/balancer-subgraph-v2.git
Update deployed contract address in subgraph.yaml to the ones listed as part of the deploy
Install dependencies
yarn
Generate the graph code
yarn codegen
Create local node
yarn create:local
Deploy locally
yarn deploy:local
Any updates can be made to this repo and re-running yarn deploy:local
without needing to re-initialize the environment.
Start Parity:
parity --chain=kovan --jsonrpc-interface=0.0.0.0
Update ethereum value in docker-compose.yml to kovan:http://host.docker.internal:8545
Comment out try_ functions in pool.ts LN52-64
docker-compose up
Create local node
yarn create:local
Deploy locally
yarn deploy:local