---
# System prepended metadata

title: Arbitrage_G3M
tags: [AMM, Research]

---

# Optimal Arbitrage in G3Ms


## Introduction
*Automated Market Makers (AMMs)* have emerged as a crucial component of *decentralized finance (DeFi)*, offering novel mechanisms for asset trading. While traditional finance relies on order books, AMMs utilize mathematical formulas to determine prices, leading to unique market dynamics. Understanding arbitrage opportunities within AMMs is essential for analyzing market efficiency and price stability in DeFi. This note investigates the optimal arbitrage behavior between a *Geometric Mean Market Maker (G3M)* and reference markets, a problem that presents interesting challenges for researchers in stochastic control and financial mathematics due to its complex dynamics and the need for sophisticated optimization techniques.

Specifically, this note addresses the following research questions:

1. What is the optimal control strategy for an arbitrageur exploiting price differences between an AMM and a reference market?
2. What are the resulting dynamics of the AMM's price?
3. How does the presence of multiple arbitrageurs affect the market dynamics (i.e., can we model this as an $N$-player or mean-field game)?



## Notations
Throughout this note, the following notations will be used:


### AMM-related variables
* $x_i$: Quantity of the $i$-th asset in the pool. *Represents the inventory of asset i in the AMM.*
* $w_i$: Weight assigned to the $i$-th asset. *Determines the influence of asset i on the pool's invariant.*
* $\ell$: Total liquidity in the pool. *A constant that defines the pool's size.*
* $P_{ij}$: Price of the $i$-th asset with respect to the $j$-th asset as determined by the AMM. *The exchange rate between asset i and j within the AMM.*
* $1-\gamma$: Transaction cost parameter. *The fraction of the trade charged by AMM.*

### Market variables
* $S_i$: Exogenous reference price of the $i$-th asset, typically obtained from an external market. *The price of asset i in a reference market.*



## Geometric Mean Market Makers
We focus on the *Geometric Mean Market Maker (G3M)* for our analysis due to its analytical tractability and common use in DeFi protocols. G3Ms are a generalization of constant product market makers, allowing for flexible asset weighting. Their price dynamics are governed by a simple invariant, making them amenable to mathematical modeling.


### Trading Mechanism
The trading mechanism is defined by maintaining the following invariant:

$$
\prod_{i=1}^n x_i^{w_i} = \ell
$$

where:
* $x_i$ represents the quantity of the $i$-th asset in the pool.
* $w_i$ is the weight assigned to the $i$-th asset.
* $\ell$ is the total liquidity in the pool.

The weights, denoted as $\mathbf{w}=(w_1,\dots,w_n)$, must satisfy the following constraints:

$$
\sum_{i=1}^n w_i = 1, \ 0 < w_i < 1.
$$

This invariant dictates how the quantities of assets in the pool must change when trades occur.

#### Pool Price Dynamics
Trades involving assets $i$ and $j$ change the relative pool price, $P_{ij}$, of asset $j$ with respect to asset $i$ by:

$$
\frac{dP_{ij}}{P_{ij}} = \frac{dx_j}{x_j} - \frac{dx_i}{x_i}
$$

This equation shows how the relative price changes with changes in asset quantities. Specifically:

- If $dx_i > 0$, the relative pool price $P_{ij}$ goes down.
- If $dx_j > 0$, the relative pool price $P_{ij}$ goes up.


### Incorporating Fees
In the presence of transaction costs, the trading mechanism needs to be adjusted. These fees are crucial in understanding the arbitrageur's profit opportunities.

For a feasible trade from asset $i$ to another asset, the trading dynamics can be described by maintaining the following quantity constant:

$$
x_i^{\gamma w_i} \prod_{k \neq i} x_k^{w_k}
$$

Differentiation gives

$$
\gamma w_i \frac{dx_i}{x_i} + w_j \frac{dx_j}{x_j} = 0.
$$

This equation reflects the fact that fees reduce the amount of the output asset received in a trade.

#### Marginal Exchange Rate 
Taking fees into account, the instantaneous rate at which asset $j$ is exchanged for asset $i$, defined as $-\frac{dx_j}{dx_i}$, is given by:

$$
\frac{dx_j}{x_j} = - \gamma \frac{w_i}{w_j} \frac{dx_i}{x_i}.
$$

Evaluating the infinitesimal exchange rate $-\frac{dx_j}{dx_i}$ yields:

