Query editor
withaave_v2 as (selectsymbol, 'aave_v2' as protocol, case when cast("borrowRateMode" as int) = 1 then "borrowRate"/1e27 end as stable_borrow_rate, case when cast("borrowRateMode" as int) = 2 then "borrowRate"/1e27 end as variable_borrow_rate, case when cast("borrowRateMode" as int) = 1 then "amount"/t.decimals end as stable_borrow_amount, case when cast("borrowRateMode" as int) = 2 then "amount"/t.decimals end as variable_borrow_amount, "evt_block_time", "evt_tx_hash"from aave_v2_ethereum.LendingPool_evt_Borrow bleft join tokens.erc20 t on t.contract_address = "reserve" and t.blockchain = 'ethereum'wheresymbol IN ('USDC')--, 'USDT', 'TUSD')), avg_rates as (selectdate,market,apy as "1d_ta",avg(apy) OVER(ORDER BY dateROWS BETWEEN 6 PRECEDING AND CURRENT ROW)as "7d_ta",avg(apy) OVER(ORDER BY dateROWS BETWEEN 29 PRECEDING AND CURRENT ROW)as "30d_ta"from (selectCONCAT(symbol,' ',protocol) as market,date_trunc('day', evt_block_time) as date,100.0*avg(variable_borrow_rate) as apy,sum(variable_borrow_amount) as borrow_volumefrom aave_v2wheresymbol = 'USDC'OR (symbol = 'TUSD' and protocol = 'aave_v2')OR (symbol = 'USDT' and protocol = 'aave_v2')group by 1,2) subwhere date < date_trunc('day',now()))select *from avg_rateswhere date > (NOW() - interval '{{num_days}}' day - interval '{{num_days}}' day)order by date desc