Skip to content

[midnight adapter] add bound on discount - #1271

Open
adhusson wants to merge 19 commits into
mainfrom
midnight-floor-discount
Open

adhusson wants to merge 19 commits into
mainfrom
midnight-floor-discount

Conversation

@adhusson

@adhusson adhusson commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

alternative to #1268

Addresses Sherlock #17.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T17:17:16.282346Z e4b7e4b New commits
🔒 Security Review ✅ Completed 2026-11-02T15:07:38.819519Z 5f8a5fc New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Preserve discount-floor accounting across the callback identifier renames and update the liveness spec to detect active buys by market id.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Fixed the liveness CI failure in 0d46b18. The counterexample started with an unconstrained inProgressBuyNetCredit = 2^255 + 4 even though the rule excludes an in-progress buy. onBuy clears both transient fields after accrual; the precondition now requires both to be zero, matching that state. No contract behavior changed in this fix.

verify (LivenessMidnightAdapter) and all 70 CI checks pass on 0d46b18.

albert-llimos and others added 7 commits November 1, 2026 21:17
…luation-only-shortfall-sell

# Conflicts:
#	src/adapters/MidnightAdapter.sol
#	src/adapters/interfaces/IMidnightAdapter.sol
#	test/MidnightAdapterTest.sol
Describe valuation in terms of future interest and shorten the error to
UnrecognizedInterestExceeded.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…luation-only-shortfall-sell

# Conflicts:
#	src/adapters/MidnightAdapter.sol
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 2, 2026

Copy link
Copy Markdown

PRO-318

Comment thread src/adapters/MidnightAdapter.sol Outdated
Comment on lines +607 to +610
maxUnrecognizedInterest =
MathLib.min(futureInterest, maxUnrecognizedInterest) + sellerAssets - soldNetCredit;
} else {
maxUnrecognizedInterest = maxUnrecognizedInterest + sellerAssets - soldNetCredit;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't like removing the explicit error (UnrecognizedInterestExceeded) in this commit. Reverting due do arithmetic error that is explicitly a mechanism protection is bad imo. This is what we currently have in main with ShortfallTooHigh().

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.

reverted

Comment thread src/adapters/MidnightAdapter.sol Resolved
(, uint256 futureInterest) = valuation(id, newNetCredit + soldNetCredit);
unrecognizedInterest = MathLib.min(futureInterest, maxUnrecognizedInterest);
} else {
unrecognizedInterest = maxUnrecognizedInterest;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't unrecognizedInterest be updated here if there is bad debt ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No update is needed in this branch. maxUnrecognizedInterest is a ceiling, not the live interest balance: valuation() reads loss-adjusted net credit, and realAssets() subtracts min(futureInterest, maxUnrecognizedInterest), so bad debt is reflected even if the ceiling is stale. A sale without a shortfall only adjusts the ceiling by sellerAssets - soldNetCredit; if a later sale has a shortfall, that branch recomputes the current futureInterest and clips the ceiling before using interest to cover the sale loss. Clipping on the no-shortfall path would require the extra full-market valuation without changing reported assets.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not very intuitive that it's not needed, here is my explanation in Slack.

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