Understanding Liquidations in Osito Protocol
Liquidations are a critical mechanism in Osito Protocol that ensure the protocol remains solvent even during changing market conditions. They help enforce the protocol's borrow limits.
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:
- A liquidator repays the full debt of the position
- The liquidator receives all collateral in the position
- The position is completely closed and removed from the protocol
How Liquidations Support the Protocol
Liquidations are the practical enforcement of Osito's core lending 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 sound state.
When Liquidations Happen
A position becomes eligible for liquidation when:
position.borrowedAmount > calculatePositionMaxBorrow(positionId)
This can happen due to several factors:
- Increased Utilization: As more of a token is borrowed across the protocol, each position's borrowing limit decreases
- Liquidity Changes: Reductions in the token's liquidity pool depth decrease borrowing capacity
- Interest Accrual: As interest accrues on the borrowed amount, it can exceed the borrowing limit
- Supply Distribution Changes: Shifts in token circulation can affect the borrow limit calculation
All of these factors can change how the protocol calculates borrow limits, which is why they are updated in real-time.
The Borrow Limit 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:
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
Before any liquidation, the protocol:
- Updates the BERA interest rate state
- Updates the token-specific state
- Updates the position state with current interest
- Recalculates the position's maximum borrowing capacity using fresh pool data
This ensures liquidations are performed based on the most current calculations, maintaining the requirement that borrowed amounts stay within calculated limits.
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 exceeds its borrow limit, economically rational actors will restore system solvency.
Protecting Your Position
To avoid liquidation, borrowers should:
- Maintain a Safe Buffer: Borrow significantly less than your maximum limit
- Monitor Utilization: Watch token utilization levels across the protocol
- Pay Back Regularly: Reduce debt periodically, especially as interest accrues
- Add Collateral: Deposit additional tokens if your position approaches the liquidation threshold
Checking Liquidation Risk
You can assess your liquidation risk through:
- Position Dashboard: Check your current borrow amount vs. maximum borrow limit
- Risk Indicator: The Osito app provides a color-coded risk indicator for each position
- Health Factor: Monitor your position's health factor (max_borrow/current_borrow)
Remember that liquidations can happen as market conditions change, which is why maintaining a safety buffer is important. This is by design to ensure the protocol's mathematical model remains effective.