What is a decentralized exchange? A beginner’s guide to DEX protocols

William Peaster
-
Jul 22, 2021
|7 minutes read
what is dex

A decentralized exchange, or DEX, is a cryptocurrency trading application that allows people to easily trade crypto on a 24/7 basis. Because DEXes are secured by blockchain technology, these decentralized finance (DeFi) apps allow users to trade permissionlessly and directly with one another rather than through gated, centralized intermediaries like stock exchanges.

On a decentralized exchange, peer-to-peer (P2P) trades are facilitated by smart contracts. Smart contracts are tamper-resistant programs on specialized blockchains like Ethereum that automatically self-execute upon certain conditions being met, e.g. a user requesting a crypto trade. As such, DEX smart contracts are custom-tailored to efficiently match crypto buyers and sellers. 

Over the past two years, the popularity of decentralized exchanges have exploded as users have flocked to their unprecedented advantages. These advantages include anonymity/pseudonymity (no sign-ups required to use), non-custodial trading (remain in control of your assets rather than delegating them to a third party like a centralized exchange), and open use (permissionlessly list, trade, or supply the crypto you want, no matter who you are or where you’re from). 

Brief history of decentralized exchanges

Decentralized exchanges are relatively new, but they’re already starting to challenge centralized crypto exchanges when it comes to users and volume. The ascension has been a rapid one, considering the first modern DEX, Bancor, appeared as recently as in 2017. 

The earliest conception of DEXes can be traced back to hashed time locked contracts (HTLCs). An HTLC can provide a simple cryptographic escrow system for facilitating on-chain trades between users who don’t know or trust each other. Bisq and LocalBitcoins, which launched in 2014 and 2012 respectively, are proto-DEXes that relied on HTLCs and showed basic decentralized trading was possible. 

The next great evolution in the progress of decentralized exchanges came as the first DEXes started to rise on Ethereum. Courtesy of Ethereum smart contracts, these exchanges became more advanced and considerably easier to use than their HTLC-based predecessors. 

Among the first of these projects were orderbook-style exchanges like EtherDelta, which launched in 2016, and automated market makers like Bancor, which launched in 2017. Ever since the public release of Uniswap V1 in late 2018, AMM-style exchanges have boomed in popularity and have helped popularize DEXes in general. 

Zooming to the present DEXes are now facilitating considerable levels of crypto volume — levels that only centralized exchanges could have handled previously. For example, between June 2020 and June 2021 DEXes impressively facilitated $600B USD worth of trade volume! 

How do DEXes work?

The way a decentralized exchange works depends on its design, of which there are a few contemporary styles. The most popular of these styles are AMM DEXes and orderbook DEXes, while hybrid implementations and newer innovations have recently been expanding the possibilities of decentralized trading. 

Orderbook DEXes

Ethereum’s earliest decentralized exchanges were built as orderbook DEXes, and the orderbook model still remains in use among some of the top DEXes today. 

Inspired by traditional trading venues, orderbook systems entail buyers and sellers setting offers around an asset, at which point these offers get organized into a list of buy and sell orders that create a market. In mainstream finance this process is facilitated by a centralized third party like a stock exchange, while an orderbook DEX ultimately facilitates it via smart contracts. 

That said, there are two main genres of orderbook DEXes: off-chain and on-chain. Off-chain DEXes settle trades on a blockchain like Ethereum but manage their orderbooks off-chain, for example through a system of third-party “relayers.” In contrast, on-chain DEXes like MakerDAO’s OasisDEX manage both orders and settlement all on the blockchain. 

Generally speaking, off-chain DEXes are good for fast trading but are dependent on supply and demand, while on-chain DEXes are good for censorship-resistant trading yet are vulnerable to frontrunning.  

Examples of active orderbook DEXes:

AMM DEXes

AMM DEXes don’t rely on orderbooks. Instead they center around liquidity pools that are secured by smart contracts and are filled with two or more cryptocurrencies, like Uniswap’s 50/50 DAI/USDC pool. Since liquidity is provided constantly, such pools allow for traders to easily trade through them on a permissionless and 24/7 basis, regardless of overall supply and demand whims. 

 Accordingly, AMM DEXes depend on liquidity providers, or LPs, supplying deposits to their pools. LPs stand to gain trading fees (and sometimes token rewards) for their service to these pools. 

