🦀 Ocean Protocol Subgraph
Go to file
2021-01-29 11:36:07 +01:00
abis project setup fixes (#1) 2020-12-11 11:37:09 +01:00
src add subgraph config for rinkeby and ropsten testnets, set ocean address based on detected network name 2021-01-20 09:35:53 +01:00
.eslintrc project setup fixes (#1) 2020-12-11 11:37:09 +01:00
.gitignore Add mappings for BFactory and BPool events with handlers 2020-11-20 13:12:02 +01:00
.prettierrc project setup fixes (#1) 2020-12-11 11:37:09 +01:00
.travis.yml project setup fixes (#1) 2020-12-11 11:37:09 +01:00
CHANGELOG.md add changelog 2020-12-11 11:42:06 +01:00
LICENSE Initial commit 2020-11-19 08:15:23 +01:00
package-lock.json Release 1.0.0 2020-12-11 11:41:26 +01:00
package.json Use same subgraph name for all different networks, since they are deployed to different instances anyway. 2021-01-20 12:11:10 +01:00
README.md Update the readme file. 2021-01-29 11:36:07 +01:00
schema.graphql capture total locked value and keep it up to date with pool updates. 2021-01-14 13:31:29 +01:00
subgraph.rinkeby.yaml add subgraph config for rinkeby and ropsten testnets, set ocean address based on detected network name 2021-01-20 09:35:53 +01:00
subgraph.ropsten.yaml add subgraph config for rinkeby and ropsten testnets, set ocean address based on detected network name 2021-01-20 09:35:53 +01:00
subgraph.yaml project setup fixes (#1) 2020-12-11 11:37:09 +01:00
tsconfig.json project setup fixes (#1) 2020-12-11 11:37:09 +01:00

banner

ocean-subgraph

🦀 Ocean Protocol Subgraph

Build Status js oceanprotocol

🏄 Get Started

This subgraph is deployed for all networks the Ocean Protocol contracts are deployed to:

🧶 Example Queries

All pools

{
  pools(orderBy: oceanReserve, orderDirection: desc) {
    consumePrice
    datatokenReserve
    oceanReserve
    spotPrice
    swapFee
    transactionCount
  }
}

All datatokens

{
  datatokens(orderBy: createTime, orderDirection: desc) {
    address
    symbol
    name
    cap
    supply
    publisher
    holderCount
  }
}

All pool transactions for a given user

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

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

🦑 Development

npm i
  • Install/run the Graph: https://thegraph.com/docs/quick-start

    • You can skip running ganache-cli and connect directly to mainnet using Infura
git clone https://github.com/graphprotocol/graph-node/
cd graph-node/docker
./setup.sh
# Update this line in the `docker-compose.yml` file with your Infura ProjectId
#   ethereum: 'mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID'
docker-compose up

Note: making contract calls using Infura fails with missing trie node errors. The fix requires editing ethereum_adapter.rs line 434 to use the latest block instead of a specific block number. Replace: web3.eth().call(req, Some(block_id)).then(|result| { with web3.eth().call(req, Some(BlockNumber::Latest.into())).then(|result| {

To run the graph-node with this fix it must be run from source.

First, remove the graph-node container from the docker-compose.yml file then run docker-compose up to get the postgresql and ipfs services running.

Now you can build and run the graph-node from source

cargo run -p graph-node --release > graphnode.log --
  --postgres-url postgres://graph-node:let-me-in@localhost:5432/graph-node
  --ethereum-rpc mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID
  --ipfs 127.0.0.1:5001

To deploy the ocean-subgraph to graph-node, see the Deployment section below.

You can make changes to the event handlers and/or features and re-deploy, again see the Deployment section below.

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

🛳 Production

⬆️ Deployment

  • Do the following to deploy the ocean-subgraph to a graph-node running locally:
git clone https://github.com/oceanprotocol/ocean-subgraph/
cd ocean-subgraph
npm i
npm run codegen
npm run create:local
npm run deploy:local

The above will deploy to mainnet. To create/deploy to Rinkeby or Ropsten test net, use :local-rinkeby or :local-ropsten with either create or deploy command.

  • You can edit the event handler code and then run npm run deploy:local
    • Running deploy will fail if the code has no changes
    • Sometimes deploy will fail no matter what, in this case:
      • Stop the graph-node run (Ctrl+C)
      • Stop the docker-compose run (docker-compose down or Ctrl+C)
      • Delete the ipfs and postgres folders in graph-node/docker/data (rm -rf ./docker/data/*)
      • Run docker-compose up to restart ipfs and postgres db
      • Run the graph-node as above (using the cargo command)
      • Run npm run create:local to create the ocean-subgraph
      • Run npm run deploy:local to deploy the ocean-subgraph

Note: to deploy to one of the remote nodes run by Ocean, you can do port-forwarding then the above local create/deploy 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

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.