Rebalance may occur due to wrong requirements check
Before a rebalance can occur, checks are implemented to ensure that `delta` and `debtRatio` remain within their specified limits. However, it's important to note that the check in `GMXChecks::beforeRebalanceChecks` ignores the scenario where these values are equal to any of their limits.\\nIn the current implementation of the `GMXRebalance::rebalanceAdd` function, it first calculates the current values of `debtRatio` and `delta` before making any changes. Subsequently, the `beforeRebalanceChecks` function, checks if these values meet the requirements for a rebalance to occur. These requirements now dictate that both `debtRatio` and `delta` must be either ≥ to the `UpperLimit`, or ≤ to the `LowerLimit` for a rebalance to take place.\\n```\\nfunction beforeRebalanceChecks(\\n  GMXTypes.Store storage self,\\n  GMXTypes.RebalanceType rebalanceType\\n) external view {\\n  if (\\n    self.status != GMXTypes.Status.Open &&\\n    self.status != GMXTypes.Status.Rebalance_Open\\n  ) revert Errors.NotAllowedInCurrentVaultStatus();\\n\\n  // Check that rebalance type is Delta or Debt\\n  // And then check that rebalance conditions are met\\n  // Note that Delta rebalancing requires vault's delta strategy to be Neutral as well\\n  if (rebalanceType == GMXTypes.RebalanceType.Delta && self.delta == GMXTypes.Delta.Neutral) {\\n    if (\\n      self.rebalanceCache.healthParams.deltaBefore < self.deltaUpperLimit &&\\n      self.rebalanceCache.healthParams.deltaBefore > self.deltaLowerLimit\\n    ) revert Errors.InvalidRebalancePreConditions();\\n  } else if (rebalanceType == GMXTypes.RebalanceType.Debt) {\\n    if (\\n      self.rebalanceCache.healthParams.debtRatioBefore < self.debtRatioUpperLimit &&\\n      self.rebalanceCache.healthParams.debtRatioBefore > self.debtRatioLowerLimit\\n    ) revert Errors.InvalidRebalancePreConditions();\\n  } else {\\n     revert Errors.InvalidRebalanceParameters();\\n  }\\n}\\n```\\n\\nSuppose a rebalance is successful. In the `afterRebalanceChecks` section, the code verifies whether both `delta` and `debtRatio` are greater than the `UpperLimit` or less than the `LowerLimit`. This confirmation implies that these limits are indeed inclusive, meaning that the correct interpretation of these limits should be that `LowerLimit` ≤ actualValue ≤ `UpperLimit`. On the other hand, this also indicates that for a rebalancing to occur, the values of `deltaBefore` and `debtRatioBefore` need to be outside their limits, i.e., `delta` should be greater than `Upper` or less than `Lower`. However, in the current implementation, if these values are equal to the limit, a rebalance may still occur, which violates the consistency of the `afterRebalanceChecks` function, thus indicating that these limits are inclusive. Consequently, a value equal to the limit needs to be treated as valid and not be able to trigger a rebalance.\\n```\\nfunction afterRebalanceChecks(\\n  GMXTypes.Store storage self\\n) external view {\\n  // Guards: check that delta is within limits for Neutral strategy\\n  if (self.delta == GMXTypes.Delta.Neutral) {\\n    int256 _delta = GMXReader.delta(self);\\n\\n    if (\\n      _delta > self.deltaUpperLimit ||\\n      _delta < self.deltaLowerLimit\\n    ) revert Errors.InvalidDelta();\\n  }\\n\\n  // Guards: check that debt is within limits for Long/Neutral strategy\\n  uint256 _debtRatio = GMXReader.debtRatio(self);\\n\\n  if (\\n    _debtRatio > self.debtRatioUpperLimit ||\\n    _debtRatio < self.debtRatioLowerLimit\\n  ) revert Errors.InvalidDebtRatio();\\n}\\n```\\n\\nImagine the case when `delta` or `debtRatio` is equal to any of its limits; a rebalance will occur. However, on the other hand, these values are valid because they are inclusively within the limits.
Rebalance may occur due to wrong requirements check\\nConsider a strict check to determine if `delta` or `debtRatio` is strictly within its limits, including scenarios where they are equal to any of its limits. In such cases, the code should ensure that a rebalance does not occur when these values are precisely at the limit.\\n```\\nfunction beforeRebalanceChecks(\\n    GMXTypes.Store storage self,\\n    GMXTypes.RebalanceType rebalanceType\\n  ) external view {\\n    if (\\n      self.status != GMXTypes.Status.Open &&\\n      self.status != GMXTypes.Status.Rebalance_Open\\n    ) revert Errors.NotAllowedInCurrentVaultStatus();\\n\\n    // Check that rebalance type is Delta or Debt\\n    // And then check that rebalance conditions are met\\n    // Note that Delta rebalancing requires vault's delta strategy to be Neutral as well\\n    if (rebalanceType == GMXTypes.RebalanceType.Delta && self.delta == GMXTypes.Delta.Neutral) {\\n      if (\\n// Remove the line below\\n       self.rebalanceCache.healthParams.deltaBefore < self.deltaUpperLimit &&\\n// Remove the line below\\n       self.rebalanceCache.healthParams.deltaBefore > self.deltaLowerLimit\\n// Add the line below\\n       self.rebalanceCache.healthParams.deltaBefore <= self.deltaUpperLimit &&\\n// Add the line below\\n       self.rebalanceCache.healthParams.deltaBefore >= self.deltaLowerLimit\\n      ) revert Errors.InvalidRebalancePreConditions();\\n    } else if (rebalanceType == GMXTypes.RebalanceType.Debt) {\\n      if (\\n// Remove the line below\\n       self.rebalanceCache.healthParams.debtRatioBefore < self.debtRatioUpperLimit &&\\n// Remove the line below\\n       self.rebalanceCache.healthParams.debtRatioBefore > self.debtRatioLowerLimit\\n// Add the line below\\n       self.rebalanceCache.healthParams.debtRatioBefore <= self.debtRatioUpperLimit &&\\n// Add the line below\\n       self.rebalanceCache.healthParams.debtRatioBefore >= self.debtRatioLowerLimit\\n      ) revert Errors.InvalidRebalancePreConditions();\\n    } else {\\n       revert Errors.InvalidRebalanceParameters();\\n    }\\n  }\\n```\\n
In such a scenario, the system might incorrectly trigger a rebalance of the vault, even when `delta` or `debtRatio` is precisely within the established limits, thus potentially causing unintended rebalancing actions.
```\\nfunction beforeRebalanceChecks(\\n  GMXTypes.Store storage self,\\n  GMXTypes.RebalanceType rebalanceType\\n) external view {\\n  if (\\n    self.status != GMXTypes.Status.Open &&\\n    self.status != GMXTypes.Status.Rebalance_Open\\n  ) revert Errors.NotAllowedInCurrentVaultStatus();\\n\\n  // Check that rebalance type is Delta or Debt\\n  // And then check that rebalance conditions are met\\n  // Note that Delta rebalancing requires vault's delta strategy to be Neutral as well\\n  if (rebalanceType == GMXTypes.RebalanceType.Delta && self.delta == GMXTypes.Delta.Neutral) {\\n    if (\\n      self.rebalanceCache.healthParams.deltaBefore < self.deltaUpperLimit &&\\n      self.rebalanceCache.healthParams.deltaBefore > self.deltaLowerLimit\\n    ) revert Errors.InvalidRebalancePreConditions();\\n  } else if (rebalanceType == GMXTypes.RebalanceType.Debt) {\\n    if (\\n      self.rebalanceCache.healthParams.debtRatioBefore < self.debtRatioUpperLimit &&\\n      self.rebalanceCache.healthParams.debtRatioBefore > self.debtRatioLowerLimit\\n    ) revert Errors.InvalidRebalancePreConditions();\\n  } else {\\n     revert Errors.InvalidRebalanceParameters();\\n  }\\n}\\n```\\n