Sandeshpalma ratio
    Updated 2025-01-13
    -- Token Distribution Analysis Query
    -- This query analyzes the distribution of token holdings across Arbitrum, base and Ethereum networks,
    -- calculating the Palma ratio to measure wealth inequality among token holders.
    -- The Palma ratio is the ratio of wealth held by the top 10% of holders to that held by the bottom 40%.
    -- The query covers the period from April 3, 2024, to the current date.

    -- examples of andrew hong's code not being ported well enough : 0x9521b2f0a3ff1cebebad28319ec5a920a8b906c9
    -- and 0x4bb55258790eCfe293d603718F969D2dF15591ff

    -- derived from andrew hong's work https://dune.com/ilemi/Token-Overview-Metrics?

    -- CTE: arb_balance
    -- Purpose: Calculate daily G3 token balances for each address on Arbitrum
    with arb_balance as
    (
    -- Subquery: dates
    -- Generate a list of dates from April 3, 2024, to the current date
    with dates as
    (
    select date_trunc('day',date_day) as date from ethereum.core.dim_dates
    where date_day>='2024-04-03'
    and date_day <= current_date
    group by date
    ),

    -- Subquery: buy_sell_table
    -- Combine token transfer data (both incoming and outgoing) on Arbitrum
    buy_sell_table as
    ((
    select
    date_trunc('day',BLOCK_TIMESTAMP) as date,
    to_address as address,
    amount
    from arbitrum.core.ez_token_transfers
    where 1=1
    and block_number>='197169618' -- April 03 2024
    QueryRunArchived: QueryRun has been archived