|
1 |
| -# daostack-subgraph |
2 |
| -A DAOstack subgraph for graph-node |
| 1 | +# DAOstack subgraph |
3 | 2 |
|
4 |
| -# Get started |
| 3 | +DAOstack subgraph for [TheGraph](https://thegraph.com/) project. |
5 | 4 |
|
6 |
| -Develop locally: |
| 5 | +## Getting started |
7 | 6 |
|
8 |
| -1. `npm i` - install dependencies. |
9 |
| -2. `npm run codegen` - generate automatic typings. |
10 |
| -3. create a `.env` file with the following environment variables (**should be kept secret**): |
11 |
| - - `POSTGRES_PASSWORD` - a secret string used as the PostgreSQL password for the created DB. |
12 |
| - - `ETHEREUM` - url to an rpc ethereum node prefixed with the network name (e.g. `mainnet:http://localhost:8545`) |
13 |
| -4. (in a seperate terminal) `docker-compose up` ([install](https://docs.docker.com/compose/install/)) - run a local graph-node with the above config. |
14 |
| -6. `npm run deploy`/`npm run deploy:watch` - deploy the subgraph. |
| 7 | +1 `git clone https://github.com/daostack/subgraph.git && cd subgraph` |
15 | 8 |
|
16 |
| -Note: All persistent data for the node will be stored in the `./data` directory, remove this directory in order to reset the node. |
| 9 | +2. `npm install` |
| 10 | +3. `npm run configure:<development|mainnet>` - configure the project to use ganache or mainnet via infura. |
17 | 11 |
|
18 |
| -Exposed endpoints: |
19 |
| -- `http://localhost:8000/daostack` - GraphQL API. |
20 |
| -- `http://localhost:8020` - graph-node RPC server. |
21 |
| -- `postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/postgres` - postgres DB connection. |
22 |
| -- `http://localhost:5001` - ipfs node api. |
| 12 | +All npm scripts can be called within a container using `docker-compose` with all dependencies and services set up: |
| 13 | + |
| 14 | +`docker-compose run subgraph -v $(pwd):/usr/app -v /usr/app/node_modules subgraph <command>` |
| 15 | + |
| 16 | +## Commands |
| 17 | + |
| 18 | +1. `configure:mainnet` - configure the project to run against mainnet. |
| 19 | +2. `configure:development` - configure the project to run against ganache. |
| 20 | +3. `migrate:development` - migrate contracts to ganache and update project configuration. |
| 21 | +4. `codegen` - automatically generate abi & type definitions for required contracts. |
| 22 | +5. `test` - run integration tests. |
| 23 | +6. `deploy` - deploy subgraph. |
| 24 | +7. `deploy:watch` - redeploy on file change. |
| 25 | + |
| 26 | +Example: `docker-compose run subgraph -v $(pwd):/usr/app -v /usr/app/node_modules subgraph test` (run intergation tests) |
| 27 | + |
| 28 | +To stop all services: `docker-compose down` |
| 29 | + |
| 30 | +## Exposed endpoints |
| 31 | + |
| 32 | +After running a command with docker-compose, the following endpoints will be exposed on your local machine: |
| 33 | + |
| 34 | +- `http://localhost:8000/daostack` - GraphiQL graphical user interface. |
| 35 | +- `http://localhost:8000/daostack/graphql` - GraphQL api endpoint. |
| 36 | +- `http://localhost:8001/daostack` - graph-node's websockets endpoint |
| 37 | +- `http://localhost:8020` - graph-node's RPC endpoint |
| 38 | +- `http://localhost:5001` - ipfs endpoint. |
| 39 | +- (if using development) `http://localhost:8545` - ganache RPC endpoint. |
| 40 | +- `http://localhost:5432` - postgresql connection endpoint. |
| 41 | + |
| 42 | +## Configuration |
| 43 | + |
| 44 | +This project automatically generates `.yaml` files used by `docker-compose` & `graph-node` based on configuration. |
| 45 | +Project configuration lives under: `ops/config.yaml` (public configration), `.env` (secret configuration). |
| 46 | + |
| 47 | +The following `.env` variables can be configured: |
| 48 | + |
| 49 | +- `daostack_mainnet__postgresPassword` - postgres password when running on mainnet (e.g `123`). |
| 50 | +- `daostack_mainnet__ethereumProvider` - mainnet web3 provider (e.g `https://mainnet.infura.io/v3/<api key>`) |
| 51 | + |
| 52 | +## Add a new contract tracker |
| 53 | + |
| 54 | +In order to add support for a new contract follow these steps: |
| 55 | + |
| 56 | +1. Create a mapping file at `src/<contract name>.ts`. |
| 57 | +2. Create a test file at `test/integration/<contract name>.spec.ts`. |
| 58 | +3. Configure the contract's mainnet address at `ops/config.yaml` under `addresses.<contract name>`. |
| 59 | +4. Add the contract to the migration script at the `migrate` function in `ops/index.js`. |
| 60 | +5. Add an additional datasource for the new contract at `subgraph.handlebars.yaml`, use `{{addresses.<contract name>}}` in place of the contract address. |
0 commit comments