Impermax Docs
Search…
Price Oracle
Impermax uses a highly automated smart contract price oracle to monitor prices on Uniswap to calculate collateral valuation.
The Price Oracle is a smart contract based on Uniswap’s TWAP (Time Weighted Average Price). It has been designed with attention to simplicity and gas costs. While numerous alternative price oracle solutions are available, this TWAP solution allows the platform to remain highly automated and permissionless.
Anyone can create a new Lending Pool containing an arbitrary combination of assets, so traditional oracles that require manual set-up of new pairs won't work. The best way to guarantee support for all pairs on Uniswap and similar AMMs is to draw the prices from Uniswap itself.
For each LP token pair, Uniswap V2 stores the cumulative price that is the sum of the spot price at each second in the history of the contract. By sampling the cumulative price at two points in time it is possible to calculate the TWAP between those two points by dividing the difference of the accumulators by the time elapsed.
The Price Oracle uses a minimum period of 30 minutes to calculate the TWAP. This prevents accidental liquidation due to high market volatility or attempts of market manipulation through flash loans. The TWAP protects borrowers. Their position won't be liquidated unless the price exits the liquidation boundaries for at least 30 minutes.
Copy link