---
# System prepended metadata

title: Kyle_equilibrium_Uniswap
tags: [AMM, Research]

---

# Kyle Style Equilibrium Model for CLMM
In this note, we propose an equilibrium model for concentrated liquidity provision market makers *a la* Kyle.



## One Period Model
Let $P_i$ be the marginal price of $X$ at time $i = 0, 1$. $P_0$ is known to the AMM and to an informed trader $\mathcal{I}$. Informed trader $\mathcal{I}$ knows $P_1$ whereas $P_1$ is random to the AMM, due to swaps from noisy traders.


### Liquidity profile
Let $\ell$ be the liquidity profile. Recall that we have the relationship between liquidity profile and pool price $(\ell, P)$ and the pool reserve $(x, y)$ as

\begin{split}
&& x = \frac12 \int_P^\infty \frac{\ell(q)}{\sqrt{q^3}} dq \\
&& y = \frac12 \int_0^P \frac{\ell(q)}{\sqrt q} dq
\end{split}


### Informed trader
Informed trader's goal is to maximize his profit from the pool. Since he knows the price $P_1$, wlog assume $P_1 > P_0$, he would buy certain amount of $X$ at time 0 then unwind this position at time 1 for profit. Assume the amount he purchases at time 0 is $\Delta x$, which push the marginal price up to $\bar P_0$. 

We have that

$$
\Delta x = \frac12 \int_{P_0}^\infty \frac{\ell(q)}{q^{3/2}} dq - \frac12 \int_{\bar P_0}^\infty \frac{\ell(q)}{q^{3/2}} dq = \frac12 \int_{P_0}^{\bar P_0} \frac{\ell(q)}{q^{3/2}} dq.
$$

He pays to the pool $\Delta y_0$

$$
\Delta y_0 = \frac12 \int_{P_0}^{\bar P_0} \frac{\ell(q)}{\sqrt q} dq
$$

At time 1, the marginal price becomes $P_1 > P_0$, he sells $\Delta x$ back to the pool, which push the marginal price down to $\bar P_1$

$$
\Delta x = \frac12 \int_{\bar P_1}^{P_1} \frac{\ell(q)}{q^{3/2}} dq
$$

and receive $\Delta y_1$ from the pool

$$
\Delta y_1 = \frac12 \int_{\bar P_1}^{P_1} \frac{\ell(q)}{\sqrt q} dq
$$

#### Informed trader's objective
Given the liquidity profile $\ell$, The informed trader's objective is to maximize his profit

$$
\max_{\Delta x} \left\{ \Delta y_1 - \Delta y_0 \right\} = \max_{\bar P_0, \bar P_1} \left\{\frac12 \int_{\bar P_1}^{P_1} \frac{\ell(q)}{\sqrt q} dq -  \frac12 \int_{P_0}^{\bar P_0} \frac{\ell(q)}{\sqrt q} dq \right\}
$$

subject to

$$
\Delta x = \frac12 \int_{P_0}^{\bar P_0} \frac{\ell(q)}{q^{3/2}} dq = \frac12 \int_{\bar P_1}^{P_1} \frac{\ell(q)}{q^{3/2}} dq
$$

We shall refer to the maximizer as $\bar P_i = \bar P_i(P_1, \ell)$ for $i = 0, 1$. Note

* If $P_1 > P_0$, we expect to have $P_0 < \bar P_0 < \bar P_1 < P_1$.
* Conversely, if $P_1 < P_0$, then $P_0 > \bar P_0 > \bar P_1 > P_1$.

<font color=red>Here I want to clarify the scenerio. 
* Based on your formulation, the informed trader knows the marginal price of AMM at time 1, which should be the same as the fair price in the market as well. This is the same as in the Kyle model.
* In practice, there is another kind of informed trader through MEV. That is, those who see the unconfirmed transactions in the mempool. To extract value from this information, they solve a similar optimization problem but with a known trading amount processing at time 1. This is called a "sandwich attack." A sandwich attack involves a trader placing buy and sell orders around a victim's pending transaction to profit from the price slippage.
    * https://docs.cow.fi/mevblocker/concepts/mev-concepts/sandwich-attacks
    * https://support.uniswap.org/hc/en-us/articles/19387081481741-What-is-a-sandwich-attack
    * https://arxiv.org/abs/2207.11835
    * https://arxiv.org/abs/2310.07865
