Folks-Finance/folks-finance-xchain-contracts

Can rebalance up to a lower stable borrow rate

Closed this issue · 0 comments

Describe the bug

When the user's stable borrow rate is greater than the pool's stable borrow rate, and the rebalance conditions are met, the stable borrow rate is able to be rebalanced up to a lower stable borrow rate

Impact Details

Unintended lower stable borrow rate

Relevant Code

function prepareForRebalanceUp(
HubPoolState.PoolData storage pool
) external returns (DataTypes.BorrowPoolParams memory borrowPoolParams) {
// can rebalance even if pool is depreciated
// update interest indexes before the interest rates change
pool.updateInterestIndexes();
uint256 utilizationRatio = MathUtils.calcUtilisationRatio(
pool.variableBorrowData.totalAmount + pool.stableBorrowData.totalAmount,
pool.depositData.totalAmount
);
uint256 rebalanceUpThreshold = MathUtils.calcRebalanceUpThreshold(
pool.stableBorrowData.rebalanceUpDepositInterestRate,
pool.variableBorrowData.vr0,
pool.variableBorrowData.vr1,
pool.variableBorrowData.vr2
);
// check conditions for rebalance
if (utilizationRatio < MathUtils.from4DPto18DP(pool.stableBorrowData.rebalanceUpUtilisationRatio))
revert RebalanceUpUtilisationRatioNotReached();
if (rebalanceUpThreshold < pool.depositData.interestRate) revert RebalanceUpThresholdNotReached();
borrowPoolParams.variableInterestIndex = pool.variableBorrowData.interestIndex;
borrowPoolParams.stableInterestRate = pool.stableBorrowData.interestRate;
}

Proposed Fix

Add check in LoanManagerLogic executeRebalanceUp

if (borrowPoolParams.stableInterestRate <= oldLoanStableInterestRate) revert RebalanceUpToLowerRate();