# Table of Contents - [Introduction | Perpl Docs](#introduction-perpl-docs) - [Order Book | Perpl Docs](#order-book-perpl-docs) - [Architecture | Perpl Docs](#architecture-perpl-docs) - [Margin | Perpl Docs](#margin-perpl-docs) - [Liquidation | Perpl Docs](#liquidation-perpl-docs) - [Fees | Perpl Docs](#fees-perpl-docs) - [Insurance & ADL | Perpl Docs](#insurance-adl-perpl-docs) - [Price Indices | Perpl Docs](#price-indices-perpl-docs) - [Order Types | Perpl Docs](#order-types-perpl-docs) - [Trading Perpetuals on Perpl | Perpl Docs](#trading-perpetuals-on-perpl-perpl-docs) - [Funding | Perpl Docs](#funding-perpl-docs) --- # Introduction | Perpl Docs ### [](https://docs.perpl.xyz/#what-is-perpl) What is Perpl? Perpl is a high-performance, decentralized, perpetual futures (perps) exchange handcrafted for Monad EVM. Monad is an open, permissionless, geographically distributed blockchain (L1) that provides fast finality and 100% EVM-compatibility. Perps just need a price oracle and a stablecoin for margin. They allow traders and speculators to take positions in crypto assets with leverage. Unlike traditional derivatives, they don't have an expiration, which fosters deeper liquidity in markets. See our blog on [perpetual future contracts](https://blog.perpl.xyz/what-are-perps-perpetual-futures-contracts/) . ### [](https://docs.perpl.xyz/#why-another-perp-dex) Why another Perp DEX? Centralized exchanges (CEX) and decentralized exchanges (DEX) are the two types of exchanges that offer perps. CEXs have good UX, but have onerous KYC/AML requirements and custodial risk. DEXs are self-custodial and enable global, permissionless trading, but they have relied on slower, decentralized infrastructure. See our blog on the differences between [decentralized vs. centralized exchanges](https://blog.perpl.xyz/decentralized-vs-centralized-exchanges/) . The early DEX era was dominated by AMMs, not because they were better, but because L1 infrastructure couldn’t support performant order books. Teams eventually pivoted to “app-chains” to run central limit order books (CLOBs). However, they couldn’t enter new markets as quickly as CEXs because they relied on external MMs. See our blog on the differences between [AMMs vs. CLOBs](https://blog.perpl.xyz/order-books-vs-automated-market-makers-amms/) . ![](https://docs.perpl.xyz/~gitbook/image?url=https%3A%2F%2F809468657-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FXVKhDpsjDZo7VFt2Qfew%252Fuploads%252Fz4JKCUgMcHMslImp9Z2x%252Fimage.png%3Falt%3Dmedia%26token%3D05fa827b-5aaa-419c-b494-268b492364d6&width=768&dpr=4&quality=100&sign=dd8f5901&sv=2) Pooled liquidity vaults, pioneered by GMX (GLP), provide liquidity to AMM-based markets with relatively simple strategies. However, CLOB-based perp DEXs require active liquidity management. This is where Hyperliquid's HLP changed the game for bootstrapping CLOB-based perp DEXs. However, there are centralized points of failure and other risks when a single team operates the exchange, vault, and blockchain. We believe the optimal combination is a performant on-chain DEX built on a standalone high-throughput L1, and bootstrapped by independently operated vaults. ### [](https://docs.perpl.xyz/#true-decentralization-optimal-ux) True Decentralization, Optimal UX The holy grail of DeFi is **a fully on-chain perp DEX with CEX-like trading experience on EVM**. Perpl, built on the Monad L1, is positioned to achieve this ideal while honoring the boundaries between protocol, liquidity, and infrastructure. Unlike other DEXs on L1s that use AMMs or off-chain matching, everything on Perpl happens on-chain. The exchange, matching, and settlement runs **entirely on-chain with no off‑chain or centralized points of failure**. See our blog on [on-chain perps](https://blog.perpl.xyz/onchain-perps-balancing-profit-vs-peril/) . ![](https://docs.perpl.xyz/~gitbook/image?url=https%3A%2F%2F809468657-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FXVKhDpsjDZo7VFt2Qfew%252Fuploads%252FVFiEe80ZEZyU9vV7DyAU%252Fimage.png%3Falt%3Dmedia%26token%3D8e8ddec2-09b9-42c2-a432-e1b137756dcb&width=768&dpr=4&quality=100&sign=e8585682&sv=2) Building a DEX is hard; building a DEX on a blockchain you don't control/operate is even harder. However, we're building Perpl to be anti-fragile, scalable, and to leverage the benefits of composability. We have hyper-optimized the exchange on a specific vector: <100k gas for market-maker post+cancel. Every GWEI of gas matters because more gas costs = fewer market maker updates = wider quotes = worse fills for the end-user. ![](https://docs.perpl.xyz/~gitbook/image?url=https%3A%2F%2F809468657-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FXVKhDpsjDZo7VFt2Qfew%252Fuploads%252FzU4pPELdwEPi8DHopKxq%252Fimage.png%3Falt%3Dmedia%26token%3D4a1cb348-4bc0-495b-9525-77bdb975f5fa&width=768&dpr=4&quality=100&sign=35762406&sv=2) [NextArchitecture](https://docs.perpl.xyz/exchange/architecture) Last updated 11 days ago --- # Order Book | Perpl Docs The order book is a real-time on-chain record of all open buy and sell orders for any given market. * **Limit Orders**: Rest on the book until matched or canceled. Specified with price and quantity. * **Market Orders**: Execute immediately against the best available orders in the book * **Priority**: Orders are matched based on best price first, then earliest submission time * **Visibility**: the order book is entirely on-chain, meaning anyone can verify the order state at any time without relying on a central operator. #### [](https://docs.perpl.xyz/exchange/order-book#architecture) Architecture Our order book is the most gas-performant primitive achievable on EVM. A post-and-cancel order costs 100k gas, including solvency checks. For context, a simple Uniswap V2 AMM swap costs 200k gas. The key design objective was to minimize gas for market maker post + cancel, as that is the most common operation. Perpl achieves O(1) constant time for post, O(1) constant time for cancel, and O(N) linear time for matching. ![](https://docs.perpl.xyz/~gitbook/image?url=https%3A%2F%2F809468657-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FXVKhDpsjDZo7VFt2Qfew%252Fuploads%252FdlunUoW3HyojD6Z36Bqh%252Fimage.png%3Falt%3Dmedia%26token%3D8868848e-649a-4b77-bb57-0378e97df70c&width=768&dpr=4&quality=100&sign=9a012f2e&sv=2) Figure 1: Order book design consisting of two bit-index trees and a partition map list #### [](https://docs.perpl.xyz/exchange/order-book#price-levels) Price Levels The order book is extremely granular, allowing for more than 16M price levels, so large assets like Bitcoin can be potentially quoted in dimes ($0.10) increments. One bit-index tree is a three-level, 256-bit-word index of prices that contain orders in the partition map list. It allows for quick discovery of the next price above or below a specified price in a gas-efficient manner. ![](https://docs.perpl.xyz/~gitbook/image?url=https%3A%2F%2F809468657-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FXVKhDpsjDZo7VFt2Qfew%252Fuploads%252F5Kv2EdwhT1xt6FXt4k9b%252Fimage.png%3Falt%3Dmedia%26token%3D83c5e890-9276-43ad-bcc8-1ff5c687a091&width=768&dpr=4&quality=100&sign=1d22df38&sv=2) Figure 2: Bit-Index tree with 4-Bit words showing 64 price-levels mapped to start at $100.0 in increments of $0.5. #### [](https://docs.perpl.xyz/exchange/order-book#order-ids) Order IDs The other bit-index tree is a two-level, 256-bit-word index of order IDs, allowing more than 65k orders per contract. It also functions as an order ID counter for the perpetual contract’s CLOB, assigning unique order IDs to each new order. To mitigate DDoS attacks on the order book, we have designed a permissioned order cancellation system. When the number of available orders falls below a given threshold, the backend can cancel orders that are a configurable distance from the maximum bid or minimum ask prices. ![](https://docs.perpl.xyz/~gitbook/image?url=https%3A%2F%2F809468657-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FXVKhDpsjDZo7VFt2Qfew%252Fuploads%252Ff5t0vHvklpSy9G4xC7Ln%252Fimage.png%3Falt%3Dmedia%26token%3Df4f39b98-f9f3-4f46-b607-112004cd1d7c&width=768&dpr=4&quality=100&sign=8485e215&sv=2) Figure 3: Order book bid and ask levels showing region where permissioned cancel is possible when number of orders exceeds permissionless cancel threshold. #### [](https://docs.perpl.xyz/exchange/order-book#time-in-force-expiry-blocks-and-recycle-fees) Time in Force: Expiry Blocks and Recycle Fees For non-immediate orders, the time in force can be specified with an expiry block, so the order automatically expires after the specified block. Orders with an expiry block require the issuer to pay an order recycling fee. This fee is refunded if the order is completely filled or canceled by the issuer. If the order has expired and another market participant encounters the expired order in a traversal of the order book, the recycling fee is paid to this participant as compensation for clearing the order. Recycling fees can be configured at run time and changed during operation. The ability to change recycling fees allows tuning the incentive to match current market conditions — higher recycling fees when many orders are impeding market transactions or when gas costs are high. #### [](https://docs.perpl.xyz/exchange/order-book#change-order-efficient-cancel-post) Change Order: Efficient Cancel-Post Market makers can quote orders with tighter spreads—the distance between the bid and ask prices—when the cost of canceling and reposting orders is reduced. Tighter spreads are attractive because they mean that the DEX is better able to compete with centralized solutions on price. As prices move, market makers cancel existing orders and post new ones to follow price movements. This is inefficient in an on-chain exchange because it implies deallocation of storage for the canceled order and allocation of new storage for the newly posted order. Figure 1 above shows how order storage and order IDs can be shared across different price levels, from m+4 down to m-3. Shared storage allows order storage to be moved to effect a price change, rather than being inefficiently deallocated and subsequently reallocated. Rather than submitting two transactions, a single transaction, “Change”, replaces Cancel and Post transactions. If the market maker is only changing the lot size or expiry block of an order, then the operation uses less gas as it does not need to move the order storage to a new partition. The change operation would move the order to the end of the current price partition's list if the order's lot size is increased or the expiry block is changed (the order is not moved to the end of the list if the lot size is decreased). [PreviousArchitecture](https://docs.perpl.xyz/exchange/architecture) [NextMargin](https://docs.perpl.xyz/exchange/margin) Last updated 0 minutes ago --- # Architecture | Perpl Docs Perpl’s protocol architecture consists of multiple on-chain systems that work in tandem to deliver the highest-quality perp trading experience. ![](https://docs.perpl.xyz/~gitbook/image?url=https%3A%2F%2F809468657-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FXVKhDpsjDZo7VFt2Qfew%252Fuploads%252FDe5GC13pb5yPQbsdnmPM%252FperpsOnly.png%3Falt%3Dmedia%26token%3D9c41717b-10fe-4d36-b3f8-75e47a1641f0&width=768&dpr=4&quality=100&sign=1f31eb7d&sv=2) These systems include: 1. **Order book**: to match buy and sell orders using price-time priority. Every trade is matched and settled on-chain. 2. **Margin**: validates collateral, ensuring that traders always have sufficient funds to open and maintain a trade. 3. **Liquidation System**: continuously monitors positions and triggers liquidation when accounts fall below maintenance margin. 1. **ADL & Insurance Fund**: protects protocol from large trading anomalies and helps protect traders from large market fluctuations. 4. **Funding Rate**: periodic (hourly) payment exchanged between long and short traders to ensure that the price of the perp aligns with the actual price index of an asset. 5. **Price Index**: aggregate and process external spot price data from multiple exchanges to generate an accurate index price. We will dive deeper into each of these concepts in the rest of the documentation. [PreviousIntroduction](https://docs.perpl.xyz/) [NextOrder Book](https://docs.perpl.xyz/exchange/order-book) Last updated 10 days ago --- # Margin | Perpl Docs The margin engine ensures that users who place trades always have the necessary capital requirements to open and maintain their intended positions. * **Initial Margin**: The amount required to open a position; calculated as a percentage of notional value based on the asset’s risk profile. * **Maintenance Margin**: Minimum collateral required to keep a position open; if breached, liquidation is triggered Initial margin requirements on Perpl are dynamic and may vary by market, depending on volatility and position size. ### [](https://docs.perpl.xyz/exchange/margin#margin-mode) Margin Mode The difference between a cross and an isolated margin is: * **Isolated Margin**: Each position has its own margin * **Cross Margin**: All collateral in the account is shared across positions * **Hybrid Margin**: Manually manage margin between positions To begin with, Perpl will be restricted to isolated margin. ![](https://docs.perpl.xyz/~gitbook/image?url=https%3A%2F%2F809468657-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FXVKhDpsjDZo7VFt2Qfew%252Fuploads%252FT0Wu8pWV98wymIzdfmLk%252Fimage.png%3Falt%3Dmedia%26token%3D3394098b-112d-466d-9014-73f294aa976f&width=768&dpr=4&quality=100&sign=a8167578&sv=2) ### [](https://docs.perpl.xyz/exchange/margin#position-equations) Position Equations Perpetual contracts can be implemented using the following representation of lot sizes, L: * {L : L > 0, L ∈ Z} #### [](https://docs.perpl.xyz/exchange/margin#position-notional-value-n) **Position Notional Value,** _**N**_**:** N\=P⋅LN = P · LN\=P⋅L _P = The mark, entry, or realized price, depending on whether or not the value being calculated is unrealized, position, or realized notional value, respectively. L = The position lot size (the number of contracts of the position)._ #### [](https://docs.perpl.xyz/exchange/margin#position-margin-requirement-mr) **Position Margin Requirement,** _**MR**_**:** MR\=N/MFMR = N/MFMR\=N/MF _N = The position notional value. MF = The margin fraction (analogous to leverage)._ #### [](https://docs.perpl.xyz/exchange/margin#position-initial-margin-requirement-imr) **Position Initial Margin Requirement,** _**IMR**_**:** IMR\=N/IMFIMR = N/IMFIMR\=N/IMF _N = The position notional value. IMF = Initial margin fraction (maximum leverage allowed to open a position)._ #### [](https://docs.perpl.xyz/exchange/margin#position-maintenance-margin-requirement-mmr) **Position Maintenance Margin Requirement,** _**MMR**_**:** MMR\=N/MMFMMR = N/MMFMMR\=N/MMF _N = The position notional value. MMF = Maintenance margin fraction (minimum collateralization permitted before a position can be liquidated)._ ### [](https://docs.perpl.xyz/exchange/margin#margining-criteria) Margining Criteria The price used to determine the notional value in the invariants presented in this section is the most accurate price available. For example, the best price to use for the notional value of a new position is the price at which the position is entered (realized). In some situations, for example, auto-deleveraging a position, a realization price is not available, and the failed position’s bankruptcy price is used. In other situations, the mark or synthetic perpetual price may be used to calculate the position's fair market value (for the value of an existing position). #### [](https://docs.perpl.xyz/exchange/margin#collateralization-for-establishing-or-changing-a-position) Collateralization for establishing or changing a position: FMV\>\=IMRFMV >= IMRFMV\>=IMR _FMV = Position fair market value. IMR = Position initial margin requirement._ #### [](https://docs.perpl.xyz/exchange/margin#collateralization-for-liquidation) Collateralization for liquidation: 0iF\_{sum}\[j\] = \\begin{cases} 0, & j \\leq i \\\\ \\sum\_{j=i}^{N} F\_{product}\[j\], & j > i \\end{cases} Fsum​\[j\]\={0,∑j\=iN​Fproduct​\[j\],​j≤ij\>i​ _F__product__\[j\] = Funding product for funding event at block number j. j = funding event block number. i = Perpetual contract creation block number._ A funding product of a particular block can be determined by subtracting any two adjacent funding sums, as shown in the equation below: Fproduct\[j\]\=Fsum\[j\]−Fsum\[j−k\]F\_{product}\[j\] = F\_{sum}\[j\] − F\_{sum}\[j − k\]Fproduct​\[j\]\=Fsum​\[j\]−Fsum​\[j−k\] _F__sum__\[j\] = Funding product sum for funding event. F__sum__\[j − k\] = Funding product sum for previous funding event. j = funding event block number. k = The number of blocks in a funding interval._ Substituting equation Fproduct into equation Fpayment, the funding payment for a position that has been held through a single funding event at block j, can be computed: Fpayment\[j\]\=(Fsum\[j\]−Fsum\[j−k\])⋅LF\_{payment}\[j\] = (F\_{sum}\[j\] − F\_{sum}\[j − k\]) · LFpayment​\[j\]\=(Fsum​\[j\]−Fsum​\[j−k\])⋅L _F__sum__\[j\] = Funding product sum for funding event. F__sum__\[j − k\] = Funding product sum for previous funding event. j = funding event block number. k = The number of blocks in a funding interval. L = Position lot size._ Observing that equation _F__payment_ only depends on the lot size and side (long or short) of a position, it is possible to extend the solution to compute funding payments cumulatively owed for a position held through multiple events. For example, consider a position held through 3 funding events, up to and including a funding event at block j. Its cumulative funding payment could be computed as follows: Fpayment\[j\]\=(Fsum\[j\]−Fsum\[j−3k\])⋅LF\_{payment}\[j\] = (F\_{sum}\[j\] − F\_{sum}\[j − 3k\]) · LFpayment​\[j\]\=(Fsum​\[j\]−Fsum​\[j−3k\])⋅L _F__sum__\[j\] = Funding product sum for funding event. F__sum__\[j − 3k\] = Funding product sum for the three funding events prior. j = funding event block number. k = The number of blocks in a funding interval. L = Position lot size._ Importantly, notice that the cumulative funding payment owed can be determined in only two read operations. An important gas efficiency. Furthermore, the value of the funding payment need not be written to the chain until the entire position settles, bypassing the problem of immediate explicit settlement. Thus, the generalized solution to compute any position’s cumulative funding payment, which can also be expressed as its premium PNL, θpnl, is: θpnl\=Fpayment\[j\]\=(Fsum\[j\]−Fsum\[m\])⋅Lθ\_{pnl} = F\_{payment}\[j\] = (F\_{sum}\[j\] − F\_{sum}\[m\]) · Lθpnl​\=Fpayment​\[j\]\=(Fsum​\[j\]−Fsum​\[m\])⋅L _F__sum__\[j\] = Funding product sum for funding event. F__sum__\[m\] = Funding product sum for funding event prior to position creation. j = funding event block number. m = The funding event block number for the funding event prior to position creation. L = Position lot size._ [PreviousInsurance & ADL](https://docs.perpl.xyz/exchange/liquidation/insurance-and-adl) [NextPrice Indices](https://docs.perpl.xyz/exchange/price-indices) Last updated 4 days ago ---