Meireth+ Delegations copy
    Updated 2023-06-20
    -- forked from hyUSD Delegations @ https://flipsidecrypto.xyz/edit/queries/2696558f-72ec-442a-87d0-f57843ab447f

    -- forked from eUSD Delegations @ https://flipsidecrypto.xyz/edit/queries/409ca944-2e06-45ae-b0d9-56634d62a0b2

    -- forked from Delegations @ https://flipsidecrypto.xyz/edit/queries/74af9882-c047-49da-9b98-2d22e8fe8c00

    with dates as (
    select
    date_day
    from ethereum.core.dim_dates
    where date_day between '{{start_date}}' and current_date()
    ),

    distinct_delegates as (
    SELECT
    DISTINCT(DECODED_LOG:delegate::string ) as delegate
    FROM ethereum.core.ez_decoded_event_logs
    WHERE CONTRACT_ADDRESS = lower('0xffa151Ad0A0e2e40F39f9e5E9F87cF9E45e819dd')
    AND EVENT_NAME = 'DelegateVotesChanged'
    ),

    dates_x_delegates as (
    select
    date_day,
    delegate
    from dates
    cross join distinct_delegates
    ),

    delegation_balance as (
    SELECT
    DECODED_LOG:delegate::string as delegate,
    DECODED_LOG:newBalance::int / pow(10,18) as new_balance,
    DECODED_LOG:previousBalance::int / power(10,18) as previous_balance,
    BLOCK_TIMESTAMP,
    block_timestamp::date as balance_date
    Run a query to Download Data