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 1 commit
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
20 changes: 10 additions & 10 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 All @@ -45,7 +45,7 @@ abstract contract BaseHealthCheck is BaseStrategy {
* @dev Use a getter function to keep the variable private.
* @return . The current profit limit ratio.
*/
function profitLimitRatio() public view returns (uint256) {
Schlagonia marked this conversation as resolved.
Show resolved Hide resolved
function profitLimitRatio() public view returns (uint16) {
return _profitLimitRatio;
}

Expand All @@ -54,7 +54,7 @@ abstract contract BaseHealthCheck is BaseStrategy {
* @dev Use a getter function to keep the variable private.
* @return . The current loss limit ratio.
*/
function lossLimitRatio() public view returns (uint256) {
function lossLimitRatio() public view returns (uint16) {
return _lossLimitRatio;
}

Expand All @@ -64,7 +64,7 @@ abstract contract BaseHealthCheck is BaseStrategy {
* @param _newProfitLimitRatio The mew profit limit ratio.
*/
function setProfitLimitRatio(
uint256 _newProfitLimitRatio
uint16 _newProfitLimitRatio
) external onlyManagement {
_setProfitLimitRatio(_newProfitLimitRatio);
}
Expand All @@ -74,7 +74,7 @@ abstract contract BaseHealthCheck is BaseStrategy {
* in basis points. I.E. 1_000 == 10%.
* @param _newProfitLimitRatio The mew profit limit ratio.
*/
function _setProfitLimitRatio(uint256 _newProfitLimitRatio) internal {
function _setProfitLimitRatio(uint16 _newProfitLimitRatio) internal {
require(_newProfitLimitRatio > 0, "!zero profit");
_profitLimitRatio = _newProfitLimitRatio;
}
Expand All @@ -85,7 +85,7 @@ abstract contract BaseHealthCheck is BaseStrategy {
* @param _newLossLimitRatio The new loss limit ratio.
*/
function setLossLimitRatio(
uint256 _newLossLimitRatio
uint16 _newLossLimitRatio
) external onlyManagement {
_setLossLimitRatio(_newLossLimitRatio);
}
Expand All @@ -95,7 +95,7 @@ abstract contract BaseHealthCheck is BaseStrategy {
* in basis points. I.E. 1_000 == 10%.
* @param _newLossLimitRatio The new loss limit ratio.
*/
function _setLossLimitRatio(uint256 _newLossLimitRatio) internal {
function _setLossLimitRatio(uint16 _newLossLimitRatio) internal {
require(_newLossLimitRatio < MAX_BPS, "!loss limit");
_lossLimitRatio = _newLossLimitRatio;
}
Expand Down Expand Up @@ -144,13 +144,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