ReserveOracle
Reserve oracles are used to determine the LST provider exchange rate and is utilizated by Ion's liquidation module. Liquidations will only be triggered against this exchange rate and will be completely market-price agnostic. Importantly, this means that liquidations will only be triggered through lack of debt repayment or slashing events.
In order to protect against potential provider bugs or incorrect one-off values (malicious or accidental), the reserve oracle does not use live data. Instead it will query the exchange every intermittent period and persist the value and this value can only move up or down by a maximum percentage per query. If additional data sources are available, they can be involved as FEED
s. If other FEED
s are provided to the reserve oracle, a mean of all the FEED
s is compared to the protocol exchange rate and the minimum of the two is used as the new exchange rate. This final value is subject to the bounding rules.
State Variables
ILK_INDEX
uint8 public immutable ILK_INDEX;
QUORUM
uint8 public immutable QUORUM;
MAX_CHANGE
uint256 public immutable MAX_CHANGE;
FEED0
IReserveFeed public immutable FEED0;
FEED1
IReserveFeed public immutable FEED1;
FEED2
IReserveFeed public immutable FEED2;
currentExchangeRate
uint256 public currentExchangeRate;
lastUpdated
uint256 public lastUpdated;
Functions
constructor
Creates a new ReserveOracle
instance.
constructor(uint8 _ilkIndex, address[] memory _feeds, uint8 _quorum, uint256 _maxChange);
Parameters
_ilkIndex
uint8
of the associated collateral.
_feeds
address[]
Alternative data sources to be used for the reserve oracle.
_quorum
uint8
The number of feeds to aggregate.
_maxChange
uint256
Maximum percent change between exchange rate updates. [RAY]
_getProtocolExchangeRate
Returns the protocol exchange rate.
Must be implemented in the child contract with LST-specific logic.
function _getProtocolExchangeRate() internal view virtual returns (uint256);
Returns
<none>
uint256
The protocol exchange rate.
getProtocolExchangeRate
Returns the protocol exchange rate.
function getProtocolExchangeRate() external view returns (uint256);
Returns
<none>
uint256
The protocol exchange rate.
_aggregate
Queries values from whitelisted data feeds and calculates the mean. This does not include the protocol exchange rate.
function _aggregate(uint8 _ILK_INDEX) internal view returns (uint256 val);
Parameters
_ILK_INDEX
uint8
of the associated collateral.
_bound
Bounds the value between the min and the max.
function _bound(uint256 value, uint256 min, uint256 max) internal pure returns (uint256);
Parameters
value
uint256
The value to be bounded.
min
uint256
The minimum bound.
max
uint256
The maximum bound.
_initializeExchangeRate
Initializes the currentExchangeRate
state variable.
Called once during construction.
function _initializeExchangeRate() internal;
updateExchangeRate
Updates the currentExchangeRate
state variable.
Takes the minimum between the aggregated values and the protocol exchange rate, then bounds it up to the maximum change and writes the bounded value to the state. NOTE: keepers should call this update to reflect recent values
function updateExchangeRate() external;
Events
UpdateExchangeRate
event UpdateExchangeRate(uint256 exchangeRate);
Errors
InvalidQuorum
error InvalidQuorum(uint8 invalidQuorum);
InvalidFeedLength
error InvalidFeedLength(uint256 invalidLength);
InvalidMaxChange
error InvalidMaxChange(uint256 invalidMaxChange);
InvalidMinMax
error InvalidMinMax(uint256 invalidMin, uint256 invalidMax);
InvalidInitialization
error InvalidInitialization(uint256 invalidExchangeRate);
UpdateCooldown
error UpdateCooldown(uint256 lastUpdated);