project setup fixes
This commit is contained in:
parent
61238ab624
commit
0a68cb4b49
|
@ -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 +0,0 @@
|
|||
*.sol linguist-language=Solidity
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"tabWidth": 2
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
language: node_js
|
||||
node_js: node
|
||||
|
||||
script:
|
||||
# will run `npm ci` automatically here
|
||||
- npm test
|
||||
|
||||
notifications:
|
||||
email: false
|
120
README.md
120
README.md
|
@ -1,15 +1,30 @@
|
|||
# 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)
|
||||
|
||||
- [🦑 Development](#-development)
|
||||
- [✨ Code Style](#-code-style)
|
||||
- [⬆️ Releases](#️-releases)
|
||||
- [🛳 Production](#-production)
|
||||
- [⬆️ Deployment](#️-deployment)
|
||||
- [🏛 License](#-license)
|
||||
|
||||
## 🦑 Development
|
||||
|
||||
* Install Graph CLI globally with npm
|
||||
```bash
|
||||
npm install -g @graphprotocol/graph-cli
|
||||
npm i
|
||||
npm start
|
||||
```
|
||||
|
||||
* 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
|
||||
|
@ -20,27 +35,29 @@ 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.
|
||||
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| {`
|
||||
`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
|
||||
|
@ -51,11 +68,64 @@ 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
|
||||
- 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
|
||||
```
|
||||
|
||||
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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
3050
abis/BPool.json
3050
abis/BPool.json
File diff suppressed because it is too large
Load Diff
152
abis/BToken.json
152
abis/BToken.json
|
@ -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
File diff suppressed because it is too large
Load Diff
58
package.json
58
package.json
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
|
||||
import { BigInt, BigDecimal } from '@graphprotocol/graph-ts'
|
||||
import { OrderStarted, Transfer } from '../types/templates/DataToken/DataToken'
|
||||
import { log } from '@graphprotocol/graph-ts'
|
||||
|
||||
import {
|
||||
Datatoken, TokenBalance, TokenOrder
|
||||
} from '../types/schema'
|
||||
import { Datatoken, TokenBalance, TokenOrder } from '../types/schema'
|
||||
import {
|
||||
tokenToDecimal,
|
||||
updateTokenBalance,
|
||||
|
@ -23,7 +20,6 @@ export function handleTransfer(event: Transfer): void {
|
|||
|
||||
let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||
|
||||
|
||||
let amount = tokenToDecimal(event.params.value.toBigDecimal(), 18)
|
||||
let tokenShareFrom = event.params.from.toHex()
|
||||
let tokenShareTo = event.params.to.toHex()
|
||||
|
@ -41,40 +37,50 @@ export function handleTransfer(event: Transfer): void {
|
|||
|
||||
if (isMint) {
|
||||
tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
||||
oldBalanceTo = (tokenBalanceTo == null) ? ZERO_BD : tokenBalanceTo.balance
|
||||
oldBalanceTo = tokenBalanceTo == null ? ZERO_BD : tokenBalanceTo.balance
|
||||
datatoken.supply = datatoken.supply.plus(amount)
|
||||
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
|
||||
|
||||
} else if (isBurn) {
|
||||
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
||||
oldBalanceFrom = (tokenBalanceFrom == null) ? ZERO_BD : tokenBalanceFrom.balance
|
||||
oldBalanceFrom =
|
||||
tokenBalanceFrom == null ? ZERO_BD : tokenBalanceFrom.balance
|
||||
datatoken.supply = datatoken.supply.minus(amount)
|
||||
updateTokenBalance(tokenBalanceFromId, tokenId, tokenShareFrom, amount.times(MINUS_1_BD))
|
||||
updateTokenBalance(
|
||||
tokenBalanceFromId,
|
||||
tokenId,
|
||||
tokenShareFrom,
|
||||
amount.times(MINUS_1_BD)
|
||||
)
|
||||
} else {
|
||||
|
||||
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
||||
oldBalanceFrom = (tokenBalanceFrom == null) ? ZERO_BD : tokenBalanceFrom.balance
|
||||
oldBalanceFrom =
|
||||
tokenBalanceFrom == null ? ZERO_BD : tokenBalanceFrom.balance
|
||||
datatoken.supply = datatoken.supply.minus(amount)
|
||||
updateTokenBalance(tokenBalanceFromId, tokenId, tokenShareFrom, amount.times(MINUS_1_BD))
|
||||
updateTokenBalance(
|
||||
tokenBalanceFromId,
|
||||
tokenId,
|
||||
tokenShareFrom,
|
||||
amount.times(MINUS_1_BD)
|
||||
)
|
||||
|
||||
tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
||||
oldBalanceTo = (tokenBalanceTo == null) ? ZERO_BD : tokenBalanceTo.balance
|
||||
oldBalanceTo = tokenBalanceTo == null ? ZERO_BD : tokenBalanceTo.balance
|
||||
datatoken.supply = datatoken.supply.plus(amount)
|
||||
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
|
||||
}
|
||||
|
||||
if (
|
||||
tokenBalanceTo !== null
|
||||
&& tokenBalanceTo.balance.notEqual(ZERO_BD)
|
||||
&& oldBalanceTo.equals(ZERO_BD)
|
||||
tokenBalanceTo !== null &&
|
||||
tokenBalanceTo.balance.notEqual(ZERO_BD) &&
|
||||
oldBalanceTo.equals(ZERO_BD)
|
||||
) {
|
||||
datatoken.holderCount += BigInt.fromI32(1)
|
||||
}
|
||||
|
||||
if (
|
||||
tokenBalanceFrom !== null
|
||||
&& tokenBalanceFrom.balance.equals(ZERO_BD)
|
||||
&& oldBalanceFrom.notEqual(ZERO_BD)
|
||||
tokenBalanceFrom !== null &&
|
||||
tokenBalanceFrom.balance.equals(ZERO_BD) &&
|
||||
oldBalanceFrom.notEqual(ZERO_BD)
|
||||
) {
|
||||
datatoken.holderCount -= BigInt.fromI32(1)
|
||||
}
|
||||
|
@ -93,10 +99,14 @@ export function handleOrderStarted(event: OrderStarted): void {
|
|||
// let feeCollector = event.params.mrktFeeCollector
|
||||
// let marketFee = event.params.marketFee
|
||||
let tx = event.transaction.hash
|
||||
let orderId = tokenId.concat('-').concat(payer).concat('-').concat(tx.toHexString())
|
||||
let orderId = tokenId
|
||||
.concat('-')
|
||||
.concat(payer)
|
||||
.concat('-')
|
||||
.concat(tx.toHexString())
|
||||
let order = TokenOrder.load(orderId)
|
||||
if (order == null) {
|
||||
order = new TokenOrder(orderId)
|
||||
order = new TokenOrder(orderId)
|
||||
}
|
||||
order.datatokenId = tokenId
|
||||
order.amount = tokenToDecimal(event.params.amount.toBigDecimal(), 18)
|
||||
|
@ -104,8 +114,11 @@ export function handleOrderStarted(event: OrderStarted): void {
|
|||
order.payer = payer
|
||||
order.serviceId = event.params.serviceId.toI32()
|
||||
order.timestamp = event.params.timestamp.toI32()
|
||||
if (event.params.mrktFeeCollector != null && event.params.mrktFeeCollector.toHex() != ZERO_ADDRESS) {
|
||||
order.marketFeeCollector = event.params.mrktFeeCollector.toHexString()
|
||||
if (
|
||||
event.params.mrktFeeCollector != null &&
|
||||
event.params.mrktFeeCollector.toHex() != ZERO_ADDRESS
|
||||
) {
|
||||
order.marketFeeCollector = event.params.mrktFeeCollector.toHexString()
|
||||
}
|
||||
order.marketFee = tokenToDecimal(event.params.marketFee.toBigDecimal(), 18)
|
||||
order.tx = tx
|
||||
|
|
|
@ -3,11 +3,7 @@ import { TokenRegistered } from '../types/DTFactory/DTFactory'
|
|||
import { DatatokenFactory, Datatoken as DatatokenEntity } from '../types/schema'
|
||||
import { DataToken as DatatokenDataSource } from '../types/templates'
|
||||
|
||||
import {
|
||||
createUserEntity,
|
||||
tokenToDecimal,
|
||||
ZERO_BD,
|
||||
} from './helpers'
|
||||
import { createUserEntity, tokenToDecimal, ZERO_BD } from './helpers'
|
||||
import { log } from '@graphprotocol/graph-ts'
|
||||
|
||||
export function handleNewToken(event: TokenRegistered): void {
|
||||
|
@ -20,7 +16,9 @@ export function handleNewToken(event: TokenRegistered): void {
|
|||
}
|
||||
|
||||
let datatoken = new DatatokenEntity(event.params.tokenAddress.toHexString())
|
||||
log.error('************************ handleNewToken: datatokenId {}', [datatoken.id.toString()])
|
||||
log.error('************************ handleNewToken: datatokenId {}', [
|
||||
datatoken.id.toString()
|
||||
])
|
||||
|
||||
datatoken.factoryID = event.address.toHexString()
|
||||
|
||||
|
@ -46,4 +44,4 @@ export function handleNewToken(event: TokenRegistered): void {
|
|||
factory.save()
|
||||
|
||||
DatatokenDataSource.create(event.params.tokenAddress)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ export function handleNewPool(event: BPoolRegistered): void {
|
|||
}
|
||||
|
||||
let pool = new Pool(event.params.bpoolAddress.toHexString())
|
||||
log.info('************************ handleNewPool: poolId {}', [pool.id.toString()])
|
||||
log.info('************************ handleNewPool: poolId {}', [
|
||||
pool.id.toString()
|
||||
])
|
||||
|
||||
pool.factoryID = event.address.toHexString()
|
||||
pool.controller = event.params.registeredBy
|
||||
|
@ -59,4 +61,4 @@ export function handleNewPool(event: BPoolRegistered): void {
|
|||
factory.save()
|
||||
|
||||
PoolContract.create(event.params.bpoolAddress)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,22 +33,31 @@ export let ENABLE_DEBUG = false
|
|||
|
||||
let network = dataSource.network()
|
||||
|
||||
export let OCEAN: string = (network == 'mainnet')
|
||||
? '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
||||
: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07'
|
||||
export let 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)
|
||||
}
|
||||
|
@ -56,17 +65,23 @@ export function debuglog(message: string, event: ethereum.Event, args: Array<str
|
|||
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()
|
||||
let 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()
|
||||
let 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()
|
||||
let scale = BigInt.fromI32(10)
|
||||
.pow(decimals as u8)
|
||||
.toBigDecimal()
|
||||
return amount.div(scale)
|
||||
}
|
||||
|
||||
|
@ -74,16 +89,26 @@ export function decimalToBigInt(value: BigDecimal): BigInt {
|
|||
value.truncate(18)
|
||||
let 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 {
|
||||
export function createPoolShareEntity(
|
||||
id: string,
|
||||
pool: string,
|
||||
user: string
|
||||
): void {
|
||||
let poolShare = new PoolShare(id)
|
||||
|
||||
createUserEntity(user)
|
||||
|
@ -94,12 +119,16 @@ export function createPoolShareEntity(id: string, pool: string, user: string): v
|
|||
poolShare.save()
|
||||
}
|
||||
|
||||
export function createPoolTokenEntity(id: string, pool: string, address: string): void {
|
||||
export function createPoolTokenEntity(
|
||||
id: string,
|
||||
pool: string,
|
||||
address: string
|
||||
): void {
|
||||
let datatoken = Datatoken.load(address)
|
||||
|
||||
let 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,10 +136,12 @@ 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)
|
||||
|
@ -143,21 +174,24 @@ export function updatePoolTransactionToken(
|
|||
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(),
|
||||
ptxTokenValues.tokenReserve.toString(),
|
||||
poolToken.poolId
|
||||
])
|
||||
|
||||
ptx.save()
|
||||
pool.save()
|
||||
}
|
||||
|
||||
export function createPoolTransaction(event: ethereum.Event, event_type: string, userAddress: string): void {
|
||||
export function createPoolTransaction(
|
||||
event: ethereum.Event,
|
||||
event_type: string,
|
||||
userAddress: string
|
||||
): void {
|
||||
let poolId = event.address.toHex()
|
||||
let pool = PoolEntity.load(poolId)
|
||||
let ptx = event.transaction.hash.toHexString()
|
||||
|
@ -191,12 +225,16 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
|||
|
||||
let p = Pool.bind(Address.fromString(poolId))
|
||||
let priceResult = p.try_calcInGivenOut(
|
||||
decimalToBigInt(ocnToken.balance), decimalToBigInt(ocnToken.denormWeight),
|
||||
decimalToBigInt(dtToken.balance), decimalToBigInt(dtToken.denormWeight),
|
||||
ONE_BASE_18, decimalToBigInt(pool.swapFee)
|
||||
decimalToBigInt(ocnToken.balance),
|
||||
decimalToBigInt(ocnToken.denormWeight),
|
||||
decimalToBigInt(dtToken.balance),
|
||||
decimalToBigInt(dtToken.denormWeight),
|
||||
ONE_BASE_18,
|
||||
decimalToBigInt(pool.swapFee)
|
||||
)
|
||||
debuglog(
|
||||
'args to calcInGivenOut (ocnBalance, ocnWeight, dtBalance, dtWeight, dtAmount, swapFee, result)', null,
|
||||
'args to calcInGivenOut (ocnBalance, ocnWeight, dtBalance, dtWeight, dtAmount, swapFee, result)',
|
||||
null,
|
||||
[
|
||||
decimalToBigInt(ocnToken.balance).toString(),
|
||||
decimalToBigInt(ocnToken.denormWeight).toString(),
|
||||
|
@ -207,10 +245,14 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
|||
priceResult.reverted ? 'failed' : priceResult.value.toString()
|
||||
]
|
||||
)
|
||||
poolTx.consumePrice = priceResult.reverted ? MINUS_1_BD : bigIntToDecimal(priceResult.value, 18)
|
||||
poolTx.consumePrice = priceResult.reverted
|
||||
? MINUS_1_BD
|
||||
: bigIntToDecimal(priceResult.value, 18)
|
||||
poolTx.spotPrice = calcSpotPrice(
|
||||
ocnToken.balance, ocnToken.denormWeight,
|
||||
dtToken.balance, dtToken.denormWeight,
|
||||
ocnToken.balance,
|
||||
ocnToken.denormWeight,
|
||||
dtToken.balance,
|
||||
dtToken.denormWeight,
|
||||
pool.swapFee
|
||||
)
|
||||
|
||||
|
@ -221,10 +263,17 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
|||
|
||||
pool.save()
|
||||
|
||||
debuglog('updated pool reserves (source, dtBalance, ocnBalance, dtReserve, ocnReserve): ',
|
||||
debuglog(
|
||||
'updated pool reserves (source, dtBalance, ocnBalance, dtReserve, ocnReserve): ',
|
||||
event,
|
||||
['createPoolTransaction', dtToken.balance.toString(), ocnToken.balance.toString(),
|
||||
pool.datatokenReserve.toString(), pool.oceanReserve.toString()])
|
||||
[
|
||||
'createPoolTransaction',
|
||||
dtToken.balance.toString(),
|
||||
ocnToken.balance.toString(),
|
||||
pool.datatokenReserve.toString(),
|
||||
pool.oceanReserve.toString()
|
||||
]
|
||||
)
|
||||
|
||||
poolTx.tx = event.transaction.hash
|
||||
poolTx.event = event_type
|
||||
|
@ -233,27 +282,30 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
|||
poolTx.gasUsed = event.transaction.gasUsed.toBigDecimal()
|
||||
poolTx.gasPrice = event.transaction.gasPrice.toBigDecimal()
|
||||
|
||||
|
||||
debuglog('####################### poolTransaction: ', event,
|
||||
[
|
||||
BigInt.fromI32(poolTx.block).toString(),
|
||||
BigInt.fromI32(poolTx.timestamp).toString(),
|
||||
pool.oceanReserve.toString()
|
||||
])
|
||||
debuglog('####################### poolTransaction: ', event, [
|
||||
BigInt.fromI32(poolTx.block).toString(),
|
||||
BigInt.fromI32(poolTx.timestamp).toString(),
|
||||
pool.oceanReserve.toString()
|
||||
])
|
||||
|
||||
poolTx.save()
|
||||
}
|
||||
|
||||
export function calcSpotPrice(
|
||||
balanceIn: BigDecimal, wIn: BigDecimal,
|
||||
balanceOut: BigDecimal, wOut: BigDecimal,
|
||||
balanceIn: BigDecimal,
|
||||
wIn: BigDecimal,
|
||||
balanceOut: BigDecimal,
|
||||
wOut: BigDecimal,
|
||||
swapFee: BigDecimal
|
||||
): BigDecimal {
|
||||
if (balanceIn <= ZERO_BD || balanceOut <= ZERO_BD) return MINUS_1_BD
|
||||
debuglog('################ calcSpotPrice', null,
|
||||
[balanceIn.toString(), wIn.toString(),
|
||||
balanceOut.toString(), wOut.toString(),
|
||||
swapFee.toString()])
|
||||
debuglog('################ calcSpotPrice', null, [
|
||||
balanceIn.toString(),
|
||||
wIn.toString(),
|
||||
balanceOut.toString(),
|
||||
wOut.toString(),
|
||||
swapFee.toString()
|
||||
])
|
||||
|
||||
let numer = balanceIn.div(wIn)
|
||||
let denom = balanceOut.div(wOut)
|
||||
|
@ -263,8 +315,13 @@ export function calcSpotPrice(
|
|||
let scale = ONE_BD.div(ONE_BD.minus(swapFee))
|
||||
let price = ratio.times(scale)
|
||||
price.truncate(18)
|
||||
debuglog('################ calcSpotPrice values:', null,
|
||||
[numer.toString(), denom.toString(), ratio.toString(), scale.toString(), price.toString()])
|
||||
debuglog('################ calcSpotPrice values:', null, [
|
||||
numer.toString(),
|
||||
denom.toString(),
|
||||
ratio.toString(),
|
||||
scale.toString(),
|
||||
price.toString()
|
||||
])
|
||||
return price
|
||||
}
|
||||
|
||||
|
@ -275,8 +332,14 @@ export function decrPoolCount(finalized: boolean): void {
|
|||
factory.save()
|
||||
}
|
||||
|
||||
export function saveTokenTransaction(event: ethereum.Event, eventName: string): void {
|
||||
let tx = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
|
||||
export function saveTokenTransaction(
|
||||
event: ethereum.Event,
|
||||
eventName: string
|
||||
): void {
|
||||
let tx = event.transaction.hash
|
||||
.toHexString()
|
||||
.concat('-')
|
||||
.concat(event.logIndex.toString())
|
||||
let userAddress = event.transaction.from.toHex()
|
||||
let transaction = TokenTransaction.load(tx)
|
||||
if (transaction == null) {
|
||||
|
@ -302,7 +365,12 @@ export function createUserEntity(address: string): void {
|
|||
}
|
||||
}
|
||||
|
||||
export function updateTokenBalance(id: string, token: string, user: string, amount: BigDecimal): void {
|
||||
export function updateTokenBalance(
|
||||
id: string,
|
||||
token: string,
|
||||
user: string,
|
||||
amount: BigDecimal
|
||||
): void {
|
||||
let tokenBalance = TokenBalance.load(id)
|
||||
if (tokenBalance == null) {
|
||||
tokenBalance = new TokenBalance(id)
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
|
||||
import {BigInt, Address, BigDecimal} from '@graphprotocol/graph-ts'
|
||||
import { LOG_CALL, LOG_JOIN, LOG_EXIT, LOG_SWAP, Transfer } from '../types/templates/Pool/Pool'
|
||||
import { BigInt, Address, BigDecimal } from '@graphprotocol/graph-ts'
|
||||
import {
|
||||
LOG_CALL,
|
||||
LOG_JOIN,
|
||||
LOG_EXIT,
|
||||
LOG_SWAP,
|
||||
Transfer
|
||||
} from '../types/templates/Pool/Pool'
|
||||
import { log } from '@graphprotocol/graph-ts'
|
||||
|
||||
import {
|
||||
|
@ -22,14 +27,18 @@ import {
|
|||
updatePoolTransactionToken,
|
||||
createPoolTransaction,
|
||||
OCEAN,
|
||||
debuglog, updatePoolTokenBalance
|
||||
debuglog,
|
||||
updatePoolTokenBalance
|
||||
} from './helpers'
|
||||
|
||||
/************************************
|
||||
********** Pool Controls ***********
|
||||
************************************/
|
||||
|
||||
export function handleSetSwapFee(event: LOG_CALL, swapFeeStr: string=null): void {
|
||||
export function handleSetSwapFee(
|
||||
event: LOG_CALL,
|
||||
swapFeeStr: string = null
|
||||
): void {
|
||||
let poolId = event.address.toHex()
|
||||
let pool = Pool.load(poolId)
|
||||
if (!swapFeeStr) {
|
||||
|
@ -42,7 +51,9 @@ export function handleSetSwapFee(event: LOG_CALL, swapFeeStr: string=null): void
|
|||
export function handleSetController(event: LOG_CALL): void {
|
||||
let poolId = event.address.toHex()
|
||||
let pool = Pool.load(poolId)
|
||||
pool.controller = Address.fromString(event.params.data.toHexString().slice(-40))
|
||||
pool.controller = Address.fromString(
|
||||
event.params.data.toHexString().slice(-40)
|
||||
)
|
||||
pool.save()
|
||||
}
|
||||
|
||||
|
@ -78,21 +89,35 @@ export function handleSetup(event: LOG_CALL): void {
|
|||
// For numbers we donot need to remove the leading zeros because they have no effect being on the left of the number
|
||||
|
||||
// skip 8 then take the last 40 (2 + 8 + 24 = 34) to (2 + 8 + 64 = 74)
|
||||
let dataTokenAddress = Address.fromString(data.slice(34,74)).toHexString()
|
||||
let dataTokenAddress = Address.fromString(data.slice(34, 74)).toHexString()
|
||||
|
||||
let dataTokenAmount = data.slice(74, 138) // 74+64
|
||||
let dataTokenWeight = data.slice(138,202) // (74+64,74+(2*64)
|
||||
let baseTokenAddress = Address.fromString(data.slice(202+24, 266)).toHexString() // (74+(2*64)+24, 74+(3*64))
|
||||
let baseTokenAmount = data.slice(266,330) // (74+(3*64),74+(4*64))
|
||||
let baseTokenWeight = data.slice(330,394) // (74+(4*64),74+(5*64))
|
||||
let dataTokenWeight = data.slice(138, 202) // (74+64,74+(2*64)
|
||||
let baseTokenAddress = Address.fromString(
|
||||
data.slice(202 + 24, 266)
|
||||
).toHexString() // (74+(2*64)+24, 74+(3*64))
|
||||
let baseTokenAmount = data.slice(266, 330) // (74+(3*64),74+(4*64))
|
||||
let baseTokenWeight = data.slice(330, 394) // (74+(4*64),74+(5*64))
|
||||
let swapFee = data.slice(394) // (74+(5*64), END)
|
||||
|
||||
let poolTokenId = poolId.concat('-').concat(baseTokenAddress)
|
||||
let poolToken = PoolToken.load(poolTokenId)
|
||||
if (poolToken != null) return
|
||||
|
||||
_handleRebind(event, poolId, dataTokenAddress, dataTokenAmount, dataTokenWeight)
|
||||
_handleRebind(event, poolId, baseTokenAddress, baseTokenAmount, baseTokenWeight)
|
||||
_handleRebind(
|
||||
event,
|
||||
poolId,
|
||||
dataTokenAddress,
|
||||
dataTokenAmount,
|
||||
dataTokenWeight
|
||||
)
|
||||
_handleRebind(
|
||||
event,
|
||||
poolId,
|
||||
baseTokenAddress,
|
||||
baseTokenAmount,
|
||||
baseTokenWeight
|
||||
)
|
||||
handleSetSwapFee(event, swapFee)
|
||||
handleFinalize(event)
|
||||
createPoolTransaction(event, 'setup', event.transaction.from.toHex())
|
||||
|
@ -101,24 +126,34 @@ export function handleSetup(event: LOG_CALL): void {
|
|||
let amount = hexToDecimal(baseTokenAmount, 18)
|
||||
|
||||
updatePoolTransactionToken(
|
||||
event.transaction.hash.toHexString(), poolTokenId,
|
||||
amount, PoolToken.load(poolTokenId).balance,
|
||||
event.transaction.hash.toHexString(),
|
||||
poolTokenId,
|
||||
amount,
|
||||
PoolToken.load(poolTokenId).balance,
|
||||
ZERO_BD
|
||||
)
|
||||
// update the datatoken
|
||||
amount = hexToDecimal(dataTokenAmount, 18)
|
||||
updatePoolTransactionToken(
|
||||
event.transaction.hash.toHexString(), poolId.concat('-').concat(dataTokenAddress),
|
||||
amount, PoolToken.load(poolId.concat('-').concat(dataTokenAddress)).balance,
|
||||
event.transaction.hash.toHexString(),
|
||||
poolId.concat('-').concat(dataTokenAddress),
|
||||
amount,
|
||||
PoolToken.load(poolId.concat('-').concat(dataTokenAddress)).balance,
|
||||
ZERO_BD
|
||||
)
|
||||
}
|
||||
|
||||
export function _handleRebind(event: LOG_CALL, poolId: string, tokenAddress: string, balanceStr: string, denormWeightStr: string): void {
|
||||
export function _handleRebind(
|
||||
event: LOG_CALL,
|
||||
poolId: string,
|
||||
tokenAddress: string,
|
||||
balanceStr: string,
|
||||
denormWeightStr: string
|
||||
): void {
|
||||
let pool = Pool.load(poolId)
|
||||
let decimals = BigInt.fromI32(18).toI32()
|
||||
|
||||
if (tokenAddress != OCEAN ) {
|
||||
if (tokenAddress != OCEAN) {
|
||||
pool.datatokenAddress = tokenAddress
|
||||
}
|
||||
pool.tokenCount += BigInt.fromI32(1)
|
||||
|
@ -154,11 +189,11 @@ export function _handleRebind(event: LOG_CALL, poolId: string, tokenAddress: str
|
|||
export function handleRebind(event: LOG_CALL): void {
|
||||
let poolId = event.address.toHex()
|
||||
_handleRebind(
|
||||
event,
|
||||
poolId,
|
||||
event.params.data.toHexString().slice(34,74),
|
||||
event.params.data.toHexString().slice(74,138),
|
||||
event.params.data.toHexString().slice(138)
|
||||
event,
|
||||
poolId,
|
||||
event.params.data.toHexString().slice(34, 74),
|
||||
event.params.data.toHexString().slice(74, 138),
|
||||
event.params.data.toHexString().slice(138)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -170,7 +205,7 @@ export function handleJoinPool(event: LOG_JOIN): void {
|
|||
let poolId = event.address.toHex()
|
||||
|
||||
let pool = Pool.load(poolId)
|
||||
if (pool.finalized == false){
|
||||
if (pool.finalized == false) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -179,7 +214,11 @@ export function handleJoinPool(event: LOG_JOIN): void {
|
|||
let ptx = event.transaction.hash.toHexString()
|
||||
let poolTx = PoolTransaction.load(ptx)
|
||||
if (poolTx != null) {
|
||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! PoolTransaction EXISTS: ', event, [])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! PoolTransaction EXISTS: ',
|
||||
event,
|
||||
[]
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -187,23 +226,41 @@ export function handleJoinPool(event: LOG_JOIN): void {
|
|||
let poolTokenId = poolId.concat('-').concat(address)
|
||||
let poolToken = PoolToken.load(poolTokenId)
|
||||
if (poolToken == null) {
|
||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! NO PoolToken: ', event, [address, poolTokenId])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! NO PoolToken: ',
|
||||
event,
|
||||
[address, poolTokenId]
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
let datatoken: Datatoken | null
|
||||
datatoken = poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||
let decimals = datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||
let tokenAmountIn = tokenToDecimal(event.params.tokenAmountIn.toBigDecimal(), decimals)
|
||||
updatePoolTokenBalance(poolToken as PoolToken, poolToken.balance.plus(tokenAmountIn), 'handleJoinPool')
|
||||
debuglog('!!!!!!!!!!!!!!!!!! JOIN JOIN JOIN : (token, amountIn, amountIn) ', event,
|
||||
[address, tokenAmountIn.toString(), event.params.tokenAmountIn.toString()])
|
||||
datatoken =
|
||||
poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||
let decimals =
|
||||
datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||
let tokenAmountIn = tokenToDecimal(
|
||||
event.params.tokenAmountIn.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
updatePoolTokenBalance(
|
||||
poolToken as PoolToken,
|
||||
poolToken.balance.plus(tokenAmountIn),
|
||||
'handleJoinPool'
|
||||
)
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! JOIN JOIN JOIN : (token, amountIn, amountIn) ',
|
||||
event,
|
||||
[address, tokenAmountIn.toString(), event.params.tokenAmountIn.toString()]
|
||||
)
|
||||
|
||||
poolToken.save()
|
||||
createPoolTransaction(event, 'join', event.params.caller.toHexString())
|
||||
updatePoolTransactionToken(
|
||||
event.transaction.hash.toHexString(), poolTokenId,
|
||||
tokenAmountIn, poolToken.balance,
|
||||
event.transaction.hash.toHexString(),
|
||||
poolTokenId,
|
||||
tokenAmountIn,
|
||||
poolToken.balance,
|
||||
tokenAmountIn.times(pool.swapFee)
|
||||
)
|
||||
}
|
||||
|
@ -215,19 +272,31 @@ export function handleExitPool(event: LOG_EXIT): void {
|
|||
let poolTokenId = poolId.concat('-').concat(address.toString())
|
||||
let poolToken = PoolToken.load(poolTokenId)
|
||||
if (!poolToken) {
|
||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! EXIT EXIT EXIT !!!!!!!!!!!! NO PoolToken: ', event, [address, poolTokenId])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! EXIT EXIT EXIT !!!!!!!!!!!! NO PoolToken: ',
|
||||
event,
|
||||
[address, poolTokenId]
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
let datatoken: Datatoken | null
|
||||
datatoken = poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||
let decimals = datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||
let tokenAmountOut = tokenToDecimal(event.params.tokenAmountOut.toBigDecimal(), decimals)
|
||||
datatoken =
|
||||
poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||
let decimals =
|
||||
datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||
let tokenAmountOut = tokenToDecimal(
|
||||
event.params.tokenAmountOut.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
let newAmount = poolToken.balance.minus(tokenAmountOut)
|
||||
updatePoolTokenBalance(poolToken as PoolToken, newAmount, 'handleExitPool')
|
||||
poolToken.save()
|
||||
debuglog('!!!!!!!!!!!!!!!!!! EXIT EXIT EXIT : (token, amountOut, amountOut)', event,
|
||||
[address, tokenAmountOut.toString(), event.params.tokenAmountOut.toString()])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! EXIT EXIT EXIT : (token, amountOut, amountOut)',
|
||||
event,
|
||||
[address, tokenAmountOut.toString(), event.params.tokenAmountOut.toString()]
|
||||
)
|
||||
let pool = Pool.load(poolId)
|
||||
pool.exitCount = pool.exitCount.plus(BigInt.fromI32(1))
|
||||
if (newAmount.equals(ZERO_BD)) {
|
||||
|
@ -238,8 +307,10 @@ export function handleExitPool(event: LOG_EXIT): void {
|
|||
|
||||
createPoolTransaction(event, 'exit', event.params.caller.toHexString())
|
||||
updatePoolTransactionToken(
|
||||
event.transaction.hash.toHexString(), poolTokenId,
|
||||
tokenAmountOut.times(MINUS_1_BD), poolToken.balance,
|
||||
event.transaction.hash.toHexString(),
|
||||
poolTokenId,
|
||||
tokenAmountOut.times(MINUS_1_BD),
|
||||
poolToken.balance,
|
||||
tokenAmountOut.times(pool.swapFee)
|
||||
)
|
||||
}
|
||||
|
@ -256,27 +327,53 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||
let poolTokenInId = poolId.concat('-').concat(tokenIn.toString())
|
||||
let poolTokenIn = PoolToken.load(poolTokenInId)
|
||||
if (!poolTokenIn) {
|
||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! SWAP SWAP SWAP !!!!!!!!!!!! NO PoolToken: ', event,
|
||||
[tokenIn, poolTokenInId])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! SWAP SWAP SWAP !!!!!!!!!!!! NO PoolToken: ',
|
||||
event,
|
||||
[tokenIn, poolTokenInId]
|
||||
)
|
||||
return
|
||||
}
|
||||
let dtIn = Datatoken.load(tokenIn)
|
||||
let tokenAmountIn = tokenToDecimal(event.params.tokenAmountIn.toBigDecimal(), (dtIn == null) ? 18 : dtIn.decimals)
|
||||
let tokenAmountIn = tokenToDecimal(
|
||||
event.params.tokenAmountIn.toBigDecimal(),
|
||||
dtIn == null ? 18 : dtIn.decimals
|
||||
)
|
||||
let newAmountIn = poolTokenIn.balance.plus(tokenAmountIn)
|
||||
updatePoolTokenBalance(poolTokenIn as PoolToken, newAmountIn, 'handleSwap.tokenIn')
|
||||
updatePoolTokenBalance(
|
||||
poolTokenIn as PoolToken,
|
||||
newAmountIn,
|
||||
'handleSwap.tokenIn'
|
||||
)
|
||||
poolTokenIn.save()
|
||||
|
||||
let tokenOut = event.params.tokenOut.toHex()
|
||||
let poolTokenOutId = poolId.concat('-').concat(tokenOut.toString())
|
||||
let poolTokenOut = PoolToken.load(poolTokenOutId)
|
||||
let dtOut = Datatoken.load(tokenOut)
|
||||
let tokenAmountOut = tokenToDecimal(event.params.tokenAmountOut.toBigDecimal(), (dtOut == null) ? 18 : dtOut.decimals)
|
||||
let tokenAmountOut = tokenToDecimal(
|
||||
event.params.tokenAmountOut.toBigDecimal(),
|
||||
dtOut == null ? 18 : dtOut.decimals
|
||||
)
|
||||
let newAmountOut = poolTokenOut.balance.minus(tokenAmountOut)
|
||||
updatePoolTokenBalance(poolTokenOut as PoolToken, newAmountOut, 'handleSwap.tokenOut')
|
||||
updatePoolTokenBalance(
|
||||
poolTokenOut as PoolToken,
|
||||
newAmountOut,
|
||||
'handleSwap.tokenOut'
|
||||
)
|
||||
poolTokenOut.save()
|
||||
debuglog('!!!!!!!!!!!!!!!!!! SWAP SWAP SWAP : (tokenIn, tokenOut, amountIn, amountIn, amountOut, amountOut)', event,
|
||||
[tokenIn, tokenOut, tokenAmountIn.toString(), event.params.tokenAmountIn.toString(),
|
||||
tokenAmountOut.toString(), event.params.tokenAmountOut.toString()])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! SWAP SWAP SWAP : (tokenIn, tokenOut, amountIn, amountIn, amountOut, amountOut)',
|
||||
event,
|
||||
[
|
||||
tokenIn,
|
||||
tokenOut,
|
||||
tokenAmountIn.toString(),
|
||||
event.params.tokenAmountIn.toString(),
|
||||
tokenAmountOut.toString(),
|
||||
event.params.tokenAmountOut.toString()
|
||||
]
|
||||
)
|
||||
let pool = Pool.load(poolId)
|
||||
|
||||
pool.swapCount = pool.swapCount.plus(BigInt.fromI32(1))
|
||||
|
@ -288,18 +385,26 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||
|
||||
createPoolTransaction(event, 'swap', event.params.caller.toHexString())
|
||||
updatePoolTransactionToken(
|
||||
ptx, poolTokenIn.id, tokenAmountIn, poolTokenIn.balance,
|
||||
tokenAmountIn.times(pool.swapFee))
|
||||
ptx,
|
||||
poolTokenIn.id,
|
||||
tokenAmountIn,
|
||||
poolTokenIn.balance,
|
||||
tokenAmountIn.times(pool.swapFee)
|
||||
)
|
||||
updatePoolTransactionToken(
|
||||
ptx, poolTokenOut.id, tokenAmountOut.times(MINUS_1_BD), poolTokenOut.balance,
|
||||
BigDecimal.fromString('0.0'))
|
||||
ptx,
|
||||
poolTokenOut.id,
|
||||
tokenAmountOut.times(MINUS_1_BD),
|
||||
poolTokenOut.balance,
|
||||
BigDecimal.fromString('0.0')
|
||||
)
|
||||
}
|
||||
|
||||
/************************************
|
||||
*********** POOL SHARES ************
|
||||
************************************/
|
||||
|
||||
export function handleTransfer(event: Transfer): void {
|
||||
export function handleTransfer(event: Transfer): void {
|
||||
let poolId = event.address.toHex()
|
||||
|
||||
let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||
|
@ -309,7 +414,8 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||
|
||||
let poolShareFromId = poolId.concat('-').concat(event.params.from.toHex())
|
||||
let poolShareFrom = PoolShare.load(poolShareFromId)
|
||||
let poolShareFromBalance = poolShareFrom == null ? ZERO_BD : poolShareFrom.balance
|
||||
let poolShareFromBalance =
|
||||
poolShareFrom == null ? ZERO_BD : poolShareFrom.balance
|
||||
|
||||
let poolShareToId = poolId.concat('-').concat(event.params.to.toHex())
|
||||
let poolShareTo = PoolShare.load(poolShareToId)
|
||||
|
@ -343,7 +449,6 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||
poolTx.sharesTransferAmount = -value
|
||||
poolTx.sharesBalance = poolShareFrom.balance
|
||||
}
|
||||
|
||||
} else {
|
||||
if (poolShareTo == null) {
|
||||
createPoolShareEntity(poolShareToId, poolId, event.params.to.toHex())
|
||||
|
@ -361,17 +466,17 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||
}
|
||||
|
||||
if (
|
||||
poolShareTo !== null
|
||||
&& poolShareTo.balance.notEqual(ZERO_BD)
|
||||
&& poolShareToBalance.equals(ZERO_BD)
|
||||
poolShareTo !== null &&
|
||||
poolShareTo.balance.notEqual(ZERO_BD) &&
|
||||
poolShareToBalance.equals(ZERO_BD)
|
||||
) {
|
||||
pool.holderCount += BigInt.fromI32(1)
|
||||
}
|
||||
|
||||
if (
|
||||
poolShareFrom !== null
|
||||
&& poolShareFrom.balance.equals(ZERO_BD)
|
||||
&& poolShareFromBalance.notEqual(ZERO_BD)
|
||||
poolShareFrom !== null &&
|
||||
poolShareFrom.balance.equals(ZERO_BD) &&
|
||||
poolShareFromBalance.notEqual(ZERO_BD)
|
||||
) {
|
||||
pool.holderCount -= BigInt.fromI32(1)
|
||||
}
|
||||
|
@ -381,4 +486,4 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||
}
|
||||
|
||||
pool.save()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ dataSources:
|
|||
name: Factory
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0xbe0083053744ECb871510C88dC0f6b77Da162706"
|
||||
address: '0xbe0083053744ECb871510C88dC0f6b77Da162706'
|
||||
abi: Factory
|
||||
startBlock: 11105585
|
||||
mapping:
|
||||
|
@ -28,7 +28,7 @@ dataSources:
|
|||
name: DTFactory
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0x57317f97E9EA49eBd19f7c9bB7c180b8cDcbDeB9"
|
||||
address: '0x57317f97E9EA49eBd19f7c9bB7c180b8cDcbDeB9'
|
||||
abi: DTFactory
|
||||
startBlock: 11105560
|
||||
mapping:
|
||||
|
@ -66,25 +66,25 @@ templates:
|
|||
file: ./abis/BToken.json
|
||||
eventHandlers:
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x34e1990700000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x34e1990700000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleSetSwapFee
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x92eefe9b00000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x92eefe9b00000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleSetController
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x49b5955200000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x49b5955200000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleSetPublicSwap
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x4bb278f300000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x4bb278f300000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleFinalize
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0xd1d7bc9100000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0xd1d7bc9100000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleSetup
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x3fdddaa200000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x3fdddaa200000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleRebind
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0xe4e1e53800000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0xe4e1e53800000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleRebind
|
||||
- event: LOG_JOIN(indexed address,indexed address,uint256)
|
||||
handler: handleJoinPool
|
||||
|
|
Loading…
Reference in New Issue