Research
MethodologyDEX · 11 min

How Uniswap V3 Swap Events Become dex.trades

A Swap log is not a trade. This note walks the decoder from topic0 to a canonical dex.trades row, including the amount and token orientation rules.

Context

Uniswap V3 emits Swap(sender, recipient, amount0, amount1, sqrtPriceX96, liquidity, tick). amount0 and amount1 are signed. Canonical trades need an unsigned sold/bought pair and a protocol tag.

Method

The decoder matches topic0 against the versioned ABI registry, reads the pool’s token0/token1 from protocol.contracts, and orients the signed amounts into token_sold / token_bought.

Findings

A naive abs() on both amounts double-counts flash-swap repayments. We keep only the user-facing leg and attach the flash flag from the surrounding call trace when present.

Implications for the data model

dex.trades is a union of protocol decoders, not a Uniswap table. Each row keeps tx_hash, log_index and protocol so a trade can be traced back to the exact Swap log that produced it.