project setup fixes (#1)

* project setup fixes

* fix typescript

* some auto fixes

* fixes

* fix all linting errors

* add urls

* fixes, deactivate type checking on Travis for now

* add query examples

* consistent examples

* note about lowercase ETH addresses

* remove npm start
pull/22/head
Matthias Kretschmann 2 years ago committed by GitHub
parent 61238ab624
commit f649083b3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      .eslintrc
  2. 1
      .gitattributes
  3. 6
      .prettierrc
  4. 12
      .travis.yml
  5. 175
      README.md
  6. 82
      abis/BFactory.json
  7. 3050
      abis/BPool.json
  8. 152
      abis/BToken.json
  9. 88
      abis/DTFactory.json
  10. 1356
      abis/DataTokenTemplate.json
  11. 7027
      package-lock.json
  12. 58
      package.json
  13. 293
      src/helpers.ts
  14. 92
      src/mappings/datatoken.ts
  15. 17
      src/mappings/dtfactory.ts
  16. 19
      src/mappings/factory.ts
  17. 426
      src/mappings/pool.ts
  18. 18
      subgraph.yaml
  19. 23
      tsconfig.json

@ -0,0 +1,21 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json"]
},
"extends": [
"oceanprotocol",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier/react",
"prettier/standard",
"prettier/@typescript-eslint"
],
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "error"
},
"env": { "es6": true, "node": true }
}

1
.gitattributes vendored

@ -1 +0,0 @@
*.sol linguist-language=Solidity

@ -0,0 +1,6 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"tabWidth": 2
}

@ -0,0 +1,12 @@
language: node_js
node_js: node
script:
# will run `npm ci` automatically here
- npm run lint
# TODO: activate once this issue is solved:
# https://github.com/graphprotocol/graph-ts/issues/113
# - npm run type-check
notifications:
email: false

