# A different view at AMMs

In this post we will attempt to formalize the key economical assumptions behind AMMs and derive from them a consistant mathematical framework as we believe that is has not been entirely done in the current litterature.

I hope to make those writings as accessible as possible but knowledge in calculus will probably help the understanding.

I will focus here only on the classical spot price AMMs such as the one proposed on the Uniswap v2 or Sushiswap platform. Formally, we consider a pool where two type of tokens get pooled, a numeraire token A and an asset token B. Traders can exchange token A for token B with the AMM following a specific set of rules and liquidity providers (LPs) can add or removes both token according to another set of rules.

With this in mind, let us ask ourself what is absolutely necessary to require from a pool AMM for it to have a chance to work. We propose the two following properties as base points for our construction:

Property 1: An AMM should never leak money , that is it should be impossible for an external actor to perform a sequence of actions such that If an AMM is in state A with $a_i$ token A and $b_i$ token B, no sequence of actions taken by external actors should put the AMM in state B with $a_f$ token A and $b_f$ token B and such that $a_i \leq a_f$, $a_i \leq a_f$ and $a_i+b_i < a_f+b_f$.

Property 2: The behavior of an AMM should be scale free. This means that the price at which the AMM is selling/buying token should only depend on variables which are independent by scale.

The first property is probably the most fundamental one. Indeed there is no point in putting your money in a pool if there a mean for external actors to arbitrage you.  The second property is more debatable but is in some sense extremely natural as we expect the behavior of an AMM to be independent on the unit of account we consider. Armed with those two properties let us now ask ourselves what an AMM consists in.

We propose to reduce an AMM to two price functions $p_A$ and $p_B$ which represents the price at which the LPs are willing to sell token A and token B at a given state. Following Property 2 we get that hose functions should only depend on the ratio of each token rather than the nominal amount of token and as such we can write them as the ask price $p_A (r)$ and the bid price $p_B(r)$ where $r=\frac{X}{Y}$ is the ratio of token A to token B.

Another way to phrase this is to consider that LPs see the ratio of tokens in the pool as an input for the respective demand of token A and token B in the market and adjust their price accordingly.

Let us now derive some useful consequences of this representation.

When the pool is selling $dX \leq 0$, $dY \geq 0$ and the number of tokens in the pool follows: $dY=-p_A(r)dX$. Conversely when the pool is buying $dY \leq 0$, $dX \geq 0$ and the number of tokens in the pool follows: $dY=-p_B(r)dX$. Let us know play around with those equations a little bit. It is not too hard to see that on can rewrite the first equation as:

$\frac{dY}{Y}=p_{A}(r) \frac{dY}{Y}$

And then

$\frac{dY}{Y}\left( 1+ r p_A(r) \right) =p_{A}(r) dr$

So that

$\frac{dY}{Y} =\frac{p_{A}(r)}{1+ r p_A(r)} dr$

We integrate the relation above to $Ye^{C_A(r)}=Cst$ where C(r) is an antiderivative of $\frac{p_{A}(r)}{1+ r p_A(r)}$.

Enough with the technicalities, let us now unpack what we have written there.

• An AMM strategy is entirely determined by two ask and bid functions $p_A(r)$ and $p_B(r)$, which encodes the price at which pool participants buy and sell at a given ratio. Moreover in order for the Property 1 to holds, we must have that there exist no interval of $r$ on which $p_A > p_B$
• Those two functions determine two invariant curves $Ye^{C_A(r)}=Cst$ and $Ye^{C_B(r)}=Cst$ for buys and sells respectively.

Provided that we allow the bid and ask function to be dependent on time all the common AMM fit in this framework.

• Uniswap without fees uses $p_A(r)=p_B(r)=r$
• Uniswap with fee k base points uses $p_A(r)=r(1+k)$ and $p_B(r)=r(1+k)$
• Synthetix models uses $p_A(r)=Cst$