All packages
uniswap-v4-substreams

uniswap-v4-substreams

StreamingFast
v0.1.1/13 downloads/Repository

Package ref

uniswap-v4-substreams@v0.1.1

Run package

CLI

Run map_events from the command line.

substreams run uniswap-v4-substreams@v0.1.1 map_events -e mainnet --start-block -1
Authenticate by running substreams auth or directly on thegraph.market (see docs).

README

Uniswap v4 Substreams

sg2ss conversion of Uniswap/v4-subgraph, running on every chain where Uniswap v4 is deployed.

LayerRole
SubstreamsDecode PoolManager + PositionManager events (address-gated)
ClickHouseEvent tables + HOL views (api_pools, api_swaps, …)
HasuraGraphQL over public api_* views

No Substreams stores for Tier A+B — v4 pool events all come from a single PoolManager per chain.

Source: streamingfast/substreams-chain-modules · dex/uniswap-v4-substreams

Showcase: substreams.dev/showcases/uniswap-v4

See DESIGN.md.

Networks

The chain is selected with --network; the manifest carries the matching contract addresses (as map_events params) and initialBlock for each one.

Chain--networkPoolManagerPositionManagerinitialBlock
Ethereummainnet0x000000000004444c5dc75cB358380D2e3dE08A900xbD216513d74C8cf14cf4747E6AaA6420FF64ee9e21688329
Basebase0x498581fF718922c3f8e6A244956aF099B2652b2b0x7C5f5A4bBd8fD63184577525326123B519429bDc25350988
Arbitrum Onearbitrum-one0x360E68faCcca8cA495c1B759Fd9EEe466db9FB320xd88F38F930b7952f2DB2432Cb002E7abbF3dD869297842872
OP Mainnetoptimism0x9a13F98Cb987694C9F086b1F5eB990EeA8264Ec30x3C3Ea4B57a46241e54610e5f022E5c45859A1017130947675
Polygonmatic0x67366782805870060151383F4BbFF9daB53e5cD60x1Ec2eBf4F37E7363FDfe3551602425af0B3ceef966980384
BNB Smart Chainbsc0x28e2Ea090877bF75740558f6BFB36A5ffeE9e9dF0x7A4a5c919aE2541AeD11041A1AEeE68f1287f95b45970610
Avalancheavalanche0x06380C0e0912312B5150364B9DC4542BA0DbBc850xB74b1F14d2754AcfcbBe1a221023a5cf50Ab8ACD56195376
Unichainunichain0x1F984000000000000000000000000000000000040x4529A01c7A0410167c5740C487A8DE60232617bf25500
World Chainworldchain0xb1860D529182ac3BC1F51Fa2ABd56662b7D13f330xC585E0f504613b5fBf874F21Af14c65260fB41fA9111872
Blastblast-mainnet0x1631559198A9e474033433b2958daBC135ab64460x4AD2F4CcA2682cBB5B950d660dD458a1D3f1bAaD14377311
Zorazora0x0575338e4C17006aE181B47900A84404247CA30f0xf66C7b99e2040f0D9b326B3b7c152E9663543D6325434534
Soneiumsoneium0x360e68faccca8ca495c1b759fd9eee466db9fb320x1b35d13a2e2528f192637f14b05f0dc0e7deb5662473300
Inkink0x360e68faccca8ca495c1b759fd9eee466db9fb320x1b35d13a2e2528f192637f14b05f0dc0e7deb5664580556
Celocelo0x288dc841A52FCA2707c6947B3A777c5E56cd87BC0xf7965f3981e4D5BC383BfBCb61501763e9068CA943985160
Linealinea0x248083fb965359d82b06c1f5322480dcfc1ad8570xddcad5775b2816a87495f207731b3571d7ee3c7628974969
Monadmonad0x188d586Ddcf52439676Ca21A244753fA19F9Ea8e0x5b7eC4a94fF9beDb700fb82aB09d5846972F401629255895
X Layerxlayer-mainnet0x360E68faCcca8cA495c1B759Fd9EEe466db9FB320xcF1EAFC6928dC385A342E7C6491d371d2871458b46106401
MegaETHmegaeth0xacb7e78fa05d562e0a5d3089ec896d57d057d38e0x9ae0921e981aaa7308f176f8d4f9129b9247c89d7009653
Tempotempo0x33620f62c5b9b2086dd6b62f4a297a9f303470290x3fc79444f8eacc1894775493ff3fa41f1e35ce116606180
Robinhood Chainrobinhood0x8366a39cc670b4001a1121b8f6a443a643e409510x58daec3116aae6d93017baaea7749052e8a04fa79070

