Constant Function Market Maker (CFMM)
- CFMMs are automated market makers that maintain a constant invariant function for every trade, ensuring consistent liquidity dynamics.
- They leverage properties like concavity, homogeneity, and scale invariance to enable efficient decentralized price discovery and programmable liquidity.
- Generalized invariants such as G3Ms offer flexible trade-offs between slippage and capacity, supporting optimal routing and robust risk management.
A constant function market maker (CFMM) is an automated market maker defined by an invariant: a deterministic, typically concave and nondecreasing, function of its reserves that must remain constant (up to fees) for each allowable trade. CFMMs underpin most decentralized exchanges (DEXs), offering programmable and algorithmically tractable liquidity, price discovery, and routing. Their mathematical structure unifies major DeFi protocols, connects to prediction market literature, and has motivated both axiomatic and optimization-based research frameworks.
1. Formal Structure and Axiomatic Foundations
A CFMM is specified by a reserve vector and a trading (or potential/invariant) function , usually required to be strictly increasing, continuous, and concave on the relevant domain. A valid trade updates reserves to if and only if , potentially with input fees adjusted by factor (Zanger, 2022, Frongillo et al., 2023, Schlegel et al., 2022).
Key Axioms for an Invariant Function
- Increasingness: is strictly increasing in each reserve.
- Separability/Independence: Marginal rates depend on only the assets traded.
- Scale Invariance: for all .
- Concavity: Ensures convexity of trade sets and monotonic worsening of terms with trade size.
- Symmetry/Non-Concentrated Liquidity: No axis intersection; infinite liquidity unless all but one reserve is exhausted (Schlegel et al., 2022).
A broad class of trading functions includes the constant-product (Uniswap), constant-sum, and weighted geometric mean (Balancer) forms:
Axiomatic analysis proves that scale-invariant, independent CFMMs are necessarily constant-product (geometric mean) forms—justifying their dominance in DeFi (Schlegel et al., 2022, Frongillo et al., 2023). Translation invariance, relevant in prediction markets, yields log-linear (LMSR) forms.
2. Family of Invariants: G3Ms and Generalized f-Means
CFMM models can be generalized via generalized mean invariants (G3Ms), parameterized by (Zanger, 2022):
- : arithmetic mean (constant-sum), giving zero slippage but finite trade capacity.
- : geometric mean (constant-product), supports unbounded trades but induces slippage.
The G3M defines a one-parameter family interpolating between these two extremes, with the trade output for input given by: For , G3M admits unbounded trades with slippage growing as a sublinear negative power of remaining reserve (Zanger, 2022). Concavity, homogeneity, and monotonicity of for guarantee economic tractability and arbitrage bounds.
A more general extension is the generalized f-mean: where is any continuous, strictly monotone function. These Gf3Ms allow designer sculpting of slippage, depth, and risk curves beyond the G3M parameterization, preserving CFMM validity where is concave, homogeneous, and differentiable (Zanger, 2022).
3. Analytical Properties: Slippage, Price Impact, and Liquidity
The spot price at state is dictated by the gradient of the invariant: Slippage for a finite trade is the deviation of the realized price from the local spot; for constant-sum (p=1), this is zero, but for geometric mean (p=0), slippage increases rapidly as reserves are depleted (Zanger, 2022).
Liquidity depth is determined directly by the invariant and is often proportional to the reserves (degree-1 homogeneity). For a homogeneous invariant, arbitrage bounds, depth metrics, and reserve depletion safeguards are inherited from the convex geometry of the invariant function (Angeris et al., 2023, Frongillo et al., 2023).
4. Optimization, Routing, and Generalization
CFMMs offer a convex-analytic framework for multi-asset and multi-market trading and optimal routing (Angeris et al., 2021, Angeris et al., 2022, Diamandis et al., 2023). In networks of CFMMs, the set of feasible trades is convex, and optimal routing reduces to a convex program: where are convex trade sets derived from the invariants of each market, and encodes the objective (utility, liquidation value, or arbitrage detection). The dual variables of this routing program converge to no-arbitrage price vectors. Special structure (e.g., Uniswap v3's "aggregate" bins) enables efficient per-bin or per-pool parallelization and rapid optimization (Diamandis et al., 2023).
Beyond two-token pools, CFMMs generalize to n-asset settings, batch auctions, and hybrid protocols. Axiomatic and geometric frameworks subsume both DeFi and cost-function prediction market structures, with convex duality providing a bridge to proper scoring rules and information-elicitation markets (Frongillo et al., 2023, Schlegel et al., 2022).
5. Economic Implications, Adversarial Considerations, and MEV
CFMMs' properties are shaped by invariant curvature. Low-curvature (flat) curves minimize slippage and benefit LPs in pools with uninformed or mean-reverting flows (e.g., stablecoins), whereas high curvature offers adverse selection protection for LPs against informed traders (Angeris et al., 2020). This trade-off is central in pool design, especially for incentivized liquidity or "yield farming."
Maximal Extractable Value (MEV)—adversarial profit from reordering or sandwiching trades—depends structurally on CFMM invariants and liquidity parameters. The game-theoretic analysis establishes that routing and reordering MEV are bounded by pool curvature and liquidity depth. For well-designed CFMMs and sufficient liquidity, the price of anarchy remains constant, and the worst-case user price impact under adversarial trade reordering only grows logarithmically with the number of trades (Kulkarni et al., 2022).
Arbitrageurs maintain price parity between CFMM-implied prices and external/oracle prices, enforcing a direct connection between reserves and real-world markets. Under mild convexity and path-deficiency conditions, rational arbitrageurs ensure efficient, truthful price discovery in the absence of external manipulation (Angeris et al., 2020, Angeris et al., 2023).
6. Extensions: Privacy, Derivative Replication, and Design Optimization
Recent work extends the CFMM framework to address privacy protection (personalized local differential privacy with per-trade fees calibrated to liquidity and privacy parameters) (Goyal et al., 2023), time-dependent option replication (e.g., RMM-01 pools that replicate Black–Scholes covered calls) (Jepsen et al., 2023), and optimal curve design derived directly from beliefs about future price distributions (Goyal et al., 2022). The latter is achieved by convex optimization over the liquidity profile function , resulting in optimal trade-off curves for slippage, fee revenue, and LP opportunity cost, and enabling the inference of implicit market-maker beliefs from an observed curve.
Design choices for fee rates, curve curvature, and liquidity range are quantitatively linked to pool profitability, capital efficiency, and market robustness (Evans et al., 2021, Dewey et al., 2023, Monga, 2024). Concentrated liquidity models (e.g., Uniswap v3) enhance capital efficiency while sacrificing convexity and continuous trade support.
7. Synthesis and Theoretical Impact
CFMMs unify core concepts from DeFi market microstructure, convex optimization, prediction market elicitation, and geometric functional analysis. The canonical trading functions are nondecreasing, concave, and positively homogeneous—properties ensuring robust economic incentives and tractable trade/price computations (Angeris et al., 2023, Angeris et al., 2021). The “geometry-first” viewpoint enables the systematic composition and aggregation of multiple market primitives.
The theoretical framework gives rigorous characterizations of admissible invariants, trade sets, and payoffs, allowing for derivative-replicating pools, risk-shaping through invariant design, and formal analysis of practical phenomena such as MEV, privacy cost, and the trade-off between capital efficiency and impermanent loss (Angeris et al., 2021, Goyal et al., 2022).
References:
- G3Ms: "G3Ms: Generalized Mean Market Makers" (Zanger, 2022)
- CFMM Axiomatic Characterization: "An Axiomatic Characterization of CFMMs and Equivalence to Prediction Markets" (Frongillo et al., 2023)
- Multi-asset Convex Optimization: "Constant Function Market Makers: Multi-Asset Trades via Convex Optimization" (Angeris et al., 2021)
- Price/Oracle: "Improved Price Oracles: Constant Function Market Makers" (Angeris et al., 2020)
- Curvature and Economic Trade-offs: "When does the tail wag the dog? Curvature and market making" (Angeris et al., 2020)
- Gf3Ms: (Zanger, 2022)
- Optimal Routing: (Angeris et al., 2022, Diamandis et al., 2023)
- Social Welfare and MEV: (Mazorra et al., 2022, Kulkarni et al., 2022)
- Optimal Curve Design: (Goyal et al., 2022)
- Geometry/Conic Duality: (Angeris et al., 2023)
- Privacy: (Goyal et al., 2023)
- Replication: (Angeris et al., 2021)
- Fee Economics: (Evans et al., 2021)
- Option Replication in CFMMs: (Jepsen et al., 2023)
- DeFi Market Microstructure: (Monga, 2024)
- Batch Auction Composition: (Ramseyer et al., 2022)