freemartian90 Fee by User Type
    Updated 2023-05-10
    -- forked from dc9ef0f8-9642-488a-8f73-0829bec1366c

    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
    ),

    delegate_votes AS (
    SELECT
    tx_hash
    FROM ethereum.aave.ez_votes
    WHERE voter IN (SELECT delegatee FROM delegatees)
    AND block_timestamp > current_date - 90
    ),

    regular_votes AS(
    SELECT
    tx_hash
    FROM ethereum.aave.ez_votes
    WHERE voter NOT IN (SELECT delegatee FROM delegatees)
    AND block_timestamp > current_date - 90

    )

    SELECT
    'Delegates' AS Voter_Type,
    sum(tx_fee) AS Fee,
    avg(tx_fee) AS average_fee,
    sum(gas_used)/pow(10,9) AS Gas,
    avg(gas_used)/pow(10,9) AS Average_gas
    Run a query to Download Data