OracleRelayer

Git Source

Inherits: Authorizable, Modifiable, Disableable, IOracleRelayer

Handles the collateral prices inside the system (SAFEEngine) and calculates the redemption price using the rate

State Variables

safeEngine

The SAFEEngine is called to update the price of the collateral in the system

ISAFEEngine public safeEngine;

systemCoinOracle

The oracle used to fetch the system coin market price

IBaseOracle public systemCoinOracle;

_params

Getter for the unpacked contract parameters struct

OracleRelayerParams public _params;

_cParams

Getter for the unpacked collateral parameters struct

mapping(bytes32 _cType => OracleRelayerCollateralParams) public _cParams;

_collateralList

EnumerableSet.Bytes32Set internal _collateralList;

_redemptionPrice

Virtual redemption price (not the most updated value) [ray]

uint256 internal _redemptionPrice;

redemptionRate

The redemption rate is the rate at which the redemption price changes over time

By changing the redemption rate, it changes the incentives of the system users

uint256 public redemptionRate;

redemptionPriceUpdateTime

Last time when the redemption price was changed

Used to calculate the current redemption price

uint256 public redemptionPriceUpdateTime;

Functions

params

Getter for the contract parameters struct

Returns a OracleRelayerParams struct

function params() external view override returns (OracleRelayerParams memory _oracleRelayerParams);

cParams

Getter for the collateral parameters struct

Returns a OracleRelayerCollateralParams struct

function cParams(bytes32 _cType) external view returns (OracleRelayerCollateralParams memory _oracleRelayerCParams);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type

constructor

constructor(
  address _safeEngine,
  IBaseOracle _systemCoinOracle,
  OracleRelayerParams memory _oracleRelayerParams
) Authorizable(msg.sender) validParams;

Parameters

NameTypeDescription
_safeEngineaddressAddress of the SAFEEngine
_systemCoinOracleIBaseOracleAddress of the system coin oracle
_oracleRelayerParamsOracleRelayerParamsInitial OracleRelayer valid parameters struct

marketPrice

The current system coin market price

function marketPrice() external view returns (uint256 _marketPrice);

Returns

NameTypeDescription
_marketPriceuint256The current system coin market price [ray]

calcRedemptionPrice

View method to fetch the current redemption price

To be used within view functions, not to be used in transactions, use redemptionPrice instead

function calcRedemptionPrice() external view returns (uint256 _virtualRedemptionPrice);

Returns

NameTypeDescription
_virtualRedemptionPriceuint256_redemptionPrice The current calculated redemption price [ray]

_updateRedemptionPrice

Calculates and updates the redemption price using the current redemption rate

function _updateRedemptionPrice() internal virtual returns (uint256 _updatedPrice);

redemptionPrice

Fetch the latest redemption price by first updating it

function redemptionPrice() external returns (uint256 _updatedPrice);

Returns

NameTypeDescription
_updatedPriceuint256The newly updated redemption price [ray]

_getRedemptionPrice

Avoids reupdating the redemptionPrice if no seconds have passed since last update

function _getRedemptionPrice() internal virtual returns (uint256 _updatedPrice);

updateCollateralPrice

Update the collateral price inside the system (inside SAFEEngine)

Usually called by a keeper, incentivized by the system to keep the prices up to date

function updateCollateralPrice(bytes32 _cType) external whenEnabled;

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type

updateRedemptionRate

Update the system redemption rate, the rate at which the redemption price changes over time

Usually called by the PIDRateSetter

function updateRedemptionRate(uint256 _redemptionRate) external isAuthorized whenEnabled;

Parameters

NameTypeDescription
_redemptionRateuint256The newly calculated redemption rate [ray]

initializeCollateralType

Register a new collateral type in the OracleRelayer

function initializeCollateralType(
  bytes32 _cType,
  OracleRelayerCollateralParams memory _oracleRelayerCParams
) external isAuthorized validCParams(_cType);

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type
_oracleRelayerCParamsOracleRelayerCollateralParams

_onContractDisable

Internal virtual method to be called when the contract is disabled

Sets the redemption rate to 1 (no change in the redemption price)

function _onContractDisable() internal override;

collateralList

List of all the collateral types registered in the OracleRelayer

function collateralList() external view returns (bytes32[] memory __collateralList);

Returns

NameTypeDescription
__collateralListbytes32[]Array of all the collateral types registered

_modifyParameters

Internal function to be overriden with custom logic to modify parameters

This function is set to revert if not overriden

function _modifyParameters(bytes32 _param, bytes memory _data) internal override whenEnabled;

_modifyParameters

Internal function to be overriden with custom logic to modify parameters

This function is set to revert if not overriden

function _modifyParameters(bytes32 _cType, bytes32 _param, bytes memory _data) internal override whenEnabled;

_validateDelayedOracle

Validates the address is IDelayedOracle compliant and returns it

function _validateDelayedOracle(address _oracle) internal view returns (IDelayedOracle _delayedOracle);

_validateParameters

Internal function to be overriden with custom logic to validate parameters

function _validateParameters() internal view override;

_validateCParameters

Internal function to be overriden with custom logic to validate collateral parameters

function _validateCParameters(bytes32 _cType) internal view override;