A Comparison of Decentralized Exchange Designs

Richard Chen
The Control
Published in
10 min readApr 18, 2019

--

Decentralized exchanges, or DEXs, have emerged last year as a solution to crypto’s bloody history of centralized exchange hacks. The main innovation is allowing users to trade directly from their wallets without having to trust an exchange to custody funds and implement robust security practices.

While self-custody is an important feature of DEXs, decentralized exchanges also present a unique opportunity to rethink how to design an exchange from scratch based on first principles. The three main models for designing an exchange are the order book model, the automated market making model, and the Dutch auction model.

Order book model

An order book contains a list of buy and sell orders for a specific token. An order to buy is called a bid and an order to sell is called an ask. An order book lists the numbers of tokens being bid or asked at each price point. The highest bid and the lowest ask are referred to as the top of the book. They signal the prevalent market sentiment and the bid and ask price that would be needed to get an order fulfilled. The difference between the highest bid and the lowest ask is called the spread.

On order book exchanges, you can submit two types of orders: a market order or a limit order. When submitting a market order, you buy or sell immediately for the best available price. Market orders are filled by instantly pairing buyers and sellers with orders currently at the top of the book. When submitting a limit order, you buy or sell a set number of tokens at a specified price and your order sits on the order book.

Examples of order book DEXs include IDEX, DDEX, Radar Relay, EtherDelta, Paradex, and Ethfinex.

Radar Relay’s order book.

Order book DEXs store their order books either on-chain or off-chain. Off-chain order book DEXs, such as 0x, need relayers to store the order books on centralized servers. On-chain order book DEXs do not and thus have the benefit of censorship resistance, but users will need to create transactions and pay for gas to place limit orders and to cancel existing orders.

On order book exchanges, market makers provide liquidity by placing limit orders that reduce the size of the spread and are compensated for taking on inventory risk. (Galois Capital published a fantastic in-depth guide to market making in crypto.) Typically the lower the trading volume, the wider the spread because there is greater risk of illiquidity assumed by market makers.

Pros

Good for liquid markets. Order book exchanges are optimal for surfacing the market price and placing large orders without much slippage when there is a lot of trading volume and market makers maintaining a tight spread. High volume centralized exchanges, such as Coinbase and Binance as well as traditional exchanges like the New York Stock Exchange, rely on the order book model.

Cons

Bad for illiquid markets. An order will only be fulfilled if a bid price matches an ask price or vice versa; you won’t be able to make a trade if your highest bid is still lower than the lowest ask. Hence, with illiquid markets, order book exchanges result in large spreads and variable prices, in addition to the regular volatility with cryptocurrencies.

Front-running. A problem on-chain order book DEXs face is front-running. To place an order on an order book DEX, you would need to submit a transaction to the blockchain, and thus miners can see all the transactions before they are included in the block.

This becomes an issue if you place a large order to buy a token. Once this order is seen by a miner who realizes that your order is big enough to drive up the price of the token, the miner can create their own buy order and include it in the block before you do. Then, assuming that the miner is able to mine this particular block, they would have earned a risk-free profit by taking advantage of the information in your order.

There are several novel solutions to front-running for order book DEXs. Injective Protocol uses Verifiable Delay Functions (VDFs) to “timestamp” orders so miners can’t frontrun users. 0x proposes using a Trade Execution Coordinator, in which relayers route trades to an entity that ensures the trades are executed according to price-time priority before the trades are settled on-chain. To this date front-running remains mostly a theoretical problem rather than a real problem in practice but there are few empirical instances of it happening in the wild.

Market manipulation. The order book provides clues about the price direction of an asset in the short term. A large number of buy orders may indicate a rising price due to buying pressure. Peaks on either side of the order book, known as buy or sell walls, indicate there may be many traders willing to trade a large amount of tokens around a specific price level.

The problem is that these signals are just clues that can change at any moment. For instance, an abusive trader can place large limit orders they have no intention of filling in an attempt to give the appearance of a desired market sentiment. An uninformed trader may believe there are many orders at a certain price level on the order book, only to see those orders cancelled mid-execution by the abusive trader, creating unexpectedly high slippage for the uninformed trader.

Order book DEXs are particularly susceptible to a variety of abuses like pump and dumps, spoofing, and wash trading. These abuses create unstable market conditions and fake or inflated volumes across exchanges, further exacerbating fears of instability and bad actors. Traditional exchanges, such as the New York Stock Exchange, have strict regulations to punish such unethical behavior. Yet real-world laws don’t apply neatly to permissionless smart contract programs, so instead we need to find a technical solution, rather than a legal solution, to market manipulation.

Automated market making (AMM) model

Automated market makers are algorithmic agents that provide liquidity in markets. The concept of AMMs has been known within academic game theory and mechanism design circles for over a decade yet only recently made its way into crypto.

An AMM exchange sheds the concept of an order book. Instead of specifying which prices buyers and sellers want to trade at, an AMM exchange pools liquidity together and makes markets according to a deterministic algorithm. This algorithm quotes prices to the end user according to some predefined formula. Different AMMs use different algorithms, each with their own sets of tradeoffs.

Uniswap is a DEX that uses the Constant Product Market Maker model. (Cyrus Younessi wrote an excellent overview of how Uniswap works.) On Uniswap, anyone can provide liquidity to the exchange for a particular trading pair and earn fees from trading activity. This is one of the main attractiveness of the automated market making model — that anyone in the community can be a liquidity provider and own a share of the upside when a public utility like Uniswap becomes successful.

Bancor is another DEX that uses a Relay Token for its AMM.

