Exploring the next step in DEX design

Author: Yellow Propeller, Encrypted KOL; Translation: Golden Finance xiaozou

Main points of this article:

Public blockchains with smart contracts are ideal for exchanges: they commoditize trust, make custody, fees, prices, and settlements equally transparent to everyone, and allow anyone to be a market maker.

However, trading volumes on decentralized exchanges (DEX) still lag behind centralized exchanges (CEX) for good reasons: prices are uncompetitive, execution is easily abused (MEV), and as LPs aren't profitable enough.

However, there are good solutions that will make DEXs more attractive: oracle pricing, slower post-trade batch settlement, centralized automated liquidity, and lower cost L2 blocks space.

1 Introduction

Decentralized exchanges are a major use case for smart contract public chains. They have been criticized as junkcoin casinos, but their permissionless mechanism of creating a market for either asset has enormous value, whether they result in speculation or more productive activity.

Today, the crypto trading space is made up of OTC, CLOB (Central Limit Order Book), RFQ, and AMM (Automated Market Maker).

AMMs become especially useful in creating markets for trading pairs where there is insufficient demand for professional market makers to participate. But CLOB is still the preferred mode for trading volumes on high-demand trading pairs (according to Defillama data, DEX trading volume only accounts for about 16% of CEX, most of which are still driven by CEX-DEX arbitrage).

dEBMqTtakJGxYHtoU7stxufuBGC4g8k9mDz1QTqF.png (DEX still only accounts for about 15% of crypto trading volume , but Its share is growing. Source: Coingecko Q1 2023 Industry Report.)

In this article, we will clarify the characteristics of a good exchange, understand the shortcomings of current DEXs, and propose some methods to improve and optimize the design of DEXs.

2**, What does a good exchange look like? **

If I were a trader, a good exchange should provide me with:

· Trust: Escrow risk should be transparent to me during, before, and after my trade and minimized as much as possible.

· Best price: I want to be able to trust that I'm getting the best price on this exchange every time, or very close to it - so I don't need to worry about better prices elsewhere.

· Fairness: I don't want my order to be abused. And no one else should get a better price or pay less than me without good reason.

Speed and Availability: Spending time waiting for transactions to go through or for exchanges to open is not fun.

Information: The exchange helps me make informed choices and monitor my orders. I can see what prices my trades are likely to settle at and get great price and slippage advice for limit orders. I can also see the status of pending, billed or canceled orders.

Deep Liquidity and Broad Asset Coverage: Seeing that many asset pairs are liquid gives me more confidence that I will get a good price on this exchange.

Liquidity Providers (LP) and Market Makers (MM) are concerned with:

· Yield: The profit that offsets capital risk and opportunity cost.

What matters to MM is the best risk-adjusted return scenario; other metrics are just means to that end. High volumes, low or cutthroat competition, high spreads, decent rebates, little harmful order flow, last look, speed bumps, low custody risk - all contribute to a higher risk-adjusted rate of return.

The blockchain is an ideal place to operate an exchange, and it has largely taken care of the thoughts of traders and market makers: decentralization, open source settlement mechanisms, and open transaction history are trust, security, transparency, and fairness. solid foundation.

But decentralized exchanges still struggle with:

· Provide reliable and good prices;

· Provide good yield for LP;

· Prevent MEVs from violating their commitment to fair execution.

Among the top 10 DEXs, 9 are AMMs. Let's take a look at AMMs, their pros and cons.

3**、Why is AMM so popular? **

You often hear the saying: "Traditional finance knows it well, order books are more efficient, constant function market makers will never work."

So, why are AMMs—especially constant function market makers (CFMMs)—still dominating the DeFi space (accounting for more than 95% of all DEX trading volumes)? They must be doing something right.

Here are the top reasons why AMMs are leading by far:

· Low Liquidity Requirement: AMM (Univ2 type) will always offer a price, even if there is little liquidity.

· Passive Liquidity: Your liquidity is managed for you by the AMM. So LPs and anyone (not just market makers) can easily earn fees.

Simplicity: Compared to order book exchanges, AMMs have lower computational and storage requirements, so they consume less gas.

· No gatekeeper** (Gatekeeper):** Listing fees for market makers and exchanges can be prohibitively high, and centralized exchanges can delist tokens at any time. AMM makes it easy for any project to go public and provide or incentivize its own liquidity.

9Zi04br1sLCONBV4xi3sPGAdfLigJrT0ITs1Czdf.png

