watcher-ts/packages/uni-info-watcher
2021-12-28 16:08:04 +05:30
..
docs/analysis Fix queries, demo mode to display all tokens (#231) 2021-08-26 15:36:16 +05:30
environments Process events in singe job and avoid block progress query to improve performance (#306) 2021-12-10 10:44:10 +05:30
src Use postgraphile client to fetch blocks 2021-12-28 16:08:04 +05:30
test Handle bigint and decimal types for entities in watchers (#295) 2021-12-02 13:22:29 +05:30
.eslintignore uniswap-info-watcher package with frontend schema (#114) 2021-07-02 16:26:32 +05:30
.eslintrc.json Test for all entities after MintEvent. (#188) 2021-08-06 12:12:52 +05:30
.gitignore uniswap-info-watcher package with frontend schema (#114) 2021-07-02 16:26:32 +05:30
.mocharc.yml Test for entities after TransferEvent (#196) 2021-08-10 12:09:00 +05:30
package.json Use node v16 and pprof to generate profile data for watchers (#299) 2021-12-09 10:39:35 +05:30
README.md Run services from transpiled ES5 (#239) 2021-09-02 10:27:56 +05:30
tsconfig.json Enable source maps for transpiled files (#242) 2021-09-07 16:01:15 +05:30

uni-info-watcher

Instructions

Setup

Create a postgres12 database for the job queue:

sudo su - postgres
createdb uni-info-watcher-job-queue

Enable the pgcrypto extension on the job queue database (https://github.com/timgit/pg-boss/blob/master/docs/usage.md#intro).

Example:

postgres@tesla:~$ psql -U postgres -h localhost uni-info-watcher-job-queue
Password for user postgres:
psql (12.7 (Ubuntu 12.7-1.pgdg18.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

uni-watcher-job-queue=# CREATE EXTENSION pgcrypto;
CREATE EXTENSION
uni-info-watcher-job-queue=# exit

Create a postgres12 database for the uni-info watcher:

sudo su - postgres
createdb uni-info-watcher

Update environments/local.toml with database connection settings for both the databases.

Run

  • Build files:

    $ yarn build
    
  • Start the server:

    $ yarn server
    
    # For development.
    $ yarn server:dev
    
    # For specifying config file.
    $ yarn server -f environments/local.toml
    
  • Start the job runner:

    $ yarn job-runner
    
    # For development.
    $ yarn job-runner:dev
    
    # For specifying config file.
    $ yarn job-runner -f environments/local.toml
    
  • Run yarn server:mock to run server with mock data.

Mock Queries

{
  bundle(id: "1", block: { number: 2 }) {
    id
    ethPriceUSD
  }

	bundles(first: 1, block: { number: 2 }) {
    id
    ethPriceUSD
  }

  burns(first: 2, orderBy: timestamp) {
    amount0
    amount1
    amountUSD
    id
    origin
    owner
    pool {
      id
    }
    timestamp
    transaction {
      id
    }
  }

  factories(first: 1, block: { number: 2 }) {
    id
    totalFeesUSD
    totalValueLockedUSD
    totalVolumeUSD
    txCount
  }

  mints(first: 2) {
    amount0
    amount1
    amountUSD
    id
    origin
    owner
    pool {
      id
    }
    timestamp
    transaction {
      id
    }
    sender
  }

  pools(first: 2, block: { number:2 }) {
    feeTier
    id
    liquidity
    sqrtPrice
    tick
    token0 {
      name
    }
    token0Price
    token1 {
      name
    }
    token1Price
    totalValueLockedToken0
    totalValueLockedToken1
    totalValueLockedUSD
    txCount
    volumeUSD
  }

  tokens {
    derivedETH
    feesUSD
    id
    name
    symbol
    totalValueLocked
    totalValueLockedUSD
    txCount
    volume
    volumeUSD
  }

  transactions(first: 2) {
    burns {
      id
    }
    id
    mints {
      id
    }
    swaps{
    	id
    }
    timestamp
  }

  swaps(first: 2) {
    amount0
    amount1
    amountUSD
    id
    origin
    pool {
      id
    }
    timestamp
    transaction {
      id
    }
  }

  poolDayDatas(skip: 1, first: 2) {
	  date
    id
    tvlUSD
    volumeUSD
  }

  tokenDayDatas(first: 2, where: {}) {
	  date
    id
    totalValueLockedUSD
    volumeUSD
  }

  uniswapDayDatas(skip:1, first: 2) {
      date
      id
      tvlUSD
      volumeUSD
  }

  ticks(skip: 1, first: 2, block: { number: 2 }) {
    id
    liquidityGross
    liquidityNet
    price0
    price1
    tickIdx
  }

  tokenHourDatas(skip: 1, first: 2) {
    close
    high
    id
    low
    open
    periodStartUnix
  }
}

Queries with ID param

{
  pool(id: "0x38bb4e5eb41aeaeec59e60ba075298f4d4dfd2a2") {
    feeTier
    id
    liquidity
    sqrtPrice
    tick
    token0 {
      name
    }
    token0Price
    token1 {
      name
    }
    token1Price
    totalValueLockedToken0
    totalValueLockedToken1
    totalValueLockedUSD
    txCount
    volumeUSD
  }

  token(id: "0xb87ddd8af3242e56e52318bacf27fe9dcc75c15a", block: { number:2}) {
    derivedETH
    feesUSD
    id
    name
    symbol
    totalValueLocked
    totalValueLockedUSD
    txCount
    volume
    volumeUSD
  }
}

Scripts

  • generate:schema

    Generate schema for uniswap subgraph in graphql format. The get-graphql-schema tool is used to generate the schema (https://github.com/prisma-labs/get-graphql-schema). The uniswap subgraph graphql endpoint is provided in the script to generate the schema.

  • lint:schema

    Lint schema graphql files:

    $ yarn lint:schema docs/analysis/schema/frontend.graphql
    

Test

Smoke test

To run a smoke test:

  • Start the server in packages/erc-20-watcher.

  • Start the server and the job-runner in packages/uni-watcher.

  • Start the server and the job-runner in packages/uni-info-watcher.

  • Run the smoke test in packages/uni-watcher atleast once.

  • Run:

    $ yarn smoke-test