mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
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
This commit is contained in:
parent
61238ab624
commit
f649083b3e
21
.eslintrc
Normal file
21
.eslintrc
Normal file
@ -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
.gitattributes
vendored
@ -1 +0,0 @@
|
|||||||
*.sol linguist-language=Solidity
|
|
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"tabWidth": 2
|
||||||
|
}
|
12
.travis.yml
Normal file
12
.travis.yml
Normal file
@ -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
|
179
README.md
179
README.md
@ -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>
|
||||||
|
|
||||||
* Install Graph CLI globally with npm
|
> 🦀 Ocean Protocol Subgraph
|
||||||
```bash
|
|
||||||
npm install -g @graphprotocol/graph-cli
|
[![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
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* Install/run the Graph: `https://thegraph.com/docs/quick-start`
|
**All datatokens**
|
||||||
* You can skip running ganache-cli and connect directly to `mainnet` using Infura
|
|
||||||
|
```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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/graphprotocol/graph-node/
|
git clone https://github.com/graphprotocol/graph-node/
|
||||||
cd graph-node/docker
|
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
|
# Update this line in the `docker-compose.yml` file with your Infura ProjectId
|
||||||
# ethereum: 'mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID'
|
# ethereum: 'mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID'
|
||||||
docker-compose up
|
docker-compose up
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: making contract calls using Infura fails with `missing trie node` errors.
|
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| {`
|
||||||
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.
|
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.
|
then run `docker-compose up` to get the postgresql and ipfs services running.
|
||||||
|
|
||||||
Now you can build and run the graph-node from source
|
Now you can build and run the graph-node from source
|
||||||
|
|
||||||
```
|
```
|
||||||
cargo run -p graph-node --release > graphnode.log --
|
cargo run -p graph-node --release > graphnode.log --
|
||||||
--postgres-url postgres://graph-node:let-me-in@localhost:5432/graph-node
|
--postgres-url postgres://graph-node:let-me-in@localhost:5432/graph-node
|
||||||
--ethereum-rpc mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID
|
--ethereum-rpc mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID
|
||||||
--ipfs 127.0.0.1:5001
|
--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
|
```bash
|
||||||
git clone https://github.com/oceanprotocol/ocean-subgraph/
|
git clone https://github.com/oceanprotocol/ocean-subgraph/
|
||||||
cd ocean-subgraph
|
cd ocean-subgraph
|
||||||
@ -48,14 +117,66 @@ npm i
|
|||||||
npm run codegen
|
npm run codegen
|
||||||
npm run create:local
|
npm run create:local
|
||||||
npm run deploy:local
|
npm run deploy:local
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
* You can edit the event handler code and then run `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
|
- Running deploy will fail if the code has no changes
|
||||||
* Sometimes deploy will fail no matter what, in this case:
|
- Sometimes deploy will fail no matter what, in this case:
|
||||||
* Stop the docker-compose run (`docker-compose down`)
|
- Stop the docker-compose run (`docker-compose down`)
|
||||||
* Delete the `ipfs` and `postgres` folders in `graph-node/docker/data`
|
- Delete the `ipfs` and `postgres` folders in `graph-node/docker/data`
|
||||||
* Restart docker-compose
|
- Restart docker-compose
|
||||||
* Run `npm run create:local` to create the ocean-subgraph
|
- Run `npm run create:local` to create the ocean-subgraph
|
||||||
* Run `npm run deploy:local` to deploy 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": {
|
"ast": {
|
||||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BFactory.sol",
|
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BFactory.sol",
|
||||||
"exportedSymbols": {
|
"exportedSymbols": {
|
||||||
"BFactory": [
|
"BFactory": [376]
|
||||||
376
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"id": 377,
|
"id": 377,
|
||||||
"nodeType": "SourceUnit",
|
"nodeType": "SourceUnit",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"id": 282,
|
"id": 282,
|
||||||
"literals": [
|
"literals": ["solidity", "0.5", ".7"],
|
||||||
"solidity",
|
|
||||||
"0.5",
|
|
||||||
".7"
|
|
||||||
],
|
|
||||||
"nodeType": "PragmaDirective",
|
"nodeType": "PragmaDirective",
|
||||||
"src": "0:22:3"
|
"src": "0:22:3"
|
||||||
},
|
},
|
||||||
@ -410,19 +404,12 @@
|
|||||||
"src": "679:8:3"
|
"src": "679:8:3"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contractDependencies": [
|
"contractDependencies": [280, 5731],
|
||||||
280,
|
|
||||||
5731
|
|
||||||
],
|
|
||||||
"contractKind": "contract",
|
"contractKind": "contract",
|
||||||
"documentation": null,
|
"documentation": null,
|
||||||
"fullyImplemented": true,
|
"fullyImplemented": true,
|
||||||
"id": 376,
|
"id": 376,
|
||||||
"linearizedBaseContracts": [
|
"linearizedBaseContracts": [376, 5731, 280],
|
||||||
376,
|
|
||||||
5731,
|
|
||||||
280
|
|
||||||
],
|
|
||||||
"name": "BFactory",
|
"name": "BFactory",
|
||||||
"nodeType": "ContractDefinition",
|
"nodeType": "ContractDefinition",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
@ -726,10 +713,7 @@
|
|||||||
"id": 308,
|
"id": 308,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "1176:7:3",
|
"src": "1176:7:3",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -1069,10 +1053,7 @@
|
|||||||
"id": 333,
|
"id": 333,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "1637:7:3",
|
"src": "1637:7:3",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -1099,9 +1080,7 @@
|
|||||||
"src": "1637:103:3"
|
"src": "1637:103:3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"assignments": [
|
"assignments": [343],
|
||||||
343
|
|
||||||
],
|
|
||||||
"declarations": [
|
"declarations": [
|
||||||
{
|
{
|
||||||
"constant": false,
|
"constant": false,
|
||||||
@ -1419,10 +1398,7 @@
|
|||||||
"id": 348,
|
"id": 348,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "1795:7:3",
|
"src": "1795:7:3",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -1671,20 +1647,14 @@
|
|||||||
"legacyAST": {
|
"legacyAST": {
|
||||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BFactory.sol",
|
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BFactory.sol",
|
||||||
"exportedSymbols": {
|
"exportedSymbols": {
|
||||||
"BFactory": [
|
"BFactory": [376]
|
||||||
376
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"id": 377,
|
"id": 377,
|
||||||
"nodeType": "SourceUnit",
|
"nodeType": "SourceUnit",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"id": 282,
|
"id": 282,
|
||||||
"literals": [
|
"literals": ["solidity", "0.5", ".7"],
|
||||||
"solidity",
|
|
||||||
"0.5",
|
|
||||||
".7"
|
|
||||||
],
|
|
||||||
"nodeType": "PragmaDirective",
|
"nodeType": "PragmaDirective",
|
||||||
"src": "0:22:3"
|
"src": "0:22:3"
|
||||||
},
|
},
|
||||||
@ -1760,19 +1730,12 @@
|
|||||||
"src": "679:8:3"
|
"src": "679:8:3"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contractDependencies": [
|
"contractDependencies": [280, 5731],
|
||||||
280,
|
|
||||||
5731
|
|
||||||
],
|
|
||||||
"contractKind": "contract",
|
"contractKind": "contract",
|
||||||
"documentation": null,
|
"documentation": null,
|
||||||
"fullyImplemented": true,
|
"fullyImplemented": true,
|
||||||
"id": 376,
|
"id": 376,
|
||||||
"linearizedBaseContracts": [
|
"linearizedBaseContracts": [376, 5731, 280],
|
||||||
376,
|
|
||||||
5731,
|
|
||||||
280
|
|
||||||
],
|
|
||||||
"name": "BFactory",
|
"name": "BFactory",
|
||||||
"nodeType": "ContractDefinition",
|
"nodeType": "ContractDefinition",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
@ -2076,10 +2039,7 @@
|
|||||||
"id": 308,
|
"id": 308,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "1176:7:3",
|
"src": "1176:7:3",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -2419,10 +2379,7 @@
|
|||||||
"id": 333,
|
"id": 333,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "1637:7:3",
|
"src": "1637:7:3",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -2449,9 +2406,7 @@
|
|||||||
"src": "1637:103:3"
|
"src": "1637:103:3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"assignments": [
|
"assignments": [343],
|
||||||
343
|
|
||||||
],
|
|
||||||
"declarations": [
|
"declarations": [
|
||||||
{
|
{
|
||||||
"constant": false,
|
"constant": false,
|
||||||
@ -2769,10 +2724,7 @@
|
|||||||
"id": 348,
|
"id": 348,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "1795:7:3",
|
"src": "1795:7:3",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -3031,4 +2983,4 @@
|
|||||||
"userdoc": {
|
"userdoc": {
|
||||||
"methods": {}
|
"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": {
|
"ast": {
|
||||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BToken.sol",
|
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BToken.sol",
|
||||||
"exportedSymbols": {
|
"exportedSymbols": {
|
||||||
"BToken": [
|
"BToken": [4285],
|
||||||
4285
|
"BTokenBase": [3979]
|
||||||
],
|
|
||||||
"BTokenBase": [
|
|
||||||
3979
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"id": 4286,
|
"id": 4286,
|
||||||
"nodeType": "SourceUnit",
|
"nodeType": "SourceUnit",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"id": 3780,
|
"id": 3780,
|
||||||
"literals": [
|
"literals": ["solidity", "0.5", ".7"],
|
||||||
"solidity",
|
|
||||||
"0.5",
|
|
||||||
".7"
|
|
||||||
],
|
|
||||||
"nodeType": "PragmaDirective",
|
"nodeType": "PragmaDirective",
|
||||||
"src": "643:22:7"
|
"src": "643:22:7"
|
||||||
},
|
},
|
||||||
@ -560,19 +552,12 @@
|
|||||||
"src": "1468:4:7"
|
"src": "1468:4:7"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contractDependencies": [
|
"contractDependencies": [280, 1422],
|
||||||
280,
|
|
||||||
1422
|
|
||||||
],
|
|
||||||
"contractKind": "contract",
|
"contractKind": "contract",
|
||||||
"documentation": null,
|
"documentation": null,
|
||||||
"fullyImplemented": true,
|
"fullyImplemented": true,
|
||||||
"id": 3979,
|
"id": 3979,
|
||||||
"linearizedBaseContracts": [
|
"linearizedBaseContracts": [3979, 1422, 280],
|
||||||
3979,
|
|
||||||
1422,
|
|
||||||
280
|
|
||||||
],
|
|
||||||
"name": "BTokenBase",
|
"name": "BTokenBase",
|
||||||
"nodeType": "ContractDefinition",
|
"nodeType": "ContractDefinition",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
@ -1617,10 +1602,7 @@
|
|||||||
"id": 3855,
|
"id": 3855,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2056:7:7",
|
"src": "2056:7:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -2312,10 +2294,7 @@
|
|||||||
"id": 3908,
|
"id": 3908,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2410:7:7",
|
"src": "2410:7:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -3312,23 +3291,12 @@
|
|||||||
"src": "2843:6:7"
|
"src": "2843:6:7"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contractDependencies": [
|
"contractDependencies": [280, 1422, 3979, 6537],
|
||||||
280,
|
|
||||||
1422,
|
|
||||||
3979,
|
|
||||||
6537
|
|
||||||
],
|
|
||||||
"contractKind": "contract",
|
"contractKind": "contract",
|
||||||
"documentation": null,
|
"documentation": null,
|
||||||
"fullyImplemented": true,
|
"fullyImplemented": true,
|
||||||
"id": 4285,
|
"id": 4285,
|
||||||
"linearizedBaseContracts": [
|
"linearizedBaseContracts": [4285, 6537, 3979, 1422, 280],
|
||||||
4285,
|
|
||||||
6537,
|
|
||||||
3979,
|
|
||||||
1422,
|
|
||||||
280
|
|
||||||
],
|
|
||||||
"name": "BToken",
|
"name": "BToken",
|
||||||
"nodeType": "ContractDefinition",
|
"nodeType": "ContractDefinition",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
@ -4299,9 +4267,7 @@
|
|||||||
"id": 4070,
|
"id": 4070,
|
||||||
"name": "Approval",
|
"name": "Approval",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6536],
|
||||||
6536
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6536,
|
"referencedDeclaration": 6536,
|
||||||
"src": "3696:8:7",
|
"src": "3696:8:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -4852,9 +4818,7 @@
|
|||||||
"id": 4106,
|
"id": 4106,
|
||||||
"name": "Approval",
|
"name": "Approval",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6536],
|
||||||
6536
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6536,
|
"referencedDeclaration": 6536,
|
||||||
"src": "3926:8:7",
|
"src": "3926:8:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -5019,9 +4983,7 @@
|
|||||||
"src": "4087:315:7",
|
"src": "4087:315:7",
|
||||||
"statements": [
|
"statements": [
|
||||||
{
|
{
|
||||||
"assignments": [
|
"assignments": [4131],
|
||||||
4131
|
|
||||||
],
|
|
||||||
"declarations": [
|
"declarations": [
|
||||||
{
|
{
|
||||||
"constant": false,
|
"constant": false,
|
||||||
@ -5639,9 +5601,7 @@
|
|||||||
"id": 4166,
|
"id": 4166,
|
||||||
"name": "Approval",
|
"name": "Approval",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6536],
|
||||||
6536
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6536,
|
"referencedDeclaration": 6536,
|
||||||
"src": "4320:8:7",
|
"src": "4320:8:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -6279,10 +6239,7 @@
|
|||||||
"id": 4211,
|
"id": 4211,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "4683:7:7",
|
"src": "4683:7:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -7047,9 +7004,7 @@
|
|||||||
"id": 4267,
|
"id": 4267,
|
||||||
"name": "Approval",
|
"name": "Approval",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6536],
|
||||||
6536
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6536,
|
"referencedDeclaration": 6536,
|
||||||
"src": "5017:8:7",
|
"src": "5017:8:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -7247,23 +7202,15 @@
|
|||||||
"legacyAST": {
|
"legacyAST": {
|
||||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BToken.sol",
|
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BToken.sol",
|
||||||
"exportedSymbols": {
|
"exportedSymbols": {
|
||||||
"BToken": [
|
"BToken": [4285],
|
||||||
4285
|
"BTokenBase": [3979]
|
||||||
],
|
|
||||||
"BTokenBase": [
|
|
||||||
3979
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"id": 4286,
|
"id": 4286,
|
||||||
"nodeType": "SourceUnit",
|
"nodeType": "SourceUnit",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"id": 3780,
|
"id": 3780,
|
||||||
"literals": [
|
"literals": ["solidity", "0.5", ".7"],
|
||||||
"solidity",
|
|
||||||
"0.5",
|
|
||||||
".7"
|
|
||||||
],
|
|
||||||
"nodeType": "PragmaDirective",
|
"nodeType": "PragmaDirective",
|
||||||
"src": "643:22:7"
|
"src": "643:22:7"
|
||||||
},
|
},
|
||||||
@ -7310,19 +7257,12 @@
|
|||||||
"src": "1468:4:7"
|
"src": "1468:4:7"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contractDependencies": [
|
"contractDependencies": [280, 1422],
|
||||||
280,
|
|
||||||
1422
|
|
||||||
],
|
|
||||||
"contractKind": "contract",
|
"contractKind": "contract",
|
||||||
"documentation": null,
|
"documentation": null,
|
||||||
"fullyImplemented": true,
|
"fullyImplemented": true,
|
||||||
"id": 3979,
|
"id": 3979,
|
||||||
"linearizedBaseContracts": [
|
"linearizedBaseContracts": [3979, 1422, 280],
|
||||||
3979,
|
|
||||||
1422,
|
|
||||||
280
|
|
||||||
],
|
|
||||||
"name": "BTokenBase",
|
"name": "BTokenBase",
|
||||||
"nodeType": "ContractDefinition",
|
"nodeType": "ContractDefinition",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
@ -8367,10 +8307,7 @@
|
|||||||
"id": 3855,
|
"id": 3855,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2056:7:7",
|
"src": "2056:7:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -9062,10 +8999,7 @@
|
|||||||
"id": 3908,
|
"id": 3908,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2410:7:7",
|
"src": "2410:7:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -10062,23 +9996,12 @@
|
|||||||
"src": "2843:6:7"
|
"src": "2843:6:7"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contractDependencies": [
|
"contractDependencies": [280, 1422, 3979, 6537],
|
||||||
280,
|
|
||||||
1422,
|
|
||||||
3979,
|
|
||||||
6537
|
|
||||||
],
|
|
||||||
"contractKind": "contract",
|
"contractKind": "contract",
|
||||||
"documentation": null,
|
"documentation": null,
|
||||||
"fullyImplemented": true,
|
"fullyImplemented": true,
|
||||||
"id": 4285,
|
"id": 4285,
|
||||||
"linearizedBaseContracts": [
|
"linearizedBaseContracts": [4285, 6537, 3979, 1422, 280],
|
||||||
4285,
|
|
||||||
6537,
|
|
||||||
3979,
|
|
||||||
1422,
|
|
||||||
280
|
|
||||||
],
|
|
||||||
"name": "BToken",
|
"name": "BToken",
|
||||||
"nodeType": "ContractDefinition",
|
"nodeType": "ContractDefinition",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
@ -11049,9 +10972,7 @@
|
|||||||
"id": 4070,
|
"id": 4070,
|
||||||
"name": "Approval",
|
"name": "Approval",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6536],
|
||||||
6536
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6536,
|
"referencedDeclaration": 6536,
|
||||||
"src": "3696:8:7",
|
"src": "3696:8:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -11602,9 +11523,7 @@
|
|||||||
"id": 4106,
|
"id": 4106,
|
||||||
"name": "Approval",
|
"name": "Approval",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6536],
|
||||||
6536
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6536,
|
"referencedDeclaration": 6536,
|
||||||
"src": "3926:8:7",
|
"src": "3926:8:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -11769,9 +11688,7 @@
|
|||||||
"src": "4087:315:7",
|
"src": "4087:315:7",
|
||||||
"statements": [
|
"statements": [
|
||||||
{
|
{
|
||||||
"assignments": [
|
"assignments": [4131],
|
||||||
4131
|
|
||||||
],
|
|
||||||
"declarations": [
|
"declarations": [
|
||||||
{
|
{
|
||||||
"constant": false,
|
"constant": false,
|
||||||
@ -12389,9 +12306,7 @@
|
|||||||
"id": 4166,
|
"id": 4166,
|
||||||
"name": "Approval",
|
"name": "Approval",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6536],
|
||||||
6536
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6536,
|
"referencedDeclaration": 6536,
|
||||||
"src": "4320:8:7",
|
"src": "4320:8:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -13029,10 +12944,7 @@
|
|||||||
"id": 4211,
|
"id": 4211,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "4683:7:7",
|
"src": "4683:7:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -13797,9 +13709,7 @@
|
|||||||
"id": 4267,
|
"id": 4267,
|
||||||
"name": "Approval",
|
"name": "Approval",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6536],
|
||||||
6536
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6536,
|
"referencedDeclaration": 6536,
|
||||||
"src": "5017:8:7",
|
"src": "5017:8:7",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -14007,4 +13917,4 @@
|
|||||||
"userdoc": {
|
"userdoc": {
|
||||||
"methods": {}
|
"methods": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,20 +157,14 @@
|
|||||||
"ast": {
|
"ast": {
|
||||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/DTFactory.sol",
|
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/DTFactory.sol",
|
||||||
"exportedSymbols": {
|
"exportedSymbols": {
|
||||||
"DTFactory": [
|
"DTFactory": [158]
|
||||||
158
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"id": 159,
|
"id": 159,
|
||||||
"nodeType": "SourceUnit",
|
"nodeType": "SourceUnit",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"literals": [
|
"literals": ["solidity", "0.5", ".7"],
|
||||||
"solidity",
|
|
||||||
"0.5",
|
|
||||||
".7"
|
|
||||||
],
|
|
||||||
"nodeType": "PragmaDirective",
|
"nodeType": "PragmaDirective",
|
||||||
"src": "0:22:0"
|
"src": "0:22:0"
|
||||||
},
|
},
|
||||||
@ -217,17 +211,12 @@
|
|||||||
"src": "651:8:0"
|
"src": "651:8:0"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contractDependencies": [
|
"contractDependencies": [5731],
|
||||||
5731
|
|
||||||
],
|
|
||||||
"contractKind": "contract",
|
"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.",
|
"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,
|
"fullyImplemented": true,
|
||||||
"id": 158,
|
"id": 158,
|
||||||
"linearizedBaseContracts": [
|
"linearizedBaseContracts": [158, 5731],
|
||||||
158,
|
|
||||||
5731
|
|
||||||
],
|
|
||||||
"name": "DTFactory",
|
"name": "DTFactory",
|
||||||
"nodeType": "ContractDefinition",
|
"nodeType": "ContractDefinition",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
@ -843,10 +832,7 @@
|
|||||||
"id": 41,
|
"id": 41,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "1528:7:0",
|
"src": "1528:7:0",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -1139,10 +1125,7 @@
|
|||||||
"id": 78,
|
"id": 78,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2359:7:0",
|
"src": "2359:7:0",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -1375,10 +1358,7 @@
|
|||||||
"id": 91,
|
"id": 91,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2499:7:0",
|
"src": "2499:7:0",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -1405,9 +1385,7 @@
|
|||||||
"src": "2499:124:0"
|
"src": "2499:124:0"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"assignments": [
|
"assignments": [101],
|
||||||
101
|
|
||||||
],
|
|
||||||
"declarations": [
|
"declarations": [
|
||||||
{
|
{
|
||||||
"constant": false,
|
"constant": false,
|
||||||
@ -1694,10 +1672,7 @@
|
|||||||
"id": 106,
|
"id": 106,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2695:7:0",
|
"src": "2695:7:0",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -2346,20 +2321,14 @@
|
|||||||
"legacyAST": {
|
"legacyAST": {
|
||||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/DTFactory.sol",
|
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/DTFactory.sol",
|
||||||
"exportedSymbols": {
|
"exportedSymbols": {
|
||||||
"DTFactory": [
|
"DTFactory": [158]
|
||||||
158
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"id": 159,
|
"id": 159,
|
||||||
"nodeType": "SourceUnit",
|
"nodeType": "SourceUnit",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"literals": [
|
"literals": ["solidity", "0.5", ".7"],
|
||||||
"solidity",
|
|
||||||
"0.5",
|
|
||||||
".7"
|
|
||||||
],
|
|
||||||
"nodeType": "PragmaDirective",
|
"nodeType": "PragmaDirective",
|
||||||
"src": "0:22:0"
|
"src": "0:22:0"
|
||||||
},
|
},
|
||||||
@ -2406,17 +2375,12 @@
|
|||||||
"src": "651:8:0"
|
"src": "651:8:0"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contractDependencies": [
|
"contractDependencies": [5731],
|
||||||
5731
|
|
||||||
],
|
|
||||||
"contractKind": "contract",
|
"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.",
|
"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,
|
"fullyImplemented": true,
|
||||||
"id": 158,
|
"id": 158,
|
||||||
"linearizedBaseContracts": [
|
"linearizedBaseContracts": [158, 5731],
|
||||||
158,
|
|
||||||
5731
|
|
||||||
],
|
|
||||||
"name": "DTFactory",
|
"name": "DTFactory",
|
||||||
"nodeType": "ContractDefinition",
|
"nodeType": "ContractDefinition",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
@ -3032,10 +2996,7 @@
|
|||||||
"id": 41,
|
"id": 41,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "1528:7:0",
|
"src": "1528:7:0",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -3328,10 +3289,7 @@
|
|||||||
"id": 78,
|
"id": 78,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2359:7:0",
|
"src": "2359:7:0",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -3564,10 +3522,7 @@
|
|||||||
"id": 91,
|
"id": 91,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2499:7:0",
|
"src": "2499:7:0",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -3594,9 +3549,7 @@
|
|||||||
"src": "2499:124:0"
|
"src": "2499:124:0"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"assignments": [
|
"assignments": [101],
|
||||||
101
|
|
||||||
],
|
|
||||||
"declarations": [
|
"declarations": [
|
||||||
{
|
{
|
||||||
"constant": false,
|
"constant": false,
|
||||||
@ -3883,10 +3836,7 @@
|
|||||||
"id": 106,
|
"id": 106,
|
||||||
"name": "require",
|
"name": "require",
|
||||||
"nodeType": "Identifier",
|
"nodeType": "Identifier",
|
||||||
"overloadedDeclarations": [
|
"overloadedDeclarations": [6555, 6556],
|
||||||
6555,
|
|
||||||
6556
|
|
||||||
],
|
|
||||||
"referencedDeclaration": 6556,
|
"referencedDeclaration": 6556,
|
||||||
"src": "2695:7:0",
|
"src": "2695:7:0",
|
||||||
"typeDescriptions": {
|
"typeDescriptions": {
|
||||||
@ -4574,4 +4524,4 @@
|
|||||||
"userdoc": {
|
"userdoc": {
|
||||||
"methods": {}
|
"methods": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
6981
package-lock.json
generated
6981
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
58
package.json
58
package.json
@ -2,24 +2,62 @@
|
|||||||
"name": "ocean-subgraph",
|
"name": "ocean-subgraph",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "",
|
||||||
"create": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
|
"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",
|
"create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
|
||||||
"codegen": "graph codegen --output-dir src/types/",
|
"codegen": "graph codegen --output-dir src/types/",
|
||||||
"build": "graph build",
|
"build": "graph build",
|
||||||
"deploy": "graph deploy oceanprotocol/ocean-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
|
"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: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": {
|
"devDependencies": {
|
||||||
"@graphprotocol/graph-cli": "^0.18.0",
|
"@graphprotocol/graph-cli": "^0.19.0",
|
||||||
"@graphprotocol/graph-ts": "^0.18.1"
|
"@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": {
|
"dependencies": {},
|
||||||
"babel-polyfill": "^6.26.0",
|
"repository": {
|
||||||
"babel-register": "^6.26.0",
|
"type": "git",
|
||||||
"keytar": "^5.0.0",
|
"url": "git+https://github.com/oceanprotocol/ocean-subgraph.git"
|
||||||
"truffle": "^5.1.0",
|
},
|
||||||
"truffle-contract": "^4.0.5",
|
"license": "Apache-2.0",
|
||||||
"truffle-hdwallet-provider": "^1.0.4"
|
"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,
|
Bytes,
|
||||||
dataSource,
|
dataSource,
|
||||||
Address,
|
Address,
|
||||||
ethereum
|
ethereum,
|
||||||
|
log
|
||||||
} from '@graphprotocol/graph-ts'
|
} from '@graphprotocol/graph-ts'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -19,72 +20,104 @@ import {
|
|||||||
TokenTransaction,
|
TokenTransaction,
|
||||||
PoolTransactionTokenValues
|
PoolTransactionTokenValues
|
||||||
} from '../types/schema'
|
} from '../types/schema'
|
||||||
import { log } from '@graphprotocol/graph-ts'
|
|
||||||
import { Pool } from '../types/templates/Pool/Pool'
|
import { Pool } from '../types/templates/Pool/Pool'
|
||||||
|
|
||||||
export let ZERO_BD = BigDecimal.fromString('0.0')
|
export const ZERO_BD = BigDecimal.fromString('0.0')
|
||||||
export let MINUS_1_BD = BigDecimal.fromString('-1.0')
|
export const MINUS_1_BD = BigDecimal.fromString('-1.0')
|
||||||
export let ONE_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 const ONE_BASE_18 = BigInt.fromI32(10).pow(18 as u8)
|
||||||
export let BONE = BigDecimal.fromString('1000000000000000000')
|
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')
|
export const OCEAN: string =
|
||||||
? '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
network === 'mainnet'
|
||||||
: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07'
|
? '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) {
|
if (event != null) {
|
||||||
args.push(event.transaction.hash.toHex())
|
args.push(event.transaction.hash.toHex())
|
||||||
args.push(event.address.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(' {}')
|
message = message.concat(' {}')
|
||||||
}
|
}
|
||||||
log.info('@@@@@@ ' + message, args)
|
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
|
if (!ENABLE_DEBUG) return
|
||||||
_debuglog(message, event, args)
|
_debuglog(message, event, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hexToDecimal(hexString: String, decimals: i32): BigDecimal {
|
export function hexToDecimal(hexString: string, decimals: i32): BigDecimal {
|
||||||
let bytes = Bytes.fromHexString(hexString.toString()).reverse() as Bytes
|
const bytes = Bytes.fromHexString(hexString.toString()).reverse() as Bytes
|
||||||
let bi = BigInt.fromUnsignedBytes(bytes)
|
const bi = BigInt.fromUnsignedBytes(bytes)
|
||||||
let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal()
|
const scale = BigInt.fromI32(10)
|
||||||
|
.pow(decimals as u8)
|
||||||
|
.toBigDecimal()
|
||||||
return bi.divDecimal(scale)
|
return bi.divDecimal(scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bigIntToDecimal(amount: BigInt, decimals: i32): BigDecimal {
|
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)
|
return amount.toBigDecimal().div(scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tokenToDecimal(amount: BigDecimal, decimals: i32): BigDecimal {
|
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)
|
return amount.div(scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decimalToBigInt(value: BigDecimal): BigInt {
|
export function decimalToBigInt(value: BigDecimal): BigInt {
|
||||||
value.truncate(18)
|
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)
|
return value.digits.times(scale)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updatePoolTokenBalance(poolToken: PoolToken, balance: BigDecimal, source: string): void {
|
export function updatePoolTokenBalance(
|
||||||
debuglog('########## updating poolToken balance (source, oldBalance, newBalance, poolId) ', null,
|
poolToken: PoolToken,
|
||||||
[source, poolToken.balance.toString(), balance.toString(), poolToken.poolId])
|
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
|
poolToken.balance = balance
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPoolShareEntity(id: string, pool: string, user: string): void {
|
export function createUserEntity(address: string): void {
|
||||||
let poolShare = new PoolShare(id)
|
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)
|
createUserEntity(user)
|
||||||
|
|
||||||
@ -94,12 +127,16 @@ export function createPoolShareEntity(id: string, pool: string, user: string): v
|
|||||||
poolShare.save()
|
poolShare.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPoolTokenEntity(id: string, pool: string, address: string): void {
|
export function createPoolTokenEntity(
|
||||||
let datatoken = Datatoken.load(address)
|
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.poolId = pool
|
||||||
poolToken.tokenId = datatoken ? datatoken.id: ''
|
poolToken.tokenId = datatoken ? datatoken.id : ''
|
||||||
poolToken.tokenAddress = address
|
poolToken.tokenAddress = address
|
||||||
poolToken.balance = ZERO_BD
|
poolToken.balance = ZERO_BD
|
||||||
poolToken.denormWeight = ZERO_BD
|
poolToken.denormWeight = ZERO_BD
|
||||||
@ -107,14 +144,16 @@ export function createPoolTokenEntity(id: string, pool: string, address: string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function updatePoolTransactionToken(
|
export function updatePoolTransactionToken(
|
||||||
poolTx: string, poolTokenId: string, amount: BigDecimal,
|
poolTx: string,
|
||||||
balance: BigDecimal, feeValue: BigDecimal
|
poolTokenId: string,
|
||||||
|
amount: BigDecimal,
|
||||||
|
balance: BigDecimal,
|
||||||
|
feeValue: BigDecimal
|
||||||
): void {
|
): void {
|
||||||
|
const ptx = PoolTransaction.load(poolTx)
|
||||||
let ptx = PoolTransaction.load(poolTx)
|
const poolToken = PoolToken.load(poolTokenId)
|
||||||
let poolToken = PoolToken.load(poolTokenId)
|
const pool = PoolEntity.load(poolToken.poolId)
|
||||||
let pool = PoolEntity.load(poolToken.poolId)
|
const ptxTokenValuesId = poolTx.concat('-').concat(poolToken.tokenAddress)
|
||||||
let ptxTokenValuesId = poolTx.concat('-').concat(poolToken.tokenAddress)
|
|
||||||
let ptxTokenValues = PoolTransactionTokenValues.load(ptxTokenValuesId)
|
let ptxTokenValues = PoolTransactionTokenValues.load(ptxTokenValuesId)
|
||||||
if (ptxTokenValues == null) {
|
if (ptxTokenValues == null) {
|
||||||
ptxTokenValues = new PoolTransactionTokenValues(ptxTokenValuesId)
|
ptxTokenValues = new PoolTransactionTokenValues(ptxTokenValuesId)
|
||||||
@ -136,34 +175,74 @@ export function updatePoolTransactionToken(
|
|||||||
|
|
||||||
ptxTokenValues.save()
|
ptxTokenValues.save()
|
||||||
|
|
||||||
if (ptxTokenValues.tokenAddress == OCEAN) {
|
if (ptxTokenValues.tokenAddress === OCEAN) {
|
||||||
ptx.oceanReserve = ptxTokenValues.tokenReserve
|
ptx.oceanReserve = ptxTokenValues.tokenReserve
|
||||||
pool.oceanReserve = ptxTokenValues.tokenReserve
|
pool.oceanReserve = ptxTokenValues.tokenReserve
|
||||||
} else {
|
} else {
|
||||||
ptx.datatokenReserve = ptxTokenValues.tokenReserve
|
ptx.datatokenReserve = ptxTokenValues.tokenReserve
|
||||||
pool.datatokenReserve = ptxTokenValues.tokenReserve
|
pool.datatokenReserve = ptxTokenValues.tokenReserve
|
||||||
}
|
}
|
||||||
debuglog('########## updatePoolTransactionToken: ', null,
|
debuglog('########## updatePoolTransactionToken: ', null, [
|
||||||
[
|
BigInt.fromI32(ptx.block).toString(),
|
||||||
BigInt.fromI32(ptx.block).toString(),
|
BigInt.fromI32(ptx.timestamp).toString(),
|
||||||
BigInt.fromI32(ptx.timestamp).toString(),
|
ptxTokenValues.type,
|
||||||
ptxTokenValues.type,
|
ptxTokenValues.value.toString(),
|
||||||
ptxTokenValues.value.toString(),
|
ptxTokenValues.tokenReserve.toString(),
|
||||||
ptxTokenValues.tokenReserve.toString(),
|
poolToken.poolId
|
||||||
poolToken.poolId,
|
])
|
||||||
])
|
|
||||||
|
|
||||||
ptx.save()
|
ptx.save()
|
||||||
pool.save()
|
pool.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPoolTransaction(event: ethereum.Event, event_type: string, userAddress: string): void {
|
export function calcSpotPrice(
|
||||||
let poolId = event.address.toHex()
|
balanceIn: BigDecimal,
|
||||||
let pool = PoolEntity.load(poolId)
|
wIn: BigDecimal,
|
||||||
let ptx = event.transaction.hash.toHexString()
|
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()
|
||||||
|
])
|
||||||
|
|
||||||
let ocnToken = PoolToken.load(poolId.concat('-').concat(OCEAN))
|
const numer = balanceIn.div(wIn)
|
||||||
let dtToken = PoolToken.load(poolId.concat('-').concat(pool.datatokenAddress))
|
const denom = balanceOut.div(wOut)
|
||||||
|
if (denom <= ZERO_BD) return MINUS_1_BD
|
||||||
|
|
||||||
|
const ratio = numer.div(denom)
|
||||||
|
const scale = ONE_BD.div(ONE_BD.minus(swapFee))
|
||||||
|
const price = ratio.times(scale)
|
||||||
|
price.truncate(18)
|
||||||
|
debuglog('################ calcSpotPrice values:', null, [
|
||||||
|
numer.toString(),
|
||||||
|
denom.toString(),
|
||||||
|
ratio.toString(),
|
||||||
|
scale.toString(),
|
||||||
|
price.toString()
|
||||||
|
])
|
||||||
|
return price
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createPoolTransaction(
|
||||||
|
event: ethereum.Event,
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
event_type: string,
|
||||||
|
userAddress: string
|
||||||
|
): void {
|
||||||
|
const poolId = event.address.toHex()
|
||||||
|
const pool = PoolEntity.load(poolId)
|
||||||
|
const ptx = event.transaction.hash.toHexString()
|
||||||
|
|
||||||
|
const ocnToken = PoolToken.load(poolId.concat('-').concat(OCEAN))
|
||||||
|
const dtToken = PoolToken.load(
|
||||||
|
poolId.concat('-').concat(pool.datatokenAddress)
|
||||||
|
)
|
||||||
|
|
||||||
if (ocnToken == null || dtToken == null) {
|
if (ocnToken == null || dtToken == null) {
|
||||||
return
|
return
|
||||||
@ -189,14 +268,18 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
|||||||
poolTx.datatokenReserve = dtToken.balance
|
poolTx.datatokenReserve = dtToken.balance
|
||||||
poolTx.oceanReserve = ocnToken.balance
|
poolTx.oceanReserve = ocnToken.balance
|
||||||
|
|
||||||
let p = Pool.bind(Address.fromString(poolId))
|
const p = Pool.bind(Address.fromString(poolId))
|
||||||
let priceResult = p.try_calcInGivenOut(
|
const priceResult = p.try_calcInGivenOut(
|
||||||
decimalToBigInt(ocnToken.balance), decimalToBigInt(ocnToken.denormWeight),
|
decimalToBigInt(ocnToken.balance),
|
||||||
decimalToBigInt(dtToken.balance), decimalToBigInt(dtToken.denormWeight),
|
decimalToBigInt(ocnToken.denormWeight),
|
||||||
ONE_BASE_18, decimalToBigInt(pool.swapFee)
|
decimalToBigInt(dtToken.balance),
|
||||||
|
decimalToBigInt(dtToken.denormWeight),
|
||||||
|
ONE_BASE_18,
|
||||||
|
decimalToBigInt(pool.swapFee)
|
||||||
)
|
)
|
||||||
debuglog(
|
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.balance).toString(),
|
||||||
decimalToBigInt(ocnToken.denormWeight).toString(),
|
decimalToBigInt(ocnToken.denormWeight).toString(),
|
||||||
@ -207,10 +290,14 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
|||||||
priceResult.reverted ? 'failed' : priceResult.value.toString()
|
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(
|
poolTx.spotPrice = calcSpotPrice(
|
||||||
ocnToken.balance, ocnToken.denormWeight,
|
ocnToken.balance,
|
||||||
dtToken.balance, dtToken.denormWeight,
|
ocnToken.denormWeight,
|
||||||
|
dtToken.balance,
|
||||||
|
dtToken.denormWeight,
|
||||||
pool.swapFee
|
pool.swapFee
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -221,63 +308,51 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
|||||||
|
|
||||||
pool.save()
|
pool.save()
|
||||||
|
|
||||||
debuglog('updated pool reserves (source, dtBalance, ocnBalance, dtReserve, ocnReserve): ',
|
debuglog(
|
||||||
|
'updated pool reserves (source, dtBalance, ocnBalance, dtReserve, ocnReserve): ',
|
||||||
event,
|
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.tx = event.transaction.hash
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
poolTx.event = event_type
|
poolTx.event = event_type
|
||||||
poolTx.block = event.block.number.toI32()
|
poolTx.block = event.block.number.toI32()
|
||||||
poolTx.timestamp = event.block.timestamp.toI32()
|
poolTx.timestamp = event.block.timestamp.toI32()
|
||||||
poolTx.gasUsed = event.transaction.gasUsed.toBigDecimal()
|
poolTx.gasUsed = event.transaction.gasUsed.toBigDecimal()
|
||||||
poolTx.gasPrice = event.transaction.gasPrice.toBigDecimal()
|
poolTx.gasPrice = event.transaction.gasPrice.toBigDecimal()
|
||||||
|
|
||||||
|
debuglog('####################### poolTransaction: ', event, [
|
||||||
debuglog('####################### poolTransaction: ', event,
|
BigInt.fromI32(poolTx.block).toString(),
|
||||||
[
|
BigInt.fromI32(poolTx.timestamp).toString(),
|
||||||
BigInt.fromI32(poolTx.block).toString(),
|
pool.oceanReserve.toString()
|
||||||
BigInt.fromI32(poolTx.timestamp).toString(),
|
])
|
||||||
pool.oceanReserve.toString()
|
|
||||||
])
|
|
||||||
|
|
||||||
poolTx.save()
|
poolTx.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calcSpotPrice(
|
|
||||||
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()])
|
|
||||||
|
|
||||||
let numer = balanceIn.div(wIn)
|
|
||||||
let denom = balanceOut.div(wOut)
|
|
||||||
if (denom <= ZERO_BD) return MINUS_1_BD
|
|
||||||
|
|
||||||
let ratio = numer.div(denom)
|
|
||||||
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()])
|
|
||||||
return price
|
|
||||||
}
|
|
||||||
|
|
||||||
export function decrPoolCount(finalized: boolean): void {
|
export function decrPoolCount(finalized: boolean): void {
|
||||||
let factory = PoolFactory.load('1')
|
const factory = PoolFactory.load('1')
|
||||||
factory.poolCount -= 1
|
factory.poolCount -= 1
|
||||||
if (finalized) factory.finalizedPoolCount -= 1
|
if (finalized) factory.finalizedPoolCount -= 1
|
||||||
factory.save()
|
factory.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveTokenTransaction(event: ethereum.Event, eventName: string): void {
|
export function saveTokenTransaction(
|
||||||
let tx = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
|
event: ethereum.Event,
|
||||||
let userAddress = event.transaction.from.toHex()
|
eventName: string
|
||||||
|
): void {
|
||||||
|
const tx = event.transaction.hash
|
||||||
|
.toHexString()
|
||||||
|
.concat('-')
|
||||||
|
.concat(event.logIndex.toString())
|
||||||
|
const userAddress = event.transaction.from.toHex()
|
||||||
let transaction = TokenTransaction.load(tx)
|
let transaction = TokenTransaction.load(tx)
|
||||||
if (transaction == null) {
|
if (transaction == null) {
|
||||||
transaction = new TokenTransaction(tx)
|
transaction = new TokenTransaction(tx)
|
||||||
@ -295,14 +370,12 @@ export function saveTokenTransaction(event: ethereum.Event, eventName: string):
|
|||||||
createUserEntity(userAddress)
|
createUserEntity(userAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createUserEntity(address: string): void {
|
export function updateTokenBalance(
|
||||||
if (User.load(address) == null) {
|
id: string,
|
||||||
let user = new User(address)
|
token: string,
|
||||||
user.save()
|
user: string,
|
||||||
}
|
amount: BigDecimal
|
||||||
}
|
): void {
|
||||||
|
|
||||||
export function updateTokenBalance(id: string, token: string, user: string, amount: BigDecimal): void {
|
|
||||||
let tokenBalance = TokenBalance.load(id)
|
let tokenBalance = TokenBalance.load(id)
|
||||||
if (tokenBalance == null) {
|
if (tokenBalance == null) {
|
||||||
tokenBalance = new TokenBalance(id)
|
tokenBalance = new TokenBalance(id)
|
@ -1,80 +1,85 @@
|
|||||||
|
|
||||||
import { BigInt, BigDecimal } from '@graphprotocol/graph-ts'
|
import { BigInt, BigDecimal } from '@graphprotocol/graph-ts'
|
||||||
import { OrderStarted, Transfer } from '../types/templates/DataToken/DataToken'
|
import { OrderStarted, Transfer } from '../types/templates/DataToken/DataToken'
|
||||||
import { log } from '@graphprotocol/graph-ts'
|
|
||||||
|
|
||||||
import {
|
import { Datatoken, TokenBalance, TokenOrder } from '../types/schema'
|
||||||
Datatoken, TokenBalance, TokenOrder
|
|
||||||
} from '../types/schema'
|
|
||||||
import {
|
import {
|
||||||
tokenToDecimal,
|
tokenToDecimal,
|
||||||
updateTokenBalance,
|
updateTokenBalance,
|
||||||
ZERO_BD,
|
ZERO_BD,
|
||||||
MINUS_1_BD,
|
MINUS_1_BD,
|
||||||
saveTokenTransaction
|
saveTokenTransaction
|
||||||
} from './helpers'
|
} from '../helpers'
|
||||||
|
|
||||||
/************************************
|
/************************************
|
||||||
********** Pool Controls ***********
|
********** Pool Controls ***********
|
||||||
************************************/
|
************************************/
|
||||||
|
|
||||||
export function handleTransfer(event: Transfer): void {
|
export function handleTransfer(event: Transfer): void {
|
||||||
let tokenId = event.address.toHex()
|
const tokenId = event.address.toHex()
|
||||||
|
|
||||||
let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||||
|
|
||||||
|
const amount = tokenToDecimal(event.params.value.toBigDecimal(), 18)
|
||||||
let amount = tokenToDecimal(event.params.value.toBigDecimal(), 18)
|
const tokenShareFrom = event.params.from.toHex()
|
||||||
let tokenShareFrom = event.params.from.toHex()
|
const tokenShareTo = event.params.to.toHex()
|
||||||
let tokenShareTo = event.params.to.toHex()
|
const tokenBalanceFromId = tokenId.concat('-').concat(tokenShareFrom)
|
||||||
let tokenBalanceFromId = tokenId.concat('-').concat(tokenShareFrom)
|
const tokenBalanceToId = tokenId.concat('-').concat(tokenShareTo)
|
||||||
let tokenBalanceToId = tokenId.concat('-').concat(tokenShareTo)
|
|
||||||
let tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
let tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
||||||
let tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
let tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
||||||
let oldBalanceFrom = BigDecimal.fromString('0.0')
|
let oldBalanceFrom = BigDecimal.fromString('0.0')
|
||||||
let oldBalanceTo = BigDecimal.fromString('0.0')
|
let oldBalanceTo = BigDecimal.fromString('0.0')
|
||||||
|
|
||||||
let isMint = tokenShareFrom == ZERO_ADDRESS
|
const isMint = tokenShareFrom === ZERO_ADDRESS
|
||||||
let isBurn = tokenShareTo == ZERO_ADDRESS
|
const isBurn = tokenShareTo === ZERO_ADDRESS
|
||||||
|
|
||||||
let datatoken = Datatoken.load(tokenId)
|
const datatoken = Datatoken.load(tokenId)
|
||||||
|
|
||||||
if (isMint) {
|
if (isMint) {
|
||||||
tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
||||||
oldBalanceTo = (tokenBalanceTo == null) ? ZERO_BD : tokenBalanceTo.balance
|
oldBalanceTo = tokenBalanceTo == null ? ZERO_BD : tokenBalanceTo.balance
|
||||||
datatoken.supply = datatoken.supply.plus(amount)
|
datatoken.supply = datatoken.supply.plus(amount)
|
||||||
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
|
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
|
||||||
|
|
||||||
} else if (isBurn) {
|
} else if (isBurn) {
|
||||||
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
||||||
oldBalanceFrom = (tokenBalanceFrom == null) ? ZERO_BD : tokenBalanceFrom.balance
|
oldBalanceFrom =
|
||||||
|
tokenBalanceFrom == null ? ZERO_BD : tokenBalanceFrom.balance
|
||||||
datatoken.supply = datatoken.supply.minus(amount)
|
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 {
|
} else {
|
||||||
|
|
||||||
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
||||||
oldBalanceFrom = (tokenBalanceFrom == null) ? ZERO_BD : tokenBalanceFrom.balance
|
oldBalanceFrom =
|
||||||
|
tokenBalanceFrom == null ? ZERO_BD : tokenBalanceFrom.balance
|
||||||
datatoken.supply = datatoken.supply.minus(amount)
|
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)
|
tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
||||||
oldBalanceTo = (tokenBalanceTo == null) ? ZERO_BD : tokenBalanceTo.balance
|
oldBalanceTo = tokenBalanceTo == null ? ZERO_BD : tokenBalanceTo.balance
|
||||||
datatoken.supply = datatoken.supply.plus(amount)
|
datatoken.supply = datatoken.supply.plus(amount)
|
||||||
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
|
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
tokenBalanceTo !== null
|
tokenBalanceTo !== null &&
|
||||||
&& tokenBalanceTo.balance.notEqual(ZERO_BD)
|
tokenBalanceTo.balance.notEqual(ZERO_BD) &&
|
||||||
&& oldBalanceTo.equals(ZERO_BD)
|
oldBalanceTo.equals(ZERO_BD)
|
||||||
) {
|
) {
|
||||||
datatoken.holderCount += BigInt.fromI32(1)
|
datatoken.holderCount += BigInt.fromI32(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
tokenBalanceFrom !== null
|
tokenBalanceFrom !== null &&
|
||||||
&& tokenBalanceFrom.balance.equals(ZERO_BD)
|
tokenBalanceFrom.balance.equals(ZERO_BD) &&
|
||||||
&& oldBalanceFrom.notEqual(ZERO_BD)
|
oldBalanceFrom.notEqual(ZERO_BD)
|
||||||
) {
|
) {
|
||||||
datatoken.holderCount -= BigInt.fromI32(1)
|
datatoken.holderCount -= BigInt.fromI32(1)
|
||||||
}
|
}
|
||||||
@ -84,19 +89,23 @@ export function handleTransfer(event: Transfer): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function handleOrderStarted(event: OrderStarted): void {
|
export function handleOrderStarted(event: OrderStarted): void {
|
||||||
let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||||
let tokenId = event.address.toHex()
|
const tokenId = event.address.toHex()
|
||||||
let datatoken = Datatoken.load(tokenId)
|
const datatoken = Datatoken.load(tokenId)
|
||||||
if (datatoken == null) return
|
if (datatoken == null) return
|
||||||
|
|
||||||
let payer = event.params.payer.toHex()
|
const payer = event.params.payer.toHex()
|
||||||
// let feeCollector = event.params.mrktFeeCollector
|
// let feeCollector = event.params.mrktFeeCollector
|
||||||
// let marketFee = event.params.marketFee
|
// let marketFee = event.params.marketFee
|
||||||
let tx = event.transaction.hash
|
const tx = event.transaction.hash
|
||||||
let orderId = tokenId.concat('-').concat(payer).concat('-').concat(tx.toHexString())
|
const orderId = tokenId
|
||||||
|
.concat('-')
|
||||||
|
.concat(payer)
|
||||||
|
.concat('-')
|
||||||
|
.concat(tx.toHexString())
|
||||||
let order = TokenOrder.load(orderId)
|
let order = TokenOrder.load(orderId)
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
order = new TokenOrder(orderId)
|
order = new TokenOrder(orderId)
|
||||||
}
|
}
|
||||||
order.datatokenId = tokenId
|
order.datatokenId = tokenId
|
||||||
order.amount = tokenToDecimal(event.params.amount.toBigDecimal(), 18)
|
order.amount = tokenToDecimal(event.params.amount.toBigDecimal(), 18)
|
||||||
@ -104,8 +113,11 @@ export function handleOrderStarted(event: OrderStarted): void {
|
|||||||
order.payer = payer
|
order.payer = payer
|
||||||
order.serviceId = event.params.serviceId.toI32()
|
order.serviceId = event.params.serviceId.toI32()
|
||||||
order.timestamp = event.params.timestamp.toI32()
|
order.timestamp = event.params.timestamp.toI32()
|
||||||
if (event.params.mrktFeeCollector != null && event.params.mrktFeeCollector.toHex() != ZERO_ADDRESS) {
|
if (
|
||||||
order.marketFeeCollector = event.params.mrktFeeCollector.toHexString()
|
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.marketFee = tokenToDecimal(event.params.marketFee.toBigDecimal(), 18)
|
||||||
order.tx = tx
|
order.tx = tx
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
import { BigInt } from '@graphprotocol/graph-ts'
|
import { BigInt, log } from '@graphprotocol/graph-ts'
|
||||||
import { TokenRegistered } from '../types/DTFactory/DTFactory'
|
import { TokenRegistered } from '../types/DTFactory/DTFactory'
|
||||||
import { DatatokenFactory, Datatoken as DatatokenEntity } from '../types/schema'
|
import { DatatokenFactory, Datatoken as DatatokenEntity } from '../types/schema'
|
||||||
import { DataToken as DatatokenDataSource } from '../types/templates'
|
import { DataToken as DatatokenDataSource } from '../types/templates'
|
||||||
|
|
||||||
import {
|
import { createUserEntity, tokenToDecimal, ZERO_BD } from '../helpers'
|
||||||
createUserEntity,
|
|
||||||
tokenToDecimal,
|
|
||||||
ZERO_BD,
|
|
||||||
} from './helpers'
|
|
||||||
import { log } from '@graphprotocol/graph-ts'
|
|
||||||
|
|
||||||
export function handleNewToken(event: TokenRegistered): void {
|
export function handleNewToken(event: TokenRegistered): void {
|
||||||
let factory = DatatokenFactory.load('1')
|
let factory = DatatokenFactory.load('1')
|
||||||
@ -19,8 +14,10 @@ export function handleNewToken(event: TokenRegistered): void {
|
|||||||
factory.tokenCount = 0
|
factory.tokenCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
let datatoken = new DatatokenEntity(event.params.tokenAddress.toHexString())
|
const 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()
|
datatoken.factoryID = event.address.toHexString()
|
||||||
|
|
||||||
@ -46,4 +43,4 @@ export function handleNewToken(event: TokenRegistered): void {
|
|||||||
factory.save()
|
factory.save()
|
||||||
|
|
||||||
DatatokenDataSource.create(event.params.tokenAddress)
|
DatatokenDataSource.create(event.params.tokenAddress)
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import { BigInt, BigDecimal } from '@graphprotocol/graph-ts'
|
import { BigInt, BigDecimal, log } from '@graphprotocol/graph-ts'
|
||||||
import { BPoolRegistered } from '../types/Factory/Factory'
|
import { BPoolRegistered } from '../types/Factory/Factory'
|
||||||
import { PoolFactory, Pool } from '../types/schema'
|
import { PoolFactory, Pool } from '../types/schema'
|
||||||
import { Pool as PoolContract } from '../types/templates'
|
import { Pool as PoolContract } from '../types/templates'
|
||||||
import { ZERO_BD } from './helpers'
|
import { ZERO_BD } from '../helpers'
|
||||||
import { log } from '@graphprotocol/graph-ts'
|
|
||||||
|
|
||||||
export function handleNewPool(event: BPoolRegistered): void {
|
export function handleNewPool(event: BPoolRegistered): void {
|
||||||
let factory = PoolFactory.load('1')
|
let factory = PoolFactory.load('1')
|
||||||
|
|
||||||
if (factory == null) {
|
if (factory === null) {
|
||||||
factory = new PoolFactory('1')
|
factory = new PoolFactory('1')
|
||||||
factory.totalLiquidity = ZERO_BD
|
factory.totalLiquidity = ZERO_BD
|
||||||
factory.totalSwapVolume = ZERO_BD
|
factory.totalSwapVolume = ZERO_BD
|
||||||
@ -18,8 +17,10 @@ export function handleNewPool(event: BPoolRegistered): void {
|
|||||||
factory.finalizedPoolCount = 0
|
factory.finalizedPoolCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
let pool = new Pool(event.params.bpoolAddress.toHexString())
|
const 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.factoryID = event.address.toHexString()
|
||||||
pool.controller = event.params.registeredBy
|
pool.controller = event.params.registeredBy
|
||||||
@ -38,8 +39,8 @@ export function handleNewPool(event: BPoolRegistered): void {
|
|||||||
|
|
||||||
pool.datatokenReserve = ZERO_BD
|
pool.datatokenReserve = ZERO_BD
|
||||||
pool.oceanReserve = ZERO_BD
|
pool.oceanReserve = ZERO_BD
|
||||||
pool.spotPrice = ZERO_BD //: BigDecimal!
|
pool.spotPrice = ZERO_BD // : BigDecimal!
|
||||||
pool.consumePrice = ZERO_BD //: BigDecimal!
|
pool.consumePrice = ZERO_BD // : BigDecimal!
|
||||||
|
|
||||||
pool.tokenCount = BigInt.fromI32(0)
|
pool.tokenCount = BigInt.fromI32(0)
|
||||||
pool.holderCount = BigInt.fromI32(0)
|
pool.holderCount = BigInt.fromI32(0)
|
||||||
@ -59,4 +60,4 @@ export function handleNewPool(event: BPoolRegistered): void {
|
|||||||
factory.save()
|
factory.save()
|
||||||
|
|
||||||
PoolContract.create(event.params.bpoolAddress)
|
PoolContract.create(event.params.bpoolAddress)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
|
import { BigInt, Address, BigDecimal } from '@graphprotocol/graph-ts'
|
||||||
import {BigInt, Address, BigDecimal} from '@graphprotocol/graph-ts'
|
import {
|
||||||
import { LOG_CALL, LOG_JOIN, LOG_EXIT, LOG_SWAP, Transfer } from '../types/templates/Pool/Pool'
|
LOG_CALL,
|
||||||
import { log } from '@graphprotocol/graph-ts'
|
LOG_JOIN,
|
||||||
|
LOG_EXIT,
|
||||||
|
LOG_SWAP,
|
||||||
|
Transfer
|
||||||
|
} from '../types/templates/Pool/Pool'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
PoolFactory,
|
PoolFactory,
|
||||||
@ -22,16 +26,20 @@ import {
|
|||||||
updatePoolTransactionToken,
|
updatePoolTransactionToken,
|
||||||
createPoolTransaction,
|
createPoolTransaction,
|
||||||
OCEAN,
|
OCEAN,
|
||||||
debuglog, updatePoolTokenBalance
|
debuglog,
|
||||||
} from './helpers'
|
updatePoolTokenBalance
|
||||||
|
} from '../helpers'
|
||||||
|
|
||||||
/************************************
|
/************************************
|
||||||
********** Pool Controls ***********
|
********** Pool Controls ***********
|
||||||
************************************/
|
************************************/
|
||||||
|
|
||||||
export function handleSetSwapFee(event: LOG_CALL, swapFeeStr: string=null): void {
|
export function handleSetSwapFee(
|
||||||
let poolId = event.address.toHex()
|
event: LOG_CALL,
|
||||||
let pool = Pool.load(poolId)
|
swapFeeStr: string = null
|
||||||
|
): void {
|
||||||
|
const poolId = event.address.toHex()
|
||||||
|
const pool = Pool.load(poolId)
|
||||||
if (!swapFeeStr) {
|
if (!swapFeeStr) {
|
||||||
swapFeeStr = event.params.data.toHexString().slice(-40)
|
swapFeeStr = event.params.data.toHexString().slice(-40)
|
||||||
}
|
}
|
||||||
@ -40,98 +48,58 @@ export function handleSetSwapFee(event: LOG_CALL, swapFeeStr: string=null): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function handleSetController(event: LOG_CALL): void {
|
export function handleSetController(event: LOG_CALL): void {
|
||||||
let poolId = event.address.toHex()
|
const poolId = event.address.toHex()
|
||||||
let pool = Pool.load(poolId)
|
const 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()
|
pool.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleSetPublicSwap(event: LOG_CALL): void {
|
export function handleSetPublicSwap(event: LOG_CALL): void {
|
||||||
let poolId = event.address.toHex()
|
const poolId = event.address.toHex()
|
||||||
let pool = Pool.load(poolId)
|
const pool = Pool.load(poolId)
|
||||||
pool.publicSwap = event.params.data.toHexString().slice(-1) == '1'
|
pool.publicSwap = event.params.data.toHexString().slice(-1) === '1'
|
||||||
pool.save()
|
pool.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleFinalize(event: LOG_CALL): void {
|
export function handleFinalize(event: LOG_CALL): void {
|
||||||
let poolId = event.address.toHex()
|
const poolId = event.address.toHex()
|
||||||
let pool = Pool.load(poolId)
|
const pool = Pool.load(poolId)
|
||||||
pool.finalized = true
|
pool.finalized = true
|
||||||
pool.symbol = 'BPT'
|
pool.symbol = 'BPT'
|
||||||
pool.publicSwap = true
|
pool.publicSwap = true
|
||||||
pool.save()
|
pool.save()
|
||||||
|
|
||||||
let factory = PoolFactory.load('1')
|
const factory = PoolFactory.load('1')
|
||||||
factory.finalizedPoolCount = factory.finalizedPoolCount + 1
|
factory.finalizedPoolCount = factory.finalizedPoolCount + 1
|
||||||
factory.save()
|
factory.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleSetup(event: LOG_CALL): void {
|
export function _handleRebind(
|
||||||
let poolId = event.address.toHex()
|
event: LOG_CALL,
|
||||||
debuglog('handleSetup: ', event, [])
|
poolId: string,
|
||||||
let data = event.params.data.toHexString()
|
tokenAddress: string,
|
||||||
// First 2 chars are 0x
|
balanceStr: string,
|
||||||
// Next there is 8 chars
|
denormWeightStr: string
|
||||||
// Next starts the data each params occupies exactly 64 chars
|
): void {
|
||||||
// Each value is padded with 0s to the left
|
const pool = Pool.load(poolId)
|
||||||
// For an Address, need to remove the leading 24 zeros, because the address itself is 40 chars
|
const decimals = BigInt.fromI32(18).toI32()
|
||||||
// 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)
|
if (tokenAddress !== OCEAN) {
|
||||||
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 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)
|
|
||||||
handleSetSwapFee(event, swapFee)
|
|
||||||
handleFinalize(event)
|
|
||||||
createPoolTransaction(event, 'setup', event.transaction.from.toHex())
|
|
||||||
|
|
||||||
// update base token
|
|
||||||
let amount = hexToDecimal(baseTokenAmount, 18)
|
|
||||||
|
|
||||||
updatePoolTransactionToken(
|
|
||||||
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,
|
|
||||||
ZERO_BD
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 ) {
|
|
||||||
pool.datatokenAddress = tokenAddress
|
pool.datatokenAddress = tokenAddress
|
||||||
}
|
}
|
||||||
pool.tokenCount += BigInt.fromI32(1)
|
pool.tokenCount += BigInt.fromI32(1)
|
||||||
let address = Address.fromString(tokenAddress)
|
const address = Address.fromString(tokenAddress)
|
||||||
let denormWeight = hexToDecimal(denormWeightStr, decimals)
|
const denormWeight = hexToDecimal(denormWeightStr, decimals)
|
||||||
let poolTokenId = poolId.concat('-').concat(address.toHexString())
|
const poolTokenId = poolId.concat('-').concat(address.toHexString())
|
||||||
let poolToken = PoolToken.load(poolTokenId)
|
let poolToken = PoolToken.load(poolTokenId)
|
||||||
if (poolToken == null) {
|
if (poolToken == null) {
|
||||||
createPoolTokenEntity(poolTokenId, poolId, address.toHexString())
|
createPoolTokenEntity(poolTokenId, poolId, address.toHexString())
|
||||||
poolToken = PoolToken.load(poolTokenId)
|
poolToken = PoolToken.load(poolTokenId)
|
||||||
pool.totalWeight += denormWeight
|
pool.totalWeight += denormWeight
|
||||||
} else {
|
} else {
|
||||||
let oldWeight = poolToken.denormWeight
|
const oldWeight = poolToken.denormWeight
|
||||||
if (denormWeight > oldWeight) {
|
if (denormWeight > oldWeight) {
|
||||||
pool.totalWeight = pool.totalWeight + (denormWeight - oldWeight)
|
pool.totalWeight = pool.totalWeight + (denormWeight - oldWeight)
|
||||||
} else {
|
} else {
|
||||||
@ -140,7 +108,7 @@ export function _handleRebind(event: LOG_CALL, poolId: string, tokenAddress: str
|
|||||||
}
|
}
|
||||||
|
|
||||||
poolToken.denormWeight = denormWeight
|
poolToken.denormWeight = denormWeight
|
||||||
let balance = hexToDecimal(balanceStr, decimals)
|
const balance = hexToDecimal(balanceStr, decimals)
|
||||||
updatePoolTokenBalance(poolToken as PoolToken, balance, '_handleRebind')
|
updatePoolTokenBalance(poolToken as PoolToken, balance, '_handleRebind')
|
||||||
|
|
||||||
poolToken.save()
|
poolToken.save()
|
||||||
@ -152,13 +120,79 @@ export function _handleRebind(event: LOG_CALL, poolId: string, tokenAddress: str
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function handleRebind(event: LOG_CALL): void {
|
export function handleRebind(event: LOG_CALL): void {
|
||||||
let poolId = event.address.toHex()
|
const poolId = event.address.toHex()
|
||||||
_handleRebind(
|
_handleRebind(
|
||||||
event,
|
event,
|
||||||
poolId,
|
poolId,
|
||||||
event.params.data.toHexString().slice(34,74),
|
event.params.data.toHexString().slice(34, 74),
|
||||||
event.params.data.toHexString().slice(74,138),
|
event.params.data.toHexString().slice(74, 138),
|
||||||
event.params.data.toHexString().slice(138)
|
event.params.data.toHexString().slice(138)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleSetup(event: LOG_CALL): void {
|
||||||
|
const poolId = event.address.toHex()
|
||||||
|
debuglog('handleSetup: ', event, [])
|
||||||
|
const data = event.params.data.toHexString()
|
||||||
|
// First 2 chars are 0x
|
||||||
|
// Next there is 8 chars
|
||||||
|
// Next starts the data each params occupies exactly 64 chars
|
||||||
|
// Each value is padded with 0s to the left
|
||||||
|
// For an Address, need to remove the leading 24 zeros, because the address itself is 40 chars
|
||||||
|
// 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)
|
||||||
|
const dataTokenAddress = Address.fromString(data.slice(34, 74)).toHexString()
|
||||||
|
|
||||||
|
const dataTokenAmount = data.slice(74, 138) // 74+64
|
||||||
|
const dataTokenWeight = data.slice(138, 202) // (74+64,74+(2*64)
|
||||||
|
const baseTokenAddress = Address.fromString(
|
||||||
|
data.slice(202 + 24, 266)
|
||||||
|
).toHexString() // (74+(2*64)+24, 74+(3*64))
|
||||||
|
const baseTokenAmount = data.slice(266, 330) // (74+(3*64),74+(4*64))
|
||||||
|
const baseTokenWeight = data.slice(330, 394) // (74+(4*64),74+(5*64))
|
||||||
|
const swapFee = data.slice(394) // (74+(5*64), END)
|
||||||
|
|
||||||
|
const poolTokenId = poolId.concat('-').concat(baseTokenAddress)
|
||||||
|
const poolToken = PoolToken.load(poolTokenId)
|
||||||
|
if (poolToken != null) return
|
||||||
|
|
||||||
|
_handleRebind(
|
||||||
|
event,
|
||||||
|
poolId,
|
||||||
|
dataTokenAddress,
|
||||||
|
dataTokenAmount,
|
||||||
|
dataTokenWeight
|
||||||
|
)
|
||||||
|
_handleRebind(
|
||||||
|
event,
|
||||||
|
poolId,
|
||||||
|
baseTokenAddress,
|
||||||
|
baseTokenAmount,
|
||||||
|
baseTokenWeight
|
||||||
|
)
|
||||||
|
handleSetSwapFee(event, swapFee)
|
||||||
|
handleFinalize(event)
|
||||||
|
createPoolTransaction(event, 'setup', event.transaction.from.toHex())
|
||||||
|
|
||||||
|
// update base token
|
||||||
|
let amount = hexToDecimal(baseTokenAmount, 18)
|
||||||
|
|
||||||
|
updatePoolTransactionToken(
|
||||||
|
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,
|
||||||
|
ZERO_BD
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,68 +201,100 @@ export function handleRebind(event: LOG_CALL): void {
|
|||||||
************************************/
|
************************************/
|
||||||
|
|
||||||
export function handleJoinPool(event: LOG_JOIN): void {
|
export function handleJoinPool(event: LOG_JOIN): void {
|
||||||
let poolId = event.address.toHex()
|
const poolId = event.address.toHex()
|
||||||
|
|
||||||
let pool = Pool.load(poolId)
|
const pool = Pool.load(poolId)
|
||||||
if (pool.finalized == false){
|
if (pool.finalized === false) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pool.joinCount = pool.joinCount.plus(BigInt.fromI32(1))
|
pool.joinCount = pool.joinCount.plus(BigInt.fromI32(1))
|
||||||
pool.save()
|
pool.save()
|
||||||
let ptx = event.transaction.hash.toHexString()
|
const ptx = event.transaction.hash.toHexString()
|
||||||
let poolTx = PoolTransaction.load(ptx)
|
const poolTx = PoolTransaction.load(ptx)
|
||||||
if (poolTx != null) {
|
if (poolTx != null) {
|
||||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! PoolTransaction EXISTS: ', event, [])
|
debuglog(
|
||||||
|
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! PoolTransaction EXISTS: ',
|
||||||
|
event,
|
||||||
|
[]
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let address = event.params.tokenIn.toHex()
|
const address = event.params.tokenIn.toHex()
|
||||||
let poolTokenId = poolId.concat('-').concat(address)
|
const poolTokenId = poolId.concat('-').concat(address)
|
||||||
let poolToken = PoolToken.load(poolTokenId)
|
const poolToken = PoolToken.load(poolTokenId)
|
||||||
if (poolToken == null) {
|
if (poolToken == null) {
|
||||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! NO PoolToken: ', event, [address, poolTokenId])
|
debuglog(
|
||||||
|
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! NO PoolToken: ',
|
||||||
|
event,
|
||||||
|
[address, poolTokenId]
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let datatoken: Datatoken | null
|
const datatoken: Datatoken =
|
||||||
datatoken = poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||||
let decimals = datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
const decimals =
|
||||||
let tokenAmountIn = tokenToDecimal(event.params.tokenAmountIn.toBigDecimal(), decimals)
|
datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||||
updatePoolTokenBalance(poolToken as PoolToken, poolToken.balance.plus(tokenAmountIn), 'handleJoinPool')
|
const tokenAmountIn = tokenToDecimal(
|
||||||
debuglog('!!!!!!!!!!!!!!!!!! JOIN JOIN JOIN : (token, amountIn, amountIn) ', event,
|
event.params.tokenAmountIn.toBigDecimal(),
|
||||||
[address, tokenAmountIn.toString(), event.params.tokenAmountIn.toString()])
|
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()
|
poolToken.save()
|
||||||
createPoolTransaction(event, 'join', event.params.caller.toHexString())
|
createPoolTransaction(event, 'join', event.params.caller.toHexString())
|
||||||
updatePoolTransactionToken(
|
updatePoolTransactionToken(
|
||||||
event.transaction.hash.toHexString(), poolTokenId,
|
event.transaction.hash.toHexString(),
|
||||||
tokenAmountIn, poolToken.balance,
|
poolTokenId,
|
||||||
|
tokenAmountIn,
|
||||||
|
poolToken.balance,
|
||||||
tokenAmountIn.times(pool.swapFee)
|
tokenAmountIn.times(pool.swapFee)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleExitPool(event: LOG_EXIT): void {
|
export function handleExitPool(event: LOG_EXIT): void {
|
||||||
let poolId = event.address.toHex()
|
const poolId = event.address.toHex()
|
||||||
|
|
||||||
let address = event.params.tokenOut.toHex()
|
const address = event.params.tokenOut.toHex()
|
||||||
let poolTokenId = poolId.concat('-').concat(address.toString())
|
const poolTokenId = poolId.concat('-').concat(address.toString())
|
||||||
let poolToken = PoolToken.load(poolTokenId)
|
const poolToken = PoolToken.load(poolTokenId)
|
||||||
if (!poolToken) {
|
if (!poolToken) {
|
||||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! EXIT EXIT EXIT !!!!!!!!!!!! NO PoolToken: ', event, [address, poolTokenId])
|
debuglog(
|
||||||
|
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! EXIT EXIT EXIT !!!!!!!!!!!! NO PoolToken: ',
|
||||||
|
event,
|
||||||
|
[address, poolTokenId]
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let datatoken: Datatoken | null
|
const datatoken: Datatoken =
|
||||||
datatoken = poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||||
let decimals = datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
const decimals =
|
||||||
let tokenAmountOut = tokenToDecimal(event.params.tokenAmountOut.toBigDecimal(), decimals)
|
datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||||
let newAmount = poolToken.balance.minus(tokenAmountOut)
|
const tokenAmountOut = tokenToDecimal(
|
||||||
|
event.params.tokenAmountOut.toBigDecimal(),
|
||||||
|
decimals
|
||||||
|
)
|
||||||
|
const newAmount = poolToken.balance.minus(tokenAmountOut)
|
||||||
updatePoolTokenBalance(poolToken as PoolToken, newAmount, 'handleExitPool')
|
updatePoolTokenBalance(poolToken as PoolToken, newAmount, 'handleExitPool')
|
||||||
poolToken.save()
|
poolToken.save()
|
||||||
debuglog('!!!!!!!!!!!!!!!!!! EXIT EXIT EXIT : (token, amountOut, amountOut)', event,
|
debuglog(
|
||||||
[address, tokenAmountOut.toString(), event.params.tokenAmountOut.toString()])
|
'!!!!!!!!!!!!!!!!!! EXIT EXIT EXIT : (token, amountOut, amountOut)',
|
||||||
let pool = Pool.load(poolId)
|
event,
|
||||||
|
[address, tokenAmountOut.toString(), event.params.tokenAmountOut.toString()]
|
||||||
|
)
|
||||||
|
const pool = Pool.load(poolId)
|
||||||
pool.exitCount = pool.exitCount.plus(BigInt.fromI32(1))
|
pool.exitCount = pool.exitCount.plus(BigInt.fromI32(1))
|
||||||
if (newAmount.equals(ZERO_BD)) {
|
if (newAmount.equals(ZERO_BD)) {
|
||||||
decrPoolCount(pool.finalized)
|
decrPoolCount(pool.finalized)
|
||||||
@ -238,8 +304,10 @@ export function handleExitPool(event: LOG_EXIT): void {
|
|||||||
|
|
||||||
createPoolTransaction(event, 'exit', event.params.caller.toHexString())
|
createPoolTransaction(event, 'exit', event.params.caller.toHexString())
|
||||||
updatePoolTransactionToken(
|
updatePoolTransactionToken(
|
||||||
event.transaction.hash.toHexString(), poolTokenId,
|
event.transaction.hash.toHexString(),
|
||||||
tokenAmountOut.times(MINUS_1_BD), poolToken.balance,
|
poolTokenId,
|
||||||
|
tokenAmountOut.times(MINUS_1_BD),
|
||||||
|
poolToken.balance,
|
||||||
tokenAmountOut.times(pool.swapFee)
|
tokenAmountOut.times(pool.swapFee)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -249,35 +317,61 @@ export function handleExitPool(event: LOG_EXIT): void {
|
|||||||
************************************/
|
************************************/
|
||||||
|
|
||||||
export function handleSwap(event: LOG_SWAP): void {
|
export function handleSwap(event: LOG_SWAP): void {
|
||||||
let poolId = event.address.toHex()
|
const poolId = event.address.toHex()
|
||||||
let ptx = event.transaction.hash.toHexString()
|
const ptx = event.transaction.hash.toHexString()
|
||||||
|
|
||||||
let tokenIn = event.params.tokenIn.toHex()
|
const tokenIn = event.params.tokenIn.toHex()
|
||||||
let poolTokenInId = poolId.concat('-').concat(tokenIn.toString())
|
const poolTokenInId = poolId.concat('-').concat(tokenIn.toString())
|
||||||
let poolTokenIn = PoolToken.load(poolTokenInId)
|
const poolTokenIn = PoolToken.load(poolTokenInId)
|
||||||
if (!poolTokenIn) {
|
if (!poolTokenIn) {
|
||||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! SWAP SWAP SWAP !!!!!!!!!!!! NO PoolToken: ', event,
|
debuglog(
|
||||||
[tokenIn, poolTokenInId])
|
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! SWAP SWAP SWAP !!!!!!!!!!!! NO PoolToken: ',
|
||||||
|
event,
|
||||||
|
[tokenIn, poolTokenInId]
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let dtIn = Datatoken.load(tokenIn)
|
const dtIn = Datatoken.load(tokenIn)
|
||||||
let tokenAmountIn = tokenToDecimal(event.params.tokenAmountIn.toBigDecimal(), (dtIn == null) ? 18 : dtIn.decimals)
|
const tokenAmountIn = tokenToDecimal(
|
||||||
let newAmountIn = poolTokenIn.balance.plus(tokenAmountIn)
|
event.params.tokenAmountIn.toBigDecimal(),
|
||||||
updatePoolTokenBalance(poolTokenIn as PoolToken, newAmountIn, 'handleSwap.tokenIn')
|
dtIn == null ? 18 : dtIn.decimals
|
||||||
|
)
|
||||||
|
const newAmountIn = poolTokenIn.balance.plus(tokenAmountIn)
|
||||||
|
updatePoolTokenBalance(
|
||||||
|
poolTokenIn as PoolToken,
|
||||||
|
newAmountIn,
|
||||||
|
'handleSwap.tokenIn'
|
||||||
|
)
|
||||||
poolTokenIn.save()
|
poolTokenIn.save()
|
||||||
|
|
||||||
let tokenOut = event.params.tokenOut.toHex()
|
const tokenOut = event.params.tokenOut.toHex()
|
||||||
let poolTokenOutId = poolId.concat('-').concat(tokenOut.toString())
|
const poolTokenOutId = poolId.concat('-').concat(tokenOut.toString())
|
||||||
let poolTokenOut = PoolToken.load(poolTokenOutId)
|
const poolTokenOut = PoolToken.load(poolTokenOutId)
|
||||||
let dtOut = Datatoken.load(tokenOut)
|
const dtOut = Datatoken.load(tokenOut)
|
||||||
let tokenAmountOut = tokenToDecimal(event.params.tokenAmountOut.toBigDecimal(), (dtOut == null) ? 18 : dtOut.decimals)
|
const tokenAmountOut = tokenToDecimal(
|
||||||
let newAmountOut = poolTokenOut.balance.minus(tokenAmountOut)
|
event.params.tokenAmountOut.toBigDecimal(),
|
||||||
updatePoolTokenBalance(poolTokenOut as PoolToken, newAmountOut, 'handleSwap.tokenOut')
|
dtOut == null ? 18 : dtOut.decimals
|
||||||
|
)
|
||||||
|
const newAmountOut = poolTokenOut.balance.minus(tokenAmountOut)
|
||||||
|
updatePoolTokenBalance(
|
||||||
|
poolTokenOut as PoolToken,
|
||||||
|
newAmountOut,
|
||||||
|
'handleSwap.tokenOut'
|
||||||
|
)
|
||||||
poolTokenOut.save()
|
poolTokenOut.save()
|
||||||
debuglog('!!!!!!!!!!!!!!!!!! SWAP SWAP SWAP : (tokenIn, tokenOut, amountIn, amountIn, amountOut, amountOut)', event,
|
debuglog(
|
||||||
[tokenIn, tokenOut, tokenAmountIn.toString(), event.params.tokenAmountIn.toString(),
|
'!!!!!!!!!!!!!!!!!! SWAP SWAP SWAP : (tokenIn, tokenOut, amountIn, amountIn, amountOut, amountOut)',
|
||||||
tokenAmountOut.toString(), event.params.tokenAmountOut.toString()])
|
event,
|
||||||
let pool = Pool.load(poolId)
|
[
|
||||||
|
tokenIn,
|
||||||
|
tokenOut,
|
||||||
|
tokenAmountIn.toString(),
|
||||||
|
event.params.tokenAmountIn.toString(),
|
||||||
|
tokenAmountOut.toString(),
|
||||||
|
event.params.tokenAmountOut.toString()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
const pool = Pool.load(poolId)
|
||||||
|
|
||||||
pool.swapCount = pool.swapCount.plus(BigInt.fromI32(1))
|
pool.swapCount = pool.swapCount.plus(BigInt.fromI32(1))
|
||||||
if (newAmountIn.equals(ZERO_BD) || newAmountOut.equals(ZERO_BD)) {
|
if (newAmountIn.equals(ZERO_BD) || newAmountOut.equals(ZERO_BD)) {
|
||||||
@ -288,36 +382,45 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||||||
|
|
||||||
createPoolTransaction(event, 'swap', event.params.caller.toHexString())
|
createPoolTransaction(event, 'swap', event.params.caller.toHexString())
|
||||||
updatePoolTransactionToken(
|
updatePoolTransactionToken(
|
||||||
ptx, poolTokenIn.id, tokenAmountIn, poolTokenIn.balance,
|
ptx,
|
||||||
tokenAmountIn.times(pool.swapFee))
|
poolTokenIn.id,
|
||||||
|
tokenAmountIn,
|
||||||
|
poolTokenIn.balance,
|
||||||
|
tokenAmountIn.times(pool.swapFee)
|
||||||
|
)
|
||||||
updatePoolTransactionToken(
|
updatePoolTransactionToken(
|
||||||
ptx, poolTokenOut.id, tokenAmountOut.times(MINUS_1_BD), poolTokenOut.balance,
|
ptx,
|
||||||
BigDecimal.fromString('0.0'))
|
poolTokenOut.id,
|
||||||
|
tokenAmountOut.times(MINUS_1_BD),
|
||||||
|
poolTokenOut.balance,
|
||||||
|
BigDecimal.fromString('0.0')
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************
|
/************************************
|
||||||
*********** POOL SHARES ************
|
*********** POOL SHARES ************
|
||||||
************************************/
|
************************************/
|
||||||
|
|
||||||
export function handleTransfer(event: Transfer): void {
|
export function handleTransfer(event: Transfer): void {
|
||||||
let poolId = event.address.toHex()
|
const poolId = event.address.toHex()
|
||||||
|
|
||||||
let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||||
|
|
||||||
let isMint = event.params.from.toHex() == ZERO_ADDRESS
|
const isMint = event.params.from.toHex() === ZERO_ADDRESS
|
||||||
let isBurn = event.params.to.toHex() == ZERO_ADDRESS
|
const isBurn = event.params.to.toHex() === ZERO_ADDRESS
|
||||||
|
|
||||||
let poolShareFromId = poolId.concat('-').concat(event.params.from.toHex())
|
const poolShareFromId = poolId.concat('-').concat(event.params.from.toHex())
|
||||||
let poolShareFrom = PoolShare.load(poolShareFromId)
|
let poolShareFrom = PoolShare.load(poolShareFromId)
|
||||||
let poolShareFromBalance = poolShareFrom == null ? ZERO_BD : poolShareFrom.balance
|
const poolShareFromBalance =
|
||||||
|
poolShareFrom == null ? ZERO_BD : poolShareFrom.balance
|
||||||
|
|
||||||
let poolShareToId = poolId.concat('-').concat(event.params.to.toHex())
|
const poolShareToId = poolId.concat('-').concat(event.params.to.toHex())
|
||||||
let poolShareTo = PoolShare.load(poolShareToId)
|
let poolShareTo = PoolShare.load(poolShareToId)
|
||||||
let poolShareToBalance = poolShareTo == null ? ZERO_BD : poolShareTo.balance
|
const poolShareToBalance = poolShareTo == null ? ZERO_BD : poolShareTo.balance
|
||||||
|
|
||||||
let pool = Pool.load(poolId)
|
const pool = Pool.load(poolId)
|
||||||
let poolTx = PoolTransaction.load(event.transaction.hash.toHexString())
|
const poolTx = PoolTransaction.load(event.transaction.hash.toHexString())
|
||||||
let value = tokenToDecimal(event.params.value.toBigDecimal(), 18)
|
const value = tokenToDecimal(event.params.value.toBigDecimal(), 18)
|
||||||
|
|
||||||
if (isMint) {
|
if (isMint) {
|
||||||
if (poolShareTo == null) {
|
if (poolShareTo == null) {
|
||||||
@ -343,7 +446,6 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||||||
poolTx.sharesTransferAmount = -value
|
poolTx.sharesTransferAmount = -value
|
||||||
poolTx.sharesBalance = poolShareFrom.balance
|
poolTx.sharesBalance = poolShareFrom.balance
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (poolShareTo == null) {
|
if (poolShareTo == null) {
|
||||||
createPoolShareEntity(poolShareToId, poolId, event.params.to.toHex())
|
createPoolShareEntity(poolShareToId, poolId, event.params.to.toHex())
|
||||||
@ -361,17 +463,17 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
poolShareTo !== null
|
poolShareTo !== null &&
|
||||||
&& poolShareTo.balance.notEqual(ZERO_BD)
|
poolShareTo.balance.notEqual(ZERO_BD) &&
|
||||||
&& poolShareToBalance.equals(ZERO_BD)
|
poolShareToBalance.equals(ZERO_BD)
|
||||||
) {
|
) {
|
||||||
pool.holderCount += BigInt.fromI32(1)
|
pool.holderCount += BigInt.fromI32(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
poolShareFrom !== null
|
poolShareFrom !== null &&
|
||||||
&& poolShareFrom.balance.equals(ZERO_BD)
|
poolShareFrom.balance.equals(ZERO_BD) &&
|
||||||
&& poolShareFromBalance.notEqual(ZERO_BD)
|
poolShareFromBalance.notEqual(ZERO_BD)
|
||||||
) {
|
) {
|
||||||
pool.holderCount -= BigInt.fromI32(1)
|
pool.holderCount -= BigInt.fromI32(1)
|
||||||
}
|
}
|
||||||
@ -381,4 +483,4 @@ export function handleSwap(event: LOG_SWAP): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pool.save()
|
pool.save()
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ dataSources:
|
|||||||
name: Factory
|
name: Factory
|
||||||
network: mainnet
|
network: mainnet
|
||||||
source:
|
source:
|
||||||
address: "0xbe0083053744ECb871510C88dC0f6b77Da162706"
|
address: '0xbe0083053744ECb871510C88dC0f6b77Da162706'
|
||||||
abi: Factory
|
abi: Factory
|
||||||
startBlock: 11105585
|
startBlock: 11105585
|
||||||
mapping:
|
mapping:
|
||||||
@ -28,7 +28,7 @@ dataSources:
|
|||||||
name: DTFactory
|
name: DTFactory
|
||||||
network: mainnet
|
network: mainnet
|
||||||
source:
|
source:
|
||||||
address: "0x57317f97E9EA49eBd19f7c9bB7c180b8cDcbDeB9"
|
address: '0x57317f97E9EA49eBd19f7c9bB7c180b8cDcbDeB9'
|
||||||
abi: DTFactory
|
abi: DTFactory
|
||||||
startBlock: 11105560
|
startBlock: 11105560
|
||||||
mapping:
|
mapping:
|
||||||
@ -66,25 +66,25 @@ templates:
|
|||||||
file: ./abis/BToken.json
|
file: ./abis/BToken.json
|
||||||
eventHandlers:
|
eventHandlers:
|
||||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||||
topic0: "0x34e1990700000000000000000000000000000000000000000000000000000000"
|
topic0: '0x34e1990700000000000000000000000000000000000000000000000000000000'
|
||||||
handler: handleSetSwapFee
|
handler: handleSetSwapFee
|
||||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||||
topic0: "0x92eefe9b00000000000000000000000000000000000000000000000000000000"
|
topic0: '0x92eefe9b00000000000000000000000000000000000000000000000000000000'
|
||||||
handler: handleSetController
|
handler: handleSetController
|
||||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||||
topic0: "0x49b5955200000000000000000000000000000000000000000000000000000000"
|
topic0: '0x49b5955200000000000000000000000000000000000000000000000000000000'
|
||||||
handler: handleSetPublicSwap
|
handler: handleSetPublicSwap
|
||||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||||
topic0: "0x4bb278f300000000000000000000000000000000000000000000000000000000"
|
topic0: '0x4bb278f300000000000000000000000000000000000000000000000000000000'
|
||||||
handler: handleFinalize
|
handler: handleFinalize
|
||||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||||
topic0: "0xd1d7bc9100000000000000000000000000000000000000000000000000000000"
|
topic0: '0xd1d7bc9100000000000000000000000000000000000000000000000000000000'
|
||||||
handler: handleSetup
|
handler: handleSetup
|
||||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||||
topic0: "0x3fdddaa200000000000000000000000000000000000000000000000000000000"
|
topic0: '0x3fdddaa200000000000000000000000000000000000000000000000000000000'
|
||||||
handler: handleRebind
|
handler: handleRebind
|
||||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||||
topic0: "0xe4e1e53800000000000000000000000000000000000000000000000000000000"
|
topic0: '0xe4e1e53800000000000000000000000000000000000000000000000000000000'
|
||||||
handler: handleRebind
|
handler: handleRebind
|
||||||
- event: LOG_JOIN(indexed address,indexed address,uint256)
|
- event: LOG_JOIN(indexed address,indexed address,uint256)
|
||||||
handler: handleJoinPool
|
handler: handleJoinPool
|
||||||
|
@ -1,23 +1,6 @@
|
|||||||
{
|
{
|
||||||
"extends": "./node_modules/@graphprotocol/graph-ts/tsconfig.json",
|
"extend": "./node_modules/@graphprotocol/graph-ts/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"types": ["@graphprotocol/graph-ts"],
|
"types": ["@graphprotocol/graph-ts"]
|
||||||
"resolveJsonModule": true,
|
}
|
||||||
"moduleResolution": "node",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"lib": ["es5", "dom"],
|
|
||||||
"declaration": true,
|
|
||||||
"module": "commonjs",
|
|
||||||
"target": "es5",
|
|
||||||
"removeComments": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"preserveConstEnums": true,
|
|
||||||
"outDir": "./dist/node/",
|
|
||||||
"rootDir": "./src/",
|
|
||||||
"sourceMap": true,
|
|
||||||
"typeRoots": ["node_modules/@types"]
|
|
||||||
},
|
|
||||||
"include": ["src/**/*"],
|
|
||||||
"exclude": ["node_modules", "**/*.test.ts"]
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user