OracleRelayer
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
Name | Type | Description |
---|---|---|
_oracleRelayerParams | OracleRelayerParams | An OracleRelayerParams struct |
cParams
Getter for the collateral parameters struct
function cParams(bytes32 _cType) external view returns (OracleRelayerCollateralParams memory _oracleRelayerCParams);
Parameters
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 representation of the collateral type |
Returns
Name | Type | Description |
---|---|---|
_oracleRelayerCParams | OracleRelayerCollateralParams | An OracleRelayerCollateralParams struct |
constructor
constructor(
address _safeEngine,
IBaseOracle _systemCoinOracle,
OracleRelayerParams memory _oracleRelayerParams
) Authorizable(msg.sender) validParams;
Parameters
Name | Type | Description |
---|---|---|
_safeEngine | address | Address of the SAFEEngine |
_systemCoinOracle | IBaseOracle | Address of the system coin oracle |
_oracleRelayerParams | OracleRelayerParams | Initial OracleRelayer valid parameters struct |
marketPrice
The current system coin market price
function marketPrice() external view returns (uint256 _marketPrice);
Returns
Name | Type | Description |
---|---|---|
_marketPrice | uint256 | The 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
Name | Type | Description |
---|---|---|
_virtualRedemptionPrice | uint256 | _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
Name | Type | Description |
---|---|---|
_updatedPrice | uint256 | The 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Bytes32 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
Name | Type | Description |
---|---|---|
_redemptionRate | uint256 | The 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | Collateral type to register |
_collateralParams | bytes | Collateral 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
Name | Type | Description |
---|---|---|
_cType | bytes32 | String identifier of the collateral to modify |
_param | bytes32 | String identifier of the parameter to modify |
_data | bytes | Encoded 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;