LLM Notice: This documentation site supports content negotiation for AI agents. Request any page with Accept: text/markdown or Accept: text/plain header to receive Markdown instead of HTML. Alternatively, append ?format=md to any URL. All markdown files are available at /md/ prefix paths. For all content in one file, visit /llms-full.txt
Skip to main content

Rebalancing Mechanics

Rebalancing is ALP's automated position management system that maintains positions within target health ranges. This powerful feature eliminates manual management and optimizes capital efficiency.

Understanding Rebalancing

What is Rebalancing?

Rebalancing is the automatic adjustment of a position's debt to maintain its health factor within a target range. When overcollateralized (HF > maxHealth), the system automatically borrows more. When undercollateralized (HF < minHealth), it automatically repays debt. When in range (minHealth ≤ HF ≤ maxHealth), no action is needed.

The goal is to keep positions at the target health factor (typically 1.3), maximizing capital efficiency while maintaining safety.


_15
graph LR
_15
subgraph "Health States"
_15
A[HF < 1.1<br/>Undercollateralized]
_15
B[HF: 1.1 - 1.5<br/>Healthy Range]
_15
C[HF > 1.5<br/>Overcollateralized]
_15
end
_15
_15
A -->|Auto-repay debt| Target[Target HF: 1.3]
_15
C -->|Auto-borrow more| Target
_15
B -.->|No action| B
_15
_15
style A fill:#fbb
_15
style B fill:#bfb
_15
style C fill:#bbf
_15
style Target fill:#bfb,stroke:#333,stroke-width:3px

Target Health Range

Each position has configurable health bounds:


_10
minHealth: 1.1 (minimum before rebalancing up)
_10
targetHealth: 1.3 (optimal target)
_10
maxHealth: 1.5 (maximum before rebalancing down)

Visual representation:


_10
0.0 ---- 1.0 ---- 1.1 ---- 1.3 ---- 1.5 ---- 2.0+
_10
| | | |
_10
Liquidation Min Target Max
_10
(Repay zone) (Borrow zone)

Rebalancing Decision Logic


_24
flowchart TD
_24
Start[Check Position Health] --> GetHF[Get Current HF]
_24
GetHF --> Check{HF vs Range?}
_24
_24
Check -->|HF < minHealth<br/>1.1| Low[Undercollateralized]
_24
Check -->|minHealth ≤ HF ≤ maxHealth<br/>1.1 - 1.5| Good[Healthy]
_24
Check -->|HF > maxHealth<br/>1.5| High[Overcollateralized]
_24
_24
Low --> CalcRepay[Calculate<br/>Required Repayment]
_24
CalcRepay --> PullFunds[Pull from<br/>TopUpSource]
_24
PullFunds --> Repay[Repay Debt]
_24
Repay --> Restored[HF = 1.3 ✓]
_24
_24
Good --> NoAction[No Action Needed]
_24
_24
High --> CalcBorrow[Calculate<br/>Additional Borrowable]
_24
CalcBorrow --> Borrow[Borrow MOET]
_24
Borrow --> PushFunds[Push to<br/>DrawDownSink]
_24
PushFunds --> Restored
_24
_24
style Low fill:#fbb
_24
style Good fill:#bfb
_24
style High fill:#bbf
_24
style Restored fill:#bfb,stroke:#333,stroke-width:3px

When Rebalancing Triggers

Automatic triggers occur when position health moves outside the min/max range, after deposits that cause overcollateralization, following price changes via oracle updates, and through scheduled checks by keepers or the protocol.

Manual triggers include user-forced rebalancing, protocol maintenance calls, and integration with external automation.

Overcollateralized Rebalancing

When It Occurs

Rebalancing down (borrowing more) happens when:


_10
Current Health Factor > maxHealth (1.5)

This means you have "excess" collateral that could be used to borrow more.

The Mathematics

The system calculates how much additional debt can be safely taken:


_12
Current State:
_12
- Effective collateral: EC
_12
- Effective debt: ED
_12
- Current health: HF = EC / ED
_12
- Target health: TH = 1.3
_12
_12
Additional borrowable amount:
_12
additionalBorrow = (EC / TH) - ED
_12
_12
New state after borrowing:
_12
- New debt: ED + additionalBorrow = EC / TH
_12
- New health: EC / (EC / TH) = TH ✓

