Package Logo
uniswap_v3
839
User Avatar abourgetgithub streamingfast/substreams-uniswap-v3
Published 21 hours ago
mainnet
uniswap_v3
uniswap-v3@v0.2.11
README

Uniswap v3 Substreams package

Substreams Package Open in DevPod! Open in GitHub Codespaces

Substreams-based Uniswap-v3 Substreams-powered-subgraph.

This module emits EntityChanges, and are written directly to graph-node without any AssemblyScript mappings therein.

This module covers all of the entities of the original v3-subgraph by the Uniswap team. It syncs much faster.

Launch the devpod above and run:

substreams auth
substreams build
substreams gui

Alternatively, run the graph_out module against a Substreams cluster, without building it locally:

substreams run -t +150 uniswap-v3@latest graph_out 
[...]
{
  "@module": "graph_out",
  "@block": 12369621,
  "@type": "sf.substreams.entity.v1.EntityChanges",
  "@data": {
    "entityChanges": [
      {
        "entity": "Factory",
        "id": "1f98431c8ad98523631ae4a59f267346ea31f984",
        "ordinal": "1",
        "operation": "CREATE",
        "fields": [
          {
            "name": "id",
            "newValue": {
              "string": "1f98431c8ad98523631ae4a59f267346ea31f984"
            }
          },
          {
            "name": "poolCount",
            "newValue": {
              "bigint": "0"
            }
          },
[...]
       ]
      },
     {
        "entity": "Pool",
        "id": "1d42064fc4beb5f8aaf85f4617ae8b3b5b8bd801",
        "ordinal": "927",
        "operation": "UPDATE",
        "fields": [
          {
            "name": "totalValueLockedToken0",
            "newValue": {
              "bigdecimal": "0.9999999999999999240000000000003427709097170609759698726797493006923644998096278868615627288818359375"
            },
            "oldValue": {
              "bigdecimal": "0"
            }
          }
        ]
      },
[...]
    ]
  }
}

Hack on it

Build substreams-uniswap-v3

make build
[...]
substreams run  -e mainnet.eth.streamingfast.io:443 substreams.yaml graph_out -t +150
[...]
try it :)

Pack everything to release

substreams pack substreams.yaml
)
Documentation
Modules
Maps icon
Maps

map
map_pools_created

c0b6bf5b10eed1d1c6192d886df9201359412f32
map map_pools_created (
blocksf.ethereum.type.v2.Block
)  -> uniswap.types.v1.Pools

This module will loop over block transactions and detect pools created events. Once the pool created events have been detected, Pools structs will be emitted out of the module.

Try with

substreams gui substreams.yaml map_pools_created -t +1000
substreams gui uniswap-v3@v0.2.11 map_pools_created

map
map_tokens_whitelist_pools

3fe75beb1c0f4f94c28c3fc2db537581548f91a9

This modules loops over the pools created and emits ERC20Tokens structs out of the module. Tokens part of the pair of a pool are checked against the WHITELIST_TOKENS constant to see if they are part of the list. If so push the address of the pool in the field whitelist_pools of the token.

Try with

substreams gui substreams.yaml map_tokens_whitelist_pools -t +1000
substreams gui uniswap-v3@v0.2.11 map_tokens_whitelist_pools

map
map_extract_data_types

497785b4981b8f9c6d43a34b7ad308afadf29074

Chunky module which emits multiple types of Events. Looping over every transaction to filter out Events. For some events, we have to loop over StorageChanges to be able to fetch certain changes such as liquidity increases and decreases. For more information on what the Event contains, check proto/uniswap/v1/uniswap.proto.

Try with

substreams gui substreams.yaml map_extract_data_types -t +1000
substreams gui uniswap-v3@v0.2.11 map_extract_data_types

map
graph_out

4af4dca6b650a234880a97409e9d74228bb11018

EntityChanges emitted out for all the entities defined in the schema.graphql for the Uniswap v3 Subgraph.

substreams gui uniswap-v3@v0.2.11 graph_out
Stores icon
Stores

store
store_pools_created

8c57c63704d72bed38586515bacf7cb2a1a7d63e

This module stores the Pools emitted by the map_pools_created module. Dynamic data sources pattern for Uniswap v3 pools.

substreams gui uniswap-v3@v0.2.11 store_pools_created

store
store_tokens

d947081c348fcf199a59eac7480202a1b07c3ab7
store <add,int64> store_tokens (
)

Int64 store accumulator for each time a token is used for any combination for a pool.

substreams gui uniswap-v3@v0.2.11 store_tokens

store
store_pool_count

6a40d215b4a15f239863eee16c3645caa4a5aa24
store <add,bigint> store_pool_count (
)

BigInt store accumulator for each time a pool is created.

substreams gui uniswap-v3@v0.2.11 store_pool_count

store
store_tokens_whitelist_pools

2d5a274f2f9e9b9075f1e53424c33b77dda8dc90
store <append,string> store_tokens_whitelist_pools (
)

String appender store which stores the whitelist_pools field of a token.

substreams gui uniswap-v3@v0.2.11 store_tokens_whitelist_pools

store
store_pool_sqrt_price

28b150ca8589aa74f9b416fdf28b93652fc86386

Store setter for PoolSqrtPrice emitted out of the map_extract_data_types.

substreams gui uniswap-v3@v0.2.11 store_pool_sqrt_price

store
store_prices

19763d8f9836df8de625a23405ce40017d59e5f5

BigDecimal store setter for storing the price of token0 <> token1 and vice versa. Also store the Daily and Hourly prices.

