• Tidak ada hasil yang ditemukan

Automated Market Makers (AMMs)

Dalam dokumen How to DeFi: Advanced (Halaman 43-49)

In our How to DeFi: Beginner book, we have gone through Uniswap, the most popular AMM. Here is a recap of how liquidity pools in AMMs work.

Unlike centralized exchanges, which have bids and ask orders placed on order books, AMMs do not have any order books. Instead, it relies on liquidity pools. Liquidity pools are essentially reserves that hold two or more tokens that reside on a DEX’s smart contract that are made readily available for users to trade against.

You can think of liquidity pools as just pools of tokens that you can trade against. If you wish to swap ETH to DAI, you will trade on the ETH/DAI liquidity pool by adding ETH and removing an amount of DAI determined algorithmically from the liquidity pool.

Depositors, known as Liquidity Providers (LPs), seed these liquidity pools.

LPs deposit their tokens into the liquidity pool based on the predefined token weights for each AMM (in Uniswap’s case - 50% for each token).

LPs provide funds in liquidity pools because they can earn a yield on their funds, collected from trading fees charged to users trading on the DEX.

Anyone can become an LP and automatically market-make a trading pair by depositing their funds into the smart contract.

With AMMs, traders can have their orders executed seamlessly without the need for a centralized market maker providing liquidity on a centralized exchange like Coinbase or Binance. Instead, orders are executed automatically via a smart contract that will calculate trade prices algorithmically, including any slippage from the trade execution. You may thus consider order book-based exchanges as following the peer-to-peer model while AMMs follow the peer-to-contract model.

What are the existing types of AMMs out there?

AMMs are a mathematical function to price assets algorithmically based on liquidity pools. Currently, several AMM formulas are utilized to cater to different asset pricing strategies.

Some of the more popular AMM formulas are as follow:

I. Constant Product Market Makers 𝑥 ∗ 𝑦 = 𝑘

The Constant Product Market Maker formula was first popularized by Uniswap and Bancor and the most popular AMM in the market.

When plotted, it is a convex curve where x and y represent the quantity of two tokens in a liquidity pool, and k represents the product. The formula helps create a range of prices for the two tokens depending on each token's available quantities.

To maintain k as constant, when the supply of x increases, the supply of y must decrease, and vice-versa. Therefore, the resulting price is inherently unstable as the size of trades may affect the price in relation to pool size. Impermanent loss may occur by higher slippage caused by large trades.

II. Constant Sum Market Maker 𝑥 + 𝑦 = 𝑘

The Constant Sum Market Maker formula creates a straight line when plotted. It is an ideal model for zero slippage trade but, unfortunately does not offer infinite liquidity. This model is flawed

as it presents an arbitrage opportunity when the quoted price is different from the market price of the asset traded elsewhere.

Arbitrageurs can drain the entire reserves in the liquidity pools, leaving no more available liquidity for other traders. This model is unfit for most AMM use cases.

III. Constant Mean Market Maker 𝑣 = ∏ 𝑡 𝐵𝑡 𝑤𝑡

The Constant Mean Market Maker formula, or also known as Value Function, was made popular by Balancer. It allows for liquidity pools with more than two tokens and different token ratios beyond the standard 50/50 distribution. Rather than the product, the weighted geometric mean remains constant. This allows for variable exposure to different assets in the pool and enables swaps between any of the liquidity pool's assets.

IV. Stableswap Invariant

The StableSwap Invariant formula is a hybrid of the Constant Product and Constant Sum formula. It was made popular by Curve Finance.

Trading occurs on a Constant Sum curve when the portfolio is relatively balanced and switches to a Constant Product curve when imbalanced. This allows for lower slippage and Impermanent Loss but is only applicable to assets with a similar value as the price of the desired trading range is always close to 1. For example, this will be useful for trading between stablecoins (DAI and USDC) and wrapped assets (wBTC and sBTC).

Source: https://curve.fi/files/stableswap-paper.pdf

This graph shows the Constant Product Market Maker (purple line) and Constant Sum (red line) curves with a Stableswap Invariant hybrid curve used by Curve Finance (blue line) in the middle. We can see that the Stableswap Invariant curve creates deeper liquidity near the Constant Sum curve. The result is a line that returns a linear exchange rate for most trades and exponential prices for larger trades.

How are prices determined on a Constant Product AMM?

Let’s look at a simple example of a Constant Product Market Maker and see how asset prices are determined algorithmically. It works by maintaining a constant product formula based on the amount of liquidity available for each asset in the pool.

To see how it works via the popular AMM, we will look at constant product market makers that Uniswap popularized:

It is important to note that the market price on AMMs changes only when the reserve ratio in the pool changes. Thus, an asset price on AMM might differ from other exchanges.

Example

Based on the Constant Product Market Maker formula x * y = k

x = the reserve token x y = the reserve token y

k = the constant total liquidity that determines the price of tokens in the liquidity pool

For example:

There are 61,404,818 DAI and 26,832 ETH in Uniswap’s DAI/ETH liquidity pool as of 21 April 2021. The reserve ratio implies that ETH’s price at the time of writing is 61,404,818 DAI / 26,832 ETH = 2,289 DAI.

Assuming 1 ETH is now valued at 2,289 DAI on Uniswap. But when the price of ETH drops to 2,100 DAI elsewhere, such as on Balancer, an arbitrage opportunity presents itself. Arbitrageurs will take advantage of the price differences by buying cheap ETH on Balancer and selling it off on Uniswap for a quick profit (ignoring the trading fee for simplicity).

Arbitrageurs will repeat this until the price reaches equilibrium between the two exchanges.

The Various Automated Market Makers (AMMs)

Dalam dokumen How to DeFi: Advanced (Halaman 43-49)