Position Health Invariant
The position health invariant is the one of Twyne's two fundamental invariants, working alongside the non-negative excess credit invariant to ensure the protocol's stability and security. This document explains what the position health invariant is, why it matters, how it's enforced, and its mathematical foundations.
What Is The Position Health Invariant?
The position health invariant states that:
A position must remain healthy according to both Twyne's criteria and the external protocol's criteria (with safety buffer) at all times.
Mathematically, a position is considered healthy when both of these conditions are met:
(Twyne condition)
(External protocol condition)
Where:
= External debt (borrowed amount)
= User collateral
= Reserved credit from Intermediate Vault
= Twyne liquidation LTV (user-selected parameter)
= External protocol liquidation LTV
= Safety buffer (0.95 to 1.0)
In simpler terms: a position should never borrow more than what's allowed by either Twyne's limits or the external protocol's limits (with safety margin).
Why is This Invariant Critical?
The position health invariant serves several essential purposes:
Borrower Protection: It ensures borrowers don't take on more debt than they can handle based on their selected risk parameters.
Credit LP Protection: It protects Credit LPs by ensuring borrowers maintain sufficient collateralization levels.
External Liquidation Prevention: It helps avoid unexpected external liquidations by maintaining a safety buffer below external protocol thresholds.
Protocol Solvency: By preventing unhealthy positions (except during liquidation), it maintains the overall solvency of the protocol.
If this invariant were violated, positions could become under-collateralized, leading to potential losses for Credit LPs, borrowers, and the protocol as a whole.
Python Implementation for Verification
Here's a Python function to verify the position health invariant:
Example Scenarios
Let's examine several scenarios to understand how this invariant works in practice:
Scenario 1: Healthy Position
In this scenario, both conditions are met, resulting in a healthy position.
Scenario 2: Unhealthy - Twyne Condition Violated
In this scenario, the borrowed amount exceeds what's allowed by the Twyne LTV, making the position internally liquidatable.
Scenario 3: Unhealthy - External Condition Violated
In this scenario, the borrowed amount exceeds both Twyne and external limits, making the position externally liquidatable.
Scenario 4: Edge Case - Zero Collateral or Zero Debt
With zero debt, the position is always healthy, and health factors are infinite.
Maintaining Position Health
Users can maintain position health in several ways:
Monitor Health Factors: Regularly check both Twyne and external health factors
Add Collateral: Deposit additional collateral to improve health factors
Repay Debt: Reduce borrowed amount to improve health factors
Adjust Twyne LTV: Lower the Twyne liquidation LTV to increase borrowing safety margin
Regular Rebalancing: Perform rebalancing to optimize credit reservation
The minimum safe values for health factors depend on user risk tolerance, but generally:
Health factor > 1.5: Very safe
Health factor between 1.2 and 1.5: Moderately safe
Health factor between 1.0 and 1.2: Risky, close to liquidation
Health factor < 1.0: Liquidatable
Interaction with Liquidation Mechanisms
The position health invariant is directly tied to Twyne's liquidation mechanisms:
Internal Liquidation: When the position health invariant is violated, internal liquidation can be triggered
External Liquidation Prevention: Maintaining the invariant with a safety buffer helps prevent external liquidations
Liquidation Function: The
_canLiquidate()function that checks the invariant also determines when positions can be liquidated
This interaction ensures that positions either remain healthy or get liquidated to restore health.
Edge Cases and Considerations
Price Volatility
Position health is affected by price changes:
Collateral price decreases make positions less healthy
Debt price increases make positions less healthy
Twyne's safety buffer helps mitigate this risk, but users should maintain additional buffers in volatile market conditions.
Parameter Changes
Changes to protocol parameters can affect position health:
Decreasing Twyne LTV makes positions less healthy
Decreasing external LTV makes positions less healthy
Decreasing safety buffer makes positions less healthy
The protocol should handle these changes carefully to avoid sudden mass liquidations.
Impact on User Operations
The position health invariant affects several user operations:
Borrowing: Users can only borrow up to the limits defined by the invariant
Withdrawing Collateral: Withdrawals are limited to maintain position health
Setting LTV: Users can only set LTV parameters that maintain position health
Liquidation Eligibility: Positions that violate the invariant become eligible for liquidation
Connection to Non-Negative Excess Credit
The position health invariant works together with the non-negative excess credit invariant:
Complementary Protection: While non-negative excess credit ensures proper credit reservation, position health ensures proper debt management
Relationship to Rebalancing: Rebalancing helps maintain both invariants by releasing excess credit and improving position health
Together, these invariants create a robust safety system for Twyne.
Last updated

