winnie-fsweekly_near_borrow_volume copy
    Updated 2024-09-06
    -- forked from charliemarketplace / weekly_near_borrow_volume @ https://flipsidecrypto.xyz/charliemarketplace/q/j2siBHLQZN2f/weekly_near_borrow_volume


    /*
    select
    date_trunc('week', block_timestamp) as week_,
    case when symbol IN ('DAI','USDt','FRAX','USDT.e','USDC','USDC.e') then 'stablecoin' else 'non-stable' end as token_category,
    sum(amount_usd) as borrow_usd_volume,
    count(distinct sender_id) as n_borrowers
    from near.defi.ez_lending
    where block_timestamp >= '2024-01-01'
    and actions = 'borrow'
    group by week_, token_category;

    select
    date_trunc('week', block_timestamp) as week_,
    sender_id as user_,
    case when symbol IN ('DAI','USDt','FRAX','USDT.e','USDC','USDC.e') then 'stablecoin' else 'non-stable' end as token_category,
    sum(amount_usd) as borrow_usd_volume
    from near.defi.ez_lending
    where block_timestamp >= '2024-01-01'
    and actions = 'borrow'
    and amount_usd is not null
    group by week_, token_category, sender_id
    having borrow_usd_volume > 1000000
    */

    select
    date_trunc('week', block_timestamp) as week_,
    case when symbol IN ('DAI','USDt','FRAX','USDT.e','USDC','USDC.e') then 'stablecoin' else 'non-stable' end as token_category,
    sum(amount_usd) as borrow_usd_volume,
    avg(amount_usd) as avg_borrow_usd_amount,
    count(distinct sender_id) as n_borrowers
    from near.defi.ez_lending
    where block_timestamp >= '2024-01-01'
    and actions = 'borrow'
    QueryRunArchived: QueryRun has been archived