Query editor
WITHcexAddresses AS (SELECTaddress AS address,nameFROMlabels.cex_ethereum where name not like '%Bitfinex%'),ethPrice AS (SELECTDATE_TRUNC('week', minute) AS date,AVG(price) AS priceFROMprices.usdWHEREsymbol = 'WETH'GROUP BY1),transfers AS (SELECTDATE_TRUNC('day', et.block_time) AS time,SUM(CAST(value AS DOUBLE) / POWER(10, 18)) AS amountFROMethereum.traces AS etJOIN cexAddresses AS cex ON cex.address = et.toWHERE(NOT call_type IN ('delegatecall', 'callcode', 'staticcall')OR call_type IS NULL)AND et.success /* and cex.address != lower(et.from) */GROUP BY1UNION ALLSELECTDATE_TRUNC('day', et.block_time) AS time,- SUM((CAST(value AS DOUBLE) / POWER(10, 18))) AS amount /* -SUM((COALESCE(et.value,0)+COALESCE(trs.gas_used*trs.gas_price,0))/POWER(10, 18)) AS amount */FROMethereum.traces AS etJOIN cexAddresses AS cex ON cex.address = et."from"WHERE(NOT call_type IN ('delegatecall', 'callcode', 'staticcall')OR call_type IS NULL)AND et.success /* and cex.address != lower(et.to) */GROUP BY1)SELECT* /* inflow + outflow as netflow */FROM(SELECTt.time,SUM(CAST(amount AS DOUBLE)) FILTER (WHERECAST(amount AS DOUBLE) > 0) AS inflow,