Skip to content

FLO-5: Consistent behaviour in withdrawAndPull/depositAndPush#286

Open
jordanschalm wants to merge 15 commits intomainfrom
jord/flo-5
Open

FLO-5: Consistent behaviour in withdrawAndPull/depositAndPush#286
jordanschalm wants to merge 15 commits intomainfrom
jord/flo-5

Conversation

@jordanschalm
Copy link
Copy Markdown
Member

@jordanschalm jordanschalm commented Mar 20, 2026

Closes #214

Previously, withdrawAndPull only triggered the top-up source when health dropped below minHealth, while depositAndPush always rebalanced to targetHealth. This asymmetry left positions between minHealth and targetHealth without rebalancing. Now both operations consistently rebalance to targetHealth when their respective flags are set.

jordanschalm and others added 6 commits March 19, 2026 19:23
…rce is true

Previously, withdrawAndPull only triggered the top-up source when health
dropped below minHealth, while depositAndPush always rebalanced to
targetHealth. This asymmetry left positions between minHealth and
targetHealth without rebalancing. Now both operations consistently
rebalance to targetHealth when their respective flags are set.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move test_withdrawAndPull_rebalancesToTargetHealth into
rebalance_undercollateralised_test.cdc and add the symmetric
testDepositAndPush_rebalancesToTargetHealth to
rebalance_overcollateralised_test.cdc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…thinVariance

Update docstrings for withdrawAndPull and depositAndPush across
FlowALPv0, FlowALPPositionResources, and FlowALPModels to state that
the push/pull always occurs at withdraw/deposit time and always
attempts to restore targetHealth. Switch tests to equalWithinVariance
for rounding-safe comparisons.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…-source bug

Add 13 scenario tests covering all combinations of pull/push flags,
health thresholds, and source/sink availability. Move the two earlier
tests into the new file and remove them from the rebalance test files.

Fix bug where withdrawAndPull panicked when pullFromTopUpSource=true,
health was between minHealth and targetHealth, but no topUpSource was
configured. The withdrawal now succeeds since the position is still
above minHealth (best-effort semantics).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jordanschalm jordanschalm marked this pull request as ready for review March 23, 2026 16:43
@jordanschalm jordanschalm requested a review from a team as a code owner March 23, 2026 16:43
Copy link
Copy Markdown
Member

@holyfuchs holyfuchs left a comment

Choose a reason for hiding this comment

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

I think we can use this PR to clean this function up a bit.

The current implementation is using:
computationUsed (pull=true, no pull needed): 163
computationUsed (pull=true, pull executed): 199
computationUsed (pull=false): 128

The suggestion:
computationUsed (pull=true, no pull needed): 114
computationUsed (pull=true, pull executed): 136
computationUsed (pull=false): 64

effectively cutting execution used on pull=false by 50%.

@jordanschalm jordanschalm changed the base branch from main to balance-sheet-health-statement-refactor March 25, 2026 16:25
Base automatically changed from balance-sheet-health-statement-refactor to main April 6, 2026 15:30
jordanschalm and others added 2 commits April 6, 2026 08:31
…ype mismatch

- Add early returns for zero-amount deposit/withdrawal in FlowALPv0 to skip
  expensive TokenSnapshot construction when not needed
- Reuse pre-computed balance sheet in _rebalancePositionNoLock instead of
  redundantly calling _getUpdatedBalanceSheet via public wrapper functions
- Use buildTokenSnapshot helper instead of inlining snapshot construction
- Add missing variance argument to equalWithinVariance calls in
  withdraw_and_pull_deposit_and_push_test
- Fix capability type in create_position_no_connectors.cdc to match the
  EParticipant-only capability stored by grant_beta_cap

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

FLO-5: Inconsistent Flag Behavior: pullFromTopUpSource Bypasses Rebalancing While pushToDrawDownSink Forces It

2 participants