Skip to content

Conversation

@holyfuchs
Copy link

Closes: #90

After reviewing PR #80, it became clear that the approach had some problems.
This PR aims to provide a cleaner and more maintainable solution.

Updated Rebalance Architecture

The core philosophy is decoupling: each component operates independently with the least privilege necessary.

The Supervisor is currently in the design phase (not yet implemented).

Key Principles

  • Isolation: FCM, Rebalancer, and Supervisor are fully independent.
  • Least Privilege: The Rebalancer can only trigger the rebalance function.
  • Resilience: The fixReschedule() call is idempotent and permissionless, ensuring the system can recover without complex auth.

Rebalancer variants

There are two rebalancer types; they behave the same for triggering rebalances.

Standard Rebalancer Paid Rebalancer
Who pays User pays Admin pays
Configuration User can set it Admin sets it
Use case User wants full autonomy Admin retains autonomy
Who can withdraw Only user Only user

The paid rebalancer is otherwise the same: it holds a rebalance capability and runs on the same schedule/trigger model; only who pays and who controls config differ.

creating a position

sequenceDiagram
    actor anyone
    participant FCMHelper as FCM<br/>Helper
    participant FCM
    participant AB as Rebalancer
    participant Supervisor
    anyone->>FCMHelper: createPosition()
    FCMHelper->>FCM: createPosition()
    FCMHelper->>AB: createRebalancer(rebalanceCapability)
    FCMHelper->>Supervisor: supervise(publicCapability)
Loading

while running

sequenceDiagram
    participant AB1 as AutoRebalancer1
    participant FCM
    participant AB2 as AutoRebalancer2
    participant SUP as Supervisor
    loop every x min
    AB1->>FCM: rebalance()
    end
    loop every y min
    AB2->>FCM: rebalance()
    end
    loop every z min
    SUP->>AB2: fixReschedule()
    SUP->>AB1: fixReschedule()
    end
Loading

- FlowCreditMarketRebalancerV1 and FlowCreditMarketRebalancerPaidV1 contracts
- RebalanceArchitecture.md with decoupled design and sequence diagrams
- Mocks (SimpleSinkSource), test helpers (test_helpers_rebalance.cdc) and auto_balance_test
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.

Copy over rebalancing logic from FYV to FCM

2 participants