Original Author: Markus Schmitt
Original Translator: Luffy, Foresight News
Smart contract blockchains are ideal for running exchanges: they commoditize trust, make custody, fees, pricing, and settlement transparent, and allow anyone to become a market maker.
However, decentralized exchanges (DEXs) still lag behind centralized exchanges (CEXs) in trading volume, due to: uncompetitive pricing; easy exploitation of execution (MEV); LPs not making enough money yet.
Improvements will make DEXs more attractive: using oracles for pricing; batch trading and post-trade settlement; centralized and automated liquidity; moving to cheaper L2s. We also list some teams working in this space trying to address the problems we raise.
DEXs are one of the primary use cases for smart contract blockchains. They are often criticized for being gambling dens of shitcoins, but the mechanism of permissionless token listing has immense value regardless of the speculation it may cause.
The current cryptocurrency exchange landscape consists of OTC, CLOB (Central Limit Order Book), RFQ (Request for Quote), and AMM (Automated Market Maker) models.
AMMs have evolved into the primary use case for creating trading markets without the need for professional market makers. But CLOBs are still the main source of trading volume (DEX trading volume only accounts for 16% of CEXs, and over 60% of DEX trading volume is driven by MEV, including arbitrage between CEXs and DEXs).
DEXs still only account for around 15% of cryptocurrency trading volume. But their share is growing. Source: Coingecko Q1 2023 Industry Report
In this article, we will first clarify what makes a good exchange, and then we will focus on the current shortcomings of DEXs and propose some paths to improve DEX design.
What makes a good exchange?
As a trader, what do I need:
Trust: custody risk before, during, and after the trade should be transparent and minimized.
Best prices: I should get the best price or close to it every time I trade on this exchange – so I don’t have to worry about being ripped off on price.
Fairness: others should not get better prices or pay lower fees than me.
Speed and availability: shorten the time to wait for trades to complete or for the exchange to open.
Information: the exchange helps me make informed choices and monitor my orders. I can see the price at which trades might settle, and get good limit order prices and slippage advice. I can also see my unfilled, settled, or cancelled orders.
Deep liquidity and broad asset coverage: high liquidity for a large number of assets can make me more confident.
What liquidity providers (LPs) and market makers (MMs) need:
Yield: To justify the capital risk and opportunity cost behind the profit.
The best risk-adjusted yield is important for MMs, with other metrics being just a means to reach that goal. High trading volume, low competition, high spreads, good rebates, lower custodial risk, and so on, are all to boost the risk-adjusted yield.
Blockchain is a great place to run an exchange, and it has already provided most of what traders and MMs want: decentralization, open-source settlement mechanics, and an accessible trading history are a solid foundation for trust, security, transparency, and fairness.
But decentralized exchanges (DEXs) still need some improvements:
Good LP returns;
Addressing MEV that violates fair execution commitments.
Why AMMs are So Popular
AMMs account for over 95% of all DEX trading volume and are the absolute leader in the DEX market. Here are the most important reasons why AMMs have been superior to alternative designs such as traditional limit order books or RFQs:
Low liquidity requirements: AMMs always provide prices, even with very little liquidity.
Passive liquidity: Your liquidity is automatically managed by the AMM, so becoming an LP is easy, and anyone can earn fees.
Simplicity: AMMs require less computation and storage than order book exchanges, so they consume less gas.
No gatekeepers: The high listing fees for MMs and exchanges can be prohibitive, and centralized exchanges can delist tokens at any time. AMMs make it easy for any project to self-list and incentivize liquidity.
Dex trading volume only started to soar by the end of 2020, two years after Uniswap’s launch. Data source: Dune
When the first DEX was launched, it had low liquidity, few MMs, and few trades, with high gas costs. Running a CLOB under these conditions was impossible, but AMMs were ideal. They were quite simple, easy to build, simulate, and audit.
But DeFi is different now. Volume is rebounding, assets with professional market-making quoting are more diverse, Gas fees are lower with L2 becoming more popular, and everyone has some awareness of the weaknesses of CFMM (i.e. most AMMs today).
AMMs remain the best choice for certain markets (e.g. long-tail tokens), but they still lag behind centralized exchanges in key areas.
Issues with AMMs
High Gas fees
On-chain transactions are still expensive. AMM transaction fees (0.01 – 0.3%) are not much different from CEX, but Gas fees can easily make small transactions (< $1000) bear high costs, even on L2.
Poor price timeliness
AMMs generally won’t give you the best price, with their prices only changing through trades. Therefore, you need arbitrageurs to ensure that AMM prices stay in sync with current market prices. However, arbitrageurs are limited by trading fees and Gas fees, in addition to holding risk. Therefore, AMM pools with low liquidity can easily deviate 1-5% from the best quote on other exchanges.
Impermanent Loss and Rebalancing (LVR)
In subsequent analyses, Uniswap LP was found to be unprofitable due to toxic order flows and LVR.
AMMs are passive, so if the price of an asset is determined by other markets (e.g. on Binance), then the price on the AMM will always lag behind. If the price on Binance goes up, then the AMM will sell tokens to the arbitrageur at a too-low price. If the price on Binance goes down, the AMM will buy tokens from the arbitrageur at a too-high price.
Over time, AMMs, especially their LPs, will accumulate losses. This is the cost that LPs pay to arbitrageurs to pull the prices back to market prices.
In contrast, market makers on limit orders will immediately attempt to adjust their quotes when the price changes. They then rebalance their portfolio at market prices. So the mechanism of AMMs is called impermanent loss and rebalancing (LVR). This is the loss that passive LPs suffer from trading with arbitrageurs at incorrect prices, rather than rebalancing their assets at current market prices.
Ankit’s tweet explains LVR well:
LVR is permanent: If the price returns to its previous level, the LVR loss cannot be recovered, which is different from impermanent losses.
LVR increases with volatility: The larger the price increase, the greater the LP’s loss. In fact, the loss is proportional to the square of the volatility.
LVR depends on the position of the discovered price: It is important how much higher or lower the price you sell to arbitrage traders is compared to the current weighted average market price.
Since you as an LP also earn fees on every transaction, this can be beneficial to you if your pool has a large enough weighting in the market. If LVR < fees earned, these transactions actually make a profit for you instead of a loss. Pools with smaller market weights will have higher LVRs, and their profits are transferred to the profits earned by LPs in larger pools.
Traders and LPs are susceptible to AMM value extraction:
Traders: Searchers can preempt, insert, or block your transaction and affect your transaction price.
Passive LPs: More mature and active LPs can offer timely liquidity to collect most of your transaction fees.
On CFMM, the same token is usually paired with multiple different tokens (e.g., USDC-WBTC, DAI-WBTC, ETH-WBTC) and even the same trading pair is divided into multiple fee levels. This disperses liquidity across multiple pools (in this example, WBTC) and leads to reduced fees for LPs and worse depth and prices for traders. Most of the liquidity is not used for trading (e.g., in Uniswap V2 design) and even on range order AMMs, prices often deviate far from where liquidity is concentrated.
In centralized exchanges, there is usually only one quote asset (e.g., USD), and market makers actively keep most of the liquidity near the current market price, which has less impact on traders’ prices.
The above issues bring more drawbacks to CFMM:
Price and included uncertainty: Transactions often fail
Fixed slippage: AMMs charge a fixed spread on orders. This makes them vulnerable to attack in highly volatile markets and less competitive in markets with small fluctuations.
Difficult to attract liquidity: Losses and rebalancing and liquidity fragmentation make LP profits lower on AMMs, making it more difficult to attract liquidity. Therefore, protocols typically need to subsidize LPs through liquidity mining incentives to attract sufficient liquidity.
Dispersed liquidity: On DEXs, a token usually has multiple trading pairs. Most of the liquidity is not used for trading, and even on range order AMMs, prices often deviate far from where liquidity is concentrated.
However, these issues don’t mean that AMMs are doomed to fail. Research and blockchain technology have made significant progress, enabling new solutions to address these shortcomings.
Improved DEX Designs
There are already several methods attempting to solve DEX issues such as suboptimal pricing, MEV, slippage and rebalancing losses, and liquidity fragmentation. Let’s summarize the most important methods and propose some new ones.
Lower Gas Fees
Cheaper Block Space
The cost of transactions on L2 is cheaper by one to two orders of magnitude than on L1. Thus, transaction costs are no longer the bottleneck. This means that more computationally intensive protocol designs (such as order books) are becoming possible. However, to compete with CEXs in small transactions, gas costs may need to be reduced by another order of magnitude.
An example of a CoW (Cash on Wire) trade where three traders match their needs with each other, providing liquidity to each other – without routing through a DEX or paying DEX fees.
CoW matching is essentially P2P asset exchange between traders who trade complementary pairs simultaneously. Traders don’t pay AMM trading fees and pay less gas (just for transfers). However, to make them work, you need an excellent oracle with the current best bid and offer.
CowSwap fully supports matching demand (full, partial, and multi-party ring trades) – settling many trades that don’t require paying DEX fees.
Off-chain computation, on-chain verification
If you have the computationally intensive part off-chain, and use the chain only for custody, settlement, and verification, you can achieve more complex functionality. For example, tracking and matching limit orders off-chain, but holding funds and settling trades on-chain.
Improved Price Timeliness
With RFQ, you can buy directly from market makers. Since market makers can trade on all venues (off-chain and other chains), through them, you also gain access to the prices and liquidity of these venues. RFQ orders are also more gas-efficient (just for transmission and signature verification, no need to route through pools).
Hashflow and Airswap provide easy on-chain access to RFQ.
In order to compensate for the risk of toxic order flow, market makers do not provide the tightest and deepest quotes possible on exchanges. In fact, regular users are taxed by market makers to subsidize toxic order flow.
However, if market makers are allowed to price after a user submits a trade, they can offer better prices because they take on less risk. This provides better prices for regular users and makes life harder for arbitrageurs.
This idea comes from the design of the JIT AMM model by ChainFlip.
Lowering DEX Fees
One reason for high fees is to protect LPs from the impact of LVR. However, if a DEX can protect itself from the impact of LVR (see below), it can also set lower fees.
One way to keep prices up-to-date and prevent unprofitable arbitrage is to use Oracles to set prices.
AMMs may be vulnerable to toxic order flow if they passively set prices. One way to avoid this is to proactively update prices on AMMs before arbitrageurs come in.
Oracles need to be fast and accurate enough to avoid leaving arbitrage opportunities. As long as the cost of trading is less than the difference between the market price and the oracle price, arbitrage is unprofitable. Therefore, to avoid toxic order flow, the accuracy of oracle prices needs to be less than the trading fee of the AMM.
AMMs can even set prices after a user signs a trade. This further protects LPs from providing stale prices, thereby avoiding arbitrage risk.
Swaap uses oracle-guided pricing to significantly reduce LP LVR.
If AMMs can differentiate between informed (potentially very unprofitable) and uninformed (average profitable) order flow, and only keep uninformed order flow, many problems will be solved.
Dynamic fees and transaction delay can help AMMs differentiate toxic and retail order flow.
The trading signal decays quickly, so the long delay of the oracle will make informed traders more difficult to catch AMMs off guard. This is how it works:
Slow settlement is cheap: If you can wait 5 minutes for your transaction to settle, transaction fees will be very cheap (e.g. 0.1% fee). Transactions will settle at the price of the oracle 5 minutes after. Uninformed traders will not mind this option as they can save on fees and the cost of waiting 5 minutes is small.
Fast settlement is expensive: Settling at the current oracle price is expensive (e.g. 0.4% fee). Higher fees will reduce the signal advantage of informed traders to the point where AMM is no longer profitable. And this still provides an option for users willing to pay for fast settlement.
Delay allows DEX to separate toxic order flow from non-toxic order flow, or DEX can simply ban fast settlement altogether. To effectively block toxic order flow, fast settlement fees must consider the impact of currency pair market volatility.
An exciting example of this is a recent vote by Balancer to reduce transaction fees for all order flows from CowSwap by 50-75%. CowSwap performs batch auctions, and batch auctions introduce delays that make them unattractive to toxic order flow, so Balancer can safely reduce their fees, increasing profits for their LP.
Active Liquidity Management
Concentrated Liquidity Positions (Uniswap V3) allow LPs to direct their liquidity to a specific price range. This allows LP or third parties to keep liquidity near the current market price and greatly increases LP capital efficiency.
Active liquidity management can even protect LP from certain LVRs.
With a reliable oracle, AMM can even set liquidity near the current oracle price on its own, so there is no need for active LP management.
Maverick has successfully utilized this strategy to greatly increase LP capital efficiency.
Dynamic Slippage and Volatility Oracles
As AMM losses depend on the size of the arbitrageur signal advantage, toxic order flow is more likely to appear on more unstable token pairs. In traditional order books, market makers increase spreads when the market fluctuates greatly. AMM can do the same thing and dynamically adjust fees based on current market volatility.
Uniswap v3 now has a rough version that offers different fee tiers for the same trading pair and allows LPs to choose the fee tier that suits the token pair’s price volatility. Market makers also adjust their slippage to rebalance their positions to achieve their goals – AMMs can do similar things for their LPs.
Private transaction submission
A privacy RPC that bypasses the public mempool is an effective way to protect transactions from frontrunning and sandwich attacks.
Batch auctions are a good way to make prices fair: you can place orders in bulk over a period of time, and all trades for the same trading pair are executed at the same price. This reduces the likelihood of your trade being frontrun. Batch auctions also add latency that prevents toxic order flow. Like negative latency oracles, batch auctions have low composability.
They also greatly improve the pricing, available liquidity, and path of trades. This mainly eliminates the possibility of trade rollback.
As mentioned earlier, CowSwap has already implemented batch auctions, bringing more fair and secure settlements to traders.
Dynamic Slippage Tolerance
Setting slippage isn’t easy. If the trading pair price fluctuates a lot, a small slippage will cause your trade to fail, while a large slippage will make you vulnerable to sandwich attacks. Therefore, to avoid trade failure, decentralized exchanges usually have a high default slippage tolerance.
However, with volatility and depth oracles, DEX UIs can do better and predict the correct slippage for each trade. This helps users avoid sandwich attacks or trade failures.
1inch has already implemented logic to dynamically set slippage.
All LPs Become Instant LPs
There is another way to mitigate just-in-time (JIT) liquidity attacks: as with the “last look” for LPs above, if you modify your model to determine the price after the user signs the transaction, you can allow everyone to submit their instant quotes and compete fairly. However, this only works for LPs who are willing to run aggressive strategies and can respond to each trade individually.
Structurally, batch auctions are also just-in-time liquidity trading, as liquidity and price are found after the user submits the trade.
Although public blockchains are excellent infrastructure for exchanges, DEXs have yet to handle a significant portion of trading volume. There are many reasons why trading volume and market makers have not fully gone on-chain: prices are not competitive, user experience is poor, yields are too low, and execution is not secure. Fortunately, all of these problems have good solutions that are expected to bring most of the trading volume on-chain.
Many thanks to @ankitchiplunkar, @thegostep, @orbmis, @SimonAHarman, @Blockingul_burlage, @CyrilleBlockingstour, and @senken_io for their valuable inputs and in-depth feedback.