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

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

VariableSymbolDescription
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

VariableSymbolDescription
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

VariableSymbolDescription
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:


_10
EC = ∑(A_t × P_t × CF_t) for all t in Collateral

Example:


_10
Collateral assets:
_10
- 1000 FLOW @ $1 each, CF = 0.8
_10
- 500 USDC @ $1 each, CF = 0.9
_10
_10
EC = (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:


_10
ED = \sum_t \in Debt A_t × P_t × BF_t

Example:


_10
Debt:
_10
- 800 MOET @ $1 each, BF = 1.0
_10
_10
ED = 800 × 1 × 1.0
_10
= $800 MOET

3. Health Factor

The health factor is the ratio of effective collateral to effective debt:


_10
HF = (EC / ED)

Critical thresholds:

  • $HF < 1.0$: Position is liquidatable
  • $HF = 1.0$: Exactly at liquidation threshold
  • $HF > 1.0$: Position is solvent

Example:


_10
EC = $1250, ED = $800
_10
_10
HF = 1250 / 800 = 1.5625

4. Maximum Borrowing Capacity

The maximum amount that can be borrowed to reach target health:


_10
MaxBorrow = (EC / HF_target)

Derivation:


_10
We want: HF = EC / ED = HF_target
_10
Therefore: ED = EC / HF_target

Example:


_10
EC = $1250
_10
HF_target = 1.3
_10
_10
Max 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:


_10
BorrowAmount = (EC / HF_target)

Step-by-step calculation:

  1. Calculate effective collateral:

_10
EC = A_collateral × P_collateral × CF_collateral

  1. Calculate target debt:

_10
ED_target = (EC / HF_target)

  1. Borrow to reach target:

_10
Borrow = ED_target = (EC / HF_target)

Complete example:


_15
User deposits: 1000 FLOW
_15
FLOW price: $1.00
_15
Collateral factor: 0.8
_15
Target health: 1.3
_15
_15
Step 1: EC = 1000 × 1.00 × 0.8 = $800
_15
_15
Step 2: ED_target = 800 / 1.3 = $615.38
_15
_15
Step 3: Borrow = $615.38 MOET
_15
_15
Result:
_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:


_10
AdditionalBorrow = (EC / HF_target) - ED_current

Proof:


_10
Want: HF_new = HF_target
_10
HF_new = EC / ED_new = HF_target
_10
ED_new = EC / HF_target
_10
_10
Additional borrow = ED_new - ED_current
_10
= (EC / HF_target) - ED_current

Example:


_13
Current state:
_13
- EC = $800
_13
- ED = $400
_13
- HF = 800 / 400 = 2.0 (> HF_max of 1.5)
_13
_13
Calculate additional borrow:
_13
ED_target = 800 / 1.3 = $615.38
_13
Additional = 615.38 - 400 = $215.38 MOET
_13
_13
After 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:


_10
RequiredRepayment = ED_current - (EC / HF_target)

Proof:


_10
Want: HF_new = HF_target
_10
HF_new = EC / ED_new = HF_target
_10
ED_new = EC / HF_target
_10
_10
Required repayment = ED_current - ED_new
_10
= ED_current - (EC / HF_target)

Example:


_15
Price drops! Collateral value decreases.
_15
_15
New 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
_15
Calculate required repayment:
_15
ED_target = 640 / 1.3 = $492.31
_15
Repayment = 615.38 - 492.31 = $123.07 MOET
_15
_15
After 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:


_10
B_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:


_10
I_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:


_10
I_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:


_10
B_true(t) = B_scaled × I_t

Example:


_10
Initial deposit: 1000 MOET
_10
Initial index: I_0 = 1.0
_10
Scaled balance: B_scaled = 1000 / 1.0 = 1000
_10
_10
After 1 year at 10% APY:
_10
Interest index: I_1 = 1.0 × e^(0.10 × 1) ≈ 1.105
_10
True balance: B_true = 1000 × 1.105 = 1105 MOET
_10
_10
User's debt grew from 1000 to 1105 MOET (10.5% with compound interest)

Why Scaled Balances?

Without scaled balances:


_10
Every 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:


_10
Every block:
_10
- Update interest index only
_10
- Gas cost: O(1)
_10
_10
When 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:


_10
HF < 1.0

Equivalently:


_10
EC < ED

Liquidation Target

Liquidations aim to restore health to a target (typically 1.05):


_10
HF_liquidation = 1.05

Collateral Seized Calculation

Amount of collateral to seize:


_10
CollateralSeized = \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:


_16
Liquidatable 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
_16
Liquidation:
_16
- Liquidator repays: 150 MOET
_16
- Liquidation bonus: 5%
_16
- Collateral seized: (150 × 1.05) / (0.60 × 0.8) = 328.125 FLOW
_16
_16
After 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:


_10
ED_repay = ED_current - (EC / HF_liquidation)

Example:


_10
From above, to reach HF = 1.05:
_10
EC = 1000 × 0.60 × 0.8 = $480
_10
ED_current = $650
_10
_10
ED_target = 480 / 1.05 = $457.14
_10
ED_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:


_10
HF_new = HF_old × \frac{P_new}{P_old}

Derivation:


_10
HF_old = EC_old / ED = (A × P_old × CF) / ED
_10
_10
HF_new = EC_new / ED = (A × P_new × CF) / ED
_10
_10
HF_new / HF_old = P_new / P_old
_10
_10
Therefore: HF_new = HF_old × (P_new / P_old)

Example:


_10
Initial: HF = 1.5, Price = $1.00
_10
_10
Price drops 20% to $0.80:
_10
HF_new = 1.5 × (0.80 / 1.00) = 1.5 × 0.80 = 1.20
_10
_10
Price drops 30% to $0.70:
_10
HF_new = 1.5 × (0.70 / 1.00) = 1.5 × 0.70 = 1.05 (approaching danger!)
_10
_10
Price drops 35% to $0.65:
_10
HF_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?


_10
MaxDropPercent = 1 - (1.0 / HF_current)

Derivation:


_10
Want: HF_new = 1.0 (liquidation threshold)
_10
HF_new = HF_old × (P_new / P_old) = 1.0
_10
_10
P_new / P_old = 1.0 / HF_old
_10
_10
P_new = P_old / HF_old
_10
_10
Drop = P_old - P_new = P_old × (1 - 1/HF_old)
_10
_10
Drop % = 1 - 1/HF_old

Examples:


_10
HF = 1.3: Max drop = 1 - 1/1.3 = 23.08%
_10
HF = 1.5: Max drop = 1 - 1/1.5 = 33.33%
_10
HF = 2.0: Max drop = 1 - 1/2.0 = 50.00%
_10
HF = 1.1: Max drop = 1 - 1/1.1 = 9.09% (very risky!)

Multi-Collateral Mathematics

Multiple Collateral Types

With multiple collateral types:


_10
EC = \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):


