Query in Decentralized Stable Coin - Liquidate Function #403
Replies: 6 comments 21 replies
-
I haven't gotten into that part of the course, but isn't the following line changing the HelathFactor?
At the start you're comparing |
Beta Was this translation helpful? Give feedback.
-
@shikhar229169 I agree with you, is better to move up the check to the top to follow CEI and don't allow a user with a broken health factor to enter the function and perform liquidations even though the tx will revert. |
Beta Was this translation helpful? Give feedback.
-
We are not modifying the health factor at this line, uint256 endingUserHealthFactor = _healthFactor(user); we are just querying final health factor. However the code seems to be missing a line to reduce the liquidators DSC balance too as we are burning his DSC without updating the s_DSCMinted mapping. The health factor would be changed after we burn liquidator's DSC but this line has to be there |
Beta Was this translation helpful? Give feedback.
-
Threshold: Company: Anybody who has any loan/credits and if whose balance/collateral ever goes below $100 then in case he/she is an undercollateralized (bad debt)..... ~ here for the sake of simplicity we are not calculating exact threshold(minimum deed against any breach).And for paying someone's loan/debts/outstandings company will give pay 10% of those debts/loan as a bonus/consideration to you. Now, You as a liquidator... 👍 ✅ Your balance = $170 (collateral) . ✅ After some time... ⌚ (Keep it in mind) 😏 you have... Me, me an undercollateralized(bad debt)....👎 ❌ My balance = $110 (collateral) . ✅ After some time... ⌚ You're agree to pay my debts out. And in consideration of it company will give you some bonus of 10% of payment, okay.After paying my debts... Reflections/affects would be .... You as a liquidator... Your balance = $40 (collateral) . (120 - 80)... Your credits = $50 (loan/outstandings). Me me an undercollateralized(bad debt).... My balance = $0 (collateral) . Lein Here company seized/lein/kinda forfeited.., my balance/collaterals. My loan/credits was of $80 dollars, So your share/bonus(more precise) would be: 10% of 80 => $8. So your updated affects...(affected ⚖️) _revertIfHealthFactorIsBroken(msg.sender); Your balance = $48 (collateral) . (40 + 8)... ❌ Oooohhhh heck...... You also went undercollateralized whilst paying my debts. 😈 Protocol Or logic will revert that whole transaction. |
Beta Was this translation helpful? Give feedback.
-
I agree, that the procedure of liquidation cannot make worse healthFactor of liquidator after successful liquidation of collateral (it can be easily only part of collateral) -> for gas efficiency we can raise call of function function liquidate(address collateral, address user, uint256 debtToCover) external moreThanZero(debtToCover) isAllowedToken(collateral) nonReentrant {
+ _revertIfHealthFactorIsBroken(msg.sender);
uint256 startHealthFactor = _healthFactor(user);
if (startHealthFactor >= MIN_HEALTH_FACTOR) {
revert DSCEngine__healthFactorIsNotBroken();
}
uint256 collateralAmountFromDebtCovered = getTokenAmountFromUSD(collateral, debtToCover);
uint256 bonusCollateral = (collateralAmountFromDebtCovered * LIQUIDATION_BONUS) / LIQUIDATION_PRECISION;
uint256 netCollateralAmount = collateralAmountFromDebtCovered + bonusCollateral;
_redeemCollateral(collateral, netCollateralAmount, user, msg.sender);
_burnDSC(user, msg.sender, debtToCover);
uint256 endingUserHealthFactor = _healthFactor(user);
if (endingUserHealthFactor <= startHealthFactor) {
revert DSCEngine__healthFactorNotImproved();
}
- _revertIfHealthFactorIsBroken(msg.sender);
} in this case, we check if liquidator health factor is good from the beginning without executing unnecessary transactions |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
In the liquidate function, the liquidator's health factor is being checked at the end, and if its below minimum health factor, we will revert this.
But I think that in the liquidation process, there is no effect on health factor of the liquidator, then why we need to check it?
Also, in case if the liquidator's health factor was broken before calling the liquidate function, then they can't liquidate anyone.
So, if it is a security measure to only allow those person to liquidate whose health factor is good, then we should consider checking it initially.
Feel free to post any suggestions for this, thanks.
Beta Was this translation helpful? Give feedback.
All reactions