PierandreaDeposits of CRV on AAVE
    Updated 2023-08-30
    WITH DEPOSITS AS (
    SELECT
    SYMBOL,
    SUM(ISSUED_TOKENS) AS DEPOSITED_TOKENS,
    SUM(SUPPLIED_USD) AS DEPOSITED_USD
    FROM ethereum.aave.ez_deposits
    WHERE DEPOSITOR_ADDRESS = LOWER('0x7a16ff8270133f063aab6c9977183d9e72835428')
    GROUP BY 1
    ),

    WITHDRAWALS AS (
    SELECT
    SYMBOL,
    SUM(WITHDRAWN_TOKENS) AS WITHDRAWN_TOKENS,
    SUM(WITHDRAWN_USD) AS WITHDRAWN_USD
    FROM ethereum.aave.ez_withdraws
    WHERE DEPOSITOR_ADDRESS = LOWER('0x7a16ff8270133f063aab6c9977183d9e72835428')
    GROUP BY 1
    ),

    X AS (SELECT D.SYMBOL AS TOKEN,
    D.DEPOSITED_TOKENS,
    W.WITHDRAWN_TOKENS,
    (D.DEPOSITED_TOKENS-W.WITHDRAWN_TOKENS) as BALANCE_CRV,
    D.DEPOSITED_USD,
    W.WITHDRAWN_USD,
    (D.DEPOSITED_USD-W.WITHDRAWN_USD) as BALANCE_USD
    FROM DEPOSITS D
    INNER JOIN WITHDRAWALS W ON D.SYMBOL = W.SYMBOL),

    p as (select price
    from ethereum.core.fact_hourly_token_prices
    where SYMBOL = 'CRV'
    order by HOUR DESC
    LIMIT 1),

    Run a query to Download Data