Decentralized finance or DeFi has definitely been one of the most revolutionary applications in Web 3. The advent of DEX’s (acronym for decentralized exchanges) has not just democratized the adoption of cryptocurrency, but also given rise to new and innovative ways to access financial opportunities – ways that were traditionally never heard of. Yes, now you can literally do all the major banking activities within the crypto ecosystem minus an intermediary. In a traditional setup, the intermediary as we all know retains the unilateral power to choose to serve you or ignore you.
This article will help you understand one of the most fundamental pillars of DeFi – Automated Market Makers i.e. AMM, in the most beginner friendly manner.
Who is a Market Maker?
Imagine you’re a farmer wanting to sell your farm produce. Who do you sell to? A buyer. Now imagine you’re somebody who needs to buy some veggies for consumption i.e. a consumer. Who do you buy from? Yes that’s right, a seller!
Let’s think of a conventional way of completing a transaction successfully in this scenario. Getting the farm produce to actual consumers would require a great amount of planning and logistics. Packaging, transporting, storage, shipping and collecting payments – all this requires a lot of resources, right? Apart from these, each of these steps can put a significant financial burden on the farmers.
So how do the farmers really sell? This is where the middlemen come in. The middlemen purchase goods in bulk from farmers. They take care of all the intermediate processes, add their cut over the purchase price (hence the concept of ‘markup’) and then sell it to consumers like us.
One of the most important functions of a market maker is to provide liquidity. Imagine being a farmer with nobody to sell to, or a consumer with no goods to purchase! These market makers ensure that there is always a buyer for a farmer to sell their produce and always a seller to purchase from, for a consumer.
Automated Market Maker (AMM)
Now that we have a basic understanding of traditional market making, let’s learn how market making works in the crypto ecosystem.
When you wish to buy some crypto – there are basically two major ways of doing it. First is through a centralized exchange or CEX (e.g. Binance, Coinbase). The other way is through a decentralized exchange or DEX (e.g. Uniswap, Balancer, Curve). In a CEX, if you wish to buy some crypto, the CEX will first try to find a buyer willing to sell some crypto in the backend. CEX here acts as an intermediary between the two parties and facilitates the transaction, by taking a fee. There is a good amount of automation to match orders in their ‘order books’ (to settle buyers and sellers near instantly) but they are prone to central points of failure.
In the case of DEXs, however, the AMM protocol and the liquidity pools locked in smart contracts collaterally help realize the transaction. Little more on this shortly. While each has its own advantages and disadvantages, the primary goal of each facilitator is to provide users a platform to exchange cryptos or convert the crypto into fiat/vice versa. Note here, DEXs/CEXs transactions are done in crypto as opposed to fiat say in stock exchanges or forex trading. After transacting, you can then convert your crypto to fiat through various options available with every exchange.
The concept of an AMM was first ideated at length by the founder of Ethereum, Vitalik Buterin. (Side note : Just go through the reddit post and you will find how legendary it is after all these years). Through this concept, he suggested creating an on-chain system that aids the token swap process, primarily based on how prediction markets run. Uniswap was the first DEX with an AMM protocol based around this idea. The fact that a single reddit post sowed the seeds of an idea that turned into a multi billion dollar industry (DeFi) – shows how powerful the idea of AMMs have been. It is as as good as his other innovations like Ethereum Virtual Machine (EVM) and smart contract which the Web 3/crypto community is heavily indebted to.
Below summarizes the ‘constant product’ formula incorporated in AMMs.
x*y = k
‘x’ is the number of token 1 within the pool, ‘y’ is the number of token 2 within the pool & ‘k’ is a constant.
This “k” stays constant and changes only when liquidity is withdrawn from the pool. How are these pools created? This is where the power of Web 3 kicks in by allowing anyone to participate, in a permissionless manner. Any user who has some spare crypto tokens can provide liquidity to the AMMs i.e. they can add tokens to the pool in proportions based on the constant, for the chosen trading pair (for eg. ETH/USDT) and they can further earn some crypto tokens in exchange.
Example of Crypto Token Swaps
Let’s take an example of the ETH/USDT pair to understand the above concept further.
Imagine a pool with 10,000 USDT and 5 ETH (figures taken only for calculation and understanding purposes)
k= x*y and in this case, k= 10,000 * 5= 50,000
If a seller wishes to sell 1 ETH to this pool, the amount of ETH would rise to 6. Now, to keep ‘k’ constant, the amount of USDT in this pool should decrease to 50,000/6 = 8333.33. Thus, the seller will receive 10,000 – 8333.33 = 1666.67 USDT in exchange of 1ETH. Similarly, if a buyer wishes to exchange, say 1000 USDT for some ETH, a similar calculation would be made in order to maintain the value of ‘k’ constant.
Keep in mind, unlike order book matching process we have been accustomed to in stock brokerage platforms and exchanges, the buy/sell transactions and the settlements are cleared instantly with the help of much higher levels of automation i.e. smart contracts as mentioned previously. Smart contracts are self executing contracts between two parties that are triggered when pre-set conditions are met. And the pre-set conditions are based on prediction markets. Although AMMs remove the necessity for an intermediary, prediction markets can’t be perfect. But innovations in this field based on better models has helped AMMs to improve over the last 6 years since the reddit post by Vitalik Buterin. As you can imagine, there are pros and cons with respect to AMMs which you can find below.
Pros and Cons of AMM
1. Arbitrage Opportunities
Since the spot price of the tokens are always along the curve defined by x*y = k, there can be instances where the price on a DEX is lesser than the market price. This potentially gives rise to an arbitrage opportunity where a trader can buy/sell from the market and exchange the tokens from the liquidity pools with larger spreads. Thus, AMMs effectively incentivize the traders to maintain the balance between tokens and maintain the constant ‘k’.
2. Yield Farming
When a participant adds liquidity to the AMM protocol, they receive LP tokens in exchange. These LP tokens can be burned to get back the tokens added initially. However, one of the biggest advantages of these LP’s is that they can also be staked. Staking unlocks passive earning opportunities as it facilitates earning interest income. You can also redeem your LP tokens when you want to, although some DEXs may charge small fees if you are redeeming them too early.
3. Impermanent Loss
As the liquidity pools on AMMs like Uniswap operates in the realm of ‘constant product’ curve, there can be cases where the ratio of the tokens you supplied initially, will change, after you add the tokens. This leads to an impermanent loss that persists till the ratio of tokens goes back to where you invested at. The loss, however, becomes permanent only when you withdraw your tokens. Let me break this down and simplify what is an impermanent loss. So let’s say you have $1000 worth BTC in June 2022. In August 2022, the BTC price went down and BTC value in your portfolio now amounts to $800. As of August 2022, your impermanent loss is $200. Note, impermanent losses are not permanent unless you wish to sell it for a loss in this scenario.
Slippages basically occur when the price quoted by the DEX changes – from the time of quote to the time of swap. The AMMs typically provide the facility to set the slippage limits. This helps traders to limit their slippages and gain more control over their transactions.
As the DeFi ecosystem grows, you can expect more innovations in the upcoming years to help you access various financial opportunities. The core principle of crypto and Web 3 in general is to empower individuals to be their own banks. The AMMs will do their part in creating utilities to provide you or anyone with permissionless access to finance beyond boundaries. The future with decentralization is definitely very exciting!
One of the most important functions of a market maker is to provide liquidity. Imagine being a farmer with nobody to sell to, or a consumer with no goods to purchase! The middlemen are the market makers who ensure that there is always a buyer for a farmer to sell their produce and always a seller to purchase from, for a consumer. They will take care of pretty much everything in between including logistics and they provide this service for a fee.
As you can imagine, instead of middlemen, market making in AMM is done with the help of
automation via smart contracts. There is also an incentive for consumers or traders in this case to make sure there is enough liquidity in the market. Traders can find incentives in the form of ages old arbitrage and slippage opportunities. Further, compared to the fees charged by an intermediary in Web 2 world, decentralized exchanges or DEXs who use AMM charge very low fees. And note, regardless of whether you are a first time DeFi/crypto user or whether you are living out of an impoverished nation, you can make use of DeFi services to earn passive income and make financial transactions for a living.
AMMs presents various opportunities and threats for a user or an investor such as arbitrages, interest-yielding deposit/savings plans, slippages, impermanent losses among others. Here the threats are really not threats per se unless you haven’t done enough research about a liquidity pair or any product for that matter in crypto ecosystem before investing or playing a role as a liquidity provider (LP). If used wisely, you can earn passive income and earn profits from arbitrages consistently.
Opinions expressed and the content in this publication are those of the author(s). They do not necessarily purport to reflect the opinions or views of Shardeum Foundation.
About the Author : Yash Nair is a product manager on the weekdays and a cinephile over the weekends. He is curiously exploring Web 3.0 and all things crypto. You can follow him on Twitter