messaripolyhedra_staking_zkj
    Updated 3 days ago
    -- forked from Jonaso / STAKING ZKJ (1) @ https://flipsidecrypto.xyz/Jonaso/q/Ed_QRpius0ib/staking-zkj-1
    -- Chong Sun modified this query, pls slack before editing
    with

    -- Price
    PP as(
    select date(hour) as date, token_address, avg(price) as price
    from ethereum.price.ez_prices_hourly
    where token_address = '0xc71b5f631354be6853efe9c3ab6b9590f8302e81'
    group by 1,2 ),

    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 ),

    BB as(
    select date_trunc('day',block_timestamp) as time, sum(amount) as stake
    from AA
    where contract_address = '0xc71b5f631354be6853efe9c3ab6b9590f8302e81'
    and pool in ('0x76538f77ce2cc5e2408392e0c20d6ee991c8fa60')
    group by 1 ),

    CC as(
    select a.time, case when stake is null then 0 else stake end as stake
    from (select distinct time from BB) as a
    left join BB as b on a.time = b.time ),

    DD as(
    select time, stake as stake1, sum(stake) over(order by time) as stake2
    from CC )

    select
    time, 'Staking TVL' as pool, 'ZKJ' as token, price,
    stake2 as staked_native, stake2*price as staked_usd
    from DD as a
    left join PP as b on date(a.time) = b.date
    Last run: 3 days ago
    TIME
    POOL
    TOKEN
    PRICE
    STAKED_NATIVE
    STAKED_USD
    1
    2025-04-02 00:00:00.000Staking TVLZKJ2.259571742.5580000121536420.7555
    2
    2025-04-01 00:00:00.000Staking TVLZKJ2.2559568736.3680000121577500.50984
    3
    2025-03-31 00:00:00.000Staking TVLZKJ2.2366666679537960.4380000121333238.17966
    4
    2025-03-30 00:00:00.000Staking TVLZKJ2.256259495963.8400000121425268.414
    5
    2025-03-29 00:00:00.000Staking TVLZKJ2.2220833339451924.1400000121002963.099425
    6
    2025-03-28 00:00:00.000Staking TVLZKJ2.2308333339438315.1500000121055308.047125
    7
    2025-03-27 00:00:00.000Staking TVLZKJ2.259431534.6100000121220952.8725
    8
    2025-03-26 00:00:00.000Staking TVLZKJ2.219475659.5800000120941207.6718
    9
    2025-03-25 00:00:00.000Staking TVLZKJ2.1554166679464569.2100000120400090.2180542
    10
    2025-03-24 00:00:00.000Staking TVLZKJ2.1158333339463054.6100000120022246.3789917
    11
    2025-03-23 00:00:00.000Staking TVLZKJ2.0820833339459484.8200000119695435.6856417
    12
    2025-03-22 00:00:00.000Staking TVLZKJ2.0633333339454410.1400000119507599.5888667
    13
    2025-03-21 00:00:00.000Staking TVLZKJ2.0633333339448991.1800000119496418.4680667
    14
    2025-03-20 00:00:00.000Staking TVLZKJ2.0783333339342391.3400000119416603.3349667
    15
    2025-03-19 00:00:00.000Staking TVLZKJ2.0654166679424191.0100000119464881.1819042
    16
    2025-03-18 00:00:00.000Staking TVLZKJ2.0454166679425720.3400000119279525.478775
    17
    2025-03-17 00:00:00.000Staking TVLZKJ2.0366666679428176.8900000119202053.5993
    18
    2025-03-16 00:00:00.000Staking TVLZKJ2.0495833339428326.8700000119324141.6139709
    19
    2025-03-15 00:00:00.000Staking TVLZKJ2.043759427438.0800000119267326.576
    20
    2025-03-14 00:00:00.000Staking TVLZKJ2.0395833339424747.1400000119222557.187625
    ...
    260
    23KB
    13s