Liquidations

Liquidations in DPerp protect the protocol and other traders by automatically closing positions that fall below maintenance margin requirements. The system uses a multi-tier liquidation approach to minimize losses and maintain system stability.

Liquidation Conditions

Liquidation Triggers

Positions are liquidated when:

  1. Maintenance Margin Breach: Remaining collateral falls below maintenance requirements

  2. Loss Exceeds Collateral: Unrealized losses exceed available collateral

  3. Fee Accumulation: Funding fees exceed remaining margin

  4. Leverage Limit Breach: Position leverage exceeds maximum allowed

Liquidation Validation

function _validateLiquidation(
    address account,
    bytes32 assetId,
    bool isLong,
    bool raise
) private view returns (uint256, uint256) {
    Position memory position = positionManager.getPosition(account, assetId, isLong);
    
    (bool hasProfit, uint256 delta) = getDelta(assetId, position.size, position.entryPrice, isLong, position.lastIncreasedTime);
    
    uint256 marginFees = _getFundingFee(assetId, position.size, position.entryFundingRate);
    marginFees += (position.size * marginFeeBasisPoints[assetId]) / BASIS_POINTS;
    
    // Check if losses exceed collateral
    if (!hasProfit && position.collateral < delta) {
        return (1, marginFees); // Liquidation state 1: Full liquidation
    }
    
    uint256 remainingCollateral = position.collateral;
    if (!hasProfit) {
        remainingCollateral = position.collateral - delta;
    }
    
    // Check if fees exceed remaining collateral
    if (remainingCollateral < marginFees + liquidationFeeUsd[assetId]) {
        return (1, marginFees); // Liquidation state 1: Full liquidation
    }
    
    // Check leverage limit
    if (remainingCollateral * maxLeverage[assetId] < position.size * BASIS_POINTS) {
        return (2, marginFees); // Liquidation state 2: Partial liquidation
    }
    
    return (0, marginFees); // Healthy position
}

Liquidation Types

Full Liquidation (State 1)

Complete position closure when:

  • Losses exceed available collateral

  • Remaining margin insufficient for fees

  • Position becomes insolvent

Partial Liquidation (State 2)

Partial position reduction when:

  • Leverage exceeds maximum allowed

  • Position can be saved by reducing size

  • Sufficient collateral remains after reduction

Liquidation Process

Liquidation Pricing

Mark Price Calculation

Liquidations use mark prices to prevent manipulation:

Liquidation Price Formula

Liquidation Fees

Fee Structure

Component
Amount
Recipient

Liquidation Fee

$5-100

Protocol

Liquidator Reward

0.5% of collateral

Liquidator

Gas Compensation

Variable

Liquidator

Fee Calculation

Liquidation Monitoring

Position Health Monitoring

Liquidation Alerts

Liquidation Protection

Auto-Deleveraging

Stop-Loss Orders

Liquidation Bots

Liquidator Implementation

Liquidation Monitoring

Risk Management

Liquidation Prevention

  • Monitor position health continuously

  • Set appropriate stop-losses

  • Maintain margin buffers

  • Use position sizing rules

Protocol Protection

  • Maximum liquidation fees

  • Liquidator incentives

  • Insurance fund coverage

  • Emergency pause mechanisms

Last updated