Price breakdown for buying ETH on a Constant Product Market Maker exchange with a liquidity pool of 100,000 DAI and 1000 ETH.

Pros

Always provides liquidity for illiquid markets. As long as there exists a liquidity pool for a particular trading pair, AMMs will always provide liquidity regardless of the order size or the size of the liquidity pool. This is great for markets where liquidity is highly fragmented, such as for prediction markets like Augur and Veil where liquidity is split among various markets. Replacing order book prediction markets with AMM prediction markets makes it easier to place bets on long-tail markets that don’t have much volume.

Cons

High slippage for large orders. Slippage is dependent on the size of the liquidity pool for the particular trading pair. In the case of Uniswap, from the chart above, the slippage premium becomes prohibitively expensive the greater the percentage of the liquidity pool an order is. For instance, an order size of half the liquidity pool causes the average price per token to double; a slippage rate of 100% would be outrageous on an order book exchange. To keep slippage under 1%, the liquidity pool would need to be 100x greater than the size of the order.

AMM exchanges are great for getting the best average price for illiquid tokens only when the order size is a small percentage of the liquidity pool. But AMM exchanges are impractical for large orders as the respective liquidity pools would need to be massive. Thus, exchanges in traditional finance that have large institutional traders placing billions of dollars in orders per day don’t use the AMM model.

Risks for liquidity providers. One common misconception is that AMM liquidity providers earn fixed income. Rather, being a liquidity provider for AMMs isn’t the same as being a lender for DeFi products like Compound and Dharma in that there are greater risks of losing money.

Pintail and Mohamed Fouda have found that being a liquidity provider is most profitable when the token pair trades at around the same price ratio at which the liquidity provider supplied the token pair. This is because there is always an impermanent loss whenever the price ratio changes, and such impermanent loss must be offset by earnings from trading fees. Thus, when there is a significant price change, liquidity providers could lose money compared to just holding the tokens. A huge increase in the price of ETH for the ETH/DAI trading pair, for instance, could be offset by the losses from supplying ETH/DAI to the AMM earlier at a lower price.

This is particularly bad with the regular volatility of cryptocurrencies and is worst for low-volume markets that have huge price fluctuations. Liquidity providers could mitigate this risk by actively increasing or decreasing supplied liquidity in response to price changes.

Dutch auction model

Blockchain time is discrete, not continuous. Each block splits time into discrete intervals, and the time between each block lets miners know before everyone else what transactions will be included in the next block. Decentralized exchanges based on discrete time — as opposed to centralized exchanges based on continuous time — are inherently designed to favor the miners. What if we could design a DEX that takes advantage of the fact that blockchain time is discrete rather than continuous?

In a Dutch auction exchange, there are discrete time windows for trading. Before an auction starts, all sell orders are collected in a batch. (Sellers can still submit orders during an auction; the orders will just be batched in the next available auction.) When the auction starts, the initial price is set at twice the closing price of the previous auction, and the price gradually decreases until the price clears the quantity of tokens sold and bought. During the auction, each buyer submits his or her bid when the current price reflects his or her maximum willingness to pay.

Source: Gnosis DutchX

The key part of the exchange design is that every buyer receives his or her tokens at the closing time for the same price. Since buyers will only have to pay for the final market clearing price (which is either at their bid or lower), buyers are incentivized to submit their bids at their highest willingness to pay. Using the size of the bid(s) a buyer has made, the final price determines the amount of tokens to be received.

Gnosis has built a Dutch auction exchange trading protocol called DutchX, and FairDEX is a trading platform to interact with the protocol. The first two high volume auctions on FairDEX worked smoothly. The first and second DAI/ETH auctions closed at a 1.23% discount and a 2.25% discount respectively from the price of the same pair on Bitfinex. This shows that the DutchX trading protocol can handle large orders without issue and that the auctions’ closing prices are not far from market prices.

0x also has a Dutch Auction Contract to create markets based on the Dutch auction model rather than the traditional order book model.

Pros

Good price discovery of illiquid tokens. By accumulating orders that are executed at the same time, the Dutch auction is better at determining the fair market price for illiquid tokens compared to a traditional order book exchange. Dutch auctions are used by sites like Decentraland and CryptoKitties to allow price discovery of new or rare non-fungible tokens (NFTs).

Reduces front-running. Since the batched sell orders are all executed at the same time, this prevents miners from front-running individual trades.

Cons

Slow trading time. The trades aren’t executed until the auction is over, which can take up to several hours. Since trades aren’t instantaneous, this makes fast trades, like a market order on an order book exchange, impossible.

The only time a Dutch auction is used in traditional finance is when the government sells treasury bonds. Since treasury bonds mature ranging from one month to 30 years, the small interval of time for the Dutch auction to happen is insignificant in the long-run. However, Dutch auctions are impractical for traditional financial exchanges since traders often don’t have the time to wait in discrete intervals for auctions to clear.

So what?

Each of the three approaches to designing exchanges — the order book model, the automated market making model, and the Dutch auction model — offers its unique set of advantages and tradeoffs. To be a winner in the exchange space though, what ultimately matters is price and liquidity. Users are willing to wade through a poorly designed product if they can get a better price on it, and there needs to be enough liquidity on the exchange to fill users’ orders.

From my perspective, order book exchanges will continue to dominate volume for liquid tokens like BTC and ETH, while automated market making exchanges and Dutch auction exchanges will complement order book exchanges and help users get better prices on long-tail illiquid tokens.

Thanks to Alex Evans for conversations that inspired this article.

About the author: Richard works at 1confirmation, an early-stage crypto venture fund based in San Francisco. Sign up for the 1confirmation newsletter and don’t hesitate to reach out on Twitter.

--

--