Submitted by 0xStalin
Users can withdraw uncollateralized deposits even though their position is liquidable, as opposed to the README. If the position is in liquidation mode, users should use their uncollateralized deposits to avoid liquidation instead of removing them.
When withdrawing deposits from public pools, at the end of the tx is executed the WiseLending._healthStateCheck() function, which depending on the value of the powerFarmCheck will determine if the positions collateral is enough to cover the borrows.
When withdrawing an uncollateralized deposit, the WiseCore._coreWithdrawToken() function calls the WiseSecurity.checksWithdraw() function to determine the value of the powerFarmCheck. If the pool from where the tokens are being withdrawn is uncollateralized, the powerFarmCheck will be set to true, which will cause that the WiseLending._healthStateCheck() function uses the bare value of the full collateral to determine if the collateral can cover the existing borrows.
Using the bare value of the collateral does not accurately reflect if a position is liquidable or not, the liquidations logic in the WiseSecurity.checksLiquidation() function uses the weightedCollateral instead of the bareCollateral to determine if the position is liquidable or not. This difference to determine if the positions collateral can cover the borrows when withdrawing uncollateralized deposits and when doing liquidation causes a discrepancy to allow the withdrawal of uncollateralized deposits even though the position is in liquidation mode.
For example, a user requests a withdrawal of an uncollateralized deposit in a position with the below values:
WiseSecurity.sol:
Now, when using the same values but for a liquidation, we have that the weightedCollateral is not enough to cover the borrows; thus, the position is liquidable.
WiseSecurity.sol:
If the protocol wants to enforce that users use their uncollateralized deposits to avoid liquidations when the positions are liquidable, dont set to true the powerFarmCheck when doing withdrawals for uncollateralized deposits. Allow the WiseLending._healthStateCheck() function to validate if the position is indeed in liquidation mode by using the weightedCollateral instead of the bareCollateral value.
WiseSecurity.sol:
Context
vonMangoldt (Wise Lending) commented:
Wise Lending commented:
