Rebalance will be delayed due to revert
The rebalancing of unhealthy currencies will be delayed due to a revert, resulting in an excess of liquidity being lent out in the external market. This might affect the liquidity of the protocol, potentially resulting in withdrawal or liquidation having issues executed due to insufficient liquidity.\\nAssume that Notional supports 5 currencies ($A, B, C, D, E$), and the Gelato bot is configured to call the `checkRebalance` function every 30 minutes.\\nAssume that the current market condition is volatile. Thus, the inflow and outflow of assets to Notional, utilization rate, and available liquidity at AAVE change frequently. As a result, the target amount that should be externally lent out also changes frequently since the computation of this value relies on the spot market information.\\nAt T1, when the Gelato bot calls the `checkRebalance()` view function, it returns that currencies $A$, $B$, and $C$ are unhealthy and need to be rebalanced.\\nShortly after receiving the execution payload from the `checkRebalance()`, the bot submits the rebalancing TX to the mempool for execution at T2.\\nWhen the rebalancing TX is executed at T3, one of the currencies (Currency $A$) becomes healthy. As a result, the require check at Line 326 will revert and the entire rebalancing transaction will be cancelled. Thus, currencies $B$ and $C$ that are still unhealthy at this point will not be rebalanced.\\nIf this issue occurs frequently or repeatedly over a period of time, the rebalancing of unhealthy currencies will be delayed.\\n```\\nFile: TreasuryAction.sol\\n    function _rebalanceCurrency(uint16 currencyId, bool useCooldownCheck) private { \\n        RebalancingContextStorage memory context = LibStorage.getRebalancingContext()[currencyId]; \\n        // Accrues interest up to the current block before any rebalancing is executed\\n        IPrimeCashHoldingsOracle oracle = PrimeCashExchangeRate.getPrimeCashHoldingsOracle(currencyId); \\n        PrimeRate memory pr = PrimeRateLib.buildPrimeRateStateful(currencyId); \\n\\n        bool hasCooldownPassed = _hasCooldownPassed(context); \\n        (bool isExternalLendingUnhealthy, OracleData memory oracleData, uint256 targetAmount) = \\n            _isExternalLendingUnhealthy(currencyId, oracle, pr); \\n\\n        // Cooldown check is bypassed when the owner updates the rebalancing targets\\n        if (useCooldownCheck) require(hasCooldownPassed || isExternalLendingUnhealthy); \\n```\\n
If one of the currencies becomes healthy when the rebalance TX is executed, consider skipping this currency and move on to execute the rebalance on the rest of the currencies that are still unhealthy.\\n```\\nfunction _rebalanceCurrency(uint16 currencyId, bool useCooldownCheck) private { \\n RebalancingContextStorage memory context = LibStorage.getRebalancingContext()[currencyId]; \\n // Accrues interest up to the current block before any rebalancing is executed\\n IPrimeCashHoldingsOracle oracle = PrimeCashExchangeRate.getPrimeCashHoldingsOracle(currencyId); \\n PrimeRate memory pr = PrimeRateLib.buildPrimeRateStateful(currencyId); \\n\\n bool hasCooldownPassed = _hasCooldownPassed(context); \\n (bool isExternalLendingUnhealthy, OracleData memory oracleData, uint256 targetAmount) = \\n  _isExternalLendingUnhealthy(currencyId, oracle, pr); \\n\\n // Cooldown check is bypassed when the owner updates the rebalancing targets\\n// Remove the line below\\n if (useCooldownCheck) require(hasCooldownPassed || isExternalLendingUnhealthy);\\n// Add the line below\\n if (useCooldownCheck && !hasCooldownPassed && !isExternalLendingUnhealthy) return;\\n```\\n
The rebalancing of unhealthy currencies will be delayed, resulting in an excess of liquidity being lent out to the external market. This might affect the liquidity of the protocol, potentially resulting in withdrawal or liquidation having issues executed due to insufficient liquidity.
```\\nFile: TreasuryAction.sol\\n    function _rebalanceCurrency(uint16 currencyId, bool useCooldownCheck) private { \\n        RebalancingContextStorage memory context = LibStorage.getRebalancingContext()[currencyId]; \\n        // Accrues interest up to the current block before any rebalancing is executed\\n        IPrimeCashHoldingsOracle oracle = PrimeCashExchangeRate.getPrimeCashHoldingsOracle(currencyId); \\n        PrimeRate memory pr = PrimeRateLib.buildPrimeRateStateful(currencyId); \\n\\n        bool hasCooldownPassed = _hasCooldownPassed(context); \\n        (bool isExternalLendingUnhealthy, OracleData memory oracleData, uint256 targetAmount) = \\n            _isExternalLendingUnhealthy(currencyId, oracle, pr); \\n\\n        // Cooldown check is bypassed when the owner updates the rebalancing targets\\n        if (useCooldownCheck) require(hasCooldownPassed || isExternalLendingUnhealthy); \\n```\\n