YieldOracle

Git Source

Inherits: IYieldOracle, Ownable2Step

An on-chain oracle that provides the APY for each collateral type.

This contract stores a history of the exchange rates of each collateral for the past LOOK_BACK days. Every time that updateAll() is called, it will update the value at currentIndex in the historicalExchangeRates with the current exchange rate and it will also calculate the APY for each collateral type based on the data currently in the buffer. The APY is calculated by taking the difference between the new element being added and the element being replaced. This provides a growth amount of LOOK_BACK days. This value is then projected out to a year. Similar to the InterestRate module, as the amount of collaterals added to the market increases, storage reads during interest accrual can become prohibitively expensive. Therefore, this contract is heavily optimized at the unfortunate cost of code-complexity.

State Variables

apys

uint32[ILK_COUNT] public apys;

historicalExchangeRates

uint64[ILK_COUNT][LOOK_BACK] public historicalExchangeRates;

ADDRESS0

address public immutable ADDRESS0;

ADDRESS1

address public immutable ADDRESS1;

ADDRESS2

address public immutable ADDRESS2;

ionPool

currentIndex

lastUpdated

Functions

constructor

Creates a new YieldOracle instance.

Parameters

Name
Type
Description

_historicalExchangeRates

uint64[ILK_COUNT][LOOK_BACK]

An initial set of values for the historical exchange rates matrix.

_weEth

address

Address of the weETH contract.

_stader

address

Address of the Stader deposit contract.

_swell

address

Address of the Swell Eth contract.

owner

address

Admin address.

updateIonPool

Updates the IonPool reference.

Parameters

Name
Type
Description

_ionPool

IonPool

pool instance

updateAll

Every update should also accrue interest on IonPool. This is because an update to the apy changes interest rates which means the previous interest rate must be accrued, or else its effect will be lost. NOTE: This contract should continue to function as normal even if IonPool is paused.

_updateAll

Handles the logic for updating the APYs and the historical exchange rates matrix. If the last update was less than UPDATE_LOCK_LENGTH seconds ago, then this function will revert. If APY is ever negative, then it will simply be set to 0.

_getExchangeRate

Returns the exchange rate for a given collateral.

Parameters

Name
Type
Description

ilkIndex

uint256

The index of the collateral.

Returns

Name
Type
Description

exchangeRate

uint64

exchangeRate

Events

ApyUpdate

Errors

InvalidExchangeRate

InvalidIlkIndex

AlreadyUpdated