What is TWAP?
TWAP (Time-Weighted Average Price) is a pricing method that calculates the average price of an asset over a specified time period, rather than using a single instantaneous price. TWAP is used both as a trading strategy (to minimize market impact) and as an oracle design (to resist price manipulation).
TWAP as a Trading Strategy
When executing a large order, buying everything at once causes significant price impact. TWAP splits the order into smaller pieces executed at regular intervals:
- Buy 100 ETH → split into 10 orders of 10 ETH, one per hour
- Each small order has minimal price impact
- The average execution price is smoother than a single large order
This strategy is widely used by whales and institutional traders to avoid moving the market.
TWAP as an Oracle Mechanism
Many DeFi protocols use TWAP oracles (popularized by Uniswap) to get price data:
- The oracle records the pool price at regular intervals
- The reported price is the average over the period (e.g., 30 minutes)
- To manipulate the TWAP, an attacker would need to sustain the manipulated price for the entire period
This makes TWAP oracles resistant to flash loan attacks — where an attacker manipulates the spot price for a single transaction. Because a flash loan must be repaid within one block, the attacker can’t sustain the manipulation long enough to affect a TWAP oracle.
TWAP vs. VWAP
| Feature | TWAP | VWAP |
|---|---|---|
| Weighting | Equal weight per time unit | Weighted by trading volume |
| Best for | Low-volume periods | High-volume periods |
| Complexity | Simple | More complex |
| Common in | DEX oracles, algorithmic trading | Traditional finance, institutional trading |
Limitations of TWAP Oracles
- Stale prices: A 30-minute TWAP reflects the average over the past 30 minutes, not the current price. During rapid market moves, TWAP lags.
- Manipulable with sustained capital: While resistant to flash loans, TWAPs can be manipulated by an attacker with enough capital to sustain price manipulation for the full period.
- Not suitable for all assets: Low-liquidity pools can have their TWAP manipulated more cheaply.
Frequently Asked Questions
Q: Can TWAP oracles be manipulated? A: Yes, but it’s much harder than manipulating a spot price. An attacker would need to sustain the manipulation for the entire TWAP window (e.g., 30 minutes), which requires significant capital and carries risk if the price reverts. This is why TWAP is considered safer than instantaneous price for oracle purposes.
Q: Should I use TWAP when selling a large token position? A: If you’re selling a significant portion of a token’s liquidity, yes. Splitting your sale into smaller pieces over time (TWAP strategy) reduces your price impact and gets you a better average price than dumping everything at once.
Q: What TWAP window do DeFi protocols typically use? A: Uniswap V2 uses a short TWAP (can be customized). Chainlink uses aggregated price feeds from multiple sources. Most lending protocols use 10-30 minute TWAP windows for collateral valuation.