LogoLogo
Trade Now
  • Trade Now
  • 👋Welcome
    • About Demex
      • Roadmap
      • Terms and Conditions
      • Disclaimers
    • Getting Started
      • Depositing
      • Activate Account
      • One-Click Trading
  • 💰Demex Rewards
    • 🪂Demex Points
      • Spins
      • Wheel of Fortune and Loot Boxes
      • Squads
      • DMX Token
      • FAQs
    • 🏁Demex Endgame: 50,000,000 Demex Points
    • 💵Demex Credits
    • 🕙Past Events
      • 2022
        • Futures Trading Competition
          • Maker vs Taker #1
          • Maker vs Taker #2
        • Perpetuals Trading Competition
          • Top Gainers and Top Traders #1
          • Top Gainers and Top Traders #2
          • Top Gainers #3
      • 2023
        • Demex Trading Leagues
          • Demex Trading League
            • How to Register
          • Demex $100,000 Mega Marathon
            • Demex Trading League Vol 1
              • How to Register
            • Deposit Booster
            • Demex Trading League Vol 2
          • Demex Trading League (Round 3)
            • How to Register
          • Demex Trading League (Round 4)
          • LUNA Earn-A-Thon & Demex Trading League (Round 5)
          • Demex Trading League (Round 6)
          • SCRT Trading League
        • Earn-a-thons
          • Demex x StaFi ATOM Earn-A-Thon
          • Demex x Zilliqa ZIL Earn-A-Thon
            • How to Register
        • Trading Challenges
          • BNB Trading Challenge
            • How to generate your custom hashtag
          • NEO Trading Challenge
            • How to Register
          • OSMO Perp Trading Challenge
          • Perps Trading Challenge
        • Special Events
          • $500 Surprise Flash Promotion
          • Demex Incentivized Devnet (Ended)
            • Perp Pools Deposits
            • Base Vault and $CLP Staking
            • Fluo Dashboard (Deprecated)
              • Stake FLUO
              • Boost Rewards
              • esFLUO Rewards
            • Demex Trading League (Devnet)
              • How to Register
            • The HODL Lottery
              • How to Register
              • How to Count Your Tickets
      • 2024
        • Celestia Trading League
        • FOMO Points Booster
        • DeFi Points Booster
        • Celestia Points Booster
        • 🥛milkTIA x Demex Points Booster Bonanza
        • BTCETH Points Booster
        • 🟠 Archway Trading League
        • ⚛️ Cosmos Trading Competition
          • 🐋Whalecome to Demex
        • 💯DeFi & FOMO Points Booster
        • 💯DeFi & Layer 1 Points Booster
        • 💧dATOM Lend and Trade Spins Promo
        • 🐸Perp Pool Incentives with Leap Wallet
        • 👋Welcome #BackToDemex
        • 🥛milkTIA Lend and Trade Spins Promo
        • 🛡️Loss Protection
        • 🏃‍♂️STRD Lend and Trade Spins Promo
        • 🐶Meme Traders Arena
        • 🛡️Loss Protection Oct-Nov
        • 🌙LUNA Lend and Trade Spins Promo
        • 💯Modular Pool Points Booster
        • 🕰️Mantle Lend & Trade Spins Promo
        • 🏎️Mantle Trading League
        • 🛡️Loss Protection Dec 9 - 20
        • 👑Mantle Trading League S2
      • 2025
        • 🔲Mantle Rewards Station: 30,000,000 Demex Points
        • 🔲Mantle Rush
        • 🔐Loss Protection March 19 - 26, 2025
        • 🌀Mantle Lend & Trade Spins Promo
        • 💙Base Trading League
        • 🧢Base Lend & Trade Spins Promo
        • 🛡️Loss Protection Feb 10 - 20, 2025
        • 📝#DemexContentQuest
        • 📈#PerpsOnDemex
        • 👥Demex Referral Club
        • 🤖Traḋemex Bot
  • 📊Trade
    • Features
    • Perps & Futures
      • Pricing Engine
      • Margin Specifications
      • Liquidation Engine
      • Market Specifications
      • Pre-launch Perpetuals
      • Glossary
      • FAQs
    • Grouped USD Token
      • Constituent Criteria
      • Safety Features
      • Migration Guide
    • Fees
      • Trading Fees
      • Funding Fees
      • Network Fees
      • Deposit & Withdrawal Fees
      • Fee Delegation
      • CEX to Demex VIP Program
      • Fee Distribution
    • Notifications
      • Demex Progressive Web App (PWA)
    • Trading Modes
      • Lite Mode
      • Pro Mode
        • Features
        • Market Leverage
        • Order Types
        • Execution Options
        • Time-In-Force 🆕
        • Trigger (Stop) Orders
          • Take-Profit
          • Stop-Loss
        • Chart Trading 🆕
  • 💰EARN
    • Liquidity Pools
      • Spot Pools
        • Earnings
        • Amplified Pools
        • Uneven Pool Weights
        • Multi-Pool Routing
        • FAQs
      • Perp Pools
        • Earnings
        • Deposting & Redeeming
        • AMM Strategy
    • Nitron (Lend & Borrow)
      • Lending
      • Borrowing
        • Avoiding Liquidations
      • Liquidation
        • Partial Liquidations
      • USC Stablecoin
        • Interest Rate Model
      • High Efficiency Mode (E-Mode)
      • Liquidations
        • Liquidation Guide
      • Strategies
        • Using Nitron for Perp Trading
      • Protocol Safety Features
      • Risks
    • Referrals
      • Sharing Your Referral Link
      • FAQs
      • Terms and Conditions
  • Stake SWTH / DMX
  • 🫂COMMUNITY
    • Public Community Nodes
    • Feedback
    • Glossary
      • Annual Percentage Rate (APR)
      • Arbitrage
      • Decentralized Applications
      • Execution Options
      • Liquidation
      • Liquidity Pool
      • Liquidity Providers
      • Perpetual Pool
      • Open Interest (OI)
      • Order Book
      • Time-In-Force
      • Volume
      • Yield Farming
  • ⚙️Developers
    • APIs Overview
    • WebSocket API
    • RPC API
    • EVM API
    • Insights API
    • Node CLI
    • Running a Node
      • Testnet
      • Mainnet
      • Public API Node
      • Validators
        • Commissions & Penalties
  • 🤖EVM
    • Overview
    • Deployment Tutorial
    • Interacting with Demex L1
      • Built-in Oracle Contracts
      • Precompiled Trading Contracts
    • ICS-20 <> ERC-20 Token Conversion
    • Explorers
