---
# System prepended metadata

title: Liquidity_book
tags: [AMM, Research]

---

# Liquidity Book Framework for Uniswap V4

This notes introduce the *liquidity book*, a mathematical framework designed to model liquidity in Uniswap V4. The liquidity book accommodates key features of Uniswap V4, such as liquidity profiles, limit orders, and *hooks*. Hooks, introduced in Uniswap V4, enable custom functionality to be added to liquidity pools, facilitating features like on-chain limit orders and dynamic fees based on external data (e.g., volatility). The concept of a liquidity book, with its ability to represent continuous limit orders, directly relates to limit order book models, such as those studied by Carmona and Webster, where liquidity providers post limit orders and liquidity takers execute market orders.

In this notes, we first define the liquidity book and demonstrate how Uniswap V3 fits within this framework. We then recall the Carmona-Webster model, a foundational approach to order book modeling, and highlight its relationship to the liquidity book. Furthermore, we extend the liquidity book framework to model macroscopic market dynamics, where order flows and prices evolve continuously. We explore several models for these dynamics, including Markovian, myopic arbitrage-driven, and mispricing-driven scenarios. Finally, we discuss the implications of these models for optimal market making.



## The Liquidity Book
This section introduces the concept of the liquidity book, a mathematical tool that extends the standard Uniswap framework to model liquidity in Uniswap V4. It accommodates the specific features of Uniswap V4, such as liquidity profiles, limit orders, and hooks, within a rigorous mathematical structure.

We consider a single liquidity taker and a single liquidity provider trading an asset whose possible logarithmic price range is $(-\infty, \infty)$.

* The liquidity provider moves first, choosing the *liquidity profile* they place on Uniswap. This liquidity profile is represented by a control variable $(\ell_a, \ell_b)$, a pair of positive measures on $(-\infty, \infty)$.
* The liquidity taker then chooses the control variable $(q_\beta, q_\alpha) \in (-\infty, \infty) \times (-\infty, \infty)$, representing the market orders they want to execute on that liquidity book.

### Basic Definitions
This subsection focuses on the fundamental relationships between the two agents, their orders, and inventories.

#### Liquidity Provider
The control $(\ell_a, \ell_b)$ of the liquidity provider represents their *liquidity profile* in logarithmic price.

We define the best bid and best ask log prices as:

$$
q_b := \sup\{q \in \text{supp}(\ell_b)\} \quad \text{and} \quad q_a := \inf\{q \in \text{supp}(\ell_a)\}
$$

#### Liquidity Taker
The control $(q_\beta, q_\alpha)$ of the liquidity taker represents their *market orders*:

* A market order placed against the bids will cause all bid orders at or above the price $q_\beta$ to be executed.
* A market order placed against the asks will cause all liquidity below the price level $q_\alpha$to be executed.
* The limit cases $q_\alpha = -\infty$ and $q_\beta = \infty$ correspond to "empty" market orders that do not execute.

The execution of a market order leads to the following changes in the liquidity provider's cash and inventory:

\begin{split}
\Delta X &= \frac12 \int_{q_\beta}^\infty \ell_b(q) e^{-\frac12q} dq - \frac12 \int^{q_\alpha}_{-\infty} \ell_a(q) e^{-\frac12q} dq\\
\Delta Y &= \frac12 \int^{q_\alpha}_{-\infty} \ell_a(q) e^{\frac12q} dq - \frac12 \int_{q_\beta}^\infty \ell_b(q) e^{\frac12q} dq
\end{split}

where $X$ is the inventory of the liquidity provider, $\Delta X$ represents the change in inventory, $Y$ is the cash of the liquidity provider, and $\Delta Y$ represents the change in cash.

#### Assumptions
We make the following assumptions:

* **(No-Cross)** The liquidity profile $(\ell_b, \ell_a)$ are such that $q_b \leq q_a$.
* **(Single-Execution)** It is never optimal for the liquidity taker to buy and sell simultaneously.

In particular, the liquidity taker's control can be represented by a single real number $\eta$:

