Original: https://joecontent.substack.com/p/part-1-a-brief-overview-of-1st-generation
In this 3-part series, we'll cover the first generation of AMMs, the second generation of AMMs, and finally arrive at our idea of what a modern AMM should look like.
Vitalik first described Automated Market Makers (AMMs) as a catalyst for DeFi in an article. Uniswap is the most famous of these, but there are many other AMMs. We will introduce them in this article.
Uniswap
Uniswap is based on the constant product formula, x * y = k, where x is the amount of asset X, y is the amount of asset Y, and k is a constant. Therefore, each pool contains only two assets, X and Y, and the formula ensures equal ratios of both.
This chart shows a graph of the constant product formula, where x is the quantity of X, y is the quantity of Y in the pool, and the slope of the point on the curve is the spot price.
This is best explained with an example.
Assuming AVAX is 100 USD, an AVAX/USDC pool consists of 20 AVAX and 2000 USDC. Because 20 AVAX is equivalent to 2000 USDC, the ratio of asset value is 1:1. If we let asset X be AVAX and asset Y be USDC, then using the constant product formula, we get k = 20 * 2000 = 40000.
This number remains constant during the swap and only changes when more liquidity is added.
Now suppose Alice wants to exchange 5 AVAX. How much USDC will she get in return?
Recalculating the formula for y, we get y = k/x. Therefore, the amount of USDC in the pool after exchange is y = 40000 / (20+5) = 1600 USDC. So Alice received 400 USDC with 5 AVAXs.
The pool now includes 25 AVAX and 1600 USDC. The spot price of AVAX is now changed from 100 USDC to 1600/25 = 64 USDC.
The price impact of this trade is (64-100) / 100 = -36%.
This could be the effect of a falling product on market maker prices. Because the curve is convex, the slope keeps changing as you move along the curve.
Take the following figure as an example. Imagine a slope at the old position and a slope at the new position. A small change in the curve produces a drastically different slope, and the difference is the price impact.
The remedy to all of this is to ensure that liquidity is deep enough to absorb the price impact.
However, this pattern has a huge benefit. If you examine the graph again, you'll notice that the curve never intersects the x or y axes. This means that the reserve of x or y can never be depleted from the pool. By providing this case, you can provide liquidity for the entire price range (i.e. [0, ∞]) and always have two assets to execute trades.
This feature makes it extremely easy to provide liquidity and basically spurs the DeFi revolution because now everyone can become a market maker, whereas in the past, market makers were the preserve of large financial institutions.
Balancer
What if we could have each pool contain more than 2 assets? This is the basis of Balancer, which takes the constant product formula but generalizes it to up to 8 assets.
In addition to this, Balancer pools also allow for custom ratios. For example, you can customize it to be 80:20 instead of 50:50 between two asset pools. There are several reasons why you might want to weight your assets more:
- You are more bullish on a certain asset and want it to take up more of your portfolio.
- The higher the weight of a token, the less impermanent loss it experiences.
This graph depicts how an unbalanced pool reduces the IL of coins with greater weight. But this comes at the cost of greater price impact for pool transactions, since one side has less liquidity.
Think of Balancer pools as automatically rebalancing portfolios, acting like decentralized index funds that anyone can create, and where fees are paid by liquidity providers rather than intermediary fund managers.
Curve
Both Uniswap and Balancer use constant products as underlying invariants, but one of the downsides is price impact. Enter constants and formulas. This is the underlying invariant that powers Curve and addresses the problem of high price impact.
The constant and formula is x + y = k and the graph looks like this:
Remember, price is the slope of the line at this point. . In this graph, the slope is always the same; i.e. the price is constant, which means that zero price affects the trade. Sounds great right? There is a caveat. This line has an intercept on both the x-axis and the y-axis, which means you will see scenarios where an asset in the pool is depleted.
Imagine a USDC/USDT fixed sum pool of $1. If the price of USDC/USDT rises to 1.1 on another exchange, the arbitrageur will immediately mine all the USDC in your pool so they can sell it on another exchange for a profit.
Therefore, Curve uses a modified version of the constant sum formula, which is a combination of constant sum and constant product. The actual equations are complicated, so I'll show you my simulated version, which can be summarized as:
A * (x + y) + xy = k
A is the amplification factor, which depends on the reserve ratio. If the pool becomes very unbalanced, A is then reduced, minimizing the (x + y) term. This allows the pool to behave like a constant product market maker.
Conversely, if the pool is well balanced, A will then be high, which maximizes the (x + y) term, making the pool behave like a constant market maker.
The result is the blue line below, which is flat in the middle because the assets are equally balanced and convex because the pool becomes heavy in one asset:
Bancor
Bancor launched in 2017 as the first AMM. Its main selling point is that it offers 100% impermanent loss protection.
This is a hotly debated topic. Nobody likes impermanence loss, but is it possible to fix it completely?
Despite the possible solutions on the market, it still seems that some people have to accept impermanent loss. The main disadvantage of the Bancor model is that BNT holders have to absorb losses.
Summarize
We cover the protocols that are the cornerstones of DeFi. Most use a constant product formula, with the exception of Curve, which uses a modified version of the constant sum. The benefit of a constant product is that it becomes easy to provide liquidity, although it does require deep liquidity for better price execution.