There are roughly 10 million people in the world that have used DeFi. And if you’ve used DeFi, one of the first things you have done is to swap tokens on a decentralized exchange. In an exchange like Uniswap, the AMM is an algorithmic ‘money robot’ which determines the price of an asset.
One of the most common and simple forms of algorithm used is the Constant Product Market Maker (CPMM):
where x is the amount of token A and y is the amount of token B. This function states that the product of x and y should always remain a constant k.
Let’s look at a simple example:
A pool has been provided with 10 ETH and 10000 USDC. Their product k is now 100000. At first glance, it looks like the price of ETH in this pool is 1 ETH = 1000 USDC. If I have 5000 USDC, you would think that I would receive 5 ETH in exchange. Wrong! Let’s examine why.
When I provide 5000 USDC, the pool now has 15000 USDC in total. To keep the k constant at 100000 with 15000 USDC, the amount of ETH in the pool would need to be 100000/15000 = 6.6667. This means I will get 3.3333 ETH in return for the 5000 USDC at the price of 1500 USDC per ETH. Since I am supplying USDC and demanding ETH, the value of ETH compared to USDC will rise following the concept of supply and demand.
This is an extreme hypothetical example. Sophisticated protocols usually have code in place to warn you about such large slippages. AMMs have progressed a lot with newer protocols. Protocols like Curve use more advanced algorithms as their money robot. I hope to cover them in future essays.
