Query editor
withaddress(address) as (values(0x2faf487a4414fe77e2327f0bf4ae2a264a776ad2),(0xc098b2a3aa256d2140208c3de6543aaef5cd3a94)), token_price_dec as (select date_trunc('day', minute) as time, symbol, contract_address, decimals, avg(price) as avg_pricefrom prices.usdwhere minute >= cast('2022-11-06' as TIMESTAMP) and minute < cast('2022-11-07' as TIMESTAMP)and blockchain = 'ethereum'and contract_address = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2and symbol = 'WETH'group by 1, 2, 3, 4), eth_in as (select date_trunc('day', block_time) as time, 'in' as category, sum( cast(value as double) / pow(10, p.decimals)) as raw_amt, sum( cast(value as double) / pow(10, p.decimals) * p.avg_price) as usd_amtfrom ethereum.traces tleft join token_price_dec p on p.time = date_trunc('day', block_time)where t.block_time >= cast('2022-11-06' as TIMESTAMP) and t.block_time < cast('2022-11-07' as TIMESTAMP)and t."to" in (select address from address)group by 1, 2), eth_out as (select date_trunc('day', block_time) as time, 'out' as category, -1 * sum( cast(value as double) / pow(10, p.decimals)) as raw_amt, -1 * sum( cast(value as double) / pow(10, p.decimals) * p.avg_price) as usd_amtfrom ethereum.traces tleft join token_price_dec p on date_trunc('day', block_time) = p.timewhere t.block_time >= cast('2022-11-06' as TIMESTAMP) and t.block_time < cast('2022-11-07' as TIMESTAMP)and t."from" in (select address from address)group by 1, 2)select sum(usd_amt) as usd_netflowfrom (select time, category, raw_amt, usd_amtfrom eth_inunion allselect time, category, raw_amt, usd_amtfrom eth_out)