Powered by GitBook
On this page
  • Liquidation
  • Maintenance Rargin Requirement
  • Liquidators
  • Liquidation Engine
  • Partial Liquidation
  • Liquidation Procedure
  • Insurance Fund
  • Auto-Deleveraging (ADL) System
  • Deleveraging Process

Was this helpful?

  1. Trade
  2. Perps & Futures

Liquidation Engine

PreviousMargin SpecificationsNextMarket Specifications

Last updated 15 days ago

Was this helpful?

Demex has an on-chain liquidation mechanism to liquidate derivatives positions that are at risk of going brankrupt (i.e. become insolvent). This ensures that their profitable counterparties receive the appropriate payouts.

During liquidation, the protocol's Liquidation Engine takes over the liquidated position to close it at the best possible price on the open market.

Additionally, Demex has an that avoids socialized losses, as well as an to maintain market continuity even in black swan events. When a position is closed at a favorable price, the surplus funds are transferred to the on-chain Insurance Fund. Conversely, if the position is closed at a loss, the Insurance Fund is first used to absorb the losses.

If the Insurance Fund is insufficient to manage the deficit, the ADL system takes over, deleveraging opposing positions in order of profit and leverage, socializing losses among the most profitable traders. This means that positions that are the most profitable and have a high level of leverage will be the first to undergo deleveraging.

Liquidation

When a position’s allocated margin is less than its required maintenance margin, the position is deemed to be at risk of bankruptcy and therefore liable for liquidation.

Maintenance Rargin Requirement

The required maintenance margin of a linear futures position is given by:

MaintenanceMargin=MaintenanceMarginRatio∗[InitialMarginBase+(floor(RiskStepSize/PositionSize)∗InitialMarginStep)]Maintenance Margin = Maintenance Margin Ratio * [Initial Margin Base + (floor(Risk Step Size / Position Size) * Initial Margin Step)]MaintenanceMargin=MaintenanceMarginRatio∗[InitialMarginBase+(floor(RiskStepSize/PositionSize)∗InitialMarginStep)]

The above parameters are specific to each market and are automatically defined when a futures (perpetuals) market is created; You can check out an example of this on the explorer .

Governance can also change these parameters.

For more details, see the section.

Liquidators

Liquidators are external actors who monitor the level of liquidation risk associated with each position. They broadcast liquidation messages to notify the chain when a risky position needs to be liquidated.

It's important to note that a position can only be liquidated when a liquidation message containing the position ID (MsgInitiateLiquidation) is broadcast by a liquidator.

The Demex node binary includes a liquidator service that can be executed by anyone with a Demex account. While there are no existing incentives for submitting liquidation transactions, it only takes one liquidator to submit a transaction, and the Demex dev team is currently operating at least one such liquidator.

Liquidation Engine

When a valid liquidation message is received, existing orders that might increase the size of the risky position are first cancelled.

Partial Liquidation

The liquidation engine then attempts to reduce the position's risk by submitting a Fill-or-Kill order at the position’s bankruptcy price for the calculated quantity. If there is insufficient liquidity on the order book to execute this order fully, a full liquidation will occur, as the position would remain at risk otherwise.

