select
date_trunc('day',block_timestamp) as block_day,
contract_label as Collateral,
case
when event_type = 'withdraw' then 'withdrawals'
else 'provide' end as type,
sum(amount_usd) as total_amount
from anchor.collateral
group by block_day, contract_label, type