Query editor
-- [CA] M3 — CEX netflow ETH (daily, 2024-01-01…now)-- H16 / H6 / M3: does ETH flow INTO or OUT of exchange wallets, per day.---- Labels: addresses_ethereum.cex (spell) = (address, cex_name, distinct_name).-- Verified 2026-09-15 via MCP searchTables.-- ⚠️ GOTCHA (fixed after a failed run, execution 01M2JRHCSPYFT06H8SFT458AJE):-- `addresses_ethereum.cex.address` is VARCHAR(42) ('0x…'), while-- `ethereum.transactions."from"/"to"` are VARBINARY. Comparing them directly-- fails with "Value expression and result of subquery must be of the same-- type: row(varbinary) vs row(address varchar(42))". We normalise the label-- set to varbinary once in the CTE instead of casting per row.---- ETH transfers = native value transfers on ethereum.transactions.-- Inflow = value sent TO a labelled CEX address (sell-side supply arriving)-- Outflow = value sent FROM a labelled CEX address (withdrawal / self-custody)-- netflow = inflow - outflow (>0 = supply moving to exchanges)-- Value is in wei -> /1e18 for ETH. USD conversion is deliberately NOT done-- here (keeps the query on one tier): the Strategist converts locally with-- the ETH daily price series.WITH cex AS (SELECT DISTINCT from_hex(replace(lower(address), '0x', '')) AS addrFROM addresses_ethereum.cex),tx AS (SELECT date_trunc('day', block_time) AS day,"from" AS sender,"to" AS receiver,value / 1e18 AS eth_valueFROM ethereum.transactionsWHERE block_time >= TIMESTAMP '2024-01-01 00:00:00'AND success = trueAND value > 0)SELECT t.day,SUM(CASE WHEN ci.addr IS NOT NULL THEN t.eth_value ELSE 0 END) AS inflow_eth,SUM(CASE WHEN co.addr IS NOT NULL THEN t.eth_value ELSE 0 END) AS outflow_eth,SUM(CASE WHEN ci.addr IS NOT NULL THEN t.eth_value ELSE 0 END)- SUM(CASE WHEN co.addr IS NOT NULL THEN t.eth_value ELSE 0 END) AS netflow_eth,COUNT_IF(ci.addr IS NOT NULL) AS inflow_txs,COUNT_IF(co.addr IS NOT NULL) AS outflow_txsFROM tx tLEFT JOIN cex ci ON t.receiver = ci.addrLEFT JOIN cex co ON t.sender = co.addrGROUP BY 1ORDER BY 1 DESC