Liquidity is the lifeblood of DeFi and is crucial for any market to function smoothly. Simply put, liquidity refers to the ability to buy or sell an asset quickly and at a price close to its true value. Liquidity is important for several reasons:
It makes trading a better experience, as transactions can be completed almost instantly.
It helps to stabilize prices and reduce slippage, or the difference between the price you want to pay for an asset and the price you end up paying.
It helps to prevent market manipulation.
In the real world, cash is considered a liquid asset because it can be easily exchanged for goods and services. On the other hand, real estate is not considered a liquid asset because it is difficult to quickly sell and convert into cash. In the crypto world, this concept can be applied to fungible coins with large market caps, which are generally considered much more liquid than NFTs.
The crypto industry has come a long way since the early days when bitcoins were traded for pizzas on online forums. We have witnessed the rise and fall of centralized exchanges such as MtGox, as well as the success of platforms like Binance and Coinbase. Currently, DEXes offer a way for users to trade crypto without the need for a third-party intermediary. In this article, we will explore the evolution of these exchanges, how they have attempted to solve the liquidity problem and what awaits us in the future.
The rise of Automated Market Makers (AMM)
DEXes were among the first blockchain-based applications, and the introduction of AMMs has been a breakthrough in their history. AMMs are algorithms that facilitate trades on DEXs, making it easier for users to buy and sell assets on-chain and increase the liquidity of the crypto markets. Let’s take a closer look at how AMMs work and how they have evolved.
Uniswap, now a DeFi juggernaut, introduced the constant product market maker (CPMM) model and the concept of liquidity pools. The CPMM model calculates the total amount of assets in a liquidity pool using the formula x*y=k, where x is the amount of asset A (e.g. ETH), y is the amount of asset B (e.g. USDC), and k is constant. To withdraw ETH from the pool, a user must deposit an amount of USDC determined by the ratio of total ETH to total USD. While this model has some limitations, including the need for a separate liquidity pool for each asset pair or impermanent loss, it was a major development that helped to kick-start the DeFi revolution.
Slippage is another common issue with AMMs and researchers have been looking for ways to optimize the model to address it. Curve Finance has found a solution to slippage for stable asset pairs such as USDC/USDT or ETH/stETH. Let’s see how it was achieved.
The price discovery mechanism in an AMM can be represented by a function, with the price of the assets shown as a point on this function. The CPMM model used by Uniswap (purple dashed line) is more sensitive to changes in the pool's reserves, resulting in a more curved function. On the other hand, in a pool where the price changes evenly (i.e. the withdrawal of token A causes the price of token B to change by the same amount), the function is linear (red dashed line). In this case, the sum of the prices of both assets is always constant. Curve elegantly combines the constant product and constant sum models in a way that the function is linear when the supply of coins is balanced but becomes more curved when there is a greater disparity in the reserves. This is the solution that allows the protocol to offer better prices for trades between stable assets.
Uniswap v3, released in May 2021, brought many improvements to the CPMM model, including the ability for liquidity providers to choose the price range in which they want to provide liquidity. In earlier versions, liquidity was evenly split across the entire curve, which resulted in underutilization of capital as trades often did not take place at the farthest points of the curve. With the ability to choose their price range, liquidity providers can now more effectively earn fees by providing liquidity in areas where it is most needed. This enhancement has significantly improved the capital efficiency of the AMM model.
Oracle-based DEXes
Oracle-based DEXes have attempted to address the issue of slippage by using external smart contracts that provide real-world data to blockchain apps. Bancor and GMX are examples of oracle-based DEXes that use this approach. Bancor uses a unique formula to determine the price of each asset in its liquidity pools, which is based on oracle-fed data. GMX, a perpetual exchange that also has a liquidity pool to trade blue-chip assets, uses Chainlink oracles to feed prices from centralized exchanges, thus enabling trading with no slippage.
While this is positive for traders, it leaves the protocol vulnerable to price manipulation. There have been several instances of oracle exploits, including a recent one on GMX in which an attacker manipulated the price of AVAX on centralized exchanges while simultaneously opening and closing long/short positions on GMX and costing liquidity providers an estimated $500 million.
Oracle-based price discovery relies on a third-party provider, which may not always be decentralized and could be exploited even if it functions flawlessly. This approach also does not solve the liquidity problem but rather avoids addressing it. Because of these issues, an oracle-based system is not a scalable and sustainable long-term solution for DEXes.
Will order book DEXes dominate DeFi?
AMMs and oracle-based DEXes have had their limitations, leading many in the industry to consider the potential for order book-based DEXes. Order book-based exchanges, such as Binance, and Coinbase are traditional centralized exchanges that use market makers to provide liquidity for their users. While the order book model is the standard for centralized exchanges, it hasn't been feasible for blockchain-based exchanges due to high transaction fees and low throughput.
There are currently only a few DEXes implementing the order-book model, such as dYdX, Solana's Serum (which rebranded as OpenBook after the FTX collapse), and Demex running on Cosmos' chain Carbon. However, the potential for order book-based DEXes to eventually take over the market has never been more appealing as the technology continues to progress.
The price discovery mechanism in an AMM can be represented by a function, with the price of the assets shown as a point on this function. The CPMM model used by Uniswap (purple dashed line) is more sensitive to changes in the pool's reserves, resulting in a more curved function. On the other hand, in a pool where the price changes evenly (i.e. the withdrawal of token A causes the price of token B to change by the same amount), the function is linear (red dashed line). In this case, the sum of the prices of both assets is always constant. Curve elegantly combines the constant product and constant sum models in a way that the function is linear when the supply of coins is balanced but becomes more curved when there is a greater disparity in the reserves. This is the solution that allows the protocol to offer better prices for trades between stable assets.
Uniswap v3, released in May 2021, brought several improvements to the CPMM model, including the ability for liquidity providers to choose the price range in which they want to provide liquidity. In earlier versions, liquidity was evenly split across the entire curve, which resulted in underutilization of capital as trades often did not take place at the farthest points of the curve. With the ability to choose their price range, liquidity providers can now more effectively earn fees by providing liquidity in areas where it is most needed. This enhancement has significantly improved the capital efficiency of the AMM model.
Oracle-based DEXes
Oracle-based DEXes have attempted to address the issue of slippage by using external smart contracts that provide real-world data to blockchain apps. Bancor and GMX are examples of oracle-based DEXes that use this approach. Bancor uses a unique formula to determine the price of each asset in its liquidity pools, which is based on oracle-fed data. GMX, a perpetual exchange that also has a liquidity pool to trade blue-chip assets, uses Chainlink oracles to feed prices from centralized exchanges, thus enabling trading with no slippage.
While this is positive for traders, it leaves the protocol vulnerable to price manipulation. There have been several instances of oracle exploits, including a recent one on GMX in which an attacker manipulated the price of AVAX on centralized exchanges while simultaneously opening and closing long/short positions on GMX and costing liquidity providers an estimated $500 million.
Oracle-based price discovery relies on a third-party provider, which may not always be decentralized and could be exploited even if it functions flawlessly. This approach also does not solve the liquidity problem but rather avoids addressing it. Because of these issues, an oracle-based system is not a scalable and sustainable long-term solution for DEXes.
Will order book DEXes dominate DeFi?
AMMs and oracle-based DEXes have had their limitations, leading many in the industry to consider the potential for order book-based DEXes. Order book-based exchanges, such as Binance, and Coinbase are traditional centralized exchanges that use market makers to provide liquidity for their users. While the order book model is the standard for centralized exchanges, it hasn't been feasible for blockchain-based exchanges due to high transaction fees and low throughput.
There are currently only a few DEXes implementing the order-book model, such as dYdX, Solana's Serum (which rebranded as OpenBook after the FTX collapse), and Demex running on Cosmos' chain Carbon. However, the potential for order book-based DEXes to eventually take over the market has never been more appealing as the technology continues to progress.
The provision (3) serves as a safeguard against market makers posting empty offers or spamming the exchange with offers that will never be fulfilled. It compensates offer takers for gas costs incurred when a maker decides or is forced to cancel an offer after a match, which can occur due to changing market conditions or the unavailability of the traded asset on the maker's side.
Later, when an offer is matched with a buy order, the callback function (4) is called twice. First, it is used to provide the asset for the trade, and then, after the trade is executed, to replenish the offer if the market maker has indicated this in the offer code. This helps to reduce the number of transactions needed to fill the order book, which in turn helps the protocol scale more efficiently.
On Mangrove, offer takers have the option to use a market order or a snipe when trying to fulfill a specific offer. A market order allows the taker to specify the highest price they are willing to pay for the offer, similar to a limit order on a traditional exchange. However, Mangrove does not offer a market order in the traditional sense, which is an order to buy a certain amount of an asset at the best available price. This is to protect users from MEV attacks, such as frontrunning or sandwiching.
The process of posting bids and asks on the exchange, including the actions of Mangrove's main smart contract, is illustrated in the following diagram:
Keeper bots, while not shown in the diagram, are a crucial part of maintaining the integrity of the Mangrove order book. These bots are responsible for calling offers that are likely to fail and collecting the provision paid by the maker. This incentivizes third parties to deploy bots that scan and clean the exchange's order book. The provision is always calculated using the upper gas bound, making it profitable for keepers to keep the order book organized. Overall, keepers are essential for ensuring that using Mangrove is a seamless and enjoyable experience.
When it comes to governance, Mangrove will issue a token. The specifics of the tokenomics have not yet been disclosed, but a portion of the initial supply will likely be allocated to outside investors. Once the token is released, Mangrove token holders will have the ability to vote on various aspects of the protocol, including potential incentives for liquidity providers or offer takers to use the platform. The Mangrove community will also be able to vote on which blockchains the protocol should expand to or build protocols on top of Mangrove (as the community does with Curve or GMX).
Navigating Mangrove's potential risks and uncertainties
While Mangrove is a promising new protocol, it is not guaranteed to succeed. There are a few potential challenges that the DEX may face. One question is whether the Polygon will be able to handle the high level of throughput required for a fully on-chain order book-based DEX. dYdX has argued that even L2s may not be able to support the scale of the order book and matching engine. One specific issue that may be difficult to manage at a reasonable cost is the need for constant order updates due to nonstop price changes. Mangrove addresses this issue by allowing for updates to be made in a single transaction, eliminating the need to cancel and repost offers.
Mangrove team surely has thoroughly researched this aspect and determined that Polygon is suitable for their needs. It's worth noting that other protocols that require a large amount of data and transactions, such as Lens Protocol (a decentralized social media platform), have also chosen Polygon as their home blockchain. If it turns out that using Polygon does not guarantee a smooth experience, there are always other L2 EVMs available as an alternative.
Another potential risk for Mangrove is the possibility of malicious code being attached to an offer due to the platform's fully permissionless market making. To address this concern, Mangrove contracts have undergone thorough auditing by Chainsecurity, which did not find any critical vulnerabilities in the code. While this does not guarantee the security of the protocol, it is a positive sign that the protocol has been well-designed.
Wrapping up
Any healthy market needs to have strong liquidity. Currently, the most popular liquidity provision methods have their drawbacks:
AMMs often have high slippage, are generally not capital efficient, and spread capital across many pools.
Oracle-based exchanges do not scale well, are at risk of market manipulation, and have no price discovery mechanism.
Centralized exchanges aren’t either transparent or trustless, and don’t offer capital efficiency for market makers.
With these factors in mind, it is safe to say that bringing the order book model onto the blockchain presents a significant opportunity and will be one of the major narratives in the DeFi space in the coming months and beyond. Many competing projects will be trying to solve the challenges of operating an order book on the blockchain, but the first to succeed will have the chance not only to disrupt the current DEX model, but potentially make centralized exchanges obsolete in the longer term.
Mangrove, with its highly capital-efficient "code-is-offer" feature, is uniquely positioned to address all the pain points that both centralized and decentralized exchanges face. It probably will not be an overstatement to say that this is a once-in-a-lifetime disruption opportunity.