Version 8 - mainnet - 0x40...f5625f
Readme
Versions
8
Dependencies
0
Dependents
0
Analytics
On the way
DeepBook Margin is a decentralized margin trading protocol built on top of DeepBookV3 on Sui. It enables leveraged trading by allowing users to borrow assets against their collateral, execute margin orders on DeepBook's central limit order book, and manage risk with advanced features like take profit and stop loss conditional orders. The protocol includes a lending pool where suppliers can earn interest by providing liquidity for margin traders to borrow.
The MarginManager is a shared object that represents a single margin trading account. It holds
collateral balances, tracks borrowed positions, and interfaces with both DeepBookV3 for trading
and the MarginPool for borrowing. Each MarginManager is linked to a specific DeepBook pool and
its corresponding MarginPool.
Users can deposit collateral (base, quote, or DEEP tokens), borrow assets to increase their trading position, and repay loans. The MarginManager tracks the user's risk ratio, which determines liquidation eligibility. If a position becomes undercollateralized, it can be liquidated by any party.
The MarginPool is a lending pool that provides liquidity for margin traders. It consists of:
Suppliers mint a SupplierCap to track their deposits and can withdraw their supplied assets
plus accrued interest at any time, subject to available liquidity.
DeepBook Margin supports conditional orders that automatically execute when price conditions are met:
Conditional orders are stored on-chain and can be executed by anyone (permissionlessly) once the trigger price is reached. This enables automated risk management without requiring users to monitor positions constantly.
A triggered order that can't execute yet stays queued: for example when the order book can't fill it inside the allowed price band, or the manager doesn't hold enough funds. A market order that the book fills only in part stays queued with the unfilled quantity. A conditional limit order is cancelled once it is past its expiry, or if it triggers while the manager is below the liquidation risk ratio.
When a MarginManager's risk ratio exceeds the maximum threshold (position becomes undercollateralized), it becomes eligible for liquidation. Any user can call the liquidate function to:
This mechanism ensures the protocol remains solvent and incentivizes liquidators to maintain system health.
You can install this package in your Move project by calling
mvr add @deepbook/margin-tradingDeepBook Margin extends the trading capabilities of DeepBookV3 by enabling leveraged trading positions. With margin trading, users can borrow funds to increase their buying power.