Query editor
-- Venue-by-venue volume on one Robinhood Chain pair.---- Four sources, because no single Dune table covers the venues that actually-- compete on a stock-token pair, and they do not all settle the same way:---- 1. dex.trades — every AMM Dune decodes (v3, DLMM, CL, v2)-- 2. uniswap_v4 ..._evt_swap — v4 split by POOL, because dex.trades books-- every v4 pool against the one PoolManager-- address and they collapse into a single row-- 3. robinhood.logs — Fermi's propAMM, which Dune does not decode-- at all: unverified, one contract per token,-- no ABI submitted, so `Swapped` is read raw-- 4. arcus_robinhood ... — Arcus. Its spot router quotes RFQ, so a fill-- settles maker-to-taker through its own-- settlement contract and touches NO pool.-- That makes it a fourth channel, not a-- double count — see `channel` below, which-- flags any Arcus fill whose tx DID also hit-- a pool on this pair.---- Volume is measured in QUOTE-TOKEN units, not Dune's amount_usd, so all four-- legs are computed the same way and none of them depends on a price feed.---- Cost control: every leg is pruned on its partition column with a constant--- foldable expression (block_month / block_date), never on a value carried in-- from a CTE — a partition filter the planner cannot fold is a full scan, and-- robinhood.logs is 160 GB.WITH params AS (SELECTfrom_hex('{{base_token}}') AS base_token,from_hex('{{quote_token}}') AS quote_token,cast(now() - interval '{{hours}}' hour AS timestamp) AS t0),-- 1. Everything Dune decodes, one row per pool. v4 is excluded here and-- recovered per-pool in the next CTE.decoded AS (SELECT'AMM pool' AS channel,t.project || ' v' || t.version AS venue_type,t.project_contract_address AS venue,count(*) AS trades,sum(CASE WHEN t.token_sold_address = p.quote_tokenTHEN t.token_sold_amount ELSE t.token_bought_amount END) AS quote_volumeFROM dex.trades tCROSS JOIN params pWHERE t.blockchain = 'robinhood'AND t.block_month >= date_trunc('month', current_date - interval '3' day)AND t.block_time >= p.t0AND NOT (t.project = 'uniswap' AND t.version = '4')AND ( (t.token_bought_address = p.base_token AND t.token_sold_address = p.quote_token)OR (t.token_bought_address = p.quote_token AND t.token_sold_address = p.base_token))GROUP BY 1, 2, 3),-- 2. The same trades for v4, joined back to the raw event to recover the pool id.-- The join is tiny: only this pair's v4 fills in the window.v4 AS (SELECT