Query editor
withborrow_index as (selectblock_date,block_number,block_time,token_address,token_symbol,max_by(borrow_index, tx_index) as borrow_index,tx_hashfromdune.ether_fi.result_etherfi_cash_borrow_indexgroup by 1, 2, 3, 4, 5, 7),borrow_events as (selectblockchain,contract_address,block_date,block_time,block_number,event_type,tx_index,tx_hash,user_safe,block_number + tx_index/1e6 as block_number_index,token_address,token_symbol,if (event_type = 'borrow', token_amount, -token_amount) as token_amountfromquery_6819800 -- etherfi cash events live querywhere event_type in ('borrow', 'repay', 'liquidation')),enrich_amounts as (selectbe.*,casewhen be.contract_address in (0x8f9d2Cd33551CE06dD0564Ba147513F715c2F4a0, 0xdffcc3536d932eb51df51a7f5fa407c4270d5308) then be.token_amountelse be.token_amount / fi.borrow_indexend as token_amount_indexfromborrow_events beleft joinborrow_index fion be.block_number = fi.block_numberand be.token_address = fi.token_addressand be.tx_hash = fi.tx_hash),daily_index_tmp as (selectblock_date as day,token_symbol,max_by(borrow_index, (block_time, block_number)) as borrow_indexfromborrow_indexgroup by 1, 2