Automated Market Maker: What Is AMM?

Automated Market Maker: What Is AMM?

The DeFi technology, likely to have the most significant impact in the next few decades, has arrived and is thriving. With a current market capitalization of $139.9 billion and a total value locked of $75.39 billion, decentralized finance is rising faster than any other sector in the cryptocurrency space.

As of April 2022, DeFi has increased by over 7x since January 2020, according to DeFi Pulse. These numbers are insane!

To say that blockchain technology has transformed financial services would be an absolute understatement. DeFi is revolutionizing the entire financial system by replacing a centralized form of financial services with smart contracts, self-executing computer programs - agreements between buyers and sellers.

It serves as the gateway between the digital blockchain space and human society. More specifically, it provides the general people with access to various financial products that were previously unavailable to them, simultaneously eliminating the need for a centralized financial intermediary.

The most essential part of the decentralized finance ecosystem is the automated market maker (AMM) - a fundamental protocol utilized by DEXs to allow anonymous transactions on the blockchain.

In this article, we’ll answer your questions like, what is AMM in crypto and find out where market making takes place, how it works, and why it’s needed.

Without waiting any longer, let’s dive right into it.

What Is an AMM?

AMM is an automated market maker, a system that provides liquidity and prices assets in an automated way.

An automated market maker crypto algorithm is an engine that powers decentralized exchanges and allows them to operate permissionless and anonymously. For the first time in world history, everyday people and global enterprises can manage their assets themselves without relying on a centralized institution but using smart contracts instead.

DEX_CEX_trading

How does it work?

  • Smart contracts are a collection of computer code and data that run on a blockchain and execute automatically when all predetermined conditions are met.
  • AMM pools with built-in smart contracts operate exclusively on DEXs.
  • Users then create liquidity pools, provide liquidity to tokens within the pool, and execute trades cheaply and quickly.

AMMs, crypto DEXs, and DeFi overall fit the world's finances naturally - they preserve the fundamental principle of blockchain: decentralization and anonymity. Moreover, they are utilizing the best of it to solve the most pressing problems of concern to humankind.

What is DeFi Liquidity?

Let's define liquidity to better understand what an automated market maker is, and how it works.

Liquidity indicates how easy it is to exchange one asset for another. For example, Bitcoin and Ethereum are two of the most liquid assets in today's cryptocurrency space since they are recognized and traded across all exchanges. BTC tokens, more specifically, are traditionally a classic in the crypto space. At the same time, ETH is inherently another system (altcoin) with a lot of functionality and features, which underlies many decentralized exchanges and other DeFi platforms.

Besides the asset's overall liquidity, the exchange's liquidity must also be considered. Even the BTC/USDT pair may be illiquid on a newly launched crypto exchange. Therefore, token projects require market makers' services to make their token markets liquid, and the same goes for DEXs and CEXs. When trading on a liquid crypto exchange, users can buy or sell cryptocurrencies way more efficiently since the orders get filled more quickly and with less influence on an asset's price due to the more significant number of market participants.

What determines liquidity in cryptocurrency DEX? Unlike the centralized exchanges that use an order book model, DEXs are solely built upon liquidity pools. The most significant factors showcasing the level of liquidity on the decentralized exchange are the number of tokens in the liquidity pool and slippage.

Indicators_of_liquidity_on_DEX
  • Suppose there are a lot of tokens available in the pool. In that case, it is way more difficult to influence their price, even with large orders, because the ratio between the transaction size and assets inside the liquidity pool will be insignificant.
  • Price slippage is when the trade gets executed at a different price than intended. Crypto slippage occurs when the bid/ask spread changes when the market order is confirmed. It’s mainly a consequence of the low liquidity.

Since there are no limits on who can contribute to the liquidity pool, the price of the assets inside can easily be manipulated by one or several market players. If the pool contains only 100 ETH and 200 BNB, every trader willing to exchange more than 10 ETH or 20 BNB can drastically influence the assets' prices.

Suppose the initial price of the tokens within the pool diverges from the current global market price. In that case, it creates an instant arbitrage opportunity that can result in lost capital for the liquidity provider. High slippages and the lack of liquidity on a cryptocurrency exchange are serious red flags for traders and startup projects, discouraging them from using a trading platform and depositing their funds there.

How Does AMM Work: The Role of Liquidity Pool and LPs

Even though the need for a counterparty is eliminated, AMMs still require someone to make the market liquid. Regular users called cryptocurrency liquidity providers (LPs) provide liquidity in smart contracts.

Besides retail crypto investors, which are a significant part of LPs, traditional market makers may also fund liquidity pools on new decentralized exchanges. For example, large quant traders and crypto trading firms, such as Alameda Research, provide foundational liquidity and control the market on the DEXs daily.