* if $\eta \in (q_b, q_a)$, there is no trade;
* if $\eta \geq q_a$, a buy happens but no sell;
* if $\eta \leq q_b$, a sell happens but no buy.

*Remark.* The second assumption follows from the first when the liquidity taker is risk-neutral.


### Uniswap V3 as a Liquidity Book
This subsection demonstrates how Uniswap V3 fits within the liquidity book framework, showing that it can be considered a specific instance of this broader model.

#### Uniswap V3 LP Position
In Uniswap V3, a *liquidity provider (LP)* determines their position by choosing a tuple $(P_l, P_r, L, \gamma)$ of parameters, where:

* $(P_l, P_r)$: price range of liquidity provision, with $P_l < P_r$
* $L$: amount of liquidity provided
* $1 - \gamma$: fixed proportional fee tier charged by the LP

The *Automated Market Maker (AMM)* records a price $p$ such that $P_l \le P \le P_r$, updated after each market order. More precisely, the execution of a market order $\eta$ leads to the following changes:

* if $\gamma^{-1}P_{old} < \eta$, then
    $$
    P_{new} = \min\{\gamma \eta, P\}, \quad \Delta X = L \left(\frac{1}{\sqrt{P_{new}}} - \frac{1}{\sqrt{P_{old}}} \right), \quad \Delta Y = \gamma^{-1} L (\sqrt{P_{new}} - \sqrt{P_{old}})
    $$
* if $\gamma P_{old} > \eta$, then
    $$
    P_{new} = \max\{\gamma^{-1} \eta, P\}, \quad \Delta X = \gamma^{-1} L \left(\frac{1}{\sqrt{P_{new}}} - \frac{1}{\sqrt{P_{old}}} \right), \quad \Delta Y = L (\sqrt{P_{new}} - \sqrt{P_{old}})
    $$

#### Connection to Liquidity Profile
A Uniswap V3 LP position can be viewed as a liquidity profile:

\begin{split}
\ell^a_p(q) &= L \cdot \pmb{1}_{q \in [p - \ln \gamma, p_r - \ln \gamma]} \\
\ell^b_p(q) &= L \cdot \pmb{1}_{q \in [p_l + \ln \gamma, p + \ln \gamma]} 
\end{split}

where $p = \ln P$, $p_l = \ln P_l$, $p_r = \ln P_r$ are prices in log scale, and $\pmb{1}_{condition}$ is an indicator function that equals 1 when the condition is true and 0 otherwise. In particular:

* $q_b = p + \ln \gamma$ and $q_a = p - \ln \gamma$
* This is an automated rule to update the log mid-price $p$ with a fixed log spread $-2 \ln \gamma$.

#### Relation to Inventory and Cash
A market order results in the following changes in cash and inventory:

\begin{split}
\Delta X &= \frac{1}{2} \int_{\ln \eta + \ln \gamma}^\infty \ell^b_p(q) e^{-\frac{1}{2}q} dq - \frac{1}{2} \int^{\ln \eta - \ln \gamma}_{-\infty} \ell^a_p(q) e^{-\frac{1}{2}q} dq \\
\Delta Y &= \frac{1}{2} \int^{\ln \eta - \ln \gamma}_{-\infty} \ell^a_p(q) e^{\frac{1}{2}q} dq - \frac{1}{2} \int_{\ln \eta + \ln \gamma}^\infty \ell^b_p(q) e^{\frac{1}{2}q}
\end{split}


### Limit Orders
*Question:* How can discrete limit orders be represented within the liquidity book framework using delta measures?



## The Carmona-Webster Model
This section recalls the order book modeling framework developed by Carmona and Webster. We consider a single liquidity taker and a single liquidity provider trading an asset whose possible price range is $(0, \infty)$.

* The liquidity provider moves first, choosing the *liquidity profile* they place on Uniswap. This liquidity profile is represented by a control variable $(b, a)$, a pair of positive measures on $(0, \infty)$.
* The liquidity taker then chooses the control variable  $(\beta, \alpha) \in (0, \infty) \times (0, \infty)$, representing the market orders they want to execute on that liquidity book.


