Why Automated Market Making in Blockchain Swap Exchanges sucks — and How to Fix it

Andreas Park
7 min readMar 21, 2021

A Microstructurist’s View

“Microstructurist” — is that a word? Anyway, my research is in market microstructure, and folks in this area study the provision of liquidity and the formation of prices. A large part of the job is to understand the impact of the underlying institutions — the rules, regulations, infrastructure, and technology. So the advent of blockchain tech and in particular Ethereum has been a big deal for the field: a blockchain allows peer-to-peer trades, cutting out intermediaries, removing frictions such as the t+2 settlement, and offering a pretty high level of transparency. By all reasonable counts, trading on the blockchain is a new ball game, a different type of market.

The thing is though: new tech alone doesn’t make a market and the “old” challenges don’t go away. Peers still have to find one another, buyers and sellers often don’t arrive at a market at the same time or do not demand and supply matching quantities. That means that the need for size and time intermediation, or, in the language of trading, liquidity provision is still there. The big question for the viability of blockchain finance or, decentralized finance, is therefore whether blockchain-based algorithms (aka smart contracts) can successfully automate the provision of liquidity.

Early approaches such as Etherdelta simply translated a normal limit order market (like most stock exchanges) to the decentralized world. Boring. Over the past year, however, we’ve seen a genuinely novel system: swap exchanges such as UniSwap, SushiSwap, Kyber, or Balancer. No complex limit order book, no complex market monitoring, no need for users to understand bids and asks, they can just trade token pairs or portfolios with the click of a button.

The idea under the hood is simple and yet phenomenal. Take Ether and USDT, a common token trading pair. The UniSwap contract for these two tokens is like a big deposit of large numbers of the two tokens aggregated across numerous liquidity providers. Liquidity seekers (folks who want to, say, buy Ether) access the contract asking to buy (or swap) one token in exchange for the other. The exchange price is not determined by individually submitted limit orders but by a deterministic pricing rule that depends on the supplies of the two tokens in the contract.

[Skip this paragraph if you’re not interested in the fine print.]
Background: How swap trading works from the liquidity provider’s perspective. Suppose you have Ether and USDT that sit in your Metamask wallet. Would you like to earn some extra cash by lending these out to people who want to trade? You can put these tokens into the UniSwap contract pair for ETH-USDT. In return, you get deposit tokens (think of them as certificates of ownership). As people trade against the contract you get extra tokens as rewards. If you decide that you want your deposit back, you exchange the deposit tokens and receive USDT and ETH at the prevailing rate. If you think it through, this is actually pretty close to a clever translation of the legacy world of finance to the decentralized world. For in the traditional world, your broker with whom you hold securities often lends out your holdings to short-sellers — except that the brokers earns the proceeds, not you.

If this sounds so good, what am I complaining about? Well, very simply put, the hard-coded pricing mechanism really, what’s the technical term?, sucks.

A Screenshot from UniSwap analysis, taken on March 21, 2021, at around 6 pm EST

[Skip this paragraph if you’re not interested in the fine print.]
Background: How does swap exchange pricing work? The pricing rule of swap exchanges is referred to as constant product automated market-making (CPAMM). Here’s how it works. Liquidity for a pair of tokens A, say ETH, and B, say USDT, is arranged via a smart contract into which liquidity providers deposit X units of ETH and Y units of USDT. The ratio Y/X is the implicit price of a teeny portion of ETH in USDT. Pricing for non-zero quantities is such that the contract keeps liquidity “invariant” at a level XY=c for some constant c. This means that if someone wants to buy x of ETH, she has to pay with y units of USDT tokens where y is such that c=(X-x)(Y-y). How about some numbers? On March 21, 2021, the USDT-ETH contract contained, 57,066 ETH and 89,207,876 USDT (above there is a screenshot). That gives us a marginal rate of +/- $1,563 and a value c of about 5T. If you’d wanted to buy 1,000 ETH, you’d have to pay 1.59M USDT or 1,591 USDT per ETH.

