🦀 Ocean Protocol Subgraph
Go to file
Maria Carmina e1df119197
Fix #628 & #629 & #621: Store event log index for all records (#630)
* Store eventIndex.

* Changed in veDelegation. Removed import of String.

* linter.

* Removed tx hash.

* Revert some tweaks.

* added logIndex.

* converted to big int.

* 0 -> BigInt.zero().

* Added eventIndex to template and OPC.

* updated tweak

* updated tweak2

* Added eventIndex in tests.

* revert.

* Added eventIndex for TokenCreated and NFTCreated events. Increase time sleep for graphql request.

* Changed position of eventIndex in entity.

* Added eventIndex for order events and for dt events. Added new test commands in package.json.

* Added eventIndex for NFT Update events.

* Added eventIndex for dispenser.

* Modified dispenser tests.

* Reverted sleep secs. Updated tests.

* Updated dispenser tests. Added eventIndex for FRE.

* Added eventIndex in df rewards.

* Updated Ve with eventIndex.

* Updating order id with event index.

* Updated @ocean/lib with multichain version.

* Updated to number type.

* Updated tests for order.

* some changes.

* Fix dt tests. Added logs for provider fee. Need fix for Simple publish and consume tests.

* Problem raised by retrieving order event index in provider fee event handler.

* Added function for searching the right order.

* Debug order with provider fee.

* Removed console logs.

* Added debug logs.

* Hardcoded eventIndex just for testing.

* Paste logs from graph node.

* added extra sleep in test.

* fixed command.

* Added comments. Modified util function for Order Reuse.

* Added more logs and other tweaks.

* fixed command for docker logs.

* Added more logs.

* Converted to lowercase.

* Removed condition just for test.

* Added more logs. Order is not null.

* Call getOrder.

* Added verification back.

* converted to hex and add toString.

* Pass toString as param.

* Added ethereumjs util.

* replaced with ==.

* Refactored logic.

* Print event index.

* added more logs of event index.

* Modified tweaks and asserts.

* Added log for reuse order.

* updates.

* Reverted changes.

* Added check for eventIndex == 0.

* Enhanced the code. Replaced while with for.

* Added more logs for reuse test.

* added another condition.

* Added logs in tests. Removed redundant condition.

* Added more logs to test.

* Fixed typo.

* still debugging

* Refactored code.

* Getting closer.

* Fix tests for orders part. Removed logs.

* Removed more logs.

* Fix DT tests related to order.

* Implemented Publishing Market Fee event handler. Added test.

* Added consume market fee handler. Test consume market fee handler.

* Fixed tests for fees. Added TODOs.

* Generated ID with eventIndex in ficed rate. Added assert errors messages.

* Added FRE tests to workflow.

* Generated dispenser transaction with event index.

* Fixed dispenser tests.

* Add event index for NftUpdate entity ID.

* Changed IDs for VeDelegation and VeAllocationUpdate.

* Added full test suite to workflow.

* Fixed nft transfer ID.

* print blocks.

* test just dt and ending test to see the last block.

* Added df test.

* Added dispenser test.

* Added FRE test.

* Added NFT test.

* Added simple publish consume test.

* Added simple subgraph test.

* Added users test.

* Added ve test.

* Increased sleep time.

* commented delegation test.

* respect lint

* Fixed ending tests. Removed commented code. Brought back test suite.

* Print values from failing tests. Updated mappings.

* Rollback changes in veDelegation and veUtils. Added more prints for debug in tests.

* Removed veDelegation creation record.

* Rollback to the approach for veDelegation like it is in main.

* Removed prints. Match changes with main.

* Removed -1 from last block.

* Added prints for eventIndex. Fixed some suggestions.

* Fixed veDelegation.

* Removed prints.
2023-05-13 15:00:52 +03:00
.github Fix #628 & #629 & #621: Store event log index for all records (#630) 2023-05-13 15:00:52 +03:00
.vscode Issue 471 provider fees (#474) 2022-07-12 11:11:43 +03:00
abis removing Vesting and opcFee (#432) 2022-05-12 20:31:12 +03:00
docker add lastPriceToken (#567) 2022-11-21 16:31:13 +02:00
docs Implementing first pass of veAllocate schema, handlers, and test cove… (#490) 2022-09-05 15:07:31 +03:00
scripts Feature/more ve (#543) 2022-09-23 15:54:27 +03:00
src/mappings Fix #628 & #629 & #621: Store event log index for all records (#630) 2023-05-13 15:00:52 +03:00
test/integration Fix #628 & #629 & #621: Store event log index for all records (#630) 2023-05-13 15:00:52 +03: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 reuse order (#444) 2022-05-25 20:04:26 +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 Release 3.0.7 2023-04-28 17:38:04 +03:00
docker-entrypoint.sh Feature/fix scripts (#331) 2022-02-17 12:59:55 +02:00
Dockerfile refactor (#314) 2022-02-14 10:35:55 +02:00
LICENSE Initial commit 2020-11-19 08:15:23 +01:00
package-lock.json Fix #628 & #629 & #621: Store event log index for all records (#630) 2023-05-13 15:00:52 +03:00
package.json Fix #628 & #629 & #621: Store event log index for all records (#630) 2023-05-13 15:00:52 +03:00
README.md Update README.md (#617) 2023-03-04 09:57:39 +02:00
schema.graphql Fix #628 & #629 & #621: Store event log index for all records (#630) 2023-05-13 15:00:52 +03:00
subgraph_ve.template.yaml proper veDelegation (#663) 2023-04-28 09:36:56 +03:00
subgraph.template.yaml Fix #628 & #629 & #621: Store event log index for all records (#630) 2023-05-13 15:00:52 +03: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 under /subgraphs/name/oceanprotocol/ocean-subgraph/ namespace for all networks the Ocean Protocol contracts are deployed to:

Example Queries

All Data NFTs

{
  nfts(orderBy: createdTimestamp, orderDirection: desc, first: 1000) {
    id
    symbol
    name
    creator
    createdTimestamp
  }
}

Note: 1000 is the maximum number of items the subgraph can return.

Total Orders for Each User

{
  users(first: 1000) {
    id
    totalOrders
  }
}

Total Orders for All Users

{
  users(first: 1000) {
    id
    totalOrders
  }
}

Note: 1000 is the maximum number of items the subgraph can return.

Total Orders for a Specific User

{
  user(id: $user) {
    id
    totalOrders
  }
}

Note: all ETH addresses like $user in above example need to be passed as a lowercase string.

All Orders

{
  orders(orderBy: createdTimestamp, orderDirection: desc, first: 1000){
    amount
    datatoken {
      id
    }
    consumer {
      id
    }
    payer {
      id
    }
  }
}

Note: 1000 is the maximum number of items the subgraph can return.

🏊 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. Let the components know where to pickup the smart contract addresses.
export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json"
  1. Generate the subgraphs
node ./scripts/generatenetworkssubgraphs.js barge
npm run codegen
  1. To deploy a subgraph use:

npm run create:local-barge npm run deploy:local-barge

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

You now have a local graph-node running on http://127.0.0.1:9000/subgraphs/name/oceanprotocol/ocean-subgraph/graphql

🏊 Deploying graphs for live networks

  1. Clone the repo and install dependencies:
git clone https://github.com/oceanprotocol/ocean-subgraph/
cd ocean-subgraph
npm i
  1. Generate & deploy on rinkeby
npm run quickstart:rinkeby

🔍 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)) 2023 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.