TWAP Implementation
TWAP, or Time-Weighted Average Price, is a mechanism used to calculate the average price of an asset over a specified period of time. By averaging prices over a duration rather than using a single spot price, TWAP reduces the impact of short-term volatility and temporary price spikes on protocol operations.
This makes it a popular tool for mitigating the risk of oracle manipulation attacks, as an attacker would need to maintain an manipulated price for the entire duration of the window to successfully affect the protocol. However, a long TWAP window can lead to stale pricing, where the reported price lags significantly behind the actual market price during rapid shifts.
Implementing an effective TWAP requires balancing the need for manipulation resistance with the need for accurate, responsive pricing. It is a common strategy in decentralized trading venues.