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_arbitrum.Interaction_evt_Borrowunion allselect time, nullfrom unnest(sequence(cast('2023-07-18' 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_arbitrum.Interaction_evt_Paybackunion allselect time, nullfrom unnest(sequence(cast('2023-07-18' 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_arbitrum.DOG_evt_Barkunion allselect time, nullfrom unnest(sequence(cast('2023-07-18' 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)),-- Calculation of borrowing fees and penalties forfees_and_penalties as (select time,