uniswapv3 is a Go library for indexing and interacting with Uniswap V3.
It provides event decoding, on-chain state tracking, swap path encoding, pool address computation, and tick/liquidity math utilities. It is designed to work with ethindexer for robust backfill and live indexing.
go get github.com/LeTamanoir/uniswapv3See examples/ for a complete indexing example.
handler := uniswapv3.NewFactoryHandler()
idx, err := ethindexer.OpenContext(ctx, ethindexer.Options{
Client: httpClient,
Handler: handler,
Store: store,
LogFunc: slog.Info,
})After processing, handler.Pools contains the tracked state for every indexed pool:
-
Slot0— currentsqrtPriceX96, tick, and protocol fee -
Liquidity— current global liquidity -
Ticks— initialized ticks with gross/net liquidity -
TickBitmap— initialized tick bitmap
Event decoding
Decodes PoolCreated, Mint, Burn, and Swap logs into typed structs:
event, err := uniswapv3.UnpackSwapEvent(log)State tracking
FactoryHandler implements ethindexer.Handler and maintains pool state by applying mints, burns, and swaps:
- Tracks tick liquidity and flips the tick bitmap when ticks are initialized or cleared
- Updates global liquidity when the current tick crosses position boundaries
- Updates
Slot0on every swap
Swap paths
Encode and decode Uniswap V3 multi-hop swap paths:
path := uniswapv3.NewPathBuilder().
From(tokenA).
Fee(3000).
Hop(tokenB).
Fee(500).
To(tokenC)Pool keys and addresses
Compute canonical pool keys and deterministic CREATE2 pool addresses:
key := uniswapv3.NewPoolKey(token0, token1, fee)
addr := uniswapv3.ComputePoolAddress(key)Utilities
-
uint24/int24helpers (ReadUint24,WriteUint24,ReadInt24) - Tick bitmap position and flip operations
- Liquidity add/sub with overflow checks
just check
go test ./...