Submitted by pkqs90, also found by hearmen
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L624
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/PoolV3.sol#L529-L576
CDPVault.sol#liquidatePositionBadDebt() should not set profit = 0 when calling pool.repayCreditAccount(), as this would cause a loss of funds to lpETH stakers.
First we need to understand how liquidatePositionBadDebt() works. When there is a bad debt detected for a position, any liquidator can come and liquidate the position. The liquidator is required to buy ALL the collateral at a discount price, and the loss (totalDebt - repayAmount) is sent to PoolV3 to be beared by the lpETH stakers.
This is all good, but the issue here is that when the liquidator repays the debt, it is compared against the totalDebt of the position, which includes the interest. This interest should also be sent to the lpETH stakers, but is currently not, which would result in loss of funds for the lpETH stakers.
An example:
However, the issue here is, the liquidator also paid off 440 of debt interest, and is not sent to the StakingLPEth as profit. This means the 440 amount of underlying token (WETH) would be stuck in PoolV3, with no lpETH to redeem it.
Note that the current implementation is similar to GearboxV3. However, the profit concept is completely different, so it is incorrect for LoopFi.
CDPVault.sol:
PoolV3.sol:
In CDPVault, change to pool.repayCreditAccount(debtData.debt, debtData.accruedInterest, loss).
In PoolV3:
0xtj24 (LoopFi) confirmed
