Query editor
-- Prepared 2026-10-09. UNEXECUTED.-- Public source: https://github.com/duneanalytics/spellbook/blob/main/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql-- UTC interval: 2026-09-09 inclusive through 2026-10-09 exclusive.-- Separate transaction-sender, taker, and affiliate-tag views: NEVER sum across grains or chain scopes.-- Affiliate tags can be opaque identifiers, not wallet addresses; never attach address-owner labels to them.-- Source rows are deduplicated 0x trades/Settler calls, not every underlying pool hop.-- Multiple valid 0x calls in one transaction remain separate volume rows.WITH base AS (SELECTblockchain, block_time, tx_hash, tx_from, taker, tx_to,affiliate_address, volume_usdFROM zeroex.api_fills_dedupedWHERE blockchain IN ('ethereum', 'polygon', 'robinhood', 'base', 'bnb', 'arbitrum')AND block_month >= DATE '2026-09-01'AND block_month < DATE '2026-11-01'AND block_date >= DATE '2026-09-09'AND block_date < DATE '2026-10-09'AND block_time >= TIMESTAMP '2026-09-09 00:00:00'AND block_time < TIMESTAMP '2026-10-09 00:00:00'), expanded AS (SELECTb.blockchain AS source_blockchain,s.chain_scope,a.grain,a.address,b.block_time, b.tx_hash, b.tx_from, b.tx_to, b.volume_usdFROM base bCROSS JOIN UNNEST(ARRAY[ROW('transaction_sender', b.tx_from),ROW('taker', b.taker),ROW('affiliate_tag', b.affiliate_address)]) AS a(grain, address)CROSS JOIN UNNEST(ARRAY[b.blockchain, 'all_six_chains']) AS s(chain_scope)), agg AS (SELECTe.chain_scope,e.grain,e.address,SUM(e.volume_usd) AS volume_usd,COUNT(*) AS trade_rows,COUNT(DISTINCT ROW(e.source_blockchain, e.tx_hash)) AS transactions,COUNT_IF(e.volume_usd IS NULL) AS unpriced_trade_rows,COUNT(DISTINCT e.tx_from) AS sender_addresses,ARRAY_JOIN(ARRAY_SORT(ARRAY_AGG(DISTINCT e.source_blockchain)), ', ') AS active_chains,MAX(e.volume_usd) AS largest_trade_usd,MIN(e.block_time) AS first_trade,MAX(e.block_time) AS last_trade,MAX_BY(e.tx_hash, e.volume_usd) AS largest_trade_tx_hash,MAX_BY(e.tx_to, e.volume_usd) AS largest_trade_tx_to,MAX_BY(e.source_blockchain, e.volume_usd) AS largest_trade_chainFROM expanded eGROUP BY e.chain_scope, e.grain, e.address), shares AS (SELECTa.*,SUM(a.volume_usd) OVER (PARTITION BY a.chain_scope, a.grain) AS scope_volume_usdFROM agg a), ranked AS (SELECTs.*,