Market Making
Anyone is welcome to provide liquidity on a level playing field. There are no advantages given to any specific parties. Market trades, limit order placement, and limit order cancelation all emit events containing the price, size, maker, and order id if applicable. Individual limit order fills do not emit an event, the market trade which fills the order emits one instead. The fallback function is designed as a gas-optimized endpoint for market makers, featuring order batching with reduced calldata size. In order to utilize this, the registerUser function must be first called once on every unique address, note that this is not necessary for regular traders. Market orders placed using the fallback function automatically self-refer to receive the maximum fee discount and do not disqualify the user from any incentive programs. The creation of a referral code is not necessary to take advantage of this feature.
Calculating Limit Price
The limit price is equal to the quote asset in its smallest denomination multiplied by the scale factor divided by the base asset amount in its smallest denomination. For example, with an ETH/USDC market with a scale factor of 10^13, the price of 3,001.1 USDC per ETH would be represented as 30,011, as ETH has 18 decimals and USDC has 6, so (3,001.1 * 10^6) * 10^13 / (1 * 10^18) = 30,011.
For markets of any marketType other than 0, precision is fixed at up to five significant figures. For example, 3,293.1 is a valid price and so is 0.00012342, but 111,233 is invalid as is 0.0149283. Scaling is the same as with other markets, so on a MON/USDC market with scale factor 10^21, the price 3.2871 USDC per MON is represented as 3287100000. Note that in this case, 3287110000 would be an invalid price point as it has six significant figures.
Gas Optimization
Unlike many centralized alternatives, Crystal is fully onchain, and that means that market makers must pay gas to place and cancel orders. Transactions on Monad are extremely cheap, and gas should not be too much of an issue. That said, there are several things that can be done to quote more efficiently:
Use client order id orders: In addition to the ability to cancel in-flight orders, attaching a client order id allows your order to reuse a storage slot, saving gas
Use internal balances: Using internal balances saves gas as tokens don't have to be seperately sent on every order placement/cancellation
Use an access list: Due to Monad's architecture, the cost of cold storage access is significantly increased. By using an access list with your transaction, the cost can be significantly reduced. It is recommended to include the storage slot of the market, storage slot of your order, storage slot of the price level, and storage slot of your balances in your access list when placing/canceling an order
Batch orders across markets: You can batch multiple actions in a single call to the fallback endpoint. You can also batch interactions with multiple markets in a single transaction. This saves significant amounts of gas as much of the storage across markets is shared. You can also specify whether to revert or continue on each action failure for the active batch. Multiple batches can be used in a single transaction to a single market as well
MEV Bribe endpoint: By adding a msg.value, you can specify a MEV bid for validators to prioritze your transactions. These bids will only be paid if the function call succeeds. Multiple function calls can be made in a single transaction, each with their own individual bid to be paid out conditionally. Note that due to Monad's asynchronous architecture, validators may not have the ability to simulate all transactions and therefore bids do not guarantee priority inclusion
For any questions or clarifications, feel free to contact our team through our Discord.
Last updated