Fundamental concepts of DeFi
When you start using DeFi, and specifically DEXs, the concepts of Automated Market Makers (AMMs), Impermanent loss (IL), and slippage come up quite frequently. These terms are complex, but also vital when doing your own research and evaluating different investment options. In this article, we'll explore them all, striving to unravel their complexities and explain them using simple terms.
Let’s start with some of the more fundamental concepts first…
Market Makers, AMMs & Liquidity Pools
In the most basic sense, a Market Maker is an actor that always stands ready to buy and/or sell a particular good or product at a publicly stated price. Market makers provide value to a market by making it more active and efficient while earning a profit on every transaction they accept. If you have ever converted any money at the currency exchange office in an airport, then you have already transacted with a market maker.
Automated Market Makers (AMM) are naturally engaging in the same activity, they are just doing it systematically, by use of blockchain smart contracts. To do so, AMMs require an inventory of assets, which they then organize in pairs or “pools”. Please note that, although more complex AMMs have been created in the past years, with pools of more than two assets and more intricate formulas, understanding the basics suffices for this article.
AMM liquidity pools essentially hold two different types of digital assets in a locked state (i.e. a smart contract) and stand permanently ready to buy or sell any one of them in exchange for the other. These pools are also designed to monitor the quantity of assets in their inventory and adjust the prices they can bid or ask. Basically, the more coins that someone wants to buy, the more expensive they become.
This happens because Liquidity pools commonly employ the "Constant Product Market Maker" model. To maintain this balance of their assets, they use the formula k = x * y, where 'x' and 'y' represent the quantities of the two tokens in the pool, and 'k' is a constant value.
To illustrate a little, let’s imagine that ETH is worth $100 and $CACAO is worth $1. In this case, a MAYA ETH/CACAO pool would be balanced when it had 1 ETH for every 100 CACAOs, and could thus only accept deposits and withdrawals that were already evened in the same ratio. The pool could still grow and reach, say, 100 ETH, but it would then require 10,000 CACAOs. In any case, multiplying the total quantity of each coin results in the value of k.
If a trader wanted to buy 10 ETH out of those 100, they would need to deposit 1,000 CACAOs into the pool (since the ratio is 100:1). After this transaction, the pool would have 90 ETH and 11,000 CACAOs. Notice that while the number of coins changed, multiplying them still equals the original k value, thereby maintaining the balance as per the "Constant Product Market Maker" model. You can read more about pools, Liquidity Providers and symmetrical deposits in this Maya Academy article.
Now let’s move on to…
Impermanent Loss (IL)
If for any reason the market price of our tokens X and Y changed dramatically relative to one another, then our pool would need to adjust its inventory to continue satisfying the constant product formula. Remember that the multiplication of the price of both tokens needs to stay the same, so now the number of tokens with a newer higher value would have to decrease and the number of tokens with a newer lower value would have to increase.
Under this scenario, any Liquidity Provider that decided to remove their positions, would quickly notice that their withdrawal contained a different ratio of assets than what they initially deposited. The initial monetary value of their investment would be the same - plus any yield they could have earned - but the composition of their capital would be different, with more of the now cheaper tokens and less of the now more expensive ones.
They would also find out that the value of their initial holdings could have been greater than the value of their new withdrawal, or in other words, their original investment - if held outside the pool - would have yielded a higher return than the assets they've now withdrawn from the liquidity pool.
This opportunity cost is called an “impermanent loss” and will become more substantial the more the prices continue to diverge.
Impermanent Loss is only realized (i.e. it becomes “permanent”) when an LP withdraws his or her position. If the prices of the tokens involved return to their original state before a withdrawal, the IL would then be “erased”.
Slippage is a term borrowed from traditional finance, and refers to a difference that might occur between the expected price of a trade and the actual price at which it is executed. In DeFi this difference is often created by heavy volatility or when a user or user interface (UI) calculates the output of a trade without proper consideration for any price impacts.
Given the constant product formula that we mentioned before, AMM liquidity pools are designed in such a way that the price of their tokens increases with the size of the orders they receive, effectively making larger orders more expensive.
Ignoring this factor when quoting a large transaction can lead to a significant “slippage” discrepancy between the anticipated output price and the actual resulting price.
Managing Impermanent Loss and Slippage with Maya Protocol
One of Maya’s coolest features is Impermanent Loss Protection (ILP), which guarantees our LPs a better outcome than they would have had by just holding their native assets after 100 days. You can read all about it in this Maya Academy dedicated article.
Slippage on the other hand, is handled using a concept called slip-based fees, which are dynamic and disincentivize bigger trades (relative to the size of the pool) to heavy price impacts and prevent excessive price fluctuations. You can read more about this in the Maya official documentation.
Maya also helps reduce slippage in a broader sense because it has been designed to add redundancy to DEXs and cross-chain UI aggregators. By integrating Maya into their systems, these platforms can use more than one source of liquidity, which minimizes price impacts and results in better price predictions. You can see Aaluxx talk a little more about this here.
We hope that this comprehensive guide has provided you with valuable insights and clarified these abstract topics. Understanding concepts like impermanent loss and slippage, along with the mechanics of AMMs, are key when doing your own research in the rapidly evolving world of the web3. But the conversation doesn't end here! If you're curious to learn more, or if you have any questions or topics you'd like to discuss, do join our vibrant community on Discord. We hope to see you there!