Submitted by ladboy233, also found by rvierdiiev
When user has bad debt, users borrow credit > collateral credit. Liqudiator can step in and liquidate and seize users share or seize user WLP and repay the debt.
While the liquidate function aims to let liqudiator take the min share available for bad debt repayment.
After the users pool share is transferred out, or after users WLP is seized, the rest of unpaid debt becomes bad debt permanently. For example, users borrow 1000 USDT and has debt 1000 USDT. His share is only worth 500 USD as collateral price drops. Because the code lets liquidator take min of whats available for both lending pool share and take min of whats available (for bad debt repayment) for WLP amount. The liqudiator can repay 800 USD and seize share of 500 USD. However, there are 200 USD remaining debt. When other liquidators (even this liquidator belongs to protocol) writes to repay and erase the rest 200 USD bad debt, he cannot because removeCollateralTo validates share > 0, if share is 0, revert.
If the underlying collateral is WLP, the second liquidation aims to write off bad debt does not work as well because if all WLP is transfered out, calling _harvest and unwrap again is likely to revert.
The bad permanently inflates the totalAssets() in lending pool and inflates the total debt to not let other users borrow from protocol because of the borrow cap checks.
Also, the lender suffers the loss because if the bad debt is not repaid, the lender that deposit cash into the lending pool is lost.
Add a way to handle not fully repaid bad debt after liquidation after the lending pool share or WLP is fully seized.
Add a function to donate to the lending pool to let user supply asset or add a function to socialize the bad debt as loss explicilty.
fez-init (INIT) confirmed
