This Substreams package provides real-time 24-hour rolling volume tracking for Uniswap V3 pools on Ethereum mainnet.
The system uses three store modules:
store_completed_periods
: Tracks the last completed 5-minute period for each poolstore_minute_volumes
: Stores volume data in 5-minute buckets (288 buckets for 24 hours)store_rolling_volumes
: Maintains the current 24-hour rolling volume for each poolUse the test script with various options:
# Run with default settings
./test.sh
# Test with swap activity and filtering
./test.sh -s 12400000 -e 12400010 -f
# Use UI output format
./test.sh --output ui
# Show help
./test.sh -h
# Build the WASM module
cargo build --target wasm32-unknown-unknown --release
# Generate required protobuf files from imported packages
substreams protogen substreams.yaml --output-path src/generated
To prepare your Substreams for deployment:
# 1. Build the WASM module
cargo build --target wasm32-unknown-unknown --release
# 2. Generate required protobuf files (if not already present)
substreams protogen substreams.yaml --output-path src/generated
# 3. Create the SPKG package
substreams pack
# This creates: coinranking-uniswap-v3-v0.1.0.spkg
The SPKG file contains:
To test your packaged Substreams:
# Load JWT token from .env file
source ../../.env
# For testing: Run 100 blocks from a specific start
substreams run coinranking-uniswap-v3-v0.1.0.spkg map_uniswap_ticker_output \
--substreams-api-token="$SUBSTREAMS_API_TOKEN" \
--substreams-endpoint="mainnet.eth.streamingfast.io:443" \
-s 22964000 \ # Start at specific block (overrides initialBlock in yaml)
-t +100 # Stop after 100 blocks
# For production: Start from 24+ hours ago for complete rolling volumes
substreams run coinranking-uniswap-v3-v0.1.0.spkg map_uniswap_ticker_output \
--substreams-api-token="$SUBSTREAMS_API_TOKEN" \
--substreams-endpoint="mainnet.eth.streamingfast.io:443" \
-s -7500 \ # ~25 hours ago (7200 blocks/day + margin)
-t 0 # Stream indefinitely
-7500
(25 hours ago)
The .env
file should contain:
SUBSTREAMS_API_TOKEN=your-jwt-token-here
Once tested, you can publish your package:
.spkg
file to GitHub releases, IPFS, or another public locationsubstreams.yaml
:
imports:
coinranking: https://github.com/coinranking/substreams/releases/download/v0.1.0/coinranking-uniswap-v3-v0.1.0.spkg
The main output includes:
The src/generated/
directory contains protobuf-generated Rust code from the imported Uniswap substreams package. These files are:
.gitignore
)substreams protogen
commandTo regenerate these files:
# Generate Rust bindings from the imported Uniswap package
substreams protogen substreams.yaml --output-path src/generated
# Note: Only uniswap.types.v1.rs is actually used by our code
This command extracts and generates Rust code from the imported Uniswap SPKG defined in substreams.yaml
.
This project uses Rust's standard formatting and linting tools:
# Format code
cargo fmt
# Check for common mistakes and improvements
cargo clippy
# Run before committing
cargo fmt && cargo clippy && cargo build --target wasm32-unknown-unknown --release
cargo fmt
before committingsubstreams gui coinranking-uniswap-v3@v0.1.0 map_uniswap_ticker_output
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 coinranking-uniswap-v3@v0.1.0 uniswap:uni_v0_2_9:map_pools_created
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 coinranking-uniswap-v3@v0.1.0 uniswap:uni_v0_2_9:map_extract_data_types
substreams gui coinranking-uniswap-v3@v0.1.0 store_period_volumes
substreams gui coinranking-uniswap-v3@v0.1.0 store_rolling_deltas
This module stores the Pools emitted by the map_pools_created
module.
Dynamic data sources pattern for Uniswap v3 pools.
substreams gui coinranking-uniswap-v3@v0.1.0 uniswap:uni_v0_2_9:store_pools_created