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/with address(address) as(values(0x2faf487a4414fe77e2327f0bf4ae2a264a776ad2),(0xc098b2a3aa256d2140208c3de6543aaef5cd3a94)), token_price_dec as (select date_trunc('day', minute) as time, avg(price) as avg_pricefrom prices.usdwhere symbol = 'ETH'and decimals = 18and minute >= cast('2022-11-05' as TIMESTAMP)and minute <= cast('2022-11-08' as TIMESTAMP)group by 1), inflow as(selectdate_trunc('day', tx_block_time) as time, 'in' as category, sum(cast(value as double) / pow(10, 18)) as raw_amt, sum(cast(value as double) / pow(10, 18) * tk.avg_price) as usd_amtfrom transfers_ethereum.eth tleft join token_price_dec tk on tk.time = date_trunc('day', tx_block_time)wheret.tx_block_time >= cast('2022-11-05' as TIMESTAMP)and t.tx_block_time <= cast('2022-11-08' as TIMESTAMP)and t.to in (select address from address)group by 1, 2), outflow as(selectdate_trunc('day', tx_block_time) as time, 'out' as category, -1 * sum(cast(value as double) / pow(10, 18)) as raw_amt, -1 * sum(cast(value as double) / pow(10, 18) * tk.avg_price) as usd_amtfrom transfers_ethereum.eth tleft join token_price_dec tk on tk.time = date_trunc('day', tx_block_time)wheret.tx_block_time >= cast('2022-11-05' as TIMESTAMP)and t.tx_block_time <= cast('2022-11-08' as TIMESTAMP)and t."from" in (select address from address)group by 1, 2)selecti.time as time, i.usd_amt as in_amt, o.usd_amt as out_amt, i.usd_amt + o.usd_amt as net_amtfrom inflow ileft join outflow o on i.time = o.time