📘Understanding Slippage in Automated Market Makers (AMMs)
Introduction to Automated Market Makers (AMMs)
The world of finance has always relied on market makers—entities that provide liquidity, hoping to profit from the difference between buying and selling prices. Traditional finance uses order books to facilitate this. Enter the world of decentralized finance (DeFi), where the pioneering concept of Automated Market Makers (AMMs) emerged.
Unlike their traditional counterparts, AMMs eliminate the need for a buyer for every seller and vice versa. Instead, they use algorithms and formulas to set asset prices, guaranteeing a counterparty for every transaction. This ensures constant liquidity, making DeFi trading more streamlined and efficient.
Why the Rise of AMMs?
DeFi's nascent stages faced a significant challenge—lack of liquidity. In such a landscape, the traditional order book model faltered due to the need for a matching buy/sell order for every trade. AMMs, with their liquidity pools, changed the game. These pools consistently provide liquidity, and in return, those who deposit their assets (liquidity providers) earn fees from the trades.
Understanding the Mechanics: Liquidity Pools & The Fundamental Formula
Central to AMMs are liquidity pools. These are reservoirs of two tokens. When users deposit their assets into these pools, they receive Liquidity Provider (LP) tokens, symbolizing their share in the pool.
For instance, if Alice chooses to deposit 1,000 DAI and 10 ETH into a DAI/ETH pool and her contribution is 10% of the total pool, she'd get LP tokens representing that 10% share.
At the heart of many AMMs, such as Uniswap, is the "Constant Product Market Maker" formula:
Here:
and represent the amounts of the two assets in the liquidity pool.
is a constant, meaning its value remains unchanged.
The beauty lies in its simplicity. If we were to examine a DAI/ETH pool, the product of the DAI and ETH amounts in the pool will always equate to .
Navigating Slippage in AMMs
The term "slippage" in the context of AMMs refers to the difference between the expected price of a trade and the price at which the trade is executed. Due to the mathematical nature of AMMs, the price of a token is continuously recalculated with every purchase or sale.
Consider our DAI/ETH pool example:
Starting with:
10,000 DAI
100 ETH
This gives us a constant, , of 1,000,000. If an individual wishes to purchase 1 ETH, the formula recalibrates the asset prices to maintain this constant. Consequently, as the pool's ETH quantity decreases, its price (in DAI) hikes up. This variance in the anticipated and actual transaction rate is the slippage.
Further, the impact of a trade on slippage is magnified or reduced based on the pool's depth or liquidity:
Higher Liquidity: Bigger pools dampen the effects of large trades, minimizing slippage.
E.g., Purchasing 1 ETH in a pool with a depth of 1,000 ETH will cause minimal slippage.
Lower Liquidity: In smaller pools, even moderate trades can disrupt the balance, leading to significant price shifts and higher slippage.
E.g., Buying the same 1 ETH in a pool containing only 50 ETH will result in much higher slippage.
Practical Example: Demonstrating Slippage in a USDC/ETH AMM Pool
For better understanding, let's delve into a practical, step-by-step example using the USDC (a stablecoin pegged to the U.S. dollar) and ETH pair.
Initial State of the USDC/ETH Pool:
10,000 USDC
100 ETH
The constant here, according to the AMM formula, is:
This means, initially, 1 ETH is priced at 100 USDC. (10,000 USDC ÷ 100 ETH)
Step 1: Buying 1 ETH
Now, a trader named Alice decides to buy 1 ETH from the pool.
Using the constant product formula, after purchasing the 1 ETH, the pool needs to adjust the quantities of USDC and ETH to keep the product constant at 1,000,000.
Let's assume the new amount of USDC after the trade is . Therefore, the amount of ETH will be (since 1 ETH was purchased).
According to the formula:
Solving for gives:
This means Alice spent USDC to buy 1 ETH. Initially, she might have expected to spend only 100 USDC for 1 ETH, but due to the AMM mechanism, she ended up paying slightly more, resulting in a slippage.
Step 2: Buying 10 ETH in a High Liquidity Pool
Now consider a larger pool:
100,000 USDC
1,000 ETH
The constant here would be 100,000,000. Bob wants to buy 10 ETH. After his purchase, the remaining ETH in the pool would be 990. If the new amount of USDC is :
Bob would spend USDC for 10 ETH or 101.01 USDC per ETH. Notice that even for a purchase 10 times larger than Alice's, the slippage per ETH remains the same, thanks to the deeper liquidity.
Step 3: Buying 10 ETH in a Lower Liquidity Pool
Returning to our initial pool:
10,000 USDC
100 ETH
Charlie decides to buy 10 ETH. Post-purchase, the ETH in the pool would be 90. Let's say the new USDC amount is :
Charlie spends USDC for 10 ETH, averaging 111.11 USDC per ETH. This is significantly higher slippage compared to Bob's transaction, even though they both bought the same amount of ETH. The smaller liquidity pool causes a greater price impact.
Impact of Trade Size on Slippage:
The size of a trade directly affects the degree of slippage. Small trades in deep liquidity pools might cause negligible slippage. But as the trade size grows, especially in comparison to the pool's liquidity, slippage can increase significantly. This is because large trades in proportion to the pool size alter the balance of assets more drastically, leading to more pronounced price changes.
Example:
Imagine a pool where you're trying to buy 5% of its total ETH. The price you pay for the first 1% might be close to the market rate. But as you keep buying and the ETH in the pool decreases, the price will progressively rise. By the time you're trying to buy the 5th percent, you could be paying a much higher rate.
In Conclusion
Slippage is the difference between the expected and actual transaction costs in AMMs. Its extent is influenced by the depth of liquidity in the pool. Higher liquidity tends to buffer large trades, reducing the price impact, whereas lower liquidity can result in substantial price shifts even for moderate trades. This example underlines the importance of considering pool sizes and potential slippage when making transactions in DeFi platforms.
Last updated