Understanding the fundamentals of DeFi is critical to analyzing new projects. In this article, we will summarize pages of AMM research so that you understand exactly how these three protocols work. Try to follow the math, it’s interesting.
Automated Market Makers (AMMs) are decentralized exchanges that create pools of liquidity (tokens) deposited by users and price the assets within the pool using algorithms. The exact mechanics vary from exchange to exchange.
Uniswap was inspired by an idea of an automated market maker posted by Vitalik Buterin in 2016. Developed by Hayden Adams and launched two years later in November of 2018.
Uniswap V1 and V2 work via a constant-product formula (remember this term):
x * y = k
x: number of token 1 in the pool
y: number of token 2 in the pool
k: constant that stays constant during trades but is recalculated when liquidity is provided / withdrawn
Uniswap V3, introduced in March 2021, uses concentrated liquidity and fee tiers. This model allows for increased liquidity around a target price and for various risk-reward profiles for LPs. Uniswap V3 is much more capital-efficient than V2.
Balancer was founded in 2018 as a project incubated by Block Science before being spun out as a separate company. They published their whitepaper in September 2019 and launched in March 2020
Let’s start with weights. Let W be the weight of a token in a pool such that all weights add up to 1. We can then modify the spot price formula to account for target weights like so:
The formula for a constant-product pool of assets is an extension of Uniswap’s x * y = k.
For three assets, it would look like so: x * y * z = k.
Reminder: x, y, and z are balances of each tokens in a pool.
The spot price between two assets = x / y
Putting it all together and generalizing to n assets, we get to this formula, which is the core equation for Balancer
Note: we use balance to the power of weight instead of the intuitive multiplication by weight because this is not summation but multiplication
Curve Finance started as a StableSwap whitepaper by Michael Egorov in November of 2019 and launched in January of 2020. Its design builds on top of the formulas used by Uniswap and Balancer.
Curve aims to provide sufficient liquidity with little slippage for like assets (e.g, UDSC and UDST)
A constant-sum formula would allow for 1:1 swaps, but it may run out of liquidity and doesn’t have a balanced state. The image illustrates a constant-sum of x + y = 10
Curve’s key equation is a combination of a constant-product formula and a constant-sum formula, such that the curve is almost flat around the target price. This allows for minimal slippage around the target price and liquidity outside the range.
So that are some basic things that you should learn in DeFi. Understanding this will help you with analising another projects in future.