From bbc3a0354f45dab087a4c82650e42225433c8fef Mon Sep 17 00:00:00 2001 From: FP <83050944+fp-crypto@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:03:06 -0700 Subject: [PATCH] feat: allow BaseHealthCheck mem to be packed (#41) * chore: allow healthcheck mem to be packed * chore: use uint256 for BHC limit getters/setters * fix: durr --- src/Bases/HealthCheck/BaseHealthCheck.sol | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Bases/HealthCheck/BaseHealthCheck.sol b/src/Bases/HealthCheck/BaseHealthCheck.sol index 23b2090..1f00f81 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, @@ -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); } /** @@ -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); } /** @@ -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" ); }