What is an Automated Market Maker (AMM)?

Automated Market Makers

The Automated Market Makers (Automated Market Makers or AMM) have become an integral part of the DeFi ecosystem, facilitating trillions in trading volume. Promoted by projects like Bancor and Uniswap in 2017/2018, AMMs provide an interesting alternative to the traditional central limit order book model.

La replication of an order book on the blockchain you run into two main problems: first, there are gas costs involved for each order that a maker wants to send or change, which becomes costly over time and inefficient. Second, since blockchain data is publicly available and easily accessible, the front running it prevents traders from executing the trades they really want.

One of the main advantages of MMAs about the order books is that anyone can supply assets to a pair to become a liquidity provider and earn trading fees. As a result, AMMs can attract more capital, resulting in greater market depth for decentralized exchanges (DEXs) compared to their centralized counterparts. So it is no surprise that this innovation has become an important foundation for the most popular DEXs and even other DeFi applications.

A brief history of MMA

Ethereum co-founder Vitalik Buterin first discussed the operation of a DEX on the blockchain with AMM in 2016, which later inspired the creation of Uniswap.

Although Bancor is credited with creating the first AMM (called an omnipool), one of the main drawbacks of this approach was that the tokens had to be paired with the protocol's native BNT token. Since this token was used as a common denominator in all pools, all exchanges required the BNT token. As a result, traders experienced slippages twice if they wanted to switch from USDC to ETH (since the general path is: USDC to BNT, then BNT to ETH).

By getting rid of the need for a network token to perform exchanges like at Bancor, Uniswap operations depend entirely on token reserves in a liquidity pool, thanks to a simple but elegant formula: x * y = k that revolutionized DeFi. The success of Uniswap since its launch in November 2018 eventually spawned the creation of dozens of similar AMM-based DEXes and showed that AMMs held great promise as a new financial primitive.

Although Uniswap made great strides with its first two implementations, since liquidity is provided evenly across the range prices from zero to infinity, capital efficiency was lacking. This problem was solved with the introduction of concentrated liquidity in Uniswap v3, where capital efficiency was greatly improved, resulting in higher liquidity and less slippage.

For LPs, it reduces the risk of permanent loss because liquidity is provided in a range of prices. Another favorable aspect of concentrated liquidity is the simplicity and flexibility it allows, with Uniswap v3 being able to take the form of any possible AMM.

Now that we know a bit about the background of MMAs, let's see how they work.

MMA explained step by step

To facilitate trading, AMM replace order books with liquidity pools. A liquidity pool is basically a smart contract that holds reserves of two different tokens in a particular ratio. The smart contract code specifies how reserves determine prices, the rules for liquidity provision and trading, as well as the fees that traders incur when exchanging through the pool.

The liquidity providers (hereinafter LP) can supply crypto assets to a pool reserve to earn trading fees from each transaction and receive token rewards for supplying liquidity to a particular pool. Token rewards are typically issued in the governance token of the protocol, giving holders voting rights on the development of the protocol and its AMM.

To keep track of the portion of fees an LP will receive, pool shares are credited as LP tokens in proportion to your liquidity contribution as a fraction of the total pool. That means if an LP provides 10% of the assets, they will earn 10% of the trading fees generated by the pool. The LP tokens that represent your liquidity position can be burned at any time to remove liquidity from the pool.

The main innovation of the MMAs over the order book model is that anyone can provide liquidity and earn a share of trading fees, which lowers barriers to participation. In the centralized order book model, the role of an LP is usually reserved for a select few high net worth individuals or companies. With the advent of MMA, this feature opens up to a much wider audience.

From a trader's perspective, the advantage is that you can get liquidity immediately when interacting with a pool, and there is no need to wait for a matching command. If a trader wants to buy or sell a token, he can go to the pool, specify the asset and the amount he wants to trade. The smart contract then will provide an exchange rate based on the peg curve, which is calculated according to the reserves of the two different tokens in the pool.

As an example, consider a pool for ETH-USDC with the following reserves: ETH = 1 and USDC = 500. Following the Uniswap v000 model, the AMM price is equal to the reserve ratio (10 USDC). Once the merchant buys 000 ETH with $2 in USDC, the AMM removes 150 ETH from the pool and credits these tokens to the merchant's wallet. The AMM also adds the trader's 1 USDC to the pool. Based on the fee parameter, which is set and calculated by the smart contract, the merchant will be charged a percentage of the transaction from it.

After the trade has been executed, there will be slightly less ETH in the pool and slightly more USDC. Since the peg curve algorithmically determines the price of ETH as the ratio of asset amounts, ETH price falls to around 147 USDC. If the trader had sold ETH for USDC, then the ratio would have moved in the opposite direction and caused an increase in the price of ETH.

For larger trade sizes, the difference between the spot price and the realized price (also known as slippage) increases as the number of tokens traded increases relative to the pool size. Therefore, AMMs force those entering larger transactions to pay a higher price compared to smaller transactions. Therefore, a certain slippage tolerance must be set for orders to be executed.

When a transaction occurs that causes the price quoted by the group to deviate significantly from the broader market value, arbitrageurs can intervene and readjust pool amounts to benefit from the price difference in the AMM and other trading venues.

For example, if a big sell-off of ETH caused the price to drop from 150 USDC to 135 USDC, but the market average remains close to 150 USDC, then arbitrageurs can buy ETH from AMM and proceed to sell it on other trading venues. . As arbitrageurs buy more ETH through the AMM and more ETH is withdrawn from the liquidity pool, the price will eventually converge with the market price of 150 USDC.

