What Is a Time-Weighted Average Price (TWAP) and Why Is It Safer than a Spot Price?
A TWAP is a price calculated by taking the average of an asset's price over a specified time interval, weighted by the time each price was valid. It is safer than a spot price because a flash loan manipulation only lasts for a single block or transaction.
The short-lived price spike is diluted when averaged over a longer period, making the resulting TWAP a much more stable and attack-resistant metric for protocols.