vendettaAAVE supplied and withdrawn copy
    Updated 2024-09-29
    -- forked from omer93 / AAVE supplied and withdrawn @ https://flipsidecrypto.xyz/omer93/q/ubcbHmzyz5dq/aave-supplied-and-withdrawn

    with
    t1 as (
    select trunc(block_timestamp,'month') as date,
    sum (issued_tokens) as AAVE_tokens_supplied,
    sum (supplied_usd) as usd_volume_supplied,
    sum (AAVE_tokens_supplied) over (order by date) as cum_AAVE_tokens_supplied,
    sum (usd_volume_supplied) over (order by date) as cum_usd_volume_supplied
    from ethereum.aave.ez_deposits
    where symbol='AAVE'
    group by 1
    ),
    t2 as (
    select trunc(block_timestamp,'month') as date,
    sum (withdrawn_tokens) as AAVE_tokens_withdrawn,
    sum (withdrawn_usd) as usd_volume_withdrawn,
    sum (AAVE_tokens_withdrawn) over (order by date) as cum_AAVE_tokens_withdrawn,
    sum (usd_volume_withdrawn) over (order by date) as cum_usd_volume_withdrawn
    from ethereum.aave.ez_withdraws
    where symbol='AAVE'
    group by 1)
    select
    t1.date,
    AAVE_tokens_supplied,
    cum_AAVE_tokens_supplied,
    usd_volume_supplied,
    cum_usd_volume_supplied,
    AAVE_tokens_withdrawn*(-1),
    cum_AAVE_tokens_withdrawn*(-1),
    usd_volume_withdrawn*(-1),
    cum_usd_volume_withdrawn*(-1),
    cum_AAVE_tokens_supplied-cum_AAVE_tokens_withdrawn as net_AAVE_tokens_supplied,
    net_AAVE_tokens_supplied*101.14 as current_supplied_usd
    from t1,t2 where t1.date=t2.date
    order by 1 desc
    QueryRunArchived: QueryRun has been archived