WITH txns as
(select distinct tx_hash, transaction_fee as tx_fee
from near.core.fact_transactions b
where (tx_receiver in ('creatives.v1.potfactory.potlock.near')
or tx_signer in ('creatives.v1.potfactory.potlock.near'))
and tx_succeeded = TRUE)
,
qmain as (
select block_timestamp,
signer_id,
receiver_id,
try_parse_json(b.action_data):"deposit"::float / 1e24 as deposit,
txns.tx_fee::float / 1e24 as tx_fee
from near.core.fact_actions_events b, txns
where b.tx_hash = txns.tx_hash
and b.action_name = 'Transfer'
and b.receiver_id <> b.signer_id
and receiver_id <> 'impact.sputnik-dao.near'
)
select signer_id,
count(DISTINCT receiver_id) as supporting_projects_count,
sum(deposit) as total_donated
from qmain
group by signer_id
order by TOTAL_DONATED DESC