# Uniswap Formulas

We consider here a pool of the form $k=x*y$, ie a pool where the *invariant function*, also called *indifference function* $k(x,y)$ is the product of the volume of pool holdings $x$ of asset *X* and $y$ of asset *Y*. Both $x$ and $y$ are measured in their native units, eg number of shares or number of tokens.

The fundamental principle of that pool is that, as the name implies, it is indifferent as to its asset holdings $(x,y)$ provided that the indifference function $k(x,y)$ remains at the same value. In other words, if initially the pool holdings are $(x_0, y_0)$ then the pool will trade with any third party provided that the pool holdings after the trade $(x, y)$ satisfy $k(x, y)=k(x_0, y_0)$. This of course ignores transaction fees charged by the pool which we will address at a later stage.

#### Exchange ratio

**Proposition.** Assume a pool that that currently contains an asset portfolio of $(x_0, y_0)$ and that charges no transaction fees. Assume a third party the wants to trade $dx$ units of assets of type *X* with the pool, and we want to know the amount of assets of type *Y* traded in return. We use the viewed-from-pool-perspective convention that $dx>0$ means the pool receives *X* and therefore returns *Y*, $dy<0$. We find that the pool offers the following exchange ratios
$$
\frac{dy}{dx} = - \frac{y_0}{x_0} \cdot \frac{1}{1+\frac{dx}{x_0}}
$$

**Proof.** We use the shorthand $x=x_0+dx$ and $y=y_0+dy$. Using the invariance equation yields $k = x_0 y_0 = x y = (x_0+dx) (y_0+dy)$.

We start with
$$
dy = y - y0 = \frac{k}{x} - \frac{k}{x_0} = \frac{kx_0-kx}{xx_0} = -\frac{k}{xx_0}dx
= - \frac{k}{x} \frac{dx}{x_0} = -y \frac{dx}{x_0}
$$
or, to slightly rewrite the above
$$
\frac{dy}{y}=-\frac{dx}{x_0}
$$
Similarly we get
$$
\frac{dy}{y_0}=-\frac{dx}{x}
$$
Note the respective index or absence thereof one the left and right hand sides of the equation – one of the terms is always *backwards* and the other *forwards*.

We are using the second equation above to write $$ dy=-\frac{y_0}{x_0+dx}dx = -\frac{y_0}{x_0} \frac{dx}{1+\frac{dx}{x_0}} $$ which is essentially the equation we wanted to prove. QED.

#### Marginal exchange ratios

We are now looking what happens in an equilibrium when this pool is embedded into a wider market. In a first step we simply look at what happens for very small trading volumes $dx$ (remember that $dx$ is the choice of the 3rd party trading with the pool, and the pool then chooses the corresponding $dy$).

**Proposition.** (i) For infinitesimal trades, ie $dx$ close to zero, we find
$$
\frac{dy}{dx} = - \frac{y_0}{x_0}
$$
ie the pool exchanges the two assets at exactly the ratio of its current composition (the minus sign simply indicates that exactly on of the terms $dx,dy$ is negative, indicating that the corresponding asset is paid out of the pool).

(ii) The above equation can trivially rewritten into the form
$$
\frac{dy}{y_0} = - \frac{dx}{x_0}
$$
ie for infinitesimal transactions, the percentage changes in the holdings of the assets *X* and *Y are of the same size and opposite sign.

(ii) Moreover, the bigger the trade the less favorable the exchange ratio for the pool.

**Proof.** The equation above is simply a consequence of the fact that in the limit $dx\to 0$ the term $\kappa = \frac{1}{1+dx/x_0} \to 1$ for any non-zero value of $x_0$. We further note that for $dx>0$ we have $\kappa<1$ and vice versa. To show that the bigger the absolute value of $dx$, ie the size of the trade, we first note that a positive $dx$ means that the pool is receiving *X* and paying away *Y* and vice versa. So lets assume that indeed $dx>0$. As we showed above in this case we have $\kappa < 1$ and this means that the amount $dy$ received by the third party is, in absolute terms, smaller than what they’d receive in the limit $dx\to 0$. Similalry for $dx<0$, meaning the pool pays of *X*, we find $\alpha > 1$ meaning that the other party has to pay more *Y* than in the case $dx\to 0$.

#### Pool composition

We now define $p_x$ and $p_y$ respectively as the *price* of one native unit in some common numeraire. To give an example, if of the pool consist of *X=ETH* and *Y=BTC* and the numeraire is *USD* then $p_x$ is the *USD* price of Ethereum (say 300 at at the time of writing) and $p_y$ is the USD price of *BTC* (say USD 10,000).

Note that the choice of numeraire is arbitrary, and in some cases it makes sense to chose one of the two assets as numeraire. Say we choose *ETH*, in which case $p_x=1$ and $p=p_y$ is the *BTC* price in *ETH*, in our example $p_y=p=10,000/300=33.3$.

We define a *deep and liquid market with no transaction costs* as a market, accessible to at least a subset of profit maximising market participants (the “arbitrageurs”) where the assets *X* and *Y* can be traded against the numeraire asset at a price of $p_x$ and $p_y$ respectively, with no transaction costs, no bid/offer spread, and at unlimited volume.

**Proposition.** (i) In a deep and liquid market, assuming no pool transaction costs, and using the notation from above, we have
$$
p_x x = p_y y
$$
In other words, when expressed in any common numeraire, the value of the assets *X* and *Y* that are held in the pool is the same.

(ii) This relation holds whatever the numeraire chosen.

**Proof.** To prove (ii) we simply note that a change of numeraire simply means multiplying the equation from (i) with the same number on both sides. In the equilibrium we must have that, for infinitesimal trades, $dy/dx$ from the marginal exchange ratios equation (i) equals $-p$, as otherwise arbitrageurs would trade against the pool. Using the other side of this equation yields $p=y_0/x_0$ or $p x_0 = y_0$. $p x_0$ is the value of the *X* component of the pool expressed in the *Y* numeraire, and $y_0$ is the value of the *Y* component, also in the $Y$ numeraire. Because we already proved part (ii) the general equation (i) is true whatever the numeraire.

#### Pricing formula

We now assume a pool that is arbitraged at a price level of $p_0$. We know from the formulas above that this means that if the pool contains $(x_0, y_0)$ units of *X* and *Y* respectively that then $p_0 x_0 = y_0$ expressing the fact that both assets in the pool are held in the same monetary amount, whatever the numeraire in which that amount is determined.

**Proposition.** (i) A pool that is arbitraged at a price $p_0$ and where the volume of assets held is $(x_0, y_0)$ trades with 3rd parties at a price of
$$
p(dx) = p_0 \cdot \frac{1}{1+\frac{dx}{x_0}}
$$
where a positive trading volume $dx>0$ indicates that the pool receives *X* and pays away *Y*, and a negative volume $dx<0$ indicates it receives *Y* and pays away *X*.

(ii) We define $\alpha = \frac{dx}{2x_0}$ which in an arbitraged pool is the trading volume as percentage of the overall pool value. In this case the above equation becomes $$ p(\alpha) = \frac{p_0}{1+2\alpha} $$

**Proof.** Noting that $p(dx) = dy/dx$ this is a trivial rewrite of the equations above.