Copy-paste-ready query patterns. Each one works against Surf’s ClickHouse tables via POST /onchain/sql.
DEX Volume
Top protocols by volume yesterday
Daily volume trend for a specific pair
token_pair is alphabetically sorted (ETH-USDC, not USDC-ETH). Use this for consistent grouping.
Token Prices
Get ETH price for the last 30 days
Price a token by contract address
When both CoinGecko and DEX VWAP prices exist, prefer CoinGecko (source = 'coingecko'). DEX VWAP fills gaps for tokens CoinGecko doesn’t cover.
Large Transfers
Biggest USDC transfers yesterday
Net flow for a wallet
DeFi Protocols
Top protocols by TVL
Highest-fee protocols this week
Best yields above $1M TVL
Use apy_mean_30d instead of apy for smoothed comparison — daily APY can be volatile.
Prediction Markets
Find a market by keyword
Latest open interest (gap-filled)
Polymarket OI is sparse — only rows on days with events. Use argMax to carry forward:
Do not filter HAVING latest_oi > 0 — neg-risk markets legitimately have negative OI on individual conditions. The sum across sibling conditions is correct.
Hyperliquid
Current funding rates (use FINAL)
Open interest in USD
open_interest is in contract units — multiply by mark_px for USD value.
Chain Activity
Daily active addresses across chains
Query Tips
-
Pre-filter in CTEs before JOINing. ClickHouse puts the RIGHT side of a JOIN into a hash table — keep it small.
-
Use
IN (SELECT ...) instead of JOIN when you only need an existence check.
-
Avoid
SELECT * on billion-row tables — project only the columns you need.
-
Use
uniq() instead of count(DISTINCT) — it’s faster and equally accurate.
-
For time-series rollups, use
toStartOfWeek(block_date) or toStartOfMonth(block_date) instead of GROUP BY toString(block_date).
-
For cross-table analysis, filter each table independently in CTEs before joining.