JonasovePUFFER (4)
    Updated 2024-10-30
    with

    X as(
    select origin_from_address as user, from_address as contract, to_address as pool, amount as amount, contract_address, block_timestamp from ethereum.core.ez_token_transfers union all
    select origin_to_address as user, to_address as contract, from_address as pool, 0 - amount as amount, contract_address, block_timestamp from ethereum.core.ez_token_transfers ),

    A as(
    select user, contract_address, sum(amount) as amount, min(date(block_timestamp)) as time
    from X
    where contract_address = lower('0x4d1c297d39c5c1277964d0e3f8aa901493664530')
    and pool in ('0xa55ed5808aecdf23ae3782c1443185f5d2363ce7')
    group by 1,2),

    B as(
    select
    case
    when amount > 1e4*1 then 10000
    when amount > 1e3*5 then 5000
    when amount > 1e3*1 then 1000
    when amount > 1e2*5 then 500
    when amount > 1e2*1 then 100
    when amount > 1e1*7 then 70
    when amount > 1e1*5 then 50
    else 0
    end as tier,
    count(*) as user
    from A
    group by 1),

    C as(
    select tier, user, sum(user) over(order by tier desc) as user_top
    from B)

    select
    '🐡 PUFFER staked > ' || tier as tiers,
    '-' "➡️",
    QueryRunArchived: QueryRun has been archived