Skip to content

Design a time-weighted average price (TWAP) oracle aggregator for stable fractional asset pricing #481

Description

@Damola-Sodiq

Description

Build an on-chain oracle module that maintains a rolling window of historical asset prices, returning a Time-Weighted Average Price (TWAP) to mitigate flash loan manipulation.

Architecture & Context

Relying on instantaneous spot prices for fractional token swaps exposes the protocol to devastating flash loan attacks. A TWAP oracle records cumulative prices across multiple ledgers, smoothing out extreme volatility and ensuring true market pricing.

Technical Requirements

  • Store cumulative price ticks inside Soroban instance storage using efficient ring buffers.
  • Calculate the TWAP accurately by dividing the difference in cumulative ticks by the time delta.
  • Implement a circuit breaker that halts pricing if updates become excessively stale.

Acceptance Criteria

  • The TWAP value correctly resists single-block price manipulation.
  • The ring buffer prevents infinite storage growth over time.
  • The contract gracefully halts execution if oracle data is manipulated or missing.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions