Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIF and LTV restrictions #77

Merged
merged 10 commits into from
Oct 7, 2024
Merged

LIF and LTV restrictions #77

merged 10 commits into from
Oct 7, 2024

Conversation

QGarchery
Copy link
Contributor

@QGarchery QGarchery commented Oct 4, 2024

The lemma 2.2.1 of the yellow paper states if LTV < 1 / LIF then the position gets healthier after a liquidation.
In case of pre-liquidations, the case of interest is LTV < LLTV (after is the range of liquidations). So we want LTV < LLTV => LTV < 1 / LIF, which is equivalent to saying LLTV <= 1 / LIF, which is equivalent to LIF <= 1 / LLTV.

In this PR, the choice was made to:

  • bound preLIF2 for simplicity, which implies that we have the bound on preLIF
  • only allow pre-liquidations if the position is not liquidatable

Todo:

  • add a test for the reverting case of preLIF2
  • add a test for the reverting case when the position is liquidatable

@QGarchery QGarchery self-assigned this Oct 4, 2024
Base automatically changed from style/constructor-readability to main October 4, 2024 15:04
@MathisGD MathisGD mentioned this pull request Oct 4, 2024
src/PreLiquidation.sol Show resolved Hide resolved
src/PreLiquidation.sol Outdated Show resolved Hide resolved
src/PreLiquidation.sol Outdated Show resolved Hide resolved
src/PreLiquidation.sol Show resolved Hide resolved
src/PreLiquidation.sol Show resolved Hide resolved
Copy link

@adhusson adhusson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only allow pre-liquidations if the position is not liquidatable

Not clear to me why. I think it makes the scenario where the is user pays a third-party to liquidate them more complex: now the third-party has to send a different tx at the liquidatable/not-liquidatable threshold.

@QGarchery
Copy link
Contributor Author

Not clear to me why.

The idea was to make sure that the invariant "position gets better after a pre-liquidation" holds. With LIF < 1 / LLTV this requires that LTV < LLTV. But maybe you think it's ok to not care much about what happens if LTV > LLTV ?

I think it makes the scenario where the is user pays a third-party to liquidate them more complex: now the third-party has to send a different tx at the liquidatable/not-liquidatable threshold.

I actually think that it makes it easier for liquidators, because:

  • before this PR there was already a threshold that makes pre-liquidations revert, because they make the position unhealthy. So liquidators would have had to handle that threshold, and use the liquidation on Morpho directly if above it, but that threshold is less clear (whereas in this PR the threshold is LLTV);
  • additionally, before this PR, efficient liquidators would have had to handle the case where a given position is eligible for both a pre-liquidation and a liquidation, but this is not the case after this PR

@adhusson
Copy link

adhusson commented Oct 5, 2024

Agree that with the constraint you go from "healthy pre-liquidated positions improve" to "pre-liquidated position improve" but it only seems useful for a preLIF2 a user would not opt into. When preLIF2 <= 1/(1-cursor *(1-LLTV) isn't it always better for the user to be pre-liquidated?

Or there is still a threshold to take into account that I missed? If not then for cheap pre-liquidation providers, or those paid out-of-band (not through LIF), this change creates an additional case to take into account. Since pre-liquidations are opt-in, it seems better to have a smooth usecase for configurations that always improve on the built-in liquidation.

@QGarchery
Copy link
Contributor Author

When preLIF2 <= 1/(1-cursor *(1-LLTV) isn't it always better for the user to be pre-liquidated?

I agree. But it seems like there would be some use case for a preLIF2 greater than the LIF on Morpho, because you could also have lower than 1 pre-liquidation close factor.

Or there is still a threshold to take into account that I missed?

Pre-liquidations do a withdraw collateral on Morpho, so they have to leave the position healthy. If they don't then they revert, so this is a threshold that was there before and is removed with this PR (even though we add another one).

If not then for cheap pre-liquidation providers, or those paid out-of-band (not through LIF), this change creates an additional case to take into account.

I'm not sure to get what you mean by "cheap pre-liquidation providers", or what you mean by "[not paid] through LIF"

colin-morpho
colin-morpho previously approved these changes Oct 6, 2024
Copy link
Contributor

@colin-morpho colin-morpho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm convinced. I think the key point is making explicit that leaving unhealthy positions is not possible with this contract because there's an underlying withdrawCollateral. Not handling (understand refusing) operations that are out of the scope of this contract could be confusing from a user point of view. If we want to support other usages maybe we need other contracts tailored for this purpose.

src/PreLiquidation.sol Outdated Show resolved Hide resolved
peyha
peyha previously approved these changes Oct 6, 2024
src/PreLiquidation.sol Outdated Show resolved Hide resolved
MathisGD
MathisGD previously approved these changes Oct 6, 2024
@MathisGD MathisGD linked an issue Oct 6, 2024 that may be closed by this pull request
@QGarchery QGarchery dismissed stale reviews from peyha and colin-morpho via 525cfdf October 6, 2024 16:05
colin-morpho
colin-morpho previously approved these changes Oct 6, 2024
@QGarchery QGarchery changed the title LIF restriction LIF and LTV restrictions Oct 6, 2024
@adhusson
Copy link

adhusson commented Oct 6, 2024

Pre-liquidations do a withdraw collateral on Morpho, so they have to leave the position healthy.

Forgot about this, so there is no scenario that looks like "with the right preLIF2 preliquidating always works", you always have to consider liquidation as an alternative. Thank you!

@peyha peyha self-requested a review October 7, 2024 07:14
@MathisGD MathisGD merged commit 3ce8ed3 into main Oct 7, 2024
4 checks passed
@MathisGD MathisGD deleted the feat/lif-restriction branch October 7, 2024 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

preLIF too high
5 participants