(At the end of 2020, two years after the launch of Uniswap, the transaction volume of DEX only picked up sharply. Source: Dune)

When the first decentralized exchanges came out, there was little liquidity, few market makers and trading volumes, and high gas fees. It is impossible to run CLOB under such conditions, so AMM is perfect for it. AMMs are fairly straightforward and easier to build, simulate, and audit.

But it looks different now. Order book volumes are increasing, professional market makers are quoting various assets, gas fees are much cheaper on L2, and all are more aware of the weaknesses of CFMMs (i.e. most AMMs today).

For certain markets (like long tail coins), AMMs are still your best bet. But they still lag behind centralized exchanges in key areas.

4**、AMMexisting problems**

(1**) high gas**** fees**

On-chain transactions are still expensive. AMM’s pool fees (0.01-0.3%) are comparable to CEX’s, but gas fees for small transactions (<1k USD) can easily cost you 1-10%, even on L2!

(2**) Expired Price**

AMMs usually won't give you the best prices. The price of the AMM changes only through transactions. Therefore, you need to rely on arbitrage traders to ensure that the AMM price keeps pace with the current market price. However, arbitrage traders are limited by pool rates and gas fees in addition to holding risk. Therefore, AMM pools with low liquidity can easily deviate from the best quotes of other exchanges by 1-5%.

(3**)Loss and Rebalance (LVR****)**

kMVcGVth3BkHBjxLCWYZ2irO0TAoTf56jHGpGKzu.png

(In the subsequent analysis, due to the LVR of harmful order flow, Uniswap LP is obviously unprofitable.)

AMMs are passive, so if the price of an asset is determined elsewhere (for example, in Binance), the price of the AMM will always be one step behind. If the price goes up (on Binance), then the AMM will sell the tokens to arbitrageurs at an extremely low price. If the price falls, the AMM will buy tokens from arbitrageurs at exorbitant prices.

Over time, AMMs, especially their LPs, will continue to lose money. It is the price paid by LP to the arbitrageur that brings the price back to the market price.

Instead, market makers who are active on limit order books will attempt to change their quotes as soon as the price changes, and then rebalance their portfolio against the market price. Hence the name "loss-vs-rebalancing". This is the loss incurred by passive LPs selling assets to arbitrageurs at the wrong price, rather than rebalancing assets at current market prices.

A typical example of LVR is as follows:

· LVR** is permanent: **If the price returns to the previous level, or the loss of LVR cannot be recovered, this will be different from impermanent loss or "loss vs holding".

· LVR** increases with volatility**: The greater the price volatility, the greater the LP's loss.

· LVR** depends on the price discovery venue: **what matters is how far you sell to arbitrageurs from the current weighted average market price.

Because you, as an LP, also earn fees from each transaction, which can be beneficial to you if your capital pool has a large enough weight in the market. As long as the LVR is less than the fee, these trades will actually make you money instead of losing you. Smaller pools with lower weights in the market will have higher LVRs and they will tend to pay out the gains of larger pool LPs.

(4**) Vulnerable Settlement (MEV****)**

Traders and LPs are vulnerable to AMM value extraction:

Traders: Seekers can front-run your trades, launch a sandwich attack on your trades, or block your trades, making your prices even worse.

Passive LP: More sophisticated and active LPs can provide timely liquidity and capture most of your transaction fees.

(5**) Liquidity Fragmentation**

In CFMM, the same token is often paired with multiple different tokens (e.g., USDC-WBTC, DAI-WBTC, ETH-WBTC), and there are even multiple fee tiers for the same trading pair. This spreads liquidity (WBTC in this case) across multiple pools, resulting in lower fees for LPs, lower liquidity depth for traders, and lower prices. Most of the liquidity is not used for trading (for example, in the Univ2 design), and even in range order AMMs, the price often deviates from where the liquidity is concentrated.

In centralized exchanges, there is usually only one quoted asset (such as USD), and market makers actively surround most of the liquidity around the current market price, which will result in fewer pools, deeper order books, and market making Better returns for traders, deeper liquidity for traders and less impact on prices.

(6**) MORE QUESTIONS**

The above problems also lead to more problems in CFMM:

· Price and Inclusion Uncertainty: Trades frequently fail or generate slippage due to intentional or unintentional front-running.

· **Fixed Spread: **The AMM charges a flat fee on orders. This makes them vulnerable in highly volatile markets and less competitive in less volatile markets.

