THE `CollateralAndLiquidity.findLiquidatableUsers` FUNCTION DOES NOT CORRECTLY SELECT THE LIQUIDATABLE WALLETS DUE TO THE ROUNDING DOWN OF THE `minCollateralValue` AND `minCollateral` VALUES DURING CALCULATIONS
Audit: 2024-01-salty-findings
Severity: MEDIUM

# Lines of code

https://github.com/code-423n4/2024-01-salty/blob/main/src/stable/CollateralAndLiquidity.sol#L322-L334


# Vulnerability details

## Impact

The `CollateralAndLiquidity.findLiquidatableUsers` function is used to find the list of borrowers who does not complement atleast the `minimumCollateralRatioPercent` and are eligible to be liquidated. 

To evaluate whether a a single `borrowed wallet` is liquidatable based on its borrowed amount and `minimumCollateralRatioPercent` is perfomed as shown below:

				{
				address wallet = _walletsWithBorrowedUSDS.at(i); //@audit-info - get the borrowed address

				// Determine the minCollateralValue a user needs to have based on their borrowedUSDS
				uint256 minCollateralValue = (usdsBorrowedByUsers[wallet] * stableConfig.minimumCollateralRatioPercent()) / 100; //@audit-issue - this should round up and since it rounds down the user can have less than the minimum collateral value required
				//@audit-info - calculate the minimum collateral value a user should have based on teh borrowedUSDS
				// Determine minCollateral in terms of minCollateralValue
				uint256 minCollateral = (minCollateralValue * totalCollateralShares) / totalCollateralValue; //@audit-issue - this should round up and since it rounds down the user can have less than the minimum collateral liquidity required
				//@audit-info - find the minimum collateral liquidity amount a user should have
				// Make sure the user has at least minCollateral
				if ( userShareForPool( wallet, collateralPoolID ) < minCollateral ) //@audit-issue - since above values round down a user who is liquidatable is not considered liquidatable.
					liquidatableUsers[count++] = wallet; //@audit-info - add to the liquidatable users array since he does not have enough collateral liqudiity
				} //@audit-issue - if not for round down minCollateral could have been 152 but with rounding down it is 150. Hence if the `userShareForPool( wallet, collateralPoolID ) == 150` then it is considered as not liquidable

As it is evident from the above code snippet the `minCollateralValue` is rounded down. As a result the `minCollateralValue` does not complement the `minimumCollateralRatioPercent`. Due to the rounding down of the `minCollateralValue` the actual `collateral ratio` now will be slightly less than the `minimumCollateralRatioPercent` which is not the expected funcitonality or behaviour of the `salty` protocol when it comes to liquidations. Here the rounding is happening in favour of the borrower and not in favour of the protocol

Furthermore `minCollateral` value calculation is also rounded down. since it rounds down the user can have less than the minimum collateral liquidity required. Since the `minCollateral` value is calculated using the `minCollateralValue` which was rounded down and the `minCollateral` value is itself rounded down the resulting `minCollateral` value does not complement the `minimumCollateralRatioPercent` value. Which means the calculate