Mai3 Contracts

Mai Protocol V3 (MCDEX v3) is a binary smart contract system comprised of several libraries. EX: Pool Creator, Liquidity Pool, Perpetual, Getter


PoolCreator creates and manages all LiquidityPool.
Every liquidity pool will be created by the trader who wants to be the operator through createLiquidityPool in the deployed PoolCreator contract.
Since the design of MCDEX v3 is totally follow the rule of 'Permissionless', the pool creator does not directly manage the implementation (contract) of liquidity pools, but supplies different implementations for operators to create with.
Pool creator also manages global variables for all created liquidity pools.


In MCDEX v3, a single liquidity pool is able to provide liquidity for multiple perpetuals using the same collateral with liquidity pool. This is so called 'shared liquidity pool'.
By default, all the trades will happen between trader and liquidity pool, which means the liquidity pool (AMM) will act as counterparties to the traders.
Liquidity provider who wants to earn trading fees can add or remove liquidity to the pool. Unlike traders, liquidity providers do not hold position directly and not have margin accounts.
Liquidity provider will receive share tokens in return which is used in voting system.


A perpetual, like a market, defines the rule of trade and stores the status of market and the data of traders.
Every trader to trade in the perpetual have a margin account to store personal information. Trader can deposit to or withdraw from the margin account, then trade in the perpetual.
*To avoid call overhead between different contract, the perpetual and liquidity pool are just different data storage in the same contract. Therefor, we use a tuple of liquidity pool address and index of data storage in liquidity pool to uniquely identify a perpetual.


Like mentioned in previous sections, LiquidityPool, Perpetual and Accounts are important for traders. In order to get all related information, using Getter object to interact with MCDEX V3.

Mai Protocol V3