Wait, how does the AMM determine the price of the two tokens in the pool?
Ok, we’re going to get into the weeds here, so bear with us.
First off, it’s important to note that AMMs and liquidity pools always strive to reflect the valuations of tokens in the outside world.
In other words, the liquidity pools don’t create a bubble, cut off from what happens on other markets. If they did, they would create what are known as arbitrage opportunities – valuation glitches that allow traders to rush in and trade tokens for a better price than they would get elsewhere.
To ensure this doesn’t happen, the person who opens the pool (the first liquidity provider) provides tokens on both sides of the pair, in a balance that reflects their real-world valuations.
So let’s say, for example, we’re opening an ETH:USDT pool and 1 ETH is worth $50 USDT. To ensure the pool reflects these valuation, the first liquidity provider might provide 1 ETH and $50 USDT, 2 ETH and $100 USDT, 0.5 ETH and 25 USDT… you get the picture.
From then on, every subsequent liquidity provider must also fill up the pool on both sides, in the same balance.
Then, when the pool opens, the AMM algorithm takes this initial ratio as a benchmark and uses it to continually adjust the weightings of the relative currencies, using a mathematical formula.
AMMs can use several different formulas, but the simplest is called the constant product formula, which is K = X * Y. ‘X’ and ‘Y’ are the two tokens in the pool, and K is the total liquidity, which must remain constant.
What this means, in very simple terms, is that K cannot change from its initial value when the pool opens. So, if either ‘X’ or ‘Y’ goes up, the other must go down – and this triggers a change in their valuations.
Confused? Don’t worry, here’s another simple example: