TWAP oracle
Uniswap TWAP is calculated using the time-weighted mean price of an asset over some interval of time. TWAP, like any average, is both a smoothed and lagging indicator of the trade price: a TWAP over a shorter time interval is a less smooth, more up-to-date function, while a TWAP over a longer time interval is a smoother function and less up-to-date.
TWAP perfectly fits Marginly protocol for several reasons. First, TWAP is resistant to price manipulation attacks. It cannot be manipulated within a transaction or block (for example, with flash loans or flash bots). It is also expensive to manipulate using large market orders because the manipulated price must be maintained for some period of time relative to the TWAP time interval. During this time, other market participants can take advantage of the manipulated price with arbitrage, which will cause it to revert back to the broader market price.
Second, the smooth nature of TWAP helps to remove the impact of price shocks on borrowers. In the event of a large trade, the current price on Uniswap can be moved significantly. Usually, arbitrageurs will quickly converge this to the fair market value, so the magnitude of the TWAP change will only be a fraction of the temporary price movement. This smoothed behaviour prevents some unnecessary liquidations and positions that may quickly become insolvent.
Last updated