### Basic Definitions
This subsection focuses on the fundamental relationships between the two agents, their orders, and inventories.

#### Liquidity Provider
The control  $(b, a)$ of the liquidity provider represents their *limit orders*.

We define the best bid and best ask prices as:

$$
\overline{b} := \sup\{p \in \text{supp}(b)\} \quad \text{and} \quad \underline{a} := \inf\{p \in \text{supp}(a)\}
$$

#### Liquidity Taker
The control $(\beta, \alpha)$ of the liquidity taker represents their *market orders*:

* A market order placed against the bids will cause all bid orders at or above the price $\beta$ to be executed.
* A market order placed against the asks will cause all the liquidity below the price level *α* to be executed.
* The limit cases $\alpha = 0$ and $\beta = \infty$ correspond to "empty" market orders that do not execute.

The execution of a market order leads to the following changes in the liquidity provider's cash and inventory:

\begin{split}
\Delta X &= b([\beta, \infty)) - a((0, \alpha]) \\
\Delta Y &= \int_{(0, \alpha]} p a(dp) - \int_{[\beta, \infty)} p b(dp)
\end{split}

where $X$ is the inventory of the liquidity provider, $\Delta X$ represents the change in inventory, $Y$ is the cash of the liquidity provider, and $\Delta Y$ represents the change in cash.


### Assumptions
We make the following assumptions:

* **(No-Cross)** The liquidity profile $(b, a)$ satisfies $\overline{b} \leq \underline{a}$.
* **(Single-Execution)** It is never optimal for the liquidity taker to buy and sell simultaneously.

In particular, the liquidity taker's control can be represented by a single real number $\eta$:

* if $\eta \in (\overline{b}, \underline{a})$, there is no trade;
* if $\eta \geq \underline{a}$, a buy occurs but no sell;
* if $\eta \leq \overline{b}$, a sell occurs but no buy.

*Remark.* Carmona and Webster show that the second assumption follows from the first when the liquidity taker is risk-neutral.


### Correspondence to Liquidity Book
Given a liquidity profile $(\ell_a, \ell_b)$, the corresponding limit order in the Carmona-Webster model is given by:

$$
b(dp) = \frac12 \ell_b(\ln p) p^{-\frac32} dp, \quad a(dp) = \frac12 \ell_a(\ln p) p^{-\frac32} dp
$$

These equations show a one-to-one correspondence between the Carmona-Webster model and the liquidity book framework. In particular, Uniswap V3 positions fall into this category, and all the results in the aforementioned work of Carmona and Webster apply directly to the liquidity book modeling.



## Macroscopic Liquidity Book Dynamics
Having established the liquidity book framework and its relationship to the Carmona-Webster model, we now turn to modeling the dynamics of the liquidity book itself. This section proposes several macroscopic market models to describe the evolution of bid/ask prices. These models use continuous-time stochastic processes to capture the flow of orders and price movements, providing a higher-level perspective on how the liquidity book evolves over time. These dynamics will later be used to formulate an optimal market-making problem.


### Markovian Order Flows
This model describes the dynamics of the best bid and ask prices as continuous stochastic processes driven by a common set of factors. We use a diffusion process to represent these underlying factors, capturing the inherent randomness and volatility of market conditions.

#### Driving Process
Consider a diffusion process $Z := (Z_t)_{t \in [0,T]}$ driven by the following SDE:

\begin{split}
Z_0 &= z_0 \in \mathbb{R}^d \\
dZ_t &= \Gamma(t, Z_t) dt + \sum_{j=1}^m \Sigma_j(t, Z_t) dW^j_t
\end{split}

for some continuous function $\Gamma:[0,T] \times \mathbb{R}^d \rightarrow \mathbb{R}^d$ and $\Sigma: [0,T] \times \mathbb{R}^d \rightarrow \mathbb{R}^{d \times m}$ with $\Sigma^{i,j} = (\Sigma_j)^i$ with $\Sigma^{i,j} = (\Sigma_j)^i$, where $W^j_t$ are independent Brownian motions.

The process $Z$ serves as a driving process that determines the dynamics in our model, representing underlying economic or market factors that influence price movements.