See FCM Mathematical Foundations for detailed formulas and step-by-step derivations.

Overcollateralized Flow


_15
sequenceDiagram
_15
participant Position
_15
participant ALP
_15
participant DrawDownSink
_15
participant FYV
_15
_15
Position->>Position: Detect HF = 2.0<br/>(above max 1.5)
_15
Position->>ALP: Calculate additional borrow
_15
Note over ALP: (EC / 1.3) - ED<br/>= additional amount
_15
ALP->>ALP: Borrow 215.38 MOET
_15
ALP->>DrawDownSink: Push MOET
_15
DrawDownSink->>FYV: Deploy to yield
_15
Position->>Position: Health = 1.3 ✓
_15
_15
Note over Position,FYV: Automatic capital efficiency!

Example:


_14
Current State:
_14
- Collateral: 1000 FLOW @ $1 = $1000, factor 0.8 = $800 effective
_14
- Debt: 400 MOET @ $1 = $400
_14
- Health: 800 / 400 = 2.0 (above maxHealth of 1.5)
_14
_14
Calculation:
_14
- Target debt for HF=1.3: 800 / 1.3 ≈ 615.38 MOET
_14
- Additional borrow: 615.38 - 400 = 215.38 MOET
_14
_14
After Rebalancing:
_14
- Collateral: $800 effective (unchanged)
_14
- Debt: 615.38 MOET
_14
- Health: 800 / 615.38 = 1.3 ✓
_14
- User receives: 215.38 MOET via DrawDownSink

DrawDownSink Integration

When borrowing during rebalancing, funds are pushed to the DrawDownSink:


_12
graph LR
_12
Position[Position<br/>HF > 1.5] --> Calculate[Calculate<br/>Excess Capacity]
_12
Calculate --> Borrow[Borrow<br/>MOET]
_12
Borrow --> Sink[DrawDownSink]
_12
_12
Sink --> Wallet[User Wallet]
_12
Sink --> FYV[FYV Strategy]
_12
Sink --> LP[LP Pool]
_12
Sink --> Other[Other DeFi]
_12
_12
style Position fill:#bbf
_12
style Sink fill:#f9f,stroke:#333,stroke-width:2px

Benefits: Funds are automatically deployed to the user's wallet or DeFi strategy without requiring manual claims, ensuring seamless capital efficiency. The system can integrate with yield farms, LP pools, and other DeFi protocols.

Undercollateralized Rebalancing

When It Occurs

Rebalancing up (repaying debt) happens when:


_10
Current Health Factor < minHealth (1.1)

This means your position is approaching liquidation risk and needs debt reduction.

The Mathematics

The system calculates how much debt must be repaid:


_12
Current State:
_12
- Effective collateral: EC
_12
- Effective debt: ED
_12
- Current health: HF = EC / ED
_12
- Target health: TH = 1.3
_12
_12
Required repayment:
_12
requiredPaydown = ED - (EC / TH)
_12
_12
New state after repayment:
_12
- New debt: EC / TH
_12
- New health: EC / (EC / TH) = TH ✓

See FCM Mathematical Foundations for detailed formulas and proofs.

Undercollateralized Flow


_19
sequenceDiagram
_19
participant Price
_19
participant Position
_19
participant TopUpSource
_19
participant FYV
_19
participant ALP
_19
_19
Price->>Position: FLOW drops 20%
_19
Position->>Position: HF = 1.04<br/>(below min 1.1!)
_19
Position->>ALP: Calculate repayment needed
_19
Note over ALP: ED - (EC / 1.3)<br/>= repayment amount
_19
ALP->>TopUpSource: Request 123.07 MOET
_19
TopUpSource->>FYV: Withdraw from yield
_19
FYV->>TopUpSource: Provide MOET
_19
TopUpSource->>ALP: Supply MOET
_19
ALP->>ALP: Repay debt
_19
Position->>Position: Health = 1.3 ✓
_19
_19
Note over Price,Position: Automatic liquidation prevention!

