Query editor
withaddresses as (SELECTtr."from" as contract, sum(case when tr.block_time >= now() - interval '{{4. Days}}' day then 1 else 0 end) as new_calls, sum(case when tr.block_time < now() - interval '{{4. Days}}' day then 1 else 0 end) as old_calls, count(*) as total_calls, min(tr.block_time) as first_called, arbitrary(tr.tx_hash) as example_hashFROM evms.traces trLEFT JOIN (SELECT *, row_number() over (partition by blockchain, address order by created_at desc) as last_submittedFROM evms.contracts) cON c.blockchain = '{{1. Blockchain}}'and c.address = tr.toand last_submitted = 1LEFT JOIN {{1. Blockchain}}.signatures sig ON bytearray_substring(tr.input,1,4) = sig.id AND sig.name = c.name AND sig.namespace = c.namespaceWHERE tr.successAND cardinality(tr.trace_address) > 1 --don't include wallets, only contractsAND tr.blockchain = '{{1. Blockchain}}'and (contains(split(replace('{{3. Contract Addresses}}',' ',''), ','), cast(tr.to as varchar))ORcontains(split('{{2. Contract Functions}}', ','), concat(c.namespace, '.', c.name, '_call_', split_part(sig.signature,'(',1))) --concat together with chain and match)group by 1HAVING count(*) >= {{5. Minimum Calls}}AND sum(case when tr.block_time < now() - interval '{{4. Days}}' day then 1 else 0 end) < {{5. Minimum Calls}})SELECTget_href(concat(get_chain_explorer('{{1. Blockchain}}'),'/address/',cast(contract as varchar)), COALESCE(concat(c.namespace, ': ', c.name), cast(contract as varchar))) as contract, a.total_calls, get_href(concat(get_chain_explorer('{{1. Blockchain}}'),'/tx/',cast(example_hash as varchar)), '🔗 tx') as example_hash, '||' as col_, date_diff('day', tt.block_time, now()) as contract_days_old, tt.times_called, tt.unique_callers, get_href(concat(get_chain_explorer('{{1. Blockchain}}'),'/address/',cast(tt.deployer as varchar)), COALESCE(ens.name, cast(tt.deployer as varchar))) as deployerFROM addresses aLEFT JOIN (SELECT *, row_number() over (partition by blockchain, address order by created_at desc) as last_submittedFROM evms.contracts) cON c.blockchain = '{{1. Blockchain}}'and c.address = a.contractand last_submitted = 1LEFT JOIN dune.dune.result_contract_stats_summary tt ON tt.address = a.contract AND tt.blockchain = '{{1. Blockchain}}'LEFT JOIN labels.ens ens ON ens.address = tt.deployerorder by total_calls desc