zerokn0wledge

How constant product AMMs work: pricing, price impact and slippage math

Thread1,061 words
Market since$UNI+8.1%since this pieceHow it played out ↓

Derives the xy=k pricing model step by step, separating quoted from transaction price, showing price impact as dx/(dx+x), and comparing a 1k ETH to wBTC trade on Uniswap versus Bitfinex.

Key claims
Price impact equals dx/(dx+x) and is increasing and concave in trade size
On a roughly $375k trade, Uniswap impact was 0.14% vs 0.6% on Bitfinex (Oct 2020 prices)
Uniswap had 66% of ETH DEX volume, over $50bn in 30 days
0/ #DEXes like @Uniswap are a core piece of the decentralized financial infrastructure on $ETH & beyond✨ but what happens under the hood when you swap tokens on exchanges like $UNI, $SUSHI, $JOE or $BOO?🤔 explainer-🧵 on the constant product #AMM model (0/46)⚖️👇 1/ automated market makers have been one of the most important innovations in DeFi and the overall crypto space. The concept was ideated by @VitalikButerin in 2016 and pioneered by @Bancor & @Uniswap in 2017 & 2018 respectively 2/ the #AMM space has quickly grown into the largest sector within #DeFi & today we find decentralized exchanges using the AMM model in various forms on basically every smart contract L1/L2 (or as app-chain implementations) 3/ some examples include: - $UNI on $ETH, $OP & #Arbitrum - $CRV across multiple EVM chains - $SUSHI on various EVM chains - $JOE on $AVAX - $BOO on $FTM - $GLINT & $STELLA on $GLMR - $RAY on $SOL - $OSMO or $RUNE built on #Cosmos 4/ on $ETH, DEX landscape is heavily dominated by $UNI as the 7 day volume shows: source: @DuneAnalytics 5/ #Uniswap's market share (based on volume) on $ETH amounts to 66%, followed by $CRV with 11% and $DODO at 8.4% 4) $SNX 5) $BAL 6) $SUSHI source: @DuneAnalytics 6/ while aggregators like $1INCH or $ZRX's @matchaxyz have introduced a layer on top of AMM #DEX protocols to improve UX, the market remains dominated by volume generated directly on AMM DEXes source: @DuneAnalytics 7/ over $50bn in trading volume have been generated across DEXes on $ETH in the past 30days and over 5m unique addresses have already interacted with DEX protocols on $ETH 8/ but instead of taking a closer look at the AMM #DEX landscape*, today we'll dive into how the basic constant product AMM model works and what happens under the hood when you swap tokens on a DEX like #Uniswap *) follow-up post coming 9/ let's start with liquidity pools on an AMM #DEX, there are two liquidity pools for each tradeable pair X and Y. The tokens are deposited by liquidity providers and allow other users to trade 10/ one pool contains a quantity x of token X, the other a quantity y of token Y x and y are hence referred to as the available liquidity for X and Y 11/ liquidity providers (or market makers) have incentives to provide liquidity. Aside liquidity mining rewards that LPs might ear, LPs earn fees that are generated on the liquidity pools they provide liquiditiy to 12/ on @uniswap for example LPs earn transaction fees paid by other traders that amount to 0.3%. These fees are paid out to market makers, proportionally to the fraction of liquidity they contributed to 13/ while market makers can withdraw liquidity at any time, providing liquidity remains risky, for example due to divergence risk (a.k.a. impermanent loss) thread covering impermanent loss in more detail will follow soon 14/ so, let's assume Alice holds ∆x > 0 of token X and swaps them for token Y using the #Uniswap protocol what happens under the hood is that Alice adds her ∆x to the liquidity pool for X and in exchange takes some ∆y from the liquidity pool of token Y 15/ consequently, the liquidity pools now contain: - token X: x + ∆x - token Y: y − ∆y 16/ but how many tokens ∆y does Alice get? Or, what is the price of token Y in units of X? on @Uniswap, pricing is regulated by the constant product formula... xy = k ...and depends on the amount of available liquidity x & y, as well as the quantity ∆x Alice wants swap 17/ we define the quoted price of X in units of Y as P(XY) = y/x however, this is a theoretical exchange rate and it's important to understand that one cannot trade at this price 18/ we also define what we refer to as the transaction price of X in units of Y as T(XY) = ∆y/∆x as opposed to the quoted price, this is the price at which you can swap (sell) ∆x units of X for ∆y, given the currently available liquidity 19/ the constant product formula imposes that the product of the two liquidity pools xy does not change after the swap in terms of a formula, ignoring the 0.3% transaction fees, we have: xy = (x+∆x)(y−∆y) = k, where k is a constant 20/ we can hence solve for ∆y and then find the transaction price by computing the ratio T(XY) = ∆y/∆x 21/ starting from the constant-product equation we get: xy = (x + ∆x)(y − ∆y) = xy + ∆x∆y − y∆x + x∆y ⇒ ∆y = ∆x*(y/(∆x+x)) We can now compute the transaction price T(XY) = ∆y/∆x = y/(∆x+x) 22/ so, we have: - a quoted price P(XY) = y/x - a transaction price T(XY) = y/(∆x + x) therefore, if Alice sells token X, the transaction price is lower than the quoted price. The difference is the price impact of the trade 23/ hence, if Alice sells a larger quantity, she gets a worse transaction price. If the size of the trade is small relative to the available liquidity on the other hand, the transaction price approaches the quoted price 24/ @Uniswap provides the price impact Π in percentage terms, depending on available liquidity & trade size we can easily compute price impact using elementary algebra: Π = (P(XY)−T(XY))/P(XY) = ∆x/(∆x+x) 25/ the price impact is increasing & concave in the trade size 26/ suppose we want to trade 1k ETH in exchange for wBTC. Based on Oct 2020 prices, trade size is roughly $375'000. According to its Limit Order Book, trading on Bitfinex would result in a price impact of around 0.6%, excluding commissions 27/ on #Uniswap on the other hand, the price impact would only amount to 0.14%, saving a significant 46bps (roughly $1'700) 28/ remember, each swap impacts the available liquidity of X and Y. As a consequence, the quoted price will be updated as follows: P(XY) = y/x → Q(XY) = (y−∆y)/(x+∆x) 29/ from the requirement (x + ∆x)(y − ∆y) = xy, it follows immediately that the new price after the trade is given by Q(XY)= xy/(x + ∆x)^2 30/ hence, the new price is lower than the transaction price: xy/(x+∆x)^2 = (x/(x+∆x))*(y/(x+∆x)) < y/(x+∆x)
First image of the post

9 more images on X

Open on X

How the covered assets moved · since 11 Sep 2022

Prices as of 23 Oct 2026

This explainer walks through how things work without making a call on the token, so price moves since publication are shown as market context.

Covered in this piece
$UNIUniswapsince publication+8.1%−71% vs BTC
Mentioned for context
$SUSHISushisince publication−84%−96% vs BTC
$JOEJOEsince publication−87%−97% vs BTC
$BOOSpookySwapsince publication−99%−99.7% vs BTC
$ETHEthereumsince publication+35%−64% vs BTC

Daily closes in USD from DefiLlama and Yahoo Finance. Only a bullish or bearish thesis is read as a call; explainers, maps and mentions are context. Not financial advice.

zerokn0wledge avatar
Working together

Research, advisory and builds for deep-tech teams.