Repository navigation
[midnight adapter] proportional cross-market rate reduction - #1301
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ortional-rate-reduction
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
[midnight adapter] consumable shortfallAllowance instead of noSalesWithShortfall
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d5b995d74d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…no loss, as in realAssets" This reverts commit edd24b3.
Note
On main, when the Midnight adapter sells credit below its amortized value, only the sold market's rate absorbs the shortfall, and the sale reverts once that market's remaining interest runs out. #1084 lets other markets absorb it too, but one at a time in an order the allocator picks. This PR spreads the shortfall over all markets in proportion to each one's remaining interest, so every market's remaining interest drops by the same fraction and nobody has to choose an order. It's an alternative to #1084, branched from
main.Context
swapMarkets) felt unnatural. Proportional reduction was the alternative raised.realAssets(): markets without bad debt (lossFactor == 0) use their stored net credit, and markets with bad debt use their current net credit. The sale reverts withOtherSellInProgressif any other market has a sale in progress (liquidationLocked), since that market's stored net credit is stale until its ownonSellruns. Matured and zero-rate markets have no interest left, so they absorb nothing.Impact of merging
ShortfallTooHighwhen the shortfall is larger than the remaining interest of all markets combined.OtherSellInProgress. Nested sales at or above amortized value are unaffected.Sellno longer carries the rate. Each market whose rate changes emitsReduceRate(marketId, newRate)instead.Sellgains a last field,absorbedShortfall: the shortfall the markets absorbed, i.e. the increase of their amortized values asrealAssetscomputes them, which is what the sale consumed fromshortfallAllowance. It is at least the shortfall, and 0 for forceSellable sales and sales without a shortfall.Special things to note
marketIdstwice (up to 250), with alossFactorcall on each market (plusliquidationLockedandupdatePositionViewfor markets with bad debt). Sales with no shortfall skip the loop.amortizedValue * ttm / 1e18per market from the rate truncation.shortfallAllowanceis charged with that increase, measured with the same rounding asrealAssets, so it bounds exactly what the vault's valuation gains and repeated small sales cannot consume more than it. Each market's amortized value rounds down in the loop, as inrealAssets. A share never exceeds its market's interest, so no rate goes negative.MidnightAdapterFactoryis 23,748 B at runtime, 828 B under the EIP-170 limit (solc).Change outline
main, no parent PR.onSell: the first pass records each market's net credit and amortized value in twouint256[]and sums their interest. The second pass skips markets with no interest and applies each market's proportional share. The sold market goes through the samelossFactornet-credit path as the others.marketData.netCreditis updated before the loop.MarketIdsMidnightAdapter.spec: added NONDET summaries forliquidationLockedandupdatePositionView.Evidence
MidnightAdapterTestcover splits across 2–3 markets with the same interest-reduction fraction, markets with bad debt, full sales absorbed by other markets, force-sellable markets absorbing their share, nested shortfall sales reverting, matured markets, insufficient total interest, and the accounting ofrealAssets.MidnightAdapterTestpasses on adf7169 (288 tests, Solar build). Gas for a sale whose shortfall is spread over 1–250 markets is in this thread.forge build --sizespasses on adf7169. Certora wasn't run locally.Related: PRO-257
Link to Devin session: https://app.devin.ai/sessions/34b1025e5fb04ad5a530c4099c4d08b8
Open in Devin Desktop: https://app.devin.ai/desktop/session/34b1025e5fb04ad5a530c4099c4d08b8?variant=devin