---
# System prepended metadata

title: Macroscopic_LP
tags: [Research]

---

# Macroscopic Liquidity Provision

This note proposes a *macroscopic model for Liquidity Provision (LP)* on Uniswap v4. This model represents market orders using continuous order flows rather than typical discrete point processes. The primary goal is to introduce a novel, tractable framework for analyzing the Uniswap v3 LP optimization problem, specifically focusing on the determination of *dynamic fees* $\gamma_t$ and the *optimal rebalancing time* $\tau$.

This joint optimization problem naturally leads to a formulation as an optimal stopping and optimal control problem, whose value function is characterized by a *Hamilton-Jacobi-Bellman Quasi-Variational Inequality (HJB QVI)*.



## The Model 

### Continuous Framework
Let $T>0$ be a trading horizon.

We study a *Concentrated Liquidity Market Maker (CLMM)* for a pair consisting of a risky asset $X$ and a numéraire $Y$. Within the CLMM, we let $X_t$ and $Y_t$ be the non-negative quantities of assets $X$ and $Y$ for the LP at time $t \in [0,T]$.

We assume that there exists an external reference market (e.g., LOB) for trading $X$ and $Y$ with price process $S = (S_t)_{t \in [0,T]}$. This external price follows the *Geometric Brownian Motion (GBM)* dynamics:

$$
dS_t = S_t \sigma dW_t
$$

with $W_t$ a standard Brownian motion. We operate under the risk-neutral measure, assuming zero drift ($\mu=0$) for simplicity.

In the CLMM, liquidity takers arrive according to a continuous flow $\alpha_t$ (liquidity-taking sells of $X$) and $\beta_t$ (liquidity-taking buys of $X$). We denote by $P = (P_t)_{t \in [0,T]}$ the marginal price of $Y$ in terms of $X$ in the CLMM, and $\gamma = (\gamma_t)_{t \in [0,T]}$ the fee tier charged, where $0 < \underline{\gamma} \leq \gamma_t \leq 1$. The CLMM inventory dynamics are then given by:

\begin{cases} 
dX_t &= \ \frac12 P_t^{\frac12} \left\{ \gamma_t^{-1} \alpha_t - \gamma_t \beta_t \right\} dt \\ 
dY_t &= \ \frac12 P_t^{-\frac12} \left\{ \beta_t - \alpha_t \right\} dt \\ 
dP_t &= \ P_t \left( \alpha_t - \beta_t \right) dt \\ 
\alpha_t &= \ \pmb{1}_{P_t \in [\underline{P}, \overline{P}]} \ \alpha(S_t,P_t,\gamma_t) \\ 
\beta_t &= \ \pmb{1}_{P_t \in [\underline{P}, \overline{P}]} \ \beta(S_t,P_t,\gamma_t) 
\end{cases}

with: 
* $X_0, Y_0 > 0$. 
* $0 \leq \underline{P} \leq \overline{P} < \infty$ representing the boundaries of the concentrated liquidity range.
* $\alpha$ and $\beta$ are order flow functions modeled by: \begin{align} \alpha(S, P, \gamma) &= \max\{a_0 (c + \ln \gamma), a_1 (c + \ln \gamma) + a_2 ( \ln S - \ln P + \ln \gamma) \} \\ \beta(S, P, \gamma) &= \max\{b_0 (c + \ln \gamma), b_1 (c + \ln \gamma) + b_2 (\ln P - \ln S + \ln \gamma) \} \end{align} Here the $\max\{\cdot, \cdot\}$ structure models a threshold where order flow is driven by two components: 
    * a baseline component dependent only on the fee tier ($\gamma$), representing *noise trading* (terms $a_0(\cdot)$ and $b_0(\cdot)$), and 
    * an arbitrage/informed component dependent on the *price difference* between the external price $S$ and the effective CLMM price ($\gamma^{-1} P$ or $\gamma P$). 
    * The indicator $\pmb{1}_{P_t \in [\underline{P}, \overline{P}]}$ ensures orders only execute within the concentrated liquidity range.

Note that the system is completely driven by the external price $S$ and the internal price $P$.

### Problem Formulation
The LP's optimization problem is defined by the following actions and goal:

* The LP **provides** a fixed amount of liquidity (W.L.O.G., $\ell=1$) in a neighborhood of the current AMM price $P_t$;
* The LP **determines** the fee tier $\gamma_t \in [\underline{\gamma},1]$; and
* The LP **fully hedges** its initial position at $t=0$.

The hedged PnL $\text{PnL}_t$ at time $t \in [0,T]$ is defined as the change in the portfolio value evaluated at the external price $S_t$:

$$
X_t - X_0 + S_t (Y_t - Y_0)
$$

The LP wants to maximize her expected hedged PnL by solving the joint control and optimal stopping problem:

