Skip to main content

Time-Weighted Average Price (TWAP)

A Time-Weighted Average Price (TWAP) is an AMM oracle mechanism that records the cumulative price over time, making the price feed resistant to short-term manipulation by flash loans or large trades executing within a single block. The TWAP is the geometric mean of prices observed at each second (or block) over the measurement window, weighted by the duration each price was active. Longer TWAP windows (e.g., 30 minutes) are more manipulation-resistant but lag the true market price, while shorter windows track more closely but are more vulnerable. Uniswap V2 introduced TWAP oracles that are widely used by lending protocols and stablecoins as price feeds. TWAP limitations include: it does not capture the current (spot) price, it can be manipulated if the attacker is willing to pay the cost across multiple blocks, and it requires regular keeper transactions to checkpoint the accumulator values. Chainlink-style oracle networks and Uniswap V3's more granular observations address some of these limitations.