Mathematical Foundations of FCM
This document explains the mathematical models and formulas that power Flow Credit Market. Understanding these fundamentals helps you reason about system behavior and make informed decisions.
Core Variables
Token-Level Variables
| Variable | Symbol | Description |
|---|---|---|
| Price | $P_t$ | Price of token $t$ in MOET terms |
| Collateral Factor | $CF_t$ | Usable percentage of token $t$ value (0 < $CF_t$ ≤ 1) |
| Borrow Factor | $BF_t$ | Multiplier for borrowed token $t$ (typically 1.0) |
| Amount | $A_t$ | Quantity of token $t$ |
Position-Level Variables
| Variable | Symbol | Description |
|---|---|---|
| Effective Collateral | $EC$ | Total usable collateral value in MOET |
| Effective Debt | $ED$ | Total debt value in MOET |
| Health Factor | $HF$ | Ratio of collateral to debt |
| Target Health | $HF_target$ | Desired health ratio (typically 1.3) |
| Min Health | $HF_min$ | Minimum before rebalancing (typically 1.1) |
| Max Health | $HF_max$ | Maximum before rebalancing (typically 1.5) |
Interest Variables
| Variable | Symbol | Description |
|---|---|---|
| Interest Index | $I_t(n)$ | Interest index for token $t$ at time $n$ |
| Scaled Balance | $B_scaled$ | Balance divided by interest index |
| True Balance | $B_true$ | Actual balance including accrued interest |
| Interest Rate | $r$ | Annual interest rate |
Fundamental Formulas
1. Effective Collateral
The effective collateral is the sum of all collateral assets multiplied by their prices and collateral factors:
_10EC = ∑(A_t × P_t × CF_t) for all t in Collateral
Example:
_10Collateral assets:_10- 1000 FLOW @ $1 each, CF = 0.8_10- 500 USDC @ $1 each, CF = 0.9_10_10EC = (1000 × 1 × 0.8) + (500 × 1 × 0.9)_10 = 800 + 450_10 = $1250 MOET
2. Effective Debt
The effective debt is the sum of all borrowed assets multiplied by their prices and borrow factors:
_10ED = \sum_t \in Debt A_t × P_t × BF_t
Example:
_10Debt:_10- 800 MOET @ $1 each, BF = 1.0_10_10ED = 800 × 1 × 1.0_10 = $800 MOET
3. Health Factor
The health factor is the ratio of effective collateral to effective debt:
_10HF = (EC / ED)
Critical thresholds:
- $HF < 1.0$: Position is liquidatable
- $HF = 1.0$: Exactly at liquidation threshold
- $HF > 1.0$: Position is solvent
Example:
_10EC = $1250, ED = $800_10_10HF = 1250 / 800 = 1.5625
4. Maximum Borrowing Capacity
The maximum amount that can be borrowed to reach target health:
_10MaxBorrow = (EC / HF_target)
Derivation:
_10We want: HF = EC / ED = HF_target_10Therefore: ED = EC / HF_target
Example:
_10EC = $1250_10HF_target = 1.3_10_10Max Borrow = 1250 / 1.3 = $961.54 MOET
Auto-Borrowing Mathematics
Initial Auto-Borrow Amount
When a user deposits collateral with pushToDrawDownSink=true, the system calculates the initial borrow amount:
_10BorrowAmount = (EC / HF_target)
Step-by-step calculation:
- Calculate effective collateral:
_10 EC = A_collateral × P_collateral × CF_collateral
- Calculate target debt:
_10 ED_target = (EC / HF_target)
- Borrow to reach target:
_10 Borrow = ED_target = (EC / HF_target)
Complete example:
_15User deposits: 1000 FLOW_15FLOW price: $1.00_15Collateral factor: 0.8_15Target health: 1.3_15_15Step 1: EC = 1000 × 1.00 × 0.8 = $800_15_15Step 2: ED_target = 800 / 1.3 = $615.38_15_15Step 3: Borrow = $615.38 MOET_15_15Result:_15- Collateral: 1000 FLOW ($800 effective)_15- Debt: 615.38 MOET_15- Health: 800 / 615.38 = 1.30 ✓
Rebalancing Mathematics
Overcollateralized Rebalancing (HF > HF_max)
When health exceeds maximum, calculate additional borrowing capacity:
_10AdditionalBorrow = (EC / HF_target) - ED_current
Proof:
_10Want: HF_new = HF_target_10HF_new = EC / ED_new = HF_target_10ED_new = EC / HF_target_10_10Additional borrow = ED_new - ED_current_10 = (EC / HF_target) - ED_current
Example:
_13Current state:_13- EC = $800_13- ED = $400_13- HF = 800 / 400 = 2.0 (> HF_max of 1.5)_13_13Calculate additional borrow:_13ED_target = 800 / 1.3 = $615.38_13Additional = 615.38 - 400 = $215.38 MOET_13_13After borrowing $215.38:_13- EC = $800 (unchanged)_13- ED = $615.38_13- HF = 800 / 615.38 = 1.30 ✓
Undercollateralized Rebalancing (HF < HF_min)
When health falls below minimum, calculate required repayment:
_10RequiredRepayment = ED_current - (EC / HF_target)
Proof:
_10Want: HF_new = HF_target_10HF_new = EC / ED_new = HF_target_10ED_new = EC / HF_target_10_10Required repayment = ED_current - ED_new_10 = ED_current - (EC / HF_target)
Example:
_15Price drops! Collateral value decreases._15_15New state:_15- EC = $640 (was $800, FLOW dropped 20%)_15- ED = $615.38 (unchanged)_15- HF = 640 / 615.38 = 1.04 (< HF_min of 1.1)_15_15Calculate required repayment:_15ED_target = 640 / 1.3 = $492.31_15Repayment = 615.38 - 492.31 = $123.07 MOET_15_15After repaying $123.07:_15- EC = $640 (unchanged)_15- ED = $492.31_15- HF = 640 / 492.31 = 1.30 ✓
Interest Mathematics
Scaled Balance System
FCM uses scaled balances to efficiently track interest:
_10B_scaled = \frac{B_true}{I_t}
Where:
- $B_scaled$: Stored scaled balance
- $B_true$: Actual balance including interest
- $I_t$: Current interest index
Key insight: Scaled balance stays constant while interest index grows.
Interest Index Growth
The interest index grows continuously based on the interest rate:
_10I_t(n+1) = I_t(n) × (1 + r × \Delta t)
Where:
- $r$: Annual interest rate (e.g., 0.10 for 10%)
- $\Delta t$: Time elapsed (in years)
For compound interest:
_10I_t(n) = I_0 × e^{r × t}
Where $e$ is Euler's number (≈2.718).
True Balance Calculation
To get the current true balance from scaled balance:
_10B_true(t) = B_scaled × I_t
Example:
_10Initial deposit: 1000 MOET_10Initial index: I_0 = 1.0_10Scaled balance: B_scaled = 1000 / 1.0 = 1000_10_10After 1 year at 10% APY:_10Interest index: I_1 = 1.0 × e^(0.10 × 1) ≈ 1.105_10True balance: B_true = 1000 × 1.105 = 1105 MOET_10_10User's debt grew from 1000 to 1105 MOET (10.5% with compound interest)
Why Scaled Balances?
Without scaled balances:
_10Every block (every ~2 seconds):_10- Update interest index_10- Iterate through ALL positions_10- Update each position's balance_10- Gas cost: O(n) where n = number of positions
With scaled balances:
_10Every block:_10- Update interest index only_10- Gas cost: O(1)_10_10When position is touched:_10- Calculate true balance: scaled × index_10- Gas cost: O(1) per position
Result: Massive gas savings for the protocol!
Liquidation Mathematics
Liquidation Trigger
A position becomes liquidatable when:
_10HF < 1.0
Equivalently:
_10EC < ED
Liquidation Target
Liquidations aim to restore health to a target (typically 1.05):
_10HF_liquidation = 1.05
Collateral Seized Calculation
Amount of collateral to seize:
_10CollateralSeized = \frac{ED_repaid × (1 + bonus)}{P_collateral × CF_collateral}
Where:
- $ED_repaid$: Amount of debt repaid by liquidator
- $bonus$: Liquidation bonus (e.g., 0.05 for 5%)
- $P_collateral$: Price of collateral token
- $CF_collateral$: Collateral factor
Example:
_16Liquidatable position:_16- Collateral: 1000 FLOW @ $0.60_16- Debt: 650 MOET @ $1.00_16- HF = (1000 × 0.60 × 0.8) / 650 = 0.738 < 1.0_16_16Liquidation:_16- Liquidator repays: 150 MOET_16- Liquidation bonus: 5%_16- Collateral seized: (150 × 1.05) / (0.60 × 0.8) = 328.125 FLOW_16_16After liquidation:_16- Collateral: 671.875 FLOW @ $0.60 = $403.125 effective_16- Debt: 500 MOET_16- HF = 403.125 / 500 = 0.806..._16_16(May need multiple liquidations or larger liquidation to reach target 1.05)
Required Debt Repayment for Target Health
To restore position to target health factor:
_10ED_repay = ED_current - (EC / HF_liquidation)
Example:
_10From above, to reach HF = 1.05:_10EC = 1000 × 0.60 × 0.8 = $480_10ED_current = $650_10_10ED_target = 480 / 1.05 = $457.14_10ED_repay = 650 - 457.14 = $192.86 MOET must be repaid
Price Impact Analysis
Health Factor Sensitivity to Price Changes
Given a percentage change in collateral price:
_10HF_new = HF_old × \frac{P_new}{P_old}
Derivation:
_10HF_old = EC_old / ED = (A × P_old × CF) / ED_10_10HF_new = EC_new / ED = (A × P_new × CF) / ED_10_10HF_new / HF_old = P_new / P_old_10_10Therefore: HF_new = HF_old × (P_new / P_old)
Example:
_10Initial: HF = 1.5, Price = $1.00_10_10Price drops 20% to $0.80:_10HF_new = 1.5 × (0.80 / 1.00) = 1.5 × 0.80 = 1.20_10_10Price drops 30% to $0.70:_10HF_new = 1.5 × (0.70 / 1.00) = 1.5 × 0.70 = 1.05 (approaching danger!)_10_10Price drops 35% to $0.65:_10HF_new = 1.5 × (0.65 / 1.00) = 1.5 × 0.65 = 0.975 < 1.0 (liquidatable!)
Maximum Safe Price Drop
What's the maximum price drop before liquidation?
_10MaxDropPercent = 1 - (1.0 / HF_current)
Derivation:
_10Want: HF_new = 1.0 (liquidation threshold)_10HF_new = HF_old × (P_new / P_old) = 1.0_10_10P_new / P_old = 1.0 / HF_old_10_10P_new = P_old / HF_old_10_10Drop = P_old - P_new = P_old × (1 - 1/HF_old)_10_10Drop % = 1 - 1/HF_old
Examples:
_10HF = 1.3: Max drop = 1 - 1/1.3 = 23.08%_10HF = 1.5: Max drop = 1 - 1/1.5 = 33.33%_10HF = 2.0: Max drop = 1 - 1/2.0 = 50.00%_10HF = 1.1: Max drop = 1 - 1/1.1 = 9.09% (very risky!)
Multi-Collateral Mathematics
Multiple Collateral Types
With multiple collateral types:
_10EC = \sum_i=1^{n} A_i × P_i × CF_i
Where $i$ iterates over all collateral token types.
Effective Collateral with Price Correlation
When collateral types are correlated (e.g., FLOW and stFLOW):
Simplified (no correlation):
_10Risk = \sum_i Risk_i
With correlation (advanced):
_10Risk = \sqrt{\sum_i\sum_j w_i w_j \sigma_i \sigma_j \rho_ij}
Where:
- $w_i$: Weight of asset $i$
- $\sigma_i$: Volatility of asset $i$
- $\rho_ij$: Correlation between assets $i$ and $j$
Practical impact:
_10Scenario 1: Uncorrelated collateral_10- 50% FLOW (volatile)_10- 50% USDC (stable)_10- Effective diversification_10_10Scenario 2: Correlated collateral_10- 50% FLOW (volatile)_10- 50% stFLOW (volatile, correlated with FLOW)_10- Limited diversification_10- Both can drop together!
Yield Calculations
Simple APY
Annual Percentage Yield without compounding:
_10APY_simple = (FinalValue - InitialValue / InitialValue) × (365 / Days)
Compound APY
With continuous compounding:
_10APY_compound = e^r - 1
Where $r$ is the continuous annual rate.
Leveraged Yield
When borrowing to increase yield exposure:
_10Yield_leveraged = Yield_strategy - Interest_borrowed
Example:
_13Deposit: $1000 collateral_13Borrow: $615 at 5% APY_13Deploy $615 to strategy earning 10% APY_13_13Costs:_13- Interest on borrowed: 615 × 0.05 = $30.75/year_13_13Returns:_13- Yield from strategy: 615 × 0.10 = $61.50/year_13_13Net leveraged yield: 61.50 - 30.75 = $30.75/year_13Effective APY on your $1000: 30.75 / 1000 = 3.075% extra_13Total return: Base yield + leveraged yield
Risk Metrics
Liquidation Risk Score
A simplified risk score:
_10\text{Risk Score} = (1 / HF - 1.0) × Volatility_collateral
Higher score = higher risk.
Value at Risk (VaR)
Maximum expected loss over time period at confidence level:
_10VaR_95% = EC × \sigma × z_0.95
Where:
- $\sigma$: Daily volatility of collateral
- $z_0.95$: Z-score for 95% confidence (≈1.645)
Example:
_10Collateral: $1000 FLOW_10Daily volatility: 5%_10Confidence: 95%_10_10VaR = 1000 × 0.05 × 1.645 = $82.25_10_10Interpretation: 95% confident that daily loss won't exceed $82.25
Validation & Safety Checks
Health Factor Bounds
All operations must satisfy:
_101.0 ≤ HF_min < HF_target < HF_max
Typical values: $HF_min = 1.1$, $HF_target = 1.3$, $HF_max = 1.5$
Collateral Factor Bounds
For safety:
_100 < CF_t ≤ 1.0
Typically:
- Volatile assets (FLOW): $CF = 0.75 - 0.85$
- Stable assets (USDC): $CF = 0.90 - 0.95$
- Liquid staking (stFLOW): $CF = 0.80 - 0.85$
Maximum Leverage
Maximum theoretical leverage:
_10MaxLeverage = (1 / 1 - CF)
Examples:
_10CF = 0.8: Max leverage = 1 / (1 - 0.8) = 5x_10CF = 0.75: Max leverage = 1 / (1 - 0.75) = 4x_10CF = 0.9: Max leverage = 1 / (1 - 0.9) = 10x (risky!)
But actual safe leverage is constrained by target health:
_10SafeLeverage = (CF / HF_target)
Examples:
_10CF = 0.8, HF = 1.3: Safe leverage = 0.8 / 1.3 ≈ 0.615 = ~1.62x_10CF = 0.75, HF = 1.5: Safe leverage = 0.75 / 1.5 = 0.50 = 1.5x
Practical Examples
Complete Position Lifecycle Math
_36=== Initial Deposit ===_36Deposit: 1000 FLOW @ $1.00_36CF = 0.8, HF_target = 1.3_36_36EC = 1000 × 1.00 × 0.8 = $800_36Borrow = 800 / 1.3 = $615.38 MOET_36HF = 800 / 615.38 = 1.30 ✓_36_36=== Price Drop 20% ===_36New price: $0.80_36EC = 1000 × 0.80 × 0.8 = $640_36ED = $615.38 (unchanged)_36HF = 640 / 615.38 = 1.04 < 1.1 ⚠️_36_36Rebalance needed:_36ED_target = 640 / 1.3 = $492.31_36Repay = 615.38 - 492.31 = $123.07_36_36After repayment:_36EC = $640, ED = $492.31_36HF = 640 / 492.31 = 1.30 ✓_36_36=== Price Recovery to $1.00 ===_36EC = 1000 × 1.00 × 0.8 = $800_36ED = $492.31_36HF = 800 / 492.31 = 1.625 > 1.5 ⚠️_36_36Rebalance needed:_36ED_target = 800 / 1.3 = $615.38_36Borrow = 615.38 - 492.31 = $123.07_36_36After borrowing:_36EC = $800, ED = $615.38_36HF = 800 / 615.38 = 1.30 ✓_36_36Position back to optimal state!
Summary of Key Formulas
| Formula | Expression | Use |
|---|---|---|
| Effective Collateral | $EC = \sum A_t × P_t × CF_t$ | Calculate total collateral value |
| Health Factor | $HF = EC / ED$ | Monitor position safety |
| Max Borrow | $Max = EC / HF_target$ | Auto-borrowing amount |
| Rebalance Up | $Repay = ED - (EC / HF_target)$ | Required debt reduction |
| Rebalance Down | $Borrow = (EC / HF_target) - ED$ | Additional borrowing capacity |
| Scaled Balance | $B_scaled = B_true / I_t$ | Interest-efficient tracking |
| True Balance | $B_true = B_scaled × I_t$ | Current balance with interest |
| Max Price Drop | $DropPercent = 1 - (1 / HF)$ | Liquidation safety margin |
Next Steps
- Apply these formulas: ALP Documentation
- Understand architecture: FCM Architecture
- Learn the basics: Understanding FCM Basics
These mathematical foundations ensure FCM operates predictably and safely. All formulas are implemented on-chain and can be verified by examining the smart contracts.