Query editor
with silo_vaults as (select * from (values('sonic', 'USDC.e', 0x29219dd400f2bf60e5a23d13be72b486d4038894, 0x322e1d5384aa4ed66aeca770b95686271de61dc3, 'id_20'), ('sonic', 'wS', 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xf55902de87bd80c6a35614b48d7f8b612a083c12, 'id_20'), ('sonic', 'wS', 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xe223c8e92aa91e966ca31d5c6590ff7167e25801, 'id_8'), ('sonic', 'USDC.e', 0x29219dd400f2bf60e5a23d13be72b486d4038894, 0x4e216c15697c1392fe59e1014b009505e05810df, 'id_8'), ('sonic', 'wS', 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0x4bfead9975a64545c3594090327ef6666c2f6164, 'id_9'), ('sonic', 'WETH', 0x50c42deacd8fc9773493ed674b675be577f2634b, 0x427514a905fa6beaed9a36e308fcfa06ce54e95b, 'id_9')) AS tab(blockchain, asset, asset_address, vault_address, vault_id)), date_parameter as (select casewhen '{{timeframe}}' = 'show all time' then date '2024-12-01' --- sonic launch datewhen '{{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), borrow_summary as (select date_trunc('day', b.block_time) as txn_date, v.asset_address, v.vault_id, sum(bytearray_to_uint256(bytearray_substring(b."data", 1, 32))) as total_borrowed_rawfrom sonic.logs bjoin silo_vaults v on b.contract_address = v.vault_addressjoin date_parameter dp on b.block_time >= dp.start_datewhere b.topic0 = 0x96558a334f4759f0e7c423d68c84721860bd8fbf94ddc4e55158ecb125ad04b5and casewhen '{{current_date}}' = 'exclude'then date_trunc('day', b.block_time) < date_trunc('day', current_date)when '{{current_date}}' = 'include'then date_trunc('day', b.block_time) <= date_trunc('day', current_date)else trueendgroup by 1, 2, 3), repay_summary as (select date_trunc('day', r.block_time) as txn_date, v.asset_address, v.vault_id, sum(bytearray_to_uint256(bytearray_substring(r."data", 1, 32))) as total_repaid_rawfrom sonic.logs rjoin silo_vaults v on r.contract_address = v.vault_addressjoin date_parameter dp on r.block_time >= dp.start_datewhere r.topic0 = 0xe4a1ae657f49cb1fb1c7d3a94ae6093565c4c8c0e03de488f79c377c3c3a24e0and casewhen '{{current_date}}' = 'exclude'then date_trunc('day', r.block_time) < date_trunc('day', current_date)when '{{current_date}}' = 'include'then date_trunc('day', r.block_time) <= date_trunc('day', current_date)else trueendgroup by 1, 2, 3), asset_market_formatted as (select date_trunc('day', "minute") as mkt_date, contract_address