connorhAAVE Proposal Target Addresses
    Updated 2022-09-30
    -- Proposal targets
    WITH targets AS (
    SELECT
    DISTINCT
    proposal_id,
    LOWER(t.value::string) AS target
    FROM aave.proposals,
    lateral flatten(input => targets) t
    ),v AS (
    SELECT
    proposal_id,
    voter,
    voting_power,
    support
    FROM aave.votes
    )

    SELECT
    target AS target_contract,
    LISTAGG(DISTINCT targets.proposal_id,', ') AS involved_proposals,
    COUNT(DISTINCT targets.proposal_id) AS n_proposals,
    COUNT(DISTINCT voter) AS n_voters,
    SUM(voting_power) AS total_voting_power,
    SUM(CASE WHEN LOWER(support) <> 'true' THEN 1 ELSE 0 END) AS voters_against,
    SUM(CASE WHEN LOWER(support) = 'true' THEN 1 ELSE 0 END) AS voters_for
    FROM
    targets
    LEFT JOIN
    v
    ON targets.proposal_id = v.proposal_id
    GROUP BY 1
    ORDER BY n_proposals DESC
    Run a query to Download Data