WITH metamask as
(SELECT DISTINCT origin_from_address as ofa from ethereum.core.ez_token_transfers
where origin_to_address = lower('0x881D40237659C251811CEC9c364ef91dC08D300C')
),
contracts as
(select contract_address as ca , count(DISTINCT tx_hash) as popular_by_users
from ethereum.core.fact_event_logs
where origin_from_address in (SELECT * from metamask) and ca != '0x881d40237659c251811cec9c364ef91dc08d300c'
GROUP by 1
order by 2 desc )
SELECT label, max(popular_by_users) as max_popular_by_users from
( SELECT * from contracts
inner join ethereum.core.dim_labels
on ca = address )
where label_type ='dex'
GROUP by 1
ORDER by 2 desc
limit 10