Open
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ributions - Add HealthStatement struct for aggregate-only health summaries - Refactor BalanceSheet to store per-token effective collateral/debt maps - Add withUpdatedContributions method for immutable per-token updates - Fix sumUFix128 bug (missing .values on effectiveDebt map) - Update _getUpdatedBalanceSheet to build per-token maps - Update FlowALPHealth adjustment functions to use withUpdatedContributions - Bundle effectiveCollateral/effectiveDebt params into HealthStatement for computeRequiredDepositForHealth and computeAvailableWithdrawal Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… pattern Replace delta-based switch/case logic with a cleaner approach: 1. Compute post-withdrawal true balance via trueBalanceAfterWithdrawal helper 2. Compute new effective contribution from the resulting balance 3. Use withUpdatedContributions to build the new BalanceSheet The wrapper now constructs a TokenSnapshot instead of passing individual price/factor/index parameters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ttern Symmetric to the withdrawal refactor. Adds trueBalanceAfterDeposit helper. The wrapper now constructs a TokenSnapshot instead of passing individual price/factor/index parameters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…elpers
These ~40-line functions duplicated the adjustment logic. Now they
delegate to computeAdjustedBalancesAfter{Deposit,Withdrawal} and
return adjusted.health.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eAvailableWithdrawal Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ose it Renames the SignedQuantity struct to Balance (more natural name) and eliminates the redundant direction field from InternalBalance by making its scaledBalance field a Balance (direction + quantity) instead of a bare UFix128. The InternalBalance init signature is preserved to minimize churn at construction sites. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jordanschalm
commented
Mar 17, 2026
…Balance Consolidate the repeated switch-on-direction pattern in FlowALPHealth into two new methods that work with Balance directly, replacing the old withUpdatedContributions which took separate optional collateral/debt values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…terDelta Consolidate the two mirror-image functions into a single trueBalanceAfterDelta that accepts a Balance (direction + quantity) as the delta argument. Deposits pass a Credit delta, withdrawals pass a Debit delta. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The balance field was globally mutable -- this makes it only mutable through type-defined functions.
…trueBalance helper Add TokenSnapshot.trueBalance helper to deduplicate scaled→true balance conversion. Refactor computeRequiredDepositForHealth and computeAvailableWithdrawal from 8 params to 4 by accepting TokenSnapshot instead of individual scalars. Remove debug logging, rename variables to generic names, and rename balanceSheet→initialBalanceSheet. 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.
This PR refactors several functions and types related to health calculations, with the goal of reducing complexity and duplication.
Balancetype, representing a signed numeric valueBalancetype and handle both deposits and withdrawals.InternalBalancenow has aBalance-typed internal field. This field was changed to beaccess(self)(previously was globally mutable).BalanceSheet:HealthStatementis a summary of effective debt/collateral totals (equivalent toBalanceSheetstructure before)BalanceSheetnow includes a per-token accounting of effective debts and collaterals. This makes some health-related calculations much simpler, because we can isolate the effect of one token.