Working with Price Oracles

initialize_oracle<CURRENCY>(...), update_oracle(...), and get_twap(...) Purpose: Integrate a price oracle to record price samples and compute a time-weighted average price (TWAP). Process:

  1. Store historical prices during trades.

  2. Update price_cumulative and price_samples periodically.

  3. Compute TWAP for stable pricing signals and detect anomalies.

Use Cases:

  • Avoiding price manipulation by referencing TWAP rather than spot prices.

  • Informing traders and liquidity providers with more reliable pricing.

Best Practices:

  • Configure appropriate sample_period to reflect market conditions.

  • Use TWAP checks in large trades to prevent large deviations from fair value.

Last updated