jkhuhnke11AAVE - Delegations By Month
    Updated 2023-05-13
    with delegatees AS (
    SELECT
    decoded_log:delegatee AS Delegatee,
    count(distinct decoded_log:delegator) AS delegated_wallets
    FROM ethereum.core.fact_decoded_event_logs
    WHERE contract_address = '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'
    AND event_name in ('DelegateChanged')
    GROUP BY delegatee
    HAVING delegated_wallets > 2
    ),
    cnts AS (
    SELECT
    date_trunc('month', block_timestamp::date) AS time,
    count(tx_hash) AS Vote_count,
    count(DISTINCT voter) AS Voter_Count,
    count(DISTINCT proposal_id) AS Participated_proposals,
    sum(voting_power)/pow(10,18) AS Voting_powerr,
    sum(Vote_count) over (ORDER BY time) AS cumulative_vote_count,
    sum(Voting_powerr) over (ORDER BY time) AS cumulative_voting_power
    FROM ethereum.aave.ez_votes
    WHERE voter IN (SELECT delegatee FROM delegatees)
    GROUP BY time
    )
    SELECT
    time as date,
    voting_powerr AS voting_power,
    cumulative_voting_power,
    16000000 AS "AAVE Locked",
    cumulative_voting_power - lag(cumulative_voting_power) OVER (ORDER BY date ASC) as del_change
    FROM cnts
    Run a query to Download Data