SocioAnalytica$VIBE Price
    Updated 2025-01-20
    -- forked from SocioCrypto / $VIBE Swaps @ https://flipsidecrypto.xyz/SocioCrypto/q/ZHA4Cn9LVybB/vibe-swaps

    SELECT -- Does not work, because the underlying table is empty when vibe is involved
    hour,
    max(open) as open,
    max(close) as close,
    min(price_usd) as low,
    max(price_usd) as high,
    sum(amount_usd) as volume,
    count(*) as num_txs
    FROM(
    SELECT
    hour, price_usd, amount_usd,
    FIRST_VALUE(price_usd) OVER (PARTITION BY hour ORDER BY block_timestamp ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as open,
    LAST_VALUE(price_usd) OVER (PARTITION BY hour ORDER BY block_timestamp ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as close
    FROM(
    SELECT
    block_timestamp,
    date_trunc('hour',block_timestamp) as hour,
    amount_in_usd, amount_in, amount_out_usd, amount_out,
    CASE WHEN token_out = '0xeedba439a4ab8987a995cf5cfefebd713000b3365718a29dfbc36bc214445fb8' THEN 'Vibe Out (Buy)'
    ELSE 'Vibe In (Sell)'
    END as action,
    CASE WHEN token_out = '0xeedba439a4ab8987a995cf5cfefebd713000b3365718a29dfbc36bc214445fb8' THEN amount_in_usd/(amount_out_unadj/pow(10,8))
    ELSE amount_out_usd/(amount_in_unadj/pow(10,8))
    END as price_usd,
    CASE WHEN token_out = '0xeedba439a4ab8987a995cf5cfefebd713000b3365718a29dfbc36bc214445fb8' THEN amount_in_usd
    ELSE amount_out_usd
    END as amount_usd
    FROM aptos.defi.ez_dex_swaps
    WHERE (token_out = '0xeedba439a4ab8987a995cf5cfefebd713000b3365718a29dfbc36bc214445fb8' or token_in = '0xeedba439a4ab8987a995cf5cfefebd713000b3365718a29dfbc36bc214445fb8')
    )
    )
    group by 1
    order by hour

    QueryRunArchived: QueryRun has been archived