Sbhn_NPwhole-lime
    Updated 2025-02-09
    with price as (
    select hour::date as datee,
    token_address ,
    avg(price) as usdprice
    from aptos.price.ez_prices_hourly
    group by 1,2
    )

    select
    date_trunc('day',block_timestamp) as date,
    symbol,
    count(DISTINCT ACCOUNT_ADDRESS) as users,
    sum(amount/pow(10,decimals)*usdprice) as borrowed
    from aptos.core.fact_transfers a
    join aptos.core.fact_transactions using(tx_hash)
    join price p on block_timestamp::date=datee and a.token_address=p.token_address
    left join aptos.core.dim_tokens t on a.token_address=t.token_address
    where payload:function = '0xeab7ea4d635b6b6add79d5045c4a45d8148d88287b1cfa1c3b6a4b56f46839ed::router::borrow_simple'
    and transfer_event = 'DepositEvent'
    and date >= '2024-10-10'
    group by 1,2
    QueryRunArchived: QueryRun has been archived