h4wkray stake
    Updated 2024-12-12

    -- forked from base_tvl @ https://flipsidecrypto.xyz/edit/queries/cedc517e-0cae-4f1f-ad37-64b7ce10168c
    -- forked from base_tvl_tokens @ https://flipsidecrypto.xyz/edit/queries/4451d5c7-b0c2-456b-ba77-0316a3037d60

    with base as (
    SELECT
    -- PARSE_JSON(defillama.get('/protocol/raydium', {})) as data
    PARSE_JSON(livequery.live.udf_api('https://drive.google.com/uc?export=download&id=1PUS-GnwF3meRzyKUUy3Yqx7NxeNNQ-UX')) as data
    )
    , base2 as (
    select tvl.value:date as raw_date, tvl.value:tokens:RAY as ray_staked_usd
    from base
    join lateral flatten (input => data:data:chainTvls:staking:tokensInUsd) tvl
    )
    , base3 as (
    select to_date(raw_date::string) as date,
    case
    when date BETWEEN '2023-01-01' and '2023-03-31' then '2023_Q1'
    when date BETWEEN '2023-04-01' and '2023-06-30' then '2023_Q2'
    when date BETWEEN '2023-07-01' and '2023-09-30' then '2023_Q3'
    when date BETWEEN '2023-10-01' and '2023-12-31' then '2023_Q4'
    end as date_type,
    ray_staked_usd
    from base2
    where date >= '2023-01-01' and date < CURRENT_DATE
    )

    select * from base3
    order by date desc
    -- , base_avg as(
    -- select date_type,
    -- avg(tvl) as "AVG TVL by Period"
    -- from base3
    -- group by 1
    -- )

    Auto-refreshes every 24 hours
    QueryRunArchived: QueryRun has been archived