Risk Engine V1

TL;DR: The Risk Engine ensures all positions are adequately collateralized by calculating margin requirements using worst-case APR assumptions. It answers: "If Variable Yield moves maximally against this position, how much could they lose?"

Overview

The Risk Engine is the protocol's safety mechanism. It calculates how much margin each position needs by considering the worst possible outcome.

spinner

The Worst Case APR Mechanism

Why Worst Case?

Consider this position:

User locked 6% Fixed Yield on 100,000 USDC for 90 days

Question: How much margin do they need? Answer: Depends on what VY could do...

  • If VY = 4% → User profits → No margin needed

  • If VY = 6% → Break even → No margin needed

  • If VY = 12% → User loses 6% → Needs margin to cover ~$1,480 loss

  • If VY = 20% → User loses 14% → Needs margin to cover ~$3,450 loss

The protocol can't know what VY will actually be. So it assumes the worst case and requires margin to cover that.

Two Worst Case Factors

The protocol maintains two worst-case VY assumptions per pool:

Factor
When Used
Scenario

worstCaseVariableFactorPositive

variableTokenBalance > 0 (receiving VY)

VY drops to minimum

worstCaseVariableFactorNegative

variableTokenBalance < 0 (paying VY)

VY rises to maximum

Example: FY Position (Locking Fixed Yield)

The user is long fixed yield and short variable yield:

  • fixedTokenBalance = +100,000 (receiving FY)

  • variableTokenBalance = −100,000 (paying VY)

Because variableYieldBalance < 0 , the risk engine applies worstCaseVariableFactorNegative (the “VY goes high” worst case for payers).

Assumptions: • Fixed yield locked at 6% APR • Term = 90 days • worstCaseVariableFactorNegative = 12% APR (admin-set)

Worst-case cashflow over the term is computed as:

Margin required is the absolute value of the worst-case loss:

MarginRequired = |−1,480| = 1,480 USD.

Example: VY Position (Trading Variable Yield)

The user is short fixed yield and long variable yield:

  • fixedTokenBalance = −100,000 (paying FY)

  • variableTokenBalance = +100,000 (receiving VY)

Because variableTokenBalance > 0 , the risk engine applies worstCaseVariableFactorPositive (the “VY goes low” worst case for receivers).

Assumptions:

  • Fixed yield given up is 6% APR

  • Term = 90 days

  • worstCaseVariableFactorPositive = 2% APR (admin-set)

Worst-case cashflow over the term:

Margin required:

MarginRequired = |−987| = 987 USD.

The Calculation Flow

Step 1: Get Position Data

Step 2: Determine Which Worst Case Factor

Step 3: Calculate Worst Case Cashflow

Step 4: Convert to Margin Requirement

LP Position Scenario Analysis

LP positions are more complex because their token balances change as price moves.

The Problem

LP provides liquidity between 5% and 8% FY (ticks tickLower to tickUpper)

Current FY = 6.5% (within range)

What if FY moves?

  • If FY → 5%: LP has more variableTokens

  • If FY → 8%: LP has more fixedTokens

Each scenario has different margin requirement!

The Solution: Evaluate Both Extremes

Scenario Calculation

Collateral Valuation

Discount Factors

Not all collateral is valued equally:

Total Collateral Value

Health Check

The Final Comparison

Liquidation Threshold

Admin Configuration

Setting Worst Case Factors

Choosing Values

Factor
Meaning
Typical Range

Positive (VY low)

Min VY if you're receiving it

0-3%

Negative (VY high)

Max VY if you're paying it

10-20%

These should be set based on:

  • Historical VY volatility for the underlying protocol

  • Term length (longer = more uncertainty)

  • Risk tolerance of the protocol

Key Takeaways

  1. Worst case, not expected — Always assume VY moves maximally against user

  2. Two scenarios per direction — Low VY for receivers, high VY for payers

  3. LP scenario analysis — Check both tick boundaries for LPs

  4. Discount factors — Volatile collateral gets haircut

  5. Admin controlled — Worst case factors are protocol parameters

Next Steps

  • Collateral Engine V1 — How positions are stored

  • Liquidations — What happens when margin is insufficient

  • Margin System — Detailed margin mechanics

Last updated