@ -1,15 +1,88 @@
# Ocean Protocol Subgraph
[![banner](https://raw.githubusercontent.com/oceanprotocol/art/master/github/repo-banner%402x.png)](https://oceanprotocol.com)
## Running locally
<h1 align="center">ocean-subgraph</h1>
> ๐Ÿฆ€ Ocean Protocol Subgraph
[![Build Status](https://travis-ci.com/oceanprotocol/ocean-subgraph.svg&branch=main)](https://travis-ci.com/oceanprotocol/ocean.js)
[![js oceanprotocol](https://img.shields.io/badge/js-oceanprotocol-7b1173.svg)](https://github.com/oceanprotocol/eslint-config-oceanprotocol)
- [๐Ÿ„ Get Started](#-get-started)
- [๐Ÿงถ Example Queries](#-example-queries)
- [๐Ÿฆ‘ Development](#-development)
- [โœจ Code Style](#-code-style)
- [โฌ†๏ธ Releases](#๏ธ-releases)
- [๐Ÿ›ณ Production](#-production)
- [โฌ†๏ธ Deployment](#๏ธ-deployment)
- [๐Ÿ› License](#-license)
## ๐Ÿ„ Get Started
This subgraph is deployed for all networks the Ocean Protocol contracts are deployed to:
- [subgraph.mainnet.oceanprotocol.com](https://subgraph.mainnet.oceanprotocol.com)
- [subgraph.ropsten.oceanprotocol.com](https://subgraph.ropsten.oceanprotocol.com)
- [subgraph.rinkeby.oceanprotocol.com](https://subgraph.ropsten.oceanprotocol.com)
## ๐Ÿงถ Example Queries
**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.
## ๐Ÿฆ‘ Development
* Install Graph CLI globally with npm
```bash
npm install -g @graphprotocol/graph-cli
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
- Install/run the Graph: `https://thegraph.com/docs/quick-start`
- You can skip running ganache-cli and connect directly to `mainnet` using Infura
```bash
git clone https://github.com/graphprotocol/graph-node/
cd graph-node/docker
@ -17,30 +90,26 @@ cd graph-node/docker
# 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| {`
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, delete the `graph-node` container from the `docker-compose.yml` file
First, delete 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
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
```
* Once the graph node is ready, do the following to deploy the ocean-subgraph to the local graph-node
- Once the graph node is ready, do the following to deploy the ocean-subgraph to the local graph-node
```bash
git clone https://github.com/oceanprotocol/ocean-subgraph/
cd ocean-subgraph
@ -48,14 +117,66 @@ npm i
npm run codegen
npm run create:local
npm run deploy:local
```
- 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 docker-compose run (`docker-compose down`)
- Delete the `ipfs` and `postgres` folders in `graph-node/docker/data`
- Restart docker-compose
- Run `npm run create:local` to create the ocean-subgraph
- Run `npm run deploy:local` to deploy the ocean-subgraph
## โœจ 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
```
## โฌ†๏ธ 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:
```bash
npm run release
```
* 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 docker-compose run (`docker-compose down`)
* Delete the `ipfs` and `postgres` folders in `graph-node/docker/data`
* Restart docker-compose
* Run `npm run create:local` to create the ocean-subgraph
* Run `npm run deploy:local` to deploy the ocean-subgraph
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)
## ๐Ÿ›ณ Production
## โฌ†๏ธ Deployment
## ๐Ÿ› License
```
Copyright ((C)) 2020 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.
```

@ -321,20 +321,14 @@
"ast": {
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BFactory.sol",
"exportedSymbols": {
"BFactory": [
376
]
"BFactory": [376]
},
"id": 377,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 282,
"literals": [
"solidity",
"0.5",
".7"
],
"literals": ["solidity", "0.5", ".7"],
"nodeType": "PragmaDirective",
"src": "0:22:3"
},
@ -410,19 +404,12 @@
"src": "679:8:3"
}
],
"contractDependencies": [
280,
5731
],
"contractDependencies": [280, 5731],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 376,
"linearizedBaseContracts": [
376,
5731,
280
],
"linearizedBaseContracts": [376, 5731, 280],
"name": "BFactory",
"nodeType": "ContractDefinition",
"nodes": [
@ -726,10 +713,7 @@
"id": 308,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "1176:7:3",
"typeDescriptions": {
@ -1069,10 +1053,7 @@
"id": 333,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "1637:7:3",
"typeDescriptions": {
@ -1099,9 +1080,7 @@
"src": "1637:103:3"
},
{
"assignments": [
343
],
"assignments": [343],
"declarations": [
{
"constant": false,
@ -1419,10 +1398,7 @@
"id": 348,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "1795:7:3",
"typeDescriptions": {
@ -1671,20 +1647,14 @@
"legacyAST": {
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BFactory.sol",
"exportedSymbols": {
"BFactory": [
376
]
"BFactory": [376]
},
"id": 377,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 282,
"literals": [
"solidity",
"0.5",
".7"
],
"literals": ["solidity", "0.5", ".7"],
"nodeType": "PragmaDirective",
"src": "0:22:3"
},
@ -1760,19 +1730,12 @@
"src": "679:8:3"
}
],
"contractDependencies": [
280,
5731
],
"contractDependencies": [280, 5731],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 376,
"linearizedBaseContracts": [
376,
5731,
280
],
"linearizedBaseContracts": [376, 5731, 280],
"name": "BFactory",
"nodeType": "ContractDefinition",
"nodes": [
@ -2076,10 +2039,7 @@
"id": 308,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "1176:7:3",
"typeDescriptions": {
@ -2419,10 +2379,7 @@
"id": 333,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "1637:7:3",
"typeDescriptions": {
@ -2449,9 +2406,7 @@
"src": "1637:103:3"
},
{
"assignments": [
343
],
"assignments": [343],
"declarations": [
{
"constant": false,
@ -2769,10 +2724,7 @@
"id": 348,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "1795:7:3",
"typeDescriptions": {
@ -3031,4 +2983,4 @@
"userdoc": {
"methods": {}
}
}
}

File diff suppressed because it is too large Load Diff

@ -497,23 +497,15 @@
"ast": {
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BToken.sol",
"exportedSymbols": {
"BToken": [
4285
],
"BTokenBase": [
3979
]
"BToken": [4285],
"BTokenBase": [3979]
},
"id": 4286,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 3780,
"literals": [
"solidity",
"0.5",
".7"
],
"literals": ["solidity", "0.5", ".7"],
"nodeType": "PragmaDirective",
"src": "643:22:7"
},
@ -560,19 +552,12 @@
"src": "1468:4:7"
}
],
"contractDependencies": [
280,
1422
],
"contractDependencies": [280, 1422],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 3979,
"linearizedBaseContracts": [
3979,
1422,
280
],
"linearizedBaseContracts": [3979, 1422, 280],
"name": "BTokenBase",
"nodeType": "ContractDefinition",
"nodes": [
@ -1617,10 +1602,7 @@
"id": 3855,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2056:7:7",
"typeDescriptions": {
@ -2312,10 +2294,7 @@
"id": 3908,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2410:7:7",
"typeDescriptions": {
@ -3312,23 +3291,12 @@
"src": "2843:6:7"
}
],
"contractDependencies": [
280,
1422,
3979,
6537
],
"contractDependencies": [280, 1422, 3979, 6537],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 4285,
"linearizedBaseContracts": [
4285,
6537,
3979,
1422,
280
],
"linearizedBaseContracts": [4285, 6537, 3979, 1422, 280],
"name": "BToken",
"nodeType": "ContractDefinition",
"nodes": [
@ -4299,9 +4267,7 @@
"id": 4070,
"name": "Approval",
"nodeType": "Identifier",
"overloadedDeclarations": [
6536
],
"overloadedDeclarations": [6536],
"referencedDeclaration": 6536,
"src": "3696:8:7",
"typeDescriptions": {
@ -4852,9 +4818,7 @@
"id": 4106,
"name": "Approval",
"nodeType": "Identifier",
"overloadedDeclarations": [
6536
],
"overloadedDeclarations": [6536],
"referencedDeclaration": 6536,
"src": "3926:8:7",
"typeDescriptions": {
@ -5019,9 +4983,7 @@
"src": "4087:315:7",
"statements": [
{
"assignments": [
4131
],
"assignments": [4131],
"declarations": [
{
"constant": false,
@ -5639,9 +5601,7 @@
"id": 4166,
"name": "Approval",
"nodeType": "Identifier",
"overloadedDeclarations": [
6536
],
"overloadedDeclarations": [6536],
"referencedDeclaration": 6536,
"src": "4320:8:7",
"typeDescriptions": {
@ -6279,10 +6239,7 @@
"id": 4211,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "4683:7:7",
"typeDescriptions": {
@ -7047,9 +7004,7 @@
"id": 4267,
"name": "Approval",
"nodeType": "Identifier",
"overloadedDeclarations": [
6536
],
"overloadedDeclarations": [6536],
"referencedDeclaration": 6536,
"src": "5017:8:7",
"typeDescriptions": {
@ -7247,23 +7202,15 @@
"legacyAST": {
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BToken.sol",
"exportedSymbols": {
"BToken": [
4285
],
"BTokenBase": [
3979
]
"BToken": [4285],
"BTokenBase": [3979]
},
"id": 4286,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 3780,
"literals": [
"solidity",
"0.5",
".7"
],
"literals": ["solidity", "0.5", ".7"],
"nodeType": "PragmaDirective",
"src": "643:22:7"
},
@ -7310,19 +7257,12 @@
"src": "1468:4:7"
}
],
"contractDependencies": [
280,
1422
],
"contractDependencies": [280, 1422],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 3979,
"linearizedBaseContracts": [
3979,
1422,
280
],
"linearizedBaseContracts": [3979, 1422, 280],
"name": "BTokenBase",
"nodeType": "ContractDefinition",
"nodes": [
@ -8367,10 +8307,7 @@
"id": 3855,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2056:7:7",
"typeDescriptions": {
@ -9062,10 +8999,7 @@
"id": 3908,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2410:7:7",
"typeDescriptions": {
@ -10062,23 +9996,12 @@
"src": "2843:6:7"
}
],
"contractDependencies": [
280,
1422,
3979,
6537
],
"contractDependencies": [280, 1422, 3979, 6537],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 4285,
"linearizedBaseContracts": [
4285,
6537,
3979,
1422,
280
],
"linearizedBaseContracts": [4285, 6537, 3979, 1422, 280],
"name": "BToken",
"nodeType": "ContractDefinition",
"nodes": [
@ -11049,9 +10972,7 @@
"id": 4070,
"name": "Approval",
"nodeType": "Identifier",
"overloadedDeclarations": [
6536
],
"overloadedDeclarations": [6536],
"referencedDeclaration": 6536,
"src": "3696:8:7",
"typeDescriptions": {
@ -11602,9 +11523,7 @@
"id": 4106,
"name": "Approval",
"nodeType": "Identifier",
"overloadedDeclarations": [
6536
],
"overloadedDeclarations": [6536],
"referencedDeclaration": 6536,
"src": "3926:8:7",
"typeDescriptions": {
@ -11769,9 +11688,7 @@
"src": "4087:315:7",
"statements": [
{
"assignments": [
4131
],
"assignments": [4131],
"declarations": [
{
"constant": false,
@ -12389,9 +12306,7 @@
"id": 4166,
"name": "Approval",
"nodeType": "Identifier",
"overloadedDeclarations": [
6536
],
"overloadedDeclarations": [6536],
"referencedDeclaration": 6536,
"src": "4320:8:7",
"typeDescriptions": {
@ -13029,10 +12944,7 @@
"id": 4211,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "4683:7:7",
"typeDescriptions": {
@ -13797,9 +13709,7 @@
"id": 4267,
"name": "Approval",
"nodeType": "Identifier",
"overloadedDeclarations": [
6536
],
"overloadedDeclarations": [6536],
"referencedDeclaration": 6536,
"src": "5017:8:7",
"typeDescriptions": {
@ -14007,4 +13917,4 @@
"userdoc": {
"methods": {}
}
}
}

@ -157,20 +157,14 @@
"ast": {
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/DTFactory.sol",
"exportedSymbols": {
"DTFactory": [
158
]
"DTFactory": [158]
},
"id": 159,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 1,
"literals": [
"solidity",
"0.5",
".7"
],
"literals": ["solidity", "0.5", ".7"],
"nodeType": "PragmaDirective",
"src": "0:22:0"
},
@ -217,17 +211,12 @@
"src": "651:8:0"
}
],
"contractDependencies": [
5731
],
"contractDependencies": [5731],
"contractKind": "contract",
"documentation": "@title DTFactory contract\n@author Ocean Protocol Team\n * @dev Implementation of Ocean DataTokens Factory\n * DTFactory deploys DataToken proxy contracts.\n New DataToken proxy contracts are links to the template contract's bytecode.\n Proxy contract functionality is based on Ocean Protocol custom implementation of ERC1167 standard.",
"fullyImplemented": true,
"id": 158,
"linearizedBaseContracts": [
158,
5731
],
"linearizedBaseContracts": [158, 5731],
"name": "DTFactory",
"nodeType": "ContractDefinition",
"nodes": [
@ -843,10 +832,7 @@
"id": 41,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "1528:7:0",
"typeDescriptions": {
@ -1139,10 +1125,7 @@
"id": 78,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2359:7:0",
"typeDescriptions": {
@ -1375,10 +1358,7 @@
"id": 91,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2499:7:0",
"typeDescriptions": {
@ -1405,9 +1385,7 @@
"src": "2499:124:0"
},
{
"assignments": [
101
],
"assignments": [101],
"declarations": [
{
"constant": false,
@ -1694,10 +1672,7 @@
"id": 106,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2695:7:0",
"typeDescriptions": {
@ -2346,20 +2321,14 @@
"legacyAST": {
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/DTFactory.sol",
"exportedSymbols": {
"DTFactory": [
158
]
"DTFactory": [158]
},
"id": 159,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 1,
"literals": [
"solidity",
"0.5",
".7"
],
"literals": ["solidity", "0.5", ".7"],
"nodeType": "PragmaDirective",
"src": "0:22:0"
},
@ -2406,17 +2375,12 @@
"src": "651:8:0"
}
],
"contractDependencies": [
5731
],
"contractDependencies": [5731],
"contractKind": "contract",
"documentation": "@title DTFactory contract\n@author Ocean Protocol Team\n * @dev Implementation of Ocean DataTokens Factory\n * DTFactory deploys DataToken proxy contracts.\n New DataToken proxy contracts are links to the template contract's bytecode.\n Proxy contract functionality is based on Ocean Protocol custom implementation of ERC1167 standard.",
"fullyImplemented": true,
"id": 158,
"linearizedBaseContracts": [
158,
5731
],
"linearizedBaseContracts": [158, 5731],
"name": "DTFactory",
"nodeType": "ContractDefinition",
"nodes": [
@ -3032,10 +2996,7 @@
"id": 41,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "1528:7:0",
"typeDescriptions": {
@ -3328,10 +3289,7 @@
"id": 78,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2359:7:0",
"typeDescriptions": {
@ -3564,10 +3522,7 @@
"id": 91,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2499:7:0",
"typeDescriptions": {
@ -3594,9 +3549,7 @@
"src": "2499:124:0"
},
{
"assignments": [
101
],
"assignments": [101],
"declarations": [
{
"constant": false,
@ -3883,10 +3836,7 @@
"id": 106,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6555,
6556
],
"overloadedDeclarations": [6555, 6556],
"referencedDeclaration": 6556,
"src": "2695:7:0",
"typeDescriptions": {
@ -4574,4 +4524,4 @@
"userdoc": {
"methods": {}
}
}
}

File diff suppressed because it is too large Load Diff

7027
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -2,24 +2,62 @@
"name": "ocean-subgraph",
"version": "0.1.0",
"scripts": {
"start": "",
"create": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
"create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"deploy": "graph deploy oceanprotocol/ocean-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"deploy:beta": "graph deploy oceanprotocol/ocean-subgraph-beta --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
"deploy:local": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020"
"deploy:local": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"test": "npm run lint && npm run type-check",
"lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .",
"format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json,yaml}' --write",
"type-check": "tsc --noEmit",
"release": "release-it --non-interactive",
"changelog": "auto-changelog -p"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.18.0",
"@graphprotocol/graph-ts": "^0.18.1"
"@graphprotocol/graph-cli": "^0.19.0",
"@graphprotocol/graph-ts": "^0.19.0",
"@release-it/bumper": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"auto-changelog": "^2.2.1",
"eslint": "^7.15.0",
"eslint-config-oceanprotocol": "^1.5.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^3.2.0",
"prettier": "^2.2.1",
"release-it": "^14.2.2",
"typescript": "^4.1.2"
},
"dependencies": {
"babel-polyfill": "^6.26.0",
"babel-register": "^6.26.0",
"keytar": "^5.0.0",
"truffle": "^5.1.0",
"truffle-contract": "^4.0.5",
"truffle-hdwallet-provider": "^1.0.4"
"dependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/oceanprotocol/ocean-subgraph.git"
},
"license": "Apache-2.0",
"release-it": {
"hooks": {
"after:bump": "npm run changelog"
},
"plugins": {
"@release-it/bumper": {
"out": [
"package.json",
"package-lock.json"
]
}
},
"git": {
"tagName": "v${version}"
},
"github": {
"release": true
},
"npm": {
"publish": false
}
}
}

@ -4,7 +4,8 @@ import {
Bytes,
dataSource,
Address,
ethereum
ethereum,
log
} from '@graphprotocol/graph-ts'
import {
@ -19,72 +20,104 @@ import {
TokenTransaction,
PoolTransactionTokenValues
} from '../types/schema'
import { log } from '@graphprotocol/graph-ts'
import { Pool } from '../types/templates/Pool/Pool'
export let ZERO_BD = BigDecimal.fromString('0.0')
export let MINUS_1_BD = BigDecimal.fromString('-1.0')
export let ONE_BD = BigDecimal.fromString('1.0')
export const ZERO_BD = BigDecimal.fromString('0.0')
export const MINUS_1_BD = BigDecimal.fromString('-1.0')
export const ONE_BD = BigDecimal.fromString('1.0')
export let ONE_BASE_18 = BigInt.fromI32(10).pow(18 as u8)
export let BONE = BigDecimal.fromString('1000000000000000000')
export const ONE_BASE_18 = BigInt.fromI32(10).pow(18 as u8)
export const BONE = BigDecimal.fromString('1000000000000000000')
export let ENABLE_DEBUG = false
export const ENABLE_DEBUG = false
let network = dataSource.network()
const network = dataSource.network()
export let OCEAN: string = (network == 'mainnet')
? '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07'
export const OCEAN: string =
network === 'mainnet'
? '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07'
export function _debuglog(message: string, event: ethereum.Event, args: Array<string>): void {
export function _debuglog(
message: string,
event: ethereum.Event,
args: Array<string>
): void {
if (event != null) {
args.push(event.transaction.hash.toHex())
args.push(event.address.toHex())
}
for (let i=0; i < args.length; i++) {
for (let i = 0; i < args.length; i++) {
message = message.concat(' {}')
}
log.info('@@@@@@ ' + message, args)
}
export function debuglog(message: string, event: ethereum.Event, args: Array<string>): void {
export function debuglog(
message: string,
event: ethereum.Event,
args: Array<string>
): void {
if (!ENABLE_DEBUG) return
_debuglog(message, event, args)
}
export function hexToDecimal(hexString: String, decimals: i32): BigDecimal {
let bytes = Bytes.fromHexString(hexString.toString()).reverse() as Bytes
let bi = BigInt.fromUnsignedBytes(bytes)
let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal()
export function hexToDecimal(hexString: string, decimals: i32): BigDecimal {
const bytes = Bytes.fromHexString(hexString.toString()).reverse() as Bytes
const bi = BigInt.fromUnsignedBytes(bytes)
const scale = BigInt.fromI32(10)
.pow(decimals as u8)
.toBigDecimal()
return bi.divDecimal(scale)
}
export function bigIntToDecimal(amount: BigInt, decimals: i32): BigDecimal {
let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal()
const scale = BigInt.fromI32(10)
.pow(decimals as u8)
.toBigDecimal()
return amount.toBigDecimal().div(scale)
}
export function tokenToDecimal(amount: BigDecimal, decimals: i32): BigDecimal {
let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal()
const scale = BigInt.fromI32(10)
.pow(decimals as u8)
.toBigDecimal()
return amount.div(scale)
}
export function decimalToBigInt(value: BigDecimal): BigInt {
value.truncate(18)
let scale = BigInt.fromI32(10).pow((value.exp.toI32() + 18) as u8)
const scale = BigInt.fromI32(10).pow((value.exp.toI32() + 18) as u8)
return value.digits.times(scale)
}
export function updatePoolTokenBalance(poolToken: PoolToken, balance: BigDecimal, source: string): void {
debuglog('########## updating poolToken balance (source, oldBalance, newBalance, poolId) ', null,
[source, poolToken.balance.toString(), balance.toString(), poolToken.poolId])
export function updatePoolTokenBalance(
poolToken: PoolToken,
balance: BigDecimal,
source: string
): void {
debuglog(
'########## updating poolToken balance (source, oldBalance, newBalance, poolId) ',
null,
[source, poolToken.balance.toString(), balance.toString(), poolToken.poolId]
)
poolToken.balance = balance
}
export function createPoolShareEntity(id: string, pool: string, user: string): void {
let poolShare = new PoolShare(id)
export function createUserEntity(address: string): void {
if (User.load(address) == null) {
const user = new User(address)
user.save()
}
}
export function createPoolShareEntity(
id: string,
pool: string,
user: string
): void {
const poolShare = new PoolShare(id)
createUserEntity(user)
@ -94,12 +127,16 @@ export function createPoolShareEntity(id: string, pool: string, user: string): v
poolShare.save()
}
export function createPoolTokenEntity(id: string, pool: string, address: string): void {
let datatoken = Datatoken.load(address)
export function createPoolTokenEntity(
id: string,
pool: string,
address: string
): void {
const datatoken = Datatoken.load(address)
let poolToken = new PoolToken(id)
const poolToken = new PoolToken(id)
poolToken.poolId = pool
poolToken.tokenId = datatoken ? datatoken.id: ''
poolToken.tokenId = datatoken ? datatoken.id : ''
poolToken.tokenAddress = address
poolToken.balance = ZERO_BD
poolToken.denormWeight = ZERO_BD
@ -107,14 +144,16 @@ export function createPoolTokenEntity(id: string, pool: string, address: string)
}
export function updatePoolTransactionToken(
poolTx: string, poolTokenId: string, amount: BigDecimal,
balance: BigDecimal, feeValue: BigDecimal
poolTx: string,
poolTokenId: string,
amount: BigDecimal,
balance: BigDecimal,
feeValue: BigDecimal
): void {
let ptx = PoolTransaction.load(poolTx)
let poolToken = PoolToken.load(poolTokenId)
let pool = PoolEntity.load(poolToken.poolId)
let ptxTokenValuesId = poolTx.concat('-').concat(poolToken.tokenAddress)
const ptx = PoolTransaction.load(poolTx)
const poolToken = PoolToken.load(poolTokenId)
const pool = PoolEntity.load(poolToken.poolId)
const ptxTokenValuesId = poolTx.concat('-').concat(poolToken.tokenAddress)
let ptxTokenValues = PoolTransactionTokenValues.load(ptxTokenValuesId)
if (ptxTokenValues == null) {
ptxTokenValues = new PoolTransactionTokenValues(ptxTokenValuesId)
@ -136,34 +175,74 @@ export function updatePoolTransactionToken(
ptxTokenValues.save()
if (ptxTokenValues.tokenAddress == OCEAN) {
if (ptxTokenValues.tokenAddress === OCEAN) {
ptx.oceanReserve = ptxTokenValues.tokenReserve
pool.oceanReserve = ptxTokenValues.tokenReserve
} else {
ptx.datatokenReserve = ptxTokenValues.tokenReserve
pool.datatokenReserve = ptxTokenValues.tokenReserve
}
debuglog('########## updatePoolTransactionToken: ', null,
[
BigInt.fromI32(ptx.block).toString(),
BigInt.fromI32(ptx.timestamp).toString(),
ptxTokenValues.type,
ptxTokenValues.value.toString(),
ptxTokenValues.tokenReserve.toString(),
poolToken.poolId,
])
debuglog('########## updatePoolTransactionToken: ', null, [
BigInt.fromI32(ptx.block).toString(),
BigInt.fromI32(ptx.timestamp).toString(),
ptxTokenValues.type,
ptxTokenValues.value.toString(),