Posts

Automated Market Makers

avatar of @lbi-token
25
·
0 views
·
7 min read

Authored by: @hetty-rowan



Rapidly changing

The world of crypto is a rapidly changing world. And new terms are used again just as easily, while you may not even have gotten used to all the 'older terms from last year'. For example, in the past year, we have of course seen the terms NFT, layer-one blockchain and DeFi. But you may have also come across the term Automated Market Maker (AMM).

Automated Market Maker

Anyone who is, or would like to be in DeFi should really know what an AMM is because an AMM is essentially the core component of a decentralized exchange (DEX). DEXs are the foundation of DeFi, so Automated Market Makers are also crucial to DeFi.

Impermanent Loss

A good understanding of the term AMM and how such an automated market maker works makes the use of well-known DeFi protocols such as UniSwap, PancakeSwap and SushiSwap a lot easier and more self-explanatory. You will also be more aware of certain risks when using DeFi protocols, such as impermanent loss.

So are you interested in DeFi? Then this blog is definitely worth reading. Pay attention, this will probably be a fairly technical blog, but of course, I do my best to explain everything as simply and clearly as possible! Whether I will succeed or not, I leave that up to you.

What is an AMM?

An AMM, or Automated Market Maker, is an underlying DEX protocol that values ​​cryptocurrency trading pairs using a mathematical formula. Such a trading pair could be ETH/USDC, for example. Unlike a traditional order book, where the price is determined by the convergence of supply and demand, cryptocurrencies at an SMP are valued by a price algorithm.

The formula used differs per protocol. For example, UniSwap uses a very simple formula, namely: xy=k**. Here x is the amount of one token in the liquidity pool and y is the amount of the other token. k is a fixed constant, so the liquidity in the pool must always remain the same.

Other AMMs work slightly differently, but ultimately the bottom line is that they all algorithmically determine the price. This may all seem a bit vague and complex, but don't worry! After reading this blog, I hope that you will fully understand what we´re talking about.

How does an AMM work?

Similar to a traditional order book, an AMM works with trading pairs, such as ETH/USDC. However, with an AMM, unlike a traditional order book, no counterparty is needed to make an exchange. We can make this a bit clearer with an example:

On an exchange like Binance, which uses a traditional order book, you want to exchange 1000 USDC for 0.25 ETH. You place a buy order for this. On the other hand, you have sell orders, ie people who want to exchange their ETH for USDC. However, the lowest sell order stands at 0.25 ETH for 1200 USDC.

In this case, there is no counterparty willing to trade at your set price, so you cannot trade either. An exchange can only take place if you adjust your buy order or someone else places a lower sell order.

So everyone is free to choose their own price with a traditional order book, but trading only takes place if two people are willing to trade at the same price.

However, an AMM uses smart contracts, which "make" the market for users. Hence the name Automated Market Maker. If you want to exchange ETH to USDC on a decentralized exchange like Uniswap, which uses an AMM, you are therefore interacting with a smart contract instead of another person.

There is no order book, so no order types are possible. All you can do is exchange one cryptocurrency for another at an algorithmically determined price. For example, you deposit ETH via a smart contract into the liquidity pool and you get USDC in return.

So no counterparty is needed. You only have to deposit X to get Y back, but where does that liquidity in such a smart contract come from? There is no magic crypto printer in such a smart contract or anything…

No, of course, that liquidity still has to be delivered, and that is done through so-called liquidity providers (LPs).

What is a liquidity pool?

I guess we all know that very well here, but for the few people who don´t know, a short explanation! To better understand the concept of Automated Market Maker, it is important that you also understand what a liquidity pool is. The two cannot live without each other.

Here again, we use an example to make it as clear as possible (Note! There is some math involved):

Pete owns 1 ETH and wants to exchange it for USDC. For this, he goes to UniSwap V2, a place where he can exchange these coins. Ahead of him lies a scale (the liquidity pool) with ETH coins on one side and USDC coins on the other.

There are currently 145.46 million USDC coins and 31,762 ETH coins on that scale. If we now have the honour of taking the aforementioned formula x*y=k into account, we can calculate the value of k. We calculate it as follows:

xy = 145.46 million (liquidity token 1) 31,762 (liquidity token 2) = k = 4.62 *10^12

