July 1, 2023
Photo by Maxim Berg on Unsplash
AMM stands for Automated Market Maker. It is a type of decentralized exchange (DEX) that is governed by smart contracts . Think of it as trading tokens without finding someone who wants to buy or sell them.You trade with a pool of tokens controlled by a smart contract. But if there is no buyer or seller, who decides the price to sell or buy from?
That's a valid question; the price of the tokens in the pool is decided by a mathematical formula that depends on how many tokens are in the pool. The most basic formula is called the constant product formula, and it looks like this:
Constant Product Variant. Image by Kishan Kumar
x * y = k, where x and y are the amount of two tokens in the pool, and k is a constant number. This means that if you increase the amount of one token in the pool, you have to decrease the amount of the other token to keep k the same. This also means that the price of one token in terms of the other token equals the ratio of their amounts in the pool.
For example, let's say you have a pool of ETH and USDT, and there are 100 ETH (x = 100) and 200,000 USDT (y = 200,000) in the pool. The constant k is 100 * 200,000 = 20,000,000. The price of one ETH in terms of USDT is 200,000 / 100 = 2,000 USDT.
If you want to buy 10 ETH from the pool (i.e., you removed 10 ETH), you have to add some USDT to keep k the same. The new amounts of ETH and USDT in the pool are 90 and 222,222.22, respectively. If we apply simple supply and demand logic, what should happen if someone buys ETH and no one sells it?
Right, its price will increase, and that is what happens in our pool as well. The new price of one ETH in terms of USDT is 222,222.22 / 90 = 2,469.13 USDT. As you can see, the price of ETH has increased because you have reduced its supply in the pool.
This formula ensures that there is always enough liquidity in the pool for any trade and that the price changes according to supply and demand. However, it also means a slippage when you trade large amounts of tokens, which is the difference between the expected price and the actual price you get from the pool. The larger the trade, the more slippage there is. This is why liquidity providers earn fees or rewards for supplying tokens to the pool because they take on the risk of price fluctuations.
Uniswap Swap Feature. Max Slippage Option.
Let's take an example to understand how slippage affects trade:
For example, let's say you want to trade 100 ETH for USDT on an AMM platform that uses the constant product formula x * y = k to price assets. The current price of ETH is 2,000 USDT, so you expect to get 200,000 USDT for your 100 ETH. However, when you execute the trade, you find out that you only get 198,000 USDT. But why? This is because your trade has changed the ratio of ETH and USDT in the pool and, therefore, the price of ETH in terms of USDT. The new price of ETH is 2,020 USDT, which means you have paid a higher price than expected. The difference between 200,000 USDT and 198,000 USDT is the slippage.
Slippage can be positive or negative, depending on whether you buy or sell an asset and whether the price moves in your favor or against you. Slippage can also vary depending on the AMM platform, the token pair, and the market conditions. Slippage can be reduced by trading smaller amounts, choosing pools with higher liquidity, or using platforms that offer lower slippage ratios.
Slippage is a financial risk that traders face when using AMM-based DEXs. Before confirming a trade, always check the slippage and be prepared for possible price fluctuations.
That's a valid concern. The price of ETH in the pool is not necessarily the same as the price of ETH on other exchanges because different factors determine them. However, there is a mechanism that helps keep the prices in sync called arbitrage. Arbitrage is taking advantage of price differences between different markets to make a profit.
For example, let's say the price of ETH in the pool is 2500 USDT, but the price of ETH on another exchange is 2100 USDT. An arbitrageur can buy ETH from the other exchange and sell it to the pool for a higher price and make a profit of 400 USDT per ETH. However, by doing so, they also change the amounts of ETH and USDT in the pool and, therefore, the price of ETH in the pool. The more ETH they sell to the pool, the lower the price of ETH becomes until it reaches an equilibrium with the other market. This way, arbitrageurs help to balance the prices across different markets and reduce the arbitrage opportunity.
Of course, arbitrage is not a perfect solution because it involves some costs and risks, such as transaction fees, network congestion, price volatility, etc. Therefore, there may still be some discrepancies between the prices in different markets at any given time. However, arbitrage is a powerful force that tends to minimize these discrepancies and create more efficiency in the market.
Uniswap (AMM) vs. Binance (Book-Based Exchange).
The difference between AMM and order book-based exchanges is mainly in how they match buyers and sellers, price assets, and provide liquidity.
Order book-based exchanges use a traditional trading model, where buyers and sellers place orders to buy or sell an asset at a specific price. The exchange matches the orders based on their prices and executes the trades. The supply and demand of the orders determine the price of the asset. The liquidity of the asset depends on the number and size of the orders in the book. Order book-based exchanges can offer more advanced trading tools like limit orders, stop-loss orders, margin trading, etc. However, they also require more intermediaries, such as brokers, custodians, or regulators, which can increase trading costs, risks, and delays.
AMM-based exchanges use a decentralized trading model, where buyers and sellers trade directly with a pool of tokens controlled by a smart contract. The exchange does not match the orders but executes them automatically using a mathematical formula. The formula and the ratio of the tokens in the pool determine the asset's price. The liquidity of the asset depends on the amount and diversity of the tokens in the pool. AMM-based exchanges can offer more permissionless, non-custodial, and automated trading of cryptocurrencies. However, they also face some challenges, such as slippage, impermanent loss, network congestion, or security issues.
Trading in AMM involves some risk factors you should be aware of before participating. Some of these risks are:
There are many AMM platforms in the DeFi space, but some of the leading ones by user activity, liquidity, and volume are:
Subscribe to the newsletter to learn more about the decentralized web, AI and technology.