SocioAnalyticaaave (avax) copy
    Updated 2024-04-30
    -- forked from avve (eth) @ https://flipsidecrypto.xyz/edit/queries/cfc6d548-120e-4bc6-bb0e-0f0eafb1de18

    with supply as (
    select
    token_address,
    sum(amount) as supply_amount
    from (
    select token_address, amount
    from avalanche.defi.ez_lending_deposits
    where platform ilike '%Aave%'
    qualify row_number() over (partition by tx_hash order by event_index desc) = 1
    )
    group by 1
    )
    ,
    withdraw as (
    select
    token_address,
    sum(amount) as withdraw_amount
    from (
    select token_address, amount

    from avalanche.defi.ez_lending_withdraws
    where platform ilike '%Aave%'
    qualify row_number() over (partition by tx_hash order by event_index desc) = 1
    )
    group by 1
    )
    ,
    borrow as (
    select
    token_address,
    sum(amount) as borrow_amount
    from (
    select token_address, amount
    from avalanche.defi.ez_lending_borrows
    QueryRunArchived: QueryRun has been archived