Query editor
-- This query used incompatible data types from Dune SQL alpha and may need to be updated.-- More details can be found on https://dune.com/docs/query/dunesql-changes/withaddress(address) as (values(0x2faf487a4414fe77e2327f0bf4ae2a264a776ad2),(0xc098b2a3aa256d2140208c3de6543aaef5cd3a94)),token_price as (selectdate_trunc('day', minute) as time,avg(price) as eth_pricefromprices.usdwheresymbol = 'ETH'and minute >= cast('2022-11-06' as TIMESTAMP)and minute < cast('2022-11-07' as TIMESTAMP)group by1),total_eth_deposited AS (SELECT date_trunc('day', block_time) as time ,SUM(cast(value as DECIMAL)/1e18) AS total_deposited_ethFROM ethereum.traces-- WHERE to in (0x2faf487a4414fe77e2327f0bf4ae2a264a776ad2,0xc098b2a3aa256d2140208c3de6543aaef5cd3a94)where to in (select address from address)AND successAND cast(value as DOUBLE) > 0and block_time >= cast('2022-11-06' as TIMESTAMP)and block_time < cast('2022-11-07' as TIMESTAMP)GROUP by 1),total_eth_withdraw AS (SELECT date_trunc('day', block_time) as time ,SUM(value/1e18) AS total_withdrawed_ethFROM ethereum.transactions-- WHERE to in (0x2faf487a4414fe77e2327f0bf4ae2a264a776ad2,0xc098b2a3aa256d2140208c3de6543aaef5cd3a94)where "from" in (select address from address)AND successAND value > 0and block_time >= cast('2022-11-06' as TIMESTAMP)and block_time < cast('2022-11-07' as TIMESTAMP)GROUP by 1),in_flow as (select tp.time, ted.total_deposited_eth as eth_total, ted.total_deposited_eth * tp.eth_price as usd_price, 'in' as category from total_eth_deposited ted left join token_price tp on tp.time = ted.time),out_flow as (select tp.time, -1*ted.total_withdrawed_eth as eth_total , -1*ted.total_withdrawed_eth * tp.eth_price as usd_price, 'out' as category from total_eth_withdraw ted left join token_price tp on tp.time = ted.time)select inf.time as time, inf.eth_total+ouf.eth_total as net_eth, (inf.usd_price+ouf.usd_price)/1e6 as net_usd from in_flow inf left join out_flow ouf on ouf.time = inf.time