Query editor
with days as (SELECT DISTINCT date_trunc('day', block_time) as dayFROM ethereum.transactionsWHERE block_time > timestamp '2023-01-01'),mint as (select evt_tx_hash, evt_index, date_trunc('day',evt_block_time) as day_ts,onBehalfOf as user_str, NULL as burn_amount, amount as mint_amount from lybra_finance_ethereum.Lybra_depositor_evt_Mint),burn as (select evt_tx_hash, evt_index, date_trunc('day',evt_block_time) as day_ts,onBehalfOf as user_str, amount as burn_amount, NULL as mint_amount from lybra_finance_ethereum.Lybra_depositor_evt_Burn-- rigid redemptions triggers burns, so there is not need to count rigid redemptions here-- Example of a rigid redemption transaction https://etherscan.io/tx/0x94276d4e63b15ebee7870c04040ea867fb6f9c2d29d2f2b9c381473fa468f5c7#eventlog-- liquidations triggers burns, so there is not need to count liquidations here-- Example of liquidation transaction https://etherscan.io/tx/0xa676f97127fe24d71c975cb0a7a728774b66be6f76160693f781f28dce53e47c#eventlog),compiled as (select * from mintUNION ALLselect * from burn),daily_aggregate as (select day_ts, user_str, sum(mint_amount/1e18) as daily_deposit_amount,sum(burn_amount/1e18) as daily_burn_amount,coalesce(sum(mint_amount/1e18),0) - coalesce(sum(burn_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_eusd_amount,lead(day_ts, 1, date(NOW() + interval '1' day)) OVER (partition by user_str ORDER BY day_ts) AS next_day_ts,net_daily_amount as net_daily_eusd_amountFROM daily_aggregate)select d.day as day_ts,user_str,total_daily_eusd_amountfrom rolling_sum bINNER JOIN days d ONb.day_ts <= d.day AND d.day < b.next_day_ts