For example: Pool: TOKEN0 <> TOKEN1 - pool:{pool_address}:{token0_addr}:token0 -> 100 - pool:{pool_address}:{token1_addr}:token1 -> 1 This means that the price of TOKEN0 is 100 for 1 TOKEN1

substreams gui uniswap-v3@v0.2.11 store_prices

store
store_pool_liquidities

72b7c20d3d3d723bc47dca29b5ff86bb3a6bdf52
store <set,bigint> store_pool_liquidities (
)

BigInt store setter for storing pool liquidites which were extracted from map_extract_data_types.

substreams gui uniswap-v3@v0.2.11 store_pool_liquidities

store
store_total_tx_counts

06a4a7b684c255c05a36f79b372f81dcb3d367b0
store <add,bigint> store_total_tx_counts (
)

BigInt accumulator store for the total transaction counts for pools, tokens, factory, daily factory, daily and hourly for token and pool data.

substreams gui uniswap-v3@v0.2.11 store_total_tx_counts

store
store_swaps_volume

00e7913dbe71385a9a5bcdd4010ddfe4c5964165

BigDecimal accumulator store for the swap volume of various entries such as amount0_abs, amount1_abs, volume_usd, volume_usd_untracked, volume_eth, fee_usd and fee_eth. The _0 and _1 entries are the value of one token for another token.

substreams gui uniswap-v3@v0.2.11 store_swaps_volume

store
store_native_amounts

51ee5e867de2e406676167ed617f118fc9332bce
store <set,bigdecimal> store_native_amounts (
)

BigDecimal setter store for the native amounts out of any Event type: Mint, Swap and Burn amounts (amount0 and amount1).

substreams gui uniswap-v3@v0.2.11 store_native_amounts

store
store_eth_prices

120a201f463df92fb1fd5f1aa27edff78c19d4ca
store <set,bigdecimal> store_eth_prices (
store_pricesGET<set,bigdecimal>
store_native_amountsGET<set,bigdecimal>
store_pool_liquiditiesGET<set,bigint>
)

BigDecimal setter store for the eth_price. This module uses a multiple stores and map_extract_data_types to find the eth_price of any given token. If a pool contains a token which has a pair with a well-known token, the eth_price is easily found. Stores the USD price of ETH.

For example: - Pool: DAI <> WBTC -> we check if there is a pool with DAI <> ETH and easily derive the price - Pool: ANYTOKEN0 <> DAI -> we can derive the price by finding the pool DAI <> ETH - Pool: ANYTOKEN0 <> ANYTOKEN1 -> more complicated case where we have to check on either side of the pool and try to find a path to reach a whitelisted_token which has a pool with ETH to be able to derive the price

substreams gui uniswap-v3@v0.2.11 store_eth_prices

store
store_token_tvl

238e662a074c718f00cef79937cbc9736a1828ca
store <add,bigdecimal> store_token_tvl (
)

BigDecimal accumulator store for the total_value_locked for tokens.

substreams gui uniswap-v3@v0.2.11 store_token_tvl

store
store_derived_tvl

fd15be7055526ce0e6920a2c0bc82f260f596560
store <set,bigdecimal> store_derived_tvl (
store_token_tvlGET<add,bigdecimal>
store_eth_pricesGET<set,bigdecimal>
)

BigDecimal accumulator store for the derived total_value_locked in USD, ETH, USDUntracked and ETHUntracked for pools and tokens.

substreams gui uniswap-v3@v0.2.11 store_derived_tvl

store
store_derived_factory_tvl

f99810c9ea4518a64eed5ae49237423ab6bc4a04
store <add,bigdecimal> store_derived_factory_tvl (
store_derived_tvlDELTAS<set,bigdecimal>
)

BigDecimal accumulator store for the derived total_value_locked in USD, ETH, USDUntracked and ETHUntracked for the factory.

substreams gui uniswap-v3@v0.2.11 store_derived_factory_tvl

store
store_ticks_liquidities

3b1e2b461f70af4cec665f483c06e57b2ce846e7
store <add,bigint> store_ticks_liquidities (
)

BigInt accumulator store for the liquidities of the pools. Tracking liquidityGross and liquidityNet for pool values at all times, daily and hourly for Mint and Burn events.

substreams gui uniswap-v3@v0.2.11 store_ticks_liquidities

store
store_positions

fac456c935011049561b0d7ebc7ad5577bd5223d

PositionEvent setter store for Position Events emitted out of map_extract_data_types. CreatedPosition, IncreaseLiquidityPosition, DecreaseLiquidityPosition, CollectPosition and TransferPosition are stored.

substreams gui uniswap-v3@v0.2.11 store_positions

store
store_min_windows

b36e0f0cda72c0849c49dbc1f80d21ebc663b15d
store <min,bigdecimal> store_min_windows (
store_pricesDELTAS<set,bigdecimal>
store_eth_pricesDELTAS<set,bigdecimal>
)

BigDecimal minimum store for the price of eth and token prices for open and low for daily and hourly.

substreams gui uniswap-v3@v0.2.11 store_min_windows

store
store_max_windows

8c3348f53b994f669b34131e0709b7d1c519920e
store <max,bigdecimal> store_max_windows (
store_pricesDELTAS<set,bigdecimal>
store_eth_pricesDELTAS<set,bigdecimal>
)

BigDecimal maximum store for the price of eth and token prices for open and low for daily and hourly.

substreams gui uniswap-v3@v0.2.11 store_max_windows
Protobuf

Protobuf Docs Explorer

uniswap.types.v1