DEV Community

Cover image for Ethereum-Solidity Quiz Q11: What is TWAP?
MihaiHng
MihaiHng

Posted on

Ethereum-Solidity Quiz Q11: What is TWAP?

TWAP = Time Weighted Average Price. It's a method of calculating the average price of an asset over a specific time period, weighted by the amount of time the price spent at each level.

TWAP takes into account prices that persist longer. For an asset trades at $100 for 10 minutes and then $110 for 50 minutes, the TWAP will incline the price toward $110 because it was the dominant price for most of the period.

Formula:

TWAP = (Price1 × Time1 + Price2 × Time2 + ... + PriceN × TimeN) / Total Time

Advantages over spot price:

  • Harder to manipulate — needs sustained price pressure over time
  • Smoother — lowers impact of temporary price spikes
  • Fair pricing — reflects actual market price

Limitations:

  • Delayed — TWAP lags behind current market price (by design)
  • Historical data needed — needs tracking prices over time
  • Still vulnerable — with enough capital and time, TWAP can still be manipulated

Example use case:

When a lending protocol like Aave liquidates a position when collateral value drops below a threshold, using TWAP instead of spot price prevents liquidations triggered by temporary price flash crashes or manipulations.

Top comments (0)