Query editor
WITH liquidation_logs AS (SELECT'ethereum' AS blockchain,contract_address AS market_address,lower(to_hex(substr(topic1, 13, 20))) AS borrower,block_time AS liq_time,tx_hashFROM ethereum.logsWHERE topic0 = 0x35f432a64bd3767447a456650432406c6cacb885819947a202216eeea6820ecfUNION ALLSELECT 'arbitrum', contract_address, lower(to_hex(substr(topic1, 13, 20))), block_time, tx_hashFROM arbitrum.logsWHERE topic0 = 0x35f432a64bd3767447a456650432406c6cacb885819947a202216eeea6820ecf),ordered AS (SELECTblockchain,market_address,borrower,liq_time,tx_hash,lag(liq_time) OVER (PARTITION BY blockchain, market_address, borrowerORDER BY liq_time, tx_hash) AS prev_liq_timeFROM liquidation_logs),flagged AS (SELECTblockchain,market_address,borrower,liq_time,tx_hash,CASEWHEN prev_liq_time IS NULL THEN 1WHEN date_diff('second', prev_liq_time, liq_time) / 60.0 > 60 THEN 1ELSE 0END AS new_episode_flagFROM ordered),episoded AS (SELECTblockchain,market_address,borrower,liq_time,tx_hash,sum(new_episode_flag) OVER (PARTITION BY blockchain, market_address, borrowerORDER BY liq_time, tx_hashROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS episode_idFROM flagged),