Query editor
-- Ondo trades executed through OKX DexRouter-- Method: Ondo team dex trades whose tx emits OKX OrderRecord (topic0).-- GMV = SUM per-tx amount (one amount_usd row aggregated with SUM within tx then counted once via DISTINCT logic).WITH ondo AS (SELECT blockchain, block_date AS day, tx_hash, SUM(amount_usd) AS amount_usdFROM dune.ondo_team.result_dex_ondoWHERE blockchain IN ('bnb', 'ethereum')AND block_date >= CURRENT_DATE - INTERVAL '30' DAYAND COALESCE(symbol, '') != 'USDon'GROUP BY 1, 2, 3),bnb_okx AS (SELECT DISTINCT tx_hash, block_dateFROM bnb.logsWHERE block_date >= CURRENT_DATE - INTERVAL '30' DAYAND topic0 = 0x1bb43f2da90e35f7b0cf38521ca95a49e68eb42fac49924930a5bd73cdf7576c),eth_okx AS (SELECT DISTINCT tx_hash, block_dateFROM ethereum.logsWHERE block_date >= CURRENT_DATE - INTERVAL '30' DAYAND topic0 = 0x1bb43f2da90e35f7b0cf38521ca95a49e68eb42fac49924930a5bd73cdf7576c),matched AS (SELECT o.day, o.blockchain, o.tx_hash, o.amount_usdFROM ondo oJOIN bnb_okx k ON o.blockchain = 'bnb' AND k.tx_hash = o.tx_hash AND k.block_date = o.dayUNION ALLSELECT o.day, o.blockchain, o.tx_hash, o.amount_usdFROM ondo oJOIN eth_okx k ON o.blockchain = 'ethereum' AND k.tx_hash = o.tx_hash AND k.block_date = o.day)SELECTday,COUNT(*) AS tx_count,ROUND(SUM(amount_usd), 2) AS gmv_usd,ROUND(SUM(CASE WHEN blockchain = 'bnb' THEN amount_usd ELSE 0 END), 2) AS gmv_bnb,ROUND(SUM(CASE WHEN blockchain = 'ethereum' THEN amount_usd ELSE 0 END), 2) AS gmv_eth,COUNT(CASE WHEN blockchain = 'bnb' THEN 1 END) AS tx_bnb,COUNT(CASE WHEN blockchain = 'ethereum' THEN 1 END) AS tx_ethFROM matchedGROUP BY 1ORDER BY 1 DESC