hessGrail Daily Price
    Updated 2024-11-18
    with prices as (
    select date(block_timestamp) as date,
    TOKEN_IN_CONTRACT,
    (sum(AMOUNT_OUT)/sum(AMOUNT_IN)) as price
    from near.defi.ez_dex_swaps
    where SYMBOL_OUT in ('wNEAR')
    and date(block_timestamp) >= '2023-12-10'
    and AMOUNT_OUT > 0
    and AMOUNT_IN > 0
    and TOKEN_IN_CONTRACT = 'gear.enleap.near'
    group by 1, 2
    ),
    near_price as (
    select hour::date as date,
    'Near' as symbol,
    min(price) as near_price
    from near.price.ez_prices_hourly
    where symbol = 'NEAR'
    and hour::date >= '2023-12-10'
    group by 1, 2
    ),
    gear_price as (
    select a.date,
    price * near_price as gear_price
    from prices a
    join near_price b on a.date = b.date
    ),
    final_gear as (select a.date,
    b.gear_price,
    a.near_price
    from near_price a
    left join gear_price b on a.date = b.date
    order by a.date)
    ,
    price as ( select date,
    gear_price as price,
    QueryRunArchived: QueryRun has been archived