ELI 5 - Automated Market Makers (AMM) Explained Like You Are Five

Every DeFi user has interacted with an AMM at least once. Uniswap, Sushiswap, 1Inch... All of these exchanges are actually automated market makers but how do they actually operate under the hood?

It is a lot simpler than you think.

ELI 5 5.png

Makers vs Takers

To understand the logic behind an AMM we first need to understand what is a market maker. The simplest way to do so is to visit the LeoDex and check the order books for any token available there.

Screenshot_1.png

In this example we see both sides of an order book - sell orders and buy orders. All of those are set by market makers since they do not fill orders, they only make them.

Market takers then come into play as these are the people that only fill orders and want to execute them immediately. In short, market makers establish token prices while takers fill both sides of the order book.

This whole creative mess requires a lot of manual work from market makers so DeFi came up with a very simple solution that eliminates the need for any more manual labor.

What Is a Liquidity Pool?

A Liquidity pool is a pool of two or more different assets that are used by an AMM to simplify the process of trading. Dual liquidity pools require users to deposit assets at a 50/50 ratio based on USD value as to not disrupt the current market price. All of this will be explained in detail below.

What Is An Automated Market Maker (AMM)?

An automated market maker like Uniswap uses math instead of manual labor. A very simple equation is responsible for keeping every single liquidity pool in balance.

x * y = k

x = Token A

y = Token B

k = Constant. Balance of assets that determines the price of tokens in a liquidity pool.

Sounds confusing but let's use a simple example where this equation comes into play. For the sake of simplicity, imagine a liquidity pool that contains 100 Apples and 100 Oranges meaning that 1 Apple = 1 Orange and vice versa.

After a while, you come along and want to exchange 30 Apples for 30 Oranges but that won't really work out as planned. Here is why...

x * y = k --> 100 * 100 = 10,000 --> K= 10,000

If you exchange 30 Apples for 30 Oranges we would be left with 130 Apples and 70 Oranges in the pool which now drastically changes the price. Instead of letting you get away with this, the protocol will do a simple calculation and determine the unit price based on your order. In this specific case, it would first need to calculate what will be left in the pool after the trade is executed.

To get that info we need to divide K with the new amount of Apples present in the pool after the trade.

10,000/130 = 76.923...

76.923 represents the number of Oranges that need to remain in the pool after the trade is executed. Why? Because any other amount would break the base equation that clearly states x * y = k.

If you want to exchange 30 Apples for Oranges you will get roughly 23 Oranges instead of the expected 30. It may seem off but when you do the math with the new state of the pool it all makes sense.

Starting balance - 100 Apples / 100 Oranges

New balance - 130 Apples / 76.923... Oranges

130 x 76.923... = 10.000

Prices and pool supply may change but the constant always needs to remain unchanged after every executed trade.

Available liquidity and order sizes will then determine the price slippage. To clarify, in the example above users would expect to get 30 Apples for 30 Oranges since they are clearly sitting in the pool at a 1:1 ratio but if you try to purchase 30 Oranges with 30 Apples you would dilute the pool at the cost of liquidity providers, which is not how we want the future of finance to look like.

Instead, the protocol will adjust the price "on the go" based on the size of your order.

H2
H3
H4
3 columns
2 columns
1 column
2 Comments