DEX mechanism comparison: order book and automatic market maker (AMM)|Injective Learn
Injective
2021-06-01 12:16
本文约2833字,阅读全文需要约11分钟
Decentralized exchanges (DEX) have emerged and flourished in the past few years, providing solutions to the problems that have plagued centralized exchanges (CEX) for a long time.

Decentralized exchanges (DEX) have emerged and flourished in the past few years, providing solutions to the problems that have plagued centralized exchanges (CEX) for a long time. These issues include hacking, lack of privacy, deposit limits, middleman issues, and high fees, among others.

Order Book Model

Order Book Model

A central limit order book (CLOB) is a trade execution model that matches buyers and sellers according to a set of rules. The main difference between trading on an AMM-based or CLOB-based trading platform is the fair price formation mechanism for trade execution. For example, centralized order books rely on aggregated lists of buy and sell orders submitted by traders on a given trading pair. CLOB allows traders to buy or sell assets at a specified price.

The difference between the highest bid price and the lowest ask price is called the spread. Liquid markets have much tighter spreads because there is a good depth of supply and demand at each price level.

Injective matches orders based on a Frequent Batch Auction (FBA) model that accepts orders during discrete time periods (auction intervals) and fills them based on priority. According to academic reports, the optimal batch interval of FBA is theoretically between 0.2 and 0.9 seconds, which is very similar to the block interval of Injective, and the batch auction is executed at the end of each block. The instant certainty of Tendermint's BFT-based PoS consensus (the consensus mechanism adopted by Injective) is very consistent with the FBA execution at the end of each block.

Market Makers as Liquidity Providers

A key feature of order book models is that they allow users to submit two types of orders: market orders or limit orders.

Market order, that is, when a trader buys or sells at the moment, he can be matched with the buyer or seller with the best offer on the order book. Among them, the highest bid and lowest ask constitute the best market price for a given asset.

advantage:

advantage:

  • Order books are ideal for liquid markets;

  • The order book is still the best option for displaying market prices and large orders;

  • Order books reduce slippage risk;

  • shortcoming:

shortcoming:

  • If the highest bid price is lower than the lowest ask price, it cannot be traded, so it is not suitable for an illiquid market;

  • secondary title

Automated Market Maker (AMM) Model

Liquidity is one of the most prominent issues in DEX. Although tokens are difficult to trade efficiently, AMMs have roughly solved this problem by design. It will act as a bot that will offer quotes anytime a user wishes to trade the two assets. While the theory behind AMMs has been around for a long time in academic game theory and mechanism design circles, its application in the crypto market is still in its infancy.

Unlike an order book, which specifies the price at which buyers and sellers want to trade, an AMM trading platform aggregates the liquidity of both trading pairs into a single pool. The AMM pool determines the market price of a single asset based on a deterministic algorithm. The price formula is usually based on the current liquidity within the pool, or in other words, the availability of assets in the pool.

AMMs do not require market makers, but rely heavily on liquidity providers to join in to expand the size of the liquidity pool, thereby ensuring that tokens reflect a fair price.

Various AMM DEXs quote prices for their liquidity pools using different mathematical formulas. Let's take the XYK formula pioneered by Uniswap as an example. In the original form of Uniswap V1, the price was calculated based on the ratio of the two assets in the pool, as follows:

x*y=k (constant)

The constant k represents the total token balance in the liquidity pool, which determines the token price x and y at a given time. We assume x = ETH and y = INJ. Every time a user buys ETH, the price of ETH increases as the amount of ETH in the pool decreases. Conversely, the price of INJ will decrease as the amount of INJ increases. Liquidity pools often provide arbitrage opportunities that can be used to profit.

Let us assume that 1 ETH = 100 INJ is traded through a pool with 10 ETH and 1000 INJ at the time of trade. If a trader wants to buy 2 ETH, they need to exchange 200 INJ for 2 ETH, leaving 8 ETH and 1200 INJ. The price of ETH is now 150 INJ, which will lead to impermanent losses for liquidity providers.

ETH = 1200/8 = 150 INJ

As an important stabilizing mechanism, arbitrage encourages traders to bring the price of the AMM trading platform closer to the spot price of other trading platforms. Extending the example above, an arbitrageur could use this loophole to buy 2 ETH at 200 INJ from a different market and then sell them for 300 INJ in this liquidity pool. This will bring the price level of 1 ETH back to 100 INJ.

Front-running is more common on AMM trading platforms than on CLOB trading platforms. A recent audit of Uniswap revealed that front-running can occur through two attacks.

Attack One: Pushing the Market Against the Trader

The blockchain is fully transparent, which means everyone can view buy and sell orders before they are successfully executed. In algorithmic marketplaces, attackers can exploit the transparency of the blockchain to execute transactions before another by setting higher gas fees, affecting the order of transactions in a block and thus the outcome of a given transaction. This poses a huge challenge to the crypto market, with a plethora of arbitrage bots taking advantage of this inherent vulnerability.

The front-running trading process in the ETH/INJ market is as follows:

1. Alice wants to buy 1 ETH of INJ at price x, gas price is y

2. Bob sees the transaction on the blockchain

3. Bob pays gas price z where z > y and buys 100 INJ at price x

4. Alice's transaction is passed, but she can only buy 90 INJ with 1 ETH at this time

5. Alice's transaction causes the price of the asset to rise

6. Bob sells 100 INJ and earns ETH

Attack 2: Sandwich Attack

In the second attack, a malicious user observes transactions on the blockchain and uses mint/burn to front-run transactions ahead of large transactions. Therefore, the attacker extracts a large amount of LP fees from transaction x without facing the inherent risks of providing liquidity in the pool, such as impermanent losses, etc.

advantage:

advantage:

  • Ability to trade in illiquid markets

  • shortcoming:

shortcoming:

  • High slippage risk for large orders due to small liquidity pool

  • Capital inefficiency as most trades are executed within a narrow range of price levels unless the market is extremely volatile

  • Risks for liquidity providers, such as impermanent losses as described above

  • in conclusion

in conclusion

These two trading methods have their own characteristics. Order book trading platforms currently dominate the market for a large number of tokens such as Bitcoin and Ethereum. Automated market makers, on the other hand, will help users get the best prices for illiquid tokens in the long-tail market.

Centralized limit order books have become the mainstream approach for large traditional trading platforms such as Nasdaq because it is arguably the most capital efficient and transparent mode of trade execution. While issues such as front-running and higher spreads have prevented DEXs from adopting the CLOB model, Injective has creatively corrected both with a unique FBA model. The FBA model provides ample time for market makers to cancel expired orders before high-frequency traders place trades. In addition to maintaining fast trading times, our trading model also enables tighter spreads by trading closer to market prices and with higher liquidity.

Injective
作者文库