Aftermath
  • Aftermath
    • About Aftermath Finance
      • What are we building?
  • Getting Started
    • Creating an account
      • zkLogin
        • Removing a zkLogin account
      • Sui Metamask Snap
      • Native Sui wallets
    • Dynamic Gas
    • Navigating Aftermath
      • Interacting with your Wallet
      • Viewing your Portfolio
      • Changing your Settings
      • Bridge
      • Referrals
  • Trade
    • Smart-Order Router
      • Agg of Aggs
      • Making a trade
      • Exact Out
      • Fees
    • DCA
      • Why should I use DCA
      • How does DCA work
      • Tutorials
        • Creating a DCA order
        • Monitoring DCA progress
        • Advanced Features
      • Fees
      • Contracts
  • Limit Orders
    • Contracts
    • Fees
  • Pools
    • Constant Function Market Maker
      • Tutorials
        • Depositing
        • Withdrawing
        • Creating a Pool
      • Fees
      • Contracts
      • Audit
  • Farms
    • Afterburner Vaults
      • Tutorials
        • Staking into a Farm
        • Claiming Rewards
        • Unstaking
        • Creating a Farm
      • Architecture
        • Vault
        • Stake Position
      • Fees
      • FAQs
  • Liquid Staking
    • afSUI
      • Tutorials
        • Staking
        • Unstaking
      • Architecture
        • Packages & Modules
        • Entry Points
      • Fees
      • FAQs
      • Contracts
      • Audit
  • Perpetuals
    • Aftermath Perpetuals
      • Tutorials
        • Creating an Account
        • Selecting a Market
        • Creating a Market Order
        • Creating a Limit Order
        • Maintaining your Positions
      • Architecture
        • Oracle Prices
        • Margin
        • Account
        • Trading
        • Funding
        • Liquidations
        • Fees
  • GameFi
    • NFT AMM
      • Architecture
        • Fission Vaults
        • AMM Pools
      • Tutorials
        • Buy
        • Sell
        • Deposit
        • Withdraw
      • Sui Overflow
  • Our validator
    • About us
  • Developers
    • Aftermath TS SDK
      • Utils
        • Coin
        • Users Data
        • Authorization
      • Products
        • Prices
        • Router
        • DCA
        • Limit Orders
        • Liquid Staking
        • Pools
        • Farms
    • Aftermath REST API
      • Authorization
  • Egg
    • About Egg
  • Legal
    • Terms of Service
    • Privacy Policy
  • Languages
    • 中文
    • 한국어
  • Links
    • X
    • Telegram
    • Discord
    • Github
    • Medium
    • Aftermath Validator
Powered by GitBook
On this page
  • Margin Ratio Formula
  • Initial and Maintenance Margin Ratio (IMR/MMR)
  • Position Margin Requirements
  1. Perpetuals
  2. Aftermath Perpetuals
  3. Architecture

Margin

PreviousOracle PricesNextAccount

Last updated 6 months ago

Margin Ratio Formula

MarginRatio(p)=Collateral(p)⋅CollateralPrice+UnrealizedFundings(p)+Pnl(p) MaxNetBase(p)⋅BasePrice{\small \begin{align*} MarginRatio(p) &= \frac{ Collateral(p) \cdot CollateralPrice + UnrealizedFundings(p) + Pnl(p)\ }{ MaxNetBase(p) \cdot BasePrice } \end{align*} }%MarginRatio(p)​=MaxNetBase(p)⋅BasePriceCollateral(p)⋅CollateralPrice+UnrealizedFundings(p)+Pnl(p) ​​

where

MaxNetBase(p)=max⁡{∣BaseAmount(p)+PendingBids(p)∣,∣BaseAmount(p)−PendingAsks(p)∣}\small MaxNetBase(p) = \max \{ | BaseAmount(p) + PendingBids(p) | , | BaseAmount(p) - PendingAsks(p) | \}MaxNetBase(p)=max{∣BaseAmount(p)+PendingBids(p)∣,∣BaseAmount(p)−PendingAsks(p)∣}

𝑀𝑎𝑥𝑁𝑒𝑡𝐵𝑎𝑠𝑒(𝑝) is motivated as follows: Instead of taking |𝐵𝑎𝑠𝑒𝐴𝑚𝑜𝑢𝑛𝑡(𝑝) + 𝑃𝑒𝑛𝑑𝑖𝑛𝑔𝐵𝑖𝑑𝑠(𝑝) − 𝑃𝑒𝑛𝑑𝑖𝑛𝑔𝐴𝑠𝑘𝑠(𝑝)| , we take the max above, since otherwise a user could place equivalent bids and asks without raising its leverage, thus artificially deepening the order book.

Initial and Maintenance Margin Ratio (IMR/MMR)

The IMR and MMR are set at market creation. These are the inverse of leverage, e.g., an IMR of 0.1 equals a maximum leverage of 10x and an MMR of 0.05 means a position can get liquidated once its leverage reaches 20x.

The owner of the AdminCapability may change these parameters, but the smart contract first stores the new values, so they are visible on-chain, and only updates the actual market parameters after sufficient time has passed (a few days).

Position Margin Requirements

MarginRequirements(p)=MaxNetBase(p)⋅BasePrice⋅IMR {\small \begin{align} MarginRequirements(p) &= MaxNetBase(p) \cdot BasePrice \cdot IMR\ \end{align} }%MarginRequirements(p)​=MaxNetBase(p)⋅BasePrice⋅IMR ​​

To check that the position's margin ratio is above the market's IMR:

{\small \begin{align} MarginRatio(p) &> IMR \\ &\equiv \\ \frac{ Coll(p) \cdot CollPrice + UF(p) + Pnl(p)\ }{ MaxNetBase(p) \cdot BasePrice } &> \frac{ MaxNetBase(p) \cdot BasePrice \cdot IMR\ }{ MaxNetBase(p) \cdot BasePrice } \\ &\equiv \\ \underbrace{ Coll(p) \cdot CollPrice + UF(p) + Pnl(p) }_{\text{margin}(p)} &> \underbrace{ MaxNetBase(p) \cdot BasePrice \cdot IMR }_{\text{margin_requirements}(p)} \end{align} }%

To get the Maintenance Margin Requirements of a position, simply replace 𝐼𝑀𝑅 with 𝑀𝑀𝑅 .