</font>

#### Lagrange multiplier method
\begin{split}
& \max_{\bar P_0, \bar P_1} \left\{\int_{\bar P_1}^{P_1} \frac{\ell(q)}{\sqrt q} dq - \int_{P_0}^{\bar P_0} \frac{\ell(q)}{\sqrt q} dq - \lambda \left( \int_{P_0}^{\bar P_0} \frac{\ell(q)}{q^{3/2}} dq - \int_{\bar P_1}^{P_1} \frac{\ell(q)}{q^{3/2}} dq \right) \right\} \\
=& \max_{\bar P_0, \bar P_1} \left\{\int_{\bar P_1}^{P_1} \left(1 + \frac\lambda q\right) \frac{\ell(q)}{\sqrt q} dq - \int_{P_0}^{\bar P_0} \left(1 + \frac\lambda q\right) \frac{\ell(q)}{\sqrt q} dq \right\}
\end{split}


### Automated Market Maker
AMM's objective is to minimize his expected *impermanent loss (IL)* subject to limited liquidity provision condition.

AMM's IL at time 1 is given by

$$
\begin{split}
\rm IL(P_1) =& x(P_0)P_1 + y(P_0) - V(P_1) \\
=& \frac12 \left\{ \int_{P_0}^\infty P_1 \frac{\ell(q)}{q^{3/2}}dq + \int_0^{P_0} \frac{\ell(q)}{\sqrt q} dq  \right\} - \frac12 \left\{ \int_{P_1}^\infty P_1 \frac{\ell(q)}{q^{3/2}}dq + \int_0^{P_1} \frac{\ell(q)}{\sqrt q} dq  \right\} \\
=& \frac12 \int_{P_0}^{P_1} \frac{P_1}q \frac{\ell(q)}{\sqrt q}dq + \frac12 \int_{P_1}^{P_0} \frac{\ell(q)}{\sqrt q} dq \\
=& \frac12 \int_{P_0}^{P_1} \left\{\frac{P_1}q - 1\right\} \frac{\ell(q)}{\sqrt q}dq \\
=& \frac12 \int_0^\infty \left\{\frac{P_1}q - 1\right\} \left(\pmb{1}_{[0,\infty)}(P_1 - P_0) \pmb{1}_{[P_0,P_1]}(q) - \pmb{1}_{[0,\infty)}(P_0 - P_1) \pmb{1}_{[P_1,P_0]}(q) \right)\frac{\ell(q)}{\sqrt q}dq \\
=& \frac12 \int_0^\infty \left\{\frac{P_1}q - 1\right\} \left\{\pmb{1}_{[P_0,\infty)}(q) \pmb{1}_{[0,P_1]}(q) - \pmb{1}_{[P_1,\infty)}(q) \pmb{1}_{[0,P_0]}(q) \right)\} \frac{\ell(q)}{\sqrt q}dq
\end{split}
$$

Note
* $\rm IL(p) > 0$ for all $p \neq P_0$ if $\ell \geq 0$ and not identically zero.


#### LP's objective
The AMM's objective is to minimize his exepected IL (since $P_1$ is random)

$$
\min_{\ell \geq 0} \mathbb{E}\left[ \frac12 \int_0^\infty \left\{\frac{P_1}q - 1\right\} \left\{\pmb{1}_{[P_0,\infty)}(q) \pmb{1}_{[0,P_1]}(q) - \pmb{1}_{[P_1,\infty)}(q) \pmb{1}_{[0,P_0]}(q) \right)\} \frac{\ell(q)}{\sqrt q}dq \right],
$$

where $P_1 = \mu + \sigma \epsilon$ and $\epsilon$ is a (exogenous) random variable of mean zero and unit variance, subject to the (normalized) liquidity provision

$$
\|\ell\|_2^2 := \int_0^\infty \ell^2(q) dq = 1 \quad \mbox{ or } \quad \|\ell\|_1 := \int_0^\infty \ell(q) dq = 1
$$

We shall denote the minimizer as $\ell = \ell(\mu)$.