Example:


_19
Initial State:
_19
- Collateral: 1000 FLOW @ $1 = $1000, factor 0.8 = $800 effective
_19
- Debt: 615.38 MOET
_19
- Health: 800 / 615.38 = 1.3
_19
_19
After FLOW Price Drops 20% to $0.80:
_19
- Collateral: 1000 FLOW @ $0.80 = $800, factor 0.8 = $640 effective
_19
- Debt: 615.38 MOET (unchanged)
_19
- Health: 640 / 615.38 = 1.04 (below minHealth of 1.1)
_19
_19
Calculation:
_19
- Target debt for HF=1.3: 640 / 1.3 ≈ 492.31 MOET
_19
- Required paydown: 615.38 - 492.31 = 123.07 MOET
_19
_19
After Rebalancing:
_19
- Collateral: $640 effective (unchanged)
_19
- Debt: 492.31 MOET
_19
- Health: 640 / 492.31 = 1.3 ✓
_19
- User paid: 123.07 MOET via TopUpSource

TopUpSource Integration

When repaying during rebalancing, funds are pulled from the TopUpSource:


_16
graph LR
_16
Position[Position<br/>HF < 1.1] --> Calculate[Calculate<br/>Repayment Needed]
_16
Calculate --> Request[Request<br/>MOET]
_16
Request --> Source[TopUpSource]
_16
_16
Wallet[User Wallet] --> Source
_16
FYV[FYV Strategy] --> Source
_16
LP[LP Pool] --> Source
_16
Other[Other DeFi] --> Source
_16
_16
Source --> Repay[Repay<br/>Debt]
_16
Repay --> Safe[HF = 1.3 ✓]
_16
_16
style Position fill:#fbb
_16
style Source fill:#f9f,stroke:#333,stroke-width:2px
_16
style Safe fill:#bfb

Benefits: The TopUpSource integration provides automatic liquidation protection without requiring manual monitoring. Funds are sourced from the user's chosen location and can integrate with yield farms to automatically exit positions when needed.

FCM's Innovation

When TopUpSource is connected to FYV, your yield automatically protects your position from liquidation. This is the core innovation of Flow Credit Market!

Rebalancing Scenarios

Scenario 1: Initial Position with Auto-Borrow


_17
sequenceDiagram
_17
participant User
_17
participant ALP
_17
participant Position
_17
participant DrawDownSink
_17
_17
User->>ALP: Deposit 1000 FLOW<br/>pushToDrawDownSink=true
_17
ALP->>Position: Create position
_17
Position->>Position: Initial HF = ∞<br/>(no debt yet)
_17
Position->>Position: Detect HF > max (1.5)
_17
Position->>Position: Calculate: 800/1.3 = 615.38
_17
Position->>Position: Auto-borrow 615.38 MOET
_17
Position->>DrawDownSink: Push MOET
_17
DrawDownSink->>User: Funds deployed
_17
Position->>Position: Final HF = 1.3 ✓
_17
_17
Note over User,DrawDownSink: Immediate auto-optimization!

What happens:

  1. Initial health: Infinite (no debt)
  2. System detects health > maxHealth
  3. Calculates borrowable: 800 / 1.3 ≈ 615.38 MOET
  4. Auto-borrows 615.38 MOET
  5. Pushes to DrawDownSink
  6. Final health: 1.3 ✓

Scenario 2: Price Increase Creates Opportunity


_12
graph TD
_12
Start[Initial State<br/>1000 FLOW @ $1<br/>Debt: 615 MOET<br/>HF: 1.3] --> PriceUp[FLOW → $1.25]
_12
PriceUp --> NewState[New Collateral: $1000<br/>Debt: 615 MOET<br/>HF: 1.625]
_12
NewState --> Detect[HF > maxHealth!]
_12
Detect --> Calc[Target Debt:<br/>1000 / 1.3 = 769 MOET]
_12
Calc --> Borrow[Borrow Additional:<br/>769 - 615 = 154 MOET]
_12
Borrow --> Push[Push to DrawDownSink]
_12
Push --> Final[Final HF: 1.3 ✓]
_12
_12
style Start fill:#bbf
_12
style NewState fill:#bfb
_12
style Final fill:#bfb

