fix: persist extra interest overflow in deductFixedPositionDebt#167
Open
ricklista wants to merge 12 commits into
Open
fix: persist extra interest overflow in deductFixedPositionDebt#167ricklista wants to merge 12 commits into
ricklista wants to merge 12 commits into
Conversation
…al liquidation When partial liquidation deducts both interest and principal from a fixed position, the old code unconditionally reset interestRepaid=0 and lastRepaidTime=now. This erased any unpaid interest from position tracking, causing getUserTotalDebt() to under-report debt. The fix introduces three branches: 1. All interest covered -> safe to reset (unchanged behavior) 2. Partial interest + formula can represent outstanding -> adjust interestRepaid precisely so outstanding = accruedInterest - paidInterest (exact) 3. Partial interest + formula too small (most principal repaid) -> set interestRepaid=0 without resetting lastRepaidTime to maximize preserved outstanding Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add `redeemSmartCollateral` to allow BOT role to redeem smart collateral LP tokens via whitelisted SmartProviders. Add `batchSetSmartProviders` for MANAGER role to manage the provider whitelist.
…r shared impl Move RELAYER and ORACLE from constructor immutables to storage variables (appended at end of layout to preserve upgrade compatibility). This allows all LendingBroker proxies to share a single implementation deployment. - Constructor now only takes moolah address - initialize() accepts relayer and oracle as additional params - Added setRelayer() and setOracle() manager-only setters - Updated deploy scripts and all tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…-interest-tracking fix: preserve unpaid interest in deductFixedPositionDebt during partial liquidation
… functions - liquidateSmartCollateral: return actual seized (collAmount) and repaid (loanToken balance diff) instead of placeholder values - flashLiquidateSmartCollateral: capture repaidAssets from onMoolahLiquidate callback via _lastRepaidAssets storage
…event silent loss When liquidation reduces principal significantly, the interest formula (based on reduced principal) can no longer represent the full outstanding interest. Previously this overflow was silently lost. Now it is persisted in a fixedPositionExtraInterest mapping and included in all debt/interest calculations.
…xedPositionDebt When partial liquidation deducts only interest (no principal), extraInterest was preserved unchanged, causing interestRepaid to exceed formula-based accrued interest and triggering arithmetic underflow on subsequent reads.
…on on full liquidation - repay(): consume fixedPositionExtraInterest before increasing interestRepaid, preventing interestRepaid from exceeding formula-based accrued interest - _deductFixedPositionsDebt(): keep position alive when principalRepaid >= principal but extraInterest > 0, preventing silent loss of unpaid interest debt - Add unit tests for BrokerMath extraInterest edge cases - Add integration tests verifying extraInterest creation via partial liquidation, interest-only repay consumption, and position cleanup
c5205c0 to
f4a2e4a
Compare
2e7613d to
3d3d63c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BrokerMath.deductFixedPositionDebtL567 was silently lost.fixedPositionExtraInterestmapping (address => uint256 => uint256) toLendingBrokerto persist the overflow, and threaded it through all debt/interest calculation paths:getTotalDebt,peek,previewRepayFixedLoanPosition,refinanceMaturedFixedPositions,repay, andonMoolahLiquidate.fixedPositionExtraInterestentries on position removal and bad debt clearing.Test plan
BrokerMathDeductFixedTesttests pass (updated for new 4-param/4-return signature)LendingBrokertests pass