CryptoIcicleFLASH BOUNTY- TWAP LUNA
    Updated 2021-12-08
    -- Like the man in the red suit himself, I'm back to dispense goodies: in this case, 5 LUNA grand prize and 1.5 LUNA minimum for the first five participants who reply with a complete solution and the #MerryChristmas hashtag. I'll throw 15 UST atop that for anyone who tweets out their solution with a brief explainer.
    -- DAMMIT KIDA
    -- The client is the general manager at Anchor Protocol, who reached out and wanted someone to calculate a rolling 30-day time-weighted average price (TWAP) for LUNA. He'd like to see what TWAP has done, beginning from 11/15 until now.
    -- No bells and whistles here - just the calculation over that time period, a simple, clean visualization, and maybe a brief explanation.
    with avg_daily_luna_price as (
    select
    date_trunc('day', block_timestamp) as date,
    avg(price_usd) as luna_price
    from
    terra.oracle_prices
    where
    symbol = 'LUNA'
    and block_timestamp >= '2020-11-15'
    group by
    date
    )
    select
    date,
    luna_price,
    avg(luna_price) over (
    ORDER BY
    date ROWS BETWEEN 29 PRECEDING
    AND CURRENT ROW
    ) as luna_30_day_moving_average
    from
    avg_daily_luna_price
    Run a query to Download Data