WITH dgs AS (
SELECT
LOWER(voter) as current_delegate,
voting_power AS current_voting_power
FROM ETHEREUM.CORE.EZ_SNAPSHOT
WHERE space_id = 'opcollective.eth'
QUALIFY(ROW_NUMBER() over(PARTITION BY voter
ORDER BY
vote_timestamp DESC)) = 1
),
top10 AS (
SELECT
current_delegate,
sum(current_voting_power) as top10_vp
FROM dgs
GROUP BY current_delegate
ORDER BY sum(current_voting_power) DESC
LIMIT 10
),
top10sum AS (
SELECT
sum(top10_vp) AS top10_vpsum
FROM top10
),
sum2 AS (
SELECT
sum(current_voting_power) as total
FROM dgs
)
SELECT
top10_vpsum
FROM top10sum