function liquidateBorrower(address userAddress) external onlyManagerOrOwner nonReentrant whenNotPaused {
_update();
uint256 userDebt = lendingPool.getUserDebt(userAddress);
uint256 scaledUserDebt = WadRayMath.rayMul(userDebt, lendingPool.getNormalizedDebt());
lendingPool.updateState();
lendingPool.finalizeLiquidation(userAddress);
}
describe("Failing liquidation", function () {
beforeEach(async function () {
const depositAmount1 = ethers.parseEther("100");
const depositAmount2 = ethers.parseEther("100");
await crvusd.mint(user1.address, depositAmount1);
await crvusd.connect(user1).approve(lendingPool.target, depositAmount1);
await lendingPool.connect(user1).deposit(depositAmount1);
await rToken.connect(user1).approve(stabilityPool.target, depositAmount1);
await stabilityPool.connect(user1).deposit(depositAmount1);
await raacHousePrices.setHousePrice(1, ethers.parseEther("50"));
await crvusd.mint(user2.address, depositAmount2);
await crvusd.connect(user2).approve(raacNFT.target, depositAmount2);
await raacNFT.connect(user2).mint(1, ethers.parseEther("50"));
await raacNFT.connect(user2).approve(lendingPool.target, 1);
await lendingPool.connect(user2).depositNFT(1);
await crvusd.mint(stabilityPool.target, depositAmount1);
});
it("should fail liquidation", async function () {
await lendingPool.connect(user2).borrow(ethers.parseEther("40"));
await raacHousePrices.setHousePrice(1, ethers.parseEther("10"));
await lendingPool.connect(user1).initiateLiquidation(user2.address);
expect(await lendingPool.isUnderLiquidation(user2.address)).to.be.true;
await ethers.provider.send("evm_increaseTime", [72 * 60 * 60 + 1]);
await ethers.provider.send("evm_mine");
const userDebtBeforeUpdateState = await lendingPool.getUserDebt(user2.address);
await expect(stabilityPool.liquidateBorrower(user2.address)).to.be.revertedWithCustomError(crvusd, "ERC20InsufficientAllowance");
await lendingPool.updateState();
const userDebtAfterUpdateState = await lendingPool.getUserDebt(user2.address);
expect(userDebtAfterUpdateState).to.be.gt(userDebtBeforeUpdateState);
});
});
function liquidateBorrower(address userAddress) external onlyManagerOrOwner nonReentrant whenNotPaused {
_update();
+ lendingPool.updateState();
uint256 userDebt = lendingPool.getUserDebt(userAddress);
uint256 scaledUserDebt = WadRayMath.rayMul(userDebt, lendingPool.getNormalizedDebt());
// ... rest of function
- lendingPool.updateState();
lendingPool.finalizeLiquidation(userAddress);
}