mondov2023-06-05 05:07 PM
    Updated 2023-06-05
    WITH deposits AS (
    SELECT
    DATE_TRUNC('{{time_period}}', BLOCK_TIMESTAMP) AS deposit_date,
    COUNT(*) AS num_deposits,
    SUM(SUPPLIED_USD) AS total_deposit_usd
    FROM ethereum.aave.ez_deposits
    WHERE AAVE_MARKET = '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'
    AND DATE_TRUNC('{{time_period}}', BLOCK_TIMESTAMP) >= CURRENT_DATE - {{past_days}}
    GROUP BY deposit_date
    ),

    withdrawals AS (
    SELECT
    DATE_TRUNC('{{time_period}}', BLOCK_TIMESTAMP) AS withdrawal_date,
    COUNT(*) AS num_withdrawals,
    SUM(WITHDRAWN_USD) AS total_withdrawal_usd
    FROM ethereum.aave.ez_withdraws
    WHERE AAVE_MARKET = '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'
    AND DATE_TRUNC('{{time_period}}', BLOCK_TIMESTAMP) >= CURRENT_DATE - {{past_days}}
    GROUP BY withdrawal_date
    ),

    cumulative_deposits AS (
    SELECT
    deposit_date,
    SUM(total_deposit_usd) OVER (ORDER BY deposit_date) AS cumulative_deposit_usd
    FROM deposits
    ),

    cumulative_withdrawals AS (
    SELECT
    withdrawal_date,
    SUM(total_withdrawal_usd) OVER (ORDER BY withdrawal_date) AS cumulative_withdrawal_usd
    FROM withdrawals
    ),

    Run a query to Download Data