🦀 Ocean Protocol Subgraph
Go to file
Alex Coseru f04fe156ac
refactor (#314)
* refactor contracts usage

* add docker support for barge

* add tests
2022-02-14 10:35:55 +02:00
.github refactor (#314) 2022-02-14 10:35:55 +02:00
abis refactor (#314) 2022-02-14 10:35:55 +02:00
docker Fix bugs (#286) 2022-01-13 08:24:57 -08:00
scripts refactor (#314) 2022-02-14 10:35:55 +02:00
src fix rate 2022-02-11 15:13:21 +02:00
test/integration refactor (#314) 2022-02-14 10:35:55 +02:00
.docignore Feature: Improve readme file for rendering in read-the-docs (#127) 2021-06-10 10:34:49 +03:00
.dockerignore refactor (#314) 2022-02-14 10:35:55 +02:00
.eslintignore basic events 2021-11-04 17:00:43 +02:00
.eslintrc Feature/bump libs (#255) 2021-10-28 19:43:50 +03:00
.gitignore add dispenser (#106) 2021-05-13 09:19:21 +03:00
.nvmrc add nvmrc (#199) 2021-08-11 18:11:49 +03:00
.prettierignore update schema 2021-10-28 19:48:53 +03:00
.prettierrc up 2021-09-15 12:53:50 +03:00
CHANGELOG.md Feature/bump libs (#255) 2021-10-28 19:43:50 +03:00
Dockerfile refactor (#314) 2022-02-14 10:35:55 +02:00
LICENSE Initial commit 2020-11-19 08:15:23 +01:00
README.md refactor (#314) 2022-02-14 10:35:55 +02:00
docker-entrypoint.sh refactor (#314) 2022-02-14 10:35:55 +02:00
package-lock.json refactor (#314) 2022-02-14 10:35:55 +02:00
package.json refactor (#314) 2022-02-14 10:35:55 +02:00
schema.graphql contract address update 2022-02-11 13:41:47 +02:00
subgraph.yaml refactor (#314) 2022-02-14 10:35:55 +02:00
tsconfig.json project setup fixes (#1) 2020-12-11 11:37:09 +01:00




🦀 Ocean Protocol Subgraph

Build Status

js oceanprotocol

🏄 Get Started

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

Example Queries

All pools

  pools(orderBy: oceanReserve, orderDirection: desc) {

All datatokens

  datatokens(orderBy: createTime, orderDirection: desc) {

All pool transactions for a given user

    where: { userAddressStr: $userAddress }
    orderBy: timestamp
    orderDirection: desc
  ) {

Note: all ETH addresses like $userAddress in above example need to be passed in lowercase.

🏊 Development

First, clone the repo and install dependencies:

git clone https://github.com/oceanprotocol/ocean-subgraph/
cd ocean-subgraph
npm i

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:

cd docker

Then add your Infura key as environment variable with a .env file, and start everything up with Docker Compose:

# create .env and modify
cp .env.example .env

docker-compose --env-file .env up

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.

You now have a local graph-node running and can start deploying your changes to it. To do so, follow the Deployment instructions.

🏊 Development on Barge

  1. Clone barge and run it in another terminal:
git clone https://github.com/oceanprotocol/barge.git
cd barge
./start_ocean.sh --with-thegraph

If you have cloned Barge previously, make sure you are using the latest version by running git pull.

  1. Switch back to your main terminal and clone the repo and install dependencies:
git clone https://github.com/oceanprotocol/ocean-subgraph/
cd ocean-subgraph
npm i
  1. If you use barge, then let the components know where to pickup the smart contract addresses. For production networks, skip this step
export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json"
  1. Generate the subgraphs
node ./scripts/generatenetworkssubgraphs.js
npm run codegen

To generate subgraph for just one network, add the network name as parameter

node ./scripts/generatenetworkssubgraphs.js rinkeby
  1. To deploy a subgraph use:

npm run create:local-[network] npm run deploy:local-[network]

npm run create:local-development
npm run deploy:local-development
  • 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.

You now have a local graph-node running on

🔍 Testing

  • Please note: the npm run test command is currently not working due to this issue.

To run the integration tests locally, first start up barge by following the instructions above, then run the following terminal commands from the ocean-subgraph folder:

export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json"
npm run test-integration

Code Style

For linting and auto-formatting you can use from the root of the project:

# lint all js with eslint
npm run lint

# auto format all js & css with prettier, taking all configs into account
npm run format

🛳 Releases

Releases are managed semi-automatically. They are always manually triggered from a developer's machine with release scripts. From a clean main branch you can run the release task bumping the version accordingly based on semantic versioning:

npm run release

The task does the following:

  • bumps the project version in package.json, package-lock.json
  • auto-generates and updates the CHANGELOG.md file from commit messages
  • creates a Git tag
  • commits and pushes everything
  • creates a GitHub release with commit messages as description
  • Git tag push will trigger Travis to do a npm release

For the GitHub releases steps a GitHub personal access token, exported as GITHUB_TOKEN is required. Setup

⬆️ Deployment

Do the following to deploy the ocean-subgraph to a graph-node running locally, pointed against mainnet:

npm run codegen

# deploy
npm run create:local
npm run deploy:local

To deploy a subgraph connected to Rinkeby or Ropsten test networks, use instead:

# Rinkeby
npm run create:local-rinkeby
npm run deploy:local-rinkeby

# Ropsten
npm run create:local-ropsten
npm run deploy:local-ropsten

You can edit the event handler code and then run npm run deploy:local, with some caveats:

  • Running deploy will fail if the code has no changes
  • Sometimes deploy will fail no matter what, in this case:
    • Stop the docker-compose run (docker-compose down or Ctrl+C) This should stop the graph-node, ipfs and postgres containers
    • Delete the ipfs and postgres folders in /docker/data (rm -rf ./docker/data/*)
    • Run docker-compose up to restart graph-node, ipfs and postgres
    • Run npm run create:local to create the ocean-subgraph
    • Run npm run deploy:local to deploy the ocean-subgraph

To deploy to one of the remote nodes run by Ocean, you can do port-forwarding and the above :local commands will work as is.

🏛 License

Copyright ((C)) 2021 Ocean Protocol Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.