LPs deposit their funds into liquidity pools and profit from fees on trades conducted via the platform according to their share of the provided liquidity. To give you an idea, if you contribute $20 worth of assets to a liquidity pool worth $100, you will receive 20% of that pool's LP tokens. You receive 20% of the LP tokens because you own 20% of the crypto liquidity pool. And that’s how an AMM works in a nutshell.

What Is a Liquidity Pool?

  • A liquidity pool is a pool of funds invested by LPs locked in a smart contract. A smart contract regulates the price of assets within the pool using mathematical formulas.
  • Liquidity pools exist only on decentralized exchanges and require no other intermediaries to proceed with a transaction rather than a robotic algorithm.

Let’s consider some examples.

Uniswap is not the first exchange employing the concept of liquidity pools yet, it’s the most popular. Automated market making implies a price to be discovered according to a specific mathematical formula. In the case of Uniswap DEX, it is a constant product automated market making formula:

Uniswap_AMM_Formula

X and Y are variables, the quantities of tokens;

K is a constant, which means it always stays the same and doesn’t change;

The constant product formula is not universally applicable. Crypto liquidity pools across different protocols utilize slightly different algorithms. The Balancer protocol, in contrast, can integrate up to 8 various digital assets in 1 liquidity pool.

The Balancer Pool AMM is defined by a function of the pool’s balances and weights, constraining V to a constant (‘Invariant V’).‌

Balancer_AMM_Formula

Based on this value function, Balancer enables users to establish pools with up to 8 digital assets and user-defined weights. Below are some of Balancer’s liquidity pools.

Balancer_liquidity_pools

The first exchange for removing order books entirely and replacing them with AMMs was Bancor. In 2017, the Bancor exchange introduced the concept of liquidity pools that served as a background for DeFi to develop.

The second major version of the Bancor Protocol, Bancor v2.1, offers two novel solutions that directly address the issues of the first-generation AMMs. Single-sided liquidity and impermanent loss protection are features that are meant to incentivize the widespread adoption of automated market makers and solve the problems standing in the way of their efficient performance.

Bancor liquidity protocol is integrated on 1inch.exchange, Zerion, and xNation.

How Do Liquidity Pools Work? Detailed Explanation With Examples

We will break down the mechanism of liquidity pools that work per the constant product formula: X*Y=K.

When the trade starts, one of the assets in the liquidity pool becomes more valuable as more and more people exchange it for another asset. The value of 2 assets within the liquidity pool must be set in 50:50 proportion. It is better to illustrate this process with a particular example.

Let’s say there is a pool of liquidity containing 200 Ethereum tokens and 200 BNBs, the native tokens of the Binance exchange. According to the constant product automated market maker formula, X*Y=K, the constant “K” must be 40,000. Some random trader comes by our DEX and decides to provide 50 ETH tokens in exchange for BNB tokens. For 50 ETH invested in the pool, he will get only 40 BNB tokens. But where are the other 10 BNBs?

The thing is, to maintain the constant value of 40,000, there should be 160 BNBs in the pool so that when the remaining BNBs and additional ETH tokens multiply, they still give 40,000.
When a trader mentioned above invested 50 ETH in the liquidity pool, the total number of ETH tokens were 250. So, if X is our ETH tokens and Y is BNBs, to find out how many of the second ones must remain in the liquidity pool, we have to divide constant K by the number of ETH: 40,000/250=160. 160 BNB tokens will stay in the pool, while the 40 BNB tokens will be transferred to the investor’s wallet. This only works if we imagine the price of 1 ETH and 1 BNB is the same. But in reality, they are not.

Let’s look at an example of how does liquidity pool work with real-time assets’ prices.

The more assets in the liquidity pool, the less they will cost. When it comes to pricing, the algorithm always wants the value of what it is holding to be 50:50. Let’s take 100 ETH and calculate their total value. At the time of writing the price of 1 ETH token is $3,043, so 100 of them are worth $304,300. Keeping in mind that the value of another cryptocurrency in the liquidity pool must also be $304,300, we do a little math and come up with around 719,4 BNBs at its current price of $423. Let’s check if the 50:50 condition was met. 719,4*$423=$304,300.

work_of_liquidity_pool

The investor comes along and deposits 20 ETH in exchange for 119,9 BNB. So, there are now 120 ETH tokens and 599,5 BNB tokens. The initial price of 1 ETH was $3,043, but after the trade it is set at $304,300/120 = $2,536 (nearly). For 1 BNB, which initial value was $423, the price after the trade will be $304,300/599,5=$508 (also nearly). The price of BNB will exponentially keep going up as the investors buy more of it.

An automated market maker conducts all the calculations we did earlier for you.

When it comes to pricing, the algorithm always wants the value of what it holds to be 50:50. Unswap liquidity pools are built on algorithms that control an equal proportion of assets within the pool. However, not all AMMs work by this rule. Balancer Protocol allows unequal currency pair weights, for example, 80/20 liquidity pool split.

Impermanent Loss Explained

