Afonso_Diazaave-borrow-uni-1
    Updated 2023-03-10
    with t as (
    select
    count(distinct tx_hash) as transactions,
    count(distinct borrower_address) as total_borrowers,
    sum(borrowed_usd) as volume_usd,
    avg(borrowed_usd) as average_volume_usd,
    sum(tx_fee) as fee_eth,
    avg(tx_fee) as average_fee_eth
    from ethereum.aave.ez_borrows a
    join ethereum.core.fact_transactions b
    using(tx_hash)
    where aave_version = 'Aave V2'
    and symbol in ('UNI')
    ),

    t3 as (
    select
    borrower_address as user,
    min(block_timestamp::date) as min_date
    from ethereum.aave.ez_borrows
    where aave_version = 'Aave V2'
    and symbol in ('UNI')
    group by 1
    ),

    t4 as (
    select avg(new_borrowers) as average_new_borrowers
    from (
    select
    min_date as day,
    count(distinct user) as new_borrowers
    from t3
    group by 1
    )
    ),

    Run a query to Download Data