Skip to content

Split FlowALPv0 further: extract health math and position resources#183

Open
liobrasil wants to merge 9 commits intomainfrom
liob/split-v0-health-position-resources
Open

Split FlowALPv0 further: extract health math and position resources#183
liobrasil wants to merge 9 commits intomainfrom
liob/split-v0-health-position-resources

Conversation

@liobrasil
Copy link
Contributor

Summary

  • extract health and balance-sheet math helpers into new FlowALPHealth contract
  • extract user-facing position resources into new FlowALPPositionResources contract
  • keep FlowALPv0 as the orchestration/entrypoint layer, delegating to extracted contracts
  • rewire rebalancer, transactions, and tests to use extracted position resource types
  • add new contract aliases in flow.json and deploy order updates in test helpers

Why

This continues Jordan split strategy by reducing FlowALPv0 surface area and isolating pure calculation logic from resource-wrapper logic while preserving behavior.

Validation

  • run_tests.sh
  • targeted health/position tests including funds_required_for_target_health_test and position_lifecycle_happy_test

Base automatically changed from jord/split-contracts to main February 26, 2026 23:11
liobrasil and others added 5 commits February 26, 2026 20:22
…ional

Add doc comments to all four public functions in FlowALPHealth following
the positionSatisfiesMinimumBalance doc style. Change interest index
parameters (withdrawCreditInterestIndex, depositDebitInterestIndex) to
optional types, passing nil when the balance direction doesn't match
instead of a dummy 1.0 value.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for adding this.

I verified that changes were move-only using the following diff commands against this commit (asked Claude to get the appropriate lines to diff on each branch):

diff -u -w <(git show origin/main:cadence/contracts/FlowALPv0.cdc | sed -n '650,709p') <(git show origin/liob/split-v0-health-position-resources:cadence/contracts/FlowALPHealth.cdc |
  sed -n '7,71p') | delta --side-by-side --file-style omit --line-fill-method ansi

  diff -u -w <(git show origin/main:cadence/contracts/FlowALPv0.cdc | sed -n '713,832p') <(git show origin/liob/split-v0-health-position-resources:cadence/contracts/FlowALPHealth.cdc |
  sed -n '75,190p') | delta --side-by-side --file-style omit --line-fill-method ansi

  diff -u -w <(git show origin/main:cadence/contracts/FlowALPv0.cdc | sed -n '890,966p') <(git show origin/liob/split-v0-health-position-resources:cadence/contracts/FlowALPHealth.cdc |
  sed -n '193,270p') | delta --side-by-side --file-style omit --line-fill-method ansi

  diff -u -w <(git show origin/main:cadence/contracts/FlowALPv0.cdc | sed -n '970,1072p') <(git show origin/liob/split-v0-health-position-resources:cadence/contracts/FlowALPHealth.cdc |
  sed -n '274,377p') | delta --side-by-side --file-style omit --line-fill-method ansi

diff -u -w <(git show origin/main:cadence/contracts/FlowALPv0.cdc | sed -n '2411,2658p') <(git show
  origin/liob/split-v0-health-position-resources:cadence/contracts/FlowALPPositionResources.cdc | sed -n '21,268p') | delta --side-by-side --file-style omit --line-fill-method
  ansi

diff -u -w <(git show origin/main:cadence/contracts/FlowALPv0.cdc | sed -n '2665,2709p') <(git show
  origin/liob/split-v0-health-position-resources:cadence/contracts/FlowALPPositionResources.cdc | sed -n '275,319p') | delta --side-by-side --file-style omit --line-fill-method
  ansi

I also added this follow-up which adds documentation to the FlowALPHealth functions: #185

@liobrasil liobrasil marked this pull request as ready for review March 3, 2026 17:25
@liobrasil liobrasil requested a review from a team as a code owner March 3, 2026 17:25
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.

2 participants