Note
* Without the $L^2$ or $L^1$ condition on $\ell$, the global minimum 0 is achieved at $\ell \equiv 0$.
* One can also consider weighted norms.
* Instead of prespecifying the distribution of $P_1$ via $\epsilon$, one can also consider distribution of $P_1$ with maximal entropy subject to constraints on mean and variance.

<font color=red>I have the following concerns: 
* The constraint is mathematically fine but lacks a clear economic interpretation. Usually, AMMs have a fixed budget of inventories and can interact with the lending protocol if necessary (i.e., using one inventory as collateral to borrow another and provide liquidity).
* To use IL as the objective, a reason should be provided for why one would provide liquidity if it consistently leads to a loss.
* Maybe one should use P\&L instead.
</font>


### Equilibrium
We define the equilibrium $P^*$ and $\ell^*$ when
* informed trader maximizes his profit at $P^*$, i.e., $P_i(P^*, \ell^*) = \max_p P_i(p, \ell^*)$ for $i=0,1$.
* AMM minimize his IL at $\ell(P^*)$, i.e., $\ell(P^*) = \min_{\mu} \ell(\mu)$.

<font color=red>I have the following questions:
* By the formulation, the LP's objective is determined by the future price $P_1$ instead of the informed trader's response $\bar P_1$. Thus, the problem as formulated is not well-posed.
* In particular, if the informed trader's response $\bar P_1$ were used directly in the AMM's objective, there would be no underlying randomness, and thus taking an expectation would be meaningless.
* A more reasonable approach would be to formulate this as a Stackelberg game, where the AMM first chooses its liquidity profile $\ell$ based on prior information, and then the informed trader solves for their optimal trading strategy $P(\ell)$ given this profile.
</font>



## One Period Model with Transaction Cost
In this section, we consider the case that AMM charges a fixed-percentage fee tier $\gamma$.


### Market mechanism with transaction fee
Let $f$ denote the bonding function.

* If a swapper swap $\Delta x > 0$ of $X$ tokens with the pool, he pays $\Delta y$ of $Y$ tokens to the pool determined by $$f(x_0 + \gamma \Delta x, y_0 + \Delta y) = f(x_0, y_0).$$ The pool collects $(1 - \gamma)\Delta x$ of $X$ tokens for transaction fee.
* On the other hand, if $\Delta x < 0$, $$f(x_0 + \Delta x, y_0 + \gamma \Delta y) = f(x_0, y_0).$$ The pool collects $(1 - \gamma)\Delta y$ of $Y$ tokens for transaction fee.

#### Adapted Inventories
Let $P_0$ be the current pool price and $P_1$ be the (random, exogeneously given) price in the future. This means that a (representive) swapper has swapped a (random) amount $(\Delta x, \Delta y)$ of tokens with the pool. We recover this amount by the change of pool price as follows.

* If $P_1 < P_0$, the pool price went down, we have $\Delta x > 0$. The pool reserve goes as $$(x(P_0), y(P_0)) \quad \longrightarrow \quad (x(P_1), y(P_1))$$ Due to transaction fee, this means that the swapper has swapped $$\Delta x = \frac1\gamma (x(P_1) - x(P_0))$$ of $X$ tokens with the pool. The pool has collected $\frac{1 - \gamma}\gamma (x(P_1) - x(P_0))$ of $X$ tokens for transaction fee, which has value $\frac{1 - \gamma}\gamma (x(P_1) - x(P_0))P_1$ if evaluated in the current pool price $P_1$.
* On the other hand, if $P_1 > P_0$, the pool price went up, we have $\Delta x < 0$. Due to transaction fee, this implies that the swapper has swapped $$\Delta y = \frac1\gamma \{y(P_1) - y(P_0)\}$$ of $Y$ tokens with the pool. The pool has collected $\frac{1 - \gamma}\gamma \{y(P_1) - y(P_0)\}$ of $Y$ tokens for transaction fee.

<font color=red>I have the following comments: 
* Here, one needs to be careful about the meaning of the future price $P_1$ for the informed trader because, in the presence of fees, the effective marginal prices for buying and selling become $\gamma^{-1}P$ and $\gamma P$.
* Therefore, if the informed trader has the information of an asset's "fair market value", he would expect the AMM's marginal price to move to that value only when it lies outside the interval $[\gamma P, \gamma^{-1} P]$. This requires extra assumptions on the AMM side.
* Empirical data suggests that price movement is zero for the majority of blocks. This provides evidence for the above inference.
</font>


