With the release of the public chain, such as the currency center, and the launch of its own decentralized exchange, more new decentralized exchanges are appearing on the market. It is foreseeable that there will be a new round of decentralized change in the exchange industry.
What are the core elements of a decentralized exchange? How to design a decentralized exchange? Richard Chen, a well-known blockchain fund 1confirmation analyst, recently wrote an article and conducted a comprehensive analysis. This article will be of great value to readers who want to understand the decentralized exchange.
The history of a centralized exchange is a bloody stolen history, and the Decentralized Exchange (DEX) is emerging as a solution.
- DEX is very hot, and DEX has loopholes, saying that "preemptive trading" is a disease.
- Decentralized exchanges: Why do markets need them? (Part 1)
- Centralized Exchange VS Decentralized Exchange Who is the future of cryptocurrency?
- The second "uprising" of the exchange
- Science | Take you to explore the mystery of the decentralized exchange structure (on)
- Opinion: Is the long tail market the future of DEX?
The innovation of the de-centered exchange is to allow users to trade directly from their wallet without having to trust the exchange to host the funds. " User self-hosting " is a core function of the decentralized exchange.
In fact, designing a decentralized cryptocurrency exchange should essentially satisfy three functions:
- Decentralization: User funds self-hosting
- Cryptographic currency: the asset on the chain as the transaction object
- Exchange: Perform asset exchange and settlement
The three classic design models of the exchange are the order book model, the automated market making model, and the Dutch auction model. How to achieve "decentralized trading" in these three classic trading models is the subject of each decentralized exchange.
What are the pioneers of the market?
Order book model
The order book contains a list of buy and sell orders for the token. A buy order is called a bid (bid) and a sell order is called an ask. The order book lists the number of tokens that are bid or ask at each price point. The highest bid (buy one) and the lowest bid (sell one) are called the top of the book. They mark market sentiment and the bid and ask prices required to get an order. The difference between the highest bid and the lowest bid is called the spread.
DDEX's order book
Currently, IDEX, DDEX, Radar Relay, EtherDelta, Paradex, and Ethfinex are all order book type DEX.
In the Order Book Decentralized Exchange (hereafter referred to as Order Book DEX), you can submit two types of orders: market order and limit order .
When submitting a market order , you can set the number of tokens to buy/sell, and DEX will immediately execute your market order at the best market price. The next market order means that the order is guaranteed to be the fastest, regardless of the price of the existing order on the order book. The way to execute the market order is to match the existing one for the buyer and the existing one for the seller.
When you submit a limit order , DEX will buy or sell the token at the price and quantity you set. If there is no order that matches you, your order will be placed in the order book and waiting for the transaction.
Radar Relay's order book
Order books can be stored on the chain or under the chain. The order book exchange under the chain (eg 0x) requires Relayer (referring to the DEX using this transaction protocol) to store the order book on the centralized server. The order book exchange on the chain does not need to centralize the server, but the user needs to create the transaction and pay the gas fee for the pending order and cancel the order. Even if the order is not filled, the gas fee cannot be refunded.
In order book exchanges, market makers provide liquidity through pending orders, which can reduce spreads and compensate for inventory risks. Generally, the lower the volume, the greater the spread, because the marketer is less exposed to the lack of liquidity.
Suitable for the liquidity market. The larger the volume of an order book exchange and the smaller the spread, the better the liquidity of an exchange. In high liquidity markets, order book exchanges are best suited to show market prices, and large orders are not affected by price slippage. Large centralized exchanges such as Coinbase and Coin and the traditional exchanges such as the New York Stock Exchange rely on the order book model.
Not suitable for markets that lack liquidity. The order will only be completed if the bid and the asking price match, and vice versa; if your maximum bid is still below the minimum asking price, then you will not be able to trade. Therefore, for markets with insufficient liquidity, the order book exchange will result in a large price difference, the transaction success rate is low, and a small amount of funds can have a huge impact on the market price.
The miners are front-running. Order book exchanges on some chains face the problem of preemptive transactions between miners and traders.
Miners can see all trades before they are packaged by the block. If you place a big buy order, once the miner sees the order and they find that your order is large enough to raise the token price, the miner can create a buy order and add his own purchase order to the block before you. in. When this block is dug out, it is equivalent to the miner buying the token at a low price, and then the price of the token is pulled up by the big one. Miners can sell this token at a high price, and they can risk-free arbitrage.
There are several innovative solutions for miners' preemptive trading on order book exchanges. The Injective Protocol uses verifiable delay functions (VDFs) to timestamp orders and prevent miners from "grabbing" users. 0x It is recommended to use a Transaction Execution Coordinator, which sends the transaction to an entity to ensure that the transaction is executed based on price-time priority before the transaction is settled. So far, the preemptive transaction between miners and traders is mainly a theoretical issue, but there are also a few cases that are quietly happening.
In fact, there are other practices. Some Hybrid mode book exchanges, such as DDEX and IDEX, can avoid the problem of preemptive transactions because they hand over the order-spinning operation to the exchange rather than the miners.
Market manipulation. The order book provides short-term signals in the direction of asset prices. For example, a large number of buy orders may indicate a price increase. But these signals can be changed at any time. For example, a trader can hang a lot of big orders, but their own motivation is not to deal with these orders, but to try to show market sentiment and induce traders.
Order book type DEX is easily influenced by market manipulation behaviors, such as pulling, spoofing, and swiping. These manipulations have caused market instability and false trading volumes. Traditional exchanges such as the New York Stock Exchange have strict penalties for this unethical behavior. But at present, real-world laws do not apply to smart contract procedures, so we need to find a technical solution to replace market manipulation problems.
Automated market making (AMM) model
Automated market makers are algorithmic agents that provide market liquidity. The concept of automated market makers has been in the field of game theory and mechanism design for more than a decade (Reference: https://www.cs.cmu.edu/~sandholm/automatedMarketMakersThatEnableNewSettings.AMMA-11.pdf) , only recently Enter the field of encryption.
The AMM exchange does not have the concept of an order book: the exchange does not provide an order book to show the price that buyers and sellers want to trade, but instead brings liquidity together and makes a market based on deterministic algorithms. The algorithm quotes the user based on a predefined formula. Different automated market makers use different algorithms.
Both Uniswap and Bancor set a currency exchange algorithm that allows the user to select a trade pair to exchange between two tokens at the exchange rate currently given by the exchange. Exchange at the airport.
Uniswap is a decentralized exchange that uses a constant product market (the Constant Product Market Maker model "ie x * y = k model") . At Unisawp, everyone can be a market maker. Users can add funds to specific transaction pairs by using the “pool of funds”. For example, if you choose ETH/DAI, you need to add ETH and DAI of equal value at the same time. When the ETH or DAI in the pool is redeemed, each user can get a transaction fee proportionally.
The user can delete the funds that he has added to the pool at any time and withdraw the principal at the exchange rate calculated by the current pool.
Uniswap: Adding and removing mobile funds
Bancor is a decentralized exchange that uses platform coins to automate its market.
Provide liquidity for markets that lack liquidity. This is very useful for markets with highly liquid flows, such as for forecast markets like Augur and Veil , where liquidity is spread across markets. It is easier to place a bet on the long tail market by replacing the order book forecast market with an automated market maker forecasting market.
Large orders have a higher slippage. Slippage refers to the difference between the price point of the order and the price point of the last transaction. In the automated market maker exchange, the slippage is reflected in the change in the instantaneous exchange rate of the order.
The price breakdown of ETH purchased at a constant product market exchange with a liquidity pool of 100,000 DAI and 1,000 ETH
The slippage depends on the size of the liquidity pool of the pair. In the case of Uniswap, as you can see from the above figure, the larger the order size is in the liquidity pool, the higher the slip point premium. For example, an order that accounts for half the size of the flow pool will double the average price of each token, which is 100% slippage, which is almost unreasonable in order book exchanges. In order to keep the slippage rate below 1%, the liquidity pool needs to be 100 times larger than the order amount.
Only when the order size accounts for a small portion of the liquidity pool, the automated market maker exchange can get the best average price for the token, and large orders are not applicable to automated market maker transactions. As a result, traditional financial exchanges and large institutional traders who execute billions of dollars of orders per day will not use the AMM model.
Market maker risk. A common misconception is that AMM liquidity providers receive a fixed return. On the contrary, AMM's liquidity providers do not have the same fixed income as the lenders of DeFi lending products such as Compound and Dharma, but there is a greater risk of loss.
Pintail and Mohamed Fouda found that only when the user's exchange rate from the fund pool is the same as the exchange rate when the funds are added, the commission fee can be earned. Take ETH/DAI, for example, regardless of the price of ETH, my total principal will depreciate. Only the fees I earn can offset this loss, so I will not lose money. When the price changes significantly, I am more likely to lose money than to hold these tokens.
This is a very serious risk for the normal fluctuation of the token, the most risky are those with low transaction volume and high price fluctuations. Market makers can respond to price changes and reduce risk by continuously adding and deleting funds to the pool of funds.
Dutch auction model
The time of the blockchain is discrete. Each block divides the time into non-contiguous time periods, and the time between blocks allows the miner to know ahead of the trader which transactions are included in a block, so there is a chance of preemptive trading. This is a drawback of the chain exchange.
But there is an exchange that takes advantage of the time dispersion of blockchains.
The Dutch auction exchange is just like this design. The Dutch auction is a kind of price reduction auction. It is widely used in items such as flowers, fruits and seafood. Simply put, the price is lowered until the buyer is willing to buy it. The buyer directly completes the transaction.
Dutch auction application in IPO pricing, all buyers declare their bids and purchases in the dark box, the background sorts the price from high to low, accumulates the purchase amount until the total circulation, and the last accumulated order price is the final transaction price. Buyers whose quotation is higher than this price will buy the number of shares they claim at this transaction price.
In the Dutch auction exchange of cryptocurrency, the transaction is carried out in "batch" using the time window of the block. All sell orders are collected in the same batch before the auction begins. (The seller can still submit the order during the auction, but the order will be placed in the next batch of auctions.)
At the beginning of the auction, the initial price of the token is set to twice the closing price of the last auction, and then the price gradually decreases. When the price reflects the buyer's maximum willingness to pay, the buyer will submit the bid. The process of lowering the offer continues until all tokens have been sold, and the clearing price is reached, and the auction ends.
The key to the design of the exchange is that each buyer receives the token at the same price at the close. Buyers pay only at the final clearing price (even if the buyer bids higher), and the amount of tokens the buyer receives is determined by the size of the order they bid.
Source: Gnosis DutchX
Gnosis has established a Dutch auction deal called DutchX , which is the trading platform on the DutchX agreement. FairDEX's first two large auctions have been successfully completed. The auction price of the first and second DAI/ETH auctions was lower than the 1.23% and 2.25% of the price of the same trade on Bitfinex. This indicates that the DutchX trading agreement has no problem dealing with large orders, and the closing price of the auction is not far from the market price.
There is also a Dutch auction contract on 0x to create a Dutch auction market.
Provide price discovery for tokens that lack liquidity. Compared to traditional order book exchanges, Dutch auctions are executed in the same batch by accumulating orders, which can better determine a fair market price for tokens that lack liquidity. Websites such as Decentraland and CryptoKitties use Dutch auctions to achieve price discovery for non-homologous tokens (NFT).
Reduce preemptive transactions. The same lot of sell orders are executed at the same time to prevent miners from preemptively ordering their own orders.
Trading time is slow. At the end of the auction, the transaction will take place and the auction can take several hours. Because the transaction is not instantaneous, fast transactions (such as market orders in the order book exchange) cannot be achieved.
Each of the three methods designed by the exchange – the order book model, the automated market-making model and the Dutch auction model – have their own unique advantages and trade-offs.
I believe that the order book exchange will continue to serve as a trading venue for mainstream tokens such as BTC and ETH, and automated marketplace exchanges and Dutch auction exchanges will complement the market to help users get better in the long tail token market. price.
But no matter which model, to be the winner in the exchange field, the most important thing is price and liquidity . Even if the product design is general, where the price is better and the liquidity is more sufficient, the user will go there.
Thanks to the exchange with Alex Evans for inspiring this article.
Written by: Richard Chen, 1confirmation Analyst, 1confirmation is an early encryption risk fund in San Francisco
Translation: Dai Shichao, head of the DDEX market on the decentralized exchange
Source: Chain News ChainNews