As we have seen before, any exchange alters the composition of pool assets and the exchange rate is automatically updated, changing the value of the entire group. As the price of an asset fluctuates, so does the value of the pool, meaning the value of the LP's pool share also fluctuates. Ideally, an LP wants to remove liquidity as close to the price at which they entered the position as possible, as they may incur a loss when assets are withdrawn from the pool after a price change, known as permanent loss. However, the impermanent loss may be offset by the fees and token reward earned by the LP.

MMA in action

In this section, we will examine three popular AMM models to highlight the different approaches: Uniswap, Corners y Balancer.

Uniswap

There are different variations of MMA with different curve designs of Union.

The Constant Product Market Maker model regulates the price by keeping the mathematical product of the quantities of two assets constant. For example, Uniswap versions 1 and 2 are known as CPMMs, where the multiple of the amount of two different tokens is held constant according to the following formula:

[highlight]x * y = k[/highlight]

Where x is the amount of one token (eg ETH), y is the amount of another token (eg USDC), and k is a constant.

In v2, the group's smart contract assumes that the reserves of the two assets have the same value. So an LP would have to provide ETH and USDC in a 50:50 ratio to the pool to keep k constant.

In v3, the liquidity provision can be concentrated in one part of the curve of bonds, reducing slippage and improving capital efficiency. LPs in v2 would provide liquidity across the full price range of the bond curve, meaning much of the liquidity is not consumed. With concentrated liquidity, LPs can choose a range in which they would provide liquidity and can adjust their positions based on market conditions.

Therefore, Uniswap v3 moves away from the constant product model, combining this model with a constant-sum market maker. Operations are not performed along the single-level curve determined by the equation x * y = k, as in previous versions. Liquidity can be discontinuous, meaning each LP position could be drained from a single pool, which cannot happen with v1/v2.

Corners

Curve is an example of Hybrid Feature MMA, which combines the constant product and constant sum models to provide an automated market maker that is more efficient for stablecoin trades.

A Curve v1 liquidity pool consists of two or more assets with the same relationship, such as USDC and DAI, WBTC and renBTC, or stETH and ETH. Stablecoins have seen a massive increase in adoption, Curve has become the DEX with the highest total value locked, facilitating stable trades with very low fees and slippage.

As the assets in a pool become unbalanced, the peg curve takes the shape of a constant output curve (similar to Uniswap v1/v2). However, when assets are offered such that the exchange rate is close enough to parity, the bond curve shifts toward a constant-sum model:

The benefit of a constant-sum approach is that it eliminates the slippage found in constant product models. The hybrid model used by Curve is illustrated by the 'stableswap invariant' in the following figure:

In Curve v2, the price scale is constantly updated according to an oracle internal price chart to better represent the market price and ensure that trade stays close to break-even. The market maker feature can be pegged at any price, which suits all tokens rather than stablecoins or assets being traded together.

Balancer

The balancer protocol allows each pool to have more than two assets and be supplied in any ratio. Each asset pool is assigned a weight in the pool creation where the sum of the weights is equal to 1, where the weights do not change with the provision or removal of liquidity, but instead represent the value of the pool as a fraction of the value of the group.

Balancer generalizes the concept of a constant product applied by Uniswap to a geometric mean, giving rise to what is called a constant mean Market Maker. This model also adds another player in the MMA in addition to the LPs and merchants, known as controllers, who are tasked with managing a group.

[highlight]x^(0,2) + y^(0,3) + z^(0,5) = k[/highlight]

With Balancer smart pools that use a constant average formula (like the one shown above), we can create liquidity pools with up to eight tokens, allowing for more customization.

Therefore, Balancer funds are like index funds that build a portfolio of assets with fixed weights. The graph below compares the curve used by Balancer with two assets (one weighted at 25% and the other at 75%) compared to the Uniswap v2 curve.

swing

 

For example, we can specify any weight for a bullish or bearish pool. A bullish group for ETH-USDC can be created by specifying a weight of 90% for ETH and 10% for USDC. Alternatively, a bearish pool can be launched by doing the opposite.

Other AMM DeFi Applications

DEXs are just one use case of protocols using the AMM algorithm, which also forms the basis for other applications in DeFi.

A notable example is Liquidity Bootstrapping Pools (LBP) from Balancer. LBPs are used for fair token releases, being Perpetual protocol the first project in do it with the token $PERP. Unlike the MMAs we have explored so far, pool parameters can be changed. A pool of two tokens is set up with the project token, such as PERP, and a collateral token, such as USDC.

It initially sets the weights in favor of the project token, then gradually changes to favor the collateral token at the end of the sale. Token sales can be calibrated so that the price drops to the desired minimum. In this way, an AMM is used to function similarly to an auction, where early buyers will pay a higher price, and over time, the project's token price will decrease until the allocation is complete.

We can find good examples of MMA applications in DeFi outside of DEX at automated loans, with projects like Notional Finance y Yield protocol. Both projects facilitate fixed-rate, fixed-term crypto asset lending and lending with a constant power-sum peg curve.

AMMs in these cases are designed to trade ERC-20 tokens similar to zero coupon bonds that can be redeemed for the underlying asset at a particular future date. A constant power sum curve embeds the time to expiration into the price, allowing users to trade based on interest rates rather than price.

MMAs are one of the defining innovations to emerge from the DeFi space and have led to the creation of a variety of decentralized applications, including DEXs and automated lending. Research on different and improved variations is still ongoing (such as TWAMM) further expanding the design space and the emergence of a new generation of protocols created with AMM.

Leave a comment