Time-Weighted Average Price, TWAP, is the average price of an asset over a window, weighted by how long the price stayed at each level, not by volume. A brief spike barely moves TWAP because it lasts a short share of the window. To move TWAP a lot, an attacker would need to hold the fake price for hours or days, which is expensive.
Uniswap v2 and v3 implement TWAP oracles by accumulating price times time so you can query averages over past windows. Those on-chain feeds resist spot manipulation without an external oracle, which matters for liquidations and collateral checks. TWAP is also an execution style.
Large orders split across time, filled in small slices, aim to land near the period's TWAP and cut impact versus one dump. Traditional desks and some DEX UIs offer this. The tradeoff is speed. You give up immediacy for a better average.
This makes TWAP resistant to spot price manipulation: an attacker who briefly pushes the price to an extreme level has minimal impact on TWAP because the manipulation duration is short relative to the averaging window. Uniswap v2 and v3 implement TWAP oracles by accumulating price*time products that can be queried to compute average prices over arbitrary historical windows.
These on-chain TWAP oracles provide manipulation-resistant price feeds without external dependencies, making them valuable for DeFi protocols needing reliable price data for liquidations, collateral valuation, or other critical operations. Uniswap v2/v3 oracles accumulate price over time so a one-block spike is a bad input. Attackers still try to move TWAPs. Read the window.
Time-Weighted Average Price (TWAP)
TWAP calculates average price over time, making it resistant to brief manipulations. Adjust parameters and watch how manipulation affects spot price vs TWAP.
Controls
Price Chart (Time: 0)
Notice how TWAP remains stable during price manipulation attacks. The longer the TWAP window, the more resistant it becomes to short-term manipulation, but the slower it adapts to real price changes.