Automated Market Makers, or AMMs, are possibly the most foundational developments in the decentralized finance world. They allow for instant swapping of tokens without the need for a centralized market maker. AMMs are the protocols that allow DEXs to operate.
In traditional finance, market makers are humans who quote bids and asks in two-sided markets and share their market sizes. Traditional exchanges use an order book to record buyer and seller interest. The disadvantage of using human market makers is if a buyer or seller does not find someone to meet their prices they have to change their orders.
When v1 went live in 2018, Uniswap became the first AMM to market and remains one of the most popular today. Between v2 and v3, Uniswap has done over $500,000,000 in trading volume in the 24 hours before writing.
How AMMs work?
AMMs replace the traditional order book method used by centralized exchanges with a constant product market maker function (CPMM) to price assets. CPMM is the function used by Uniswap and other AMMs.
The CPMM formula is X * Y = K, with X representing the quantity of one token in the liquidity pool and Y representing the other token in the pool. K is a constant used to balance the equation. If the quantity of X tokens increases in the pool, the supply of Y must decrease. This function establishes a range of prices based on the available supply of each token in the pool.
Using this formula, the model of tokens follows the curve shown above. When Alice buys A tokens with her B tokens (thereby spending A tokens in the contract), the supply of B tokens in the contract increases. The transaction will also increase the price of token A and decrease the value of token B.
AMMs like Uniswap allow any user to provide liquidity to a pool of their choice in return for a portion of trading fees collected by the pool. This represents an improvement in equity from traditional financial markets, which only allow high-net-worth individuals or companies to provide liquidity on exchanges.
For more on how providing liquidity to an AMM works, check out our recent post on Yield Farming in DeFi.
As with anything in crypto, the use of AMMs comes with risk. The two main risks are impermanent loss and slippage.
For traders, the biggest risk is called slippage. Slippage is the difference in the price you expect to receive compared to the price you paid. Slippage can occur because of high volume or low liquidity. When caused by low liquidity, slippage occurs because there is an imbalance of tokens in the liquidity pool, and prices begin to “slip” making one asset more expensive and the other cheaper.
Slippage can be caused by high volume because DEXs don’t process trades instantly. Miners need some time to confirm these transactions. In the time it takes to process a transaction, prices can fluctuate greatly, causing the number of tokens you were quoted to receive from Uniswap to be different than the amount you end up receiving.
The second risk of impermanent loss is for liquidity providers and is explained in detail in the previous blog post linked above.