Limit Orders
Limit orders on Mangrove work by creating offers via a shared maker contract called MangroveOrder.
Each user interacts with the system through their own User Router, a contract that holds token approvals and is called by MangroveOrder to transfer tokens when offers are matched.
In essence:
You post an offer to buy or sell tokens at a defined price.
Mangrove matches it when a counter party executes a trade that meets your conditions.
The router handles token transfers securely on your behalf.

Order Types
MangroveOrder supports four types of orders:
GTC (Good Til Cancelled)
Executes a market order up to a given price, then posts any remaining volume as a limit order.
IOC (Immediate or Cancel)
Executes as a market order; any unfilled portion is discarded.
FOK (Fill or Kill)
Executes only if the full order can be filled; otherwise reverts.
PO (Post Only)
Posts directly to the order book without attempting immediate execution.
Note: Each order can have an optional expiry date. When creating an offer, you must deposit a provision (a small amount of collateral). If the offer later fails (e.g. missing approvals), this provision is used as a bounty for the executor. You can withdraw any unused provision once the offer is no longer active.
The offer is consumed as follows:

Creating a User Router
Each user’s router is a deterministic address that is derived from their account. It’s automatically deployed during the first transaction that needs it. Before posting any order, you must grant approval to this router (even before it’s deployed).
For infinite approval logic, see Market orders.
Creating a Limit Order
So let's take a look at an example where we create a Post Only limit buy order, buying 1 ETH with 2500 USDC:
Retracting a Limit Order
To cancel or modify a limit order, you'll need to have its offerId, as well as the market side (BS.buy or BS.sell).
Modifying a Limit Order
In order to modify a limit order, any updateOrder***Params function may be used to build the modification, and then it should call MangroveOrder with those parameters.
Last updated