Magic number is used in _calculateHealthFactor
function.
It is better to use readable constants instead of hex/numeric literals. Instance:
https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L331
function _calculateHealthFactor(uint256 totalDscMinted, uint256 collateralValueInUsd)
internal
pure
returns (uint256)
{
if (totalDscMinted == 0) return type(uint256).max;
uint256 collateralAdjustedForThreshold = (collateralValueInUsd * LIQUIDATION_THRESHOLD) / LIQUIDATION_PRECISION;
return (collateralAdjustedForThreshold * 1e18) / totalDscMinted;
}
Here, we can see 1e18
which is a magic number used for calculating health factor of the user.
Use of constants over magic numbers improves the readability of the code and helps the developers to understand the code better.
Manual review
There is already a constant state variable PRECISION
that is equal to 1e18
. Therefore, use PRECISION
instead of 1e18
.
return (collateralAdjustedForThreshold * PRECISION) / totalDscMinted;
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.