
As centralized exchanges such as Binance release public chains and launch their own decentralized exchanges, more new decentralized exchanges are emerging on the market. It is foreseeable that there will be a new wave of decentralized changes in the exchange industry.
What are the core elements of a decentralized exchange? How to design a decentralized exchange? The well-known blockchain fund 1confirmation analyst Richard Chen recently wrote an article and conducted a comprehensive analysis. This article will be of great value to readers who wish to learn about decentralized exchanges.
Written by: Richard Chen, Analyst at 1confirmation, an early-stage crypto venture fund based in San Francisco
Compile: Neo
Translated by: Dai Shichao, Market Leader of Decentralized Exchange DDEX
The history of centralized exchanges is a bloody history of theft, and decentralized exchanges (DEX) are emerging as a solution.
The innovation of decentralized exchanges is to allow users to trade directly from their own wallets, without trusting the exchange to host funds. "User self-custody" is the core function of decentralized exchanges.
Lianwen X Hydro comments:
Exchange: Perform asset exchange and settlement
Decentralization: self-custody of user funds
Cryptocurrencies: On-chain Assets as Transaction Objects
Exchange: Perform asset exchange and settlement
The three classic design models of exchanges 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 every decentralized exchange.
Order Book Model
Order Book Model
image description
DDEX's order book
Currently, IDEX, DDEX, Radar Relay, EtherDelta, Paradex, and Ethfinex are all order book DEXs.
In the order book DEX (hereinafter referred to as order book DEX), you can submit two types of orders: market orders and limit orders.
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 priority is given to ensuring the speed of order execution, regardless of the existing order price on the order book. The way to execute a market order is to match the existing sell one order for the buyer and match the existing buy one order for the seller.
image description
Radar Relay's Order Book
Order books can be stored on-chain or off-chain. Off-chain order book exchanges (such as 0x) require Relayer (referring to the DEX that adopts this trading protocol) to store the order book on a centralized server. On-chain order book exchanges do not require a centralized server, but users need to create transactions by themselves and pay gas fees for pending and canceling orders. Even if the order is not executed, the gas fee cannot be refunded.
advantage
advantage
shortcoming
shortcoming
Not suitable for illiquid markets. The order will only be filled if the bid and ask match, and vice versa; if your highest bid is still lower than the lowest ask, then you won't be able to trade. Therefore, for an illiquid market, order book exchanges will result in large spreads, low transaction success rates, and a small amount of capital can have a huge impact on market prices.
Miners front-running transactions. Some on-chain order book exchanges face front-running issues between miners and traders.
Miners can see all transactions before they are included in a block. If you place a big buy order, once the miners see this order, they find that your order is big enough to drive up the token price, then the miners can create a buy order themselves and add their own buy order to the block before you middle. When this block is dug out, it means that the miner bought the token at a low price, and then the price of the token was raised by a large order. If the miners sell the token at a high price, they can arbitrage without risk.
There are several innovative solutions for miner front-running on order book exchanges. The Injective Protocol uses Verifiable Delay Functions (VDFs) to timestamp orders to prevent miners from "running away" users. 0x proposes to use a trade execution coordinator, where exchanges send trades to an entity that ensures trades are executed according to price-time priority before they are settled on-chain. Front-running between miners and traders has so far been mostly a theoretical matter, but there have been a few quiet cases.
Lianwen X Hydro comments:
In fact, there are other practices. Some order book exchanges in the hybrid mode, such as DDEX and IDEX, can avoid the problem of front-running transactions because the operation of submitting orders to the chain is handed over to exchanges instead of miners.
market manipulation. Order books provide short-term signals of the direction of an asset's price. For example, a large buy order may indicate an increase in price. But these signals can change at any time. For example, a trader can place many large orders, but their own motivation is not to close these orders, but to try to show market sentiment and induce traders.
secondary title
Automated Market Making (AMM) Model
Automated market makers are algorithmic agents that provide market liquidity. The concept of automated market makers has been around in game theory and mechanism design for over a decade (Reference: https://www.cs.cmu.edu/~sandholm/automatedMarketMakersThatEnableNewSettings.AMMA-11.pdf), and only recently Enter the world of encryption.
The concept of an order book does not exist in an AMM exchange: the exchange does not provide an order book to show the prices that buyers and sellers want to trade, but brings together liquidity and makes a market based on a deterministic algorithm. The algorithm quotes prices to users based on some predefined formula. Different automated market makers use different algorithms.
Both Uniswap and Bancor have set up a currency-to-coin exchange algorithm. Users can select a trading pair to exchange between two tokens at the current exchange rate given by the exchange. This transaction is similar to Exchange money at the airport.
Uniswap is a decentralized exchange that uses constant product market making (Constant Product Market Maker model "that is, x * y = k model"). On Unisawp, everyone can become a market maker. Users can add funds to a specific trading pair by adding funds to the "fund pool". 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 exchanged, each user can share the transaction fee in proportion.
image description
Uniswap: Adding and removing liquidity
advantage
advantage
shortcoming
shortcoming
image description
Breakdown of prices to buy ETH on a constant product market-making exchange with a liquidity pool of 100,000 DAI and 1,000 ETH
Slippage depends on the size of the liquidity pool of the trading pair. In the case of Uniswap, it can be seen from the above figure that the larger the order size as a proportion of the liquidity pool, the higher the slippage premium. For example, an order that is half the size of the liquidity pool will result in a doubling of the average price per token, which is 100% slippage, which is almost unreasonable on an order book exchange. To keep slippage below 1%, the liquidity pool needs to be 100 times larger than the order size.
Automated market maker exchanges get the best average price for tokens only when the order size is a small fraction of the liquidity pool, large orders are not suitable for automated market maker trading. Therefore, traditional financial exchanges and large institutional traders who execute billions of dollars in orders every day will not use the AMM model.
Market Maker Risk. A common misconception is that AMM liquidity providers will receive fixed income. On the contrary, AMM's liquidity providers do not have the same fixed income as lenders of DeFi lending products such as Compound and Dharma, but have a greater risk of loss.
Pintail and Mohamed Fouda found that only when the exchange rate when the user withdraws the principal from the fund pool is the same as the exchange rate when adding funds, can he earn a stable fee commission. Take ETH/DAI as an example, no matter the price of ETH rises or falls, my total principal will depreciate, and only if the handling fee I earn can offset this part of the loss, will I not lose money. When the price changes significantly, I am more likely to lose money than holding these tokens.
secondary title
Dutch auction model
Blockchain time is discrete. Each block divides time into discontinuous time periods. The time between blocks allows miners to know which transactions are included in a block ahead of traders, so they have the opportunity to pre-empt transactions. This is a drawback of on-chain exchanges.
But there is an exchange that takes advantage of the time-discrete nature of the blockchain.
The Dutch auction exchange is exactly such a design. A Dutch auction is a reduced-price auction widely used in flowers, fruits, seafood and other items. In simple terms, the bid is continuously lowered until a buyer is willing to buy, and the buyer directly completes the transaction.
The Dutch auction is used in the IPO pricing. All buyers declare their bids and purchases in secret. After sorting the prices from high to low in the background, the purchases are accumulated until the total issuance. The last accumulated order price is the final transaction price. , each buyer whose quotation is higher than this price will buy the number of shares he declared at this transaction price.
On a cryptocurrency Dutch auction exchange, trades are made in “batches” using the time window of a block. All sell orders are collected in the same batch before the auction starts. (Sellers can still submit orders 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 tokens is set at twice the closing price of the previous auction, and then the price is gradually reduced. When the price reflects the buyer's maximum willingness to pay, the buyer will submit a bid. The process of price reduction continues until all tokens are sold out and the auction ends when the liquidation price is reached.
image description
Source: Gnosis DutchX
Gnosis built a Dutch-style auction trading protocol called DutchX, and FairDEX is a trading platform on the DutchX protocol. The first two large auctions of FairDEX have been successfully completed. The transaction prices of the first and second auctions of DAI/ETH were 1.23% and 2.25% lower than the price of the same trading pair on Bitfinex, respectively. This shows that the DutchX trading protocol has no problem handling large orders, and the closing price of the auction is not far from the market price.
advantage
advantage
Provides price discovery for illiquid tokens. Compared with traditional order book exchanges, Dutch auctions can better determine a fair market price for illiquid tokens by accumulating orders and executing them in batches. Sites such as Decentraland and CryptoKitties use Dutch auctions to enable price discovery for non-fungible tokens (NFTs).
shortcoming
shortcoming
Transaction times are slower. The transaction is not executed until the auction closes, which can take several hours. Fast trades, such as market orders on order book exchanges, are not possible because the trades are not instant.
so what?
Each of the three approaches to exchange design—the order book model, the automated market-making model, and the Dutch auction model—has its own unique advantages and trade-offs.
In my opinion, order book exchanges will continue to serve as a trading venue for mainstream tokens such as BTC and ETH, and automated market-making exchanges and Dutch auction exchanges will be used as supplements to help users obtain better returns in the long-tail token market. price.
But regardless of the model, to become a winner in the exchange field, the most important thing is price and liquidity. Even if the product design is mediocre, users will go wherever the price is better and the liquidity is more sufficient.
Thanks to an exchange with Alex Evans for inspiring this article.