During the entire liquidation process, the financial health of the liquidator will not undergo any changes.After the liquidation is completed, the financial health of the liquidator will be examined. If the liquidator's account balance is less than the health value, the entire transaction will be rolled back.I believe that even if the liquidator has a bad debt, they should still have the right to conduct liquidations.
function burn(uint256 _amount) public override onlyOwner {
- MockV3Aggregator(mockAggregator).updateAnswer(0);
uint256 balance = balanceOf(msg.sender);
if (_amount <= 0) {
revert DecentralizedStableCoin__AmountMustBeMoreThanZero();
}
if (balance < _amount) {
revert DecentralizedStableCoin__BurnAmountExceedsBalance();
}
super.burn(_amount);
}
function testRevertBecauseOfLiquidatorHealthFactor() public {
MockMoreDebtDSC mockDsc = new MockMoreDebtDSC(ethUsdPriceFeed);
tokenAddresses = [weth];
feedAddresses = [ethUsdPriceFeed];
address owner = msg.sender;
vm.prank(owner);
DSCEngine mockDsce = new DSCEngine(
tokenAddresses,
feedAddresses,
address(mockDsc)
);
mockDsc.transferOwnership(address(mockDsce));
vm.startPrank(user);
ERC20Mock(weth).approve(address(mockDsce), amountCollateral);
mockDsce.depositCollateralAndMintDsc(weth, amountCollateral, amountToMint);
vm.stopPrank();
collateralToCover = 1 ether;
ERC20Mock(weth).mint(liquidator, collateralToCover);
vm.startPrank(liquidator);
ERC20Mock(weth).approve(address(mockDsce), collateralToCover);
uint256 debtToCover = 10 ether;
mockDsce.depositCollateralAndMintDsc(weth, collateralToCover, amountToMint);
mockDsc.approve(address(mockDsce), debtToCover);
int256 ethUsdUpdatedPrice = 18e8;
MockV3Aggregator(ethUsdPriceFeed).updateAnswer(ethUsdUpdatedPrice);
vm.expectRevert(abi.encodeWithSelector(DSCEngine.DSCEngine__BreaksHealthFactor.selector, mockDsce.getHealthFactor(liquidator)));
mockDsce.liquidate(weth, user, debtToCover);
vm.stopPrank();
}
1.If the liquidator has bad debt, the liquidation process cannot be successfully executed
2.The liquidator cannot liquidate their own bad debt.