Liquidation Procedure

When a liquidated position is taken over by the on-chain liquidation engine, any remaining margin within that position is transferred to the liquidation engine.

The position is then disposed of by the liquidation engine in amalgamated blocks of liquidation orders.

Each liquidation order is first quoted at the bankruptcy price of the position, which is the closing price that renders the amalgamated position to be worth $0.

Any profits earned, due to existing orders on the order book matching the liquidation order at a price more favourable than the bankruptcy price, is transferred to the Insurance Fund.

If the liquidation order does not fill immediately, the order is aggressed every 5 seconds by making the order price progressively worse (such that it is more attractive to fill). Any shortfall caused by the unfavourable closing price is covered by the Insurance Fund.

In the event that the liquidation order remains unfilled on the order book for a certain duration, which is defined by MaxLiquidationOrderDuration, auto-deleveraging will be initiated to force the closure of the liquidation engine’s outstanding position.

Accounts with administrative privileges can adjust these parameters as well.

Insurance Fund

The insurance fund is shared by all markets.

In the future, Demex will allow users to directly contribute to the insurance fund to increase its size and avoid ADL. In return, contributors will be able to earn a yield on their contribution when the fund exceeds a particular target threshold.

Auto-Deleveraging (ADL) System

Demex uses an Auto-Deleveraging (ADL) system as its margining approach for derivative instruments, as an evolution to the “Socialised Loss” system.

The Socialised Loss system has some drawbacks:

  • A single risky trader can cause significant losses for all traders, including low-risk ones.

  • Profits must be locked until rebalancing or settlement occurs, in case of a loss.

The ADL system addresses these issues by resolving loss uncertainty, allowing traders to make timely decisions when a deleveraging event occurs, instead of having to wait for rebalancing or settlement to occur.

Deleveraging Process

If (i) liquidation orders cannot be filled in a timely manner, or (ii) there are insufficient funds in the Insurance Fund to cover the shortfall, the ADL system will start to deleverage opposing positions in order of profit and leverage, socializing losses among only the most profitable positions.

The positions with the highest profit and leverage are closed out first (in order of ranking) until the initially liquidated position is fully closed. The price at which a profitable positions are closed out is the bankruptcy price of the liquidation order.

Priority Ranking Calculation

The priority for deleveraging is determined by the profit earned and leverage set by traders, where those who are more profitable and have higher leverage are deleveraged first

The ranking calculation is as follows:

Ranking = PNL Percentage * Effective Leverage  (if PNL percentage > 0)
        = PNL Percentage / Effective Leverage  (if PNL percentage < 0)
where
	Effective Leverage = abs(Mark Value) / (Mark Value - Bankrupt Value)
	PNL percentage = (Mark Value - Avg Entry Value) / abs(Avg Entry Value)
	Mark Value = Position Value at Mark Price
	Bankrupt Value = Position Value at Bankruptcy Price
	Avg Entry Value = Position Value at Average Entry Price

The system splits the positions into longs and shorts and arranges them in descending order of rank (e.g. from highest to lowest), such that positions with higher ranks are deleveraged first.

Example

Suppose there are six long positions in the system, and their effective leveraged PnL score has been calculated. Note that a higher PnL Ranking corresponds to a higher effective leveraged PnL.

Position
Quantity
PNL Ranking

1

10

3

2

10

6

3

20

1

4

30

4

5

20

5

6

10

2

The system then ranks these positions based on their scores, from highest score to lowest score:

Position
Quantity
PNL Ranking

2

10

6

5

20

5

4

30

4

1

10

3

6

10

2

3

20

1

In the case of a liquidation, the system will prioritize deleveraging the higher-ranked positions first.

Let’s consider a short position that has been liquidated with a size of 20 and a bankruptcy price of $650. In this case, Positions 2 and 5 will be deleveraged at the bankruptcy price of $650.

Position 2 will have its entire position of 10 contracts closed, while the remaining 10 contracts from the liquidated short position will be assigned to Position 5.

As a result, Position 5 will have 10 contracts remaining out of its original 20 contracts.

Since margin requirements increase as position size grows (due to the market parameter), to lower the margin requirements of larger positions, they may be partially liquidated to reduce their risk.

The minimum quantity of the position that needs to be reduced such that it meets the , is first calculated.

The liquidation engine's maximum order size is defined by MaxLiquidationOrderTicket. To reduce the impact on the market's , larger positions are split up into multiple orders.

The above parameters are specific to each market and are automatically defined when a futures (perpetuals) market is created; You can check out an example of this on .

The address of the insurance fund can be found .

📊
here
here
maintenance margin requirements
here
Insurance Fund
Auto-Deleveraging (ADL) System
Margin Requirement
RiskStepSize
Mark Price