# Automated Market Makers (AMMs) & more...

### Until Now,

The exchange markets worked on a trade execution model called "CLOB" or the **Central Limit Book Order**. This model is transparent but slow and requires a middleman. The middleman (in our case, the exchanges / derivative / equity markets) match the orders in real-time, which means that the buyer **Alice**, posts a buy order for the highest price she is willing to pay. The seller, **Bob**, posts the lowest price he will sell for. The moment these prices match, a transaction is executed.

### But,

When Decentralized Exchanges came in with the idea of efficiency, ease of use, and better capital efficiency - they brought with them the Automated Market Makers. What do these do? They remove any intermediaries and introduced liquidity pools and algorithms to balance the balance. Before moving forward let's understand what is a liquidity pool.

A **Liquidity Pool:**

is a digital pool where people lock up their cryptocurrencies, like tokens, to make trading easier. This pool acts like a market maker, allowing instant buying or selling without waiting for others. When you trade, the pool gives you tokens from its stash, and you give back other tokens. The pool's prices can change based on how much of each token is in it. Many people can use the same pool simultaneously, creating a busy trading environment. In return for putting tokens in, people get special tokens that represent their share of the pool - these tokens often allow you to participate in governance for that token/project. Liquidity pools help make cryptocurrency trading faster and more efficient.

## Okay, So how does an AMM really work?

We have already established the idea of a Liquidity Pool. An AMM is, in its most basic form - a formula:

X * Y = K

The main objective of an AMM is to ensure that the ratio of assets in the Liquidity Pool, remains balanced. This formula ensures that the product of token balances in a liquidity pool is constant, ensuring that their relative value remains stable as trades occur. When the pool is created, AMM calculates the constant `"k"`

.

Now every trade that follows, AMM ensures that this ratio `"k"`

is maintained throughout its lifetime. If a buyer, say Alice purchases an asset `"X"`

in exchange for the asset `"Y"`

, asset `"X"`

becomes more expensive - basic supply and demand. Alice buys `X`

, the volume of `X`

in the pool goes down which means that the given number of `Y`

tokens in the pool, now have to maintain the ratio with a lesser amount of `X`

thus increasing the price of `X`

.

For example:

Let's consider a pool of

`50 LINK`

tokens and`1000 USDC`

tokens. The constant formula`X * Y = k`

implies that`50 LINK * 1000 USDC = 50000`

.If a trader wishes to swap for

`10 LINK`

tokens, the formula will get rearranged to calculate the value of`"Y"`

from the initial formula, taking our`"k"`

to be constant, resulting in:

Y = (10 * 5000) / (50 - 10) = 5000 / 40 = 1250 USDC

Therefore, the price of

`10 LINK`

tokens will be`1250 USDC`

.Since such transactions flow both ways.

### Phew, that's all, right?

Well, not really. Apart from the CPMM variant already discussed, Decentralized Exchanges (or DEXes) have come up with variations of AMM(s) as follows:

**Constant Sum Market Maker (CSMM)**: In CSMM, the sum of token balances in the liquidity pool remains constant. This type of AMM aims to maintain the ratio between the two tokens while allowing the sum of their values to fluctuate.**Constant Mean Market Maker (CMMM)**: CMMM seeks to maintain a constant average price of the two tokens in the liquidity pool. As one token's price changes, the pool rebalances to keep the average price steady.**Advanced Hybrid Constant Function Market Maker (CFMM)**: CFMM combines features of different AMM models to optimize trading efficiency and minimize impermanent loss. It may use various mathematical functions to determine pricing and rebalancing.**Dynamic Automated Market Maker (DAMM)**: DAMM adjusts the pricing formula dynamically based on factors like market volatility, liquidity levels, and trading volume. This approach aims to provide better price accuracy during periods of high market activity.

There are some challenges to AMMs as well. One of them is "**Impermanent Loss**".

In very simple terms, Impermanent Loss refers to the price difference that a Liquidity Provider bears as compared to the scenario if he held the token (pair) individually rather than providing it as liquid.

Let's say we provide liquidity for a trading pair involving tokens `M`

and `S`

. For instance:

Token M: $100

Token S: 10 (Valued at $10 / each)

Considering initial value of token

`M`

to be $1 and token`S`

to be $10, the total value of the pool is $200.Now let's say the value of token

`S`

increases by $2 (making S to be valued at $12) on some other exchange, while`M`

remains at $1 and a trader, Bob, buys 2`S`

tokens from our pool at a lower price ($10) and sells it on the other exchange for a $2 profit.Now updated balance in our pool is:

Token M: $ (100+20) = $120

Token S: 8 (Eff. Value = 8 * 12 = $96)

Total Value = 120 + 96 = 216Here, the Liquidity Provider made a profit of (216 - 200) = $16

However, lets calculate the total value of the same if these were held outside of the Liquidity Pool.

Token M: $100

Token S: 10 ( 10 x 10 ) --> 10 ( 10 x 12 ) = $120

Total Value = 100 + 120 = $220So we can say that the Liquidity Provider suffered a loss of $4. This loss is termed as the "Impermanent Loss" and the reason it is Impermanent is because it can disappear if the prices revert.

### As of now,

Multiple protocols use AMMs, some of the popular ones are UNISWAP, SushiSwap, Balancer and Curve Finance.

**Uniswap**'s deployment of the Constant Product Market Maker introduced us to the concept, while SushiSwap extended its features, adding community-driven enhancements, introducing yield farming and liquidity mining.

**SushiSwap** revolutionized how users engaged with AMMs. It encouraged liquidity providers to participate actively by not only sharing trading fees but also distributing additional SUSHI tokens as rewards. The incorporation of community governance empowered SUSHI token holders to influence the platform's direction, creating a decentralized decision-making process.

**Balancer** offered novel multi-token pools, enabling greater customization, it allowed users to create and participate in customizable liquidity pools containing multiple tokens, as opposed to the conventional two-token pairs. This innovation provided increased flexibility for liquidity providers and traders, enabling them to fine-tune their exposure and optimize their strategies. Additionally, Balancer introduced a dynamic fee structure that allowed liquidity providers to set their own fees. Finally,

**Curve Finance** addressed stablecoin trading with specialized bonding curves. Curve specializes in providing extremely low-slippage trading for stablecoin pairs, making it particularly valuable for users seeking to swap stablecoins with minimal price impact. The protocol achieves this through specialized bonding curves tailored to stablecoin assets, effectively reducing impermanent loss and providing efficient price stability. Curve's unique design prioritizes liquidity provision for stablecoin pairs and has garnered significant adoption in yield farming and stablecoin trading strategies.

## Conclusion

These platforms showcase the versatility and innovation of AMMs, each catering to specific needs and preferences within the DeFi ecosystem. As the DeFi space continues to expand, the scope of AMMs promises to grow even broader, potentially spanning cross-chain compatibility, advanced trading strategies, and seamless integration with emerging technologies. The journey of AMMs is far from over, and as they shape the future of decentralized exchanges, we eagerly anticipate the next chapters in their evolution.