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

IonPool public ionPool;

currentIndex

uint32 public currentIndex;

lastUpdated

uint48 public lastUpdated;

Functions

constructor

Creates a new YieldOracle instance.

constructor(
    uint64[ILK_COUNT][LOOK_BACK] memory _historicalExchangeRates,
    address _weEth,
    address _stader,
    address _swell,
    address owner
)
    Ownable(owner);

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.

function updateIonPool(IonPool _ionPool) external onlyOwner;

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.

function updateAll() external;

_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.

function _updateAll() internal;

_getExchangeRate

Returns the exchange rate for a given collateral.

function _getExchangeRate(uint256 ilkIndex) internal view returns (uint64 exchangeRate);

Parameters

Name
Type
Description

ilkIndex

uint256

The index of the collateral.

Returns

Name
Type
Description

exchangeRate

uint64

exchangeRate

Events

ApyUpdate

event ApyUpdate(uint256 indexed ilkIndex, uint256 newApy);

Errors

InvalidExchangeRate

error InvalidExchangeRate(uint256 ilkIndex);

InvalidIlkIndex

error InvalidIlkIndex(uint256 ilkIndex);

AlreadyUpdated

error AlreadyUpdated();