Main
An Automated Market Maker (AMM) is a software algorithm for controlling the liquidity and pricing of cryptoassets on decentralized exchanges.
AMM systems are widely used in the DeFi industry, in particular on decentralized exchanges (DEX) such as including Uniswap, Balancer, Bancor and Curve.
To create decentralized markets, AMM uses liquidity in cryptocurrency public pools of multiple tokens locked in special smart contracts.
How did the automatic market maker (AMM) come about?
Automated Market Maker (AMM) is an autonomous trading mechanism on which most DeFi trading protocols operate. It provides capital movement and execution of users’ exchange transactions in the available crypto-asset markets.
The first prominent developer to talk about implementing AMM was Alan Liu, a member of the Gnosis project team. His ideas were outlined by Ethereum founder Vitalik Buterin on Reddit in 2016 and in his personal blog in July 2017.
This concept formed the basis of the Uniswap platform protocol, which received its first $100,000 grant from the Ethereum Foundation. In addition, Vitalik Buterin advised the developers of Uniswap.
Subsequently, AMM became widely known precisely because of Uniswap. At the same time, one of the first successful implementations of AMM is the Bancor Network platform, which raised $140 million through an ICO in June 2017.
How are liquidity pools related to AMM?
The key element necessary for AMM to work is a liquidity pool – a kind of storage of crypto-assets in the form of a smart contract. A liquidity pool usually consists of two crypto-assets and forms a market, analogous to a trading pair on a centralized exchange.
Some pool participants lock in their funds to generate income through exchange fees. Such users are called liquidity providers.
The other category is the direct users of the decentralized exchange, who exchange cryptocurrencies in the protocol (such operations are called “swaps”), using some of the pools.
To better understand liquidity pools, consider what led to their creation.
The first DEX exchanges ran on Ethereum and used the standard order book used on centralized exchanges for trading. For such a trading mechanism to be effective, it must have extremely high transaction processing speeds. Given that transactions on a decentralized exchange are confirmed via a blockchain, the actual speed and capabilities of such DEX were extremely limited. AMM made it possible to find a solution to this problem.
Thus, AMM is a fundamentally different way of creating an asset market, being a formula or rules by which the protocol works with bids to buy or sell, as well as with users’ reserves.
How do liquidity pools work?
Pools can use two or more assets. For example, on the Uniswap exchange you can create pools for paired tokens. The Balancer platform allows you to create pools for three or more tokens. And the Curve protocol is designed for pools based on assets with a similar value, such as ETH and wrapped token WETH or USDC and DAI. The operation of these pools is governed by AMMs.
Each of these AMM-DEXs can use their own formulas and rules to interact with liquidity pools. For example, the Uniswap protocol uses the following formula: x * y = k.
In the equation, x and y represent the number of tokens available in the liquidity pool; k is a constant, called an invariant. In the case of Curve, the formulas x * y = k and x + y = k are used.
SushiSwap and PancakeSwap projects also work according to the formula x * y = k, which is the most common type of AMM-DEX.
How does the pricing of an asset in a liquidity pool work?
When liquidity in a pool is blocked, its provider receives special LP-tokens that confirm their share in the pool. They can be represented as a promissory note, ownership of which entitles you to receive commissions from exchange transactions on the exchange and return your share from the pool.
LP-tokens are transferable crypto-assets that can be sold or exchanged on the open market, as well as invested in third-party DeFi applications.
The process of exchanging one asset for another through a liquidity pool is called a swap. The essence of the process is to add to the pool only one asset, instead of two, as in the case of LP. For swaps, the pool charges a small fee, comparable to the fee for a deal at a centralized exchange, which is 0.1-0.3%. The commissions are distributed among liquidity providers in proportion to their share in the pool.
Example
Let’s create a conditional pool of liquidity for the pair ETH/USDC. At the price of 1 ETH equal to 2000 USDC, we’ll need to block any amount of those two coins at a ratio of 1:2000 in a smart contract at the same time. At that price, there could be 100 ETH and 200,000 USDC in the pool.
The balance of assets in the pool is determined by their price. When a user decides to exchange 10 ETH using the pool described above, he will put his coins into a smart contract in a regular transaction. In exchange for his 10 ETH he will receive 20,000 USDC (not including exchange fees).
After that exchange, the pool balance will already be 110 ETH and 180,000 USDC. Consequently, the price of ETH in this particular pool will be about 1636 USDC instead of 2000 USDC on other markets. This situation attracts arbitrage traders, who take advantage of the imbalance by adding USDC to the pool until the price reaches the market 2,000 USDC per ETH.
What are the disadvantages of AMM?
While AMM has been a breakthrough for trading and DeFi, it has a number of glaring disadvantages. First, there is a high risk of price slippage when making swaps with AMM. In turn, this leads to risks of volatile losses for LPs and Miner Extracted Value (MEV) for regular users.
Other types of AMMs are created to protect against such risks, such as the CowSwap project, which combines the development of AMM-Balancer and the Gnosis protocol.
Secondly, unlike centralized exchanges, you can place only one type of order when trading via AMM. You cannot trade limit orders or other types, such as Stop Loss.
What is an Impermanent Loss?
An Impermanent Loss (IL) is a temporary or unrealized loss when holding assets in the liquidity pool using AMM-DEX. ILs refer to liquidity providers (LPs), referring to the difference in price at the time the tokens are locked into the pool and the actual price at the time of the hold. Losses are called unrealized because they are not fixed until liquidity is withdrawn from the pool.
As an example, let’s take a liquidity pool on the Uniswap exchange that works according to the classic formula x * y = k:
- A liquidity provider has blocked 1 ETH and 2,000 DAI. His share in the pool is 10%.
- The pool has a total of 10 ETH and 20,000 DAI – the equivalent of 40,000 DAI.
- The balance of the pool did not change, as there were no new liquidity providers.
- Let’s assume that the market price of ETH changed to 4,000 DAI.
- Then arbitrage traders took advantage of the situation and changed the ratio in the pool to 5 ETH on one side, and 20,000 DAI on the other. At the same time, the total size of the pool remained the original 40,000 DAI.
- At this point, the liquidity provider decided to withdraw his share of the pool – it is 10%.
- Given the current pool balance, he withdraws 0.5 ETH and 2,000 DAI, although he originally added 1 ETH and 2,000 DAI.
- The original value of his share was 4,000 DAI (1 ETH plus 2,000 DAI) in terms of stabelcoins. The value of the assets at the time of withdrawal was the same 4000 DAI (0.5 ETH plus 2000 DAI)
- However, if the user had simply kept his 1 ETH and 2000 DAI, the value of his assets would have been 6000 DAI. This is the unrealized loss or gain when using AMM-DEX.
- The user would also receive 10% (in proportion to his share of the pool) of all pool commissions as a liquidity reward. The reward can be reduced, for example, because of taxes paid to developers or to the project’s treasury for future development.
This is a conditional example of a sharp increase in the price of one asset by 50%, without taking into account the many trades of arbitrage traders and the time it takes to equalize the price
the price of the asset within the pool with the price on centralized exchanges, where changes occur instantly.
When the market is “calm”, variable movements are added to the calculation of volatile losses, as described by StarkNet developer Peteris Erins in his blog. As a result of these forecast calculations, the Impermanent Loss value on a two-fold movement of the asset price will be about 5.7%. But this is only a forecasted value – potential “losses” are very difficult to predict.
How to reduce risks when trading with AMM?
Before you use the liquidity pool, you should calculate all the possible commissions you will have to pay at the time of deposit and the planned withdrawal of assets.
You need to consider the possibility of asset price movements in both directions. Some potential problems, such as non-permanent loss (IL) risk, can be calculated in advance.
To calculate IL, you need to understand the nature of its origin. You can also use one of the non-permanent loss calculators available on the Internet.