Skip to content

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

Draft
liobrasil wants to merge 5 commits intomainfrom
liob/split-v0-health-position-resources
Draft

Split FlowALPv0 further: extract health math and position resources#183
liobrasil wants to merge 5 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
access(all) contract FlowALPHealth {

/// Computes effective collateral/debt after a hypothetical withdrawal.
access(all) fun computeAdjustedBalancesAfterWithdrawal(
Copy link
Member

Choose a reason for hiding this comment

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

The refactor removed explanatory documentation inline in the implementation. For example, this function removed these comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will restaure them all

Base automatically changed from jord/split-contracts to main February 26, 2026 23:11
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants