hessAverage Unstake
    Updated 2022-11-21
    with sol_price as ( select date(block_timestamp) as date, (sum(SWAP_TO_AMOUNT)/sum(SWAP_FROM_AMOUNT)) as price
    from solana.core.fact_swaps
    where SWAP_FROM_MINT = 'So11111111111111111111111111111111111111112'
    and SWAP_TO_MINT = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
    and date >= '2022-11-02'
    group by 1)
    ,
    staking as ( select date(block_timestamp) as date, action, tx_id,address,stake_pool, (amount/pow(10,9)) as amount , amount*price as amount_usd
    from solana.core.fact_stake_pool_actions a left outer join sol_price b on a.block_timestamp::date = b.date
    where (action ilike '%deposit%' or action ilike '%withdraw%' ) and SUCCEEDED = 'TRUE'
    and date > '2022-11-02')

    ,
    final as ( select date ,case when date <= '2022-11-08' then 'Before FTX' else 'After FTX' end as date_type, count(DISTINCT(tx_id)) as total_Tx, count(DISTINCT(address)) as total_address,
    sum(amount) as total_amount, sum(amount_usd) as total_usd , avg(amount) as avg_amount,
    max(amount) as max_amount, min(amount) as min_amount, median(amount) as median_amount,
    sum(total_amount) over (partition by date_type order by date asc) as cum_amount
    from staking
    where action ilike '%withdraw%'
    group by 1,2
    order by 1)


    select date_type, avg(total_tx) as avg_tx, avg(total_address) as avg_user, avg(total_amount) as avg_amount
    from final
    group by 1

    Run a query to Download Data