RAI uses several oracles to function, some are core to the system while others are not critical.
This post will describe each oracle used in the RAI protocol and the contracts that depend on them.
All oracles (for compatibility reasons) use the same interface, forked from DS-Value, but with easier to understand function names.
One of the two key oracle components in the system, the FSM (Feed Security Module) will take prices from the ETH oracle and force a 1 hour delay between consecutive updates.
The Oracle Relayer contract consumes the delayed price, divides it by the redemption price and then divides the result again by the Safe liquidation ratio before pushing the final output in the core system.
This is the second core oracle used in the system. It produces a RAI-USD time weighted average price and is consumed by the RAI controller, and therefore is key in periodically recalculating the redemption rate.
This is an auxiliary oracle, used only by periphery contracts. It is currently fixed at 300 USD (a value that can be changed by governance). It could be switched to a proper oracle once a reliable and easy to maintain feed is available.
Contracts that use it:
This is an auxiliary oracle, used only by periphery contracts. It is currently fixed at 150 gwei. Although Chainlink provides a gas price oracle, they do not offer a gas price TWAP. A TWAP would be needed to avoid attacks against the system (overpaying oracles with rewards set at gas price peaks).
Since the contracts using it are non critical, the gas oracle can use a fixed price.
These are implementations used for each of the oracles:
- DSValue: stores a fixed price that can be changed by an authed address (governance).
- ChainlinkRelayer: relays a Chainlink aggregator’s result to another contract.
- ChainlinkTWAP: creates and returns a TWAP formed from several Chainlink feed updates.
- ChainlinkPriceFeedMedianizer: reads, stores and returns the price feed fetched from a Chainlink aggregator.
- GovernanceLedPriceFeedMedianizer: median price feed formed from aggregating multiple price feeds submitted by whitelisted providers.
- UniswapConsecutiveSlotsPriceFeedMedianizer: forms and exposes a TWAP from a Uniswap v2 pair.
- UniswapConverterBasicAveragePriceFeedMedianizer: forms and exposes a TWAP from a Uniswap v2 pair.
- UniswapV3Medianizer: forms and exposes a TWAP from a Uniswap v3 pair.