$$
-\frac{dx_j}{dx_i} =  \gamma \frac{x_j/w_j}{x_i/w_i} = \gamma P_{ij},
$$

where $P_{ij}$ represents the relative price of asset $i$ in terms of asset $j$. This equation shows that the effective exchange rate is the AMM's price scaled by the transaction cost.

#### Liquidity Dynamics 
With transaction costs, liquidity changes with trading activity as follows:

$$
\frac{d \ell}{\ell} = \sum_{i=1}^n w_i \frac{dx_i}{x_i} = \sum_{i: dx_i > 0} (1 - γ) w_i \frac{dx_i}{x_i}
$$

which indicates that trading increases the pool's liquidity. This is because fees are added to the pool, increasing its total value.



## The Arbitrageur's Problem (w.r.t. a Reference Market)
In this section, we model how a single arbitrageur interacts with an AMM and a reference market. This sets the stage for understanding more complex multi-agent scenarios.


### Scenario
We consider the following scenario:

1. The (external) reference market offers infinite liquidity and incurs no trading cost for assets $1, \dots n$. (*This simplifies the analysis by isolating the AMM's price impact.*)
2. The market operates without the interference of noise traders. (*Focuses on the pure arbitrage dynamics.*)
3. Arbitrageurs maintain continuous surveillance of the market. (*Captures the high-frequency trading nature of arbitrage.*)

#### Model Details
The arbitrageur controls the AMM price by using the following strategy:

* First, borrowing an asset $i$ from the lending protocol (flash loan).
* Then, trading against the AMM from asset $i$ to another asset $j$.
* Next, selling asset $j$ for asset $i$ in the reference market to repay the loan in the lending protocol.
* Finally, making a profit by selling the remaining asset $j$ to the reference market.

#### Remarks
* Initial capital is not necessary for arbitrage due to flash loans and atomic transactions. *This is a key feature of DeFi arbitrage.*
* The arbitrageur doesn't need any inventory of any risky assets and thus is risk-free. *Arbitrage in this setting is theoretically risk-free, abstracting away from gas fees and execution risk.*


### Control
The arbitrageur determines the amount $\Delta_{ik}$ for trading asset $i$ for asset $k$ against the AMM:

\begin{split}
d x_i =& \sum_k d \Delta_{ik} -  \gamma \sum_k \frac{w_i x_i}{w_k x_k} d\Delta_{ki}
\end{split}

**Remark:** It's difficult to write down a simple expression in the jump case. Thus, we restrict ourselves to the singular control (i.e., $d\Delta_{ik} = d(\Delta_{ik})^c$).

The corresponding AMM price dynamics are:

\begin{split}
d \ln P_{ij} 
&= d \ln x_j - d \ln x_i \\
&= \left( \sum_k \frac{d \Delta_{jk}}{x_k} - \sum_k \frac{d \Delta_{ik}}{x_k} \right) - \gamma \left( \sum_k \frac{w_j d \Delta_{kj}}{w_k x_k} - \sum_k \frac{w_id \Delta_{ki}}{w_k x_k} \right)
\end{split}

This equation describes how arbitrage trades influence the AMM's prices.

#### Normalization
By adopting the normalization

$$
d \xi_k = \frac{1}{w_i x_i} d \Delta_{ik}
$$

the dynamics become:

\begin{split}
\frac{d x_i}{x_i} &= w_i \sum_k d \xi_{ik} - \gamma w_i \sum_k d\xi_{ki} \\
\frac{d P_{ij}}{P_{ij}} &= \sum_k \left( w_j d\xi_{jk} - w_i d\xi_{ik} \right) - \gamma \sum_k \left( w_j d\xi_{kj} - w_i d\xi_{ki} \right) \\
\frac{d \ell}{\ell} &= (1-\gamma) \sum_i w_i^2 \sum_k d \xi_{ik}
\end{split}

These normalized equations simplify the analysis and reveal the underlying structure of the system.

#### Objective
The arbitrageur's objective is to maximize the expected profit of their arbitrage strategy $(\xi_{ij})_{i \neq j}$ over a time horizon $T$:

\begin{split}
J_{T,S_{ij},P_{ij}}(\xi_{ij}) 
&= \mathbb{E}\left[ \int_0^T \sum_{(i,j)} (S_{ij} dx_{j} - dx_i) 1_{d\xi_{ij}>0} \right] \\
&= \mathbb{E}\left[ \int_0^T \sum_{(i,j)} (S_{ij} - \gamma P_{ij}) 1_{d\xi_{ij}>0}  dx_j \right]
\end{split}

where $S_{ij}$ follows a SDE system (e.g., geometric Brownian motion). This objective function represents the expected cumulative profit from exploiting price differences $S_{ij} - \gamma P_{ij}$ between the reference market and the AMM.

#### Remark
* One may add extra penalty terms to the objective function to account for factors such as mispricing, control costs, or borrowing fees, reflecting risk aversion or transaction expenses. *This would make the model more realistic.*
* It is also possible to consider the infinite horizon and the ergodic version of the problem, which would analyze the long-term average behavior of the system. *This would provide insights into the steady-state properties of the market.*



## The Arbitrageur's Problem (w.r.t. a LOB)
In this section, we increase the complexity of the model by considering the interaction between an arbitrageur, a G3M, and a *limit order book (LOB)*. This is a more realistic scenario, as LOBs are the dominant mechanism in centralized exchanges. We focus on the two-asset case for simplicity.


### Scenario
The arbitrageur trades against a G3M and a LOB simultaneously without holding any inventory, that is, buys/sells from AMM and sells/buys to LOB at the same time. This reflects the typical arbitrage strategy of exploiting temporary price discrepancies between different venues.

#### Assumptions
* $n = 2$ (one risky asset and one numeraire). 


### Control
The arbitrageur determines the trading speed $v_t = v_t^+ - v_t^-$ for trading the risky asset for numeraire against the AMM following:

\begin{split}
dx_t &= (v_t^+ - v_t^-) dt \\
dy_t &= \frac{w y_t}{(1-w) x_t} (\gamma^{-1} v_t^- - \gamma v_t^+) dt = P_t (\gamma^{-1} v_t^- - \gamma v_t^+) dt \\
dP_t &= \frac{P_t}{x_t} \left\{ \left(1 + \frac{\gamma^{-1} w}{1-w} \right) v^-_t - \left(1 + \frac{\gamma w}{1-w} \right) v^+_t \right\} dt \\
&= \frac{w y_t}{(1-w) x^2_t} \left\{ \left(1 + \frac{\gamma^{-1} w}{1-w} \right) v^-_t - \left(1 + \frac{\gamma w}{1-w} \right) v^+_t \right\} dt
\end{split}

where:
* $x_t$ is the quantity of the risky asset in the AMM.
* $y_t$ is the quantity of the numeraire in the AMM.
* $v_t^+$ is the trading speed for selling the risky asset from the AMM.
* $v_t^-$ is the trading speed for buying the risky asset to the AMM.

and against LOB with a linear temporary price impact:

$$
\tilde{S}_t = S_t + \eta (v_t^+ - v_t^-)
$$

where:
* $\tilde{S}_t$ is the effective price at which the arbitrageur trades with the LOB.
* $S_t$ is the mid-price of the LOB.
* $\eta$ is the temporary price impact coefficient.

**Remark:** Given that G3M price mechanism is geometric in nature, it might be more suitable to consider a log linear temporary price impact model.

#### Objective
The arbitrageur's objective is to maximize the expected profit of their arbitrage strategy $(v^+_t, v^-_t)$ over a time horizon $T$:

\begin{split}
J_{T,S,x,y}(v^+,v^-) 
&= \mathbb{E}\left[ \int_0^T \left\{ (\gamma P_t - \tilde{S}_t) v^+_t + (\tilde{S}_t - \gamma^{-1} P_t) v^-_t \right\} dt \right]
\end{split}

where $S_t$ follows a SDE.

**Remark:** One might also consider the ergodic control for the arbitrageur. *This would explore the long-run profitability of the strategy.*


### Transformation and Approximation of the Objective Function
To simplify the objective function and facilitate analysis, we introduce a change of coordinates and apply approximations. This aims to transform the problem into a more analytically tractable form, potentially suitable for linear-quadratic control techniques.

#### Change of Coordinate
Instead of using $(x, y)$ (the quantities of the risky asset and the numeraire in the AMM), we parametrize the system in terms of $(P, \ell)$ (the AMM price and the total liquidity). This change of coordinates aims to decouple the price dynamics from the asset quantities, offering a different perspective on the system's dynamics and potentially simplifying the control problem. The resulting dynamics become:

\begin{split}
d \ln P_t &= (u^+_t - u^-_t) dt \\
d \ln \ell_t &= (1-\gamma) \left\{ \frac{w(1-w)}{w + \gamma(1-w)} u^+_t + \frac{w(1-w)}{\gamma w + (1-w)} u^-_t \right\} dt \\
d \ln x_t &= \left\{ \frac{1-w}{w + \gamma(1-w)} u^-_t - \frac{\gamma (1-w)}{\gamma w + (1-w)} u^+_t \right\} dt \\
d \ln y_t &= \left\{ \frac{w}{\gamma w + (1-w)} u^+_t - \frac{\gamma w}{w + \gamma(1-w)} u^-_t \right\} dt
\end{split}

where $u^+_t$ and $u^-_t$ are new control variables related to the original trading speeds $v^+_t$ and $v^-_t$ by:

$$
v^+_t = \frac{1-w}{w + \gamma(1-w)} x_t u^-_t, \quad
v^-_t = \frac{\gamma (1-w)}{\gamma w + (1-w)} x_t u^+_t
$$

#### Rewritten Objective Function
Substituting these new coordinates and control variables into the original objective function yields the following expression:

\begin{split}
J_{T,S,P,\ell}(u^+,u^-) 
&= \mathbb{E}\left[ \int_0^T \left\{ (\gamma P_t - \tilde{S}_t) v^+_t + (\tilde{S}_t - \gamma^{-1} P_t) v^-_t \right\} dt \right] \\
&= \mathbb{E}\left[ \int_0^T \left\{ \frac{1-w}{w + \gamma(1-w)} (\gamma P_t - \tilde{S}_t) x_t u^-_t + \frac{\gamma (1-w)}{\gamma w + (1-w)} (\tilde{S}_t - \gamma^{-1} P_t) x_t u^+_t \right\} dt \right] \\
&= \mathbb{E}\left[ \int_0^T w^{1-w} (1-w)^w \ell_t P^w_t \left\{ \frac{1}{w + \gamma(1-w)} \left(\gamma - \frac{\tilde{S}_t}{P_t} \right) u^-_t + \frac{1}{\gamma w + (1-w)} \left(\gamma \frac{\tilde{S}_t}{P_t} - 1\right) u^+_t \right\} dt \right]
\end{split}

The final expression of the objective function reveals how the arbitrageur's (absolute) profit depends on the AMM's liquidity, price, and the price difference between the AMM and the LOB.

#### Approximations for Simplified Analysis
To derive a more analytically tractable problem, particularly one that might lend itself to linear-quadratic (LQ) control techniques, we apply the following first-order approximations.

* Assuming that the price difference between the LOB and the AMM is small (i.e., $S_t \approx P_t$), we have the following first-order approximations: $$\gamma - \frac{S_t}{P_t} \approx \ln \gamma - Z_t, \quad \frac{S_t}{P_t} - \gamma^{-1} \approx \ln \gamma + Z_t$$ where $Z_t = \ln S_t - \ln P_t$. 
* Furthermore, given the multiplicative nature of the G3M price mechanism, we replace the linear temporary price impact model with a multiplicative one: $$\tilde{S}_t = S_t + \eta P_t (u_t^- - u_t^+)$$ This alternative price impact formulation suggests that the price impact on the LOB is proportional to the AMM price, which may be more suitable than a linear model.
* Note that the term $w^{1-w} (1-w)^w \ell P^w$ is exactly the LP wealth in terms of AMM price. We may change the objective from absolute PnL to relative PnL w.r.t. pool wealth (in percentage) by getting rid of this wealth term.

These approximations and the modified price impact model may lead to a more analytically tractable LQ control problem:

\begin{split}
\tilde{J}_{T,Z}(u^+,u^-) 
&= \mathbb{E}\left[ \int_0^T \left\{ \frac{1}{w + \gamma(1-w)} \left(\ln \gamma - Z_t - \eta u^-_t \right) u^-_t + \frac{1}{\gamma w + (1-w)} \left(\ln \gamma + Z_t - \eta u^+_t\right) u^+_t \right\} dt \right]
\end{split}

**Remark:** To ensure that the AMM price $P_t$ remains closely aligned with the LOB price $S_t$ (i.e., to penalize large mispricing), a quadratic penalty term, such as $\tau Z_t^2$, can be added to the objective function. This term would incentivize the arbitrageur to keep the mispricing $Z_t$ small, reflecting a more stable and efficient market.


### HJB for G3M Arbitrage
To solve the arbitrageur's optimal control problem, we utilize the Hamilton-Jacobi-Bellman (HJB) equation approach. This method provides a framework for finding the optimal control strategies by analyzing the value function of the problem.

For simplicity, we introduce the following substitutions:
* $k = \ln\gamma < 0$
* $c_1 = \frac{1}{w + \gamma(1-w)}$
* $c_2 = \frac{1}{\gamma w + (1-w)}$

Note that $c_1 = c_2 = \frac2{1+\gamma}$ when $w = \frac12$.

#### State Variable
We assume that the external reference price $S_t$ follows a GBM, modeled by the following SDE:

$$
d\ln S_t = \mu dt + \sigma dW_t. 
$$

Consequently, the mispricing process $Z_t = \ln S_t - d\ln P_t$ evolves according to:

$$
dZ_t = d\ln S_t - d\ln P_t = (\mu - u_t^+ + u_t^- )dt + \sigma dW_t
$$

#### Value Function
The arbitrageur's objective is to maximize their expected cumulative profit. We define the value function $V(t,z)$ as the maximum expected future profit from time $t$ to $T$, given the current mispricing $Z_t = z$:

$$
V(t, z) = \sup_{u^+, u^- \geq 0, \ u^+u^-=0} \mathbb{E}\left[\left.\int_t^T \left\{ c_1 \left(k - Z_s - \eta u^-_s \right) u^-_s + c_2 \left(k + Z_s - \eta u^+_s\right) u^+_s \right\} ds\right|Z_t = z \right]
$$

<font color=red>Comment: The constraint $u^+u^-=0$ is expected to emerge naturally from the analysis of the HJB equation, rather than being imposed a priori.</font>

#### HJB Equation
The value function $V$ satisfies the HJB equation

\begin{split}
0 &= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_x + \max_{u^+, u^- \geq 0}\left\{(u^- - u^+)V_z + c_1 \left(k - z - \eta u^- \right) u^- + c_2 \left(k + z - \eta u^+\right) u^+  \right\} \\
&= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_x + \max_{u^+, u^- \geq 0}\left\{-c_1\eta (u^-)^2 + \left[V_z + c_1(k-z)\right] u^- - c_2\eta (u^+)^2 + \left(-V_z + c_2\left[k + z\right] \right) u^+  \right\}
\end{split}

#### Optimal Controls
By maximizing the terms within the HJB equation with respect to $u^-$ and $u^+$ independently, we derive the expressions for the optimal controls $u^{-*}$ and $u^{+*}$:

$$
u^{-*} = \frac{\max\{V_z + c_1\left(k-z\right), 0\}}{2c_1\eta}
$$

and

$$
u^{+*} = \frac{\max\{-V_z + c_2\left(k+z\right), 0\}}{2c_2\eta}
$$

We will use the notation $x_+$ to denote $\max\{x, 0\}$. 

#### No Trade Zone and Free Boundaries
The "no trade zone" occurs when both optimal controls are zero, i.e., $u^{-*} = u^{+*} = 0$. This condition translates to: 

$$
V_z + c_1(k-z) < 0 \quad \mbox{and} \quad -V_z + c_2 (k+z) < 0
$$

or, equivalently,

$$
c_2 (z+k) < V_z < c_1(z-k).
$$

In this region, the HJB equation simplifies to: 

$$
V_t + \frac{\sigma^2}2 V_{zz} + \mu V_z =  0
$$

with the terminal condition $V(T,z) = 0$. The boundaries of this no-trade zone are known as free boundaries, determined by the conditions $V_z = c_2 (z+k)$ and $V_z = c_1(z-k)$.

##### Special case: $c_1 = c_2$
When $c_1 = c_2$, the condition for the no trade zone simplifies to:

$$
c(z+k) < V_z - z < c(z-k), \quad \text{where } c=c_1=c_2.
$$

We can show that $c_1 = c_2$ if and only if
* $w = \frac12$ ($c = \frac2{1 + \gamma}$)
* $\gamma = 1$ ($c = 1$)

Furthermore, in the case where $c_1 = c_2$, if $u^{-*} > 0$, then $u^{+*} = 0$ and vice versa. This indicates that simultaneous buying and selling against the AMM does not occur optimally under these conditions.

Specifically, if $u^{-*} > 0$, then $V_z > c_1 (z-k)$. Since $c_1 = c_2$, it follows that

$$
-V_z + c_2(k + z) < c_1(k-z) + c_2(k+z) = 2ck
$$

As $k = \ln \gamma \leq 0$ (since $\gamma \leq 1$), we have $2ck \leq 0$. Therefore, $-V_z + c_2(k + z) < 0$, which implies $u^{+*} = 0$. 

<font color=red>To do: Demonstrate that the optimal arbitrageur's control strategies $(u^{+*}_t, u^{-*}_t)$ satisfy the non-simultaneous trading condition, i.e., $u^{+*}_t \cdot u^{-*}_t = 0$ in general case where $c_1 \neq c_2$. 
</font>

#### Simplified HJB Equation - General Case
Substituting the optimal controls back into the HJB equation, the maximization terms simplify as follows:

\begin{split}
& \max_{u^-\geq 0}\left\{-c_1\eta (u^-)^2 + \left[V_z + c_1(k-z)\right] u^- \right\} \\
=& \ \frac1{4c_1\eta} \left( \max\{V_z + c_1\left(k-z\right), 0\} \right)^2 
\end{split}

and

\begin{split}
& \max_{u^+\geq 0}\left\{- c_2\eta (u^+)^2 + \left(-V_z + c_2\left[k + z\right] \right) u^+  \right\} \\
=& \ \frac1{4c_2\eta}\left(\max\{-V_z + c_2\left(k+z\right), 0\} \right)^2 
\end{split}

The HJB equation can thus be rewritten as

\begin{split}
0 &= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_x + \max_{u^+, u^- \geq 0}\left\{-c_1\eta (u^-)^2 + \left[V_z + c_1(k-z)\right] u^- - c_2\eta (u^+)^2 + \left(-V_z + c_2\left[k + z\right] \right) u^+  \right\} \\
&= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_x + \frac1{4\eta} \left(\frac1{c_1}\left\{ (V_z + c_1\left[k-z\right])^+ \right\}^2 + \frac1{c_2}\left\{ (-V_z + c_2\left[k+z\right])^+ \right\}^2 \right)
\end{split}

#### Case No Transaction Fee ($\gamma = 1$)
In the absence of transaction fees, $\gamma = 1$, which implies $k=0$, and $c_1 = c_2 = 1$. The HJB equation simplifies to LQ problem:

$$
\begin{split}
0 &= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_x + \max_{u^+, u^- \geq 0}\left\{-c_1\eta (u^-)^2 + \left[V_z + c_1(k-z)\right] u^- - c_2\eta (u^+)^2 + \left(-V_z + c_2\left[k + z\right] \right) u^+  \right\} \\
&= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_x + \max_{u^+, u^- \geq 0}\left\{-\eta (u^-)^2 + (V_z - z) u^- - \eta (u^+)^2 + \left(-V_z + z \right) u^+  \right\} \\
&= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_x + \max_{u \in \mathbb{R}} \left\{-\eta u^2 + \left(-V_z + z \right) u \right\}
\end{split}
$$

where $u = u^+ - u^-$.

The optimal control $u^*$ is given by 

$$
u^* = \frac{-V_z + z}{2\eta}
$$

As the price impact coefficient $\eta \to 0^+$ the optimal control $u^∗$ tends to:

$$
u^* \to
\left\{\begin{array}{ll}
+\infty & \mbox{ if } -V_z + z > 0 \\
0 & \mbox{ if } V_z = z \\
-\infty & \mbox{ if } -V_z + z < 0
\end{array}\right.
$$

The HJB equation for this case reduces to

$$
V_t + \frac{\sigma^2}2 V_{zz} + \mu V_z + \frac1{4\eta}\left(z - V_z\right)^2 = 0
$$

with terminal condition $V(T,z) = 0$.

<font color=red>To do: Verify if a quadratic ansatz $V(t,z) = \frac12 h_2(t) z^2 + h_1(t) z + h_0(t)$ provides a solution for this specific case, potentially referencing our previous work.</font>

#### Case $w = \frac12$ (CPMM)
When $w = \frac12$, the AMM becomes a Constant Product Market Maker (CPMM), and we have $c = c_1 = c_2 = \frac2{1 + \gamma}$. The HJB equation takes the form:

\begin{split}
0 &= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_x + \max_{u^+, u^- \geq 0\\}\left\{-c_1\eta (u^-)^2 + \left[V_z + c_1(k-z)\right] u^- - c_2\eta (u^+)^2 + \left(-V_z + c_2\left[k + z\right] \right) u^+  \right\} \\
&= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_x + \max_{u^+, u^- \geq 0}\left\{-c\eta (u^-)^2 + V_z u^- - c(z-k) u^- - c\eta (u^+)^2 - V_z u^+ + c(k+z) u^+  \right\} \\
&= V_t + \frac{\sigma^2}2 V_{zz} + \mu V_z + \Phi(z, V_z),
\end{split}

where $\Phi(z,V_z)$ captures the optimal control contribution:

$$
\Phi(z,V_z) := 
\left\{\begin{array}{ll}
\frac1{4c\eta}\left\{V_z - c(z+k)\right\}^2 & \mbox{ if } \frac{V_z}c < z+k \\
0 & \mbox{ if } z+k \leq \frac{V_z}c \leq z-k \\
\frac1{4c\eta}\left\{V_z - c(z-k)\right\}^2 & \mbox{ if } \frac{V_z}c > z-k
\end{array}\right.
$$

##### Infinite Horizon or Laplace Transform Time
Considering the problem in an infinite horizon or applying a Laplace transform to the time variable, the HJB equation reduces to an ODE:

$$
\beta V + \frac{\sigma^2}2 V'' + \mu V' + \Phi(z, V') = 0
$$

where $\beta$ is the discount factor or the Laplace transform variable.

This approach transforms the problem into determining the boundaries $z_l \leq z_r$ and the solution $V$ across different regions:

* **No-Trade Zone ($z \in [z_l, z_r]$):** In this region, $V=0$ with $u^{*+}=u^{*-}=0$.
* **Arbitrage Buying Zone ($z \geq z_r$):** In this region, $V$ satisfies ODE: $$\beta V + \frac{\sigma^2}2 V'' + \mu V' + \frac1{4c\eta}\left\{V' - c(z - k)\right\}^2 = 0$$ with boundary conditions $V(z_r) =0$ and (the smooth pasting) $V'(z_r) = c(z_r - k)$. The optimal controls are given by $$u^{+*} = 0, \quad u^{*-} = \frac1{2c\eta}\left\{ V' - c(z-k)\right\}.$$
* **Arbitrage Selling Zone ($z \leq z_l$):** In this region, $V$ satisfies ODE: $$\beta V + \frac{\sigma^2}2 V'' + \mu V' + \frac1{4c\eta}\left\{V' - c(z + k)\right\}^2 = 0$$ with boundary conditions $V(z_l) =0$ and (the smooth pasting) $V'(z_l) = -c(z_l + k)$. The optimal controls are given by $$u^{*+} = \frac1{2c\eta}\left\{ -V' + c(z+k)\right\}, \quad u^{-*} = 0.$$

