The function _revertIfHealthFactorIsBroken within the burnDsc function is not required and can be removed. Burning tokens will allow a user to improve his health factor regardless of the amount chosen to repay. This removal will enhance the deployment cost by around 1800 gas units.
Furthermore, this check currently prevents users from repaying a fraction of their debt in the case of an undercollateralized position. If a user chooses to repay a fraction of the debt that does not increase their health factor above the MIN_HEALTH_FACTOR, it should still improve it. However, invoking _revertIfHealthFactorIsBroken stops them from doing so, which is an undesirable side effect.
Removing this check would not only optimize gas but also provide a better user experience by allowing more flexibility in debt repayment strategies.
Unnecessary Health Factor Check in
burnDsc
FunctionSeverity
Gas Optimization / Informational
Relevant GitHub Links
https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol
The function
_revertIfHealthFactorIsBroken
within the burnDsc function is not required and can be removed. Burning tokens will allow a user to improve his health factor regardless of the amount chosen to repay. This removal will enhance the deployment cost by around 1800 gas units. Furthermore, this check currently prevents users from repaying a fraction of their debt in the case of an undercollateralized position. If a user chooses to repay a fraction of the debt that does not increase their health factor above theMIN_HEALTH_FACTOR
, it should still improve it. However, invoking_revertIfHealthFactorIsBroken
stops them from doing so, which is an undesirable side effect. Removing this check would not only optimize gas but also provide a better user experience by allowing more flexibility in debt repayment strategies.