Understanding Liquidations in Osito Protocol

Liquidations are a critical security mechanism in Osito Protocol that ensure the protocol remains solvent even during extreme market conditions. They're the last line of defense in the protocol's attack-proof security model.

What is a Liquidation?

A liquidation occurs when a position's borrowed amount exceeds its maximum borrowing capacity. During liquidation, the entire position is closed:

  1. A liquidator repays the full debt of the position
  2. The liquidator receives all collateral in the position
  3. The position is completely closed and removed from the protocol

How Liquidations Support the Security Model

Liquidations are the practical enforcement of Osito's core security principle:

max_borrow ≤ pool_BERA - extractable_BERA

When this inequality is violated (due to changing market conditions, increasing utilization, or accruing interest), liquidations restore the system to a mathematically secure state.

When Liquidations Happen

A position becomes eligible for liquidation when:

position.borrowedAmount > calculatePositionMaxBorrow(positionId)

This can happen due to several factors:

  1. Increased Utilization: As more of a token is borrowed across the protocol, each position's borrowing limit decreases
  2. Liquidity Changes: Reductions in the token's liquidity pool depth decrease borrowing capacity
  3. Interest Accrual: As interest accrues on the borrowed amount, it can exceed the borrowing limit
  4. Supply Distribution Changes: Shifts in token circulation can affect the extraction calculation

All of these factors can change how much BERA an attacker could theoretically extract, which is why the protocol must adapt its borrowing limits in real-time.

The Extraction Calculation

The borrowing limit is calculated using Osito's core formula for CPMM pools:

max_borrow = pool_BERA - (pool_BERA * pool_tokens) / (pool_tokens + dumpable_tokens)

Or for CLMM pools with better execution:

max_borrow = pool_BERA - (dumpable_tokens * pool_BERA/pool_tokens / 2)

As these values change based on market conditions, positions may cross the liquidation threshold.

How Liquidations Work

Osito uses an "all-or-nothing" liquidation mechanism:

function liquidate(uint256 positionId) external nonReentrant {
    // Get position data
    Position storage position = positions[positionId];
    address token = position.token;
    
    // Update state with fresh data
    _updateWberaRate();
    _updateTokenState(token);
    _updatePosition(positionId);
    
    // Check if position is liquidatable
    uint256 maxBorrow = calculatePositionMaxBorrow(positionId);
    if (position.borrowedAmount <= maxBorrow) {
        revert("OsitoLending: Position not liquidatable");
    }
    
    // Get position details
    uint256 requiredWbera = position.borrowedAmount;
    uint256 tokenAmount = position.tokenAmount;
    
    // Transfer all collateral to liquidator
    IERC20(token).safeTransfer(msg.sender, tokenAmount);
    
    // Liquidator repays all debt
    IERC20(wbera).safeTransferFrom(msg.sender, address(this), requiredWbera);
    
    // Update protocol state
    totalWberaBorrowed -= requiredWbera;
    tokenData[token].totalBorrowed -= requiredWbera;
    tokenData[token].totalDeposited -= tokenAmount;
    
    // Close the position
    delete positions[positionId];
    
    emit Liquidated(positionId, msg.sender, token, tokenAmount, requiredWbera);
}

Real-Time State Updates

Critical to the security model, before any liquidation the protocol:

  1. Updates the BERA interest rate state
  2. Updates the token-specific state
  3. Updates the position state with current interest
  4. Recalculates the position's maximum borrowing capacity using fresh pool data

This ensures liquidations are performed based on the most current extraction calculations, maintaining the security guarantee that borrowed amounts never exceed what could be extracted in an attack.

Liquidation Incentives

Liquidators are incentivized to monitor positions and perform liquidations when needed. The primary incentive is the potential value difference between:

  • The BERA debt that must be repaid
  • The collateral token value they receive

This market-based incentive system ensures that as soon as a position violates the security model constraints, economically rational actors will restore system solvency.

Protecting Your Position

To avoid liquidation, borrowers should:

  1. Maintain a Safe Buffer: Borrow significantly less than your maximum limit
  2. Monitor Utilization: Watch token utilization levels across the protocol
  3. Pay Back Regularly: Reduce debt periodically, especially as interest accrues
  4. Add Collateral: Deposit additional tokens if your position approaches the liquidation threshold

Checking Liquidation Risk

You can assess your liquidation risk through:

  1. Position Dashboard: Check your current borrow amount vs. maximum borrow limit
  2. Risk Indicator: The Osito app provides a color-coded risk indicator for each position
  3. Health Factor: Monitor your position's health factor (max_borrow/current_borrow)

Remember that liquidations can happen suddenly as market conditions change, which is why maintaining a safety buffer is essential. This is not a flaw in the protocol - it's a feature that ensures the mathematical security guarantees always hold.