Some exchanges, like Uniswap V1, distribute liquidity evenly all along algorithmically-managed price curves, while the newer and optimized Uniswap V3 system allows for concentrated liquidity. This is the ability to provide liquidity in specific places along a price curve, like between $0.98 and $1.02 on the DAI/USDC pool. 

Examples of AMM DEXes:

Hybrid DEXes and new innovations

In recent months we’ve seen a lot of blending and innovation around traditional decentralized exchange styles. 

For example, the new Integral DEX has pioneered a new type of hybrid exchange style dubbed the orderbook AMM, or OB-AMM. This kind of DEX “decouples” capital from depth, thus allowing the exchange to mirror the orderbooks of competitors onto its own smaller liquidity reserves to actualize concentrated, efficient liquidity. 

Additionally, there are also newer AMM evolutions like the DODO DEX’s Proactive Market Making (PMM) style, which allows the decentralized exchange to “proactively” change parameters like price curves in real-time for greater trading efficiency. 

DEX Aggregators

A decentralized exchange aggregator is a type of trading protocol that sources and routes liquidity across multiple DEXes as needed instead of exclusively servicing traders from its own liquidity pools. 

In this way, DEX aggregators attempt to deliver traders the most efficient trades possible, no matter where the trades have to be sourced from in DeFi.

Examples of DEX aggregators:

  • 1inch
  • 0x / Matcha
  • Slingshot

Decentralized exchanges vs. centralized exchanges

There are a handful of fundamental differences between decentralized crypto exchanges and centralized crypto exchanges, not least among them how they’re operated. DEXes transparently run on open-sourced code without intermediaries and are governed by their own respective communities of users. In contrast, CEXes run on closed-source, proprietary code and are administered by their owners, i.e. a company.

This is why we say DEXes are permissionless and CEXes are permissioned: no one is gatekeeping your access to the former — they’re totally open to use by anyone who has an internet connection — while the latter are open only to those people who can play by the owners’ rules. 

Moreover, design is a crucial differentiating factor between the two main types of crypto exchanges. CEXes rely exclusively on orderbook style trading, while the DEX ecosystem has pioneered AMM trading as a novel innovation in finance altogether. Moreover, DEXes are designed to be programmable “money legos” so they can be easily linked with other open-source DeFi apps to create new apps. Conversely, CEXes are built as siloed, for-profit money towers that mainly enrich their owners. 

Some other key differences between DEXes and CEXes include:

  • DEXes offer non-custodial trading (you remain in control of your crypto at all times), whereas CEXes are custodial and are ultimately in control of any money you deposit onto their platforms. 
  • Because of their open and permissionless nature, DEXes are notably excellent for long-tail asset trading, i.e. facilitating trading around many small, low volume cryptocurrencies. For regulatory reasons CEXes are generally suited only for short-tail asset trading, i.e. facilitating lots of volume around the top cryptocurrencies. 
  • Yet it’s also regulatory demands that make it so CEXes can offer direct business-to-consumer protections, like deposit insurance, customer service guarantees, and beyond. DEXes aren’t companies and thus don’t offer any of these sorts of mainstream protections. 

The risks of DEXes

Using decentralized exchanges for trading and LPing crypto comes with its share of risks. Accordingly, you should only attempt to use a DEX if you’ve researched these risks first. Some of the main ones include:

  • Volatility Cryptocurrency prices can swing wildly in rapid fashion, which can lead to considerable slippage for traders and to impermanent loss (IL) for liquidity providers. IL just means an LP is temporarily losing money. 
  • Frontrunning — Frontrunning involves using advance knowledge of another entity’s pending trade to take advantage of that trade. This happens plenty in mainstream finance, and it can happen in DeFi, too, if someone observes the blockchain and then tries to beat you to the punch on your own trade. 

Rug-pulls — “Rug-pulling” is really only a concern with smaller liquidity pools, so this is hardly some ubiquitous risk for DeFi. Still, though, the ecosystem has seen its share of rug-pulls, which entails bad actors pumping up farce tokens and their associated liquidity pools only to disappear after withdrawing massive swathes of money from these same pools!