Query editor
with steth_price as (select minute,price from prices.usdwhere blockchain = 'ethereum'and symbol = 'stETH'),days as (SELECT DISTINCT date_trunc('day', block_time) as dayFROM ethereum.transactionsWHERE block_time > timestamp '2023-01-01'),withdraw as (select evt_tx_hash, evt_index, date_trunc('day',evt_block_time) as day_ts,onBehalfOf as user_str, amount as withdraw_amount, NULL as deposit_amount from lybra_finance_ethereum.Lybra_depositor_evt_WithdrawEther),deposit as (select evt_tx_hash, evt_index, date_trunc('day',evt_block_time) as day_ts,onBehalfOf as user_str, NULL as withdraw_amount, amount as deposit_amount from lybra_finance_ethereum.Lybra_depositor_evt_DepositEther),compiled as (select * from withdrawUNION ALLselect * from deposit),daily_aggregate as (select day_ts, user_str, sum(deposit_amount/1e18) as daily_deposit_amount,sum(withdraw_amount/1e18) as daily_withdraw_amount,coalesce(sum(deposit_amount/1e18),0) - coalesce(sum(withdraw_amount/1e18),0) as net_daily_amountfrom compiledgroup by 1,2),rolling_sum as (select day_ts,user_str,sum(net_daily_amount) over (partition by user_str order by day_ts) as total_daily_steth_amount,net_daily_amount as net_daily_steth_amount,lead(day_ts, 1, date(NOW() + interval '1' day)) OVER (partition by user_str ORDER BY day_ts) AS next_day_tsFROM daily_aggregate)select d.day as day_ts,user_str,total_daily_steth_amountfrom rolling_sum bINNER JOIN days d ONb.day_ts <= d.day AND d.day < b.next_day_ts