$$
\sup_{\tau \in \mathcal{T}} \sup_{\gamma \in \Gamma} \mathbb{E} \left[ X_\tau - X_0 + S_\tau (Y_\tau - Y_0)\right]
$$

Here we define:
* $\mathcal{T}_{t,T}$ as the set of *stopping times* taking values in $[t,T]$, and $\mathcal{T} = \mathcal{T}_{0,T}$.
* $\Gamma = [\underline{\gamma},1]$ as the set of admissible fee tiers, with $0 < \underline{\gamma} < 1$.

#### Interpretation
* The stopping time $\tau$ is viewed as the time for rebalancing or exiting the liquidity position.
* The fee tier $\gamma$ is adjusted dynamically to maximize the LP's expected revenue.



## Mathematical Analysis

### PnL Dynamics and Value Function Definition
The accumulation of instantaneous profit (the running reward) can be written as the integral of the change in PnL:

$$
\mathbb{E} \left[ \text{PnL}_t \right] = \int^t_0 \mathbb{E} \left[ d\text{PnL}_s \right] = \int^t_0 \frac12 P_s^{-\frac12} \left\{ \left( \gamma_s^{-1} P_s - S_s \right) \alpha_s + \left( S_s - \gamma_s P_s \right) \beta_s \right\} ds
$$

The terms $\left( \gamma_s^{-1} P_s - S_s \right)$ and $\left( S_s - \gamma_s P_s \right)$ represent the difference between the effective trading price in the CLMM (including the fee $\gamma$) and the external market price $S_s$.

We define the associated value function $v$, which depends on the current state $(t,P,S)$, as the maximum expected future running reward until the optimal stopping time $\tau$:

\begin{align}
v: \quad& [0,T] \times \mathbb{R}_+ \times \mathbb{R}_+ \rightarrow \mathbb{R} \\
&(t,P,S) \mapsto \sup_{\tau \in \mathcal{T}_{t,T}} \sup_{\gamma \in \Gamma} \mathbb{E} \left[ \int^\tau_t \frac12 P_s^{-\frac12} \left\{ \left( \gamma^{-1} P_s - S_s \right) \alpha_s + \left( S_s - \gamma P_s \right) \beta_s \right\} ds\right]
\end{align}

### HJB Quasi-Variational Inequality (QVI)
The value function $v$ is the unique viscosity solution to the following HJB QVI:

$$
0 = \max \left\{ \mathcal{L}v, -v \right\} \quad \text{on} \ [0,T) \times \mathbb{R}_+ \times \mathbb{R}_+
$$

where $\mathcal{L}v$ is the operator associated with the optimal continuation problem, defined as:

$$
\mathcal{L}v = v_t + \frac12 \sigma^2 S^2 v_{SS} +  \sup_{\gamma \in \Gamma} \left\{ P (\alpha - \beta) v_P + \frac12 P^{-\frac12} \left[ \left( \gamma^{-1} P - S \right) \alpha + \left(S - \gamma P \right) \beta \right] \right\}
$$

with the terminal condition $v(T,P,S)=0$.

The term $\sup_{\gamma}$ inside $\mathcal{L}v$ determines the optimal dynamic fee policy, and the $\max\{\mathcal{L}v, -v\}$ structure characterizes the optimal stopping time $\tau$.

### To Do
* Work out the viscosity properties of the value function.



## Numerical Scheme
The HJB QVI is solved backwards in time from $T$ to $0$ using a specialized finite difference approach that balances stability and computational efficiency.


### Discretization and Iterative Method
We discretize the time variable $t$ and state variables $P$ and $S$.

* **Time Grid**: Uniform grid $t_n = n \Delta t$ for $n = 0, \ldots, N$.
* **State Grids**: $P$ is restricted to $[P_\min, P_\max]$ and $S$ to a finite domain $[S_\min, S_\max]$.
* **Efficiency Strategy**: By applying an implicit scheme to the diffusion term $\partial_{S}^{2}v$ and an *explicit scheme* to the reward terms, we decouple the state variables. This allows us to independently solve a smaller, tridiagonal linear system for each $P_j$ grid point, significantly reducing complexity.


### Backward Iteration Step
Starting from the terminal condition $v^N = 0$, the value at time $n$ is found by evolving the PDE and then applying the stopping constraint.

#### Discrete Operator and Stability
We approximate the continuation value $v^*$ using centered differences $D_S^2$ for the diffusion and upwind differences $D_P$ for the price drift. The evolution equation is:

$$
\frac{v^n - v^*}{\Delta t} + \frac{1}{2}\sigma^2 S^2 D_S^2 v^* + b^n D_P v^n + c^n = 0
$$

To ensure the numerical solution remains unpolluted by boundary errors, the following *CFL Stability Constraint* must be satisfied:

$$
\frac{\Delta t}{\Delta P} < \frac{1}{\max_{S,P} |b^n|}
$$

<font color=red>To be verified</font>

#### Boundary Condition Management
The algorithm proceeds via backward induction to handle the optimal control $\sup_{\gamma}$ and the stopping constraint $\max$:

* **$P$ Boundaries**: If the boundary at $P_{\min}$ or $P_{\max}$ is *upwind*, a condition must be prescribed. If the boundary is *downwind*, the PDE evolves naturally, and the boundary value is determined by the internal dynamics.
* **$S$ Boundaries (Neumann)**: Unlike the upwind drift in the $P$ direction, diffusion in the $S$ direction causes boundary errors to propagate globally and immediately. We prescribe the derivative $v_S$ at $S_0$ and $S_{N_S}$.
    * At the lower boundary $S_0$, we replace $D_S^2 v^*(S_0)$ using the given $v_S^*(S_0)$ data: $\frac{v^*(S_1) - v^*(S_0)}{\Delta S^2} - \frac{v_S^*(S_0)}{\Delta S}$.
    * At the upper boundary $S_{N_S}$, we replace $D_S^2 v^*(S_{N_S})$ with: $\frac{v^*(S_{N_S-1}) - v^*(S_{N_S})}{\Delta S^2} + \frac{v_S^*(S_{N_S})}{\Delta S}$.
    * This formulation results in an $(N_S+1) \times (N_S+1)$ linear system that remains tridiagonal and solvable via a standard tridiagonal solver.

#### Pseudocode

```
FUNCTION Solve_HJB_QVI_Optimized(T, N_t, P_grid, S_grid, sigma, gamma_search):
    """
    Optimized solver using explicit drift to decouple linear systems and 
    Neumann boundary conditions for the S-dimension.
    
    Inputs:
        T, N_t: Time horizon and steps.
        P_grid, S_grid: Discretized state vectors.
        sigma: Volatility of external price S.
        gamma_search: Discrete set of fee tiers.
    """
    dt = T / N_t
    N_P = len(P_grid)
    N_S = len(S_grid)
    v_grid = zeros(N_t + 1, N_P, N_S)
    
    # 1. Terminal Condition
    v_grid[N_t, :, :] = 0 

    # 2. Backward Evolution Loop
    for n = N_t - 1 down to 0:
        # A. Optimal Control & Hamiltonian (Explicit Step)
        # Use the already computed v_grid[n+1] to find optimal gamma, 
        # the drift term b^n, and running reward c^n.
        gamma_star, b_n, c_n = compute_explicit_control(P_grid, S_grid, v_grid[n+1], gamma_search)
        
        # B. Independent Tridiagonal Solves (Decoupled P-direction) 
        # Treat each P_j independently to solve for the S-diffusion.
        FOR each j from 0 to N_P - 1:
            # Solve an (N_S + 1) x (N_S + 1) linear system 
            # Use Neumann BCs at S_0 and S_{N_S} to handle global diffusion errors.
            v_star = solve_tridiagonal_S_Neumann(v_grid[n+1, j, :], b_n[j, :], c_n[j, :], sigma, dt)
            
            # C. Stopping Constraint & Free Interface
            # If the continuation value v_star < 0, stopping is optimal (v = 0).
            v_grid[n, j, :] = max(v_star, 0)

    return v_grid

FUNCTION solve_tridiagonal_S_Neumann(v_next, b_j, c_j, sigma, dt):
    """
    Solves the implicit diffusion step in S for a fixed P_j.
    Incorporates Neumann BCs: v_S is prescribed at S_0 and S_max.
    """
    # 1. Construct the (N_S+1) tridiagonal matrix coefficients.
    # 2. Modify the first and last rows to implement Neumann discretization:
    #    At S_0: Replace D_S^2 with (v[1] - v[0])/dS^2 - v_S_given/dS.
    #    At S_N: Replace D_S^2 with (v[N-1] - v[N])/dS^2 + v_S_given/dS.
    # 3. Solve the system via Thomas Algorithm.
    RETURN v_star
```



## Reference
* Aqsha, A., Bergault, P., & Sánchez-Betancourt, L. (2025). Equilibrium reward for liquidity providers in automated market makers. arXiv. https://doi.org/10.48550/arXiv.2503.22502
* Baggiani, L., Herdegen, M., & Sánchez-Betancourt, L. (2025). Optimal dynamic fees in automated market makers. arXiv. https://doi.org/10.48550/arXiv.2506.02869
* Bergault, P., Bieber, S., & Sánchez-Betancourt, L. (2025). Optimal exit time for liquidity providers in automated market makers. arXiv. https://doi.org/10.48550/arXiv.2509.06510
* 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*.