# Optimal Fee Control for G3Ms
*Automated Market Makers (AMMs)* are a cornerstone of decentralized finance (DeFi), facilitating trustless asset trading. Among AMM designs, **Balancer** is recognized for its flexible pool configurations. Specifically, the *Geometric Mean Market Maker (G3M)* maintains constant asset weights, effectively operating as a *passive index fund* in which the constant weighted geometric mean of its assets is maintained.
A critical operational element is the *fee* charged per transaction, which compensates liquidity providers (LPs). Balancer's latest iteration, v3, introduces sophisticated mechanisms for **dynamically adjusting these fee tiers**. This capability gives rise to the core optimization problem of this study: determining the optimal fee control policy $\gamma_t$ to maximize the long-term wealth growth for liquidity providers.
This study investigates strategies for dynamically adjusting the fee tier within G3Ms to achieve the maximal long-term growth rate of LP wealth. By analyzing the interplay between trading dynamics and fee adjustments, we aim to provide insights into effective fee management in AMMs.
## Fee Control in G3Ms
This section explores the crucial aspect of optimizing fee tiers within G3Ms.
### Problem Formulation
The primary objective is to determine the optimal fee tier, denoted as $\gamma_t$, that maximizes the long-term wealth growth of liquidity providers. To simplify the analysis, we focus on a two-asset pool ($n=2$) consisting of one risky asset (e.g., ETH) and one numéraire (e.g. USDC). This simplification allows us to gain key insights without sacrificing the generality of the problem.
### Objective
The liquidity provider's fundamental objective is to maximize the long-run growth rate of their actual wealth, $W_T$, by controlling the fee tier, $\gamma_t$. This is expressed as:
$$
\sup_{\gamma_t \in (0,1]} \liminf_{T \to \infty} \frac{\ln W_T}{T}
$$
For analytical tractability, we reformulate the objective based on the underlying Geometric Brownian Motion (GBM) model:
* **LP Wealth Proxy**: We focus on maximizing the long-run growth rate of the LP's liquidity $\ell_T$, assuming the mispricing $Z_t$ is stable with a zero ergodic limit.
* **Mispricing Penalty**: A penalty term, $-\eta Z^2_t$, is imposed. This ensures near-monotonicity of the value function, which is critical for solving the HJB equation, and economically discourages strategies that permit large pricing gaps between the AMM and the external market.
The resulting ergodic optimization problem uses the instantaneous reward rate, $R(Z_t, \gamma_t)$:
$$
\lambda^* = \sup_{\gamma_t \in [\underline{\gamma},1]} \liminf_{T \to \infty} \frac1{T} \int_{t=0}^{T} R(Z_t, \gamma_t) dt
$$
where
* the instantaneous reward rate $R(Z, \gamma)$, derived from $\frac{d \ln \ell_t}{dt} - \eta Z^2_t$, is: $$R(Z, \gamma) = (1-\gamma) \left\{ \frac{w(1-w)}{w + \gamma (1-w)} \alpha(Z, \gamma) + \frac{w(1-w)}{\gamma w + (1-w)} \beta(-Z, \gamma) \right\} - \eta Z^2$$
* $\underline{\gamma} \in (0,1]$ is the lower bound for the fee tier, and $\eta$ is the mispricing penalty parameter.
### Macroscopic Order Flow Model
We assume an external reference market with price process $S = (S_t)_{t \in [0,\infty)}$ following Geometric Brownian Motion (GBM) dynamics:
$$
d \ln S_t = \mu dt + \sigma dW_t
$$
The AMM price dynamics follow a continuous process driven by order flow:
$$
d\ln P_t = \left\{ \alpha(Z_t, \gamma_t) - \beta(-Z_t, \gamma_t) \right\} dt
$$
Here, $\alpha(Z_t, \gamma_t)$ and $\beta(-Z_t, \gamma_t)$ represent the macroscopic order flow rates that push the AMM price toward the external price $S_t$. $Z_t = \ln S_t - \ln P_t$ is the mispricing process. Order flow functions take the piecewise linear form:
\begin{align}
\alpha(Z, \gamma) &= \max \{a_0 (c + \ln \gamma), a_1 (c + \ln \gamma) + a_2 ( Z + \ln \gamma) \} \\
\beta(Z, \gamma) &= \max \{b_0 (c + \ln \gamma), b_1 (c + \ln \gamma) + b_2 (-Z + \ln \gamma) \}
\end{align}
with $a_0, b_0>0$, $a_1, a_2, b_1, b_2 \geq 0$.
#### Inventory and Liquidity Dynamics
The logarithmic dynamics for inventory ($x_t, y_t$) and total liquidity $\ell_t$ are defined as:
\begin{split}
d \ln x_t &= \frac{1-w}{\gamma_t w + 1-w} \beta(-Z_t, \gamma_t) dt - \frac{\gamma_t (1-w)}{w + \gamma_t(1-w)} \alpha(Z_t, \gamma_t) dt, \\
d \ln y_t &= \frac{w}{w + \gamma_t (1-w)} \alpha(Z_t, \gamma_t) dt - \frac{\gamma_t w}{\gamma_t w + (1-w)} \beta(-Z_t, \gamma_t) dt, \\
d \ln \ell_t &= (1-\gamma_t) \left\{ \frac{w(1-w)}{w + \gamma_t (1-w)} \alpha(Z_t, \gamma_t) + \frac{w(1-w)}{\gamma_t w + (1-w)} \beta(-Z_t, \gamma_t) \right\} dt.
\end{split}
### HJB Equation for Optimal Control
To find the optimal control policy $\gamma_t$, we characterize the maximal ergodic growth rate $\lambda^*$ as the solution to the steady-state Hamilton-Jacobi-Bellman (HJB) equation:
$$
\lambda^* = \sup_{\gamma \in [\underline{\gamma},1]} \left\{ \mathcal{L}^\gamma u + R(z, \gamma) \right\}
$$
where
* $\mathcal{L}^\gamma = \frac{\sigma^2}{2} \frac{d^2}{dz^2} + (\mu - (\alpha - \beta)) \frac{d}{dz}$ is the controlled extended generator.
* $R(z, \gamma)$ is the instantaneous reward rate (including the $\eta Z^2$ penalty).
* $u$ is the relative value function, unique up to an additive constant.
### Research Questions
The aim is to explore the following research questions:
* **Optimal Policy Characterization:** Does an optimal fee tier policy exist within these constraints, and can we characterize its properties? Can we identify the features of the fee tier that lead to optimal results?
* **Performance Quantification:** How does the growth rate achieved by the optimal fee tier policy compare to the growth rate observed in Stochastic Portfolio Theory (SPT)? Can we quantify the benefits of optimal fee control in AMMs?
## Numerical Scheme -- Semi-Implicit Relative Value Iteration (RVI)
The RVI scheme solves a time-dependent quasi-linear parabolic equation that converges to the stationary solution of the HJB equation.
### Solving the Ergodic HJB via RVI
The RVI equation centers the instantaneous reward by subtracting the value at a reference point, $\varphi(t, 0)$, to ensure the solution remains bounded as it evolves toward the relative value function $u^*(z)$.
$$
\frac{\partial \varphi}{\partial t}(t,z) = \sup_{\gamma \in [\underline{\gamma},1]} \left\{ \mathcal{L}^\gamma \varphi(t,z) + R(z, \gamma) \right\} - \varphi(t,0)
$$
* **Semi-Implicit Discretization**: To improve stability and convergence speed, the second-order diffusion term ($\frac{\sigma^2}{2} \partial_{zz}$) is discretized implicitly. Because this term is independent of the control $\gamma$, it can be solved efficiently as a linear system. The drift and reward terms, which involve the maximizing procedure for $\gamma$, are discretized explicitly using centered differences for second-order spatial accuracy.
* **Initial Condition**: We assign a bounded and smooth initial condition, such as $\varphi(0, z) = V_0(z) \equiv 0$.
* **Boundary Conditions**: Neumann boundary conditions are applied at the grid edges to ensure the stability of the mispricing process $Z$.
### Characterizing the Optimal Policy and Cost
As $t \to \infty$, the RVI stabilizes to the following stationary characteristics:
* **Maximal Ergodic Cost $\lambda^*$**: Recovered from the asymptotic centering term: $\lambda^* = \lim_{t \to \infty} \varphi(t, 0)$.
* **Optimal Relative Value Function**: The converged solution represents $u^*(z) = \lim_{t \to \infty} \varphi(t, z) - \varphi(t, 0)$.
* **Optimal Stationary Policy $\gamma^*$**: Obtained by solving the pointwise maximization of the Hamiltonian using the converged relative value function $u^*(z)$: $$\gamma^*(z) = \arg\max_{\gamma \in [\underline{\gamma},1]} \left\{ \mathcal{L}^\gamma u^*(z) + R(z, \gamma) \right\}$$
### Pseudocode: Semi-Implicit RVI
This implementation utilizes an implicit solve for diffusion to allow for significantly larger time steps ($dt$).
#### Initialization
```
// Define Model and Numerical Parameters
INPUT:
Z_min, Z_max, N_grid // Computational grid for Z
sigma, mu, w, eta // Model parameters
gamma_min, gamma_max // Control bounds
dt, T_max // Time step and max simulation time
OUTPUT:
lambda_star // Maximal ergodic growth rate
gamma_star[Z] // Optimal stationary fee control policy
// Initialize Grid and Variables
Z_grid = generate N_grid uniform points from Z_min to Z_max
phi_current = array[N_grid] initialized to 0
Z_ref_idx = index of Z_grid closest to Z=0
// Pre-compute Implicit Diffusion Matrix (M)
// M = [I - dt * (sigma^2/2) * D2], where D2 is the 2nd-order differentiation matrix
M = construct_implicit_diffusion_matrix(Z_grid, sigma, dt)
t = 0
```
#### Main Algorithm: Time Evolution
```
WHILE t < T_max AND NOT converged(phi_current) DO
// STEP 2.1: Explicit Drift and Reward (Hamiltonian)
dphi_dZ = calculate_centered_difference(phi_current)
FOR i from 1 to N_grid DO
// Find optimal gamma explicitly for the current drift
gamma_opt[i] = arg_max_gamma(Z_grid[i], dphi_dZ[i])
// Compute explicit components: Drift * dphi/dz + Reward - Centering
explicit_rhs[i] = (mu - alpha + beta) * dphi_dZ[i] + R(Z_grid[i], gamma_opt[i]) - phi_current[Z_ref_idx]
END FOR
// STEP 2.2: Semi-Implicit Step
// Solve: [I - dt * (sigma^2/2) * D2] * phi_next = phi_current + dt * explicit_rhs
b = phi_current + dt * explicit_rhs
phi_next = solve_tridiagonal(M, b) // Linear solve for implicit diffusion
phi_current = phi_next
t = t + dt
END WHILE
```
#### Characterizing the Optimal Limit
```
// STEP 3.1: Final Values
u_star = phi_current - phi_current[Z_ref_idx]
lambda_star = phi_current[Z_ref_idx]
// STEP 3.2: Final Policy Extraction via Hamiltonian
dphi_dZ_star = calculate_centered_difference(u_star)
d2phi_dZ2_star = calculate_second_order_difference(u_star)
FOR i from 1 to N_grid DO
gamma_star[i] = arg_max_gamma(Z_grid[i], dphi_dZ_star[i], d2phi_dZ2_star[i])
END FOR
PRINT "Maximal ergodic growth rate:", lambda_star
```
## References
* Arapostathis, A., & Biswas, A. (2018). Infinite horizon risk-sensitive control of diffusions without any blanket stability assumptions. Stochastic Processes and their Applications, 128(5), 1485–1524. https://doi.org/10.1016/j.spa.2017.08.001
* Arapostathis, A., & Borkar, V. S. (2012). A relative value iteration algorithm for nondegenerate controlled diffusions. SIAM Journal on Control and Optimization, 50(4), 1886–1902. https://doi.org/10.1137/110850529
* Arapostathis, A., Borkar, V. S., & Ghosh, M. K. (2011). Ergodic control of diffusion processes. *Cambridge University Press*.
* Evans, A. (2021). Liquidity Provider Returns in Geometric Mean Markets. *Cryptoeconomic Systems*, *1*(2). https://doi.org/10.21428/58320208.56ddae1b
* Arapostathis, A., Borkar, V. S., & Kumar, K. S. (2014). Convergence of the relative value iteration for the ergodic control problem of nondegenerate diffusions under near-monotone costs. SIAM Journal on Control and Optimization, 52(1), 1–31. https://doi.org/10.1137/130912918
* Lee, C. Y., Tung, S. N., & Wang, T. H. (2024). Growth rate of liquidity provider's wealth in G3Ms. *arXiv preprint arXiv:2403.18177*.