Example:


_13
Initial: 1000 FLOW @ $1, debt 615.38 MOET, health 1.3
_13
FLOW price increases to $1.25
_13
_13
New state:
_13
- Collateral: 1000 FLOW @ $1.25 = $1250, factor 0.8 = $1000 effective
_13
- Debt: 615.38 MOET
_13
- Health: 1000 / 615.38 = 1.625 (above maxHealth)
_13
_13
Rebalancing triggers:
_13
- Target debt: 1000 / 1.3 ≈ 769.23 MOET
_13
- Additional borrow: 769.23 - 615.38 = 153.85 MOET
_13
- User receives: 153.85 MOET via DrawDownSink
_13
- New health: 1.3 ✓

Scenario 3: Price Decrease Requires Repayment


_12
graph TD
_12
Start[Initial State<br/>1000 FLOW @ $1<br/>Debt: 615 MOET<br/>HF: 1.3] --> PriceDown[FLOW → $0.80]
_12
PriceDown --> NewState[New Collateral: $640<br/>Debt: 615 MOET<br/>HF: 1.04]
_12
NewState --> Detect[HF < minHealth!]
_12
Detect --> Calc[Target Debt:<br/>640 / 1.3 = 492 MOET]
_12
Calc --> Repay[Repay:<br/>615 - 492 = 123 MOET]
_12
Repay --> Pull[Pull from TopUpSource]
_12
Pull --> Final[Final HF: 1.3 ✓]
_12
_12
style Start fill:#bbf
_12
style NewState fill:#fbb
_12
style Final fill:#bfb

Example:


_13
Initial: 1000 FLOW @ $1, debt 615.38 MOET, health 1.3
_13
FLOW price decreases to $0.80
_13
_13
New state:
_13
- Collateral: 1000 FLOW @ $0.80 = $800, factor 0.8 = $640 effective
_13
- Debt: 615.38 MOET
_13
- Health: 640 / 615.38 = 1.04 (below minHealth)
_13
_13
Rebalancing triggers:
_13
- Target debt: 640 / 1.3 ≈ 492.31 MOET
_13
- Required repayment: 615.38 - 492.31 = 123.07 MOET
_13
- System pulls: 123.07 MOET from TopUpSource
_13
- New health: 1.3 ✓

Scenario 4: Interest Accrual Over Time


_11
graph LR
_11
Start[Initial<br/>HF: 1.3] --> Time[6 Months<br/>10% APY]
_11
Time --> Interest[Interest Accrues<br/>Debt ↑ 5%]
_11
Interest --> Check{HF < 1.1?}
_11
Check -->|Yes| Trigger[Trigger<br/>Rebalancing]
_11
Check -->|No| Monitor[Continue<br/>Monitoring]
_11
Trigger --> Repay[Repay from<br/>TopUpSource]
_11
Repay --> Restored[HF = 1.3 ✓]
_11
_11
style Interest fill:#ffa
_11
style Restored fill:#bfb

Example:


_12
Initial: 1000 FLOW @ $1, debt 615.38 MOET, health 1.3
_12
After 6 months at 10% APY:
_12
_12
New state:
_12
- Collateral: $800 effective (unchanged)
_12
- Debt: 615.38 * 1.05 ≈ 646.15 MOET (5% accrued interest)
_12
- Health: 800 / 646.15 = 1.238 (approaching minHealth)
_12
_12
If health drops below 1.1:
_12
- Rebalancing triggers
_12
- Repays enough to restore health to 1.3
_12
- Funds pulled from TopUpSource

Rebalancing Strategies

Strategy Comparison


