<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: DILSHODJON MUXTOROV</title>
    <description>The latest articles on DEV Community by DILSHODJON MUXTOROV (@dilshodjon_muxtorov_df648).</description>
    <link>https://dev.to/dilshodjon_muxtorov_df648</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3912077%2F33077dfb-081e-43e9-a02a-278508f60582.png</url>
      <title>DEV Community: DILSHODJON MUXTOROV</title>
      <link>https://dev.to/dilshodjon_muxtorov_df648</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dilshodjon_muxtorov_df648"/>
    <language>en</language>
    <item>
      <title>The Mathematics of Automated Market Makers: From Constant Product Invariants to Concentrated Liquidity</title>
      <dc:creator>DILSHODJON MUXTOROV</dc:creator>
      <pubDate>Mon, 04 May 2026 12:54:24 +0000</pubDate>
      <link>https://dev.to/dilshodjon_muxtorov_df648/the-mathematics-of-automated-market-makers-from-constant-product-invariants-to-concentrated-6fe</link>
      <guid>https://dev.to/dilshodjon_muxtorov_df648/the-mathematics-of-automated-market-makers-from-constant-product-invariants-to-concentrated-6fe</guid>
      <description>&lt;h1&gt;
  
  
  &lt;em&gt;A rigorous analysis of the algebraic foundations underlying decentralized exchange protocols&lt;/em&gt;
&lt;/h1&gt;




&lt;h2&gt;
  
  
  Abstract
&lt;/h2&gt;

&lt;p&gt;Automated Market Makers (AMMs) represent one of the most consequential algorithmic innovations in decentralized finance. Rather than relying on a traditional order book, AMMs use deterministic mathematical functions to price assets and execute trades. This article derives the core invariant of the constant product market maker, analyzes the phenomenon of impermanent loss through calculus, and examines how Uniswap V3's concentrated liquidity model generalizes the classic formula. We provide formal derivations, numerical examples, and a discussion of the trade-offs inherent in each design.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;Traditional financial exchanges operate via an &lt;strong&gt;order book&lt;/strong&gt;: a continuously updated ledger of buy and sell orders matched by price and time priority. While efficient in liquid markets, this model requires active market-making — counterparties willing to post and update limit orders. In decentralized, permissionless networks, coordinating such activity is costly and slow.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Automated Market Maker&lt;/strong&gt; eliminates the order book entirely. Instead, liquidity is pooled into a smart contract, and a deterministic pricing function governs every trade. The seminal realization — first popularized by Uniswap V1 (2018) and formalized in V2 (2020) — is that a simple algebraic invariant is sufficient to create a functional, manipulation-resistant exchange mechanism.&lt;/p&gt;

&lt;p&gt;This article focuses primarily on the &lt;strong&gt;constant product market maker (CPMM)&lt;/strong&gt;, characterized by the invariant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x · y = k
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; are the reserve quantities of two assets in a liquidity pool, and &lt;code&gt;k&lt;/code&gt; is a constant preserved across all trades. We will derive its properties from first principles, analyze its economic implications, and describe how Uniswap V3 extends it with the concept of &lt;strong&gt;concentrated liquidity&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The Constant Product Invariant
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Formal Definition
&lt;/h3&gt;

&lt;p&gt;Let a liquidity pool hold reserves &lt;code&gt;(x, y)&lt;/code&gt; of tokens X and Y respectively. The pool is governed by the invariant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f(x, y) = x · y = k,   where k &amp;gt; 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;strong&gt;trade&lt;/strong&gt; is an operation that modifies the reserves while preserving &lt;code&gt;k&lt;/code&gt;. Suppose a trader submits &lt;code&gt;Δx&lt;/code&gt; units of token X to the pool and receives &lt;code&gt;Δy&lt;/code&gt; units of token Y in return. The post-trade state must satisfy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(x + Δx)(y − Δy) = k = x · y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Solving for &lt;code&gt;Δy&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y − Δy = (x · y) / (x + Δx)

