Skip to free scan

DeFi Concepts

TWAP (Time-Weighted Average Price)

A Time-Weighted Average Price (TWAP) is an asset's price averaged over a defined time window rather than read at a single instant. In DeFi, TWAPs are used as manipulation-resistant price oracles: because the value is averaged over time, a momentary spike — such as one caused by a flash loan — has little effect on the reported price.

Why It Resists Manipulation

To move a TWAP meaningfully, an attacker must sustain a manipulated price across the whole averaging window, which is far more expensive and risky than a single-block spike. This is why using a raw spot price from a DEX is dangerous, while a Uniswap V3 TWAP is a common safer alternative — directly addressing oracle manipulation.

Trade-offs

A longer window is more manipulation-resistant but slower to reflect real price changes; a shorter window is more responsive but easier to skew. Many protocols combine a TWAP with an independent feed like Chainlink.

Frequently Asked Questions

Q: Why is a TWAP safer than a spot price?

A: A spot price can be moved within a single block (e.g. by a flash loan). A TWAP averages over time, so a brief spike barely changes it, making manipulation far more expensive.


Q: What window length should a TWAP use?

A: It depends on the protocol's tolerance for staleness versus manipulation. Longer windows resist manipulation but lag real prices; many designs pair a TWAP with a second oracle.

Firepan

Scan Your Contracts

Run a free surface scan — results in minutes, no credit card required.

Run Free Scan →