The Automated Market Maker or AMM, are one of the technological, economic and financial tools on which the technology that makes decentralized exchanges (DEX) and the DeFi ecosystem possible is based.
Un automated market maker (AMM) or automatic market creator, is a widely used protocol for creating decentralized exchange (DEX). This protocol It is generally based on a series of mathematical and economic formulations that seek to create a balanced medium that allows users to exchange cryptocurrencies safely., and thus avoid risky or counterproductive situations for transactions.
Unlike traditional exchanges, AMM-type DEXs are completely autonomous and their entire operation is algorithmic, as indicated in the smart contracts that make its operation possible. A good example of this type of DEX is Uniswap, which was one of the first to use the AMM model for trading on its platform.
Of course, MMAs are not exclusive to the world of cryptocurrencies. The first experiences with AMM come from the traditional financial market, where they have existed for several years. In any case, we will explain how AMMs work in the world of cryptocurrencies and we will provide you with information that will help you understand the evolution of AMMs and how they work.
How does an Automated Market Maker (AMM) work in the world of cryptocurrencies?
In general, an AMM type DEX does not differ from a traditional exchange. In other words, it is a space where cryptocurrencies can be exchanged and for this purpose a user interface and all the necessary tools to carry out these operations are offered. However, the similarities end there, since behind all this there is a completely different operating model.
First of all, most MMAs work, using a fairly simple formulation that is mathematically described as follows:
x * y = k
What does this all mean? Well, let's break down the meaning of each part of the formula:
- The x serves to indicate the amount of the first token of the pair (token A, in this case) that is in a liquidity pool.
- The y serves to indicate the amount of the second token of the pair (token B, in this case) that is in a liquidity pool.
- And finally the k, which serves to indicate the fixed constant that relates both tokens, and that will remain unchanged throughout the life of the liquidity pool.
This formula makes it clear to us that AMM-type DEXs follow the same trading pair presentation model as traditional exchanges. For example, we can trade a BTC/USDT pair on an AMM-type DEX exchange, thanks to the fact that there is a liquidity pool that has related amounts of BTC and USDT that follow and respect the formulation explained above. An example of a DEX that uses this type of formulation is Sushi Swap, Uniswap V2 (Uniswap V3, uses a different formulation), PancakeSwap and other derivatives.
Of course, AMM-type DEXs are not limited to the formula described above and, for example, Bancor uses a proprietary technique designed to be very similar to this, but which offers several unique advantages that are tailored to the needs of their platform. In a nutshell, DEX AMMs can use different formulations tailored to their needs, some more complex than others.
Liquidity pool, the engine of the AMM
Of course, the operation of the MMAs also falls on another actor: liquidity pools. These pools are nothing more than spaces controlled by smart contracts that allow liquidity providers to add pairs of tokens so that said liquidity can be used for exchanges and instead receive rewards for each change made.
For example, when you go to Uniswap and want to do a B2M/ETH trade, what happens is the following:
- You indicate the B2M amount to exchange for ETH.
- The Uniswap system offers you an exchange value using the formulation x * y = k, doing what is called “market making”.
- By accepting the trade value, Uniswap takes your B2M and places it in the pool (increasing the amount of B2M in the pool) and exchanges it for ETH which will be sent to your wallet (decreasing the amount of ETH in the pool), which maintains the balance of the formula x * y = k (remember that k is a constant).
- Fees are charged, part of which will go to Uniswap and part to liquidity providers (the users who added B2M/ETH to the pool so you could make your trade).
- With the ETH in your hands, the B2M in the pool can be taken by someone who wants to buy it in that space, maintaining the exchange dynamics.
As you can see, the role of liquidity pools is vital and, in fact, you can see part of this in our article on liquidity mining, a practice that is closely related to these pools and that you will surely love to learn about.
Rewards within MMA
WMA protocols often have various reward schemes, including compensation for liquidity, staking, and governance rights, in order to encourage participation and contribution to the protocol that implements them.
- Liquidity Reward: Liquidity Providers (LPs) are rewarded for supplying assets to the liquidity pool, as they have to bear the opportunity costs associated with funds locked in the pool. LPs receive their share of commissions paid by DEX users.
- Staking reward: In addition to the liquidity reward, LPs can stake within the platform in order to improve the position of their rewards on the platform. This seeks to promote the holding of LP tokens and revalue them.
- Governance Law: Another reward within the MMA is to allow governance decisions within the protocol, with which the LPs can make decisions about the development of the protocol in which they participate.
Implicit costs within the MMA
On the other hand, interacting with the Automated Market Maker (AMM) protocols carries various costs, including charges for some form of “value” created or “service” provided and fees for interacting with the blockchain network. Participants in the AMM must anticipate three types of commissions: the liquidity withdrawal penalty, the exchange fee and the network fee.
- Liquidity withdrawal penalty: This applies when the liquidity provider wishes to withdraw the liquidity that it has introduced to the protocol, which negatively affects the usability of the pool by raising the slippeage or sliding.
- exchange commission: Users who interact with the liquidity pool have to reimburse LPs for the supply of assets. This compensation comes in the form of trading fees that are collected on each trade and then distributed to all LPs.
- network commission: Each interaction with the protocol is executed as a transaction in the chain, and therefore is subject to the commissions applicable to the blockchain where they are executed.
Other MMA costs
Two other costs native to AMM-based DEXs are slippage for exchange users and divergence loss for LPs.
- Slippage: slipping or slippage It is defined as the difference between the spot price and the realized price of a trade. It has a close relationship with the spreads that we usually see in centralized exchanges.
- impermanent loss: For LPs, assets supplied to a protocol remain exposed to volatility risk, which comes into play in addition to the temporary loss of value of the locked funds. Thus, as the asset price moves back and forth, the depreciation in value of the pool disappears and reappears, only becoming real when the assets are withdrawn from the pool. This event is also known as a “divergence loss”.
Types of AMM formulations
Now, at first we explained that most of the Automated Market Maker (AMM) in the crypto world use the formula x * y = k, because it is simple and does its job tremendously well. However, there are other formulations both in the world of cryptocurrencies and the traditional one, which make the operation of AMMs possible and here we will explain some of them:
Constant Function Market Makers (CFMM)
This is a type of Automated Market Maker (AMM) widely used in traditional financial and cryptocurrency markets. CFMMs were designed based on a function that establishes a predefined set of prices based on the available quantities of two or more assets. Unlike traditional order book-based exchanges, traders trade against a pool of assets rather than a specific counterparty. The term "constant function" refers to the fact that any operation must change the reserves in such a way that the product of the reserves remains unchanged (ie, equal to a constant).
CFMMs typically have three participants:
- Merchants: They exchange one asset for another.
- Liquidity Providers (LP): They willingly accept trades against your portfolio in exchange for a commission.
- Arbitrators: They maintain the price of the assets within that portfolio according to the market price in exchange for a profit.
CFMMs are typically used for secondary market trading and tend to accurately reflect, as a result of arbitrage, the price of individual assets in the relevant markets. For example, if the CFMM price is lower than the reference market price, arbitrageurs will buy the asset on the CFMM and sell it on an exchange based on the order book to make a profit.
Constant Product Market Makers (CPMM)
CPMMs are the most widely seen type of AMM in the crypto world and, in fact, their origin is within this ecosystem since their first implementation was within Uniswap, and from these comes the famous formulation:
x * y = k
In this type of AMM, trading any amount of either asset must change reserves in such a way that, when the commission is zero, the product x * y remains equal to the constant k. However, keep in mind that since Uniswap charges a commission, each trade actually increases k, and a slippeage is generated within the formulation until no trades are possible until the balance in the pool is restored.
Constant Sum Market Makers (CSMM)
A constant-sum Automated Market Maker (AMM) is a relatively simple implementation of a constant-function AMM, satisfying the formula:
where Ri are the reserves of each asset and k is a constant. Although this feature produces “zero slippage”, it does not provide infinite liquidity and is therefore likely not suitable as a standalone implementation for a decentralized exchange use case. In practice, what would happen is that any arbitrageur would always drain one of the reserves if the relative reference price of the reserve tokens is not one.
Constant Mean Market Maker (CMMM)
A constant mean market maker is a generalization of a constant product market maker, allowing more than two assets and weightings outside of 50/50. First introduced by Balancer, constant-mean markets satisfy the following equation in the absence of commissions:
where Ri are the reserves of each asset, W are the weights of each asset and k is the constant. In other words, in the absence of fees, constant-mean markets ensure that the weighted geometric mean of reserves remains constant. A famous DEX AMM that uses this model is Balancer, which you can learn more about at this link.
Conclusions
AMMs are one of the fundamental constructions on which the DeFi ecosystem is based, which has been forming in recent years within the crypto ecosystem. The different protocols that currently exist that use this model have demonstrated not only their feasibility, but also their reliability as sustainable and practical economic models to achieve completely autonomous and secure finance systems.
Although, the AMM are a technology that can still be improved, and it is not uncommon to see how they adjust more and more realistically to the needs of the markets. A good example of this situation is Uniswap, whose AMM system has been adapting to the needs of its LPs and users.