_17
graph TD
_17
subgraph Conservative
_17
C1[minHealth: 1.2<br/>target: 1.5<br/>maxHealth: 2.0]
_17
C2[✅ Stable<br/>✅ Low gas<br/>❌ Low efficiency]
_17
end
_17
_17
subgraph Balanced
_17
B1[minHealth: 1.1<br/>target: 1.3<br/>maxHealth: 1.5]
_17
B2[✅ Efficient<br/>✅ Reasonable gas<br/>✅ Good safety]
_17
end
_17
_17
subgraph Aggressive
_17
A1[minHealth: 1.1<br/>target: 1.2<br/>maxHealth: 1.3]
_17
A2[✅ Max efficiency<br/>❌ High gas<br/>❌ Risky]
_17
end
_17
_17
style Balanced fill:#bfb,stroke:#333,stroke-width:3px

Conservative Strategy

Configuration:


_10
minHealth: 1.2
_10
targetHealth: 1.5
_10
maxHealth: 2.0

Characteristics: Conservative strategy offers less frequent rebalancing, lower gas costs, more stable positions, and a buffer against volatility. However, it results in lower capital efficiency and less borrowed funds.

Best for: Risk-averse users, volatile collateral, learning the system

Configuration:


_10
minHealth: 1.1
_10
targetHealth: 1.3
_10
maxHealth: 1.5

Characteristics: Balanced strategy provides good capital efficiency, reasonable rebalancing frequency, balanced risk/reward ratios, and serves as the standard configuration.

Best for: Most users, general purpose lending

This is the default and most common configuration.

Aggressive Strategy

Configuration:


_10
minHealth: 1.1
_10
targetHealth: 1.2
_10
maxHealth: 1.3

Characteristics: Aggressive strategy offers maximum capital efficiency, more borrowed funds, and higher yield potential. However, it requires frequent rebalancing, incurs higher gas costs, is more sensitive to volatility, and requires a reliable TopUpSource.

Best for: Experienced users, stable collateral, maximum leverage

Important

Aggressive strategy requires reliable TopUpSource with sufficient liquidity. If TopUpSource runs dry during a price drop, liquidation risk increases significantly!

Helper Functions for Rebalancing

ALP provides two key functions to check rebalancing status:

Checking Borrowable Amount

Purpose: See how much can be borrowed without triggering rebalancing

Formula: (effectiveCollateral / targetHealth) - effectiveDebt

Returns: Amount that can be borrowed while maintaining target health (0 if already at/below target)

Checking Required Repayment

Purpose: See how much must be repaid to restore health

Formula: effectiveDebt - (effectiveCollateral / targetHealth)

Returns: Amount that must be repaid to reach target health (0 if already at/above target)

For Developers

_11
// Check borrowable amount above target health
_11
let available = position.fundsAvailableAboveTargetHealth()
_11
if available > 0.0 {
_11
// Can borrow 'available' amount without triggering rebalancing
_11
}
_11
_11
// Check required repayment for target health
_11
let required = position.fundsRequiredForTargetHealth()
_11
if required > 0.0 {
_11
// Must repay 'required' amount to restore health
_11
}

See GitHub for complete API documentation.

Manual vs Automatic Rebalancing


_13
graph TB
_13
subgraph Automatic
_13
A1[DrawDownSink<br/>Configured] --> A2[TopUpSource<br/>Configured]
_13
A2 --> A3[✅ Auto-borrow<br/>✅ Auto-repay<br/>✅ Hands-free]
_13
end
_13
_13
subgraph Manual
_13
M1[User Monitors<br/>Health] --> M2[User Triggers<br/>Rebalance]
_13
M2 --> M3[❌ Manual work<br/>✅ Full control<br/>⚠️ Risk if delayed]
_13
end
_13
_13
style Automatic fill:#bfb
_13
style Manual fill:#bbf

Automatic Rebalancing

Advantages: Automatic rebalancing requires no user intervention, maintains optimal capital efficiency, provides protection against liquidation, and enables integration with DeFi strategies.

Requirements: To enable automatic rebalancing, you must configure DrawDownSink for borrowing and TopUpSource for repayment, ensure sufficient funds in TopUpSource, and set up proper automation (keepers or protocol).

Manual Rebalancing

When to use: Manual rebalancing is suitable for testing and learning, conservative management approaches, situations where manual control is preferred, and complex strategy execution.