Δy = y − (x · y) / (x + Δx) = (y · Δx) / (x + Δx)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the &lt;strong&gt;output formula&lt;/strong&gt; for a CPMM trade. Note several important properties:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;Δy &amp;lt; y&lt;/code&gt; for all finite &lt;code&gt;Δx&lt;/code&gt; — the pool can never be fully drained.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Δy&lt;/code&gt; is a concave function of &lt;code&gt;Δx&lt;/code&gt; — marginal returns diminish as trade size increases.&lt;/li&gt;
&lt;li&gt;There is no separate pricing oracle; price is implicit in the reserve ratio.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  2.2 The Spot Price
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;spot price&lt;/strong&gt; of token X in terms of token Y is the marginal cost of an infinitesimal trade, obtained by differentiating the output with respect to input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P(X/Y) = lim(Δx → 0) of Δy/Δx
        = d/d(Δx) [ (y · Δx) / (x + Δx) ] evaluated at Δx = 0
        = y / x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus, the spot price is simply the ratio of reserves:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P(X/Y) = y / x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an elegant result: the pool's "opinion" of the relative value of X and Y is encoded entirely in the reserve ratio. As reserves shift through trading, the spot price adjusts continuously.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.3 Price Impact and Slippage
&lt;/h3&gt;

&lt;p&gt;For a trade of finite size &lt;code&gt;Δx&lt;/code&gt;, the &lt;strong&gt;effective price&lt;/strong&gt; paid per unit of X is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P_eff = Δy / Δx = y / (x + Δx)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;price impact&lt;/strong&gt; — the percentage deviation from spot price — is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Price Impact = 1 − P_eff / P(X/Y)
             = 1 − [y / (x + Δx)] / [y / x]
             = 1 − x / (x + Δx)
             = Δx / (x + Δx)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This shows that price impact is determined entirely by the relative trade size &lt;code&gt;Δx / x&lt;/code&gt;. A pool with large reserves (deep liquidity) minimizes slippage for a given trade. This formalizes the intuitive relationship between liquidity depth and trading efficiency.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Liquidity Provider Economics and Impermanent Loss
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 The Liquidity Share Model
&lt;/h3&gt;

&lt;p&gt;When a liquidity provider (LP) deposits assets into a CPMM pool, they receive &lt;strong&gt;LP tokens&lt;/strong&gt; representing a fractional ownership of the pool. If the pool holds reserves &lt;code&gt;(x, y)&lt;/code&gt; and the LP deposits &lt;code&gt;(δx, δy)&lt;/code&gt; proportionally, they receive a share:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = δx / x = δy / y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At any later time, the LP can redeem their share for &lt;code&gt;(s · x', s · y')&lt;/code&gt; where &lt;code&gt;(x', y')&lt;/code&gt; are the current pool reserves. This seems straightforward, but the reserve ratio may have shifted due to trading activity — leading to the phenomenon of &lt;strong&gt;impermanent loss&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2 Derivation of Impermanent Loss
&lt;/h3&gt;

