Query editor
/* Dune: @gasweighing & Twitter/X: @Selectrong */with date_parameter as (select casewhen '{{timeframe}}' = 'show all time' then date '2024-12-01'when '{{timeframe}}' = 'past one year' then now() - interval '1' yearwhen '{{timeframe}}' = 'past six months' then now() - interval '6' monthwhen '{{timeframe}}' = 'past three months'then now() - interval '3' monthwhen '{{timeframe}}' = 'past one month' then now() - interval '1' monthwhen '{{timeframe}}' = 'past two weeks' then now() - interval '14' daywhen '{{timeframe}}' = 'past one week' then now() - interval '7' dayend as start_date), silo_vaults as (select date_trunc('day', "day") as txn_date--- id20 usdc.e vault, round(sum(case when symbol = 'USDC.e' and id = 'ID20' then total_deposites_usd - net_collateral_usd else 0 end), 3) as id20_usdc_e_deposites_usd, round(case when sum(case when symbol = 'USDC.e' and id = 'ID20' then total_deposites_usd - net_collateral_usd else 0 end) = 0 then 0else sum(case when symbol = 'USDC.e' and id = 'ID20' then total_borrows_usd else 0 end) / sum(case when symbol = 'USDC.e' and id = 'ID20' then total_deposites_usd - net_collateral_usd else 0 end)end, 6) as id20_usdc_e_utilization_rate, round(sum(case when symbol = 'USDC.e' and id = 'ID20' then available_to_borrow_usd else 0 end), 3) as id20_usdc_e_available_to_borrow_usd, round(sum(case when symbol = 'USDC.e' and id = 'ID20' then total_borrows_usd else 0 end), 3) as id20_usdc_e_total_borrows_usd--- id20 ws vault, round(sum(case when symbol = 'wS' and id = 'ID20' then total_deposites_usd - net_collateral_usd else 0 end), 3) as id20_ws_deposites_usd, round(case when sum(case when symbol = 'wS' and id = 'ID20' then total_deposites_usd - net_collateral_usd else 0 end) = 0 then 0else sum(case when symbol = 'wS' and id = 'ID20' then total_borrows_usd else 0 end) / sum(case when symbol = 'wS' and id = 'ID20' then total_deposites_usd - net_collateral_usd else 0 end)end, 6) as id20_ws_utilization_rate, round(sum(case when symbol = 'wS' and id = 'ID20' then available_to_borrow_usd else 0 end), 3) as id20_ws_available_to_borrow_usd, round(sum(case when symbol = 'wS' and id = 'ID20' then total_borrows_usd else 0 end), 3) as id20_ws_total_borrows_usd--- id8 usdc.e vault, round(sum(case when symbol = 'USDC.e' and id = 'ID8' then total_deposites_usd - net_collateral_usd else 0 end), 3) as id8_usdc_e_deposites_usd, round(case when sum(case when symbol = 'USDC.e' and id = 'ID8' then total_deposites_usd - net_collateral_usd else 0 end) = 0 then 0else sum(case when symbol = 'USDC.e' and id = 'ID8' then total_borrows_usd else 0 end) / sum(case when symbol = 'USDC.e' and id = 'ID8' then total_deposites_usd - net_collateral_usd else 0 end)end, 6) as id8_usdc_e_utilization_rate, round(sum(case when symbol = 'USDC.e' and id = 'ID8' then available_to_borrow_usd else 0 end), 3) as id8_usdc_e_available_to_borrow_usd, round(sum(case when symbol = 'USDC.e' and id = 'ID8' then total_borrows_usd else 0 end), 3) as id8_usdc_e_total_borrows_usd--- id8 ws vault: status is non-borrowable, round(sum(case when symbol = 'wS' and id = 'ID8' then total_deposites_usd - net_collateral_usd else 0 end), 3) as id8_ws_deposites_usd, round(case when sum(case when symbol = 'wS' and id = 'ID8' then total_deposites_usd - net_collateral_usd else 0 end) = 0 then 0else sum(case when symbol = 'wS' and id = 'ID8' then total_borrows_usd else 0 end) / sum(case when symbol = 'wS' and id = 'ID8' then total_deposites_usd - net_collateral_usd else 0 end)end, 6) as id8_ws_utilization_rate, round(sum(case when symbol = 'wS' and id = 'ID8' then available_to_borrow_usd else 0 end), 3) as id8_ws_available_to_borrow_usd, round(sum(case when symbol = 'wS' and id = 'ID8' then total_borrows_usd else 0 end), 3) as id8_ws_total_borrows_usd--- id9 ws vault, round(sum(case when symbol = 'wS' and id = 'ID9' then total_deposites_usd - net_collateral_usd else 0 end), 3) as id9_ws_deposites_usd, round(case when sum(case when symbol = 'wS' and id = 'ID9' then total_deposites_usd - net_collateral_usd else 0 end) = 0 then 0else sum(case when symbol = 'wS' and id = 'ID9' then total_borrows_usd else 0 end) / sum(case when symbol = 'wS' and id = 'ID9' then total_deposites_usd - net_collateral_usd else 0 end)end, 6) as id9_ws_utilization_rate, round(sum(case when symbol = 'wS' and id = 'ID9' then available_to_borrow_usd else 0 end), 3) as id9_ws_available_to_borrow_usd, round(sum(case when symbol = 'wS' and id = 'ID9' then total_borrows_usd else 0 end), 3) as id9_ws_total_borrows_usd--- id9 weth vault, round(sum(case when symbol = 'WETH' and id = 'ID9' then total_deposites_usd - net_collateral_usd else 0 end), 3) as id9_weth_deposites_usd, round(case when sum(case when symbol = 'WETH' and id = 'ID9' then total_deposites_usd - net_collateral_usd else 0 end) = 0 then 0else sum(case when symbol = 'WETH' and id = 'ID9' then total_borrows_usd else 0 end) / sum(case when symbol = 'WETH' and id = 'ID9' then total_deposites_usd - net_collateral_usd else 0 end)end, 6) as id9_weth_utilization_rate, round(sum(case when symbol = 'WETH' and id = 'ID9' then available_to_borrow_usd else 0 end), 3) as id9_weth_available_to_borrow_usd