2020-12-11 11:37:09 +01:00
[![banner ](https://raw.githubusercontent.com/oceanprotocol/art/master/github/repo-banner%402x.png )](https://oceanprotocol.com)
2020-11-20 13:12:02 +01:00
2020-12-11 11:37:09 +01:00
< h1 align = "center" > ocean-subgraph< / h1 >
> 🦀 Ocean Protocol Subgraph
2021-06-10 09:34:49 +02:00
< center >
2021-02-09 11:13:31 +01:00
[![Build Status ](https://github.com/oceanprotocol/ocean-subgraph/workflows/CI/badge.svg )](https://github.com/oceanprotocol/ocean-subgraph/actions)
2021-06-10 09:34:49 +02:00
< / center >
< center >
2020-12-11 11:37:09 +01:00
[![js oceanprotocol ](https://img.shields.io/badge/js-oceanprotocol-7b1173.svg )](https://github.com/oceanprotocol/eslint-config-oceanprotocol)
2021-06-10 09:34:49 +02:00
< / center >
2020-12-11 11:37:09 +01:00
- [🏄 Get Started ](#-get-started )
2021-06-10 09:34:49 +02:00
- [⛵ Example Queries ](#-example-queries )
- [🏊 Development on barge ](#-development-on-barge )
2022-02-17 11:59:55 +01:00
- [🏊 Deploying graphs for live networks ](#-Deploying-graphs-for-live-networks )
2021-06-10 09:34:49 +02:00
- [🔍 Testing ](#-testing )
2020-12-11 11:37:09 +01:00
- [✨ Code Style ](#-code-style )
2021-02-10 13:03:47 +01:00
- [🛳 Releases ](#️ -releases )
2020-12-11 11:37:09 +01:00
- [⬆️ Deployment ](#️ -deployment )
- [🏛 License ](#-license )
## 🏄 Get Started
2021-02-10 13:03:47 +01:00
This subgraph is deployed under `/subgraphs/name/oceanprotocol/ocean-subgraph/` namespace for all networks the Ocean Protocol contracts are deployed to:
2020-12-11 11:37:09 +01:00
2022-02-17 11:59:55 +01:00
- [subgraphv4.ropsten.oceanprotocol.com ](https://subgraphv4.ropsten.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql )
- [subgraphv4.rinkeby.oceanprotocol.com ](https://subgraphv4.rinkeby.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql )
- [subgraphv4.mumbai.oceanprotocol.com ](https://subgraphv4.mumbai.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql )
- [subgraphv4.moonbase.oceanprotocol.com ](https://subgraphv4.moonbase.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql )
2020-12-11 11:37:09 +01:00
2021-06-10 09:34:49 +02:00
## ⛵ Example Queries
2020-12-11 11:37:09 +01:00
**All pools**
```graphql
{
pools(orderBy: oceanReserve, orderDirection: desc) {
consumePrice
datatokenReserve
oceanReserve
spotPrice
swapFee
transactionCount
}
}
```
**All datatokens**
```graphql
{
datatokens(orderBy: createTime, orderDirection: desc) {
address
symbol
name
cap
supply
publisher
holderCount
}
}
```
**All pool transactions for a given user**
```graphql
{
poolTransactions(
where: { userAddressStr: $userAddress }
orderBy: timestamp
orderDirection: desc
) {
poolAddressStr
}
}
```
> Note: all ETH addresses like `$userAddress` in above example need to be passed in lowercase.
2021-04-13 17:10:03 +02:00
2021-06-10 09:34:49 +02:00
## 🏊 Development on Barge
2021-04-13 17:10:03 +02:00
2021-05-05 16:21:52 +02:00
2021-05-12 17:10:30 +02:00
1. Clone [barge ](https://github.com/oceanprotocol/barge ) and run it in another terminal:
2021-05-05 16:21:52 +02:00
2021-04-13 17:10:03 +02:00
```bash
2021-04-21 10:58:27 +02:00
git clone https://github.com/oceanprotocol/barge.git
cd barge
2021-04-13 17:10:03 +02:00
./start_ocean.sh --with-thegraph
```
2021-04-21 10:58:27 +02:00
If you have cloned Barge previously, make sure you are using the latest version by running `git pull` .
2021-05-12 17:10:30 +02:00
2. Switch back to your main terminal and clone the repo and install dependencies:
2021-04-13 17:10:03 +02:00
```bash
git clone https://github.com/oceanprotocol/ocean-subgraph/
cd ocean-subgraph
npm i
```
2022-02-17 11:59:55 +01:00
3. Let the components know where to pickup the smart contract addresses.
2021-05-12 11:49:29 +02:00
```
export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json"
```
2022-02-14 09:35:55 +01:00
4. Generate the subgraphs
2021-04-13 17:10:03 +02:00
```bash
2022-02-17 11:59:55 +01:00
node ./scripts/generatenetworkssubgraphs.js barge
2021-05-13 08:19:21 +02:00
npm run codegen
2021-04-13 17:10:03 +02:00
```
2022-02-14 09:35:55 +01:00
5. To deploy a subgraph use:
2022-02-17 11:59:55 +01:00
npm run create:local-barge
npm run deploy:local-barge
2021-04-13 17:10:03 +02:00
```bash
2022-02-17 11:59:55 +01:00
npm run create:local
npm run deploy:local
2021-04-13 17:10:03 +02:00
```
2022-02-17 11:59:55 +01:00
- Alternatively, if you want to get the sub-graph quickly running on barge, you can run `npm run quickstart:barge` which combines steps 4-5 above.
2021-05-12 17:10:30 +02:00
2022-02-14 09:35:55 +01:00
You now have a local graph-node running on http://127.0.0.1:9000/subgraphs/name/oceanprotocol/ocean-subgraph/graphql
2021-04-13 17:10:03 +02:00
2021-05-12 17:10:30 +02:00
2022-02-17 11:59:55 +01:00
## 🏊 Deploying graphs for live networks
1. Clone the repo and install dependencies:
```bash
git clone https://github.com/oceanprotocol/ocean-subgraph/
cd ocean-subgraph
npm i
```
2. Generate & deploy on rinkeby
```bash
npm run quickstart:rinkeby
```
2021-05-12 17:10:30 +02:00
2021-06-10 09:34:49 +02:00
## 🔍 Testing
2021-04-21 10:58:27 +02:00
2021-05-05 16:21:52 +02:00
- Please note: the `npm run test` command is currently not working due to [this issue ](https://github.com/graphprotocol/graph-ts/issues/113 ).
2021-04-21 10:58:27 +02:00
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:
```Bash
export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json"
npm run test-integration
```
2021-04-13 17:10:03 +02:00
2020-12-11 11:37:09 +01:00
## ✨ Code Style
For linting and auto-formatting you can use from the root of the project:
```bash
# lint all js with eslint
npm run lint
# auto format all js & css with prettier, taking all configs into account
npm run format
```
2020-11-20 13:12:02 +01:00
2021-02-10 13:03:47 +01:00
## 🛳 Releases
2020-12-11 11:37:09 +01:00
2021-02-09 11:13:31 +01:00
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:
2020-12-11 11:37:09 +01:00
```bash
npm run release
2020-11-20 13:12:02 +01:00
```
2020-12-09 15:03:40 +01:00
2020-12-11 11:37:09 +01:00
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 ](https://github.com/release-it/release-it#github-releases )
## ⬆️ Deployment
2021-02-10 13:03:47 +01:00
Do the following to deploy the ocean-subgraph to a graph-node running locally, pointed against `mainnet` :
2021-02-09 11:13:31 +01:00
```bash
npm run codegen
2021-02-10 13:03:47 +01:00
# deploy
2021-02-09 11:13:31 +01:00
npm run create:local
npm run deploy:local
```
2021-02-10 13:03:47 +01:00
To deploy a subgraph connected to Rinkeby or Ropsten test networks, use instead:
```bash
# 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:
2021-02-09 11:13:31 +01:00
2021-02-10 13:03:47 +01:00
- 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)
2021-02-09 11:13:31 +01:00
This should stop the graph-node, ipfs and postgres containers
2021-02-10 13:03:47 +01:00
- 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
2021-02-09 11:13:31 +01:00
2021-02-10 13:03:47 +01:00
> 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.
2020-12-11 11:37:09 +01:00
## 🏛 License
```
2022-02-24 10:28:22 +01:00
Copyright ((C)) 2022 Ocean Protocol Foundation
2020-12-11 11:37:09 +01:00
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.
```