with
main as (
select
tx_id,
event_contract as contract,
block_timestamp
from
flow.core.fact_events
)
select
contract,
count(distinct tx_id) as transactions
from main
where
block_timestamp::date between case '{{ type }}'
when 'daily' then date('{{ end_date }}') - interval '1 day'
when 'weekly' then date('{{ end_date }}') - interval '1 week'
when 'monthly' then date('{{ end_date }}') - interval '1 month'
when 'yearly' then date('{{ end_date }}') - interval '1 year'
end and '{{ end_date }}'
group by 1
order by 2 desc
limit 10