From ce58ead1796dc6cf7d8ff3a091bb327f129014a7 Mon Sep 17 00:00:00 2001 From: FP Date: Mon, 25 Mar 2024 10:03:44 -0700 Subject: [PATCH 1/3] chore: allow healthcheck mem to be packed --- src/Bases/HealthCheck/BaseHealthCheck.sol | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Bases/HealthCheck/BaseHealthCheck.sol b/src/Bases/HealthCheck/BaseHealthCheck.sol index 23b2090..9bbdb4f 100644 --- a/src/Bases/HealthCheck/BaseHealthCheck.sol +++ b/src/Bases/HealthCheck/BaseHealthCheck.sol @@ -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, @@ -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) { + function profitLimitRatio() public view returns (uint16) { return _profitLimitRatio; } @@ -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; } @@ -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); } @@ -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; } @@ -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); } @@ -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; } @@ -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" ); } From 4311d9b418e3ae010407b34d65c8d410d9d853e8 Mon Sep 17 00:00:00 2001 From: FP Date: Mon, 25 Mar 2024 10:35:17 -0700 Subject: [PATCH 2/3] chore: use uint256 for BHC limit getters/setters --- src/Bases/HealthCheck/BaseHealthCheck.sol | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Bases/HealthCheck/BaseHealthCheck.sol b/src/Bases/HealthCheck/BaseHealthCheck.sol index 9bbdb4f..7aefa4a 100644 --- a/src/Bases/HealthCheck/BaseHealthCheck.sol +++ b/src/Bases/HealthCheck/BaseHealthCheck.sol @@ -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 (uint16) { + function profitLimitRatio() public view returns (uint256) { return _profitLimitRatio; } @@ -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 (uint16) { + function lossLimitRatio() public view returns (uint256) { return _lossLimitRatio; } @@ -64,7 +64,7 @@ abstract contract BaseHealthCheck is BaseStrategy { * @param _newProfitLimitRatio The mew profit limit ratio. */ function setProfitLimitRatio( - uint16 _newProfitLimitRatio + uint256 _newProfitLimitRatio ) external onlyManagement { _setProfitLimitRatio(_newProfitLimitRatio); } @@ -74,9 +74,10 @@ abstract contract BaseHealthCheck is BaseStrategy { * in basis points. I.E. 1_000 == 10%. * @param _newProfitLimitRatio The mew profit limit ratio. */ - function _setProfitLimitRatio(uint16 _newProfitLimitRatio) internal { + function _setProfitLimitRatio(uint256 _newProfitLimitRatio) internal { require(_newProfitLimitRatio > 0, "!zero profit"); - _profitLimitRatio = _newProfitLimitRatio; + require(_newProfitLimitRatio <= type(uint16).max, "!too high"); + _profitLimitRatio = uint16(_newProfitLimitRatio); } /** @@ -85,7 +86,7 @@ abstract contract BaseHealthCheck is BaseStrategy { * @param _newLossLimitRatio The new loss limit ratio. */ function setLossLimitRatio( - uint16 _newLossLimitRatio + uint256 _newLossLimitRatio ) external onlyManagement { _setLossLimitRatio(_newLossLimitRatio); } @@ -95,9 +96,10 @@ abstract contract BaseHealthCheck is BaseStrategy { * in basis points. I.E. 1_000 == 10%. * @param _newLossLimitRatio The new loss limit ratio. */ - function _setLossLimitRatio(uint16 _newLossLimitRatio) internal { + function _setLossLimitRatio(uint256 _newLossLimitRatio) internal { require(_newLossLimitRatio < MAX_BPS, "!loss limit"); - _lossLimitRatio = _newLossLimitRatio; + require(_newLossLimitRatio <= type(uint16).max, "!too high"); + _lossLimitRatio = uint16(_newLossLimitRatio); } /** From 125ca16e7ca85d07df9950b54b3c0e8ccdb0fd69 Mon Sep 17 00:00:00 2001 From: FP Date: Mon, 25 Mar 2024 10:38:34 -0700 Subject: [PATCH 3/3] fix: durr --- src/Bases/HealthCheck/BaseHealthCheck.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bases/HealthCheck/BaseHealthCheck.sol b/src/Bases/HealthCheck/BaseHealthCheck.sol index 7aefa4a..1f00f81 100644 --- a/src/Bases/HealthCheck/BaseHealthCheck.sol +++ b/src/Bases/HealthCheck/BaseHealthCheck.sol @@ -98,7 +98,6 @@ abstract contract BaseHealthCheck is BaseStrategy { */ function _setLossLimitRatio(uint256 _newLossLimitRatio) internal { require(_newLossLimitRatio < MAX_BPS, "!loss limit"); - require(_newLossLimitRatio <= type(uint16).max, "!too high"); _lossLimitRatio = uint16(_newLossLimitRatio); }