Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow BaseHealthCheck mem to be packed #41

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Bases/HealthCheck/BaseHealthCheck.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ abstract contract BaseHealthCheck is BaseStrategy {
uint256 internal constant MAX_BPS = 10_000;

// Default profit limit to 100%.
uint256 private _profitLimitRatio = MAX_BPS;
uint16 private _profitLimitRatio = uint16(MAX_BPS);

// Defaults loss limit to 0.
uint256 private _lossLimitRatio;
uint16 private _lossLimitRatio;

constructor(
address _asset,
Expand Down Expand Up @@ -76,7 +76,8 @@ abstract contract BaseHealthCheck is BaseStrategy {
*/
function _setProfitLimitRatio(uint256 _newProfitLimitRatio) internal {
require(_newProfitLimitRatio > 0, "!zero profit");
_profitLimitRatio = _newProfitLimitRatio;
require(_newProfitLimitRatio <= type(uint16).max, "!too high");
_profitLimitRatio = uint16(_newProfitLimitRatio);
}

/**
Expand All @@ -97,7 +98,7 @@ abstract contract BaseHealthCheck is BaseStrategy {
*/
function _setLossLimitRatio(uint256 _newLossLimitRatio) internal {
require(_newLossLimitRatio < MAX_BPS, "!loss limit");
_lossLimitRatio = _newLossLimitRatio;
_lossLimitRatio = uint16(_newLossLimitRatio);
}

/**
Expand Down Expand Up @@ -144,13 +145,13 @@ abstract contract BaseHealthCheck is BaseStrategy {
if (_newTotalAssets > currentTotalAssets) {
require(
((_newTotalAssets - currentTotalAssets) <=
(currentTotalAssets * _profitLimitRatio) / MAX_BPS),
(currentTotalAssets * uint256(_profitLimitRatio)) / MAX_BPS),
"healthCheck"
);
} else if (currentTotalAssets > _newTotalAssets) {
require(
(currentTotalAssets - _newTotalAssets <=
((currentTotalAssets * _lossLimitRatio) / MAX_BPS)),
((currentTotalAssets * uint256(_lossLimitRatio)) / MAX_BPS)),
"healthCheck"
);
}
Expand Down
Loading