Skip to content

[fallback rolling] max LTV - #1115

Open
peyha wants to merge 5 commits into
blue-fallback-rollingfrom
feat/max-ltv-fallback-rolling
Open

[fallback rolling] max LTV#1115
peyha wants to merge 5 commits into
blue-fallback-rollingfrom
feat/max-ltv-fallback-rolling

Conversation

@peyha

@peyha peyha commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Similarly as for Bundles, implement a max LTV. Rationale being

  • the incentive is taken as additional debt for the borrower so the rolling deteriorates the LTV of the position
  • liquidation is much harsher on blue than on midnight so a borrower close to insolvency would prefer staying on midnight instead of rolling

claude[bot]

This comment was marked as resolved.

Comment thread src/periphery/blue-fallback-rolling/BlueFallbackRolling.sol

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we say that one must use the fallback rolling only with a Blue market that has an LLTV equal or lower than the Midnight's LLTV (reasonable constrain imo), it means that they health is only improved by the rolling (minus the rolling incentive, but this is predictable and set by them). what is a situation where you would rather prevent the rolling (with requireMaxLTV) and be liquidated on Midnight post-maturity? because the LIF will be smaller on Midnight? the rolling incentive might change things as well (if you get rolled then liquidated on Blue, you have a implied LIF higher because of the incentive).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Was expecting the Blue market LLTV to be always equal to Midnight's LLTV thus the health would be (predictably) slightly worsen by the rolling and would continue worsening through time because of the interest accrual. Thought that we could have a LTV margin that would include these two elements (interest at the expected rate over some short period such as a month) and eventually the volatility of the collateral.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the question we should answer is: is there a setup in which you prefer to be liquidated on midnight's post maturity liquidation instead of being rolled on Blue? Maybe when 1) your LTV is so high that you will likely be liquidated soon on Blue, so you would rather be liquidated at a soft LIF on Midnight or 2) when the rolling incentive makes you close to be liquidated on Blue so same you prefer a soft liquidation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would expect 2) to be way less likely than 1) because the incentive should be computed such that it's minimal (just enough to cover the gas cost)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

about 2): interestingly, the rolling incentive should be in the order of magnitude of the midnight post-maturity effective LIF (assuming gas to liquidate ~= gas to roll on blue). Meaning that they cancel out => you want fallback rolling to keep your position open (in order to not pay tax for example), not to avoid paying the midnight LIF.

then it kind of invalidates 1), no? you would rather try it on blue, hope that you will not get liquidated, rather than staying on midnight and get liquidated?

@peyha peyha Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in the order of magnitude of the midnight post-maturity effective LIF

I don't think that it would be the case for large positions because the post-maturity effecitve LIF would take the swapping cost into account (which is usually a few bps in pool fees and possibly a few extra bps in price impact) while rolling is just the gas cost (which would be the same for all position size).
That's one of the reason why I think having an auction could be beneficial here, the incentive is currently in proportion of the debt but the gas cost isn't (and can be very volatile) so an auction could capture the relevant incentive more accurately

no? you would rather try it on blue, hope that you will not get liquidated

That's an interesting point and I'm honestly not sure how borrowers would behave. Suppose my LTV on midnight is quite high and I'm close to maturity, there are three possible paths

  1. I don't roll and I get liquidated post-maturity (small loss, taxable event trigger, will happen surely)
  2. I roll and I get liquidated on blue (larger loss, taxable event trigger, more likely to happen if my LTV is very close to LLTV)
  3. I roll and I don't get liquidated on blue
    I would guess I absolutely don't want 2) and 1) but if I know I am likely to have 2) I would prefer 1) and the max LTV could be set to ensure that

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@peyha peyha changed the title [blue buy callback] max LTV [Blue fallback rolling] max LTV Aug 3, 2026
@peyha peyha changed the title [Blue fallback rolling] max LTV [fallback rolling] max LTV Aug 3, 2026

@chrmatt chrmatt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Left some comments. Also, README probably should be updated?

How relevant is this PR after our discussion this morning?

Comment thread src/periphery/blue-fallback-rolling/BlueFallbackRolling.sol
InconsistentCollateralToken()
);

// Round in favor of the Midnight position.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not round in favor of Blue? Liquidations are worse on Blue, so it seems better to have more collateral there to avoid liquidation.

Comment thread src/periphery/blue-fallback-rolling/BlueFallbackRolling.sol Outdated
}

function testRollRevertsWhenMaxLtvExceeded() public {
uint256 tightMaxLtv = BLUE_LLTV / 2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure I understand the logic here. This might not always be tight if other numbers change? Wouldn't it be better to retrieve the actual LTV and then pick something tight based on the actual numbers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the position is collateralized very close to LLTV and then a smaller tightMaxLtv is used to raise the MaxLtvExceeded. It's just a small test for this error. We could also use actual numbers yes


/// @param incentive The caller incentive as a WAD-scaled percentage of the debt rolled.
function setConfig(bytes32 midnightId, bytes32 blueId, uint64 start, uint64 incentive, bool enabled)
function setConfig(bytes32 midnightId, bytes32 blueId, uint64 start, uint64 incentive, uint256 maxLtv, bool enabled)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think I understand how this works. Can there be multiple configs be valid at once? If so, can the one rolling a position choose which one to use? So if I want to set a stricter maxLtv, can the roller still use the old value unless I disable it (how?)? It would be more intuitive for me to just have a single config at every point in time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the current setting yes nothing prevents the user from setting multiple configs. The roller can use any enabled config but the user can also deactivate a config with setConfig setting enabled=False

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49cfe2cd4b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

function testRollRevertsWhenMaxLtvIsAboveLltv() public {
uint256 invalidMaxLtv = BLUE_LLTV;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use an actually above-LLTV value in this test

This test sets invalidMaxLtv equal to BLUE_LLTV, but roll only rejects values greater than blueMarketParams.lltv because the guard is maxLtv <= blueMarketParams.lltv; with the default setup this call proceeds past InvalidMaxLtv, so the test asserts the wrong boundary. Use BLUE_LLTV + 1 if the case is meant to cover values above LLTV.

AGENTS.md reference: AGENTS.md:L72-L79

Useful? React with 👍 / 👎.

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.

3 participants