select
date_trunc('day', block_timestamp) as day,
case
when day = '2022-11-08' then 'FTX collapse'
when day > '2022-11-08' then 'After FTX collapse'
when day >= date '2022-11-08' - interval '7 days' then 'A week before FTX collapse'
else 'else' end as priod,
count(distinct tx_id) as tx_count,
count(distinct sender) as unique_user,
avg(tx_count) over (order by day rows between 6 preceding and 0 following) as ma_7_tx_count,
avg(unique_user) over (order by day rows between 6 preceding and 0 following) as ma_7_unique_user
from osmosis.core.fact_transfers
where transfer_type = 'IBC_TRANSFER_IN' and day >= date '2022-11-08' - interval '60 days' and receiver ilike '%osmo%' and tx_status = 'SUCCEEDED'
group by 1, 2