select block_timestamp, sum(borrowed_in_ust) as total_borrows_in_ust, avg(borrowed_in_ust) as average_borrows_in_ust from (
select date_trunc('day',block_timestamp) as block_timestamp, event_attributes:borrow_amount/pow(10,6) as borrowed_in_ust from terra.msg_events
where event_type = 'wasm' and tx_status='SUCCEEDED' and
event_attributes:"contract_address"='terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' and event_attributes:action='borrow_stable')
group by block_timestamp