Pine AnalyticscbBTC 5 copy
    Updated 2024-11-07
    -- forked from cbBTC 5 @ https://flipsidecrypto.xyz/studio/queries/8c7f62cc-c5cb-422a-bb4b-abe78b9a49ec


    WITH tab1 AS (
    SELECT
    block_timestamp,
    to_address as user,
    'in' as flow,
    amount

    FROM base.core.ez_token_transfers
    WHERE contract_address LIKE lower('0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf')
    union all

    SELECT
    block_timestamp,
    from_address as user,
    'out' as flow,
    amount

    FROM base.core.ez_token_transfers
    WHERE contract_address LIKE lower('0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf')
    ), tab2 as (
    SELECT
    user,
    sum(CASE when flow like 'in' then amount else -amount end) as balance
    from tab1
    where not user like '0x0000000000000000000000000000000000000000'
    GROUP BY 1
    ), tab3 as (
    SELECT
    median(price) as price
    from ethereum.price.ez_prices_hourly
    where token_address like lower('0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599')
    QueryRunArchived: QueryRun has been archived