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:
Offer makers add liquidity promises to Mangrove.
Takers use Mangrove to find liquidity by executing market orders and thereby executing offers published on Mangrove.
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.
Governance adjusts Mangrove parameters such as setting fees or opening and closing markets.
Takersβ
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.
Makersβ
Makers own offers, which live in offer lists in the Mangrove order book.
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β
Smart offers are where Mangrove really distinguishes itself from other DEXes, so we shall discuss them in a bit more detail in this overview.
The offer logic of the maker contract is called twice by the Mangrove protocol during trade execution: when the smart offer is taken and after the smart offer was taken.
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β
Mangrove calls the offer logic of the maker contract a second time, via the callback function makerPosthook
during trade execution immediately after the offer has been 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.
Governanceβ
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.