FLO-15: Fix incorrect linearization in fundsAvailableAboveTargetHealthAfterDepositing#284
Open
jordanschalm wants to merge 2 commits intobalance-sheet-health-statement-refactorfrom
Open
FLO-15: Fix incorrect linearization in fundsAvailableAboveTargetHealthAfterDepositing#284jordanschalm wants to merge 2 commits intobalance-sheet-health-statement-refactorfrom
fundsAvailableAboveTargetHealthAfterDepositing#284jordanschalm wants to merge 2 commits intobalance-sheet-health-statement-refactorfrom
Conversation
The shortcut in fundsAvailableAboveTargetHealthAfterDepositing incorrectly treats a same-type deposit as a simple additive offset. When the deposit flips a debit balance to credit, the first portion repays debt (scaled by 1/borrowFactor) while the excess becomes collateral (scaled by collateralFactor). With cf=0.8 and bf=1.0, this overestimates by 10 (returns 150 instead of 140). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove the incorrect shortcut in fundsAvailableAboveTargetHealthAfterDepositing that assumed depositing and withdrawing the same token is a simple additive offset. Instead, always compute the post-deposit true balance via trueBalanceAfterDelta, which correctly handles debt repayment vs collateral addition when a deposit flips a debit balance to credit. Also extract buildTokenSnapshot helper to deduplicate 6 identical TokenSnapshot constructor calls in FlowALPv0, and change FlowALPHealth.computeAvailableWithdrawal to accept a true balance directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Closes #224.
Extends #275 (review that first).
This PR:
buildTokenSnapshotto avoid inline construction of token snapshotsfundsAvailableAboveTargetHealthAfterDepositingto correctly handle same deposit/withdrawal types, by simulating the deposit on theBalancepassed to the underlying health calculation function.