When Uniswap launched in 2018, it became the first decentralized platform to successfully utilize an automated market maker system.
An automated market maker (AMM) is the underlying protocol that powers all decentralized exchanges (DEXs). Simply put, they are autonomous trading mechanisms that eliminate the need for centralized exchanges and related market-making techniques. In this guide, we will explore how automated market makers work.
But first, let us take a look at what are market makers.
What is a market maker?
Related: A Beginner’s Guide to Atomic Swaps
A centralized exchange oversees the operations of traders and provides an automated system that ensures trading orders are matched accordingly. In other words, when Trader A decides to buy 1 BTC at $34,000, the exchange ensures that it finds a Trader B that is willing to sell 1 BTC at Trader A’s preferred exchange rate. As such, the centralized exchange is more or less the middleman between Trader A and Trader B. Its job is to make the process as seamless as possible and match users’ buy and sell orders in record time.
So, what happens if the exchange cannot find suitable matches for buy and sell orders instantaneously?
In such a scenario, we say that the liquidity of the assets in question is low.
Liquidity, in terms of trading, refers to how easily an asset can be bought and sold. High liquidity suggests the market is active and there are lots of traders buying and selling a particular asset. Conversely, low liquidity means there is less activity and it is harder to buy and sell an asset.
When liquidity is low, slippages tend to occur. In other words, the price of an asset at the point of executing a trade shifts considerably before the trade is completed. This often occurs in volatile terrains like the crypto market. Hence, exchanges must ensure that transactions are executed instantaneously to reduce price slippages.
Related: ¿Qué es un token cripto semifungible?
To achieve a fluid trading system, centralized exchanges rely on professional traders or financial institutions to provide liquidity for trading pairs. These entities create multiple bid-ask orders to match the orders of retail traders. With this, the exchange can ensure that counterparties are always available for all trades. In this system, the liquidity providers take up the role of market makers. In other words, market-making embodies the processes required to provide liquidity for trading pairs.
What is an automated market maker?
Unlike centralized exchanges, DEXs look to eradicate all intermediate processes involved in crypto trading. They do not support order matching systems or custodial infrastructures (where the exchange holds all the wallet private keys.) As such, DEXs promote autonomy such that users can initiate trades directly from non-custodial wallets (wallets where the individual controls the private key.)
Also, DEXs replace order matching systems and order books with autonomous protocols called AMMs. These protocols use smart contracts – self-executing computer programs – to define the price of digital assets and provide liquidity. Here, the protocol pools liquidity into smart contracts. In essence, users are not technically trading against counterparties – instead, they are trading against the liquidity locked inside smart contracts. These smart contracts are often called liquidity pools.
Notably, only high-net-worth individuals or companies can assume the role of a liquidity provider in traditional exchanges. As for AMMs, any entity can become liquidity providers as long as it meets the requirements hardcoded into the smart contract. Examples of AMMs include Uniswap, Balancer and Curve.
How do AMMs work?
There are two important things to know first about AMMs:
Trading pairs you would normally find on a centralized exchange exist as individual “liquidity pools” in AMMs. For example, if you wanted to trade ether for tether, you would need to find an ETH/USDT liquidity pool.
Instead of using dedicated market makers, anyone can provide liquidity to these pools by depositing both assets represented in the pool. For example, if you wanted to become a liquidity provider for an ETH/USDT pool, you’d need to deposit a certain predetermined ratio of ETH and USDT.
To make sure the ratio of assets in liquidity pools remains as balanced as possible and to eliminate discrepancies in the pricing of pooled assets, AMMs use preset mathematical equations. For example, Uniswap and many other DeFi exchange protocols use a simple x*y=k equation to set the mathematical relationship between the particular assets held in the liquidity pools.
Here, x represents the value of Asset A, y denotes the value of Asset B, while k is a constant.
In essence, the liquidity pools of Uniswap always maintain a state whereby the multiplication of the price of Asset A and the price of B always equals the same number.
To understand how this works, let us use an ETH/USDT liquidity pool as a case study. When ETH is purchased by traders, they add USDT to the pool and remove ETH from it. This causes the amount of ETH in the pool to fall, which, in turn, causes the price of ETH to increase in order to fulfill the balancing effect of x*y=k. In contrast, because more USDT has been added to the pool, the price of USDT decreases. When USDT is purchased, the reverse is the case – the price of ETH falls in the pool while the price of USDT rises.
When large orders are placed in AMMs and a sizable amount of a token is removed or added to a pool, it can cause notable discrepancies to appear between the asset’s price in the pool and its market price (the price it’s trading at across multiple centralized exchanges.) For example, the market price of ETH might be $3,000 but in a pool, it might be $2,850 because someone added a lot of ETH to a pool in order to remove another token.
This means ETH would be trading at a discount in the pool, creating an arbitrage opportunity. Arbitrage trading is the strategy of finding differences between the price of an asset on multiple exchanges, buying it on the platform where it’s slightly cheaper and selling it on the platform where it’s slightly higher.
For AMMs, arbitrage traders are financially incentivized to find assets that are trading at discounts in liquidity pools and buy them up until the asset’s price returns in line with its market price.
For instance, if the price of ETH in a liquidity pool is down, compared to its exchange rate on other markets, arbitrage traders can take advantage by buying the ETH in the pool at a lower rate and selling it at a higher price on external exchanges. With each trade, the price of the pooled ETH will gradually recover until it matches the standard market rate.
Note that Uniswap’s x*y=k is just one of the mathematical formulas used by AMMs today. For instance, Balancer uses a much more complex form of mathematical relationship that lets users combine up to 8 digital assets in a single liquidity pool. Curve, on the other hand, adopts a mathematical formula suitable for pairing stablecoins or similar assets.
The role of liquidity providers
As discussed earlier, AMMs require liquidity to function properly. Pools that are not adequately funded are susceptible to slippages. To mitigate slippages, AMMs encourage users to deposit digital assets in liquidity pools so that other users can trade against these funds. As an incentive, the protocol rewards liquidity providers (LPs) with a fraction of the fees paid on transactions executed on the pool. In other words, if your deposit represents 1% of the liquidity locked in a pool, you will receive an LP token which represents 1% of the accrued transaction fees of that pool. When a liquidity provider wishes to exit from a pool, they redeem their LP token and receive their share of transaction fees.
In addition to this, AMMs issue governance tokens to LPs as well as traders. As its name implies, a governance token allows the holder to have voting rights on issues relating to the governance and development of the AMM protocol.
Yield farming opportunities
Apart from the incentives highlighted above, LPs can also capitalize on yield farming opportunities that promise to increase their earnings. To enjoy this benefit, all you need to do is deposit the appropriate ratio of digital assets in a liquidity pool. Once the deposit has been confirmed, the AMM protocol will send you LP tokens. In some instances, you can then deposit – or “stake” – this token into a separate lending protocol and earn extra interest.
By doing this, you will have managed to maximize your earnings by capitalizing on the composability, or interoperability, of decentralized finance (DeFi) protocols. Note, however, that you will need to redeem the liquidity provider token to withdraw your funds from the initial liquidity pool.
What is impermanent loss?
One of the risks associated with liquidity pools is impermanent loss. This occurs when the price ratio of pooled assets fluctuates. An LP will automatically incur losses when the price ratio of the pooled asset deviates from the price at which he deposited funds. The higher the shift in price, the higher the loss incurred. Impermanent losses commonly affect pools that contain volatile digital assets.
However, this loss is impermanent because there is a probability that the price ratio will revert. The loss only becomes permanent when the LP withdraws the said funds before the price ratio reverts. Also, note that the potential earnings from transaction fees and LP token staking can sometimes cover such losses.
How Much Energy Does Bitcoin Use?
What Is a ‘Semi-Fungible’ Crypto Token?