#### Bid-Ask Dynamics
We model the best bid/ask log prices, $q^a_t$ and $q^b_t$, as continuous stochastic processes adapted to the Brownian filtration 𝔽 generated by the $m$-dimensional Brownian motion $W = (W^1, \dots, W^m)$. The dynamics are given by:

$$
d q^a_t = a_t - dL_t, \quad d q^b_t = dU_t -b_t
$$

where
* $q^a_t$ is the best ask price.
* $q^b_t$ is the best bid price.
* $a_t = a(Z_t)$ and $b_t = b(Z_t)$ with $a,b: \mathbb{R}^d \rightarrow \mathbb{R}_+$ are bounded positive functions, representing the influence of the driving process on price movements.
* $U_t$ and $L_t$ are non-decreasing continuous processes satisfying:
    * $U_0 = L_0 = 0$
    * $U_t$ increases only when $q^a_t - q^b_t = \delta$ and $a(Z_t) > b(Z_t)$.
    * $L_t$ increases only when $q^a_t - q^b_t = \delta$ and $b(Z_t) > a(Z_t)$.
* $\delta = 2\ln \gamma_\min$ with $1-\gamma_\min$ the minimum Uniswap fee tier existing, representing the maximum log price spread due to Uniswap V3 liquidity provision.

#### Intuition
* Liquidity provision on the blockchain is relatively slow compared to high-frequency market making. Therefore, we use the diffusion process $Z_t$ and functions  $a(Z_t)$ and $b(Z_t)$ to model the price movements primarily driven by market orders, reflecting the impact of supply and demand. The diffusion process captures the continuous and random nature of price fluctuations in the market.
* Given that a portion of the liquidity comes from Uniswap V3 positions, which operate with a fixed log spread, the bid-ask spread $q^a_t - q^b_t$ is capped by $\delta = -2\ln \gamma_\min$. Since $1-\gamma_\min$ represents the minimum Uniswap fee tier, $\delta = -2\ln \gamma_\min$ represents the log price spread imposed by these positions.
* As a result, we introduce two reflection processes, $L_t$ and $U_t$, to model the automated liquidity adjustments by Uniswap V3 positions. $L_t$ and $U_t$ act to constrain the bid-ask spread to be greater than or equal to $\delta$.

#### Comparison: Uniswap V3
To illustrate how Uniswap V3 works within our framework, we describe the dynamics of Uniswap V3 with a fixed fee tier $\gamma$.

Let $q_t$ be the log price reported by Uniswap, then we have

$$
q_t = a_t - b_t, \quad q^a_t = q_t - \ln \gamma, \quad q^b_t = q_t + \ln \gamma
$$

where 
* $a_t$ represents the price movement driven by ask market orders.
* $b_t$ represents the price movement driven by bid market orders.
* $q^a_t$ is the ask price reported by the AMM, adjusted for the fee.
* $q^b_t$ is the bid price reported by the AMM, adjusted for the fee.

*Remark.* In this degenerate case, $U_t$ and $L_t$ are completely determined by the order flows through $a_t = dU_t$ and $b_t = dL_t$.


### Myopic Arbitrage-Driven Order Flows
This model assumes that price dynamics are primarily driven by arbitrageurs who exploit price discrepancies between the liquidity book and an external reference market.

#### Assumptions
1.  The external reference market offers infinite liquidity and incurs no trading cost. This implies that arbitrageurs can trade any amount in the reference market without affecting its price.
2.  The market operates without the influence of noise traders. This simplification focuses the model on the behavior of arbitrageurs, excluding random or uninformed trading activity.
3.  Arbitrageurs continuously monitor the market and act instantaneously to exploit any arbitrage opportunities. This "myopic" behavior means they only consider the current price difference and act immediately, without anticipating future price movements.

#### Bid-Ask Dynamics
Let $S_t$ be the reference market price and $s_t = \ln S_t$ be the log price. Then, the liquidity book dynamics are given by:

$$
dq^a_t = d \tilde{U}_t - dL_t, \quad dq^b_t = dU_t - d\tilde{L}_t
$$