Process:

  1. Monitor position health factor regularly
  2. Detect when health moves outside range
  3. Manually trigger rebalancing
  4. Verify new health factor

Rebalancing Best Practices

Setup

  1. Configure both Sink and Source: Ensures full automation
  2. Test with small amounts: Verify rebalancing works as expected
  3. Monitor initial rebalancing: Watch first few cycles
  4. Fund TopUpSource adequately: Ensure sufficient repayment capacity

Monitoring

  1. Track rebalancing events: Log when rebalancing occurs
  2. Monitor gas costs: Frequent rebalancing costs gas
  3. Watch health factor trends: Identify patterns
  4. Alert on failures: Know if TopUpSource runs dry

Optimization

  1. Adjust health ranges: Based on volatility and strategy
  2. Choose appropriate tokens: Stable collateral = less rebalancing
  3. Balance efficiency vs stability: Find your risk tolerance
  4. Consider timing: Some times have better gas prices

Risk Management

  1. Ensure TopUpSource liquidity: Always have funds available
  2. Monitor collateral prices: Know when to add collateral manually
  3. Have backup plans: What if automation fails?
  4. Regular health checks: Even with automation, monitor positions

Troubleshooting Rebalancing

Rebalancing Not Triggering


_11
graph TD
_11
Issue[Rebalancing<br/>Not Triggering] --> Check1{Health in<br/>range?}
_11
Check1 -->|Yes| OK[Working as<br/>intended]
_11
Check1 -->|No| Check2{Sink/Source<br/>configured?}
_11
Check2 -->|No| Fix1[Configure<br/>Sink/Source]
_11
Check2 -->|Yes| Check3{Funds in<br/>Source?}
_11
Check3 -->|No| Fix2[Add funds to<br/>TopUpSource]
_11
Check3 -->|Yes| Fix3[Manual trigger<br/>force=true]
_11
_11
style Issue fill:#fbb
_11
style OK fill:#bfb

Possible causes:

  1. Health within min/max range (working as intended)
  2. DrawDownSink not configured
  3. TopUpSource not configured or empty
  4. Automation not running

Solutions: Verify the health factor is outside the target range, check Sink/Source configuration, ensure sufficient funds in Source, and manually trigger with force: true if needed.

Rebalancing Fails

Possible causes:

  1. TopUpSource has insufficient funds
  2. Oracle price stale or unavailable
  3. Gas limit exceeded
  4. Smart contract error

Solutions: Add funds to TopUpSource, wait for fresh oracle updates, increase the gas limit, and check contract logs for specific errors.

Excessive Rebalancing

Possible causes:

  1. Health range too narrow
  2. Highly volatile collateral
  3. Oracle price updates too frequent

Solutions: Widen the health range (increase maxHealth - minHealth), use more stable collateral, adjust target health to the middle of the range, and consider switching to a conservative strategy.

Summary

Rebalancing Mechanics:

  • 📊 Maintains health factor in target range (1.1 - 1.5)
  • 🔄 Automatic borrowing when overcollateralized (HF > 1.5)
  • 🛡️ Automatic repayment when undercollateralized (HF < 1.1)
  • 🎯 Targets optimal health factor (1.3)

Key Integrations:

  • DrawDownSink: Where borrowed funds go (overcollateralized)
  • TopUpSource: Where repayment funds come from (undercollateralized)
  • DeFi Actions: Framework enabling automated flows

Strategy Selection:

  • Conservative: Wide range (1.2-2.0), stable, low efficiency
  • Balanced: Moderate range (1.1-1.5), recommended for most
  • Aggressive: Narrow range (1.1-1.3), risky, max efficiency

Best Practices:

  • Configure both Sink and Source for full automation
  • Ensure TopUpSource has sufficient liquidity
  • Monitor rebalancing events and health trends
  • Choose strategy based on collateral volatility

Mathematical Foundation

For detailed rebalancing formulas and calculations:

Next Steps


Key Takeaway

Rebalancing is ALP's secret weapon for capital efficiency. By automatically adjusting debt based on collateral value changes, it keeps positions optimized while protecting against liquidation. Combined with FYV as TopUpSource, you get truly hands-free DeFi lending!