OracleRelayer

Git Source

Inherits: Authorizable, Disableable, Modifiable, ModifiablePerCollateral, 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;

_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

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

Returns

NameTypeDescription
_oracleRelayerParamsOracleRelayerParamsAn OracleRelayerParams struct

cParams

Getter for the collateral parameters struct

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

Parameters

NameTypeDescription
_cTypebytes32Bytes32 representation of the collateral type

Returns

NameTypeDescription
_oracleRelayerCParamsOracleRelayerCollateralParamsAn OracleRelayerCollateralParams struct

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]

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

_initializeCollateralType

Register a new collateral type in the SAFEEngine

function _initializeCollateralType(bytes32 _cType, bytes memory _collateralParams) internal override;

Parameters

NameTypeDescription
_cTypebytes32Collateral type to register
_collateralParamsbytesCollateral parameters

_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

Set a new value for a collateral specific parameter

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

Parameters

NameTypeDescription
_cTypebytes32String identifier of the collateral to modify
_parambytes32String identifier of the parameter to modify
_databytesEncoded data to modify the parameter

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