where
* $\tilde{U}_t$ and $\tilde{L}_t$ are non-decreasing continuous processes satisfying:
    * $\tilde{U}_0 = \tilde{L}_0 = 0$
    * $\tilde{U}_t$ increases only when $s_t = q^a_t$. This represents arbitrageurs buying from the liquidity book (increasing the ask price) when it's overpriced compared to the reference market.
    * $\tilde{L}_t$ increases only when $s_t = q^b_t$. This represents arbitrageurs selling to the liquidity book (decreasing the bid price) when it's underpriced compared to the reference market.
* $U_t$ and $L_t$ are non-decreasing continuous processes as described in the "Markovian Order Flows" section.

#### Intuition
* $\tilde{U}_t$ and $\tilde{L}_t$ model the price pressure exerted by myopic arbitrageurs seeking to align the liquidity book prices with the reference market price.
* $U_t$ and $L_t$ model the automated liquidity adjustments imposed by Uniswap V3 positions, which may counteract or reinforce the arbitrage activity.

#### Comparison: Uniswap V3
Under these assumptions, Uniswap V3 behaves as described in our previous work:

$$
q_t = \tilde{U}_t - \tilde{L}_t, \quad q^a_t = q_t - \ln \gamma, \quad q^b_t = q_t + \ln \gamma
$$

where
* $q_t$ is the log price reported by the AMM.
* $\tilde{U}_t$ and $\tilde{L}_t$ represent the price movements driven by arbitrage activity, as described above.
* $\gamma$ is the fee tier.


### Mispricing-Driven Order Flows
This model assumes that order flows are driven by the deviation of the liquidity book's bid/ask prices from the reference market price.

#### Bid-Ask Dynamics
We define the bid/ask mispricing as $Z^a_t = q^a_t - s_t$ and $Z^b_t = s_t - q^b_t$, where $s_t$ is the log price of the reference market.

Then, the liquidity book dynamics are described as in the Markovian Order Flows model:

$$
d q^a_t = a(Z^a_t) - dL_t, \quad d q^b_t = dU_t - b(Z^b_t)
$$

where
* $a,b: \mathbb{R} \rightarrow \mathbb{R}_+$ are bounded, non-decreasing, positive functions. The non-decreasing property of these functions implies that as the mispricing increases, the order flow also increases.
* $L_t$ and $U_t$ are non-decreasing continuous processes representing the automated liquidity adjustments, as described in the "Markovian Order Flows" section.

#### Intuition
The greater the deviation of the liquidity book's prices from the reference market price, the higher the expected order flow. This reflects the idea that traders are more likely to trade when they perceive a price discrepancy.

#### Comparison: Uniswap V3
Under this setup, the Uniswap V3 dynamics simplify to:

$$
dp_t = a(Z_t) - b(-Z_t), \quad q^a_t = p_t - \ln \gamma, \quad q^b_t = p_t + \ln \gamma
$$

where $Z_t = s_t - p_t$ is the mispricing process, representing the difference between the reference market's log price and Uniswap V3's log price.



## Macroscopic Market Making
The macroscopic market models described above lead to considerations of the corresponding optimal market-making problem.


### Control Problem Formulation
The liquidity provider (LP) aims to maximize their profit over a finite time horizon $[0,T]$, while considering inventory risk and ensuring the liquidation of any remaining assets by time $T$. The market state is described by the tuple $(x_t, y_t, q^a_t, q^b_t)$.

#### LP Strategies
The liquidity provider controls their capital by two binary predictable processes $\pmb{\ell}_t = (\ell^a_t, \ell^b_t) \in \{0,1\}^2$ representing the LP's active state:

* $\ell^a_t = 1$ (resp. $\ell^b_t = 1$): Active liquidity provision, with the position is at an infinitesimal neighborhood of the current best ask (resp. bid) price.
* $\ell^a_t = 0$ (resp. $\ell^b_t = 0$): No active liquidity provision around the current best ask (resp. bid) price.

The resulting dynamics of the LP's inventory $X$ and cash holdings $Y$ are given by:

\begin{split}
dX_t &= L \left( \ell^b_t e^{-\frac12 q^b_t} b_t - \ell^a_t e^{-\frac12 q^a_t} a_t \right) dt \\
dY_t &= L \left( \ell^a_t e^{\frac12 q^a_t} a_t - \ell^b_t e^{-\frac12 q^b_t} b_t \right) dt
\end{split}

where $L$ is a given constant representing the fixed amount of liquidity provided.

*Remark.* We could also explore controlling the amount of liquidity provided, represented by $\mathcal{L}_t = (L^a_t, L^b_t)$.

#### Objective
The LP's objective is to maximize the following expected value:

$$
\max_{\pmb{\ell} \in \mathcal{A}_{0, T}} \mathbb{E} \left[ Y^{\pmb{\ell}}_T + X^{\pmb{\ell}}_T \left(e^{q_T} - \alpha X^{\pmb{\ell}}_T \right) - \phi \int_0^T (X^{\pmb{\ell}}_t)^2 dt \right]
$$

where:
* $q_T$ is LP's fair price, which could be a "mid price" between $(q^a_T, q^b_T)$ (e.g. $\frac{q^a_T + q^b_T}2$ in the Markovian model and $s_T$ in the arbitrage/mispricing model).
* $\pmb{\ell} = (\ell^a_t, \ell^b_t)_{0 \leq t \leq T}$ represents the LP strategy.
* $X^{\pmb{\ell}} = (X^{\pmb{\ell}}_t)$ is the process representing the liquidity provider's inventory of the risky asset.
* $Y^{\pmb{\ell}} = (Y^{\pmb{\ell}}_t)$ is the process representing the liquidity provider's cash holdings.
* $\alpha$ and $\phi$ are parameters that capture inventory risk aversion and the cost of holding cash, respectively.
* $\mathcal{A}_{t, T} = \{0,1\}^2 \times [t,T]$ is the admissible set of strategies.

#### Comparison to Uniswap V3
While the same market-making problem can be considered within Uniswap V3 setups, the liquidity book framework offers several advantages in tractability:

* In Uniswap V3, bid/ask positions are inherently linked. This constraint limits the LP's ability to reduce inventory skewness (and thus risk) in certain situations.
* Consequently, the optimal control in a Uniswap V3 setting might be to cease providing liquidity entirely after a certain threshold.
* In contrast, this framework decouples control of bid and ask liquidity provision, similar to classical LOB market-making models. This decoupling allows for more nuanced and potentially more effective market-making strategies.



## References
* Carmona, R., & Webster, K. (2019). The self-financing equation in limit order book markets. *Finance and Stochastics*, *23*, 729–759. <https://doi.org/10.1007/s00780-019-00398-z>
* Carmona, R., & Webster, K. (2012). High Frequency Market Making. *arXiv preprint arXiv:1210.5781*.
* Cartea, Á., Jaimungal, S., & Penalva, J. (2015). Algorithmic and high-frequency trading. *Cambridge University Press*.
* Chitra, T., Kulkarni, K., & Srinivasan, K. (2025). Optimal Routing in the Presence of Hooks: Three Case Studies. *arXiv preprint arXiv:2502.02059*.
* Guéant, O. (2017). Optimal market making. *Applied Mathematical Finance*, *24*(2), 112–154. <https://doi.org/10.1080/1350486X.2017.1342552>
* Guilbaud, F., & Pham, H. (2015). Optimal high-frequency trading in a pro rata microstructure with predictive information. *Mathematical Finance*, *25*(3), 545–575. <https://doi.org/10.1111/mafi.12042>
* Guo, X., & Zervos, M. (2015). Optimal Execution with Multiplicative Price Impact. *SIAM Journal on Financial Mathematics*, *6*(1), 281–306. https://doi.org/10.1137/120894622
* Guo, I., Jin, S., & Nam, K. (2024). Macroscopic Market Making Games. *arXiv preprint arXiv:2406.05662*.
* Tung, S.-N., & Wang, T.-H. (2024). A mathematical framework for modelling CLMM dynamics in continuous time. *arXiv preprint arXiv:2412.18580*.
