Overview of Mangrove's ecosystem
The illustration below depicts a bird's-eye view of the Mangrove ecosystem. The main actors are depicted as well as their most important interactions.
The Mangrove contract is depicted in the middle, with the three most important actors interacting with Mangrove around it:
Cleaners identify offers that will fail to deliver the promised liquidity and clean them, i.e. remove them from the book in exchange for a bounty.
As a taker on Mangrove you take offers published by makers as liquidity promises. Offers are taken using market orders.
Takers typically operate via a web front-end or with the help of the TypeScript SDK for developing off-chain apps to interact with the Mangrove ecosystem.
As a maker you have the choice of posting two kinds of offers:
- On-the-fly offers posted directly from an EOA. Such offers have no logic attached, and the promised liquidity should be available on the EOA, when the offer is matched during a trade.
- Smart offers posted via a smart contract - called a maker contract. When a smart offer is matched by a market order during trade execution, the maker contract will be called and given the opportunity to execute its offer logic.
Smart offers are where Mangrove really distinguishes itself from other DEXes, so we shall discuss them in a bit more detail in this overview.
When a smart offer is taken
Mangrove calls the offer logic of the maker contract a first time, via the callback function
makerExecute, when an offer is matched by a market order. This happens immediately prior to trade settlement allowing makers to source liquidity reactively and just-in-time for the trade. It also allows makers to renege on the offer to trade by incorporating defensive code (called last look) in the maker contract (e.g., because the market conditions changed).
This implies that offers posted to Mangrove need not be fully provisioned. As a maker, your liquidity can be shared, borrowed, lent, and, at the same time, be displayed in Mangrove's order book - ready to be sourced when, and only when, your offer is taken.
After a smart offer is taken
This allows makers to, for instance, post another offer to redisplay their liquidity instantly, in a manner similar to Automated Market Makers (AMMs).
Call sequence overview
The diagram below summarizes the call sequence induced by a market order. Notice that first the
makerExecute functions is executed for all offers, and only subsequently are the
makerPosthook functions of the offers executed.
Where can I read more?
- The concepts of ticks and ratio are crucial in Mangrove - you'll want to get familiar with them first.
- Refer to the section on Creating and Updating Offers.
- Read more about Offer Execution on Mangrove.
- Read about the freely available Strat Library - a repository of Solidity code to help write your own custom maker contract.
- Read about the TypeScript SDK for developing off-chain apps to interact with Mangrove ecosystem.
Literate source code
The Mangrove core protocol is commented in the tradition of literate programming where natural language and code is intervowen. Thus, the protocol code itself actually constitutes a very readable and comprehensive technical documentation.
A nicely formatted, single webpage representation of the literate source code can be found here.
The Mangrove Governance may set a number of parameters, which governs how Mangrove operates globally or for specific pairs. Refer to the section on Governance Parameters for details.