· ** Difficult to attract liquidity: ** Relative loss rebalancing (LVR) and liquidity fragmentation make AMM's LP profitability decline, making it more difficult to attract liquidity. Therefore, protocols usually need to subsidize LPs with liquidity mining incentives to attract sufficient liquidity.

· Liquidity fragmentation: On DEX, a token usually has multiple trading pairs, and even the same trading pair has multiple fee levels. Most of the liquidity is not used for trading (for example, in the Univ2 design), and even in range order AMMs, the price often deviates from where the liquidity is concentrated. This results in lower fees for LPs, less investment depth and worse prices for traders.

But that doesn't mean AMMs are doomed. Blockchain technology and related research have made significant progress and enabled new building blocks that can address these issues.

5**, Build a better on-chain exchange module**

Several solutions have been developed and there are related proposals to address distressed prices, MEV, relative loss rebalancing, and liquidity fragmentation. Let's summarize the most important solutions and put forward some new suggestions.

(1**) Solve the problem of expensive gas**** fees**

· Lower cost block space

L2 costs an order of magnitude or two less. As a result, transaction costs are no longer the bottleneck. This means that the design of more computationally intensive protocols (such as order books) becomes possible. But to compete with CEX in terms of small transactions, the gas fee may need to drop by another order of magnitude.

CoW** (need matching)**

zF3rupQJTV8UsinhWOy8uVC0SY7ca53ivRQ05T2O.png

(Example of a CoW transaction between three traders. Each trader makes the trade he wants, providing liquidity to each other - no need to go through a DEX or pay.)

Demand Matching (CoW) is basically P2P trading assets between traders who trade complementary pairs at the same time. Demand matching optimizes prices as traders pay no AMM transaction fees and pay less gas fees (only transfer fees). However, for demand matching to work, you need to have a good forecast of the current best buy and sell prices.

Off-chain calculation, on-chain verification

If you take the computationally intensive part off-chain and only use the chain for escrow, settlement, and verification, you can achieve more clever and complex functions. For example, track and match limit orders off-chain, but keep funds and settle trades on-chain.

(2**) Solve invalid price issue**

· Invitation for Proposal (RFQ**)**

With an invitation to propose, you can buy directly from a market maker. Since market makers can trade on all trading venues (off-chain and other chains), through them, you can also access the prices and liquidity of these trading venues, even if you only use one chain. RFQ orders also save gas fees (just transfer and signature verification, no need for the intervention of the fund pool).

· Instant (JIT**) Liquidity**

To compensate for the risk of detrimental order flow, market makers do not offer the rigorous depth of quoting that they would on an exchange. In effect, regular users pay taxes to market makers to subsidize harmful order flow (arbitrageurs).

However, if, instead, the market maker sets the price after the user submits the trade, then the market maker can give a better price because they are taking less risk. This gives the average user a better price and makes life harder for arbitrageurs.

· Lower DEX****fees

One reason for the high fees is to protect LPs from LVR. However, if the DEX can protect itself from LVR, then it can also set lower fees. Through arbitrage, lower fees bring one pool closer to other pools.

One way to keep prices up to date and prevent unprofitable arbitrage is to use oracle pricing.

(3**)SOLVE LVR**** PROBLEMS**

· Oracle** based pricing**

As long as AMMs are passively setting prices, they are likely to be vulnerable to signal traders. One way to avoid this is to proactively update prices on the AMM before arbitrage traders come in.

Oracles need to be fast and accurate enough not to leave harmful arbitrage opportunities. As long as the fee charged from the transaction is less than the difference from the market price, then arbitrage is unprofitable and therefore harmful. Therefore, to avoid harmful order flow, the accuracy of the oracle price needs to be higher than the accuracy of the pool's transaction fees.

The AMM can even set the price after the user has signed the transaction**. This can prevent LP from providing outdated quotations, thereby preventing arbitrage risks.

· Delay is encouraged

If AMMs could differentiate between informed (and potentially very unprofitable) order flows and uninformed (on average profitable) order flows, and keep only uninformed order flows, many problems would be solved.

CkYFu3AbCOnlhThi9V6qaKnqkSv0SjeIoupQMLKH.png

(Dynamic fees and transaction delays can help AMMs distinguish harmful order flow from retail order flow)

