A Formal Approach to AMM Fee Mechanisms with Lean 4

A Formal Approach to AMM Fee Mechanisms with Lean 4
Notice: This research summary and analysis were automatically generated using AI technology. For absolute accuracy, please refer to the [Original Paper Viewer] below or the Original ArXiv Source.

Decentralized Finance (DeFi) has revolutionized financial markets by enabling complex asset-exchange protocols without trusted intermediaries. Automated Market Makers (AMMs) are a central component of DeFi, providing the core functionality of swapping assets of different types at algorithmically computed exchange rates. Several mainstream AMM implementations are based on the constant-product model, which ensures that swaps preserve the product of the token reserves in the AMM – up to a \emph{trading fee} used to incentivize liquidity provision. Trading fees substantially complicate the economic properties of AMMs, and for this reason some AMM models abstract them away in order to simplify the analysis. However, trading fees have a non-trivial impact on users’ trading strategies, making it crucial to develop refined AMM models that precisely account for their effects. We extend a foundational model of AMMs by introducing a new parameter, the trading fee $ϕ\in(0,1]$, into the swap rate function. Fee amounts increase inversely proportional to $ϕ$. When $ϕ= 1$, no fee is applied and the original model is recovered. We analyze the resulting fee-adjusted model from an economic perspective. We show that several key properties of the swap rate function, including output-boundedness and monotonicity, are preserved. At the same time, other properties - most notably additivity - no longer hold. We precisely characterize this deviation by deriving a generalized form of additivity that captures the effect of swaps in the presence of trading fees. We prove that when $ϕ< 1$, executing a single large swap yields strictly greater profit than splitting the trade into smaller ones. Finally, we derive a closed-form solution to the arbitrage problem in the presence of trading fees and prove its uniqueness. All results are formalized and machine-checked in the Lean 4 proof assistant.


💡 Research Summary

This paper presents a formal treatment of trading‑fee mechanisms in automated market makers (AMMs), extending the classic constant‑product model to incorporate a fee parameter ϕ∈(0,1]. The authors embed the fee directly into the swap rate function used by real‑world protocols such as Uniswap v2, defining
SXϕ(x, r₀, r₁) = ϕ·r₁·r₀ / (r₀ + ϕ·x).
When ϕ = 1 the model collapses to the fee‑free case; for ϕ < 1 each swap increases the product of reserves, meaning the AMM retains a portion of the output token as fee revenue for liquidity providers.

The paper first formalizes the system: token types, accounts, AMM state, and swap transactions A:swap(x, τ₀, τ₁). It then analyses core economic properties of the fee‑adjusted swap function. Lemma 4 proves output‑boundedness (x·SXϕ < r₁) for all non‑negative inputs and positive reserves, guaranteeing the AMM always has enough output tokens. Lemma 5 establishes strict monotonicity: decreasing the input amount or the reserve of the input token, or increasing the reserve of the output token, strictly raises the swap rate. These properties are essential for the existence of arbitrage opportunities and for proving optimality of certain trades.

A key contribution is the investigation of additivity. In the fee‑free setting the swap rate is additive: swapping x + y tokens yields the same total output as swapping x then y. Lemma 6 introduces a correction factor ζϕ(x, y, r₀, r₁) that quantifies the deviation when ϕ < 1. The factor exceeds 1, showing that a single large swap is more profitable than splitting the same total amount into multiple smaller swaps. Theorem 8 formalizes this “additivity of swap gain”: the gain from a combined swap equals the sum of gains from the constituent swaps plus a strictly positive εϕ term whenever ϕ < 1. This result has practical implications: traders should avoid transaction fragmentation in fee‑bearing AMMs.

The authors then turn to arbitrage. They model an external price oracle P: T₀ → ℝ⁺ and define the external exchange rate X(τ₀, τ₁) = P(τ₀)/P(τ₁). The internal exchange rate XΓ(τ₀, τ₁) is the limit of the swap function as the input amount tends to zero. Theorem 9 derives a closed‑form expression for the swap amount x* that aligns the internal rate with the external rate, effectively bringing the AMM to equilibrium. Lemma 10 proves that this equilibrium swap amount is unique. Theorem 12 identifies an interval of swap amounts that strictly improve the trader’s gain beyond the equilibrium point, and Theorem 13 pinpoints the exact swap amount that maximizes gain—providing a closed‑form optimal arbitrage strategy. Lemma 14 confirms the uniqueness of this optimal solution.

All theorems, lemmas, and auxiliary results are mechanized in the Lean 4 proof assistant. The accompanying library consists of roughly 3,500 lines of Lean code, and each proof has been checked by the verifier. This machine‑checked formalization offers a high degree of confidence in the correctness of the economic analysis and serves as a template for future formal verification of DeFi protocols.

In summary, the paper makes three major contributions: (1) a formal model of AMMs that faithfully captures trading fees, (2) a rigorous economic analysis showing that fees preserve output‑boundedness and monotonicity but break additivity, leading to strictly higher profit for unsplit trades, and (3) a closed‑form, uniquely optimal arbitrage solution for fee‑adjusted AMMs, all verified in Lean 4. The work bridges the gap between theoretical DeFi economics and formal methods, providing both deeper insight into fee dynamics and a concrete, verified foundation for building safer smart‑contract implementations.


Comments & Academic Discussion

Loading comments...

Leave a Comment