Abbas_ra21Daily 2
    Updated 2025-04-14
    -- forked from Daily 2 @ https://flipsidecrypto.xyz/edit/queries/ba26e0cb-af0e-4834-9976-d105f99c5d23

    with main AS (select
    date_trunc('Week',block_timestamp) AS Week,
    'Deposit' AS "Event Name",
    sum(case when Amount_USD is not null then Amount_USD else Amount*Price end) AS Volume
    from
    base.defi.ez_lending_deposits A
    inner join base.price.ez_prices_hourly B on B.TOKEN_ADDRESS=A.TOKEN_ADDRESS and HOUR=date_trunc('hour',BLOCK_TIMESTAMP)
    where
    PLATFORM = 'Moonwell'
    group by 1
    union ALL
    select
    date_trunc('Week',block_timestamp) AS Week,
    'Borrow' AS "Event Name",
    sum(case when Amount_USD is not null then Amount_USD else Amount*Price end) AS Volume
    from
    base.defi.ez_lending_borrows A
    inner join base.price.ez_prices_hourly B on B.TOKEN_ADDRESS=A.TOKEN_ADDRESS and HOUR=date_trunc('hour',BLOCK_TIMESTAMP)
    where
    PLATFORM = 'Moonwell'
    group by 1
    union ALL
    select
    date_trunc('Week',block_timestamp) AS Week,
    'Repayment' AS "Event Name",
    sum(case when Amount_USD is not null then Amount_USD else Amount*Price end) AS Volume
    from
    base.defi.ez_lending_repayments A
    inner join base.price.ez_prices_hourly B on B.TOKEN_ADDRESS=A.TOKEN_ADDRESS and HOUR=date_trunc('hour',BLOCK_TIMESTAMP)
    where
    PLATFORM = 'Moonwell'
    group by 1
    union ALL
    select
    QueryRunArchived: QueryRun has been archived