With the explosion of DEFI onto the world its time to pull it apart and make sense of what it is and what it offers us now that yet another crypto Djinn is out of the bottle.
Automated market makers (AMMs) are a major part of the decentralised finance ( DeFi ) ecosystem. These forms of magic allow crypto currencies and other digital assets to be traded in a permissionless and automated way. They use pools of liquidity rather than requiring a seller and buyer in a market place. The prices are worked out via math. Liquidity can be provided by any one and incentives are offered for doing so, keep in mind they are not risk free.
- What is an AMM
- How do they work?
- Liquidity Providers and Liquidity Pools
- The Math!
What is an AMM
Automated Market Makers ( AMM ) allow crypto currencies/digital assets to be traded in a permissionless way and automatically using liquidity pools, these differ to traditional markets because both buyers and sellers are not needed, in these markets the buyer and seller agree upon a price and then the transation takes place. With AMM's transactions can take place at anytime so long as the buyer is happy with the rate that is currently available.
Decentralised Exchanges that us AMM's
With Decentralised Exchanges ( DEX ), there is not 3rd party that mediates the exchahge. With AMM's the algorithm will utilise the liquidity form that which is provided to settle the transaction at the current rate. The algorithms can vary between dex's but the intention is to have deep liquidity, cheap to use and be available all the time.
Liquidity Providers and Liquidity Pools ( Yeild farming )
Liquidity relates to how easy it is to buy/sell or convert an asset. A house is not very liquid as it takes a long time to sell it and for the asset to be transferred. Cash is liquid, you can take it and convert it to many assets / goods or services and requires little time to settle the transaction. As Decentralised Finance started out it was difficult to find people on the network to trade crypto currencies with, so there was a liquidity problem. Finding a person that wanted to trade the same crypto currencies and also the same amount was a task in itself, AMM's fix this but creating liquidity pools of assets, the users who provide liquidity are offered rewards and incentives for doing so, the greater the amount of assets in the pool the deeper the liquidity and the easier it is to trade on DEX's
With traditional exchanges users buy and sell with other users, these AMM's allow users to trade against the pool of tokens. the pools usually consists of two tokens eg BTC and USDC and this is used for people wanting to trade BTC for USDC or USDC for BTC. The price is worked out by a formula and these forumulas can be different between different DEX even between different pools on a single DEX.
When a users alters the amount of tokens in the pool the ratio changes and as result the price does.
Anyone who has tokens ( usually ERC-20) is able to provide liquidity and earn for doing some, incentives come in the form of trading fees ( typically 0.1% per trade ) and bonus rewards usually in the dex's native tokens or some other offering to entice people to provide liquidity. this is known as Yield farming
When going to use a DEX and trade one token for another depending on how deep the liquidity is and the size of the trade you will encounter slippage, this is the deviation of the current price to the price you will pay per token. This is a result of you moving the market and if the slippage quite is high your trade will be large relative to the pools liquidity.
A simple example here is lets say you want to swap USDC for USDT, both are USD Stable coins so equal to $1. If we swap 100 USDC and have a slippage of 5% then we can expect to get 95 USDT. So 1 USDC will trade for 0.95 USDT.
If that same pool had a lot more liquidity then we may get a slippage of 0.1% (basically just the AMM trading fee ) and in that case 100 USDC would get is 99.99 USDT.
Constant Price Formula
The elegance of math and what allowed this bit of technology to be unleashed is the following simple fomula:
Constant product formula
x * y = k
Here X represents the amount of AssetX in the pool and Y represents AssetY whilst K is a constant. If someone buys AssetY and sells AssetX for it then the relative price of AssetY to AssetX will change. We remove some AssetY and add some AssetX more X and less Y results in Y relative price increasing and X decreasing to equate the constant K.
I like to think about it as a see saw, as there are more X its price goes lower, less Y so it goes higher ( relative to each other). This creates arbitrage opportunities for traders and keeps the pools close to the values on exchanges.
There are a range of formula to equate values of tokens in pools.
Constant sum formula
x + y = k
Constant mean formula
(x1 * x2 * … * xn)(1/n) = k
There are many more and each variation tries each tries to achieve an outcome, an edge for their users. Lower slippage, lower impermanent loss or even to increase slippage for very large orders that will unbalance the pool.
AMM's have been wildly successful and are one of the bedrock technologies of decentralise finance. They are not risk free but they also off there average person to participate in financial market services and make yield when providing liquidity.