Query editor
-- Reality onchain trades — base (DEX swaps + Reality primary fills), arbitrum + morph-- Window: HOT 2026-10-01 .. yesterday (UTC); move the cut date forward together with the frozen query---- Sources (each execution is recorded by exactly one source):-- dex : dex.trades swap events where an rToken is bought or sold.-- Token scope = dune.bitgetwallet.result_reality_aum_base (on-chain factory registry,-- all statuses, so delisted tokens still count).-- reality : Reality order-fill event, topic0 0x06ba895c… emitted by the Reality core-- (arbitrum 0x129ea4dd…, morph 0xf49fcde4…). Not indexed by dex.trades.-- Decoded data words: w2 pay token, w3 pay amount (6 dp), w4 price (1e18),-- w5 rToken amount (1e18), w7 side (0 = buy / mint, 1 = sell / burn).-- De-duplication:-- * A swap's two sides are one execution: rToken<->rToken swaps keep USD on the bought leg only-- (`dedup_volume_usd`), so summing across tokens never double counts.-- * Chained routes (e.g. memecoin -> rToken on Uniswap -> burned at Reality in the same tx):-- the Reality fill is kept (exact USD), DEX legs of the SAME rToken in that tx are excluded-- (`overlap_excluded_trades`).-- Router: 'bitget_aggregator' if the tx carries a BGW router event (arb 0xbc1d…c973 / morph 0xc0ce…aa67)-- or tx_to is that router; otherwise dex -> dex.trades.project, reality -> 'reality_direct'.-- Pricing: DEX legs without amount_usd are valued at the same-day, same-token implied price-- (priced DEX legs + Reality fills); still unpriced legs are counted in `unpriced_trades`.WITH reg AS (SELECT blockchain, FROM_HEX(SUBSTR(token_address, 3)) AS token, MAX(token_symbol) AS symbolFROM dune.bitgetwallet.result_reality_aum_baseWHERE blockchain IN ('arbitrum', 'morph') AND token_address IS NOT NULLGROUP BY 1, 2),-- ---------- one pass over logs: Reality fills + BGW router events ----------lg AS (SELECT 'arbitrum' AS chain, block_date, tx_hash, index, contract_address, topic0, topic2, data, tx_from, tx_toFROM arbitrum.logsWHERE block_date >= DATE '2026-10-01' AND block_date < CURRENT_DATEAND ((topic0 = 0x06ba895cfd0d77acded3ac1b6ace1bd4d46226c5a5e76f8c40673b183725c7cfAND contract_address = 0x129ea4ddb91c836f89dfa9ef8102f9e505dfc4ba)OR contract_address = 0xbc1d9760bd6ca468ca9fb5ff2cfbeac35d86c973)UNION ALLSELECT 'morph', block_date, tx_hash, index, contract_address, topic0, topic2, data, tx_from, tx_toFROM morph.logsWHERE block_date >= DATE '2026-10-01' AND block_date < CURRENT_DATEAND ((topic0 = 0x06ba895cfd0d77acded3ac1b6ace1bd4d46226c5a5e76f8c40673b183725c7cfAND contract_address = 0xf49fcde434cf62b9c69d79269c950d46f9c0810e)OR contract_address = 0xc0ce9a3b911f2f52f93f6bf35475be703998aa67)),ev_tx AS (SELECTchain, tx_hash,ARBITRARY(block_date) AS day,ARBITRARY(tx_from) AS tx_from,ARBITRARY(tx_to) AS tx_to,BOOL_OR(topic0 <> 0x06ba895cfd0d77acded3ac1b6ace1bd4d46226c5a5e76f8c40673b183725c7cf) AS has_bgw,ARRAY_AGG(CAST(ROW(BYTEARRAY_SUBSTRING(topic2, 13, 20),IF(BYTEARRAY_TO_UINT256(BYTEARRAY_SUBSTRING(data, 225, 32)) = UINT256 '0', 'buy', 'sell'),CAST(BYTEARRAY_TO_UINT256(BYTEARRAY_SUBSTRING(data, 161, 32)) AS double) / 1e18,CASE WHEN BYTEARRAY_SUBSTRING(data, 77, 20) IN (0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9, -- arb USDT00xaf88d065e77c8cc2239327c5edb3a432268e5831, -- arb USDC0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, -- arb USDC.e0xcfb1186f4e93d60e60a8bdd997427d1f33bc372b) -- morph USDCTHEN CAST(BYTEARRAY_TO_UINT256(BYTEARRAY_SUBSTRING(data, 97, 32)) AS double) / 1e6 END)