winnie-fsweekly_near_borrow_volume copy
    Updated 2025-02-11
    -- 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') and amount_usd >= 100000 then 'stablecoin $100k+'
    when symbol IN ('DAI','USDt','FRAX','USDT.e','USDC','USDC.e') and amount_usd < 100000 then 'stablecoin $0-99k'
    when symbol NOT IN ('DAI','USDt','FRAX','USDT.e','USDC','USDC.e') and amount_usd >= 100000 then 'non-stable $100k+'
    when symbol NOT IN ('DAI','USDt','FRAX','USDT.e','USDC','USDC.e') and amount_usd < 100000 then 'non-stable $0-99k'
    else 'error' end as token_category,
    sum(amount_usd) as borrow_usd_volume,
    Last run: 3 months ago
    WEEK_
    TOKEN_CATEGORY
    BORROW_USD_VOLUME
    AVG_BORROW_USD_AMOUNT
    N_BORROWERS
    1
    2024-02-26 00:00:00.000non-stable $0-99k179094.9882633422888.62884295729
    2
    2024-12-09 00:00:00.000stablecoin $100k+586071.03790252293035.518951262
    3
    2024-05-06 00:00:00.000non-stable $0-99k635953.4572354976056.69959271936
    4
    2024-06-10 00:00:00.000stablecoin $100k+2199334.68042598274916.8350532474
    5
    2024-01-01 00:00:00.000non-stable $100k+637189.173540714212396.3911802382
    6
    2024-10-07 00:00:00.000non-stable $100k+468121.818425284234060.9092126422
    7
    2024-08-05 00:00:00.000stablecoin $0-99k5207570.27889003871.4140359592548
    8
    2024-07-01 00:00:00.000non-stable $100k+296424.448648276148212.2243241382
    9
    2024-07-22 00:00:00.000non-stable $100k+105783.533945402105783.5339454021
    10
    2024-05-13 00:00:00.000stablecoin $100k+2294985.64730218208635.0588456536
    11
    2024-12-23 00:00:00.000stablecoin $100k+2503720.04704281208643.3372535686
    12
    2024-05-27 00:00:00.000stablecoin $100k+960956.530306454192191.3060612913
    13
    2024-09-09 00:00:00.000non-stable $0-99k53061.8713222821128.9759855835
    14
    2024-06-03 00:00:00.000stablecoin $0-99k2319520.386367852565.841135363555
    15
    2024-02-05 00:00:00.000stablecoin $0-99k179027.0951896822081.71040918237
    16
    2024-06-17 00:00:00.000stablecoin $100k+2380743.96684109793581.3222803643
    17
    2024-12-16 00:00:00.000stablecoin $100k+710256.241327513142051.2482655032
    18
    2024-04-01 00:00:00.000non-stable $100k+131048.640247625131048.6402476251
    19
    2024-04-22 00:00:00.000non-stable $100k+1989459.31734079180859.9379400722
    20
    2024-08-05 00:00:00.000stablecoin $100k+40090270.81625531002256.7704063813
    ...
    195
    16KB
    4s