messariSTAKING ZKJ (0) copy
    Updated 2024-09-18
    -- forked from Jonaso / STAKING ZKJ (0) @ https://flipsidecrypto.xyz/Jonaso/q/f9G_zgBlmV9D/staking-zkj-0

    with

    PP as(
    select hour, price
    from ethereum.price.ez_prices_hourly
    where token_address = '0xc71b5f631354be6853efe9c3ab6b9590f8302e81'
    order by 1 desc limit 1),

    AA as(
    select 'ethereum' as chain, 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 'ethereum' as chain, 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
    )

    select '2024-01-01' as date, count(distinct user) as user, sum(amount) as stake, sum(amount*price) as stake_usd, max(price) as price
    from AA, PP
    where contract_address = '0xc71b5f631354be6853efe9c3ab6b9590f8302e81'
    and pool in ('0x76538f77ce2cc5e2408392e0c20d6ee991c8fa60')
    and block_timestamp <= date
    group by 1


    QueryRunArchived: QueryRun has been archived