Time-Weighted Average Price (TWAP)

A TWAP oracle computes the average price of an asset over a defined time window, smoothing out short-term volatility and resisting single-block price manipulation.

In Depth

Time-weighted average price oracles track cumulative price data over time and compute an average, making them resistant to instantaneous manipulation. Uniswap V3 introduced a highly efficient TWAP mechanism using stored price observations that protocols can query for any historical window. The choice of TWAP window length involves a trade-off: longer windows provide stronger manipulation resistance but slower response to legitimate price changes, while shorter windows are more responsive but easier to manipulate through sustained trading. TWAPs are not immune to all attacks — a well-funded attacker can manipulate prices over multiple blocks — so they are often combined with other oracle solutions and sanity checks for defense in depth.

Frequently Asked Questions

What is a TWAP oracle?

A TWAP (Time-Weighted Average Price) oracle computes the average price of an asset over a time window rather than using the instantaneous spot price. This smoothing effect makes it much harder for an attacker to manipulate the reported price with a single large trade or flash loan.

How does the TWAP window length affect security?

Longer TWAP windows (e.g., 30 minutes) provide stronger manipulation resistance because an attacker would need to sustain distorted prices for the entire window. However, longer windows also mean the oracle is slower to reflect legitimate price changes, which can be dangerous during volatile markets.

Are TWAP oracles fully manipulation-resistant?

No. While TWAPs resist single-block manipulation, a well-capitalized attacker can distort prices over multiple consecutive blocks, especially in low-liquidity pools. Protocols should combine TWAPs with additional safeguards like deviation checks, circuit breakers, and decentralized oracle networks.

Related Terms

Need expert help with time-weighted average price (twap)?