Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
64 changes: 42 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
# polymarket-subgraph
# Polymarket Subgraph

## Environment Variables
## Published Versions on The Graph Network

Create a `.env` file with the following variables:
- [Polymarket Subgraph](https://thegraph.com/explorer/subgraphs/81Dm16JjuFSrqz813HysXoUPvzTwE7fsfPk2RTf66nyC?view=Query&chain=arbitrum-one)
- [Polymarket Profit and Loss (PnL)](https://thegraph.com/explorer/subgraphs/6c58N5U4MtQE2Y8njfVrrAfRykzfqajMGeTMEvMmskVz?view=Query&chain=arbitrum-one)
- [Polymarket Activity](https://thegraph.com/explorer/subgraphs/Bx1W4S7kDVxs9gC3s2G6DS8kdNBJNVhMviCtin2DiBp?view=Query&chain=arbitrum-one)
- [Polymarket Open Interest](https://thegraph.com/explorer/subgraphs/ELaW6RtkbmYNmMMU6hEPsghG9Ko3EXSmiRkH855M4qfF?view=Query&chain=arbitrum-one)

## Development

### Preparing `subgraph.yaml`

This repo contains multiple subgraphs, pnl-subgraph, activity-subgraph, and market-subgraph. Each subgraph has dedicated yarn scripts for convenience.

First, to prepare `subgraph.yaml` and other templated files, run `yarn templatify:matic`.

It's recommended to run the codegen command for the subgraph you're working on, as it will only generate the types and schemas for that subgraph. To do this, run `yarn pnl:codegen`, `yarn activity:codegen`, `yarn oi:codegen` or `yarn polymarket:codegen`.

### Deploy to Goldsky

Build the subgraph with `yarn <subgraph>:build`, and deploy with:

```bash
MATIC_RPC_URL=
goldsky subgraph deploy <subgraph-name>/<version> --path ./build/
```

Here, `MATIC_RPC_URL` should be your RPC URL for the Polygon network. Common providers include Alchemy and Infura.
### Deploy to Subgraph Studio

## Running the test suite
After subgraphs are built, deploy to [Subgraph Studio](https://thegraph.com/studio/):

Run `yarn test` to run the test suite, which will run in a docker container.
```
yarn activity:deploy-graph
yarn pnl:deploy-graph
yarn oi:deploy-graph
yarn polymarket:deploy-graph
```

## Preparing `subgraph.yaml`
### Run Graph Node locally

This repo contains multiple subgraphs, pnl-subgraph, activity-subgraph, and market-subgraph. Each subgraph has dedicated yarn scripts for convenience.
Create a `.env` file with the following variables:

First, to prepare `subgraph.yaml` and other templated files, run `yarn templatify:matic`.
```bash
MATIC_RPC_URL=
```

Here, `MATIC_RPC_URL` should be your RPC URL for the Polygon network. Common providers include Alchemy and Infura.

It's recommended to run the codegen command for the subgraph you're working on, as it will only generate the types and schemas for that subgraph. To do this, run `yarn pnl:codegen`, `yarn activity:codegen` or `yarn polymarket:codegen`.
### Running the test suite

## Local Deployment
Run `yarn test` to run the test suite, which will run in a docker container.

### Local Deployment

To start the docker environment, run `docker compose up`. Once the environment is ready, create and deploy the subgraph:

Expand All @@ -47,7 +75,7 @@ query tokenIdConditions {
}
```

## Restart graph node and clear volumes
### Restart graph node and clear volumes

```bash
docker compose down
Expand All @@ -59,15 +87,7 @@ sudo docker rm polymarket-subgraph-graph-node-1 && sudo docker rm polymarket-sub

The names of you docker containers may vary; check the terminal.

## Goldsky

Build the subgraph with `yarn <subgraph>:build`, and deploy with:

```bash
goldsky subgraph deploy <subgraph-name>/<version> --path ./build/
```

## Running on an M1 Chip
### Running on an M1 Chip

To run locally on an M1 chip, you'll need to build a local copy of the graph-node docker image. To do this, clone the [graph-node repo](https://github.com/graphprotocol/graph-node) and run the following commands:

Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
"deploy:matic-trading": "SUBGRAPH=Polymarket/polymarket-matic-trading yarn deploy",
"deploy:matic-backup-two": "SUBGRAPH=polymarket/matic-markets-5 yarn deploy",
"deploy:mumbai": "SUBGRAPH=TokenUnion/polymarket-mumbai yarn deploy",
"codegen": "graph codegen --debug --output-dir src/types/",
"prepare:mainnet": "NETWORK_NAME=mainnet ts-node ./templatify.ts && yarn codegen",
"prepare:matic": "NETWORK_NAME=matic ts-node ./templatify.ts && yarn codegen",
"prepare:matic": "NETWORK_NAME=matic ts-node ./templatify.ts matic && yarn codegen",
"prepare:mumbai": "NETWORK_NAME=mumbai ts-node ./templatify.ts && yarn codegen",
"publish-graph:matic": "yarn prepare:matic && yarn deploy:matic",
"publish-graph:matic-backup": "yarn prepare:matic && yarn deploy:matic-backup",
Expand All @@ -31,23 +30,27 @@
"publish-graph:mumbai": "yarn prepare:mumbai && yarn deploy:mumbai",
"test": "RUST_BACKTRACE=full graph test",
"templatify:matic": "ts-node ./templatify.ts matic",
"activity:codegen": "yarn graph codegen ./activity-subgraph/subgraph.yaml --debug --output-dir ./activity-subgraph/src/types",
"activity:build": "yarn graph build ./activity-subgraph/subgraph.yaml",
"activity:codegen": "graph codegen ./activity-subgraph/subgraph.yaml --output-dir ./activity-subgraph/src/types",
"activity:build": "graph build ./activity-subgraph/subgraph.yaml",
"activity:create-local": "graph create --node http://localhost:8020/ activity-subgraph",
"activity:deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 activity-subgraph ./activity-subgraph/subgraph.yaml",
"pnl:codegen": "yarn graph codegen ./pnl-subgraph/subgraph.yaml --debug --output-dir ./pnl-subgraph/src/types",
"pnl:build": "yarn graph build ./pnl-subgraph/subgraph.yaml",
"activity:deploy-graph": "graph deploy --studio polymarket-activity ./activity-subgraph/subgraph.yaml",
"pnl:codegen": "graph codegen ./pnl-subgraph/subgraph.yaml --output-dir ./pnl-subgraph/src/types",
"pnl:build": "graph build ./pnl-subgraph/subgraph.yaml",
"pnl:create-local": "graph create --node http://localhost:8020/ pnl-subgraph",
"pnl:deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 pnl-subgraph ./pnl-subgraph/subgraph.yaml",
"oi:codegen": "yarn graph codegen ./oi-subgraph/subgraph.yaml --debug --output-dir ./oi-subgraph/src/types",
"oi:build": "yarn graph build ./oi-subgraph/subgraph.yaml",
"pnl:deploy-graph": "graph deploy --studio polymarket-profit-and-loss ./pnl-subgraph/subgraph.yaml",
"oi:codegen": "graph codegen ./oi-subgraph/subgraph.yaml --output-dir ./oi-subgraph/src/types",
"oi:build": "graph build ./oi-subgraph/subgraph.yaml",
"oi:create-local": "graph create --node http://localhost:8020/ oi-subgraph",
"oi:deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 oi-subgraph ./oi-subgraph/subgraph.yaml",
"oi:remove-local": "graph remove --node http://localhost:8020/ oi-subgraph",
"polymarket:codegen": "yarn graph codegen ./polymarket-subgraph/subgraph.yaml --debug --output-dir ./polymarket-subgraph/src/types",
"polymarket:build": "yarn graph build ./polymarket-subgraph/subgraph.yaml",
"oi:deploy-graph": "graph deploy --studio polymarket-open-interest ./oi-subgraph/subgraph.yaml",
"polymarket:codegen": "graph codegen ./polymarket-subgraph/subgraph.yaml --output-dir ./polymarket-subgraph/src/types",
"polymarket:build": "graph build ./polymarket-subgraph/subgraph.yaml",
"polymarket:create-local": "graph create --node http://localhost:8020/ polymarket-subgraph",
"polymarket:deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 polymarket-subgraph ./polymarket-subgraph/subgraph.yaml"
"polymarket:deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 polymarket-subgraph ./polymarket-subgraph/subgraph.yaml",
"polymarket:deploy-graph": "graph deploy --studio polymarket ./polymarket-subgraph/subgraph.yaml"
},
"repository": {
"type": "git",
Expand All @@ -71,8 +74,8 @@
"devDependencies": {
"@as-pect/cli": "^8.1.0",
"@goldskycom/cli": "^7.4.0",
"@graphprotocol/graph-cli": "^0.33.1",
"@graphprotocol/graph-ts": "^0.27.0",
"@graphprotocol/graph-cli": "^0.86.0",
"@graphprotocol/graph-ts": "^0.35.1",
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.5",
"eslint": "^8.24.0",
Expand Down
Loading