Sandeshtop G3 holders
    Updated 2025-01-13
    -- Description:
    -- This query performs a series of calculations to analyze token balances across two chains: Arbitrum and Ethereum.
    -- It computes supply metrics such as Total Supply, Locked Supply, Circulating Supply, and others.
    -- Key techniques include the use of CTEs, window functions, and filtering for specific user types (e.g., Gam3sg-controlled, contracts, EOAs).
    -- Description:
    -- This query calculates token balances on both the Arbitrum, Base and Ethereum chains, combines them,
    -- and returns the number of unique token holders per day, along with their classification based on labels.

    WITH balances_table AS (
    -- Arbitrum chain balance calculation
    WITH arb AS (
    -- CTE for all unique dates within the specified date range
    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 <= date_day
    GROUP BY date
    ),
    -- CTE to calculate daily buy and sell amounts 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 -- Placeholder for easy addition of conditions
    AND block_number >= '197169618' -- date : Apr-03-2024
    AND contract_address = LOWER('0xc24a365a870821eb83fd216c9596edd89479d8d7') -- token address of G3
    )
    UNION ALL
    (
    SELECT
    QueryRunArchived: QueryRun has been archived