Trading signals decay quickly, so if an oracle experiences long undesirable delays, it will be more difficult for informed traders to catch an AMM off guard. The mechanism of operation is as follows:

  • Slow settlement costs less: If you can wait 5 minutes for your trade to settle, then swaps are cheap (eg, 0.1% fee). Trades will be settled at the price after 5 minutes from the Oracle. An uninformed trader won't mind doing this because it will save fees, wait 5 minutes, and the cost will be low.

  • Fast settlement is expensive: Settlement is very expensive at current oracle prices (eg 0.4%). Higher fees reduce the likelihood that an informed trader's signal advantage will be large enough to make the AMM unprofitable. Moreover, a fast settlement option is still provided for users who are willing to pay.

The delay allows the DEX to differentiate harmful order flow from harmless order flow and adjust guardrails (fees) accordingly, or the DEX can simply prohibit fast settlement entirely. In order to effectively prevent harmful order flow, fast settlement fees must take into account the market volatility of the trading pair.

· Active Liquidity Management

A centralized liquidity position (Uni v3) allows LPs to direct their liquidity within a specific price range. This makes it possible for LPs or third parties to surround liquidity around the current market price and greatly improve the capital efficiency of LPs.

Active liquidity management can even protect LPs from certain LVRs.

With reliable oracles, AMMs can even set their own liquidity around the current oracle price, so there is no need for active LP management.

· Dynamic spread and fluctuation forecast

Since AMM losses depend on the size of the arbitrageur's signal advantage, more volatile trading pairs are more likely to experience harmful order flow. In traditional order books, market makers widen spreads when markets are volatile. AMMs can do the same, dynamically adjusting fees based on current market volatility.

Uniswap v3 already has a preliminary version of this, which can provide different fee levels for the same trading pair, and let LP choose the fee level that suits the price fluctuation of this trading pair.

Market makers also adjust spreads to rebalance positions against target inventories - AMMs may do something similar for LPs.

(4**) Solve the fragile settlement problem**

· Secret Commit

Privacy RPC that bypasses the public mempool is one way to effectively protect transactions from front-running and sandwich attacks.

· Batch Auction

Batch auctions are a great way to make prices fair: you bundle orders together over a period of time so that trades for the same pair are all executed at the same price. This reduces the chances of your trade being frontrunned or sandwiched. Batch auctions also add latency, which can somewhat prevent harmful order flow. But like bad latency oracles, batch auctions are less composable.

Lot auctions also dramatically improve the pricing, available liquidity, and routing of swaps. This largely eliminates the possibility of tailgating.

· Dynamic slippage range

Setting slippage is not an easy task. If the price of the trading pair fluctuates greatly, too small slippage will cause the transaction to fail, and too large slippage will make your transaction vulnerable to sandwich attacks. Therefore, in order to avoid failed transactions, DEX usually has a large default slippage range.

However, with volatility and depth predictions, DEX users can do a better job predicting the right slippage for each trade. This helps users avoid sandwich attacks or failed transactions.

· Make all LP** JIT**** (instant) LP**

There is another way to mitigate JIT (just-in-time) liquidity attacks: just like the "last look" mechanism of LP mentioned above, if you change the model to determine the price after the user signs the transaction, then you can Let everyone submit offers instantly, leveling the playing field. However, this only applies to LPs willing to execute an aggressive strategy and able to respond to each trade individually.

Structurally, batch auctions are also instant liquidity transactions — as liquidity and prices are discovered after users submit transactions.

6 Conclusion

While blockchain is an excellent infrastructure for exchanges, DEXs are not yet able to handle most of the transaction volume. However, there are good reasons why trading volume and market makers have not fully migrated to on-chain: uncompetitive prices, poor user experience for traders, low yields, and insufficient security of execution. Fortunately, there are good solutions to these problems. Together, these solutions will one day be able to bring the majority of transactions on-chain.

View Original
This page may contain third-party content, which is provided for information purposes only (not representations/warranties) and should not be considered as an endorsement of its views by Gate, nor as financial or professional advice. See Disclaimer for details.
  • Reward
  • Comment
  • Share
Comment
0/400
No comments
Trade Crypto Anywhere Anytime
qrCode
Scan to download Gate app
Community
English
  • 简体中文
  • English
  • Tiếng Việt
  • 繁體中文
  • Español
  • Русский
  • Français (Afrique)
  • Português (Portugal)
  • Bahasa Indonesia
  • 日本語
  • بالعربية
  • Українська
  • Português (Brasil)