AMM Automated market maker

AMM Automated market maker

INTRODUCTION:-

AMMs have gained significant popularity in the DeFi (Decentralized Finance) space, as they provide a decentralized and permissionless way to trade assets and earn fees by providing liquidity. However, it's important to note that AMMs come with their own set of risks, including impermanent loss and smart contract vulnerabilities, so users should exercise caution and perform due diligence when participating in AMM-based activities. In this article, I am going to open this AMM box and explain to you about it in simple wording. So, let deep dive into AMMs.

Trade-In Centralized World:-

Before understanding the AMM trade system let's first understand the centralized trading system from where the trade word is origin.

  1. What does this centralized word mean? Centralized means when a single entity controls the assets or something this is called a centralized system.
  • For example:- Whatever article I wrote in my hashnode account is stored inside the hashnode company database and they have all control over my channel means they can delete my channel or blogs from my account if they want to delete ( hashnode owner it's just for explaining the topic please don't delete my account ). I hope with this risky example you get the idea about a centralized system.

Let's move forward, In the centralized system there is a thing named the order book this is the main part of the centralized trade.

  1. What this order book is? order book stores the price and quantity that you and the other trader are ready to buy something as well as it stores the price and quantity of the seller that at this price I will ready to sell this much of quantity of this thing.

Let's take an example of the share market to understand this topic more clearly.

Let's You decide to buy a share of a particular company named " Depth " ( there is no company with this name in the real world ). Let's say the current share price is '$100' and there is already a person who has '2000' shares of this company and another person who has '1000' shares of quantity of this same company. Let's imagine you want to buy '500' shares of quantity of this company at the price of '$100'.

So this order you placed is stored in the order book like the above image example. Now the sellers have started putting their orders to sell the shares. Person 1 places the order of selling '1000' quantity of share at the price of '$110' and person 2 places the order of selling '500' quantity of share at the price of '$100'. Now this order is also placed in the order book.

As we can see your buy order is matching with the person 2 selling order. So, this order is executed and you get a '500' quantity of shares and you need to pay '500\100 = 50000$'* to the seller.

This is how trading happens in a centralized world but if we use this centralized order book in our decentralized exchanges our exchange depends on a centralized system or if we try to create an order book on blockchain and write every order on blockchain but if we do this cost so much gas fee and the exchange is going to bankrupt in paying this fee of every transaction. So, to solve this problem AMMs are created. Now let's move to our main topic.

What are the AMMs?

AMMs stand for "Automated Market Maker."

In the DeFi space there is concept liquidity ( I already explained it Click Here to read ) that contain two pair of coin or token inside the pool with an equal ratio of 50:50. If a trader wants to trade inside this pool then the question i occur that if a trader puts x amount of token A then how much amount of token B will trader get. This is calculated by the mathematical formula that the AMM has.

With the help of AMMs, we can able to achieve this thing without using the order book in the DeFi space.

To understand the AMM let's take an example of the Liquidity pool that contains two tokens named "USDT" and "DAI" in a 50:50 ratio. For example purpose '100' quantity of 'USDT' and '100' quantity of 'DAI' provided by the 'Tom'. Now 'Alice' wants to trade in this pool he wants to put a '10' quantity of "USDT" inside the pool. Now AMM needs to find how much quantity of 'DAI' Alice will get.

First, use a constant variable that holds the multiplication product of this token "50 \ 50 = 2500".* 2500 is the constant quantity that AMM needs to maintain inside the pool when any trade happens. Now using this constant AMM can get the quantity that needs to be paid back to Alice let's see how AMM calculated this.

After Alice adds his token the quantity of 'USDT' becomes from 50 to 60. Now if we multiply the two token quantities the the product we get is "60 * 50 = 3000". But as we all know constant is constant means if one value is assigned to it than we can't change the value and here 2500 does not equal 3000 to get 2500 we need to subtract the value of the 'DAI' token but how much we can by using this formula "DAI = constant/USDT" means 'DAI = 2500/60" then we get '41.6666666667' after round up it becomes '41.6'. This means 41.6 quantity needs to stay in the pool and the remaining quantity will transfer to Alice '50-41.6 = 8.4'.

Now if we do the calculation for constant '60 * 41.6 = 2500'. Now you are thinking that we put 10 quantities but get 8.4 why? It is because if any of one token or coin amount is increased it becomes cheap and the other is less in amount so it is costly means if you pay high you will get a lower amount of token or coin.

