Query editor
with constants as (select * from query_5207063), winds as (selectblock_time,varbinary_substring(data,13,20) as address,tx_hash, 'lock' as mode,casewhen topic0 in (select ca from constants where name='unwindtopic') then 'begin unwind'when topic0 in (select ca from constants where name='rewindtopic') then 'cancel unwind'end as op,contract_address, datafrom ethereum.logswhereblock_number >= 22540590 andcontract_address in (select ca from constants where name='unwindingmodule') andtopic0 in (select ca from constants where name in ('unwindtopic','rewindtopic'))), unwinding as (select*, cast(varbinary_to_uint256(varbinary_substring(data,65,32)) as int) as unwinding_epochsfrom windswhere op='begin unwind'), cancels as (select*,varbinary_to_uint256(varbinary_substring(data,33,32)) as unwinding_timestamp,cast(varbinary_to_uint256(varbinary_substring(data,65,32)) as int) as durationfrom windswhere op='cancel unwind'), txs as (select tx_hash, amountfrom dune.bob_dinkytown.result_infinifi_transactionswhere tx_hash in (select tx_hash from unwinding)), records as (selectu.block_time as unwinding_timestamp, c.block_time as cancel_timestamp, t.amount,u.address, u.tx_hash as unwinding_hash, c.tx_hash as cancel_hash,cast(u.unwinding_epochs as int) as duration,cast(coalesce(date_diff('week',date_add('day',casewhen day_of_week(u.block_time)=7 and u.block_time>date_trunc('day',u.block_time)then 7else 7-day_of_week(u.block_time)end,date_trunc('day', u.block_time)),c.block_time),casewhendate_add('week',u.unwinding_epochs,date_add('day',case