What is impermanent loss? Impermanent loss is a temporary loss of value that you experience when the two tokens you invested in the liquidity pool change in value relative to each other. The loss of deposited funds is called impermanent because it only becomes permanent whenever you cash out your liquidity. Until then, there is still an opportunity for the loss to get back to its normal state.

To calculate impermanent loss, you need to calculate how much money he would have had if he didn't invest in the liquidity pool and just held his stablecoin and ethereum in his wallet instead so

Impermanent loss is calculated by finding the difference between the number of assets you would have had if you didn't invest in the liquidity pool and just held your tokens (ETH and BNB in our case) in the wallet instead.

It is essential to understand that impermanent loss happens no matter which direction the price changes. It's suitable for any liquidity provider when two assets you invest in stay roughly the same price. When one goes up and the other stays the same the liquidity provider starts to experience impermanent loss and can only recover if the first asset starts to come down to equal out the liquidity. However, when both asset prices increase at the same rate or decrease at the same rate, the liquidity provider may not lose money due to impermanent loss and may just reap the rewards of the profits from the trading fees.

impermanent_loss

How much exactly does the price of the assets affect impermanent loss? The estimated numbers are plotted on the impermanent loss chart below.

impermanent_loss_curve

The impermanent loss curve tells us that when the price of a token grows by 500%, the liquidity provider will suffer an impermanent loss of around 25%. LP will face a 25% loss compared to HODLing.

Is there a chance that crypto impermanent loss won't affect your profit from liquidity providing? Sometimes the earnings generated from providing liquidity can cover the losses. Even though the pool is exposed to impermanent loss, it still can be profitable thanks to reward fees.
Impermanent loss only happens to people that contributed assets to the liquidity pool.

To mitigate the risks of facing an impermanent loss, one can consider investing in the pools with stablecoin pairs because, by nature, they are less volatile.

Liquidity Provider (LP) Token Reward System

Liquidity providers earn LP tokens in proportion to how much liquidity they supplied to the pool.

By depositing tokens in the liquidity pool, you allow traders to trade back and forth using your tokens as liquidity in exchange for a small trading fee that they will pay for every transaction. In most cases, there is way more than 1 person investing in the liquidity pool, so the fees will be split among all the investors evenly, based on the portion of funds they contributed.

LP_Token_Reward_System

LP crypto tokens are tokens created by decentralized exchanges that are distributed to the liquidity providers following the size of their contribution to the liquidity pool and proof of their right to get X share of trading fees generated.

In addition, the holders of crypto LP tokens can stake them and get rewarded on top of the fees they receive for every transaction within the liquidity pool.

When the liquidity providers want to withdraw their underlying investments, all the liquidity tokens they hold will be immediately burned.

AMM vs Order Book

When comparing order book vs AMM, traditional stock exchanges and centralized cryptocurrency exchanges use the order book model to express the Demand and Supply and let them form an asset’s price. The main goal of the buyer (bidder) is to buy an asset for the lowest price possible, while sellers (askers) try to sell an asset as high as possible. For a transaction to happen buyer and seller have to find a mutually acceptable compromise solution, which implies either a buyer bidding higher or a seller lowering the price.

Order book relies heavily on market makers that are always willing to close an order to facilitate trading. Without a market maker, exchanges face liquidity issues and are not attractive and accessible for regular traders. Traditionally, CEXs have higher trading volume and liquidity in contrast to decentralized exchanges. But only big players (trading firms or hedge-funds) can be a true market maker there.

AMMs operate solely within liquidity pools on DEXs. The price of assets inside the pool is quoted by a robotic algorithm, which ensures transactions execute without any counterparty. Liquidity providers of different sizes (retail users and trading firms) play the role of market makers by depositing tokens inside the pool and earning rewards for these actions. AMMs were built to solve the problem of illiquid markets on decentralized exchanges. However, it brought a few additional issues, such as high slippage and impermanent loss.

Conclusion: The Role of DeFi Market Makers on AMMs

No doubt, AMMs have become one of our most disruptive and revolutionary technologies. But unfortunately, they are not flawless; liquidity providers still experience such liquidity pool risks as impermanent loss, high slippage, and involuntary token exposure.

Managing efficient work of liquidity pools is becoming a new and important service delivered by DeFi market makers. BitQuant is utilizing its trading expertise and technology to secure your DEX from arbitrage opportunities and the rug of the pool. In addition, we are balancing the liquidity pools and ensuring the prices do not diverge from external crypto exchanges.

Apart from assisting AMMs in their efficient and stable performance, we are also helping tokens to list on them by providing much-needed liquidity and attracting investors.

Our experience in market making for CEX and highly deployable algorithms allow us to embrace the world of DeFi and bring the best solutions for our partners.

Reach out to us and we will craft the best fitting market making for your DEX, CEX or token.




Recent posts:

Crypto Liquidity Provider: How to Find and Choose the Best One?
Our article will provide a full rundown of crypto liquidity providers and cover how to choose the best crypto liquidity provider to aid your technology and c...