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
|
169
README.md
169
README.md
@ -1,14 +1,87 @@
|
||||
# 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
|
||||
```bash
|
||||
npm install -g @graphprotocol/graph-cli
|
||||
> 🦀 Ocean Protocol Subgraph
|
||||
|
||||
[![Build Status](https://travis-ci.com/oceanprotocol/ocean-subgraph.svg&branch=main)](https://travis-ci.com/oceanprotocol/ocean.js)
|
||||
[![js oceanprotocol](https://img.shields.io/badge/js-oceanprotocol-7b1173.svg)](https://github.com/oceanprotocol/eslint-config-oceanprotocol)
|
||||
|
||||
- [🏄 Get Started](#-get-started)
|
||||
- [🧶 Example Queries](#-example-queries)
|
||||
- [🦑 Development](#-development)
|
||||
- [✨ Code Style](#-code-style)
|
||||
- [⬆️ Releases](#️-releases)
|
||||
- [🛳 Production](#-production)
|
||||
- [⬆️ Deployment](#️-deployment)
|
||||
- [🏛 License](#-license)
|
||||
|
||||
## 🏄 Get Started
|
||||
|
||||
This subgraph is deployed for all networks the Ocean Protocol contracts are deployed to:
|
||||
|
||||
- [subgraph.mainnet.oceanprotocol.com](https://subgraph.mainnet.oceanprotocol.com)
|
||||
- [subgraph.ropsten.oceanprotocol.com](https://subgraph.ropsten.oceanprotocol.com)
|
||||
- [subgraph.rinkeby.oceanprotocol.com](https://subgraph.ropsten.oceanprotocol.com)
|
||||
|
||||
## 🧶 Example Queries
|
||||
|
||||
**All pools**
|
||||
|
||||
```graphql
|
||||
{
|
||||
pools(orderBy: oceanReserve, orderDirection: desc) {
|
||||
consumePrice
|
||||
datatokenReserve
|
||||
oceanReserve
|
||||
spotPrice
|
||||
swapFee
|
||||
transactionCount
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
* Install/run the Graph: `https://thegraph.com/docs/quick-start`
|
||||
* You can skip running ganache-cli and connect directly to `mainnet` using Infura
|
||||
**All datatokens**
|
||||
|
||||
```graphql
|
||||
{
|
||||
datatokens(orderBy: createTime, orderDirection: desc) {
|
||||
address
|
||||
symbol
|
||||
name
|
||||
cap
|
||||
supply
|
||||
publisher
|
||||
holderCount
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**All pool transactions for a given user**
|
||||
|
||||
```graphql
|
||||
{
|
||||
poolTransactions(
|
||||
where: { userAddressStr: $userAddress }
|
||||
orderBy: timestamp
|
||||
orderDirection: desc
|
||||
) {
|
||||
poolAddressStr
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> Note: all ETH addresses like `$userAddress` in above example need to be passed in lowercase.
|
||||
|
||||
## 🦑 Development
|
||||
|
||||
```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
|
||||
git clone https://github.com/graphprotocol/graph-node/
|
||||
@ -17,15 +90,9 @@ cd graph-node/docker
|
||||
# Update this line in the `docker-compose.yml` file with your Infura ProjectId
|
||||
# ethereum: 'mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID'
|
||||
docker-compose up
|
||||
|
||||
```
|
||||
|
||||
Note: making contract calls using Infura fails with `missing trie node` errors.
|
||||
The fix requires editing `ethereum_adapter.rs` line 434 to use the latest block
|
||||
instead of a specific block number.
|
||||
Replace:
|
||||
`web3.eth().call(req, Some(block_id)).then(|result| {`
|
||||
with `web3.eth().call(req, Some(BlockNumber::Latest.into())).then(|result| {`
|
||||
Note: making contract calls using Infura fails with `missing trie node` errors. The fix requires editing `ethereum_adapter.rs` line 434 to use the latest block instead of a specific block number. Replace: `web3.eth().call(req, Some(block_id)).then(|result| {` with `web3.eth().call(req, Some(BlockNumber::Latest.into())).then(|result| {`
|
||||
|
||||
To run the graph-node with this fix it must be run from source.
|
||||
|
||||
@ -33,6 +100,7 @@ First, delete the `graph-node` container from the `docker-compose.yml` file
|
||||
then run `docker-compose up` to get the postgresql and ipfs services running.
|
||||
|
||||
Now you can build and run the graph-node from source
|
||||
|
||||
```
|
||||
cargo run -p graph-node --release > graphnode.log --
|
||||
--postgres-url postgres://graph-node:let-me-in@localhost:5432/graph-node
|
||||
@ -40,7 +108,8 @@ cargo run -p graph-node --release > graphnode.log --
|
||||
--ipfs 127.0.0.1:5001
|
||||
```
|
||||
|
||||
* Once the graph node is ready, do the following to deploy the ocean-subgraph to the local graph-node
|
||||
- Once the graph node is ready, do the following to deploy the ocean-subgraph to the local graph-node
|
||||
|
||||
```bash
|
||||
git clone https://github.com/oceanprotocol/ocean-subgraph/
|
||||
cd ocean-subgraph
|
||||
@ -48,14 +117,66 @@ npm i
|
||||
npm run codegen
|
||||
npm run create:local
|
||||
npm run deploy:local
|
||||
|
||||
```
|
||||
|
||||
* You can edit the event handler code and then run `npm run deploy:local`
|
||||
* Running deploy will fail if the code has no changes
|
||||
* Sometimes deploy will fail no matter what, in this case:
|
||||
* Stop the docker-compose run (`docker-compose down`)
|
||||
* Delete the `ipfs` and `postgres` folders in `graph-node/docker/data`
|
||||
* Restart docker-compose
|
||||
* Run `npm run create:local` to create the ocean-subgraph
|
||||
* Run `npm run deploy:local` to deploy the ocean-subgraph
|
||||
- You can edit the event handler code and then run `npm run deploy:local`
|
||||
- Running deploy will fail if the code has no changes
|
||||
- Sometimes deploy will fail no matter what, in this case:
|
||||
- Stop the docker-compose run (`docker-compose down`)
|
||||
- Delete the `ipfs` and `postgres` folders in `graph-node/docker/data`
|
||||
- Restart docker-compose
|
||||
- Run `npm run create:local` to create the ocean-subgraph
|
||||
- Run `npm run deploy:local` to deploy the ocean-subgraph
|
||||
|
||||
## ✨ Code Style
|
||||
|
||||
For linting and auto-formatting you can use from the root of the project:
|
||||
|
||||
```bash
|
||||
# lint all js with eslint
|
||||
npm run lint
|
||||
|
||||
# auto format all js & css with prettier, taking all configs into account
|
||||
npm run format
|
||||
```
|
||||
|
||||
## ⬆️ Releases
|
||||
|
||||
Releases are managed semi-automatically. They are always manually triggered from a developer's machine with release scripts. From a clean `main` branch you can run the release task bumping the version accordingly based on semantic versioning:
|
||||
|
||||
```bash
|
||||
npm run release
|
||||
```
|
||||
|
||||
The task does the following:
|
||||
|
||||
- bumps the project version in `package.json`, `package-lock.json`
|
||||
- auto-generates and updates the CHANGELOG.md file from commit messages
|
||||
- creates a Git tag
|
||||
- commits and pushes everything
|
||||
- creates a GitHub release with commit messages as description
|
||||
- Git tag push will trigger Travis to do a npm release
|
||||
|
||||
For the GitHub releases steps a GitHub personal access token, exported as `GITHUB_TOKEN` is required. [Setup](https://github.com/release-it/release-it#github-releases)
|
||||
|
||||
## 🛳 Production
|
||||
|
||||
## ⬆️ Deployment
|
||||
|
||||
## 🏛 License
|
||||
|
||||
```
|
||||
Copyright ((C)) 2020 Ocean Protocol Foundation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
```
|
||||
|
@ -321,20 +321,14 @@
|
||||
"ast": {
|
||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BFactory.sol",
|
||||
"exportedSymbols": {
|
||||
"BFactory": [
|
||||
376
|
||||
]
|
||||
"BFactory": [376]
|
||||
},
|
||||
"id": 377,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 282,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"0.5",
|
||||
".7"
|
||||
],
|
||||
"literals": ["solidity", "0.5", ".7"],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "0:22:3"
|
||||
},
|
||||
@ -410,19 +404,12 @@
|
||||
"src": "679:8:3"
|
||||
}
|
||||
],
|
||||
"contractDependencies": [
|
||||
280,
|
||||
5731
|
||||
],
|
||||
"contractDependencies": [280, 5731],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 376,
|
||||
"linearizedBaseContracts": [
|
||||
376,
|
||||
5731,
|
||||
280
|
||||
],
|
||||
"linearizedBaseContracts": [376, 5731, 280],
|
||||
"name": "BFactory",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
@ -726,10 +713,7 @@
|
||||
"id": 308,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "1176:7:3",
|
||||
"typeDescriptions": {
|
||||
@ -1069,10 +1053,7 @@
|
||||
"id": 333,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "1637:7:3",
|
||||
"typeDescriptions": {
|
||||
@ -1099,9 +1080,7 @@
|
||||
"src": "1637:103:3"
|
||||
},
|
||||
{
|
||||
"assignments": [
|
||||
343
|
||||
],
|
||||
"assignments": [343],
|
||||
"declarations": [
|
||||
{
|
||||
"constant": false,
|
||||
@ -1419,10 +1398,7 @@
|
||||
"id": 348,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "1795:7:3",
|
||||
"typeDescriptions": {
|
||||
@ -1671,20 +1647,14 @@
|
||||
"legacyAST": {
|
||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BFactory.sol",
|
||||
"exportedSymbols": {
|
||||
"BFactory": [
|
||||
376
|
||||
]
|
||||
"BFactory": [376]
|
||||
},
|
||||
"id": 377,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 282,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"0.5",
|
||||
".7"
|
||||
],
|
||||
"literals": ["solidity", "0.5", ".7"],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "0:22:3"
|
||||
},
|
||||
@ -1760,19 +1730,12 @@
|
||||
"src": "679:8:3"
|
||||
}
|
||||
],
|
||||
"contractDependencies": [
|
||||
280,
|
||||
5731
|
||||
],
|
||||
"contractDependencies": [280, 5731],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 376,
|
||||
"linearizedBaseContracts": [
|
||||
376,
|
||||
5731,
|
||||
280
|
||||
],
|
||||
"linearizedBaseContracts": [376, 5731, 280],
|
||||
"name": "BFactory",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
@ -2076,10 +2039,7 @@
|
||||
"id": 308,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "1176:7:3",
|
||||
"typeDescriptions": {
|
||||
@ -2419,10 +2379,7 @@
|
||||
"id": 333,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "1637:7:3",
|
||||
"typeDescriptions": {
|
||||
@ -2449,9 +2406,7 @@
|
||||
"src": "1637:103:3"
|
||||
},
|
||||
{
|
||||
"assignments": [
|
||||
343
|
||||
],
|
||||
"assignments": [343],
|
||||
"declarations": [
|
||||
{
|
||||
"constant": false,
|
||||
@ -2769,10 +2724,7 @@
|
||||
"id": 348,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "1795:7:3",
|
||||
"typeDescriptions": {
|
||||
|
150
abis/BToken.json
150
abis/BToken.json
@ -497,23 +497,15 @@
|
||||
"ast": {
|
||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BToken.sol",
|
||||
"exportedSymbols": {
|
||||
"BToken": [
|
||||
4285
|
||||
],
|
||||
"BTokenBase": [
|
||||
3979
|
||||
]
|
||||
"BToken": [4285],
|
||||
"BTokenBase": [3979]
|
||||
},
|
||||
"id": 4286,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 3780,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"0.5",
|
||||
".7"
|
||||
],
|
||||
"literals": ["solidity", "0.5", ".7"],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "643:22:7"
|
||||
},
|
||||
@ -560,19 +552,12 @@
|
||||
"src": "1468:4:7"
|
||||
}
|
||||
],
|
||||
"contractDependencies": [
|
||||
280,
|
||||
1422
|
||||
],
|
||||
"contractDependencies": [280, 1422],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 3979,
|
||||
"linearizedBaseContracts": [
|
||||
3979,
|
||||
1422,
|
||||
280
|
||||
],
|
||||
"linearizedBaseContracts": [3979, 1422, 280],
|
||||
"name": "BTokenBase",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
@ -1617,10 +1602,7 @@
|
||||
"id": 3855,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2056:7:7",
|
||||
"typeDescriptions": {
|
||||
@ -2312,10 +2294,7 @@
|
||||
"id": 3908,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2410:7:7",
|
||||
"typeDescriptions": {
|
||||
@ -3312,23 +3291,12 @@
|
||||
"src": "2843:6:7"
|
||||
}
|
||||
],
|
||||
"contractDependencies": [
|
||||
280,
|
||||
1422,
|
||||
3979,
|
||||
6537
|
||||
],
|
||||
"contractDependencies": [280, 1422, 3979, 6537],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 4285,
|
||||
"linearizedBaseContracts": [
|
||||
4285,
|
||||
6537,
|
||||
3979,
|
||||
1422,
|
||||
280
|
||||
],
|
||||
"linearizedBaseContracts": [4285, 6537, 3979, 1422, 280],
|
||||
"name": "BToken",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
@ -4299,9 +4267,7 @@
|
||||
"id": 4070,
|
||||
"name": "Approval",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6536
|
||||
],
|
||||
"overloadedDeclarations": [6536],
|
||||
"referencedDeclaration": 6536,
|
||||
"src": "3696:8:7",
|
||||
"typeDescriptions": {
|
||||
@ -4852,9 +4818,7 @@
|
||||
"id": 4106,
|
||||
"name": "Approval",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6536
|
||||
],
|
||||
"overloadedDeclarations": [6536],
|
||||
"referencedDeclaration": 6536,
|
||||
"src": "3926:8:7",
|
||||
"typeDescriptions": {
|
||||
@ -5019,9 +4983,7 @@
|
||||
"src": "4087:315:7",
|
||||
"statements": [
|
||||
{
|
||||
"assignments": [
|
||||
4131
|
||||
],
|
||||
"assignments": [4131],
|
||||
"declarations": [
|
||||
{
|
||||
"constant": false,
|
||||
@ -5639,9 +5601,7 @@
|
||||
"id": 4166,
|
||||
"name": "Approval",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6536
|
||||
],
|
||||
"overloadedDeclarations": [6536],
|
||||
"referencedDeclaration": 6536,
|
||||
"src": "4320:8:7",
|
||||
"typeDescriptions": {
|
||||
@ -6279,10 +6239,7 @@
|
||||
"id": 4211,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "4683:7:7",
|
||||
"typeDescriptions": {
|
||||
@ -7047,9 +7004,7 @@
|
||||
"id": 4267,
|
||||
"name": "Approval",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6536
|
||||
],
|
||||
"overloadedDeclarations": [6536],
|
||||
"referencedDeclaration": 6536,
|
||||
"src": "5017:8:7",
|
||||
"typeDescriptions": {
|
||||
@ -7247,23 +7202,15 @@
|
||||
"legacyAST": {
|
||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/balancer/BToken.sol",
|
||||
"exportedSymbols": {
|
||||
"BToken": [
|
||||
4285
|
||||
],
|
||||
"BTokenBase": [
|
||||
3979
|
||||
]
|
||||
"BToken": [4285],
|
||||
"BTokenBase": [3979]
|
||||
},
|
||||
"id": 4286,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 3780,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"0.5",
|
||||
".7"
|
||||
],
|
||||
"literals": ["solidity", "0.5", ".7"],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "643:22:7"
|
||||
},
|
||||
@ -7310,19 +7257,12 @@
|
||||
"src": "1468:4:7"
|
||||
}
|
||||
],
|
||||
"contractDependencies": [
|
||||
280,
|
||||
1422
|
||||
],
|
||||
"contractDependencies": [280, 1422],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 3979,
|
||||
"linearizedBaseContracts": [
|
||||
3979,
|
||||
1422,
|
||||
280
|
||||
],
|
||||
"linearizedBaseContracts": [3979, 1422, 280],
|
||||
"name": "BTokenBase",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
@ -8367,10 +8307,7 @@
|
||||
"id": 3855,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2056:7:7",
|
||||
"typeDescriptions": {
|
||||
@ -9062,10 +8999,7 @@
|
||||
"id": 3908,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2410:7:7",
|
||||
"typeDescriptions": {
|
||||
@ -10062,23 +9996,12 @@
|
||||
"src": "2843:6:7"
|
||||
}
|
||||
],
|
||||
"contractDependencies": [
|
||||
280,
|
||||
1422,
|
||||
3979,
|
||||
6537
|
||||
],
|
||||
"contractDependencies": [280, 1422, 3979, 6537],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 4285,
|
||||
"linearizedBaseContracts": [
|
||||
4285,
|
||||
6537,
|
||||
3979,
|
||||
1422,
|
||||
280
|
||||
],
|
||||
"linearizedBaseContracts": [4285, 6537, 3979, 1422, 280],
|
||||
"name": "BToken",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
@ -11049,9 +10972,7 @@
|
||||
"id": 4070,
|
||||
"name": "Approval",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6536
|
||||
],
|
||||
"overloadedDeclarations": [6536],
|
||||
"referencedDeclaration": 6536,
|
||||
"src": "3696:8:7",
|
||||
"typeDescriptions": {
|
||||
@ -11602,9 +11523,7 @@
|
||||
"id": 4106,
|
||||
"name": "Approval",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6536
|
||||
],
|
||||
"overloadedDeclarations": [6536],
|
||||
"referencedDeclaration": 6536,
|
||||
"src": "3926:8:7",
|
||||
"typeDescriptions": {
|
||||
@ -11769,9 +11688,7 @@
|
||||
"src": "4087:315:7",
|
||||
"statements": [
|
||||
{
|
||||
"assignments": [
|
||||
4131
|
||||
],
|
||||
"assignments": [4131],
|
||||
"declarations": [
|
||||
{
|
||||
"constant": false,
|
||||
@ -12389,9 +12306,7 @@
|
||||
"id": 4166,
|
||||
"name": "Approval",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6536
|
||||
],
|
||||
"overloadedDeclarations": [6536],
|
||||
"referencedDeclaration": 6536,
|
||||
"src": "4320:8:7",
|
||||
"typeDescriptions": {
|
||||
@ -13029,10 +12944,7 @@
|
||||
"id": 4211,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "4683:7:7",
|
||||
"typeDescriptions": {
|
||||
@ -13797,9 +13709,7 @@
|
||||
"id": 4267,
|
||||
"name": "Approval",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6536
|
||||
],
|
||||
"overloadedDeclarations": [6536],
|
||||
"referencedDeclaration": 6536,
|
||||
"src": "5017:8:7",
|
||||
"typeDescriptions": {
|
||||
|
@ -157,20 +157,14 @@
|
||||
"ast": {
|
||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/DTFactory.sol",
|
||||
"exportedSymbols": {
|
||||
"DTFactory": [
|
||||
158
|
||||
]
|
||||
"DTFactory": [158]
|
||||
},
|
||||
"id": 159,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 1,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"0.5",
|
||||
".7"
|
||||
],
|
||||
"literals": ["solidity", "0.5", ".7"],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "0:22:0"
|
||||
},
|
||||
@ -217,17 +211,12 @@
|
||||
"src": "651:8:0"
|
||||
}
|
||||
],
|
||||
"contractDependencies": [
|
||||
5731
|
||||
],
|
||||
"contractDependencies": [5731],
|
||||
"contractKind": "contract",
|
||||
"documentation": "@title DTFactory contract\n@author Ocean Protocol Team\n * @dev Implementation of Ocean DataTokens Factory\n * DTFactory deploys DataToken proxy contracts.\n New DataToken proxy contracts are links to the template contract's bytecode.\n Proxy contract functionality is based on Ocean Protocol custom implementation of ERC1167 standard.",
|
||||
"fullyImplemented": true,
|
||||
"id": 158,
|
||||
"linearizedBaseContracts": [
|
||||
158,
|
||||
5731
|
||||
],
|
||||
"linearizedBaseContracts": [158, 5731],
|
||||
"name": "DTFactory",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
@ -843,10 +832,7 @@
|
||||
"id": 41,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "1528:7:0",
|
||||
"typeDescriptions": {
|
||||
@ -1139,10 +1125,7 @@
|
||||
"id": 78,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2359:7:0",
|
||||
"typeDescriptions": {
|
||||
@ -1375,10 +1358,7 @@
|
||||
"id": 91,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2499:7:0",
|
||||
"typeDescriptions": {
|
||||
@ -1405,9 +1385,7 @@
|
||||
"src": "2499:124:0"
|
||||
},
|
||||
{
|
||||
"assignments": [
|
||||
101
|
||||
],
|
||||
"assignments": [101],
|
||||
"declarations": [
|
||||
{
|
||||
"constant": false,
|
||||
@ -1694,10 +1672,7 @@
|
||||
"id": 106,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2695:7:0",
|
||||
"typeDescriptions": {
|
||||
@ -2346,20 +2321,14 @@
|
||||
"legacyAST": {
|
||||
"absolutePath": "/home/travis/build/oceanprotocol/ocean-contracts/contracts/DTFactory.sol",
|
||||
"exportedSymbols": {
|
||||
"DTFactory": [
|
||||
158
|
||||
]
|
||||
"DTFactory": [158]
|
||||
},
|
||||
"id": 159,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 1,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"0.5",
|
||||
".7"
|
||||
],
|
||||
"literals": ["solidity", "0.5", ".7"],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "0:22:0"
|
||||
},
|
||||
@ -2406,17 +2375,12 @@
|
||||
"src": "651:8:0"
|
||||
}
|
||||
],
|
||||
"contractDependencies": [
|
||||
5731
|
||||
],
|
||||
"contractDependencies": [5731],
|
||||
"contractKind": "contract",
|
||||
"documentation": "@title DTFactory contract\n@author Ocean Protocol Team\n * @dev Implementation of Ocean DataTokens Factory\n * DTFactory deploys DataToken proxy contracts.\n New DataToken proxy contracts are links to the template contract's bytecode.\n Proxy contract functionality is based on Ocean Protocol custom implementation of ERC1167 standard.",
|
||||
"fullyImplemented": true,
|
||||
"id": 158,
|
||||
"linearizedBaseContracts": [
|
||||
158,
|
||||
5731
|
||||
],
|
||||
"linearizedBaseContracts": [158, 5731],
|
||||
"name": "DTFactory",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
@ -3032,10 +2996,7 @@
|
||||
"id": 41,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "1528:7:0",
|
||||
"typeDescriptions": {
|
||||
@ -3328,10 +3289,7 @@
|
||||
"id": 78,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2359:7:0",
|
||||
"typeDescriptions": {
|
||||
@ -3564,10 +3522,7 @@
|
||||
"id": 91,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2499:7:0",
|
||||
"typeDescriptions": {
|
||||
@ -3594,9 +3549,7 @@
|
||||
"src": "2499:124:0"
|
||||
},
|
||||
{
|
||||
"assignments": [
|
||||
101
|
||||
],
|
||||
"assignments": [101],
|
||||
"declarations": [
|
||||
{
|
||||
"constant": false,
|
||||
@ -3883,10 +3836,7 @@
|
||||
"id": 106,
|
||||
"name": "require",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [
|
||||
6555,
|
||||
6556
|
||||
],
|
||||
"overloadedDeclarations": [6555, 6556],
|
||||
"referencedDeclaration": 6556,
|
||||
"src": "2695:7:0",
|
||||
"typeDescriptions": {
|
||||
|
6965
package-lock.json
generated
6965
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",
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"start": "",
|
||||
"create": "graph create oceanprotocol/ocean-subgraph --node https://api.thegraph.com/deploy/",
|
||||
"create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020",
|
||||
"codegen": "graph codegen --output-dir src/types/",
|
||||
"build": "graph build",
|
||||
"deploy": "graph deploy oceanprotocol/ocean-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
|
||||
"deploy:beta": "graph deploy oceanprotocol/ocean-subgraph-beta --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
|
||||
"deploy:local": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020"
|
||||
"deploy:local": "graph deploy oceanprotocol/ocean-subgraph subgraph.yaml --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
|
||||
"test": "npm run lint && npm run type-check",
|
||||
"lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .",
|
||||
"format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json,yaml}' --write",
|
||||
"type-check": "tsc --noEmit",
|
||||
"release": "release-it --non-interactive",
|
||||
"changelog": "auto-changelog -p"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@graphprotocol/graph-cli": "^0.18.0",
|
||||
"@graphprotocol/graph-ts": "^0.18.1"
|
||||
"@graphprotocol/graph-cli": "^0.19.0",
|
||||
"@graphprotocol/graph-ts": "^0.19.0",
|
||||
"@release-it/bumper": "^2.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.9.1",
|
||||
"@typescript-eslint/parser": "^4.9.1",
|
||||
"auto-changelog": "^2.2.1",
|
||||
"eslint": "^7.15.0",
|
||||
"eslint-config-oceanprotocol": "^1.5.0",
|
||||
"eslint-config-prettier": "^7.0.0",
|
||||
"eslint-plugin-prettier": "^3.2.0",
|
||||
"prettier": "^2.2.1",
|
||||
"release-it": "^14.2.2",
|
||||
"typescript": "^4.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babel-register": "^6.26.0",
|
||||
"keytar": "^5.0.0",
|
||||
"truffle": "^5.1.0",
|
||||
"truffle-contract": "^4.0.5",
|
||||
"truffle-hdwallet-provider": "^1.0.4"
|
||||
"dependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/oceanprotocol/ocean-subgraph.git"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"release-it": {
|
||||
"hooks": {
|
||||
"after:bump": "npm run changelog"
|
||||
},
|
||||
"plugins": {
|
||||
"@release-it/bumper": {
|
||||
"out": [
|
||||
"package.json",
|
||||
"package-lock.json"
|
||||
]
|
||||
}
|
||||
},
|
||||
"git": {
|
||||
"tagName": "v${version}"
|
||||
},
|
||||
"github": {
|
||||
"release": true
|
||||
},
|
||||
"npm": {
|
||||
"publish": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ import {
|
||||
Bytes,
|
||||
dataSource,
|
||||
Address,
|
||||
ethereum
|
||||
ethereum,
|
||||
log
|
||||
} from '@graphprotocol/graph-ts'
|
||||
|
||||
import {
|
||||
@ -19,72 +20,104 @@ import {
|
||||
TokenTransaction,
|
||||
PoolTransactionTokenValues
|
||||
} from '../types/schema'
|
||||
import { log } from '@graphprotocol/graph-ts'
|
||||
|
||||
import { Pool } from '../types/templates/Pool/Pool'
|
||||
|
||||
export let ZERO_BD = BigDecimal.fromString('0.0')
|
||||
export let MINUS_1_BD = BigDecimal.fromString('-1.0')
|
||||
export let ONE_BD = BigDecimal.fromString('1.0')
|
||||
export const ZERO_BD = BigDecimal.fromString('0.0')
|
||||
export const MINUS_1_BD = BigDecimal.fromString('-1.0')
|
||||
export const ONE_BD = BigDecimal.fromString('1.0')
|
||||
|
||||
export let ONE_BASE_18 = BigInt.fromI32(10).pow(18 as u8)
|
||||
export let BONE = BigDecimal.fromString('1000000000000000000')
|
||||
export const ONE_BASE_18 = BigInt.fromI32(10).pow(18 as u8)
|
||||
export const BONE = BigDecimal.fromString('1000000000000000000')
|
||||
|
||||
export let ENABLE_DEBUG = false
|
||||
export const ENABLE_DEBUG = false
|
||||
|
||||
let network = dataSource.network()
|
||||
const network = dataSource.network()
|
||||
|
||||
export let OCEAN: string = (network == 'mainnet')
|
||||
export const OCEAN: string =
|
||||
network === 'mainnet'
|
||||
? '0x967da4048cd07ab37855c090aaf366e4ce1b9f48'
|
||||
: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07'
|
||||
|
||||
export function _debuglog(message: string, event: ethereum.Event, args: Array<string>): void {
|
||||
export function _debuglog(
|
||||
message: string,
|
||||
event: ethereum.Event,
|
||||
args: Array<string>
|
||||
): void {
|
||||
if (event != null) {
|
||||
args.push(event.transaction.hash.toHex())
|
||||
args.push(event.address.toHex())
|
||||
}
|
||||
for (let i=0; i < args.length; i++) {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
message = message.concat(' {}')
|
||||
}
|
||||
log.info('@@@@@@ ' + message, args)
|
||||
}
|
||||
|
||||
export function debuglog(message: string, event: ethereum.Event, args: Array<string>): void {
|
||||
export function debuglog(
|
||||
message: string,
|
||||
event: ethereum.Event,
|
||||
args: Array<string>
|
||||
): void {
|
||||
if (!ENABLE_DEBUG) return
|
||||
_debuglog(message, event, args)
|
||||
}
|
||||
|
||||
export function hexToDecimal(hexString: String, decimals: i32): BigDecimal {
|
||||
let bytes = Bytes.fromHexString(hexString.toString()).reverse() as Bytes
|
||||
let bi = BigInt.fromUnsignedBytes(bytes)
|
||||
let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal()
|
||||
export function hexToDecimal(hexString: string, decimals: i32): BigDecimal {
|
||||
const bytes = Bytes.fromHexString(hexString.toString()).reverse() as Bytes
|
||||
const bi = BigInt.fromUnsignedBytes(bytes)
|
||||
const scale = BigInt.fromI32(10)
|
||||
.pow(decimals as u8)
|
||||
.toBigDecimal()
|
||||
return bi.divDecimal(scale)
|
||||
}
|
||||
|
||||
export function bigIntToDecimal(amount: BigInt, decimals: i32): BigDecimal {
|
||||
let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal()
|
||||
const scale = BigInt.fromI32(10)
|
||||
.pow(decimals as u8)
|
||||
.toBigDecimal()
|
||||
return amount.toBigDecimal().div(scale)
|
||||
}
|
||||
|
||||
export function tokenToDecimal(amount: BigDecimal, decimals: i32): BigDecimal {
|
||||
let scale = BigInt.fromI32(10).pow(decimals as u8).toBigDecimal()
|
||||
const scale = BigInt.fromI32(10)
|
||||
.pow(decimals as u8)
|
||||
.toBigDecimal()
|
||||
return amount.div(scale)
|
||||
}
|
||||
|
||||
export function decimalToBigInt(value: BigDecimal): BigInt {
|
||||
value.truncate(18)
|
||||
let scale = BigInt.fromI32(10).pow((value.exp.toI32() + 18) as u8)
|
||||
const scale = BigInt.fromI32(10).pow((value.exp.toI32() + 18) as u8)
|
||||
return value.digits.times(scale)
|
||||
|
||||
}
|
||||
|
||||
export function updatePoolTokenBalance(poolToken: PoolToken, balance: BigDecimal, source: string): void {
|
||||
debuglog('########## updating poolToken balance (source, oldBalance, newBalance, poolId) ', null,
|
||||
[source, poolToken.balance.toString(), balance.toString(), poolToken.poolId])
|
||||
export function updatePoolTokenBalance(
|
||||
poolToken: PoolToken,
|
||||
balance: BigDecimal,
|
||||
source: string
|
||||
): void {
|
||||
debuglog(
|
||||
'########## updating poolToken balance (source, oldBalance, newBalance, poolId) ',
|
||||
null,
|
||||
[source, poolToken.balance.toString(), balance.toString(), poolToken.poolId]
|
||||
)
|
||||
poolToken.balance = balance
|
||||
}
|
||||
|
||||
export function createPoolShareEntity(id: string, pool: string, user: string): void {
|
||||
let poolShare = new PoolShare(id)
|
||||
export function createUserEntity(address: string): void {
|
||||
if (User.load(address) == null) {
|
||||
const user = new User(address)
|
||||
user.save()
|
||||
}
|
||||
}
|
||||
|
||||
export function createPoolShareEntity(
|
||||
id: string,
|
||||
pool: string,
|
||||
user: string
|
||||
): void {
|
||||
const poolShare = new PoolShare(id)
|
||||
|
||||
createUserEntity(user)
|
||||
|
||||
@ -94,12 +127,16 @@ export function createPoolShareEntity(id: string, pool: string, user: string): v
|
||||
poolShare.save()
|
||||
}
|
||||
|
||||
export function createPoolTokenEntity(id: string, pool: string, address: string): void {
|
||||
let datatoken = Datatoken.load(address)
|
||||
export function createPoolTokenEntity(
|
||||
id: string,
|
||||
pool: string,
|
||||
address: string
|
||||
): void {
|
||||
const datatoken = Datatoken.load(address)
|
||||
|
||||
let poolToken = new PoolToken(id)
|
||||
const poolToken = new PoolToken(id)
|
||||
poolToken.poolId = pool
|
||||
poolToken.tokenId = datatoken ? datatoken.id: ''
|
||||
poolToken.tokenId = datatoken ? datatoken.id : ''
|
||||
poolToken.tokenAddress = address
|
||||
poolToken.balance = ZERO_BD
|
||||
poolToken.denormWeight = ZERO_BD
|
||||
@ -107,14 +144,16 @@ export function createPoolTokenEntity(id: string, pool: string, address: string)
|
||||
}
|
||||
|
||||
export function updatePoolTransactionToken(
|
||||
poolTx: string, poolTokenId: string, amount: BigDecimal,
|
||||
balance: BigDecimal, feeValue: BigDecimal
|
||||
poolTx: string,
|
||||
poolTokenId: string,
|
||||
amount: BigDecimal,
|
||||
balance: BigDecimal,
|
||||
feeValue: BigDecimal
|
||||
): void {
|
||||
|
||||
let ptx = PoolTransaction.load(poolTx)
|
||||
let poolToken = PoolToken.load(poolTokenId)
|
||||
let pool = PoolEntity.load(poolToken.poolId)
|
||||
let ptxTokenValuesId = poolTx.concat('-').concat(poolToken.tokenAddress)
|
||||
const ptx = PoolTransaction.load(poolTx)
|
||||
const poolToken = PoolToken.load(poolTokenId)
|
||||
const pool = PoolEntity.load(poolToken.poolId)
|
||||
const ptxTokenValuesId = poolTx.concat('-').concat(poolToken.tokenAddress)
|
||||
let ptxTokenValues = PoolTransactionTokenValues.load(ptxTokenValuesId)
|
||||
if (ptxTokenValues == null) {
|
||||
ptxTokenValues = new PoolTransactionTokenValues(ptxTokenValuesId)
|
||||
@ -136,34 +175,74 @@ export function updatePoolTransactionToken(
|
||||
|
||||
ptxTokenValues.save()
|
||||
|
||||
if (ptxTokenValues.tokenAddress == OCEAN) {
|
||||
if (ptxTokenValues.tokenAddress === OCEAN) {
|
||||
ptx.oceanReserve = ptxTokenValues.tokenReserve
|
||||
pool.oceanReserve = ptxTokenValues.tokenReserve
|
||||
} else {
|
||||
ptx.datatokenReserve = ptxTokenValues.tokenReserve
|
||||
pool.datatokenReserve = ptxTokenValues.tokenReserve
|
||||
}
|
||||
debuglog('########## updatePoolTransactionToken: ', null,
|
||||
[
|
||||
debuglog('########## updatePoolTransactionToken: ', null, [
|
||||
BigInt.fromI32(ptx.block).toString(),
|
||||
BigInt.fromI32(ptx.timestamp).toString(),
|
||||
ptxTokenValues.type,
|
||||
ptxTokenValues.value.toString(),
|
||||
ptxTokenValues.tokenReserve.toString(),
|
||||
poolToken.poolId,
|
||||
poolToken.poolId
|
||||
])
|
||||
|
||||
ptx.save()
|
||||
pool.save()
|
||||
}
|
||||
|
||||
export function createPoolTransaction(event: ethereum.Event, event_type: string, userAddress: string): void {
|
||||
let poolId = event.address.toHex()
|
||||
let pool = PoolEntity.load(poolId)
|
||||
let ptx = event.transaction.hash.toHexString()
|
||||
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 ocnToken = PoolToken.load(poolId.concat('-').concat(OCEAN))
|
||||
let dtToken = PoolToken.load(poolId.concat('-').concat(pool.datatokenAddress))
|
||||
const numer = balanceIn.div(wIn)
|
||||
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) {
|
||||
return
|
||||
@ -189,14 +268,18 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
||||
poolTx.datatokenReserve = dtToken.balance
|
||||
poolTx.oceanReserve = ocnToken.balance
|
||||
|
||||
let p = Pool.bind(Address.fromString(poolId))
|
||||
let priceResult = p.try_calcInGivenOut(
|
||||
decimalToBigInt(ocnToken.balance), decimalToBigInt(ocnToken.denormWeight),
|
||||
decimalToBigInt(dtToken.balance), decimalToBigInt(dtToken.denormWeight),
|
||||
ONE_BASE_18, decimalToBigInt(pool.swapFee)
|
||||
const p = Pool.bind(Address.fromString(poolId))
|
||||
const priceResult = p.try_calcInGivenOut(
|
||||
decimalToBigInt(ocnToken.balance),
|
||||
decimalToBigInt(ocnToken.denormWeight),
|
||||
decimalToBigInt(dtToken.balance),
|
||||
decimalToBigInt(dtToken.denormWeight),
|
||||
ONE_BASE_18,
|
||||
decimalToBigInt(pool.swapFee)
|
||||
)
|
||||
debuglog(
|
||||
'args to calcInGivenOut (ocnBalance, ocnWeight, dtBalance, dtWeight, dtAmount, swapFee, result)', null,
|
||||
'args to calcInGivenOut (ocnBalance, ocnWeight, dtBalance, dtWeight, dtAmount, swapFee, result)',
|
||||
null,
|
||||
[
|
||||
decimalToBigInt(ocnToken.balance).toString(),
|
||||
decimalToBigInt(ocnToken.denormWeight).toString(),
|
||||
@ -207,10 +290,14 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
||||
priceResult.reverted ? 'failed' : priceResult.value.toString()
|
||||
]
|
||||
)
|
||||
poolTx.consumePrice = priceResult.reverted ? MINUS_1_BD : bigIntToDecimal(priceResult.value, 18)
|
||||
poolTx.consumePrice = priceResult.reverted
|
||||
? MINUS_1_BD
|
||||
: bigIntToDecimal(priceResult.value, 18)
|
||||
poolTx.spotPrice = calcSpotPrice(
|
||||
ocnToken.balance, ocnToken.denormWeight,
|
||||
dtToken.balance, dtToken.denormWeight,
|
||||
ocnToken.balance,
|
||||
ocnToken.denormWeight,
|
||||
dtToken.balance,
|
||||
dtToken.denormWeight,
|
||||
pool.swapFee
|
||||
)
|
||||
|
||||
@ -221,21 +308,27 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
||||
|
||||
pool.save()
|
||||
|
||||
debuglog('updated pool reserves (source, dtBalance, ocnBalance, dtReserve, ocnReserve): ',
|
||||
debuglog(
|
||||
'updated pool reserves (source, dtBalance, ocnBalance, dtReserve, ocnReserve): ',
|
||||
event,
|
||||
['createPoolTransaction', dtToken.balance.toString(), ocnToken.balance.toString(),
|
||||
pool.datatokenReserve.toString(), pool.oceanReserve.toString()])
|
||||
[
|
||||
'createPoolTransaction',
|
||||
dtToken.balance.toString(),
|
||||
ocnToken.balance.toString(),
|
||||
pool.datatokenReserve.toString(),
|
||||
pool.oceanReserve.toString()
|
||||
]
|
||||
)
|
||||
|
||||
poolTx.tx = event.transaction.hash
|
||||
// eslint-disable-next-line camelcase
|
||||
poolTx.event = event_type
|
||||
poolTx.block = event.block.number.toI32()
|
||||
poolTx.timestamp = event.block.timestamp.toI32()
|
||||
poolTx.gasUsed = event.transaction.gasUsed.toBigDecimal()
|
||||
poolTx.gasPrice = event.transaction.gasPrice.toBigDecimal()
|
||||
|
||||
|
||||
debuglog('####################### poolTransaction: ', event,
|
||||
[
|
||||
debuglog('####################### poolTransaction: ', event, [
|
||||
BigInt.fromI32(poolTx.block).toString(),
|
||||
BigInt.fromI32(poolTx.timestamp).toString(),
|
||||
pool.oceanReserve.toString()
|
||||
@ -244,40 +337,22 @@ export function createPoolTransaction(event: ethereum.Event, event_type: string,
|
||||
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 {
|
||||
let factory = PoolFactory.load('1')
|
||||
const factory = PoolFactory.load('1')
|
||||
factory.poolCount -= 1
|
||||
if (finalized) factory.finalizedPoolCount -= 1
|
||||
factory.save()
|
||||
}
|
||||
|
||||
export function saveTokenTransaction(event: ethereum.Event, eventName: string): void {
|
||||
let tx = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
|
||||
let userAddress = event.transaction.from.toHex()
|
||||
export function saveTokenTransaction(
|
||||
event: ethereum.Event,
|
||||
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)
|
||||
if (transaction == null) {
|
||||
transaction = new TokenTransaction(tx)
|
||||
@ -295,14 +370,12 @@ export function saveTokenTransaction(event: ethereum.Event, eventName: string):
|
||||
createUserEntity(userAddress)
|
||||
}
|
||||
|
||||
export function createUserEntity(address: string): void {
|
||||
if (User.load(address) == null) {
|
||||
let user = new User(address)
|
||||
user.save()
|
||||
}
|
||||
}
|
||||
|
||||
export function updateTokenBalance(id: string, token: string, user: string, amount: BigDecimal): void {
|
||||
export function updateTokenBalance(
|
||||
id: string,
|
||||
token: string,
|
||||
user: string,
|
||||
amount: BigDecimal
|
||||
): void {
|
||||
let tokenBalance = TokenBalance.load(id)
|
||||
if (tokenBalance == null) {
|
||||
tokenBalance = new TokenBalance(id)
|
@ -1,80 +1,85 @@
|
||||
|
||||
import { BigInt, BigDecimal } from '@graphprotocol/graph-ts'
|
||||
import { OrderStarted, Transfer } from '../types/templates/DataToken/DataToken'
|
||||
import { log } from '@graphprotocol/graph-ts'
|
||||
|
||||
import {
|
||||
Datatoken, TokenBalance, TokenOrder
|
||||
} from '../types/schema'
|
||||
import { Datatoken, TokenBalance, TokenOrder } from '../types/schema'
|
||||
import {
|
||||
tokenToDecimal,
|
||||
updateTokenBalance,
|
||||
ZERO_BD,
|
||||
MINUS_1_BD,
|
||||
saveTokenTransaction
|
||||
} from './helpers'
|
||||
} from '../helpers'
|
||||
|
||||
/************************************
|
||||
********** Pool Controls ***********
|
||||
************************************/
|
||||
|
||||
export function handleTransfer(event: Transfer): void {
|
||||
let tokenId = event.address.toHex()
|
||||
const tokenId = event.address.toHex()
|
||||
|
||||
let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||
|
||||
|
||||
let amount = tokenToDecimal(event.params.value.toBigDecimal(), 18)
|
||||
let tokenShareFrom = event.params.from.toHex()
|
||||
let tokenShareTo = event.params.to.toHex()
|
||||
let tokenBalanceFromId = tokenId.concat('-').concat(tokenShareFrom)
|
||||
let tokenBalanceToId = tokenId.concat('-').concat(tokenShareTo)
|
||||
const amount = tokenToDecimal(event.params.value.toBigDecimal(), 18)
|
||||
const tokenShareFrom = event.params.from.toHex()
|
||||
const tokenShareTo = event.params.to.toHex()
|
||||
const tokenBalanceFromId = tokenId.concat('-').concat(tokenShareFrom)
|
||||
const tokenBalanceToId = tokenId.concat('-').concat(tokenShareTo)
|
||||
let tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
||||
let tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
||||
let oldBalanceFrom = BigDecimal.fromString('0.0')
|
||||
let oldBalanceTo = BigDecimal.fromString('0.0')
|
||||
|
||||
let isMint = tokenShareFrom == ZERO_ADDRESS
|
||||
let isBurn = tokenShareTo == ZERO_ADDRESS
|
||||
const isMint = tokenShareFrom === ZERO_ADDRESS
|
||||
const isBurn = tokenShareTo === ZERO_ADDRESS
|
||||
|
||||
let datatoken = Datatoken.load(tokenId)
|
||||
const datatoken = Datatoken.load(tokenId)
|
||||
|
||||
if (isMint) {
|
||||
tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
||||
oldBalanceTo = (tokenBalanceTo == null) ? ZERO_BD : tokenBalanceTo.balance
|
||||
oldBalanceTo = tokenBalanceTo == null ? ZERO_BD : tokenBalanceTo.balance
|
||||
datatoken.supply = datatoken.supply.plus(amount)
|
||||
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
|
||||
|
||||
} else if (isBurn) {
|
||||
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
||||
oldBalanceFrom = (tokenBalanceFrom == null) ? ZERO_BD : tokenBalanceFrom.balance
|
||||
oldBalanceFrom =
|
||||
tokenBalanceFrom == null ? ZERO_BD : tokenBalanceFrom.balance
|
||||
datatoken.supply = datatoken.supply.minus(amount)
|
||||
updateTokenBalance(tokenBalanceFromId, tokenId, tokenShareFrom, amount.times(MINUS_1_BD))
|
||||
updateTokenBalance(
|
||||
tokenBalanceFromId,
|
||||
tokenId,
|
||||
tokenShareFrom,
|
||||
amount.times(MINUS_1_BD)
|
||||
)
|
||||
} else {
|
||||
|
||||
tokenBalanceFrom = TokenBalance.load(tokenBalanceFromId)
|
||||
oldBalanceFrom = (tokenBalanceFrom == null) ? ZERO_BD : tokenBalanceFrom.balance
|
||||
oldBalanceFrom =
|
||||
tokenBalanceFrom == null ? ZERO_BD : tokenBalanceFrom.balance
|
||||
datatoken.supply = datatoken.supply.minus(amount)
|
||||
updateTokenBalance(tokenBalanceFromId, tokenId, tokenShareFrom, amount.times(MINUS_1_BD))
|
||||
updateTokenBalance(
|
||||
tokenBalanceFromId,
|
||||
tokenId,
|
||||
tokenShareFrom,
|
||||
amount.times(MINUS_1_BD)
|
||||
)
|
||||
|
||||
tokenBalanceTo = TokenBalance.load(tokenBalanceToId)
|
||||
oldBalanceTo = (tokenBalanceTo == null) ? ZERO_BD : tokenBalanceTo.balance
|
||||
oldBalanceTo = tokenBalanceTo == null ? ZERO_BD : tokenBalanceTo.balance
|
||||
datatoken.supply = datatoken.supply.plus(amount)
|
||||
updateTokenBalance(tokenBalanceToId, tokenId, tokenShareTo, amount)
|
||||
}
|
||||
|
||||
if (
|
||||
tokenBalanceTo !== null
|
||||
&& tokenBalanceTo.balance.notEqual(ZERO_BD)
|
||||
&& oldBalanceTo.equals(ZERO_BD)
|
||||
tokenBalanceTo !== null &&
|
||||
tokenBalanceTo.balance.notEqual(ZERO_BD) &&
|
||||
oldBalanceTo.equals(ZERO_BD)
|
||||
) {
|
||||
datatoken.holderCount += BigInt.fromI32(1)
|
||||
}
|
||||
|
||||
if (
|
||||
tokenBalanceFrom !== null
|
||||
&& tokenBalanceFrom.balance.equals(ZERO_BD)
|
||||
&& oldBalanceFrom.notEqual(ZERO_BD)
|
||||
tokenBalanceFrom !== null &&
|
||||
tokenBalanceFrom.balance.equals(ZERO_BD) &&
|
||||
oldBalanceFrom.notEqual(ZERO_BD)
|
||||
) {
|
||||
datatoken.holderCount -= BigInt.fromI32(1)
|
||||
}
|
||||
@ -84,16 +89,20 @@ export function handleTransfer(event: Transfer): void {
|
||||
}
|
||||
|
||||
export function handleOrderStarted(event: OrderStarted): void {
|
||||
let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||
let tokenId = event.address.toHex()
|
||||
let datatoken = Datatoken.load(tokenId)
|
||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||
const tokenId = event.address.toHex()
|
||||
const datatoken = Datatoken.load(tokenId)
|
||||
if (datatoken == null) return
|
||||
|
||||
let payer = event.params.payer.toHex()
|
||||
const payer = event.params.payer.toHex()
|
||||
// let feeCollector = event.params.mrktFeeCollector
|
||||
// let marketFee = event.params.marketFee
|
||||
let tx = event.transaction.hash
|
||||
let orderId = tokenId.concat('-').concat(payer).concat('-').concat(tx.toHexString())
|
||||
const tx = event.transaction.hash
|
||||
const orderId = tokenId
|
||||
.concat('-')
|
||||
.concat(payer)
|
||||
.concat('-')
|
||||
.concat(tx.toHexString())
|
||||
let order = TokenOrder.load(orderId)
|
||||
if (order == null) {
|
||||
order = new TokenOrder(orderId)
|
||||
@ -104,7 +113,10 @@ export function handleOrderStarted(event: OrderStarted): void {
|
||||
order.payer = payer
|
||||
order.serviceId = event.params.serviceId.toI32()
|
||||
order.timestamp = event.params.timestamp.toI32()
|
||||
if (event.params.mrktFeeCollector != null && event.params.mrktFeeCollector.toHex() != ZERO_ADDRESS) {
|
||||
if (
|
||||
event.params.mrktFeeCollector != null &&
|
||||
event.params.mrktFeeCollector.toHex() !== ZERO_ADDRESS
|
||||
) {
|
||||
order.marketFeeCollector = event.params.mrktFeeCollector.toHexString()
|
||||
}
|
||||
order.marketFee = tokenToDecimal(event.params.marketFee.toBigDecimal(), 18)
|
||||
|
@ -1,14 +1,9 @@
|
||||
import { BigInt } from '@graphprotocol/graph-ts'
|
||||
import { BigInt, log } from '@graphprotocol/graph-ts'
|
||||
import { TokenRegistered } from '../types/DTFactory/DTFactory'
|
||||
import { DatatokenFactory, Datatoken as DatatokenEntity } from '../types/schema'
|
||||
import { DataToken as DatatokenDataSource } from '../types/templates'
|
||||
|
||||
import {
|
||||
createUserEntity,
|
||||
tokenToDecimal,
|
||||
ZERO_BD,
|
||||
} from './helpers'
|
||||
import { log } from '@graphprotocol/graph-ts'
|
||||
import { createUserEntity, tokenToDecimal, ZERO_BD } from '../helpers'
|
||||
|
||||
export function handleNewToken(event: TokenRegistered): void {
|
||||
let factory = DatatokenFactory.load('1')
|
||||
@ -19,8 +14,10 @@ export function handleNewToken(event: TokenRegistered): void {
|
||||
factory.tokenCount = 0
|
||||
}
|
||||
|
||||
let datatoken = new DatatokenEntity(event.params.tokenAddress.toHexString())
|
||||
log.error('************************ handleNewToken: datatokenId {}', [datatoken.id.toString()])
|
||||
const datatoken = new DatatokenEntity(event.params.tokenAddress.toHexString())
|
||||
log.error('************************ handleNewToken: datatokenId {}', [
|
||||
datatoken.id.toString()
|
||||
])
|
||||
|
||||
datatoken.factoryID = event.address.toHexString()
|
||||
|
||||
|
@ -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 { PoolFactory, Pool } from '../types/schema'
|
||||
import { Pool as PoolContract } from '../types/templates'
|
||||
import { ZERO_BD } from './helpers'
|
||||
import { log } from '@graphprotocol/graph-ts'
|
||||
import { ZERO_BD } from '../helpers'
|
||||
|
||||
export function handleNewPool(event: BPoolRegistered): void {
|
||||
let factory = PoolFactory.load('1')
|
||||
|
||||
if (factory == null) {
|
||||
if (factory === null) {
|
||||
factory = new PoolFactory('1')
|
||||
factory.totalLiquidity = ZERO_BD
|
||||
factory.totalSwapVolume = ZERO_BD
|
||||
@ -18,8 +17,10 @@ export function handleNewPool(event: BPoolRegistered): void {
|
||||
factory.finalizedPoolCount = 0
|
||||
}
|
||||
|
||||
let pool = new Pool(event.params.bpoolAddress.toHexString())
|
||||
log.info('************************ handleNewPool: poolId {}', [pool.id.toString()])
|
||||
const pool = new Pool(event.params.bpoolAddress.toHexString())
|
||||
log.info('************************ handleNewPool: poolId {}', [
|
||||
pool.id.toString()
|
||||
])
|
||||
|
||||
pool.factoryID = event.address.toHexString()
|
||||
pool.controller = event.params.registeredBy
|
||||
@ -38,8 +39,8 @@ export function handleNewPool(event: BPoolRegistered): void {
|
||||
|
||||
pool.datatokenReserve = ZERO_BD
|
||||
pool.oceanReserve = ZERO_BD
|
||||
pool.spotPrice = ZERO_BD //: BigDecimal!
|
||||
pool.consumePrice = ZERO_BD //: BigDecimal!
|
||||
pool.spotPrice = ZERO_BD // : BigDecimal!
|
||||
pool.consumePrice = ZERO_BD // : BigDecimal!
|
||||
|
||||
pool.tokenCount = BigInt.fromI32(0)
|
||||
pool.holderCount = BigInt.fromI32(0)
|
||||
|
@ -1,7 +1,11 @@
|
||||
|
||||
import {BigInt, Address, BigDecimal} from '@graphprotocol/graph-ts'
|
||||
import { LOG_CALL, LOG_JOIN, LOG_EXIT, LOG_SWAP, Transfer } from '../types/templates/Pool/Pool'
|
||||
import { log } from '@graphprotocol/graph-ts'
|
||||
import { BigInt, Address, BigDecimal } from '@graphprotocol/graph-ts'
|
||||
import {
|
||||
LOG_CALL,
|
||||
LOG_JOIN,
|
||||
LOG_EXIT,
|
||||
LOG_SWAP,
|
||||
Transfer
|
||||
} from '../types/templates/Pool/Pool'
|
||||
|
||||
import {
|
||||
PoolFactory,
|
||||
@ -22,16 +26,20 @@ import {
|
||||
updatePoolTransactionToken,
|
||||
createPoolTransaction,
|
||||
OCEAN,
|
||||
debuglog, updatePoolTokenBalance
|
||||
} from './helpers'
|
||||
debuglog,
|
||||
updatePoolTokenBalance
|
||||
} from '../helpers'
|
||||
|
||||
/************************************
|
||||
********** Pool Controls ***********
|
||||
************************************/
|
||||
|
||||
export function handleSetSwapFee(event: LOG_CALL, swapFeeStr: string=null): void {
|
||||
let poolId = event.address.toHex()
|
||||
let pool = Pool.load(poolId)
|
||||
export function handleSetSwapFee(
|
||||
event: LOG_CALL,
|
||||
swapFeeStr: string = null
|
||||
): void {
|
||||
const poolId = event.address.toHex()
|
||||
const pool = Pool.load(poolId)
|
||||
if (!swapFeeStr) {
|
||||
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 {
|
||||
let poolId = event.address.toHex()
|
||||
let pool = Pool.load(poolId)
|
||||
pool.controller = Address.fromString(event.params.data.toHexString().slice(-40))
|
||||
const poolId = event.address.toHex()
|
||||
const pool = Pool.load(poolId)
|
||||
pool.controller = Address.fromString(
|
||||
event.params.data.toHexString().slice(-40)
|
||||
)
|
||||
pool.save()
|
||||
}
|
||||
|
||||
export function handleSetPublicSwap(event: LOG_CALL): void {
|
||||
let poolId = event.address.toHex()
|
||||
let pool = Pool.load(poolId)
|
||||
pool.publicSwap = event.params.data.toHexString().slice(-1) == '1'
|
||||
const poolId = event.address.toHex()
|
||||
const pool = Pool.load(poolId)
|
||||
pool.publicSwap = event.params.data.toHexString().slice(-1) === '1'
|
||||
pool.save()
|
||||
}
|
||||
|
||||
export function handleFinalize(event: LOG_CALL): void {
|
||||
let poolId = event.address.toHex()
|
||||
let pool = Pool.load(poolId)
|
||||
const poolId = event.address.toHex()
|
||||
const pool = Pool.load(poolId)
|
||||
pool.finalized = true
|
||||
pool.symbol = 'BPT'
|
||||
pool.publicSwap = true
|
||||
pool.save()
|
||||
|
||||
let factory = PoolFactory.load('1')
|
||||
const factory = PoolFactory.load('1')
|
||||
factory.finalizedPoolCount = factory.finalizedPoolCount + 1
|
||||
factory.save()
|
||||
}
|
||||
|
||||
export function handleSetup(event: LOG_CALL): void {
|
||||
let poolId = event.address.toHex()
|
||||
debuglog('handleSetup: ', event, [])
|
||||
let 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
|
||||
export function _handleRebind(
|
||||
event: LOG_CALL,
|
||||
poolId: string,
|
||||
tokenAddress: string,
|
||||
balanceStr: string,
|
||||
denormWeightStr: string
|
||||
): void {
|
||||
const pool = Pool.load(poolId)
|
||||
const decimals = BigInt.fromI32(18).toI32()
|
||||
|
||||
// skip 8 then take the last 40 (2 + 8 + 24 = 34) to (2 + 8 + 64 = 74)
|
||||
let dataTokenAddress = Address.fromString(data.slice(34,74)).toHexString()
|
||||
|
||||
let 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 ) {
|
||||
if (tokenAddress !== OCEAN) {
|
||||
pool.datatokenAddress = tokenAddress
|
||||
}
|
||||
pool.tokenCount += BigInt.fromI32(1)
|
||||
let address = Address.fromString(tokenAddress)
|
||||
let denormWeight = hexToDecimal(denormWeightStr, decimals)
|
||||
let poolTokenId = poolId.concat('-').concat(address.toHexString())
|
||||
const address = Address.fromString(tokenAddress)
|
||||
const denormWeight = hexToDecimal(denormWeightStr, decimals)
|
||||
const poolTokenId = poolId.concat('-').concat(address.toHexString())
|
||||
let poolToken = PoolToken.load(poolTokenId)
|
||||
if (poolToken == null) {
|
||||
createPoolTokenEntity(poolTokenId, poolId, address.toHexString())
|
||||
poolToken = PoolToken.load(poolTokenId)
|
||||
pool.totalWeight += denormWeight
|
||||
} else {
|
||||
let oldWeight = poolToken.denormWeight
|
||||
const oldWeight = poolToken.denormWeight
|
||||
if (denormWeight > oldWeight) {
|
||||
pool.totalWeight = pool.totalWeight + (denormWeight - oldWeight)
|
||||
} else {
|
||||
@ -140,7 +108,7 @@ export function _handleRebind(event: LOG_CALL, poolId: string, tokenAddress: str
|
||||
}
|
||||
|
||||
poolToken.denormWeight = denormWeight
|
||||
let balance = hexToDecimal(balanceStr, decimals)
|
||||
const balance = hexToDecimal(balanceStr, decimals)
|
||||
updatePoolTokenBalance(poolToken as PoolToken, balance, '_handleRebind')
|
||||
|
||||
poolToken.save()
|
||||
@ -152,83 +120,181 @@ export function _handleRebind(event: LOG_CALL, poolId: string, tokenAddress: str
|
||||
}
|
||||
|
||||
export function handleRebind(event: LOG_CALL): void {
|
||||
let poolId = event.address.toHex()
|
||||
const poolId = event.address.toHex()
|
||||
_handleRebind(
|
||||
event,
|
||||
poolId,
|
||||
event.params.data.toHexString().slice(34,74),
|
||||
event.params.data.toHexString().slice(74,138),
|
||||
event.params.data.toHexString().slice(34, 74),
|
||||
event.params.data.toHexString().slice(74, 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
|
||||
)
|
||||
}
|
||||
|
||||
/************************************
|
||||
********** JOINS & EXITS ***********
|
||||
************************************/
|
||||
|
||||
export function handleJoinPool(event: LOG_JOIN): void {
|
||||
let poolId = event.address.toHex()
|
||||
const poolId = event.address.toHex()
|
||||
|
||||
let pool = Pool.load(poolId)
|
||||
if (pool.finalized == false){
|
||||
const pool = Pool.load(poolId)
|
||||
if (pool.finalized === false) {
|
||||
return
|
||||
}
|
||||
|
||||
pool.joinCount = pool.joinCount.plus(BigInt.fromI32(1))
|
||||
pool.save()
|
||||
let ptx = event.transaction.hash.toHexString()
|
||||
let poolTx = PoolTransaction.load(ptx)
|
||||
const ptx = event.transaction.hash.toHexString()
|
||||
const poolTx = PoolTransaction.load(ptx)
|
||||
if (poolTx != null) {
|
||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! PoolTransaction EXISTS: ', event, [])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! PoolTransaction EXISTS: ',
|
||||
event,
|
||||
[]
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
let address = event.params.tokenIn.toHex()
|
||||
let poolTokenId = poolId.concat('-').concat(address)
|
||||
let poolToken = PoolToken.load(poolTokenId)
|
||||
const address = event.params.tokenIn.toHex()
|
||||
const poolTokenId = poolId.concat('-').concat(address)
|
||||
const poolToken = PoolToken.load(poolTokenId)
|
||||
if (poolToken == null) {
|
||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! NO PoolToken: ', event, [address, poolTokenId])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! JOIN JOIN JOIN !!!!!!!!!!!! NO PoolToken: ',
|
||||
event,
|
||||
[address, poolTokenId]
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
let datatoken: Datatoken | null
|
||||
datatoken = poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||
let decimals = datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||
let tokenAmountIn = tokenToDecimal(event.params.tokenAmountIn.toBigDecimal(), decimals)
|
||||
updatePoolTokenBalance(poolToken as PoolToken, poolToken.balance.plus(tokenAmountIn), 'handleJoinPool')
|
||||
debuglog('!!!!!!!!!!!!!!!!!! JOIN JOIN JOIN : (token, amountIn, amountIn) ', event,
|
||||
[address, tokenAmountIn.toString(), event.params.tokenAmountIn.toString()])
|
||||
const datatoken: Datatoken =
|
||||
poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||
const decimals =
|
||||
datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||
const tokenAmountIn = tokenToDecimal(
|
||||
event.params.tokenAmountIn.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
updatePoolTokenBalance(
|
||||
poolToken as PoolToken,
|
||||
poolToken.balance.plus(tokenAmountIn),
|
||||
'handleJoinPool'
|
||||
)
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! JOIN JOIN JOIN : (token, amountIn, amountIn) ',
|
||||
event,
|
||||
[address, tokenAmountIn.toString(), event.params.tokenAmountIn.toString()]
|
||||
)
|
||||
|
||||
poolToken.save()
|
||||
createPoolTransaction(event, 'join', event.params.caller.toHexString())
|
||||
updatePoolTransactionToken(
|
||||
event.transaction.hash.toHexString(), poolTokenId,
|
||||
tokenAmountIn, poolToken.balance,
|
||||
event.transaction.hash.toHexString(),
|
||||
poolTokenId,
|
||||
tokenAmountIn,
|
||||
poolToken.balance,
|
||||
tokenAmountIn.times(pool.swapFee)
|
||||
)
|
||||
}
|
||||
|
||||
export function handleExitPool(event: LOG_EXIT): void {
|
||||
let poolId = event.address.toHex()
|
||||
const poolId = event.address.toHex()
|
||||
|
||||
let address = event.params.tokenOut.toHex()
|
||||
let poolTokenId = poolId.concat('-').concat(address.toString())
|
||||
let poolToken = PoolToken.load(poolTokenId)
|
||||
const address = event.params.tokenOut.toHex()
|
||||
const poolTokenId = poolId.concat('-').concat(address.toString())
|
||||
const poolToken = PoolToken.load(poolTokenId)
|
||||
if (!poolToken) {
|
||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! EXIT EXIT EXIT !!!!!!!!!!!! NO PoolToken: ', event, [address, poolTokenId])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! EXIT EXIT EXIT !!!!!!!!!!!! NO PoolToken: ',
|
||||
event,
|
||||
[address, poolTokenId]
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
let datatoken: Datatoken | null
|
||||
datatoken = poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||
let decimals = datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||
let tokenAmountOut = tokenToDecimal(event.params.tokenAmountOut.toBigDecimal(), decimals)
|
||||
let newAmount = poolToken.balance.minus(tokenAmountOut)
|
||||
const datatoken: Datatoken =
|
||||
poolToken.tokenId != null ? Datatoken.load(poolToken.tokenId) : null
|
||||
const decimals =
|
||||
datatoken == null ? BigInt.fromI32(18).toI32() : datatoken.decimals
|
||||
const tokenAmountOut = tokenToDecimal(
|
||||
event.params.tokenAmountOut.toBigDecimal(),
|
||||
decimals
|
||||
)
|
||||
const newAmount = poolToken.balance.minus(tokenAmountOut)
|
||||
updatePoolTokenBalance(poolToken as PoolToken, newAmount, 'handleExitPool')
|
||||
poolToken.save()
|
||||
debuglog('!!!!!!!!!!!!!!!!!! EXIT EXIT EXIT : (token, amountOut, amountOut)', event,
|
||||
[address, tokenAmountOut.toString(), event.params.tokenAmountOut.toString()])
|
||||
let pool = Pool.load(poolId)
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! EXIT EXIT EXIT : (token, amountOut, amountOut)',
|
||||
event,
|
||||
[address, tokenAmountOut.toString(), event.params.tokenAmountOut.toString()]
|
||||
)
|
||||
const pool = Pool.load(poolId)
|
||||
pool.exitCount = pool.exitCount.plus(BigInt.fromI32(1))
|
||||
if (newAmount.equals(ZERO_BD)) {
|
||||
decrPoolCount(pool.finalized)
|
||||
@ -238,8 +304,10 @@ export function handleExitPool(event: LOG_EXIT): void {
|
||||
|
||||
createPoolTransaction(event, 'exit', event.params.caller.toHexString())
|
||||
updatePoolTransactionToken(
|
||||
event.transaction.hash.toHexString(), poolTokenId,
|
||||
tokenAmountOut.times(MINUS_1_BD), poolToken.balance,
|
||||
event.transaction.hash.toHexString(),
|
||||
poolTokenId,
|
||||
tokenAmountOut.times(MINUS_1_BD),
|
||||
poolToken.balance,
|
||||
tokenAmountOut.times(pool.swapFee)
|
||||
)
|
||||
}
|
||||
@ -249,35 +317,61 @@ export function handleExitPool(event: LOG_EXIT): void {
|
||||
************************************/
|
||||
|
||||
export function handleSwap(event: LOG_SWAP): void {
|
||||
let poolId = event.address.toHex()
|
||||
let ptx = event.transaction.hash.toHexString()
|
||||
const poolId = event.address.toHex()
|
||||
const ptx = event.transaction.hash.toHexString()
|
||||
|
||||
let tokenIn = event.params.tokenIn.toHex()
|
||||
let poolTokenInId = poolId.concat('-').concat(tokenIn.toString())
|
||||
let poolTokenIn = PoolToken.load(poolTokenInId)
|
||||
const tokenIn = event.params.tokenIn.toHex()
|
||||
const poolTokenInId = poolId.concat('-').concat(tokenIn.toString())
|
||||
const poolTokenIn = PoolToken.load(poolTokenInId)
|
||||
if (!poolTokenIn) {
|
||||
debuglog('!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! SWAP SWAP SWAP !!!!!!!!!!!! NO PoolToken: ', event,
|
||||
[tokenIn, poolTokenInId])
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!! SWAP SWAP SWAP !!!!!!!!!!!! NO PoolToken: ',
|
||||
event,
|
||||
[tokenIn, poolTokenInId]
|
||||
)
|
||||
return
|
||||
}
|
||||
let dtIn = Datatoken.load(tokenIn)
|
||||
let tokenAmountIn = tokenToDecimal(event.params.tokenAmountIn.toBigDecimal(), (dtIn == null) ? 18 : dtIn.decimals)
|
||||
let newAmountIn = poolTokenIn.balance.plus(tokenAmountIn)
|
||||
updatePoolTokenBalance(poolTokenIn as PoolToken, newAmountIn, 'handleSwap.tokenIn')
|
||||
const dtIn = Datatoken.load(tokenIn)
|
||||
const tokenAmountIn = tokenToDecimal(
|
||||
event.params.tokenAmountIn.toBigDecimal(),
|
||||
dtIn == null ? 18 : dtIn.decimals
|
||||
)
|
||||
const newAmountIn = poolTokenIn.balance.plus(tokenAmountIn)
|
||||
updatePoolTokenBalance(
|
||||
poolTokenIn as PoolToken,
|
||||
newAmountIn,
|
||||
'handleSwap.tokenIn'
|
||||
)
|
||||
poolTokenIn.save()
|
||||
|
||||
let tokenOut = event.params.tokenOut.toHex()
|
||||
let poolTokenOutId = poolId.concat('-').concat(tokenOut.toString())
|
||||
let poolTokenOut = PoolToken.load(poolTokenOutId)
|
||||
let dtOut = Datatoken.load(tokenOut)
|
||||
let tokenAmountOut = tokenToDecimal(event.params.tokenAmountOut.toBigDecimal(), (dtOut == null) ? 18 : dtOut.decimals)
|
||||
let newAmountOut = poolTokenOut.balance.minus(tokenAmountOut)
|
||||
updatePoolTokenBalance(poolTokenOut as PoolToken, newAmountOut, 'handleSwap.tokenOut')
|
||||
const tokenOut = event.params.tokenOut.toHex()
|
||||
const poolTokenOutId = poolId.concat('-').concat(tokenOut.toString())
|
||||
const poolTokenOut = PoolToken.load(poolTokenOutId)
|
||||
const dtOut = Datatoken.load(tokenOut)
|
||||
const tokenAmountOut = tokenToDecimal(
|
||||
event.params.tokenAmountOut.toBigDecimal(),
|
||||
dtOut == null ? 18 : dtOut.decimals
|
||||
)
|
||||
const newAmountOut = poolTokenOut.balance.minus(tokenAmountOut)
|
||||
updatePoolTokenBalance(
|
||||
poolTokenOut as PoolToken,
|
||||
newAmountOut,
|
||||
'handleSwap.tokenOut'
|
||||
)
|
||||
poolTokenOut.save()
|
||||
debuglog('!!!!!!!!!!!!!!!!!! SWAP SWAP SWAP : (tokenIn, tokenOut, amountIn, amountIn, amountOut, amountOut)', event,
|
||||
[tokenIn, tokenOut, tokenAmountIn.toString(), event.params.tokenAmountIn.toString(),
|
||||
tokenAmountOut.toString(), event.params.tokenAmountOut.toString()])
|
||||
let pool = Pool.load(poolId)
|
||||
debuglog(
|
||||
'!!!!!!!!!!!!!!!!!! SWAP SWAP SWAP : (tokenIn, tokenOut, amountIn, amountIn, amountOut, amountOut)',
|
||||
event,
|
||||
[
|
||||
tokenIn,
|
||||
tokenOut,
|
||||
tokenAmountIn.toString(),
|
||||
event.params.tokenAmountIn.toString(),
|
||||
tokenAmountOut.toString(),
|
||||
event.params.tokenAmountOut.toString()
|
||||
]
|
||||
)
|
||||
const pool = Pool.load(poolId)
|
||||
|
||||
pool.swapCount = pool.swapCount.plus(BigInt.fromI32(1))
|
||||
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())
|
||||
updatePoolTransactionToken(
|
||||
ptx, poolTokenIn.id, tokenAmountIn, poolTokenIn.balance,
|
||||
tokenAmountIn.times(pool.swapFee))
|
||||
ptx,
|
||||
poolTokenIn.id,
|
||||
tokenAmountIn,
|
||||
poolTokenIn.balance,
|
||||
tokenAmountIn.times(pool.swapFee)
|
||||
)
|
||||
updatePoolTransactionToken(
|
||||
ptx, poolTokenOut.id, tokenAmountOut.times(MINUS_1_BD), poolTokenOut.balance,
|
||||
BigDecimal.fromString('0.0'))
|
||||
ptx,
|
||||
poolTokenOut.id,
|
||||
tokenAmountOut.times(MINUS_1_BD),
|
||||
poolTokenOut.balance,
|
||||
BigDecimal.fromString('0.0')
|
||||
)
|
||||
}
|
||||
|
||||
/************************************
|
||||
*********** POOL SHARES ************
|
||||
************************************/
|
||||
|
||||
export function handleTransfer(event: Transfer): void {
|
||||
let poolId = event.address.toHex()
|
||||
export function handleTransfer(event: Transfer): void {
|
||||
const poolId = event.address.toHex()
|
||||
|
||||
let ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
|
||||
|
||||
let isMint = event.params.from.toHex() == ZERO_ADDRESS
|
||||
let isBurn = event.params.to.toHex() == ZERO_ADDRESS
|
||||
const isMint = event.params.from.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 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 poolShareToBalance = poolShareTo == null ? ZERO_BD : poolShareTo.balance
|
||||
const poolShareToBalance = poolShareTo == null ? ZERO_BD : poolShareTo.balance
|
||||
|
||||
let pool = Pool.load(poolId)
|
||||
let poolTx = PoolTransaction.load(event.transaction.hash.toHexString())
|
||||
let value = tokenToDecimal(event.params.value.toBigDecimal(), 18)
|
||||
const pool = Pool.load(poolId)
|
||||
const poolTx = PoolTransaction.load(event.transaction.hash.toHexString())
|
||||
const value = tokenToDecimal(event.params.value.toBigDecimal(), 18)
|
||||
|
||||
if (isMint) {
|
||||
if (poolShareTo == null) {
|
||||
@ -343,7 +446,6 @@ export function handleSwap(event: LOG_SWAP): void {
|
||||
poolTx.sharesTransferAmount = -value
|
||||
poolTx.sharesBalance = poolShareFrom.balance
|
||||
}
|
||||
|
||||
} else {
|
||||
if (poolShareTo == null) {
|
||||
createPoolShareEntity(poolShareToId, poolId, event.params.to.toHex())
|
||||
@ -361,17 +463,17 @@ export function handleSwap(event: LOG_SWAP): void {
|
||||
}
|
||||
|
||||
if (
|
||||
poolShareTo !== null
|
||||
&& poolShareTo.balance.notEqual(ZERO_BD)
|
||||
&& poolShareToBalance.equals(ZERO_BD)
|
||||
poolShareTo !== null &&
|
||||
poolShareTo.balance.notEqual(ZERO_BD) &&
|
||||
poolShareToBalance.equals(ZERO_BD)
|
||||
) {
|
||||
pool.holderCount += BigInt.fromI32(1)
|
||||
}
|
||||
|
||||
if (
|
||||
poolShareFrom !== null
|
||||
&& poolShareFrom.balance.equals(ZERO_BD)
|
||||
&& poolShareFromBalance.notEqual(ZERO_BD)
|
||||
poolShareFrom !== null &&
|
||||
poolShareFrom.balance.equals(ZERO_BD) &&
|
||||
poolShareFromBalance.notEqual(ZERO_BD)
|
||||
) {
|
||||
pool.holderCount -= BigInt.fromI32(1)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ dataSources:
|
||||
name: Factory
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0xbe0083053744ECb871510C88dC0f6b77Da162706"
|
||||
address: '0xbe0083053744ECb871510C88dC0f6b77Da162706'
|
||||
abi: Factory
|
||||
startBlock: 11105585
|
||||
mapping:
|
||||
@ -28,7 +28,7 @@ dataSources:
|
||||
name: DTFactory
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0x57317f97E9EA49eBd19f7c9bB7c180b8cDcbDeB9"
|
||||
address: '0x57317f97E9EA49eBd19f7c9bB7c180b8cDcbDeB9'
|
||||
abi: DTFactory
|
||||
startBlock: 11105560
|
||||
mapping:
|
||||
@ -66,25 +66,25 @@ templates:
|
||||
file: ./abis/BToken.json
|
||||
eventHandlers:
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x34e1990700000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x34e1990700000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleSetSwapFee
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x92eefe9b00000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x92eefe9b00000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleSetController
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x49b5955200000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x49b5955200000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleSetPublicSwap
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x4bb278f300000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x4bb278f300000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleFinalize
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0xd1d7bc9100000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0xd1d7bc9100000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleSetup
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0x3fdddaa200000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0x3fdddaa200000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleRebind
|
||||
- event: LOG_CALL(indexed bytes4,indexed address,bytes)
|
||||
topic0: "0xe4e1e53800000000000000000000000000000000000000000000000000000000"
|
||||
topic0: '0xe4e1e53800000000000000000000000000000000000000000000000000000000'
|
||||
handler: handleRebind
|
||||
- event: LOG_JOIN(indexed address,indexed address,uint256)
|
||||
handler: handleJoinPool
|
||||
|
@ -1,23 +1,6 @@
|
||||
{
|
||||
"extends": "./node_modules/@graphprotocol/graph-ts/tsconfig.json",
|
||||
"extend": "./node_modules/@graphprotocol/graph-ts/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"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"]
|
||||
"types": ["@graphprotocol/graph-ts"]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user