Updated 2024-07-06
    with final as (
    select
    date_trunc('{{Time_Interval}}', BLOCK_TIMESTAMP)::date as date,
    'Borrow' as type,
    count(DISTINCT(tx_hash)) as total_tx,
    count(DISTINCT(BORROWER)) as total_user,
    sum(LOAN_AMOUNT_USD) as total_volume,
    avg(LOAN_AMOUNT_USD) as avg_volume,
    sum(total_tx) over (partition by type order by date) as cum_tx,
    sum(total_volume) over (partition by type order by date) as cum_volume,
    avg(total_volume) over (partition by type order by date asc rows between 6 preceding and current row ) as avg_7_days_moving
    from ethereum.compound.ez_borrows
    where block_timestamp::date >= CURRENT_DATE - INTERVAL '{{Past_Weeks}} WEEK'
    group by 1,2
    UNION
    select
    date_trunc('{{Time_Interval}}', BLOCK_TIMESTAMP)::date as date,
    'Deposit' as type,
    count(DISTINCT(tx_hash)) as total_tx,
    count(DISTINCT(SUPPLIER)) as total_user,
    sum(SUPPLIED_BASE_ASSET_USD) as total_volume,
    avg(SUPPLIED_BASE_ASSET_USD) as avg_volume,
    sum(total_tx) over (partition by type order by date) as cum_tx,
    sum(total_volume) over (partition by type order by date) as cum_volume,
    avg(total_volume) over (partition by type order by date asc rows between 6 preceding and current row ) as avg_7_days_moving
    from ethereum.compound.ez_deposits
    where block_timestamp::date >= CURRENT_DATE - INTERVAL '{{Past_Weeks}} WEEK'
    group by 1,2
    UNION
    select
    date_trunc('{{Time_Interval}}', BLOCK_TIMESTAMP)::date as date,
    'Repayment' as type,
    QueryRunArchived: QueryRun has been archived