_10
Risk = \sum_i Risk_i

With correlation (advanced):


_10
Risk = \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:


_10
Scenario 1: Uncorrelated collateral
_10
- 50% FLOW (volatile)
_10
- 50% USDC (stable)
_10
- Effective diversification
_10
_10
Scenario 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:


_10
APY_simple = (FinalValue - InitialValue / InitialValue) × (365 / Days)

Compound APY

With continuous compounding:


_10
APY_compound = e^r - 1

Where $r$ is the continuous annual rate.

Leveraged Yield

When borrowing to increase yield exposure:


_10
Yield_leveraged = Yield_strategy - Interest_borrowed

Example:


_13
Deposit: $1000 collateral
_13
Borrow: $615 at 5% APY
_13
Deploy $615 to strategy earning 10% APY
_13
_13
Costs:
_13
- Interest on borrowed: 615 × 0.05 = $30.75/year
_13
_13
Returns:
_13
- Yield from strategy: 615 × 0.10 = $61.50/year
_13
_13
Net leveraged yield: 61.50 - 30.75 = $30.75/year
_13
Effective APY on your $1000: 30.75 / 1000 = 3.075% extra
_13
Total 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:


_10
VaR_95% = EC × \sigma × z_0.95

Where:

  • $\sigma$: Daily volatility of collateral
  • $z_0.95$: Z-score for 95% confidence (≈1.645)

Example:


_10
Collateral: $1000 FLOW
_10
Daily volatility: 5%
_10
Confidence: 95%
_10
_10
VaR = 1000 × 0.05 × 1.645 = $82.25
_10
_10
Interpretation: 95% confident that daily loss won't exceed $82.25

Validation & Safety Checks

Health Factor Bounds

All operations must satisfy:


_10
1.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:


_10
0 < 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:


_10
MaxLeverage = (1 / 1 - CF)

Examples:


_10
CF = 0.8: Max leverage = 1 / (1 - 0.8) = 5x
_10
CF = 0.75: Max leverage = 1 / (1 - 0.75) = 4x
_10
CF = 0.9: Max leverage = 1 / (1 - 0.9) = 10x (risky!)

But actual safe leverage is constrained by target health:


_10
SafeLeverage = (CF / HF_target)

Examples:


_10
CF = 0.8, HF = 1.3: Safe leverage = 0.8 / 1.3 ≈ 0.615 = ~1.62x
_10
CF = 0.75, HF = 1.5: Safe leverage = 0.75 / 1.5 = 0.50 = 1.5x

Practical Examples

Complete Position Lifecycle Math


_36
=== Initial Deposit ===
_36
Deposit: 1000 FLOW @ $1.00
_36
CF = 0.8, HF_target = 1.3
_36
_36
EC = 1000 × 1.00 × 0.8 = $800
_36
Borrow = 800 / 1.3 = $615.38 MOET
_36
HF = 800 / 615.38 = 1.30 ✓
_36
_36
=== Price Drop 20% ===
_36
New price: $0.80
_36
EC = 1000 × 0.80 × 0.8 = $640
_36
ED = $615.38 (unchanged)
_36
HF = 640 / 615.38 = 1.04 < 1.1 ⚠️
_36
_36
Rebalance needed:
_36
ED_target = 640 / 1.3 = $492.31
_36
Repay = 615.38 - 492.31 = $123.07
_36
_36
After repayment:
_36
EC = $640, ED = $492.31
_36
HF = 640 / 492.31 = 1.30 ✓
_36
_36
=== Price Recovery to $1.00 ===
_36
EC = 1000 × 1.00 × 0.8 = $800
_36
ED = $492.31
_36
HF = 800 / 492.31 = 1.625 > 1.5 ⚠️
_36
_36
Rebalance needed:
_36
ED_target = 800 / 1.3 = $615.38
_36
Borrow = 615.38 - 492.31 = $123.07
_36
_36
After borrowing:
_36
EC = $800, ED = $615.38
_36
HF = 800 / 615.38 = 1.30 ✓
_36
_36
Position back to optimal state!

Summary of Key Formulas

FormulaExpressionUse
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


tip

These mathematical foundations ensure FCM operates predictably and safely. All formulas are implemented on-chain and can be verified by examining the smart contracts.