Level 4 · Money and marketsThe gold rush#279

Decentralised exchanges: the machine runs itself, but someone built the shopfront

A decentralised exchange is a set of smart contracts that matches or prices trades on a blockchain. Some keep an order book, most trade against a pool, and almost all are reached through a website that a company runs.

A trading post in a boomtown had two ways to set a price. Either buyers and sellers shouted offers at each other across a board, or the post kept a stock of both goods and changed its price as the stock ran down.

Now imagine both posts turned into machines. Nobody stands behind the counter, nobody keeps your gold overnight. But somebody still painted the sign, built the front door and decides which goods appear in the window.

That's a decentralised exchange, or DEX. The trading happens in smart contracts. The shopfront you use to reach them is often a company's website, and that's where the sheriff tends to knock.

What it is

A DEX is a set of smart contracts that lets people trade tokens from their own wallets. The contracts hold the rules and, during a trade, the coins. The difference from a company-run exchange, which the article on centralised vs decentralised exchanges covers, is that nobody holds your balance in an account.

There are two main designs. An order-book DEX keeps a list of buy and sell offers and matches them. An AMM DEX, short for automated market maker, keeps a pool of two tokens and sets the price from the ratio between them.

How it works

The order-book machine. Hyperliquid, one example, runs its own blockchain and says it "includes fully onchain perpetual futures and spot order books" (Hyperliquid). Its docs say the book "works in essentially the same way as all centralized exchanges but is fully on-chain", and that "The orders are matched in price-time priority" (Hyperliquid). Best price first; at the same price, first come first served.

The pool machine. Uniswap, another example, has no list of offers. Its whitepaper describes a "constant product formula": the pool keeps two reserves and the product of them may not fall (Uniswap v2 whitepaper). Traders pay "a 30-basis-point fee", 0.30%, most of which goes to the people who filled the pool.

Here is the same sale on both machines. You want to sell 1 ether, at an assumed price of 2,000 dollars (an assumption, not a reading).

On the order book, say the best buyers bid 1,999 dollars for 0.6 ether and 1,998 dollars for 0.4 ether. Your order eats both: 0.6 times 1,999 plus 0.4 times 1,998 makes 1,998.60 dollars, before the venue's fee.

On a pool holding 100 ether and 200,000 dollar stablecoins, the formula pays you 1,974.32 dollars. About 6 dollars of the gap is the 0.30% fee. The other 19.68 dollars or so is price impact: your ether is 1% of the pool, and the machine charges you for moving its ratio. In a pool ten times bigger, the impact would be far smaller. The next article does the arithmetic step by step.

Neither result is a recommendation of either venue. They are examples of two designs.

Why it matters

Each design suits a different crowd. Order books need someone, usually a professional market maker, to keep posting and cancelling offers. On a slow, expensive chain that's a transaction each time, which is one reason order-book DEXs often run on their own fast chains. Pools need no active traders at all, so any token can get a market the day it launches, fool's gold included.

Then there is the shopfront. Uniswap's documentation says its core contracts are "not upgradeable" and that "No party can pause them" (Uniswap). The website people use is another matter. On 4 September 2024 the US Commodity Futures Trading Commission ordered Uniswap Labs, the company behind the main Uniswap website, to pay a civil penalty of 175,000 dollars. The order said the company "developed and maintained a web interface that it made available to users", through which users could trade leveraged tokens the CFTC treated as illegal retail commodity transactions (CFTC).

The contracts kept running. The company in front of them paid. That's the shape of most DeFi enforcement: the sheriff can't arrest a machine, so he visits the people who built the door.

Where people get it wrong

  • "A DEX has no owner." The contracts may have none. The website, the app, the token list and often the brand belong to a company.
  • "Every DEX works like Uniswap." Some match orders like a stock exchange; some trade against pools; some mix both.
  • "The price on a DEX is the market price." A pool's price is only the ratio of its two reserves. A large order in a small pool gets a worse price than the screen suggests.
  • "If the website shows a token, it's genuine." Anyone can create a pool for any token. Check the contract address against the project's own site.
  • "If the website disappears, my coins disappear." Your coins sit in your wallet or in the contracts. Another front end, or a block explorer, can still reach them.

Check who runs the door

Before you trade on a DEX, find out two things: which design it uses, and who runs the website you are clicking. The first tells you how your price is set. The second tells you who decides what you see, which tokens are listed and whose rules apply.

Then check the contract address you are about to approve on a block explorer, not just on the website.

The machine has no owner. The shopfront does, and the sheriff knows its address.

Frequently asked questions

What is a decentralised exchange?

A decentralised exchange, or DEX, is a set of smart contracts on a blockchain that lets people trade tokens from their own wallets. No company holds the coins in an account. The price comes either from an order book of offers or from a pool of tokens.

What is the difference between an order-book DEX and an AMM?

An order-book DEX matches buy and sell offers, usually by best price first and then by time. An automated market maker trades against a pool of two tokens and sets the price from their ratio. Order books need active market makers; pools only need people to deposit tokens.

Who runs a decentralised exchange?

The smart contracts may run without an operator, but the website or app most people use is usually run by a company. In September 2024 the CFTC fined Uniswap Labs 175,000 dollars over leveraged tokens available through its web interface. The front end is often where the law reaches a DEX.

Why is a DEX price sometimes worse than the quoted price?

On a pool-based DEX, your own trade changes the ratio of the two reserves, so a large trade in a small pool gets a worse average price. You also pay the pool fee and the network fee. On an order-book DEX, a large order runs through several price levels.

Can I use a DEX if its website goes offline?

Usually yes, if the contracts themselves keep running. Other websites or direct contract calls through a block explorer can still reach them. Be careful: fake websites copying a real DEX are a common trap.

Sources

  1. Hyperliquid, Docs: overview
  2. Hyperliquid, Docs: order book
  3. Hayden Adams, Noah Zinsmeister, Dan Robinson, Uniswap v2 Core (whitepaper, March 2020)
  4. Uniswap, The Uniswap protocol (developer documentation)
  5. CFTC, Release 8961-24: CFTC issues order against Uniswap Labs (4 September 2024)

Read next.