Time-weighted Average Price (TWAP) Oracle
1 min read
Pronunciation
[time-weyt-ed av-er-ij prahys awr-uh-kl]
Analogy
Think of a TWAP oracle like averaging every minute’s temperature over an hour to determine the true trend.
Definition
An oracle that provides an average asset price over a specified time window to smooth short-term volatility and resist manipulation.
Key Points Intro
TWAP oracles mitigate price manipulation by smoothing price data over time.
Key Points
Time window: defines start and end points for averaging
Cumulative data: uses cumulative price ticks or volumes
On-chain computation: contracts calculate averages from stored cumulatives
Manipulation resistance: short spikes have limited impact
Example
A lending protocol queries Uniswap V2’s TWAP every 30 minutes to determine collateral valuations, reducing susceptibility to flash loan attacks.
Technical Deep Dive
TWAP on Uniswap V2 uses `priceCumulativeLast` values: averagePrice = (priceCumul(t2) – priceCumul(t1)) / (t2 – t1). Contracts must call `sync` or `update` at regular intervals and store block timestamps to compute deltas accurately.
Security Warning
Infrequent updates or long windows can lag true market prices, while very short windows remain manipulable.
Caveat
Choosing the optimal window length balances responsiveness with manipulation resistance.
Time-weighted Average Price (TWAP) Oracle - Related Articles
No related articles for this term.