Testnets:

Chain--networkPoolManagerPositionManagerinitialBlock
Ethereum Sepoliasepolia0xE03A1074c86CFeDd5C142C4F04F1a1536e2035430x429ba70129df741B2Ca2a85BC3A2a3328e5c09b47258946
Base Sepoliabase-sepolia0x05E73354cFDd6745C338b50BcFDfA3Aa6fA034080x4b2c77d209d3405f41a037ec6c77f7f5b8e2ca8019088197
Arbitrum Sepoliaarbitrum-sepolia0xFB3e0C6F74eB1a21CC1Da29aeC80D2Dfe6C9a3170xAc631556d3d4019C95769033B5E719dD77124BAc105909222
Unichain Sepoliaunichain-testnet0x00b036b58a818b1bc34d502d3fe730db729e62ac0xf969aee60879c54baaed9f3ed26147db216fd6647092034

Addresses come from networks.json in the upstream subgraph; initialBlock is the earlier of the two deployment blocks.

Uniswap v4 is also deployed on Arc, which has no Substreams endpoint yet.

To point the module at contracts not listed here, override the params directly:

substreams run ./substreams.yaml map_events \
  --network base

Prerequisites

Install the Substreams CLI (includes substreams sink clickhousemigration guide). Docker for the local ClickHouse + Hasura stack.

Build

From the monorepo root (workspace member):

cd substreams-chain-modules
cargo build -p uniswap_v4_substreams --release --target wasm32-unknown-unknown
# or:
cd dex/uniswap-v4-substreams && substreams build
# → uniswap-v4-substreams-v0.1.0.spkg

Sink to Postgres (without views and docker helpers)

(You need a postgresql instance accessible with DSN)

DSN="psql://user:$PASSWORD@host:port/dbname?schemaName=..."
substreams sink postgres uniswap-v4-substreams map_events  --dsn "$DSN" --spool-dir=/path/to/tmpdir --spool-max-size=8GiB --network=base

Sink To Clickhouse

git clone https://github.com/streamingfast/substreams-chain-modules.git
cd substreams-chain-modules/dex/uniswap-v4-substreams

docker compose up -d                    # ClickHouse + Hasura + connector
# substreams auth                       # once

substreams sink clickhouse ./substreams.yaml map_events \
  --dsn "clickhouse://default:SecureMe!@127.0.0.1:9000/uniswap_v4" \
  --network base \
  --bytes-encoding hex \
  --cursor-file-path ./cursor.txt \
  --sink-info-folder ./ch-sink-info

# after event tables exist:
./scripts/apply_views.sh
./scripts/hasura_connect_clickhouse.sh

Then open the Console or hit GraphQL:

ServiceURL
GraphQLhttp://localhost:8080/v1/graphql · header x-hasura-admin-secret: SecureMe!
Consolehttp://localhost:8080/console
ClickHousehttp://127.0.0.1:8123 · DB uniswap_v4
curl -s http://localhost:8080/v1/graphql \
  -H 'content-type: application/json' \
  -H 'x-hasura-admin-secret: SecureMe!' \
  -d '{"query":"{ uniswap_v4_api_pools(limit: 5) { pool_id token0 token1 fee tick liquidity swap_count } }"}'

More examples: sql/hasura/examples.graphql

Hosted option: StreamingFast can host the sink against your warehouse — hosted sinks · Portal.

API views

ViewMeaning
api_poolsPool id HOL: tokens, fee, latest price/tick/liquidity
api_swapsSwap events
api_modify_liquidityLiquidity modifications
api_positionsPosition NFT latest owner
api_tokensCurrency addresses seen (no symbol/decimals eth_call yet)

Out of core (for now)

  • USD volumes / Bundle pricing
  • Tick entities, day/hour aggregates as full subgraph parity
  • Hook factory extras (Arrakis/Euler)
  • Token metadata eth_call

Modules

Execution graph

1 modules