### Fee-adjusted IL
The fee-adjusted IL, denoted by $\tilde{\rm IL}$, is then given as

$$
\tilde{\rm IL} := \{x(P_0) P_1 + y(P_0)\} - \{x(P_1) P_1 + y(P_1)\} - F(P_1, P_0),
$$

where the fee $F$ is calculated as

\begin{split}
F(P_1, P_0) 
&= \frac{1-\gamma}\gamma \{y(P_1) - y(P_0)\} \pmb{1}_{[0,\infty)}(P_1 - P_0) + \frac{1-\gamma}\gamma \{x(P_1) - x(P_0)\} P_1 \pmb{1}_{[0,\infty)}(P_0 - P_1) \\
&= \frac{1-\gamma}\gamma \{y(P_1) - y(P_0)\}^+ + \frac{1-\gamma}\gamma P_1 \{x(P_1) - x(P_0)\}^+. 
\end{split}

We combine the terms as

\begin{split}
&\{x(P_0) P_1 + y(P_0)\} - \{x(P_1) P_1 + y(P_1)\} - F(P_1, P_0) \\
=& \left\{1 + \frac{1 - \gamma}\gamma \pmb{1}_{[0,\infty)}(P_0 - P_1) \right\} \{x(P_0) - x(P_1)\}P_1 \\
& + \left\{1 + \frac{1 - \gamma}\gamma \pmb{1}_{[0,\infty)}(P_1 - P_0) \right\} \{y(P_0) - y(P_1)\}
\end{split}

By applying the relationship between liquidity profile $\ell$ and pool reserves $(x,y)$, we have

\begin{split}
&\frac{P_1}2 \left\{1 + \frac{1 - \gamma}\gamma \pmb{1}_{[0,\infty)} (P_0 - P_1) \right\} \int_{P_0}^{P_1} \frac{\ell(q)}{\sqrt{q^3}} dq + \left\{1 + \frac{1 - \gamma}\gamma \pmb{1}_{[0,\infty)}(P_1 - P_0) \right\} \frac12 \int_{P_1}^{P_0} \frac{\ell(q)}{\sqrt q} dq \\
=& \frac12 \int_0^\infty \left\{ -\frac1\gamma \pmb{1}_{[0,\infty)}(P_0 - P_1) \pmb{1}_{[P_1, P_0]}(q) + \pmb{1}_{[0,\infty)}(P_1 - P_0) \pmb{1}_{[P_0, P_1]}(q) \right\} \frac{P_1}q \frac{\ell(q)}{\sqrt q} dq \\
& + \frac12 \int_0^\infty \left\{ -\frac1\gamma \pmb{1}_{[0,\infty)}(P_1 - P_0) \pmb{1}_{[P_0, P_1]}(q) + \pmb{1}_{[0,\infty)}(P_0 - P_1) \pmb{1}_{[P_1, P_0]}(q) \right\} \frac{\ell(q)}{\sqrt q} dq \\
=& \frac12 \int_0^\infty \left\{\left(-\frac1\gamma + \frac{P_1}{q} \right) \pmb{1}_{[P_0,\infty)}(q) \pmb{1}_{[0, P_1]}(q) + \left(-\frac{P_1} {\gamma q} + 1\right) \pmb{1}_{[P_1,\infty)}(q) \pmb{1}_{[0, P_0]}(q) \right\}  \frac{\ell(q)}{\sqrt q} dq \\
=& \int_0^\infty \varphi(P_1, q) \ell(q) dq
\end{split}

where we defined the function $\varphi$ as

$$
\varphi(P_1, q) := \left\{\left(\frac{P_1}{q} - \frac1\gamma \right) \pmb{1}_{[P_0,\infty)}(q) \pmb{1}_{[0, P_1]}(q) + \left(1 - \frac{P_1} {\gamma q} \right) \pmb{1}_{[P_1,\infty)}(q) \pmb{1}_{[0, P_0]}(q) \right\} \frac1{2\sqrt q}.
$$

By Fubini's theorem, we obtain the expected fee-adjusted IL as