<font color=red> There are some errors in this part. To correct these errors, one needs to simultaneously solve for the value function $V(z)$ and the free boundaries $z_l$ and $z_r$. The solution involves matching conditions across the different regions:
* **No-Trade Zone ($z \in [z_l, z_r]$):** In this region, no arbitrage occurs, and the value function $V(z)$ satisfies the linear ODE: $$\beta V + \frac{\sigma^2}2 V_1'' + \mu V_1' = 0$$ Let $V_1(z)$ denote the solution in this zone.
* **Arbitrage Buying Zone ($z \geq z_r$):** In this region, arbitrageurs are actively buying the risky asset from the AMM. The value function $V(z)$ satisfies the same ODE above. At the free boundary $z_r$, the following conditions must hold to ensure a smooth transition:
    * $V(z_r)=V_1(z_r)$
    * $V'(z_r) = c(z_r - k)$
* **Arbitrage Selling Zone ($z \leq z_l$):** In this region, arbitrageurs are actively selling the risky asset to the AMM. The value function $V(z)$ satisfies the same ODE above. At the free boundary $z_l$, the following conditions must hold:
    * $V(z_l)=V_1(z_l)$
    * $V'(z_l) = -c(z_l + k)$
</font>

<font color=red>Comment: It is generally more reasonable and tractable to consider the infinite horizon or ergodic version of the problem, given that arbitrage bots operate continuously. For the infinite horizon case, the primary objective is to determine 
* long-run optimal strategies
* the steady-state mispricing 
* grwoth rate of LP wealth
</font>



