How Slippage Works in Uniswap V2

This is the third article from the deep dive series into how Uniswap V2 works, and it focuses on what slippage is, how it is related to the pool liquidity depth, and how it affects the token price. This article is also the continuation of the previous article on how price is discovered on Uniswap V2 and you should consider checking it out first before diving deeper into this topic.

Slippage is a very simple concept. Slippage is a percentage value that describes the percentage difference between the tokens you will receive from a trade, and the tokens you would receive if there was zero slippage. This definition might sound cryptic at first glance, but it’s quite easy to understand.

As we discussed in the previous article, when you exchange x tokens for y tokens through a liquidity pool, the exchange adds x tokens to one side of the pool, and removes y tokens from the other side of the pool, affecting the pool ratios, which in turn changes the exchange rate for the next exchange. This can be visualized through the X Y Ratio curve shown below, from which the exchange rate, and consequently price, can be discovered.

The blue line plots the X Y Ratio curve, and as we trade x and y tokens we move along this curve. As an example, let’s say the pool is loaded with 100 x tokens and 100 y tokens. If we look at the chart above, we will be on the point (x = 100, y = 100) along the blue curve.

Now, if we want to exchange 100 x tokens through this liquidity pool, we can check the blue line and see to where we will move in the curve, and how many tokens we will receive for this trade. We will add 100 x tokens to the x side of the pool, pushing the amount of x tokens inside the pool to 200, and we can check by looking at the blue line that the y tokens inside the pool must be reduced from 100 to 50 (x = 200, y = 50). And therefore, just by looking at the chart above, we have deducted that we will receive 50 y tokens for 100 x tokens.

We can also do this mathematically through the exchange formula we’ve been using:

\( \triangle y= y\ – \dfrac {k}{x+\triangle x} \)

Plugging in the values we get:

\(\triangle y = 100\ – \dfrac{10000}{(100+ 100)} = 50 \)

Ok, so we exchanged 100 x tokens for 50 y tokens. If there was zero slippage, we would have exchanged 100 x tokens for 100 y tokens. This means we received 50% less than what a “perfect exchange” would have given us, and this is the slippage of the trade.

We can deduce a formula from what we concluded. The formula is as follows:

\( slippage= \dfrac {PE – AE}{PE} \)

Where PE is Perfect Exchange, and AE is Actual Exchange.

With an exchange rate of 100 x tokens to 100 y tokens, the perfect exchange is at a one-to-one ratio, and would results in receiving exactly the same amount of y tokens for the x tokens given. So, for this example we can plug in the numbers and calculate the slippage:

\( slippage= \dfrac {100 – 50}{100} = 0.5 = 50\% \)

To drive this point home, let’s now consider another exchange of 100 x tokens. We just exchanged 100 x tokens for 50 y tokens, having experienced 50% slippage, and have changed the liquidity amounts inside the pool from 100 x tokens on one side of the pool, and 100 y tokens on the other side of the pool, to 200 x tokens and 50 y tokens, respectively.

So, if we now exchanged again 100 x tokens, we would move on the X Y Ratio line (the blue line on the chart above), from 200 x tokens to 300 x tokens, and on the Y axis for the y tokens we would move from 50 y tokens to 33.333 y tokens. Therefore, for the 100 x tokens we would receive only 16.666 y (50 – 33.333 = 16.666) tokens.

We can also check with our formula to make sure this is true:

\(\triangle y = 50\ – \dfrac{10000}{(200+ 100)} = 16.666 \)

Ok, so if this was a perfect exchange, the exchange rate would stand at 200 x tokens for 50 y tokens, and therefore we would receive one y token for every four x tokens given. For the 100 x tokens we want to exchange, we would receive 25 y tokens through a perfect exchange. So let’s calculate the slippage we are experiencing this time:

\( slippage= \dfrac {25 – 16.666}{25} = 0.333 = 33.3\% \)

This means that in this second (and consecutive) trade of 100 x tokens, we received only 16.666 y tokens, and experienced a slippage of 33.3%. It is interesting to notice here that slippage got lower.

The table below shows 10 consecutive 100 x token swaps and how much slippage each consecutive trade experiences:

SwapPool XPool YTrade XReceive YPEAESlippage
1100100100501005050%
22005010016.666672516.6666733%
330033.333331008.33333311.111118.33333325%
44002510056.25520%
5500201003.33333343.33333317%
660016.666671002.3809522.7777782.38095214%
770014.285711001.7857142.0408161.78571413%
880012.51001.3888891.56251.38888911%
990011.111111001.1111111.2345681.11111110%
101000101000.90909110.9090919%

As we can clearly see, every consecutive trade reduces the slippage experienced. To understand exactly why that is the case, we require a deeper analysis still, which will be provided in the next article.

But for now, what we can observe is that slippage is reduced as we do consecutive trades of x tokens for y tokens. Slippage is also related to price action. The higher the slippage, the greater the price change. Intuitively, this means that as we go through each one of these consecutive trades, we are producing a less and less pronounced price change.

Does this mean that as we exchange x tokens for y tokens we are moving towards price stabilization and finding an equilibrium? Actually no, far from it. To understand why, we need to look at what is happening on the other side of the pool. Spoiler alert: slippage is increasing.

Let’s do the following thought experiment: After each consecutive trade, from which we have accumulated more y tokens, what would happen if we sold all y tokens in one go. The table below shows exactly those calculations.

SwapPool XPool YTrade XReceive YSlippage XSlippage Y
11001001005050%50%
22005010016.6666733%67%
330033.333331008.33333325%75%
440025100520%80%
5500201003.33333317%83%
660016.666671002.38095214%86%
770014.285711001.78571413%88%
880012.51001.38888911%89%
990011.111111001.11111110%90%
101000101000.9090919%91%

As we can see from the table, after the first trade, if we decided to sell all our y tokens (the 50 y tokens we just received from the trade), we would produce an equivalent slippage of 50% but in the opposite direction, taking us back to the starting price. And if we consider only selling all our y tokens after a few consecutive trades, we can see that slippage from the sale would be greater.

What is more surprising still, is that the slippage from buying + selling y tokens totals always 100%. This means that we are pushing slippage around as we trade, and that the pool has “forces” that tend to bring back price to it’s original position.

This should be disconcerting for all degen traders out there, expecting a 1000x from the next gem out there.

«
»