Skip to main content

BaseHealthCheck

Git Source

Inherits: BaseStrategy, IBaseHealthCheck

Title: Base Health Check

Author: Golem Foundation

This contract is based on Yearn's BaseHealthCheck from https://github.com/yearn/tokenized-strategy-periphery/blob/master/src/Bases/HealthCheck/BaseHealthCheck.sol This contract can be inherited by any strategy wishing to implement a health check during the report function in order to prevent any unexpected behavior from being permanently recorded as well as the checkHealth modifier. A strategist simply needs to inherit this contract. Set the limit ratios to the desired amounts and then override _harvestAndReport() just as they otherwise would. If the profit or loss that would be recorded is outside the acceptable bounds the tx will revert. The healthcheck does not prevent a strategy from reporting losses, but rather can make sure manual intervention is needed before reporting an unexpected loss or profit.

Note: security-contact: [email protected]

Quick Start — What Matters Most

Adds configurable safety bounds to strategy reports. If profit or loss exceeds the configured ratio, report() reverts.

Key functions to understand:

  • setProfitLimitRatio — Set max acceptable profit change per report
  • setLossLimitRatio — Set max acceptable loss change per report

State Variables

doHealthCheck

bool public doHealthCheck = true

MAX_BPS

uint256 internal constant MAX_BPS = 10_000

_profitLimitRatio

uint16 private _profitLimitRatio = uint16(MAX_BPS)

_lossLimitRatio

uint16 private _lossLimitRatio

Functions

constructor

constructor(
address _asset,
string memory _name,
string memory _symbol,
address _management,
address _keeper,
address _emergencyAdmin,
address _donationAddress,
bool _enableBurning,
address _tokenizedStrategyAddress
)
BaseStrategy(
_asset,
_name,
_symbol,
_management,
_keeper,
_emergencyAdmin,
_donationAddress,
_enableBurning,
_tokenizedStrategyAddress
);

profitLimitRatio

Returns the current profit limit ratio.

Use a getter function to keep the variable private.

function profitLimitRatio() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256profitLimitRatio Current profit limit ratio in basis points

lossLimitRatio

Returns the current loss limit ratio.

Use a getter function to keep the variable private.

function lossLimitRatio() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256lossLimitRatio Current loss limit ratio in basis points

setProfitLimitRatio

Set the profitLimitRatio.

Denominated in basis points. I.E. 1_000 == 10%.

function setProfitLimitRatio(uint256 _newProfitLimitRatio) external onlyManagement;

Parameters

NameTypeDescription
_newProfitLimitRatiouint256New profit limit ratio in basis points

_setProfitLimitRatio

Internally set the profit limit ratio. Denominated in basis points. I.E. 1_000 == 10%.

function _setProfitLimitRatio(uint256 _newProfitLimitRatio) internal;

Parameters

NameTypeDescription
_newProfitLimitRatiouint256New profit limit ratio in basis points

setLossLimitRatio

Set the lossLimitRatio.

Denominated in basis points. I.E. 1_000 == 10%.

function setLossLimitRatio(uint256 _newLossLimitRatio) external onlyManagement;

Parameters

NameTypeDescription
_newLossLimitRatiouint256New loss limit ratio in basis points

_setLossLimitRatio

Internally set the loss limit ratio. Denominated in basis points. I.E. 1_000 == 10%.

function _setLossLimitRatio(uint256 _newLossLimitRatio) internal;

Parameters

NameTypeDescription
_newLossLimitRatiouint256New loss limit ratio in basis points

setDoHealthCheck

Turns the healthcheck on and off.

If turned off the next report will auto turn it back on.

function setDoHealthCheck(bool _doHealthCheck) public onlyManagement;

Parameters

NameTypeDescription
_doHealthCheckboolBool if healthCheck should be done.

harvestAndReport

Overrides the default harvestAndReport to include a healthcheck.

function harvestAndReport() external override onlySelf returns (uint256 _totalAssets);

Returns

NameTypeDescription
_totalAssetsuint256New totalAssets post report.

_executeHealthCheck

To be called during a report to make sure the profit or loss being recorded is within the acceptable bound.

function _executeHealthCheck(uint256 _newTotalAssets) internal virtual;

Parameters

NameTypeDescription
_newTotalAssetsuint256Amount that will be reported in asset base units

Events

HealthCheckUpdated

Emitted when the health check flag is updated

event HealthCheckUpdated(bool doHealthCheck);

ProfitLimitRatioUpdated

Emitted when the profit limit ratio is updated

event ProfitLimitRatioUpdated(uint256 newProfitLimitRatio);

LossLimitRatioUpdated

Emitted when the loss limit ratio is updated

event LossLimitRatioUpdated(uint256 newLossLimitRatio);