amirrzAverage Daily CEX Inflow and Outflow Volume
    Updated 2022-10-15
    with
    cextable as (select * from solana.core.dim_labels where label_type = 'cex'),
    pricetable as (
    select
    block_timestamp::date as day,
    swap_from_mint,
    avg (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
    succeeded = 'TRUE' group by 1,2),
    table1 as ( select
    'Inflow To CEXs' as type,
    block_timestamp::date as date,
    case
    when
    block_timestamp >= '2022-09-11' and block_timestamp <'2022-10-11 23:00:00.000' then 'Before Mango Hack'
    when
    block_timestamp >= '2022-10-11 23:00:00.000' then 'After Mango Hack' else null end as timespan,
    count (distinct tx_id) as TX_Count,
    count (distinct tx_from) as Users_Count,
    sum (amount*usdprice) as Volume
    from
    solana.core.fact_transfers t1 join pricetable t2 on t1.block_timestamp::date = t2.day and t1.mint = t2.swap_from_mint
    where
    tx_to in (select address from cextable)
    and
    timespan is not null group by 1,2,3
    union ALL
    select
    Run a query to Download Data