From 0825e0d6ffcd3ab7d5f4f65eb1bcd4b06806a8db Mon Sep 17 00:00:00 2001 From: ckoopmann Date: Mon, 11 Nov 2024 12:31:19 +0100 Subject: [PATCH] fix: Apply unitilizedLeveragePercentage to maxBorrowCollateral only when levering up --- contracts/adapters/MorphoLeverageStrategyExtension.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/adapters/MorphoLeverageStrategyExtension.sol b/contracts/adapters/MorphoLeverageStrategyExtension.sol index 32bbf35c..4e5392a0 100644 --- a/contracts/adapters/MorphoLeverageStrategyExtension.sol +++ b/contracts/adapters/MorphoLeverageStrategyExtension.sol @@ -1123,10 +1123,11 @@ contract MorphoLeverageStrategyExtension is BaseExtension { // Note NetBorrow Limit is already denominated in borrow asset uint256 netBorrowLimit = _actionInfo.collateralBalance .mul(_actionInfo.collateralPrice).div(MORPHO_ORACLE_PRICE_SCALE) - .preciseMul(_actionInfo.lltv) - .preciseMul(PreciseUnitMath.preciseUnit().sub(execution.unutilizedLeveragePercentage)); + .preciseMul(_actionInfo.lltv); + if (_isLever) { return netBorrowLimit + .preciseMul(PreciseUnitMath.preciseUnit().sub(execution.unutilizedLeveragePercentage)) .sub(_actionInfo.borrowBalance) .mul(MORPHO_ORACLE_PRICE_SCALE).div(_actionInfo.collateralPrice); } else {