with link as
(select
PERMISSION:FunctionCall:receiver_id as contract,
count(tx_hash) as trans
FROM near.core.fact_actions_events_addkey
where PERMISSION:FunctionCall:receiver_id is not null
and block_timestamp >= '2021-09-01'
group by 1
order by 2 DESC
limit 5)
select date_trunc('days', block_timestamp),
count(*) as transactions,
PERMISSION:FunctionCall:receiver_id
from near.core.fact_actions_events_addkey
where PERMISSION:FunctionCall:receiver_id in (select contract from link)
and block_timestamp >= '2021-09-01'
group by 1,3