CartanGroupPYUSD Liquidity (Test) copy
    Updated 2024-07-24
    -- forked from mattkstew / PYUSD Liquidity (Test) @ https://flipsidecrypto.xyz/mattkstew/q/XsEr58_SBsJF/pyusd-liquidity-test

    with tab1 as (
    select
    date_trunc('hour', block_timestamp) as Date,
    tx_from as User,
    sum(-1*amount) as Total_PYUSD

    from solana.core.fact_transfers
    where tx_from in ('9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B', '39GrsozbzM9Sg1U7EDnEtQ69fsVF3pmVtmV2DGDAQQJ5')
    and mint like '2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo'
    group by 1,2

    UNION ALL

    select
    date_trunc('hour', block_timestamp) as Date,
    tx_to as User,
    sum(amount) as Total_PYUSD
    from solana.core.fact_transfers
    where tx_to in ('9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B', '39GrsozbzM9Sg1U7EDnEtQ69fsVF3pmVtmV2DGDAQQJ5')
    and mint like '2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo'
    group by 1,2
    )

    select
    Date,
    case when user like '9tXiuRRw7kbejLhZXtxDxYs2REe43uH2e7k1kocgdM9B' then 'ORCA: USDC/PYUSD'
    else 'ORCA: USDT/PYUSD' end as Pool,
    sum(Total_PYUSD) as Balance_PYUSD,
    SUM(sum(Total_PYUSD)) OVER (PARTITION BY Pool ORDER BY Date) AS Cumulative_Balance_PYUSD
    from tab1
    group by 1,2
    order by 1 desc

    QueryRunArchived: QueryRun has been archived