Let’s start with some principles for prices. In markets, prices emerge because of demand and supply, they don’t follow an arbitrary, ad hoc formula. Yes, economists build models that, under a set of simplifying assumptions, yield a formula for a price. But that price is the result of the relationship between demands/supplies. There is no model, not even an approximation of economically sound demands and supplies that spits out the swap exchange pricing formula. What could go wrong when we apply an ad hoc approach to a real market? Worst case, demand and supply develops around the formula and creates poor allocations of resources, arbitrage opportunities, and economically wasteful behavior.

And that’s exactly what happens. There are at least two severe, intrinsic problems that lead to distortions. The first is that under the common pricing rule, the front-running of a trade inherently profitable. The second is that temporary price dislocations at a swap venue relative to other venues create “excessive” losses for liquidity providers.

The first issue is known, and it is linked to the visibility of authenticated, but unsettled trades in the mempool in proof-of-work blockchains. Many teams of engineers and computer scientists are working on cryptographic solutions to solve the mempool visibility by obfuscating the profitability of a front-running attack when the trade enters the mempool. As well, people fiddle with fees and other restrictions — which adds frictions. The mempool visibility and the technology is not the problem, the pricing rule is!

How dare I say this? Well, I’ve done that math: In a new paper, I show that a pricing function that would emerge from a standard economic model has none of these problems: front running is never profitable, and price dislocations do not lead to excessive costs for liquidity providers.

Look, this matters — I studied an (admittedly small) dataset from UniSwap. OK, for very liquid contracts (like the one above), the loss for investors from the swap pricing relative to “canonical” (aka economics-based) pricing is negligible. But: for less liquid trading pairs (for which swap trading has the most merit!), the theoretical loss is substantial: for my January 2021 data, more than 10% of investors stood to lose (theoretically) .5% or more of their trade size by using a swap exchange (which is a lot in the trading world).

And there is more. The possibility of exploiting the inefficiencies actually causes much bigger problems: it creates so-called “miner extractable value”. Front-running profits are real, miners know this, bots know this — there are algos that scan the mempools for profitable trades such as front-running attacks. The folks from the Flashbots project show that bots trying to extract these profits brings about “gas fee auctions” that make the usage of Ethereum more expensive for everyone and that clog up the system. What I argue is that as far as swap exchanges are concerned, these distortions could be entirely avoided if venues adopted an economically sound pricing function!

What do I propose? In the paper, I describe in more detail how the “canonical” pricing works. To be clear, the underlying model isn’t my idea, nor is it new; actually, the specific model I use goes back to a 1993 paper by Bruno Biais in the Journal of Finance. (It’s a mode from a different time, but the organization of the underlying market that Bruno describes can just as week capture a swap contract in the sense that liquidity is aggregated across many market participants.) The model’s liquidity providers’ willingness to take risk depends on some features of the underlying and gives rise to an equilibrium pricing function: The liquidity-price relationship has users pay the integral under a linear function of their demand. Properly designed, this function is impervious to arbitrage and causes no excess losses to liquidity providers from price dislocations.

Quite frankly, it’s not even clear to me what problem the prevailing swap exchange pricing formula solves. My suspicion is that the pervasive use of constant product pricing stems more from the formula’s origin than from its inherent utility. For the original idea, as I understand it, is Ethereum’s co-founder, Vitalik Buterin’s, who suggested running an on-chain swap market using such constant product pricing in a Reddit post about 4 years ago, and things progressed from there to here and here. Vitalik has many brilliant ideas, but this pricing form is not one of them.

So can we please change and adopt an arbitrage-proof, economically sound pricing rule rather than patch gaping wounds with techy band-aids?

--

--

Andreas Park

Andreas is an associate professor of finance at the University of Toronto and Research Director at the Rotman School of Managements FinHub