From f1a8269036be37dcb1128bbafc4ca22c170fe254 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 9 Feb 2021 11:13:31 +0100 Subject: [PATCH] Activate dependabot, build tweaks, green CI (#6) * activate dependabot * package updates * move auto-generated typings, adapt .gitignore * lint fix * eslint config tweaks, turn off eqeqeq rule * kick out Travis, switch to GitHub Actions * Update the readme file. * Add totalOceanLiquidity and fix TVL calculation * add logs to track pool shares. * lockedValue fix * update variable names * Feature/devel instructions (#19) * improve developer docs * fix readme Signed-off-by: mihaisc * update gitignore Signed-off-by: mihaisc * .env, and infura key Signed-off-by: mihaisc Co-authored-by: mihaisc * merged/dependabot-tvl-fix (#21) * Update the readme file. * Add totalOceanLiquidity and fix TVL calculation * add logs to track pool shares. * update variable names * fix error after merge Co-authored-by: ssallam * use const Co-authored-by: ssallam Co-authored-by: Alex Coseru Co-authored-by: mihaisc Co-authored-by: Samer <36411297+ssallam@users.noreply.github.com> --- .eslintrc | 11 +-- .github/dependabot.yml | 8 ++ .github/workflows/ci.yml | 36 +++++++ .gitignore | 8 +- .travis.yml | 12 --- README.md | 91 +++++++++--------- docker/.env.example | 1 + docker/README.md | 80 ++++++++++++++++ docker/bin/create | 11 +++ docker/bin/debug | 9 ++ docker/bin/deploy | 12 +++ docker/bin/reassign | 12 +++ docker/bin/remove | 11 +++ docker/docker-compose.yml | 38 ++++++++ docker/hooks/post_checkout | 8 ++ docker/setup.sh | 42 ++++++++ docker/start | 111 +++++++++++++++++++++ docker/wait_for | 83 ++++++++++++++++ package-lock.json | 191 ++++++++++++++++++++++++++----------- package.json | 16 ++-- schema.graphql | 7 +- src/helpers.ts | 38 ++++++-- src/mappings/datatoken.ts | 4 +- src/mappings/dtfactory.ts | 9 +- src/mappings/factory.ts | 12 +-- src/mappings/pool.ts | 38 +++++++- 26 files changed, 741 insertions(+), 158 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100644 docker/.env.example create mode 100644 docker/README.md create mode 100755 docker/bin/create create mode 100755 docker/bin/debug create mode 100755 docker/bin/deploy create mode 100755 docker/bin/reassign create mode 100755 docker/bin/remove create mode 100644 docker/docker-compose.yml create mode 100755 docker/hooks/post_checkout create mode 100755 docker/setup.sh create mode 100755 docker/start create mode 100755 docker/wait_for diff --git a/.eslintrc b/.eslintrc index 06c96aa..f2a06b1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,17 +5,14 @@ }, "extends": [ "oceanprotocol", - "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended", - "prettier/react", - "prettier/standard", + "prettier", "prettier/@typescript-eslint" ], - "plugins": ["@typescript-eslint", "prettier"], + "plugins": ["@typescript-eslint"], "rules": { "no-use-before-define": "off", + "eqeqeq": "off", "@typescript-eslint/no-use-before-define": "error" - }, - "env": { "es6": true, "node": true } + } } diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..a96934e --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: npm + directory: '/' + schedule: + interval: weekly + time: '03:00' + timezone: Europe/Berlin diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3a51f15 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: 'CI' + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: '14' + + - name: Cache node modules + uses: actions/cache@v1 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: ${{ runner.os }}-node- + + - run: npm ci + - run: npm run lint + # TODO: activate once this issue is solved: + # https://github.com/graphprotocol/graph-ts/issues/113 + # - run: npm run type-check + - run: npm run codegen + - run: npm run build diff --git a/.gitignore b/.gitignore index ad46b30..33da998 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +src/@types +build + # Logs logs *.log @@ -10,6 +13,9 @@ pids *.pid *.seed *.pid.lock +/docker/data +/src/types + # Directory for instrumented libs generated by jscoverage/JSCover lib-cov @@ -30,7 +36,7 @@ bower_components .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release +build # Dependency directories node_modules/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 185d667..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -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 diff --git a/README.md b/README.md index 759b600..b8da669 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ > 🦀 Ocean Protocol Subgraph -[![Build Status](https://travis-ci.com/oceanprotocol/ocean-subgraph.svg?branch=main)](https://travis-ci.com/oceanprotocol/ocean-subgraph) +[![Build Status](https://github.com/oceanprotocol/ocean-subgraph/workflows/CI/badge.svg)](https://github.com/oceanprotocol/ocean-subgraph/actions) [![js oceanprotocol](https://img.shields.io/badge/js-oceanprotocol-7b1173.svg)](https://github.com/oceanprotocol/eslint-config-oceanprotocol) - [🏄 Get Started](#-get-started) @@ -75,58 +75,27 @@ This subgraph is deployed for all networks the Ocean Protocol contracts are depl ## 🦑 Development +Prepare the docker setup: ```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/ -cd graph-node/docker +cd docker ./setup.sh -# Update this line in the `docker-compose.yml` file with your Infura ProjectId -# ethereum: 'mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID' +``` +Edit docker-compose and add your infura key & network + +Start : +```bash 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| {` - -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 -then run `docker-compose up` to get the postgresql and ipfs services running. - -Now you can build and run the graph-node from source - -``` -cargo run -p graph-node --release > graphnode.log -- - --postgres-url postgres://graph-node:let-me-in@localhost:5432/graph-node - --ethereum-rpc mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID - --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 - +To use with ifura key create a .env file (look at .env.example) ```bash -git clone https://github.com/oceanprotocol/ocean-subgraph/ -cd ocean-subgraph -npm i -npm run codegen -npm run create:local -npm run deploy:local +docker-compose --env-file .env up ``` -- 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 +Switch to a new terminal: + +To deploy the ocean-subgraph to graph-node, see the `Deployment` section below. + +You can make changes to the event handlers and/or features and re-deploy, again see the `Deployment` section below. ## ✨ Code Style @@ -142,7 +111,9 @@ 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: +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 @@ -162,6 +133,32 @@ For the GitHub releases steps a GitHub personal access token, exported as `GITHU ## 🛳 Production ## ⬆️ Deployment +- Do the following to deploy the ocean-subgraph to a graph-node running locally: + +```bash +git clone https://github.com/oceanprotocol/ocean-subgraph/ +cd ocean-subgraph +npm i +npm run codegen +npm run create:local +npm run deploy:local +``` + +The above will deploy ocean-subgraph connecting to mainnet. To create/deploy subgraph connecting to Rinkeby or Ropsten test net, +use :local-rinkeby or :local-ropsten with either create or deploy command. + +- 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` or Ctrl+C) + This should stop the graph-node, ipfs and postgres containers + - Delete the `ipfs` and `postgres` folders in `/docker/data` (`rm -rf ./docker/data/*`) + - Run `docker-compose up` to restart graph-node, ipfs and postgres + - Run `npm run create:local` to create the ocean-subgraph + - Run `npm run deploy:local` to deploy the ocean-subgraph + +Note: to deploy to one of the remote nodes run by Ocean, you can do port-forwarding then using the +above `local` create/deploy commands will work as is. ## 🏛 License diff --git a/docker/.env.example b/docker/.env.example new file mode 100644 index 0000000..2005556 --- /dev/null +++ b/docker/.env.example @@ -0,0 +1 @@ +INFURA_PROJECT_ID="xxx" \ No newline at end of file diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..78e82de --- /dev/null +++ b/docker/README.md @@ -0,0 +1,80 @@ +# Graph Node Docker Image + +Preconfigured Docker image for running a Graph Node. + +## Usage + +```sh +docker run -it \ + -e postgres_host= \ + -e postgres_port= \ + -e postgres_user= \ + -e postgres_pass= \ + -e postgres_db= \ + -e ipfs=: \ + -e ethereum=: \ + graphprotocol/graph-node:latest +``` + +### Example usage + +```sh +docker run -it \ + -e postgres_host=host.docker.internal \ + -e postgres_port=5432 \ + -e postgres_user=graph-node \ + -e postgres_pass=oh-hello \ + -e postgres_db=graph-node \ + -e ipfs=host.docker.internal:5001 \ + -e ethereum=mainnet:http://localhost:8545/ \ + graphprotocol/graph-node:latest +``` + +## Docker Compose + +The Docker Compose setup requires an Ethereum network name and node +to connect to. By default, it will use `mainnet:http://host.docker.internal:8545` +in order to connect to an Ethereum node running on your host machine. +You can replace this with anything else in `docker-compose.yaml`. + +> **Note for Linux users:** On Linux, `host.docker.internal` is not +> currently supported. Instead, you will have to replace it with the +> IP address of your Docker host (from the perspective of the Graph +> Node container). +> To do this, run: +> +> ``` +> CONTAINER_ID=$(docker container ls | grep graph-node | cut -d' ' -f1) +> docker exec $CONTAINER_ID /bin/bash -c 'apt install -y iproute2 && ip route' | awk '/^default via /{print $3}' +> ``` +> +> This will print the host's IP address. Then, put it into `docker-compose.yml`: +> +> ``` +> sed -i -e 's/host.docker.internal//g' docker-compose.yml +> ``` + +After you have set up an Ethereum node—e.g. Ganache or Parity—simply +clone this repository and run + +```sh +docker-compose up +``` + +This will start IPFS, Postgres and Graph Node in Docker and create persistent +data directories for IPFS and Postgres in `./data/ipfs` and `./data/postgres`. You +can access these via: + +- Graph Node: + - GraphiQL: `http://localhost:8000/` + - HTTP: `http://localhost:8000/subgraphs/name/` + - WebSockets: `ws://localhost:8001/subgraphs/name/` + - Admin: `http://localhost:8020/` +- IPFS: + - `127.0.0.1:5001` or `/ip4/127.0.0.1/tcp/5001` +- Postgres: + - `postgresql://graph-node:let-me-in@localhost:5432/graph-node` + +Once this is up and running, you can use +[`graph-cli`](https://github.com/graphprotocol/graph-cli) to create and +deploy your subgraph to the running Graph Node. diff --git a/docker/bin/create b/docker/bin/create new file mode 100755 index 0000000..9d9a4eb --- /dev/null +++ b/docker/bin/create @@ -0,0 +1,11 @@ +#! /bin/bash + +if [ $# != 1 ]; then + echo "usage: create " + exit 1 +fi + +api="http://index-node.default/" + +data=$(printf '{"jsonrpc": "2.0", "method": "subgraph_create", "params": {"name":"%s"}, "id":"1"}' "$1") +curl -s -H "content-type: application/json" --data "$data" "$api" diff --git a/docker/bin/debug b/docker/bin/debug new file mode 100755 index 0000000..87649f1 --- /dev/null +++ b/docker/bin/debug @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ -f "$1" ] +then + exec rust-gdb -c "$1" /usr/local/cargo/bin/graph-node +else + echo "usage: debug " + exit 1 +fi diff --git a/docker/bin/deploy b/docker/bin/deploy new file mode 100755 index 0000000..f0c9833 --- /dev/null +++ b/docker/bin/deploy @@ -0,0 +1,12 @@ +#! /bin/bash + +if [ $# != 3 ]; then + echo "usage: deploy " + exit 1 +fi + +api="http://index-node.default/" + +echo "Deploying $1 (deployment $2)" +data=$(printf '{"jsonrpc": "2.0", "method": "subgraph_deploy", "params": {"name":"%s", "ipfs_hash":"%s", "node_id":"%s"}, "id":"1"}' "$1" "$2" "$3") +curl -s -H "content-type: application/json" --data "$data" "$api" diff --git a/docker/bin/reassign b/docker/bin/reassign new file mode 100755 index 0000000..a8eb703 --- /dev/null +++ b/docker/bin/reassign @@ -0,0 +1,12 @@ +#! /bin/bash + +if [ $# -lt 3 ]; then + echo "usage: reassign " + exit 1 +fi + +api="http://index-node.default/" + +echo Assigning to "$3" +data=$(printf '{"jsonrpc": "2.0", "method": "subgraph_reassign", "params": {"name":"%s", "ipfs_hash":"%s", "node_id":"%s"}, "id":"1"}' "$1" "$2" "$3") +curl -s -H "content-type: application/json" --data "$data" "$api" diff --git a/docker/bin/remove b/docker/bin/remove new file mode 100755 index 0000000..baaad2b --- /dev/null +++ b/docker/bin/remove @@ -0,0 +1,11 @@ +#! /bin/bash + +if [ $# != 1 ]; then + echo "usage: create " + exit 1 +fi + +api="http://index-node.default/" + +data=$(printf '{"jsonrpc": "2.0", "method": "subgraph_remove", "params": {"name":"%s"}, "id":"1"}' "$1") +curl -s -H "content-type: application/json" --data "$data" "$api" diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..0dca88e --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3' +services: + graph-node: + image: oceanprotocol/graph-node:latest + ports: + - '8000:8000' + - '8001:8001' + - '8020:8020' + - '8030:8030' + - '8040:8040' + depends_on: + - ipfs + - postgres + environment: + postgres_host: postgres + postgres_user: graph-node + postgres_pass: let-me-in + postgres_db: graph-node + ipfs: 'ipfs:5001' + ethereum: 'rinkeby:https://rinkeby.infura.io/v3/${INFURA_PROJECT_ID}' + RUST_LOG: info + ipfs: + image: ipfs/go-ipfs:v0.4.23 + ports: + - '5001:5001' + volumes: + - ./data/ipfs:/data/ipfs + postgres: + image: postgres + ports: + - '5432:5432' + command: ['postgres', '-cshared_preload_libraries=pg_stat_statements'] + environment: + POSTGRES_USER: graph-node + POSTGRES_PASSWORD: let-me-in + POSTGRES_DB: graph-node + volumes: + - ./data/postgres:/var/lib/postgresql/data diff --git a/docker/hooks/post_checkout b/docker/hooks/post_checkout new file mode 100755 index 0000000..f1b6f18 --- /dev/null +++ b/docker/hooks/post_checkout @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e +set -x + +echo "Setting SOURCE_BRANCH to ${SOURCE_BRANCH}" + +sed -i "s@^ENV SOURCE_BRANCH \"master\"@ENV SOURCE_BRANCH \"${SOURCE_BRANCH}\"@g" Dockerfile diff --git a/docker/setup.sh b/docker/setup.sh new file mode 100755 index 0000000..5823ad0 --- /dev/null +++ b/docker/setup.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -e + +if ! which docker 2>&1 > /dev/null; then + echo "Please install 'docker' first" + exit 1 +fi + +if ! which docker-compose 2>&1 > /dev/null; then + echo "Please install 'docker-compose' first" + exit 1 +fi + +if ! which jq 2>&1 > /dev/null; then + echo "Please install 'jq' first" + exit 1 +fi + +# Create the graph-node container +docker-compose up --no-start graph-node + +# Start graph-node so we can inspect it +docker-compose start graph-node + +# Identify the container ID +CONTAINER_ID=$(docker container ls | grep graph-node | cut -d' ' -f1) + +# Inspect the container to identify the host IP address +HOST_IP=$(docker inspect "$CONTAINER_ID" | jq -r .[0].NetworkSettings.Networks[].Gateway) + +echo "Host IP: $HOST_IP" + +# Inject the host IP into docker-compose.yml +sed -i -e "s/host.docker.internal/$HOST_IP/g" docker-compose.yml + +function stop_graph_node { + # Ensure graph-node is stopped + docker-compose stop graph-node +} + +trap stop_graph_node EXIT diff --git a/docker/start b/docker/start new file mode 100755 index 0000000..c3e681b --- /dev/null +++ b/docker/start @@ -0,0 +1,111 @@ +#!/bin/bash + +save_coredumps() { + graph_dir=/var/lib/graph + datestamp=$(date +"%Y-%m-%dT%H:%M:%S") + ls /core.* >& /dev/null && have_cores=yes || have_cores=no + if [ -d "$graph_dir" -a "$have_cores" = yes ] + then + core_dir=$graph_dir/cores + mkdir -p $core_dir + exec >> "$core_dir"/messages 2>&1 + echo "${HOSTNAME##*-} Saving core dump on ${HOSTNAME} at ${datestamp}" + + dst="$core_dir/$datestamp-${HOSTNAME}" + mkdir "$dst" + cp /usr/local/bin/graph-node "$dst" + cp /proc/loadavg "$dst" + [ -f /Dockerfile ] && cp /Dockerfile "$dst" + tar czf "$dst/etc.tgz" /etc/ + dmesg -e > "$dst/dmesg" + # Capture environment variables, but filter out passwords + env | sort | sed -r -e 's/^(postgres_pass|ELASTICSEARCH_PASSWORD)=.*$/\1=REDACTED/' > "$dst/env" + + for f in /core.* + do + echo "${HOSTNAME##*-} Found core dump $f" + mv "$f" "$dst" + done + echo "${HOSTNAME##*-} Saving done" + fi +} + +wait_for_ipfs() { + # Take the IPFS URL in $1 apart and extract host and port. If no explicit + # host is given, use 443 for https, and 80 otherwise + if [[ "$1" =~ ^((https?)://)?([^:/]+)(:([0-9]+))? ]] + then + proto=${BASH_REMATCH[2]:-http} + host=${BASH_REMATCH[3]} + port=${BASH_REMATCH[5]} + if [ -z "$port" ] + then + [ "$proto" = "https" ] && port=443 || port=80 + fi + wait_for "$host:$port" -t 120 + else + echo "invalid IPFS URL: $1" + exit 1 + fi +} + +start_query_node() { + export DISABLE_BLOCK_INGESTOR=true + graph-node \ + --postgres-url "$postgres_url" \ + --ethereum-rpc $ethereum \ + --ipfs "$ipfs" +} + +start_index_node() { + # Only the index node with the name set in BLOCK_INGESTOR should ingest + # blocks + if [[ ${node_id} != "${BLOCK_INGESTOR}" ]]; then + export DISABLE_BLOCK_INGESTOR=true + fi + + graph-node \ + --node-id "${node_id//-/_}" \ + --postgres-url "$postgres_url" \ + --ethereum-rpc $ethereum \ + --ipfs "$ipfs" +} + +start_combined_node() { + graph-node \ + --postgres-url "$postgres_url" \ + --ethereum-rpc $ethereum \ + --ipfs "$ipfs" +} + +postgres_port=${postgres_port:-5432} +postgres_url="postgresql://$postgres_user:$postgres_pass@$postgres_host:$postgres_port/$postgres_db" + +wait_for_ipfs "$ipfs" +wait_for "$postgres_host:$postgres_port" -t 120 +sleep 5 + +trap save_coredumps EXIT + +export PGAPPNAME="${node_id-$HOSTNAME}" + +# Set custom poll interval +if [ -n "$ethereum_polling_interval" ]; then + export ETHEREUM_POLLING_INTERVAL=$ethereum_polling_interval +fi + +case "${node_role-combined-node}" in + query-node) + start_query_node + ;; + index-node) + start_index_node + ;; + combined-node) + start_combined_node + ;; + *) + echo "Unknown mode for start-node: $1" + echo "usage: start (combined-node|query-node|index-node)" + exit 1 +esac diff --git a/docker/wait_for b/docker/wait_for new file mode 100755 index 0000000..eb0865d --- /dev/null +++ b/docker/wait_for @@ -0,0 +1,83 @@ +#!/bin/sh + +# POSIX compatible clone of wait-for-it.sh +# This copy is from https://github.com/eficode/wait-for/commits/master +# at commit 8d9b4446 + +TIMEOUT=15 +QUIET=0 + +echoerr() { + if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi +} + +usage() { + exitcode="$1" + cat << USAGE >&2 +Usage: + $cmdname host:port [-t timeout] [-- command args] + -q | --quiet Do not output any status messages + -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout + -- COMMAND ARGS Execute command with args after the test finishes +USAGE + exit "$exitcode" +} + +wait_for() { + for i in `seq $TIMEOUT` ; do + nc -z "$HOST" "$PORT" > /dev/null 2>&1 + + result=$? + if [ $result -eq 0 ] ; then + if [ $# -gt 0 ] ; then + exec "$@" + fi + exit 0 + fi + sleep 1 + done + echo "Operation timed out" >&2 + exit 1 +} + +while [ $# -gt 0 ] +do + case "$1" in + *:* ) + HOST=$(printf "%s\n" "$1"| cut -d : -f 1) + PORT=$(printf "%s\n" "$1"| cut -d : -f 2) + shift 1 + ;; + -q | --quiet) + QUIET=1 + shift 1 + ;; + -t) + TIMEOUT="$2" + if [ "$TIMEOUT" = "" ]; then break; fi + shift 2 + ;; + --timeout=*) + TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + break + ;; + --help) + usage 0 + ;; + *) + echoerr "Unknown argument: $1" + usage 1 + ;; + esac +done + +if [ "$HOST" = "" -o "$PORT" = "" ]; then + echoerr "Error: you need to provide a host and port to test." + usage 2 +fi + +wait_for "$@" diff --git a/package-lock.json b/package-lock.json index e9b538e..4a26433 100644 --- a/package-lock.json +++ b/package-lock.json @@ -83,9 +83,9 @@ } }, "@eslint/eslintrc": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.2.2.tgz", - "integrity": "sha512-EfB5OHNYp1F4px/LI/FEnGylop7nOqkQ1LRzCM0KccA2U8tvV8w01KBv37LbO7nW4H+YhKyo2LcJhRwjjV17QQ==", + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.3.0.tgz", + "integrity": "sha512-1JTKgrOKAHVivSvOYw+sJOunkBjUOvjqWk1DPja7ZFhIS2mX/4EgTT8M7eTK9jrKhL/FvXXEbQwIs3pg1xp3dg==", "dev": true, "requires": { "ajv": "^6.12.4", @@ -95,7 +95,7 @@ "ignore": "^4.0.6", "import-fresh": "^3.2.1", "js-yaml": "^3.13.1", - "lodash": "^4.17.19", + "lodash": "^4.17.20", "minimatch": "^3.0.4", "strip-json-comments": "^3.1.1" }, @@ -459,70 +459,71 @@ } }, "@typescript-eslint/eslint-plugin": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.9.1.tgz", - "integrity": "sha512-QRLDSvIPeI1pz5tVuurD+cStNR4sle4avtHhxA+2uyixWGFjKzJ+EaFVRW6dA/jOgjV5DTAjOxboQkRDE8cRlQ==", + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.13.0.tgz", + "integrity": "sha512-ygqDUm+BUPvrr0jrXqoteMqmIaZ/bixYOc3A4BRwzEPTZPi6E+n44rzNZWaB0YvtukgP+aoj0i/fyx7FkM2p1w==", "dev": true, "requires": { - "@typescript-eslint/experimental-utils": "4.9.1", - "@typescript-eslint/scope-manager": "4.9.1", + "@typescript-eslint/experimental-utils": "4.13.0", + "@typescript-eslint/scope-manager": "4.13.0", "debug": "^4.1.1", "functional-red-black-tree": "^1.0.1", + "lodash": "^4.17.15", "regexpp": "^3.0.0", "semver": "^7.3.2", "tsutils": "^3.17.1" } }, "@typescript-eslint/experimental-utils": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.9.1.tgz", - "integrity": "sha512-c3k/xJqk0exLFs+cWSJxIjqLYwdHCuLWhnpnikmPQD2+NGAx9KjLYlBDcSI81EArh9FDYSL6dslAUSwILeWOxg==", + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.13.0.tgz", + "integrity": "sha512-/ZsuWmqagOzNkx30VWYV3MNB/Re/CGv/7EzlqZo5RegBN8tMuPaBgNK6vPBCQA8tcYrbsrTdbx3ixMRRKEEGVw==", "dev": true, "requires": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/scope-manager": "4.9.1", - "@typescript-eslint/types": "4.9.1", - "@typescript-eslint/typescript-estree": "4.9.1", + "@typescript-eslint/scope-manager": "4.13.0", + "@typescript-eslint/types": "4.13.0", + "@typescript-eslint/typescript-estree": "4.13.0", "eslint-scope": "^5.0.0", "eslint-utils": "^2.0.0" } }, "@typescript-eslint/parser": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.9.1.tgz", - "integrity": "sha512-Gv2VpqiomvQ2v4UL+dXlQcZ8zCX4eTkoIW+1aGVWT6yTO+6jbxsw7yQl2z2pPl/4B9qa5JXeIbhJpONKjXIy3g==", + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.13.0.tgz", + "integrity": "sha512-KO0J5SRF08pMXzq9+abyHnaGQgUJZ3Z3ax+pmqz9vl81JxmTTOUfQmq7/4awVfq09b6C4owNlOgOwp61pYRBSg==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "4.9.1", - "@typescript-eslint/types": "4.9.1", - "@typescript-eslint/typescript-estree": "4.9.1", + "@typescript-eslint/scope-manager": "4.13.0", + "@typescript-eslint/types": "4.13.0", + "@typescript-eslint/typescript-estree": "4.13.0", "debug": "^4.1.1" } }, "@typescript-eslint/scope-manager": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.9.1.tgz", - "integrity": "sha512-sa4L9yUfD/1sg9Kl8OxPxvpUcqxKXRjBeZxBuZSSV1v13hjfEJkn84n0An2hN8oLQ1PmEl2uA6FkI07idXeFgQ==", + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.13.0.tgz", + "integrity": "sha512-UpK7YLG2JlTp/9G4CHe7GxOwd93RBf3aHO5L+pfjIrhtBvZjHKbMhBXTIQNkbz7HZ9XOe++yKrXutYm5KmjWgQ==", "dev": true, "requires": { - "@typescript-eslint/types": "4.9.1", - "@typescript-eslint/visitor-keys": "4.9.1" + "@typescript-eslint/types": "4.13.0", + "@typescript-eslint/visitor-keys": "4.13.0" } }, "@typescript-eslint/types": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.9.1.tgz", - "integrity": "sha512-fjkT+tXR13ks6Le7JiEdagnwEFc49IkOyys7ueWQ4O8k4quKPwPJudrwlVOJCUQhXo45PrfIvIarcrEjFTNwUA==", + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.13.0.tgz", + "integrity": "sha512-/+aPaq163oX+ObOG00M0t9tKkOgdv9lq0IQv/y4SqGkAXmhFmCfgsELV7kOCTb2vVU5VOmVwXBXJTDr353C1rQ==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.9.1.tgz", - "integrity": "sha512-bzP8vqwX6Vgmvs81bPtCkLtM/Skh36NE6unu6tsDeU/ZFoYthlTXbBmpIrvosgiDKlWTfb2ZpPELHH89aQjeQw==", + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.13.0.tgz", + "integrity": "sha512-9A0/DFZZLlGXn5XA349dWQFwPZxcyYyCFX5X88nWs2uachRDwGeyPz46oTsm9ZJE66EALvEns1lvBwa4d9QxMg==", "dev": true, "requires": { - "@typescript-eslint/types": "4.9.1", - "@typescript-eslint/visitor-keys": "4.9.1", + "@typescript-eslint/types": "4.13.0", + "@typescript-eslint/visitor-keys": "4.13.0", "debug": "^4.1.1", "globby": "^11.0.1", "is-glob": "^4.0.1", @@ -532,12 +533,12 @@ } }, "@typescript-eslint/visitor-keys": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.9.1.tgz", - "integrity": "sha512-9gspzc6UqLQHd7lXQS7oWs+hrYggspv/rk6zzEMhCbYwPE/sF7oxo7GAjkS35Tdlt7wguIG+ViWCPtVZHz/ybQ==", + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.13.0.tgz", + "integrity": "sha512-6RoxWK05PAibukE7jElqAtNMq+RWZyqJ6Q/GdIxaiUj2Ept8jh8+FUVlbq9WxMYxkmEOPvCE5cRSyupMpwW31g==", "dev": true, "requires": { - "@typescript-eslint/types": "4.9.1", + "@typescript-eslint/types": "4.13.0", "eslint-visitor-keys": "^2.0.0" } }, @@ -1884,13 +1885,13 @@ "dev": true }, "eslint": { - "version": "7.15.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.15.0.tgz", - "integrity": "sha512-Vr64xFDT8w30wFll643e7cGrIkPEU50yIiI36OdSIDoSGguIeaLzBo0vpGvzo9RECUqq7htURfwEtKqwytkqzA==", + "version": "7.18.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.18.0.tgz", + "integrity": "sha512-fbgTiE8BfUJZuBeq2Yi7J3RB3WGUQ9PNuNbmgi6jt9Iv8qrkxfy19Ds3OpL1Pm7zg3BtTVhvcUZbIRQ0wmSjAQ==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@eslint/eslintrc": "^0.2.2", + "@eslint/eslintrc": "^0.3.0", "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", @@ -1914,7 +1915,7 @@ "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", - "lodash": "^4.17.19", + "lodash": "^4.17.20", "minimatch": "^3.0.4", "natural-compare": "^1.4.0", "optionator": "^0.9.1", @@ -1923,7 +1924,7 @@ "semver": "^7.2.1", "strip-ansi": "^6.0.0", "strip-json-comments": "^3.1.0", - "table": "^5.2.3", + "table": "^6.0.4", "text-table": "^0.2.0", "v8-compile-cache": "^2.0.3" }, @@ -1940,6 +1941,12 @@ "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true }, + "astral-regex": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", + "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", + "dev": true + }, "chalk": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", @@ -1950,6 +1957,12 @@ "supports-color": "^7.1.0" } }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, "enquirer": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", @@ -1959,6 +1972,40 @@ "ansi-colors": "^4.1.1" } }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true + }, + "slice-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", + "integrity": "sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==", + "dev": true, + "requires": { + "ansi-styles": "^4.0.0", + "astral-regex": "^2.0.0", + "is-fullwidth-code-point": "^3.0.0" + } + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, "strip-ansi": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", @@ -1973,6 +2020,32 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true + }, + "table": { + "version": "6.0.7", + "resolved": "https://registry.npmjs.org/table/-/table-6.0.7.tgz", + "integrity": "sha512-rxZevLGTUzWna/qBLObOe16kB2RTnnbhciwgPbMMlazz1yZGVEgnZK762xyVdVznhqxrfCeBMmMkgOOaPwjH7g==", + "dev": true, + "requires": { + "ajv": "^7.0.2", + "lodash": "^4.17.20", + "slice-ansi": "^4.0.0", + "string-width": "^4.2.0" + }, + "dependencies": { + "ajv": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-7.0.3.tgz", + "integrity": "sha512-R50QRlXSxqXcQP5SvKUrw8VZeypvo12i2IX0EeR5PiZ7bEKeHWgzgo264LDadUsCU42lTJVhFikTqJwNeH34gQ==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + } + } + } } } }, @@ -2275,9 +2348,9 @@ } }, "eslint-config-prettier": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-7.0.0.tgz", - "integrity": "sha512-8Y8lGLVPPZdaNA7JXqnvETVC7IiVRgAP6afQu9gOQRn90YY3otMNh+x7Vr2vMePQntF+5erdSUBqSzCmU/AxaQ==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-7.1.0.tgz", + "integrity": "sha512-9sm5/PxaFG7qNJvJzTROMM1Bk1ozXVTKI0buKOyb0Bsr1hrwi0H/TzxF/COtf1uxikIK8SwhX7K6zg78jAzbeA==", "dev": true }, "eslint-config-standard": { @@ -2480,9 +2553,9 @@ } }, "eslint-plugin-prettier": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.2.0.tgz", - "integrity": "sha512-kOUSJnFjAUFKwVxuzy6sA5yyMx6+o9ino4gCdShzBNx4eyFRudWRYKCFolKjoM40PEiuU6Cn7wBLfq3WsGg7qg==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.3.1.tgz", + "integrity": "sha512-Rq3jkcFY8RYeQLgk2cCwuc0P7SEFwDravPhsJZOQ5N4YI4DSg50NyqJ/9gdZHzQlHf8MvafSesbNJCcP/FF6pQ==", "dev": true, "requires": { "prettier-linter-helpers": "^1.0.0" @@ -6589,6 +6662,12 @@ } } }, + "require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "dev": true + }, "resolve": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", @@ -7275,9 +7354,9 @@ "dev": true }, "tsutils": { - "version": "3.17.1", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz", - "integrity": "sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==", + "version": "3.19.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.19.1.tgz", + "integrity": "sha512-GEdoBf5XI324lu7ycad7s6laADfnAqCw6wLGI+knxvw9vsIYBaJfYdmeCEG3FMMUiSm3OGgNb+m6utsWf5h9Vw==", "dev": true, "requires": { "tslib": "^1.8.1" @@ -7329,9 +7408,9 @@ } }, "typescript": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.2.tgz", - "integrity": "sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz", + "integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==", "dev": true }, "uglify-js": { diff --git a/package.json b/package.json index 5291573..ea8283a 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,14 @@ "create:local": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020", "create:local-rinkeby": "graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020", "create:local-ropsten": "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", "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://127.0.0.1:5001 --node http://127.0.0.1:8020", "deploy:local-rinkeby": "graph deploy oceanprotocol/ocean-subgraph subgraph.rinkeby.yaml --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020", "deploy:local-ropsten": "graph deploy oceanprotocol/ocean-subgraph subgraph.ropsten.yaml --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020", - "test": "npm run lint && npm run type-check", + "test": "npm run codegen && 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", @@ -25,16 +25,16 @@ "@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", + "@typescript-eslint/eslint-plugin": "^4.13.0", + "@typescript-eslint/parser": "^4.13.0", "auto-changelog": "^2.2.1", - "eslint": "^7.15.0", + "eslint": "^7.18.0", "eslint-config-oceanprotocol": "^1.5.0", - "eslint-config-prettier": "^7.0.0", - "eslint-plugin-prettier": "^3.2.0", + "eslint-config-prettier": "^7.1.0", + "eslint-plugin-prettier": "^3.3.1", "prettier": "^2.2.1", "release-it": "^14.2.2", - "typescript": "^4.1.2" + "typescript": "^4.1.3" }, "dependencies": {}, "repository": { diff --git a/schema.graphql b/schema.graphql index 397a7cb..bbe0f99 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,8 +1,9 @@ type PoolFactory @entity { id: ID! - totalLockedValue: BigDecimal # total value from all pools expressed in OCEAN - totalLiquidity: BigDecimal! # All the pools liquidity value in Ocean + totalValueLocked: BigDecimal # total value from all pools expressed in OCEAN + + totalOceanLiquidity: BigDecimal! # Total of OCEAN liquidity from all pools totalSwapVolume: BigDecimal! # All the swap volume in Ocean totalSwapFee: BigDecimal! # All the swap fee in Ocean @@ -29,7 +30,7 @@ type Pool @entity { totalSwapVolume: BigDecimal! # Total swap volume in OCEAN totalSwapFee: BigDecimal! # Total swap fee in OCEAN - lockedValue: BigDecimal! # locked value expressed in OCEAN (captures both Ocean and Datatoken) + valueLocked: BigDecimal! # value locked in pool expressed in OCEAN (captures both Ocean and Datatoken) datatokenReserve: BigDecimal! # Total pool reserve of Datatoken oceanReserve: BigDecimal! # Total pool reserve of OCEAN spotPrice: BigDecimal! diff --git a/src/helpers.ts b/src/helpers.ts index 7039b91..ee6f3a1 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -19,9 +19,9 @@ import { TokenBalance, TokenTransaction, PoolTransactionTokenValues -} from './types/schema' +} from './@types/schema' -import { Pool } from './types/templates/Pool/Pool' +import { Pool } from './@types/templates/Pool/Pool' export const ZERO_BD = BigDecimal.fromString('0.0') export const MINUS_1_BD = BigDecimal.fromString('-1.0') @@ -34,8 +34,6 @@ export const ENABLE_DEBUG = true const network = dataSource.network() -export const OCEAN: string = getOceanAddress() - function getOceanAddress(): string { if (network == 'ropsten') { return '0x5e8dcb2afa23844bcc311b00ad1a0c30025aade9' @@ -46,6 +44,8 @@ function getOceanAddress(): string { return '0x967da4048cd07ab37855c090aaf366e4ce1b9f48' } +export const OCEAN: string = getOceanAddress() + export function _debuglog( message: string, event: ethereum.Event, @@ -109,6 +109,12 @@ export function updatePoolTokenBalance( null, [source, poolToken.balance.toString(), balance.toString(), poolToken.poolId] ) + if (balance < ZERO_BD || poolToken.balance < ZERO_BD) { + log.warning( + 'EEEEEEEEEEEEEEEEE poolToken.balance < Zero: pool={}, poolToken={}, oldBalance={}, newBalance={}', + [poolToken.poolId, poolToken.tokenAddress.toString(), poolToken.balance.toString(), balance.toString()]) + } + poolToken.balance = balance } @@ -183,8 +189,16 @@ export function updatePoolTransactionToken( ptxTokenValues.save() if (ptxTokenValues.tokenAddress == OCEAN) { + const factory = PoolFactory.load('1') + factory.totalOceanLiquidity = factory.totalOceanLiquidity + ptxTokenValues.tokenReserve - pool.oceanReserve + if (factory.totalOceanLiquidity < ZERO_BD || pool.oceanReserve < ZERO_BD) { + log.warning( + 'EEEEEEEEEEEEEEEEE totalOceanLiquidity or oceanReserve < Zero: pool={}, totOcnLiq={}, ocnRes={}', + [pool.id, factory.totalOceanLiquidity.toString(), pool.oceanReserve.toString()]) + } ptx.oceanReserve = ptxTokenValues.tokenReserve pool.oceanReserve = ptxTokenValues.tokenReserve + factory.save() } else { ptx.datatokenReserve = ptxTokenValues.tokenReserve pool.datatokenReserve = ptxTokenValues.tokenReserve @@ -310,10 +324,18 @@ export function createPoolTransaction( pool.consumePrice = poolTx.consumePrice pool.spotPrice = poolTx.spotPrice - const lockedValue = pool.lockedValue - pool.lockedValue = pool.oceanReserve + (pool.datatokenReserve * pool.spotPrice) - let factory = PoolFactory.load('1') - factory.totalLockedValue = factory.totalLockedValue - lockedValue + pool.lockedValue + const oldValueLocked = pool.valueLocked + const spotPrice = pool.spotPrice >= ZERO_BD ? pool.spotPrice : ZERO_BD + pool.valueLocked = poolTx.oceanReserve + (poolTx.datatokenReserve * spotPrice) + const factory = PoolFactory.load('1') + if (oldValueLocked < ZERO_BD || pool.valueLocked < ZERO_BD) { + log.warning( + 'EEEEEEEEEEEEEEEEE valueLocked < Zero: pool={}, oldVL={}, newVL={}, OCEAN={}, DT={}, spotPrice={}', + [pool.id, oldValueLocked.toString(), pool.valueLocked.toString(), + poolTx.oceanReserve.toString(), poolTx.datatokenReserve.toString(), + pool.spotPrice.toString()]) + } + factory.totalValueLocked = factory.totalValueLocked - oldValueLocked + pool.valueLocked pool.transactionCount = pool.transactionCount.plus(BigInt.fromI32(1)) diff --git a/src/mappings/datatoken.ts b/src/mappings/datatoken.ts index 06f44f8..cb008f9 100644 --- a/src/mappings/datatoken.ts +++ b/src/mappings/datatoken.ts @@ -1,7 +1,7 @@ import { BigInt, BigDecimal } from '@graphprotocol/graph-ts' -import { OrderStarted, Transfer } from '../types/templates/DataToken/DataToken' +import { OrderStarted, Transfer } from '../@types/templates/DataToken/DataToken' -import { Datatoken, TokenBalance, TokenOrder } from '../types/schema' +import { Datatoken, TokenBalance, TokenOrder } from '../@types/schema' import { tokenToDecimal, updateTokenBalance, diff --git a/src/mappings/dtfactory.ts b/src/mappings/dtfactory.ts index 50d88c7..889604e 100644 --- a/src/mappings/dtfactory.ts +++ b/src/mappings/dtfactory.ts @@ -1,7 +1,10 @@ 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 { 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' diff --git a/src/mappings/factory.ts b/src/mappings/factory.ts index 8963be8..9eb59f7 100644 --- a/src/mappings/factory.ts +++ b/src/mappings/factory.ts @@ -1,7 +1,7 @@ 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 { BPoolRegistered } from '../@types/Factory/Factory' +import { PoolFactory, Pool } from '../@types/schema' +import { Pool as PoolContract } from '../@types/templates' import { ZERO_BD } from '../helpers' export function handleNewPool(event: BPoolRegistered): void { @@ -9,10 +9,10 @@ export function handleNewPool(event: BPoolRegistered): void { if (factory == null) { factory = new PoolFactory('1') - factory.totalLiquidity = ZERO_BD + factory.totalOceanLiquidity = ZERO_BD factory.totalSwapVolume = ZERO_BD factory.totalSwapFee = ZERO_BD - factory.totalLockedValue = ZERO_BD + factory.totalValueLocked = ZERO_BD factory.poolCount = 0 factory.finalizedPoolCount = 0 @@ -37,7 +37,7 @@ export function handleNewPool(event: BPoolRegistered): void { pool.totalShares = ZERO_BD pool.totalSwapVolume = ZERO_BD pool.totalSwapFee = ZERO_BD - pool.lockedValue = ZERO_BD + pool.valueLocked = ZERO_BD pool.datatokenReserve = ZERO_BD pool.oceanReserve = ZERO_BD diff --git a/src/mappings/pool.ts b/src/mappings/pool.ts index 7a74a5a..7309521 100644 --- a/src/mappings/pool.ts +++ b/src/mappings/pool.ts @@ -5,7 +5,7 @@ import { LOG_EXIT, LOG_SWAP, Transfer -} from '../types/templates/Pool/Pool' +} from '../@types/templates/Pool/Pool' import { PoolFactory, @@ -14,7 +14,7 @@ import { PoolShare, Datatoken, PoolTransaction -} from '../types/schema' +} from '../@types/schema' import { hexToDecimal, tokenToDecimal, @@ -425,6 +425,8 @@ export function handleTransfer(event: Transfer): void { const pool = Pool.load(poolId) const poolTx = PoolTransaction.load(event.transaction.hash.toHexString()) const value = tokenToDecimal(event.params.value.toBigDecimal(), 18) + debuglog('poolShare Transfer event: (from, to, value)', event, + [event.params.from.toHex(), event.params.to.toHex(), value.toString()]) if (isMint) { if (poolShareTo == null) { @@ -438,8 +440,17 @@ export function handleTransfer(event: Transfer): void { poolTx.sharesTransferAmount = value poolTx.sharesBalance = poolShareTo.balance } - debuglog('pool shares mint: (id, value, totalShares)', event, [poolId, value.toString(), pool.totalShares.toString()]) - + debuglog( + 'pool shares mint: (id, value, totalShares, shareToBalance, toAddress)', + event, + [ + poolId, + value.toString(), + pool.totalShares.toString(), + poolShareTo.balance.toString(), + poolShareTo.userAddress + ] + ) } else if (isBurn) { if (poolShareFrom == null) { createPoolShareEntity(poolShareFromId, poolId, event.params.from.toHex()) @@ -452,7 +463,17 @@ export function handleTransfer(event: Transfer): void { poolTx.sharesTransferAmount = -value poolTx.sharesBalance = poolShareFrom.balance } - debuglog('pool shares burn: (id, value, totalShares)', event, [poolId, value.toString(), pool.totalShares.toString()]) + debuglog( + 'pool shares burn: (id, value, totalShares, shareFromBalance, fromAddress)', + event, + [ + poolId, + value.toString(), + pool.totalShares.toString(), + poolShareFrom.balance.toString(), + poolShareFrom.userAddress + ] + ) } else { if (poolShareTo == null) { createPoolShareEntity(poolShareToId, poolId, event.params.to.toHex()) @@ -467,6 +488,13 @@ export function handleTransfer(event: Transfer): void { } poolShareFrom.balance -= value poolShareFrom.save() + debuglog( + 'pool shares transfer: ' + + '(id, value, totalShares, shareToBalance, shareFromBalance, toAddress, fromAddress)', event, + [poolId, value.toString(), pool.totalShares.toString(), + poolShareTo.balance.toString(), poolShareFrom.balance.toString(), + poolShareTo.userAddress, poolShareFrom.userAddress + ]) } if (