SandeshCEX inflows + outflow
    Updated 2024-10-10
    -- forked from Binance CEX inflows + outflow @ https://flipsidecrypto.xyz/studio/queries/f12c1fcb-a604-468c-adf7-700ac6c84dbb

    /*
    This query analyzes Binance's arbitrum wallet activity, focusing on deposits and withdrawals.
    It identifies transactions between Binance's labeled addresses and external addresses,
    then aggregates the daily volume for each action type (deposit or withdrawal).

    Key features:
    1. Separates withdrawals and deposits into distinct CTEs
    2. Uses label information to identify Binance-related addresses
    3. Excludes internal transfers between Binance's own addresses
    4. Combines withdrawal and deposit data
    5. Aggregates daily volume by action type
    */

    -- CTE for withdrawal transactions from Binance hot wallets to external addresses
    with arb as
    (
    WITH withdrawals AS (
    with transactions as (
    SELECT
    ent.tx_hash
    , ent.block_timestamp
    , -1 * ent.amount AS amount -- Negative amount to represent outflow
    , ent.to_address
    , 'withdraw' AS action
    , dl.project_name as cex
    , ent.to_address as user
    FROM
    arbitrum.core.ez_token_transfers ent
    INNER JOIN
    arbitrum.core.dim_labels dl
    ON ent.from_address = dl.address
    LEFT JOIN
    arbitrum.core.dim_labels dl_to_address
    ON ent.to_address = dl_to_address.address
    QueryRunArchived: QueryRun has been archived