Ali3NTotal Inflow / Outflow / Net Flow From/To CEX (Solana) METRICS
    Updated 2022-11-21
    with pricet as (
    select block_timestamp::date as day,
    swap_from_mint as token,
    median (swap_to_amount/swap_from_amount) as USDPrice
    from solana.fact_swaps
    where swap_to_mint in ('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v','Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB') --USDC,USDT
    and swap_to_amount > 0
    and swap_from_amount > 0
    and block_timestamp >= CURRENT_DATE - 21
    and succeeded = 'TRUE'
    group by 1,2),

    cext as (
    select *
    from solana.core.dim_labels
    where label_type ilike '%cex%'),
    Inflowt as (
    select sum (amount*USDPrice) as Inflow_Volume
    from solana.core.fact_transfers t1 join pricet t2 on t1.block_timestamp::date = t2.day and t1.mint = t2.token
    where tx_to in (select distinct address from cext)
    and tx_from not in (select distinct address from cext)
    and block_timestamp >= CURRENT_DATE - 21),

    Outflowt as (
    select sum (amount*USDPrice) as Outflow_Volume
    from solana.core.fact_transfers t1 join pricet t2 on t1.block_timestamp::date = t2.day and t1.mint = t2.token
    where tx_from in (select distinct address from cext)
    and tx_to not in (select distinct address from cext)
    and block_timestamp >= CURRENT_DATE - 21)


    select inflow_volume as Inflow,
    outflow_volume*-1 as Outflow,
    inflow_volume - outflow_volume as Net_Flow
    from Inflowt t1 join Outflowt t2
    Run a query to Download Data