Now, this might be too tricky an example to count with, so let's take an unrealistic situation where there are 50 USDC coins in the pool and 10 ETH coins. The k-value is now 50*10 = 500.

As mentioned before, this value should remain constant before and after a trade. So Pete is allowed to exchange 1 ETH against USDC, provided the k-value remains 500.

Pete puts his 1 ETH on the scale, leaving 11 ETH coins. To keep the scales in balance (keep the k-value constant) according to the formula, he now gets 4.55 USDC. Why?

The k value should remain 500, and we know that y is now equal to 11 (11 ETH coins). By solving the equation x * 11 = 500, we arrive at x = 45.45. That means that to balance the scales, 11 ETH should only be 45.45 USDC. The rest (50-45.45 = 4.55) goes to Pete.

In a liquidity pool, prices are thus determined by the liquidity in a pool and the constant k.

So liquidity has now changed to 11 ETH and 45.45 USDC. What happens if Pete wants to exchange 1 more ETH?

Now y is equal to 12 ETH coins and we want to keep the k value at 500 again, so what should the liquidity of x be? x * 12 = 500, solving the equation gives x = 41.66.

On the first trade, Pete got 4.55 USDC for 1 ETH, but on the second trade (45.45-41.66=3.79) he only gets 3.79 USDC for 1 ETH.

So you see that the formula xy=k** ensures that a price is established, which depends on the liquidity of both tokens in the pool.

That price can be different from, for example, the price on Binance, but in that case, the price will be quickly straightened because there is the possibility of arbitrage. This means taking advantage of price differences of the same good in two different places.

Now we know how such a liquidity pool works, but how does a decentralized exchange ensure that there is enough liquidity in such a pool so that people can always trade? If there is no ETH and USD in the pool, it is not possible to trade. The liquidity providers (LPs) take care of this.

What is a liquidity provider (LP)?

The coins in a liquidity pool are provided by the so-called liquidity providers (LPs), users who make their liquidity available so that others can trade against those coins. But why?

Platforms such as UniSwap and PancakeSwap incentivize users to provide liquidity through two types of incentives:

  • A trading fee is also paid with every trade made in a liquidity pool. A small part of these fees goes to the liquidity providers, so they get paid for providing liquidity.


  • Additional token rewards. For example, as an LP on PancakeSwap, you can stake your LP tokens (tokens that represent your liquidity in a pool) to earn PancakeSwap coin CAKE.

If you are going to provide liquidity, the two coins you place in the pool must have equal $dollar value, on most pools. There are some exceptions to this, but I'm not going to talk about that today.

So in short, for providing liquidity, you are rewarded with a small part of the transaction fees that other people in your pool paid for swapping their coins and will receive extra reward tokens. On the other hand, there is the risk of permanent loss.

Conclusion

The Automated Market Maker (AMM) has been one of the most genius yet relatively simple inventions in the rapidly evolving crypto industry. The idea of ​​a decentralized exchange, where people could trade cryptocurrencies from their wallets and without the intervention of a central authority, has been around for a long time. But it was still a search for the right execution.

The traditional order book was not a solution, because such an order book only works well if there is already high liquidity, with many buy and sell orders. With traditional order books, the decentralized exchanges could never beat central exchanges, but the AMM brought a solution.

The idea that LPs can "make" the market themselves through an AMM and earn from it turned out to be a great move because suddenly there was an actual incentive for people to go to the decentralized exchange instead of the central exchange. Apart from of course the fact that trading from your own wallet is already a huge incentive because we know the saying: Not your keys, not your crypto.

The Automated Market Maker also introduces new concepts such as liquidity pools and liquidity providers, which at first glance seem very complicated, so that some prefer to watch from the sidelines, but with the right knowledge, the AMM also provides new earning opportunities.

Many new crypto projects are even using an AMM to launch their project through an IDO. The new possibilities are endless, while the AMMs are also developing.

Nowadays, you already have UniSwap V3, an even more advanced version of the V2 AMM. Crypto is evolving at a breakneck pace.

Hopefully, after reading this article, you will know more about what an Automated Market Maker (AMM) is and how it works.


Posted Using LeoFinance Beta