Skip to content

FLO-15: Fix incorrect linearization in fundsAvailableAboveTargetHealthAfterDepositing#284

Open
jordanschalm wants to merge 2 commits intobalance-sheet-health-statement-refactorfrom
jord/flo-15
Open

FLO-15: Fix incorrect linearization in fundsAvailableAboveTargetHealthAfterDepositing#284
jordanschalm wants to merge 2 commits intobalance-sheet-health-statement-refactorfrom
jord/flo-15

Conversation

@jordanschalm
Copy link
Copy Markdown
Member

Closes #224.

Extends #275 (review that first).

This PR:

  • Adds a test case for FLO-15
  • Adds buildTokenSnapshot to avoid inline construction of token snapshots
  • Modifies the implementation of fundsAvailableAboveTargetHealthAfterDepositing to correctly handle same deposit/withdrawal types, by simulating the deposit on the Balance passed to the underlying health calculation function.

jordanschalm and others added 2 commits March 19, 2026 10:56
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>
@jordanschalm jordanschalm requested a review from a team as a code owner March 19, 2026 20:47
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.

1 participant