PIDController
Inherits: Authorizable, Modifiable, IPIDController
Redemption Rate Feedback Mechanism (RRFM) controller that implements a PI controller
State Variables
_NEGATIVE_RATE_LIMIT
The lower (when negative) bound for the redemption rate
Represents a rate of -99.999% per second (as -100% is not allowed) in RAY precision
uint256 internal constant _NEGATIVE_RATE_LIMIT = RAY - 1;
_POSITIVE_RATE_LIMIT
The upper bound for the redemption rate
Maximum possible value that can be safely casted to int256
uint256 internal constant _POSITIVE_RATE_LIMIT = uint256(type(int256).max);
seedProposer
Returns the address allowed to call computeRate method
address public seedProposer;
_params
Getter for the unpacked contract parameters struct
PIDControllerParams public _params;
_deviationObservation
Raw data about the last deviation observation
The last deviation observation, containing latest timestamp, proportional and integral terms
DeviationObservation public _deviationObservation;
_controllerGains
Raw data about the Kp and Ki values used in this calculator
ControllerGains public _controllerGains;
Functions
params
Getter for the contract parameters struct
function params() external view returns (PIDControllerParams memory _pidParams);
Returns
Name | Type | Description |
---|---|---|
_pidParams | PIDControllerParams | The PID controller parameters struct |
deviationObservation
Returns the last deviation observation, containing latest timestamp, proportional and integral terms
function deviationObservation() external view returns (DeviationObservation memory __deviationObservation);
Returns
Name | Type | Description |
---|---|---|
__deviationObservation | DeviationObservation | The last deviation observation struct |
controllerGains
Returns the Kp and Ki values used in this calculator
The values are expressed in WAD, Kp stands for proportional and Ki for integral terms
function controllerGains() external view returns (ControllerGains memory _cGains);
constructor
constructor(
ControllerGains memory _cGains,
PIDControllerParams memory _pidParams,
DeviationObservation memory _importedState
) Authorizable(msg.sender) validParams;
Parameters
Name | Type | Description |
---|---|---|
_cGains | ControllerGains | Initial valid controller gains settings struct |
_pidParams | PIDControllerParams | Initial valid PID controller parameters struct |
_importedState | DeviationObservation | Imported initial state of the controller (optional) |
getBoundedRedemptionRate
Return a redemption rate bounded by feedbackOutputLowerBound and feedbackOutputUpperBound as well as the timeline over which that rate will take effect
function getBoundedRedemptionRate(int256 _piOutput) external view returns (uint256 _newRedemptionRate);
Parameters
Name | Type | Description |
---|---|---|
_piOutput | int256 | The raw redemption rate computed from the proportional and integral terms |
Returns
Name | Type | Description |
---|---|---|
_newRedemptionRate | uint256 | _redemptionRate The bounded redemption rate |
_getBoundedRedemptionRate
Computes the new redemption rate by taking into account the feedbackOutputUpperBound and feedbackOutputLowerBound
function _getBoundedRedemptionRate(int256 _piOutput) internal view virtual returns (uint256 _newRedemptionRate);
_getBoundedPIOutput
Computes the pi output by taking into account the feedbackOutputUpperBound and feedbackOutputLowerBound
function _getBoundedPIOutput(int256 _piOutput) internal view virtual returns (int256 _boundedPIOutput);
computeRate
Compute a new redemption rate
function computeRate(uint256 _marketPrice, uint256 _redemptionPrice) external returns (uint256 _newRedemptionRate);
Parameters
Name | Type | Description |
---|---|---|
_marketPrice | uint256 | The system coin market price |
_redemptionPrice | uint256 | The system coin redemption price |
Returns
Name | Type | Description |
---|---|---|
_newRedemptionRate | uint256 | _redemptionRate The computed redemption rate |
_getProportionalTerm
Computes the proportional term using the scaled difference between market price and redemption price
function _getProportionalTerm(
uint256 _marketPrice,
uint256 _redemptionPrice
) internal view virtual returns (int256 _proportionalTerm);
breaksNoiseBarrier
Returns whether the P + I sum exceeds the noise barrier
function breaksNoiseBarrier(uint256 _piSum, uint256 _redemptionPrice) external view virtual returns (bool _breaksNb);
Parameters
Name | Type | Description |
---|---|---|
_piSum | uint256 | Represents a sum between P + I |
_redemptionPrice | uint256 | The system coin redemption price |
Returns
Name | Type | Description |
---|---|---|
_breaksNb | bool | Whether the P + I sum exceeds the noise barrier |
_breaksNoiseBarrier
Returns whether the P + I sum exceeds the noise barrier
function _breaksNoiseBarrier(uint256 _piSum, uint256 _redemptionPrice) internal view virtual returns (bool _breaksNb);
getGainAdjustedPIOutput
Apply Kp to the proportional term and Ki to the integral term (by multiplication) and then sum P and I
function getGainAdjustedPIOutput(
int256 _proportionalTerm,
int256 _integralTerm
) external view returns (int256 _gainAdjustedPIOutput);
Parameters
Name | Type | Description |
---|---|---|
_proportionalTerm | int256 | The proportional term |
_integralTerm | int256 | The integral term |
Returns
Name | Type | Description |
---|---|---|
_gainAdjustedPIOutput | int256 | _piOutput The sum of P and I |
_getGainAdjustedPIOutput
Computes the gain adjusted PI output by multiplying P by Kp and I by Ki and then sum P & I
function _getGainAdjustedPIOutput(
int256 _proportionalTerm,
int256 _integralTerm
) internal view virtual returns (int256 _adjustedPIOutput);
_getGainAdjustedTerms
Computes the gain adjusted terms by multiplying P by Kp and I by Ki
function _getGainAdjustedTerms(
int256 _proportionalTerm,
int256 _integralTerm
) internal view virtual returns (int256 _ajustedProportionalTerm, int256 _adjustedIntegralTerm);
getGainAdjustedTerms
Independently return and calculate P * Kp and I * Ki
function getGainAdjustedTerms(
int256 _proportionalTerm,
int256 _integralTerm
) external view returns (int256 _ajustedProportionalTerm, int256 _adjustedIntegralTerm);
Parameters
Name | Type | Description |
---|---|---|
_proportionalTerm | int256 | The proportional term |
_integralTerm | int256 | The integral term |
Returns
Name | Type | Description |
---|---|---|
_ajustedProportionalTerm | int256 | _proportionalGain The proportional gain |
_adjustedIntegralTerm | int256 | _integralGain The integral gain |
_updateDeviation
Push new observations in deviationObservations while also updating priceDeviationCumulative
function _updateDeviation(
int256 _proportionalTerm,
uint256 _accumulatedLeak
) internal virtual returns (int256 _integralTerm);
Parameters
Name | Type | Description |
---|---|---|
_proportionalTerm | int256 | The proportionalTerm |
_accumulatedLeak | uint256 | The total leak (similar to a negative interest rate) applied to priceDeviationCumulative before proportionalTerm is added to it |
getNextDeviationCumulative
Compute a new priceDeviationCumulative (integral term)
function getNextDeviationCumulative(
int256 _proportionalTerm,
uint256 _accumulatedLeak
) external view returns (int256 _nextDeviationCumulative, int256 _appliedDeviation);
Parameters
Name | Type | Description |
---|---|---|
_proportionalTerm | int256 | The proportional term (redemptionPrice - marketPrice) |
_accumulatedLeak | uint256 | The total leak applied to priceDeviationCumulative before it is summed with the new time adjusted deviation |
Returns
Name | Type | Description |
---|---|---|
_nextDeviationCumulative | int256 | _priceDeviationCumulative The new priceDeviationCumulative |
_appliedDeviation | int256 | _timeAdjustedDeviation The new time adjusted deviation |
_getNextDeviationCumulative
Computes the new priceDeviationCumulative (integral term)
function _getNextDeviationCumulative(
int256 _proportionalTerm,
uint256 _accumulatedLeak
) internal view virtual returns (int256 _nextDeviationCumulative, int256 _appliedDeviation);
getNextRedemptionRate
Compute and return the upcoming redemption rate
This method is used to provide a view of the next redemption rate without updating the state of the controller
function getNextRedemptionRate(
uint256 _marketPrice,
uint256 _redemptionPrice,
uint256 _accumulatedLeak
) external view returns (uint256 _redemptionRate, int256 _proportionalTerm, int256 _integralTerm);
Parameters
Name | Type | Description |
---|---|---|
_marketPrice | uint256 | The system coin market price |
_redemptionPrice | uint256 | The system coin redemption price |
_accumulatedLeak | uint256 | The total leak applied to priceDeviationCumulative before it is summed with the proportionalTerm |
Returns
Name | Type | Description |
---|---|---|
_redemptionRate | uint256 | The upcoming redemption rate |
_proportionalTerm | int256 | The upcoming proportional term |
_integralTerm | int256 | The upcoming integral term |
timeSinceLastUpdate
Returns the time elapsed since the last computeRate call
function timeSinceLastUpdate() external view returns (uint256 _elapsed);
_timeSinceLastUpdate
function _timeSinceLastUpdate() internal view returns (uint256 _elapsed);
_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;
_validateParameters
Internal function to be overriden with custom logic to validate parameters
function _validateParameters() internal view override;