\begin{split}
\mathbb{E}[\tilde{\rm IL}] 
&= \mathbb{E}[\{x(P_0) P_1 + y(P_0)\} - \{x(P_1) P_1 + y(P_1)\} - F(P_1, P_0)] \\
&= \int_0^\infty \frac12 \left\{ \left(-\frac1\gamma \mathbb{P}(P_1 \geq q) + \mathbb{E}[\frac{P_1}q; P_1 \geq q] \right) \pmb{1}_{[P_0, \infty)}(q) \right. \\
& \left. + \left(-\frac1\gamma \mathbb{E}[\frac{P_1}q; P_1 \leq q] + \mathbb{P}(P_1 \leq q)\right) \pmb{1}_{[0, P_0]}(q) \right\} \frac{\ell(q)}{\sqrt q} dq \\
&= \int_0^\infty c(q)\ell(q) dq
\end{split}

where apparently

$$
c(q) = \mathbb{E}[\varphi(P_1, q)]
$$

We observe that, for $q \geq P_0$, $c(q)$ is less than or equal to zero if

$$
\frac1\gamma \mathbb{P}(P_1 \geq q) \geq  \mathbb{E}[\frac{P_1}q; P_1 \geq q].
$$

On the other hand, for $q \leq P_0$, $c(q)$ is less than or equal to zero if

$$
\frac1\gamma \mathbb{E}[\frac{P_1}q; P_1 \leq q\ \geq \mathbb{P}(P_1 \leq q).
$$

Note that $-c(q)$ is bounded above, i.e., $c(q)$ is bounded below, since

\begin{split}
-c(q) &\leq \frac1{2\sqrt q} \left\{ \left(\frac1\gamma \mathbb{P}(P_1 \geq q) - \mathbb{P}(P_1 \geq q) \right)\pmb{1}_{[P_0, \infty)}(q) \right. \\
&\qquad \qquad \left. + \left( \frac1\gamma \mathbb{P}(P_1 \leq q) - \mathbb{P}(P_1 \leq q) \right)\pmb{1}_{[0, P_0]}(q) \right\} \\
&= \frac1{2\sqrt q} \left( \frac1\gamma - 1 \right) \left\{ \mathbb{P}(P_1 \geq q) \pmb{1}_{[P_0, \infty)}(q) +  \mathbb{P}(P_1 \leq q) \pmb{1}_{[0, P_0]}(q) \right\} \\
&\leq \frac1{2\sqrt q} \left( \frac1\gamma - 1 \right)
\end{split}

It follows that

\begin{split}
-\mathbb{E}[\tilde{\rm IL}] 
&= \int_0^\infty -c(q)\ell(q) dq \\
&\leq \frac12\left(\frac1\gamma - 1\right) \int_0^\infty \frac{\ell(q)}{\sqrt q}dq \\
&= \left(\frac1\gamma - 1\right) \lim_{p\to\infty} y(p)
\end{split}

We remark that, since $V(p) := x(p)p + y(p)$ is increasing in $p$, therefore

$$
\max_p V(p) = \lim_{p\to\infty} \left\{ px(p) + y(p)\right\}.
$$

Also,

$$
\lim_{p\to\infty} px(p) = \frac12 \lim_{p\to\infty} p \int_p^\infty \frac{\ell(q)}{q^{3/2}} dq
= \frac12 \lim_{p\to\infty} p^2 \frac{\ell(p)}{p^{3/2}} = \frac12 \lim_{p\to\infty} \sqrt p \ell(p).
$$

We conclude that

$$
\max_p V(p) = \lim_{p\to\infty} y(p)
$$

if $\lim_{p\to\infty} \sqrt p \ell(p) = 0$, i.e., the liquidity profile $\ell$ decays to zero faster than one over square root.

In reality, since $\ell$ will be compactly supported, we have $\max_p V(p) = \max_p y(p)$.

<font color=red>My main concern for this part is on the choice of model for the distribution of $P_1$. 
* As I mentioned above, the probability of no price movement should be positive, and thus a normal distribution is not directly applicable. 
* Perhaps a distribution with a point mass at zero, or another distribution that allows for a higher probability of small price changes, would be more appropriate to reflect the empirical observation.
</font>