&lt;p&gt;Consider an LP who deposits at time &lt;code&gt;t₀&lt;/code&gt; when the price ratio is &lt;code&gt;P₀ = y₀ / x₀&lt;/code&gt;, and withdraws at time &lt;code&gt;t₁&lt;/code&gt; when the external market price has moved to &lt;code&gt;P₁&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The pool automatically adjusts its reserves to track the external price (via arbitrage). After arbitrage, the new reserves satisfy both the constant product invariant and the updated price:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x₁ · y₁ = k = x₀ · y₀   and   y₁ / x₁ = P₁
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Solving:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x₁ = √(k / P₁)
y₁ = √(k · P₁)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let &lt;code&gt;r = P₁ / P₀&lt;/code&gt; be the price ratio. The LP's portfolio value at &lt;code&gt;t₁&lt;/code&gt;, if they had simply &lt;strong&gt;held&lt;/strong&gt; the initial assets (HODL strategy), would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;V_hold = s · (x₀ · P₁ + y₀)
       = s · (x₀ · r·P₀ + x₀·P₀)
       = s · x₀ · P₀ · (r + 1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The LP's actual value from the pool at &lt;code&gt;t₁&lt;/code&gt; is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;V_pool = s · (x₁ · P₁ + y₁)
       = s · (√(k/P₁) · P₁ + √(k · P₁))
       = 2s · √(k · P₁)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since &lt;code&gt;k = x₀ · y₀ = x₀² · P₀&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;V_pool = 2s · x₀ · P₀ · √r
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;impermanent loss (IL)&lt;/strong&gt; is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IL(r) = (V_pool − V_hold) / V_hold = 2√r / (r + 1) − 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This formula is symmetric in &lt;code&gt;r&lt;/code&gt; and &lt;code&gt;1/r&lt;/code&gt; (price doubling is as damaging as price halving). Key values:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Price Ratio (r)&lt;/th&gt;
&lt;th&gt;Impermanent Loss&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1.00× (no change)&lt;/td&gt;
&lt;td&gt;0.00%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.25×&lt;/td&gt;
&lt;td&gt;−0.60%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.50×&lt;/td&gt;
&lt;td&gt;−2.02%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.00×&lt;/td&gt;
&lt;td&gt;−5.72%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4.00×&lt;/td&gt;
&lt;td&gt;−20.0%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10.0×&lt;/td&gt;
&lt;td&gt;−42.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The loss is called "impermanent" because it is only realized upon withdrawal. If prices return to &lt;code&gt;P₀&lt;/code&gt;, the LP's position is equivalent to the HODL strategy. In practice, fees earned during the LP period partially or fully offset impermanent loss.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Uniswap V3: Concentrated Liquidity
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 Motivation
&lt;/h3&gt;

&lt;p&gt;In a standard CPMM, liquidity is distributed uniformly across the entire price range &lt;code&gt;(0, ∞)&lt;/code&gt;. In practice, most trading occurs within a narrow band around the current price. Capital deployed outside this band earns no fees and represents wasted capital efficiency.&lt;/p&gt;

&lt;p&gt;Uniswap V3 (2021) introduced &lt;strong&gt;concentrated liquidity&lt;/strong&gt;: LPs can specify a price range &lt;code&gt;[Pₐ, P_b]&lt;/code&gt; within which their liquidity is active. This dramatically increases capital efficiency at the cost of added complexity.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.2 The Virtual Reserve Formulation
&lt;/h3&gt;

&lt;p&gt;Uniswap V3 achieves concentration by introducing a &lt;strong&gt;virtual liquidity&lt;/strong&gt; parameter &lt;code&gt;L&lt;/code&gt;, defined such that the standard CPMM invariant holds for &lt;strong&gt;virtual&lt;/strong&gt; reserves &lt;code&gt;x̃&lt;/code&gt; and &lt;code&gt;ỹ&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x̃ · ỹ = L²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The virtual reserves are offset from the real reserves by amounts that pin the curve to the desired price bounds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x̃ = x + L / √P_b
ỹ = y + L · √Pₐ
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives the &lt;strong&gt;Uniswap V3 pricing curve&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(x + L/√P_b)(y + L·√Pₐ) = L²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the current price &lt;code&gt;P = y/x&lt;/code&gt; is within &lt;code&gt;[Pₐ, P_b]&lt;/code&gt;, the position is &lt;strong&gt;active&lt;/strong&gt; and earns fees. Outside this range, the position holds 100% of one token and earns nothing.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.3 Liquidity Parameter and Position Sizing
&lt;/h3&gt;

&lt;p&gt;The liquidity parameter &lt;code&gt;L&lt;/code&gt; governs how much of each token is deposited. For a position at current price &lt;code&gt;P ∈ [Pₐ, P_b]&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Δx = L · (1/√P − 1/√P_b)
Δy = L · (√P − √Pₐ)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These formulas allow LPs to compute the exact token quantities needed to provide a specific &lt;code&gt;L&lt;/code&gt; over a chosen range. The &lt;strong&gt;capital efficiency ratio&lt;/strong&gt; — compared to V2 — is approximately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;η = 1 / (1 − √(Pₐ / P_b))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a ±5% price range (tight band), &lt;code&gt;η ≈ 10×&lt;/code&gt;. For a ±50% range, &lt;code&gt;η ≈ 2.5×&lt;/code&gt;. This quantifies the leverage that concentrated liquidity provides.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.4 The Sqrt-Price Representation
&lt;/h3&gt;

&lt;p&gt;Uniswap V3 internally represents all prices as &lt;code&gt;√P&lt;/code&gt; using a fixed-point Q64.96 number. This choice simplifies the arithmetic — the core swap formulas become:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Δ(√P) = Δy / L
Δ(1/√P) = Δx / L
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The use of &lt;code&gt;√P&lt;/code&gt; instead of &lt;code&gt;P&lt;/code&gt; ensures that the formulas for &lt;code&gt;Δx&lt;/code&gt; and &lt;code&gt;Δy&lt;/code&gt; are symmetric in structure, reducing the risk of numerical asymmetries in the smart contract implementation.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Beyond Constant Product: The Generalized AMM Landscape
&lt;/h2&gt;

&lt;p&gt;The constant product formula is one instance of a broader class. Several alternative invariants have been proposed:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constant Sum:&lt;/strong&gt; &lt;code&gt;x + y = k&lt;/code&gt;. Zero slippage but can be fully drained; suitable only for pegged assets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constant Mean (Balancer):&lt;/strong&gt; &lt;code&gt;xʷ · y^(1−w) = k&lt;/code&gt; for weight &lt;code&gt;w ∈ (0, 1)&lt;/code&gt;. Generalizes CPMM to non-50/50 pools. The spot price becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P = (w_y · x) / (w_x · y)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;StableSwap (Curve):&lt;/strong&gt; A hybrid that interpolates between constant sum (low slippage near peg) and constant product (resistance to full drain):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A · nⁿ · Σxᵢ + D = A · nⁿ · D + D^(n+1) / (nⁿ · Πxᵢ)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;A&lt;/code&gt; is the &lt;strong&gt;amplification coefficient&lt;/strong&gt;, &lt;code&gt;n&lt;/code&gt; is the number of tokens, and &lt;code&gt;D&lt;/code&gt; is the invariant. As &lt;code&gt;A → 0&lt;/code&gt;, this approaches constant product; as &lt;code&gt;A → ∞&lt;/code&gt;, it approaches constant sum.&lt;/p&gt;

&lt;p&gt;Each invariant represents a different position on the &lt;strong&gt;liquidity-slippage trade-off curve&lt;/strong&gt;, optimized for different asset classes and market conditions.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Fee Mechanics and Arbitrage Equilibrium
&lt;/h2&gt;

&lt;h3&gt;
  
  
  6.1 Fee Integration
&lt;/h3&gt;

&lt;p&gt;In practice, Uniswap V2 applies a 0.3% fee to each trade. The fee is retained in the pool, incrementally increasing &lt;code&gt;k&lt;/code&gt; over time. Formally, for a trade of &lt;code&gt;Δx&lt;/code&gt; with fee rate &lt;code&gt;γ ∈ (0, 1)&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Δy = (y · γ · Δx) / (x + γ · Δx),   where γ = 1 − fee rate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Uniswap V2's 0.3% fee, &lt;code&gt;γ = 0.997&lt;/code&gt;. This slight modification ensures fees accrue to LPs without disrupting the core invariant logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  6.2 Arbitrage as Price Discovery
&lt;/h3&gt;

&lt;p&gt;The AMM does not fetch external prices. Instead, it relies on &lt;strong&gt;arbitrageurs&lt;/strong&gt; to keep pool prices aligned with external markets. If the pool's spot price &lt;code&gt;P(X/Y) = y/x&lt;/code&gt; deviates from the market price &lt;code&gt;P*&lt;/code&gt;, an arbitrageur can profit by trading against the pool until the prices converge. This is the mechanism by which AMMs participate in global price discovery, and why deep pools (large &lt;code&gt;k&lt;/code&gt;) are valuable: they resist price manipulation by requiring large capital to shift the spot price.&lt;/p&gt;

&lt;p&gt;The equilibrium condition is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P(X/Y)_pool = P(X/Y)_market   ⟺   y/x = P*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any deviation creates a risk-free arbitrage opportunity (net of fees and gas costs), which market participants rapidly eliminate.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Conclusion
&lt;/h2&gt;

&lt;p&gt;The constant product market maker is a remarkable piece of applied mathematics. From the simple constraint &lt;code&gt;x · y = k&lt;/code&gt;, an entire ecosystem of automated, trustless trading emerges. We have derived the output formula for trades, characterized spot price and slippage, and formally quantified impermanent loss as a function of price divergence. We have also shown how Uniswap V3's concentrated liquidity generalizes the classic model via virtual reserves and a liquidity parameter &lt;code&gt;L&lt;/code&gt;, achieving dramatic capital efficiency gains within user-defined price ranges.&lt;/p&gt;

&lt;p&gt;These constructs are not merely academic curiosities. As of 2024, Uniswap alone has processed over $2 trillion in cumulative trading volume, all governed by these invariants encoded in a few hundred lines of Solidity. The mathematics of AMMs sits at the intersection of convex optimization, mechanism design, and financial engineering — and continues to evolve with new invariant designs, oracle integrations, and layer-2 deployments.&lt;/p&gt;

&lt;p&gt;Understanding the underlying mathematics is not optional for practitioners in this space. The formulas presented here directly determine LP profitability, trading costs, and systemic risk — making rigorous analysis both intellectually rewarding and practically essential.&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Adams, H., Zinsmeister, N., Salem, M., Keefer, R., &amp;amp; Robinson, D. (2021). &lt;em&gt;Uniswap v3 Core&lt;/em&gt;. Uniswap Labs. &lt;a href="https://uniswap.org/whitepaper-v3.pdf" rel="noopener noreferrer"&gt;https://uniswap.org/whitepaper-v3.pdf&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adams, H., &amp;amp; Zinsmeister, N. (2020). &lt;em&gt;Uniswap v2 Core&lt;/em&gt;. Uniswap Labs. &lt;a href="https://uniswap.org/whitepaper.pdf" rel="noopener noreferrer"&gt;https://uniswap.org/whitepaper.pdf&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Egorov, M. (2019). &lt;em&gt;StableSwap — efficient mechanism for Stablecoin liquidity&lt;/em&gt;. Curve Finance. &lt;a href="https://curve.fi/files/stableswap-paper.pdf" rel="noopener noreferrer"&gt;https://curve.fi/files/stableswap-paper.pdf&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Angeris, G., Kao, H. T., Chiang, R., Noyes, C., &amp;amp; Chitra, T. (2019). &lt;em&gt;An analysis of Uniswap markets&lt;/em&gt;. arXiv:1911.03380.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pintail. (2020). &lt;em&gt;Uniswap: A Good Deal for Liquidity Providers?&lt;/em&gt; Medium. &lt;a href="https://medium.com/@pintail/uniswap-a-good-deal-for-liquidity-providers-104c0b6816f2" rel="noopener noreferrer"&gt;https://medium.com/@pintail/uniswap-a-good-deal-for-liquidity-providers-104c0b6816f2&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Martinelli, F., &amp;amp; Mushegian, N. (2019). &lt;em&gt;Balancer: A Non-Custodial Portfolio Manager, Liquidity Provider, and Price Sensor&lt;/em&gt;. Balancer Labs. &lt;a href="https://balancer.fi/whitepaper.pdf" rel="noopener noreferrer"&gt;https://balancer.fi/whitepaper.pdf&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>algorithms</category>
      <category>blockchain</category>
      <category>computerscience</category>
      <category>cryptocurrency</category>
    </item>
  </channel>
</rss>
