Query editor
with borrowed_dusd as (select time, sum(net_daily) over (order by time asc) as total_borrowedfrom(select date_trunc('day', evt_block_time) as time, sum(amount/1e18) as net_dailyfrom (select evt_block_time, cast(amount as double) as amountfrom davos_blast.Interaction_evt_Borrowunion allselect time, nullfrom unnest(sequence(cast('2024-07-11' as timestamp), cast(now() as timestamp), interval '1' day)) as tbl(time)) xgroup by 1order by 1 desc ) y),repayed as (select time, sum(net_daily) over (order by time asc) as total_repayedfrom (select date_trunc('day', evt_block_time) as time, sum(amount/1e18) as net_dailyfrom (select evt_block_time, cast(amount as double) as amountfrom davos_blast.Interaction_evt_Paybackunion allselect time, nullfrom unnest(sequence(cast('2024-07-11' as timestamp), cast(now() as timestamp), interval '1' day)) as tbl(time)) xgroup by 1order by 1 desc ) y),liquidated as (select time, sum(net_daily) over (order by time asc) as total_liquidatedfrom (select date_trunc('day', evt_block_time) as time, sum(amount/1e18) as net_dailyfrom(select evt_block_time, cast(art as double) as amountfrom davos_blast.DOG_evt_Barkunion allselect time, nullfrom unnest(sequence(cast('2024-07-11' as timestamp), cast(now() as timestamp), interval '1' day)) as tbl(time)) xgroup by 1order by 1 desc ) y),summary_table as (select time, coalesce(total_borrowed, 0) as total_borrowed,coalesce(total_repayed, 0) as total_repayed, coalesce(total_liquidated, 0) as total_liquidatedfrom borrowed_dusdleft join repayed using(time)left join liquidated using(time))select *, total_borrowed - (total_repayed+total_liquidated) as currently_borrowed_dusdfrom summary_tableorder by time desc