## Extention to Stackelberg Game
One may extend the previous arbitrageur's problem to a Stackelberg game framework, providing a more comprehensive model of the strategic interaction between the AMM and arbitrageurs. In this hierarchical game, the AMM acts as the leader, making decisions that influence the arbitrageur's optimal strategy, who in turn acts as the follower. This setup is particularly relevant for understanding how AMM design choices, such as fee structures, impact market dynamics and overall liquidity provision.

### Game Structure
In this Stackelberg game formulation:

* **The Leader (AMM):** The AMM, representing the liquidity providers, determines its optimal fee tier, $\gamma_tc$, as its control variable. This decision is made with the foresight of how arbitrageurs will react.
* **The Follower (Arbitrageur):** The arbitrageur, as modeled in the preceding sections, observes the AMM's chosen fee tier and then optimizes their trading strategy $(u^+_t, u^-_t)$ to maximize their expected profit, taking the AMM's fee into account.

### AMM's Objective
The AMM's objective is to maximize the long-term profitability and growth of the liquidity pool. Specifically, the AMM aims to maximize the expected logarithm of the LP wealth over a time horizon $T$:

$$
V_{T,P,\ell}(\gamma) 
= \mathbb{E} \left[ \ln W_T \right]
= \mathbb{E} \left[ \ln \ell_T + w \ln P_T \right]
$$

