# Dynamics of Liquidity Profile in AMM: An SPIDE Approach
## Introduction and Motivation
*Automated Market Makers (AMMs)* have revolutionized decentralized finance by enabling permissionless and continuous trading of digital assets. Among them, Uniswap V3 introduces the concept of concentrated liquidity, allowing *liquidity providers (LPs)* to allocate capital within specific price ranges. This feature significantly enhances capital efficiency but also introduces a complex, dynamic liquidity profile that is challenging to model and predict. Understanding the evolution of this liquidity profile is crucial for LPs seeking to optimize returns, for developers aiming to improve AMM design, and for researchers exploring the stability and efficiency of decentralized exchanges.
Traditional stochastic process are often designed for finite-dimensional systems. However, the liquidity profile in AMMs represents a continuous function over a price range, necessitating an infinite-dimensional approach. Existing models typically simplify the liquidity dynamics or focus on specific aspects like price processes, often overlooking the detailed evolution of the liquidity distribution itself.
This proposal introduces a robust mathematical framework for modeling AMM liquidity using a **stochastic partial integro-differential equation (SPIDE)**. This framework is particularly well-suited to capture the nonlocal interactions and continuous nature of liquidity. By leveraging orthonormal eigenfunction expansions, we demonstrate how this infinite-dimensional SPIDE can be systematically transformed into a more tractable, albeit infinite-dimensional, system of linear stochastic differential equations (SDEs). This transformation is key, as it opens avenues for efficient parameter estimation and data analysis using established techniques adapted for infinite-dimensional systems.
The subsequent sections of this proposal will:
* Detail the general $M$-factor SPIDE setup and its components.
* Present the eigenfunction expansion technique used to transform the SPIDE into a system of SDEs.
* Derive the evolution equations for the eigenmodes and their associated moments (mean and covariance).
* Illustrate the application of this SPIDE framework to model liquidity within a Uniswap V3-like AMM.
* Outline a comprehensive framework for model estimation, goodness-of-fit evaluation, and statistical comparison with simpler models.
## $M$-factor SPIDE
### SPIDE Setup
We assume that the evolution of a random function $u_t(x)$, representing a transformed liquidity profile, is governed by an $M$-factor stochastic partial integro-differential equation (SPIDE) defined on the finite interval $[-L, L]$.
For $x \in [-L, L]$ and with $\mathbb{W}_t = (W^1_t, \dots, W^M_t)'$ denoting an $M$-dimensional Brownian motion, the SPIDE is given by
$$
du_t(x) = \{\mathcal{L} u_t - V_t[u_t] + h(t, x) \}dt + \sum_{m=1}^M \sigma_m(t, x)[u_t] dW^m_t
$$
with an initial condition $u_0(x)$. Here, $\mathcal{L}$ is a second-order differential operator, and $V_t$ and $\sigma_m(t,x)$ are bounded linear operators defined by the following kernels:
\begin{split}
V_t[u] &:= \int V_t(x,y) u(y) w(y) dy \\
\sigma_m(t,x)[u] &:= \int\sigma_m(t,x,y) u(y) w(y) dy
\end{split}
**Remark:**
* The introduction of these linear integral operators, in addition to the differential operator $\mathcal{L}$, allows the coefficients of the SPIDE to potentially depend on the entire liquidity profile (via its eigenmodes) or even be stochastic.
* These integral operators $V_t$ and $\sigma_m(t,x)$ induce nonlocal dynamics, meaning the evolution of $u_t(x)$ at a given point $x$ depends on the values of $u_t(y)$ across the entire domain $[-L, L]$.
#### Special Case: $M$-factor SPDE of GBM Type
If the linear operators $V_t$ and $\sigma_m$ degenerate to delta functions, specifically:
$$
V_t(x,y) = V_t \delta(y-x), \quad \sigma_m(t) \delta(y-x),
$$
where $V_t(x)$ and $\sigma_m(t,x)$ are functions of $t$ and $x$ only, then the evolution of $u_t(x)$ simplifies to an SPDE of the GBM type:
$$
du_t(x) = \{\mathcal{L} u_t(x) - V_tu_t(x) + h(t, x) \}dt + \sum_{m=1}^M \sigma_m(t)u_t(x) dW^m_t.
$$
#### Special Case: $M$-factor SPDE of OU Type
Similarly, if the linear operator $V_t$ degenerates to a delta function, and $\sigma_m$ degenerates to functions of $t$ and $x$ only:
$$
V_t(x,y) = V_t \delta(y-x),
$$
where $V_t(x)$ is a function of $t$ and $x$, and the $\sigma_m(t,x)$'s are functions of $t$ and $x$ only, then the evolution of $u_t(x)$ reduces to an SPDE of the OU type:
$$
du_t(x) = \{\mathcal{L} u_t - V_tu_t + h(t, x) \}dt + \sum_{m=1}^M \sigma_m(t, x) dW^m_t.
$$
### Eigenfunction Expansion
To analyze the infinite-dimensional SPIDE, we utilize an eigenfunction expansion. Assume that the differential operator $\mathcal{L}$ is equipped with an orthonormal eigensystem $\{\lambda_n, e_n(x)\}_{n=0}^\infty$ with respect to a measure $w(x)dx$ within the finite interval $[-L, L]$. This implies that for $n = 0, 1, \dots$,
$$
\mathcal{L} e_n(x) = -\lambda_n e_n(x).
$$
and the orthonormality condition holds:
$$
\int_{-L}^L e_i(x) e_j(x) w(x)dx = \delta_{ij}
$$
Under suitable boundary conditions, Sturm-Liouville theory guarantees the existence of such an eigensystem, where the eigenfunctions often behave similarly to trigonometric functions.
We consider the eigenfunction expansion of $u_t(x)$, the solution to the SPIDE, given by
$$
u_t(x) = \sum u_t^n e_n(x).
$$
where the Fourier coefficients $u_t^n$ are obtained as
$$
u_t^n = \int_{-L}^L u_t(x) e_n(x) w(x) dx
$$
Similarly, the eigenfunction expansion for $h(t, x)$ is
$$
h(t, x) = \sum h^n(t)e_n(x)
$$
Moreover, the kernels $V_t(x,y)$ and $\sigma_m(t,x,y)$ can also be expressed in terms of the eigenfunctions:
\begin{split}
V_t(x,y) &= \sum_{i,j} V^{ij}_t e_i(x) e_j(y)\\
\sigma_m(t,x,y) &= \sum_{i,j} \sigma_m^{ij}(t) e_i(x) e_j(y)
\end{split}
where their respective coefficients are given by
\begin{split}
V^{ij}_t &= \iint V_t(x,y) e_i(x) e_j(y) dxdy \\
\sigma_m^{ij}(t) &= \iint \sigma_m(t,x,y) e_i(x) e_j(y) dxdy
\end{split}
We assume that $V_t^{ij}, \sigma_m^{ij}(t) \in \ell^2$ for all $t$.
### Evolution of Eigenmodes
By substituting the eigenfunction expansions into the SPIDE and leveraging the orthonormality, it follows that the Fourier coefficients $u_t^n$ satisfy the following *coupled* system of linear SDEs in infinite dimensions:
\begin{split}
du_t^n &= \left\{-\lambda_n u^n_t - \sum_k V_t^{nk} u_t^k + h_t^n \right\} dt + \sum_{m,k} \sigma_m^{nk}(t) u^k_t dW_t^m \\
&= \left\{-\sum_k\left(\lambda_k \delta_{nk} + V_t^{nk} \right) u_t^k + h_t^n \right\} dt + \sum_{m,k} \sigma_m^{nk}(t) u^k_t dW_t^m
\end{split}
for $n = 0, 1, \dots$.
#### SPDE of GBM Type
In the case where the kernels degenerate to yield an SPDE of GBM type (as defined above), the Fourier coefficients $u_t^n$ satisfy the following *decoupled* system of linear SDEs in infinite dimensions:
\begin{split}
du_t^n = \left\{-(\lambda_n+ V_t) u_t^n + h_t^n \right\} dt + \sum_{m} \sigma_m(t) u_t^n dW_t^m
\end{split}
for $n = 0, 1, \dots$. (Note: $V_t(x_n)$ and $\sigma_m(t,x_n)$ here imply a projection or evaluation of the original spatially-dependent coefficients onto the $n$-th mode.)
#### SPDE of OU Type
For the SPDE of OU type (as defined above), the Fourier coefficients $u_t^n$ satisfy the following *decoupled* system of linear SDEs in infinite dimensions:
\begin{split}
du_t^n &=& \left\{-(\lambda_n+ V_t) u_t^n + h_t^n \right\} dt + \sum_{m} \sigma_m^n(t) dW_t^m
\end{split}
for $n = 0, 1, \dots$.
### Matrix Notation
For a more compact representation, we introduce vector and matrix notation. Let $\mathbf{u}_t = (u_t^0, u_t^1, \dots)'$, $\mathbf{h}_t = (h^0(t), h^1(t), \dots)'$, $\mathbf{\Lambda} = \text{diag}(\lambda_0, \dots, \lambda_n, \dots)$, $\mathbf{V}_t = (V_t^{ij})$, and $\mathbf{\Sigma}_m(t) = (\sigma_m^{ij}(t))$.
The $M$-factor controlled linear SPIDE can then be concisely expressed as an infinite-dimensional version of a linear SDE:
$$
d\mathbf{u}_t = \left\{-\left(\mathbf{\Lambda} + \mathbf{V}_t \right) \mathbf{u}_t + \mathbf{h}_t \right\} dt + \sum_{m=1}^M \mathbf{\Sigma}_m(t) \mathbf{u}_t dW^m_t.
$$
#### SPDE of GBM Type (Matrix Notation)
In this specialized case, we have $\mathbf{V}_t = V_t \mathbf{I}$ (where $V_t$ is a scalar function of $t$) and $\mathbf{\Sigma}_m(t) = \text{diag}(\sigma_m^0(t), \dots, \sigma_m^n(t), \dots)$.
The $M$-factor linear SPDE then takes the form:
$$
d\mathbf{u}_t = \left\{-\left(\mathbf{\Lambda} + \mathbf{V}_t \right) \mathbf{u}_t + \mathbf{h}_t \right\} dt + \sum_m \mathbf{\Sigma}_m(t) \mathbf{u}_t dW^m_t.
$$
Crucially, in this case, the matrices $\mathbf{\Lambda}$, $\mathbf{V}_t$, and $\mathbf{\Sigma}_m(t)$ are all diagonal.
#### SPDE of OU Type (Matrix Notation)
For the OU type SPDE, we have $\mathbf{V}_t = V_t \mathbf{I}$ (where $V_t$ is a scalar function of $t$) and $\mathbf{\Sigma}_m(t)$ is a vector $\mathbf{\sigma}_m(t) = (\sigma_m^0(t), \dots, \sigma_m^n(t), \dots)'$.
The $M$-factor linear SPDE becomes
$$
d\mathbf{u}_t = \left\{-\left(\mathbf{\Lambda} + \mathbf{V}_t \right) \mathbf{u}_t + \mathbf{h}_t \right\} dt + \sum_m \mathbf{\Sigma}_m(t) dW^m_t.
$$
Here, both $\mathbf{\Lambda}$ and $\mathbf{V}_t$ are diagonal matrices.
#### Connection to VAR Models
By truncating this infinite-dimensional system of SDEs to a finite number of dimensions, say $N$ dimensions, and subsequently discretizing time, we can derive a Vector Autoregression (VAR) model. This connection facilitates empirical analysis and estimation using time series techniques.
### Diagonalizable Case
A particularly tractable scenario arises when all kernels are diagonalizable, i.e., $V_t^{ij} = V_t^i \delta_{ij}$ and $\sigma_m^{ij}(t) = \sigma_m^i(t)\delta_{ij}$. In this situation, the infinite-dimensional system of SDEs *decouples*. Specifically, each eigenmode $u_t^n$ satisfies an independent SDE:
$$
du_t^n = \left\{-\lambda_n u^n_t - V_t^{n} u_t^n + h_t^n \right\} dt + \sum_{m} \sigma_m^{n}(t) u^n_t dW_t^m.
$$
In matrix notation, this implies that the matrices $\mathbf{V}_t$ and $\mathbf{\Sigma}_m(t)$ are all diagonal. While simplified, this case still falls under the SPIDE framework and offers more tunable parameters than the pure SPDE cases due to mode-specific coefficients.
### Expected Shape
Let $\bar u_t(x) = \mathbb{E}\left[ u_t(x) \right]$. Under the assumption of sufficient regularity and integrability, $\bar u(t,x)$ satisfies the partial integro-differential equation (PIDE):
$$
\bar u_t = \mathcal{L} \bar u - V_t[\bar u_t] + h(t,x)
$$
with initial condition $\bar u(0,x) = u_0(x)$. The expected profile $\bar u(t,x)$ can also be expanded in terms of eigenfunctions:
$$
\bar u(t,x) = \sum \bar u^n_t e_n(x),
$$
where the expected Fourier coefficients $\bar u^n_t$ satisfy the coupled system of linear ODEs
$$
\frac{d\bar u_t^n}{dt} = \left\{-\sum_{k=0}^\infty\left(\lambda_k \delta_{nk} + V_t^{nk} \right) \bar u_t^k + h^n(t) \right\}.
$$
In matrix notation, this system is
$$
\frac{d\bar{\mathbf{u}}_t}{dt} = -\left(\mathbf{\Lambda} + \mathbf{V}_t \right) \bar{\mathbf{u}}_t + \mathbf{h}_t,
$$
where $\bar{\mathbf{u}}_t = (\bar u_t^0, \dots, \bar u_t^n, \dots)'$.
### Covariance Function
Let $\gamma_t(x,y)$ be the covariance function of $u_t$, defined as
$$
\gamma_t(x,y) = {\rm cov}\left[ u_t(x), u_t(y) \right] = \mathbb{E}\left[ u_t(x)u_t(y) \right] - \bar u_t(x)\bar u_t(y)
$$
To calculate this, we first consider the uncentered second moment $\mathbb{E}\left[ u_t(x)u_t(y) \right]$ in terms of eigenfunctions:
$$
d\left\{ u_t(x) u_t(y) \right\} = \sum_{k,\ell} d\{u_t^k u_t^\ell \} e_k(x) e_\ell(y)
$$
Applying Itô's Lemma to the product $u_t^k u_t^\ell$:
\begin{split}
d\{u_t^k u_t^\ell \}
=& \ u_t^k du_t^\ell + u_t^\ell d u_t^k + d[u^k, u^\ell]_t\\
=& \ u_t^k \left(\left\{-\lambda_\ell u^\ell_t - \sum_i V_t^{\ell i} u_t^i + h^\ell(t) \right\} dt + \sum_{m,i} \sigma_m^{\ell i}(t) u_t^i dW_t^m \right) \\
&+ u_t^\ell \left(\left\{-\lambda_k u^k_t - \sum_i V_t^{ki} u_t^i + h^k(t) \right\} dt + \sum_{m,i} \sigma_m^{ki}(t) u_t^i dW_t^m \right) \\
&+ \sum_{i,j,m} \sigma_m^{ki} \sigma_m^{\ell j} u_t^i u_t^j dt
\end{split}
Taking expectations, let $\gamma_t^{k\ell} = \mathbb{E}\left[ u_t^k u_t^\ell \right]$. It follows that $\gamma_t^{k\ell}$ satisfies the linear matrix-valued ODE:
$$
\dot\gamma_t^{k\ell} = -(\lambda_k + \lambda_\ell) \gamma_t^{k\ell} - \sum_i V_t^{\ell i} \gamma_t^{ki} - \sum_i V_t^{k i} \gamma_t^{\ell i} + h^\ell_t \bar u_t^k + h^k_t \bar u^\ell_t + \sum_{i,j,m} \sigma^{ki}_m \sigma_m^{\ell j} \gamma_t^{ij}
$$
Thus, the covariance function $\gamma_t(x,y)$ can be expressed as
$$
\gamma_t(x,y) = \sum_{k,\ell} \left\{\gamma_t^{k\ell} - \bar u_t^k \bar u^\ell_t \right\} e_k(x) e_\ell(y).
$$
#### Diagonalizable Case with Zero Mean
In the diagonalizable case, and assuming $u_t(x)$ has zero mean ($\bar u_t(x)=0$), the matrix ODE for $\gamma_t^{k\ell}$ significantly simplifies to
$$
\dot\gamma_t^{k\ell} = -\left(\lambda_k + \lambda_\ell + V_t^k + V_t^\ell - \sum_m \sigma^k_m \sigma_m^\ell \right) \gamma_t^{k\ell}
$$
From this, the autocovariance function $\gamma_t(x,y)$ can be obtained explicitly for each mode
$$
\gamma_{t+h}^{k\ell} = \gamma_t^{k\ell} e^{-\int_t^{t+h}\left(\lambda_k + \lambda_\ell + V_s^k + V_s^\ell - \sum_m \sigma^k_m \sigma_m^\ell \right)ds}
$$
#### SPDE of GBM Type
For the SPDE of GBM type, the ODEs for $\gamma^{k\ell}$ further reduce to
$$
\dot\gamma_t^{k\ell} = -\left(\lambda_k + \lambda_\ell + 2 V_t - \sum_m \sigma^2_m \right) \gamma_t^{k\ell}.
$$
If $V_t$ is constant (i.e., independent of $t$), $\gamma_t^{k\ell}$ can be expressed as
$$
\gamma_{t+h}^{k\ell} = \gamma_t^{k\ell} e^{-(\tilde\lambda_k + \tilde\lambda_\ell)h + \int_t^{t+h}\sum_m \sigma^2_m(s)ds}
$$
where $\tilde\lambda_k = \lambda_k + V$.
#### SPDE of OU type
In the case of the SPDE of OU type, the ODEs for $\gamma^{k\ell}$ reduce to
$$
\dot\gamma_t^{k\ell} = -(\lambda_k + \lambda_\ell + 2 V_t)\gamma_t^{k\ell} + \sum_{m} \sigma^{k}_m \sigma^{\ell}_m.
$$
If $V_t$ is constant, $\gamma_t^{k\ell}$ can be expressed as
$$
\gamma_{t+h}^{k\ell} = \gamma_t e^{-(\tilde\lambda_k + \tilde\lambda_\ell)h} + \int_t^{t+h} e^{-(\tilde\lambda_k + \tilde\lambda_\ell)(t+h-s)} \sum_{m} \sigma^{k}_m \sigma^{\ell}_m ds
$$
where $\tilde\lambda_k = \lambda_k + V$.
## Application to Liquidity Modeling in Uniswap V3
This section details how the general SPIDE framework can be applied to model liquidity within a Uniswap V3-like AMM. The motivation for using an SPIDE stems from the continuous and interacting nature of concentrated liquidity. The differential operator $\mathcal{L}$ can capture diffusion-like processes of liquidity (e.g., how liquidity "spreads" or "contracts" over the price range). The integral operators $V_t$ and $\sigma_m$ are crucial for capturing nonlocal effects, such as how liquidity changes in one price range might instantly influence the dynamics in other, distant price ranges, or how global market conditions impact the entire liquidity curve. The stochastic terms account for the inherent randomness in market price movements and LP behavior.
Recall the definitions for the quantity of asset $X$ (risky) and $Y$ (numeraire) in a liquidity pool, based on the continuous liquidity profile $\ell(q)$ at price $q$:
$$
X(p, \ell) = \frac12 \int_p^\infty \frac{\ell(q)}{q^{3/2}} dq, \quad Y(p, \ell) = \frac12 \int_0^p \frac{ \ell(q)}{\sqrt q} dq.
$$
The total value $V$ of the pool at price $p$ is given by
$$
V(p, \ell) = p X(p, \ell) + Y(p, \ell)
$$
As functionals of $u$ (where $\ell(q) = e^{u(x)}$), $X$, $Y$, and consequently $V$ are all linear. It follows that
\begin{split}
V(p, \ell)
&= p X(p, \ell) + Y(p, \ell) \\
&= \frac12 \int_p^\infty \frac{p}{q} \ell(q) \frac{dq}{\sqrt q} + \frac12 \int_0^p \ell(q) \frac{dq}{\sqrt q} \\
&= \frac12 \int_0^\infty \left\{ \frac{p}{q} \mathbf{1}_{[p,\infty)}(q) - \mathbf{1}_{[0,p]}(q) \right\} \ell(q) \frac{dq}{\sqrt q}
\end{split}
### Centering Log Liquidity Profile
We consider the logarithm of the liquidity profile, $\ln \ell(q) = u(x)$, centered at the log pool price $\tilde{p} = \ln p$. The spatial variable $x$ is defined as $x = \ln q - \ln p$.
#### Pool Reserve and Pool Value as Functionals of $u(x)$
By a change of variable from $q$ to $x = \ln q - \ln p$ (so $q = e^{x+\tilde{p}}$ and $dq = e^{x+\tilde{p}} dx$), we can express $X$ and $Y$ as functionals of $u(x)$:
\begin{split}
X(p,\ell)
&= \frac12 \int_p^\infty \frac{\ell(q)}{q^{3/2}} dq \\
&= \frac12 \int_0^\infty e^{u(x)} e^{-\frac12 (x+\tilde{p})} dx =: X(\tilde{p},u).
\end{split}
Likewise, for $Y$:
\begin{split}
Y(p,u) &=& \frac12 \int_{-\infty}^0 e^{u(x)} e^{\frac12(x+\tilde{p})} dx.
\end{split}
It then follows that the total pool value $V(\tilde{p}, u)$ can be expressed as:
\begin{split}
V(\tilde{p}, u)
&:= p X(p,u) + Y(p,u) \\
&= \frac12 e^{\frac{\tilde{p}}{2}} \int_{-\infty}^\infty \left\{ e^{-\frac{x}2} \mathbf{1}_{[0,\infty)}(x) + e^{\frac{x}2} \mathbf{1}_{[-\infty,0]}(x) \right\} e^{u(x)} dx.
\end{split}
<font color=red>To do:
* Estimation procedure
* Goodness-of-fit metrics
* Percentage of covariance recovered
* Statistical significance
* Is there a statistically significant improvment of SPIDE from SPDE (of either GBM or OU type)?
* Is SPDE of GBM significantly different from that of OU?
</font>