Skip to main content

Uniswap V3 Swap Table

Description

Every Uniswap V3 swap with before/after sqrt price, amounts, USD values, and routing details.

Schema

FieldTypeDescription
idBYTESDeterministic ID (MD5 of pool_id, txn_hash, log_index)
uniswap_v3_pool_idSTRINGFK → uniswap_v3_pool.id.
txn_hashSTRINGTransaction hash.
datetimeTIMESTAMPSwap time (UTC).
block_numberINTEGERBlock containing the swap.
log_indexINTEGERLog index within transaction.
token_in_contract_idSTRINGFK → token_contract.id (input token).
token_out_contract_idSTRINGFK → token_contract.id (output token).
sender_addressSTRINGInitiator of the swap.
origin_addressSTRINGOriginal sender if routed via aggregator (nullable).
recipient_addressSTRINGSwap recipient.
sqrt_price_x96_beforeBIGNUMERICsqrt price before (× 2^96).
sqrt_price_x96_afterBIGNUMERICsqrt price after (× 2^96).
raw_amount_inBIGNUMERICAmount in (smallest unit).
raw_amount_outBIGNUMERICAmount out (smallest unit).
usd_value_inFLOATUSD value of inputs at swap time.
usd_value_outFLOATUSD value of outputs at swap time.
ingested_atTIMESTAMPInsert time (UTC).

Example Queries

Price impact per swap (last 7d), top pools by volume

SELECT
p.name,
SUM(s.usd_value_in) AS volume_usd,
AVG(ABS(POW(SAFE_DIVIDE(CAST(s.sqrt_price_x96_after AS FLOAT64),
NULLIF(CAST(s.sqrt_price_x96_before AS FLOAT64), 0)), 2) - 1)) AS avg_price_impact
FROM `defi_prepared.uniswap_v3_swap` s
JOIN `defi_prepared.uniswap_v3_pool` p ON s.uniswap_v3_pool_id = p.id
WHERE s.datetime >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
AND s.sqrt_price_x96_before IS NOT NULL
AND s.sqrt_price_x96_after IS NOT NULL
GROUP BY p.name
ORDER BY volume_usd DESC
LIMIT 25;

Large routed trades (≥ $50k) in the last 30 days

SELECT p.name, s.txn_hash, s.datetime, s.usd_value_in,
CASE WHEN s.sender_address != s.origin_address THEN 'Routed' ELSE 'Direct' END AS route_type
FROM `defi_prepared.uniswap_v3_swap` s
JOIN `defi_prepared.uniswap_v3_pool` p ON s.uniswap_v3_pool_id = p.id
WHERE s.datetime >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
AND s.usd_value_in >= 50000
ORDER BY s.usd_value_in DESC
LIMIT 100;