where $W_T = \ell_T P^w_T$ represents the total wealth of the liquidity providers at time $T$. 

Maximizing the logarithm of wealth is a common objective in financial mathematics, often related to maximizing geometric returns or long-term growth rates, reflecting a preference for compounded returns over absolute returns. The AMM's optimal fee strategy $\gamma_t$ will be determined by anticipating the arbitrageur's optimal response to different fee levels.


### To Do
* Determine the closed-form solution for the optimal arbitrageur's control strategies, denoted as $u(\gamma) = (\bar{u}^+_t, \bar{u}^-_t)$, representing their best response to a given fee tier $\gamma_t$ set by the AMM.
* Analyze the optimal fee tier $\bar{\gamma}_t$ set by the AMM, taking into account the arbitrageur's optimal response. Subsequently, analyze the associated mispricing process $\bar{Z}_t$ that arises under this optimal Stackelberg equilibrium.
* Investigate the infinite time horizon and ergodic version of this Stackelberg game to understand the long-run optimal strategies for both the AMM and the arbitrageurs, and the steady-state behavior of the market.
* Extend the model to include fixed transaction costs (e.g., gas fees) in addition to the proportional transaction costs and price impact. This would likely transform the singular control problem into an impulse control problem, requiring a different solution approach.



## References
* Almgren, R., & Chriss, N. (2001). Optimal execution of portfolio transactions. *Journal of Risk*, *3*(2), 5–39. https://doi.org/10.21314/JOR.2001.041
* Donnelly, R. (2022). Optimal Execution: A Review. *Applied Mathematical Finance*, *29*(3), 181–212. https://doi.org/10.1080/1350486X.2022.2161588
* Evans, A. (2021). Liquidity Provider Returns in Geometric Mean Markets. *Cryptoeconomic Systems, 1(2)*. https://doi.org/10.21428/58320208.56ddae1b
* 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
* Heemels, W. P. M. H., Van Eijndhoven, S. J. L., & Stoorvogel, A. A. (1998). Linear quadratic regulator problem with positive controls. *International Journal of Control*, 70(4), 551–578. https://doi.org/10.1080/002071798222208
* Lee, C. Y., Tung, S. N., & Wang, T. H. (2024). Growth rate of liquidity provider's wealth in G3Ms. *arXiv preprint arXiv:2403.18177*.
* Mei, H., Wei, Q., & Yong, J. (2021). Optimal Ergodic Control of Linear Stochastic Differential Equations with Quadratic Cost Functionals Having Indefinite Weights. *SIAM Journal on Control and Optimization*, *59*(1), 584–613. https://doi.org/10.1137/20M1334206
* Muhle-Karbe, J., Reppen, M., & Soner, H. M. (2017). A Primer on Portfolio Choice with Small Transaction Costs. *Annual Review of Financial Economics*, *9*, 301–331. https://doi.org/10.1146/annurev-financial-110716-032445
* Tung, S. N., & Wang, T. H. (2024). A mathematical framework for modelling CLMM dynamics in continuous time. *arXiv preprint arXiv:2412.18580*.