In our case, the value of "USDT" becomes 60 and the "DAI" is only 50 concerning token A. Let's explain to you with a trade example I am going to put 'DAI' and see using the above formula how much amount I will get of 'USDT'.

Let's assume I am going to put 8.4 DAI if the pool then the value of DAI increases and it becomes 50. Now find the amount of USDT I will get ' USDT = 2500/50 ' it returns me 50 means this much amount of USDT needs to stay in the pool and the rest remaining will transfer to me.

Let's calculate ' current value - result value = value I get ' means ' 60 - 50 = 10 '. 10 is the amount I will receive. It's simply supply and demand if something more in supply but the demand is decreases and those in less supply are more in demand for example 'Gold'.

Types of AMMs:-

Automated Market Makers (AMMs) come in various types, each designed to address specific needs and trading scenarios in the decentralized finance (DeFi) space. Here are some of the most common types of AMMs:

  1. Constant Product AMM (e.g., Uniswap): This is one of the most popular types of AMMs. It maintains a constant product of the quantities of two assets (e.g., ETH and DAI) in a liquidity pool. The product of the reserve balances remains constant, and this determines the exchange rate between the two assets.

  2. Constant Sum AMM (e.g., Balancer): Unlike constant product AMMs, constant sum AMMs like Balancer allow multiple tokens to be part of a single pool. They maintain a constant sum of the total value in the pool, which means that the more one token is added, the less of the other tokens are available.

  3. Curve AMM (e.g., Curve Finance): Curve AMMs are designed to provide low-slippage and stablecoin-to-stablecoin trading. They focus on maintaining a stable ratio between stablecoins, which is particularly useful for stablecoin swaps with minimal price impact.

  4. Weighted AMM (e.g., Kyber Network): In weighted AMMs, liquidity providers can assign different weights to each asset in a pool. This allows for more control over the pool's dynamics. The pricing and exchange rates are determined by these weights.

  5. Liquidity-Sensitive AMM (e.g., Bancor): These AMMs adjust the pricing algorithm based on the pool's current liquidity. When liquidity is low, it's designed to provide more price protection against large trades.

  6. Derivative-Based AMM (e.g., Hegic, Saddle Finance): Some AMMs specialize in derivative trading, where users can mint or trade synthetic assets. These AMMs use more complex mechanisms to maintain the pegging of synthetic assets to their underlying collateral.

  7. Volatility AMM (e.g., vAMM): These are AMMs optimized for trading volatile assets. They adjust their pricing algorithms to account for the anticipated volatility of assets.

  8. Interest Rate AMM (e.g., Yield): Yield AMMs aim to provide stable and predictable interest rates for lending and borrowing by maintaining the balance between lending and borrowing liquidity.

  9. Liquidity Concentration AMM (e.g., Concentrated Liquidity): These AMMs allow liquidity providers to concentrate their funds in specific price ranges to capture higher fees and provide better liquidity within that range.

  10. Liquidity-Weighted AMM (e.g., Perpetual Protocol): AMMs like Perpetual Protocol use liquidity weighting to determine prices. Traders are incentivized to provide liquidity near the index price, reducing slippage.

Different AMM types offer distinct advantages and cater to various use cases within the DeFi ecosystem. The choice of AMM type depends on factors such as the assets being traded, liquidity preferences, and the specific DeFi platform or protocol you are using. It's essential to understand the characteristics of different AMMs to choose the right one for your needs.

Summary:-

This article introduces Automated Market Makers (AMMs) in the context of DeFi (Decentralized Finance). It explains the concept of AMM as a decentralized and permissionless way to trade assets and earn fees by providing liquidity. The article delves into the limitations of centralized trading systems and order books, highlighting the need for a more efficient solution, which led to the development of AMMs.

The article goes on to define AMMs as "Automated Market Makers" and describes how they function in DeFi liquidity pools, where two different tokens are paired in a 50:50 ratio. It illustrates how AMMs calculate the quantities to be exchanged without relying on traditional order books, making them ideal for decentralized exchanges.

The concept of a constant variable to maintain balance in the pool is explained, along with a step-by-step example of how AMMs determine the quantities to be exchanged. The article emphasizes that changes in token quantities affect the cost and amount received, based on supply and demand dynamics.

The article serves as an accessible introduction to AMMs, making complex DeFi concepts more understandable for readers. It highlights the advantages of AMMs in DeFi trading, paving the way for a deeper understanding of blockchain and decentralized finance.