Constant Product Market Maker (CPMM) - Powering the global trading in DeFi era - State of adoption in DEX (P.4)
Constant Product Market Maker - Powering the global trading in DeFi era
Pricing formula and swap rate function
Ethereum founder Vitalik Buterin came up with the idea for a constant product (Andrea P, 2021). His proposed approach is to adopt the style of “on-chain automated market maker” used in prediction markets in decentralized exchange settings (Vitalik, 2016). As analyzed the business model of AMM-based DEXes, the liquidity pool includes x units of token A, y units of token B. For any quantities of (x, y), the exchange function is:
x*y = k (for some constant k)
for x, y > 0; k > 0
k can vary in the version where anyone can invest, but only during investment/withdrawal transactions, not during trading (Vitalik ,2016).
LMSR or AMMs design cannot predict a specific price (Guillermo et al, 2019). Early Ethereum-based AMMs such as Bancor (E.Hertzog et al, 2017) adopted the function called “bonding curve” in which the cost of an asset is based on the total available supply (tokens are minted or burned). Meanwhile, Uniswap proposed another pricing approach that does not require the ability of supply adjustment to determine an asset's price (Y. Zhang et al, 2018). The pricing function of Uniswap’s AMM relates the number of assets in reverse to their marginal price (the implicit derivative of the curve xy=k) suggested by Vitalik; this price is changed on a regular basis as the reserves fluctuate with each trade. Uniswap and its AMM model are conceptually similar to the bonding-curve approach, but it is a narrow range of applications and a specific case of CPMM, this research focuses only on Uniswap V2 to explore how the CPMM model works. Vijay Mohan (2022) explains the CPMM model in the following way:
Suppose a token pair: token A is ETH, token B is one of ERC-20 tokens
Initial amount ETH and B x0= 10 ; y0 = 500
Initial pool k0 = x0y0= 5000 (k is constant)
AMM reserve (x0, y0)
Assumption 1: trading fee 𝜏 = 0:
Type 1.1: Assume the trader wants to sell 1 ETH for token B
x1 = 11 ETH ; y1 = k0x1 = 500011 = 454.5454
The change in the pool reserves of token B:
y1 - y0 = -45.4546 token B (negative)
This quantity is sent to trader’s accounts which causes the fallen reverses of token B in AMM.
It means that:
After the transaction, AMM’s reserve profile has changed into (x0, y0)
and k0 = x1y1
The bid (b) price (P) of one unit of token A in terms of token B (B/A):
In this example of ETH: PB/Ab = 45.4546 B/ETH
Type 1.2: In contrary, traders wants to buy 1 ETH from the pool
x1 = 9 ; y1 = k0x1 = 50009 = 555.556
The change in the pool reserves of token B:
y1 - y0 = 55.556 token B (positive)
The ask (a) price (P) of one unit of token A in terms of token B (B/A):
In this example of ETH: PB/Aa = 55.5566 B/ETH
If there is immeasurably small change in amounts of tokens and no trading fee:
PB/Ab = PB/Aa = y0x0 = PB/A
It means that:
The single price PB/A equals to the ratio of the two reserves (y0x0)
The price of one unit B in terms of ETH: PA/B = 1PB/A = x0y0
If the trading fee 𝜏 = 0, k is stable
Assumption 2: trading fee 𝜏 ≠ 0:
This example uses the trading fee of Uniswap V2 (Uniswap.org) 0.3% and it is added to the liquidity pool. The trading fee is: 𝜏 = 0.3%
Type 2.1: Trader wants to sell 1 ETH for token B
Transaction cost of selling 1 ETH: 𝜏 x 1 = 0.003 ETH
The remaining amount of ETH: (1 - 𝜏 ) x 1 = 0.997 ETH
Stage 2.1.1: After deducting the cost, the trade is executed utilizing initial constant k0
k0 = 500
Interim amount of ETH: x1' = 10.997 ETH
Amount of token B: y1 = k0x1' = 500010.997 = 454.669
The change in the pool reserves of token B:
y1 - y0 = -45.331 token B (negative)
The bid (b) price (p) of ETH when a trading fee has been applied:
pB/Ab = 45.331 B/ETH
Stage 2.1.2: When the fees are added to the liquidity pool, a new constant k1 is created.
If the initial version of k proposed by Vitalik is constant during trading, Uniswap's version of k can vary in case of the trading fees. The term “constant” can be confusing.
The final balance of ETH: x1 = 11, y1 = 454.669
and k1 = x1y1 = 5001.359
consequently k1 > k0
The change in k: k1 - k0= 1.359
If comparing the bid price of ETH with and without the trading fees:
pB/Ab (45.331) < PB/Ab (45.4546)
The more transaction cost is, the less token B per ETH trader receives and the larger the amount of transactions is executed on Unsiwap V2, the faster k expands.
Type 2.2: Traders want to buy 1 ETH from the pool
A trading fee is charged on the amount of token B
Deposited amount of token B: Δy
Remaining amount of B after fee: (1 - 𝜏) x Δy
Trade is executed after the deducted fee
Balance of ETH: x1 = 9
Balance of token B: y1 = k1x1 = 50009 = 555.556
Amount of token B before fee: Δy = y1 - y0 1 - 𝜏 = 55.723
The ask (a) price (p) of ETH with trading fee:
pB/Aa = 55.723 B/ETH
If comparing the ask price of ETH with and without the trading fees:
pB/Aa (55.723) > PB/Aa (55.5566)
Combining (1) and (2), the bid-ask spread is larger than the case without trading fee. It implies that there are less arbitrage opportunities in the context of greater transaction costs. On the other hand, the larger the bid-ask spread, the riskier and less liquid the exchange is likely to be.
The exchange rate (E) between tokens A and B is x number of unit A required to purchase y number of unit B (Massimo et al, 2022)
X (A,B) = PAPB
As referred to, the swap rate function, which estimates the token exchange rate using an algorithm, is one of the key economic mechanisms of the AMM model. In AMM, participants are encouraged to swap tokens in order to maintain their swap rates consistent with the exchange rate provided by price oracles. In other words, if the swap rate in AMM is greater than the oracle's exchange rate, rational individuals will trade to close the difference. Aside from the present AMM's balances, the swap rate is determined by previous activities in order to reduce the potential of arbitrage opportunities so that the swap rate moves closer to the exchange rate (Massimo et al, 2022). Even when there is no asymmetric information, LPs suffer arbitrage difficulties, then impermanent loss and the pool suffers the liquidity problem if the exchange rate X swings (Agostino, 2021).
Arbitrage problem
Some researchers focus on arbitrage problems of the AMM, Vijay Mohan (2022) provides a systematic study on two-point arbitrage and triangular arbitrage of Constant Product model.
Applying two assumptions above to the two-point arbitrage:
Suppose: External market price of token A: MB/A = 49.9
Internal price of token A in CPMM: PB/A= 50
Assumption 1: trading fee 𝜏 = 0:
Profit for arbitrageurs: PB/A - MB/A = 0.1
In this case: Demand for token A in external market increases which results in the increasing external market price MB/A. Then, arbitrageurs will sell back token A in AMM platforms, price of token A, PB/A decreases until the arbitrage disappears.
The equilibrium point: PB/A = MB/A
Assumption 2: trading fee 𝜏 ≠ 0:
If: 𝜏 = 0.3%
pB/Ab = 49.85 < MB/A
pB/Aa = 50.15 > MB/A
It is not profitable to arbitrage between the external market and the AMM, especially in the case of trading fees.
pB/Ab ≤ MB/A ≤ pB/Aa
Two-point arbitrage takes advantage of pricing discrepancies between marketplaces, on the other hand, triangle arbitrage refers to the internal uniformity of prices supplied within a single market and requires three price quotes to execute.
Suppose that token A, B, C are available for trading, and a trader can switch between any pair. The first CPMM model is applied in Uniswap V1 built on the Ethereum blockchain, it takes ETH as the native settlement token. For any transaction between ERC-20 tokens, ETH is an intermediate point.
Token A is ETH
The trader wants to swap token B to C: B → ETH → C
If the trading fee 𝜏 = 0:
Swap B → ETH in ETH-B liquidity pool: the number of units of token B depends on the price of token B (PETH/B). The PETH/B units of B can then be changed to C at a cost of PC/ETH.
The price of token C in terms of B is: PC/B = PC/ETH x PETH/B
In Uniswap V2, a special smart contract is constructed for direct swap between ERC-20 tokens. Adam et al (2020) acknowledge the extra functionality of this development, but they don't go into detail about the new arbitrage opportunities it opens up. Uniswap V2 just introduces the potential of three-point arbitrage, which was not presented in V1.
In this case, three liquidity pools are available: A – B, A – C, B – C with price in turn PB/A , PA/C , PB/C
When PB/C < PB/A x PA/C and no trading fee, traders can make profit by buying token C in B – C liquidity pool then selling it through C → A → B.
Equilibrium point: PC/B x PB/A x PA/C = 1
If applying the trading fee (𝜏 ≠ 0), no arbitrage opportunity happens when:
pB/Ca ≥ pB/Ab x pA/Cb and pB/Aa x pA/Ca ≥ pB/Cb
From the theoretical analysis of arbitrage, the Constant Product model is designed to minimize the arbitrage opportunities. Other studies provide further detail of the arbitrage problem in AMM. Arbitrage issue doesn't stem from the nature of the pricing model, it results from the slow (on-chain) trading which is one of the drawbacks of the decentralized exchanges (Daian P et al, 2019). Because transactions on the Ethereum network are published, opponents can spot profitable transactions before they are carried out and put their own orders with greater fees to get ahead of the victim. Market and system stability are jeopardized by front-running attackers. Arbitrageurs aggressively optimize transmission delay and perform priority gas auctions to get ahead of successful transactions (Micheal L, 2014), resulting in high transaction costs for normal users in blockchain ecosystems. Liyi et al (2021) study the sandwich attacks, the attackers place one order just before (front-run) the normal transaction and another just after it (back-run) to profit from the difference in exchange rates. Ye Wang et al (2022) proposed a broader framework and an empirical study of cyclic arbitrage with n token with n trades. The number of exploitable arbitrage opportunities in Uniswap V2 increased over time. The Uniswap market grew from May to September 2020, reaching more than 3,000 cycle transactions every day and the overall revenue from cyclic arbitrage with ETH was 34,429 ETH (from May 2020 to March 2021).
Slippage problem and Impermanent loss
In the exchange function of the CPMM model: xy = k, the slope of k0 is unchanged due to the homogeneous function, and reverses of tokens have never been frozen. Between two models, the marginal price k0 of CPMM is a curve while CSMM’s is a straight line. At the Constant Product model (CPMM), the amount of deposited token determines the marginal exchange rate yx. That the exchange rate from A to B tokens is positive drops the volume of token A trade in Δx, resulting in “slippage” (Agostino, 2021). The overall slippage will be higher for a larger trade, acting as a barrier for a trader to conduct large trades with the LP (Bhaska et al, 2021).
Suppose traders want to buy Δx units of token A
When the liquidity pool is at (x0, y0) with price p0: Δy0 = p0Δx
For a new point (xn, yn): xn = x0 - Δx
Δy = yn - y0
Slippage happens when: Δy ≠ Δy0
The price p0 of the original pair of value (x0, y0) changes to a new price pn at the point (xn, yn), which leads to a decrease in the value of the liquidity pool, on the other hand, results in an impermanent loss (Bhaska et al, 2021). The pool price in Uniswap V2 is fundamentally dynamic, and the size of trades relative to pool size has varying effects on pool pricing. The larger the trades, the greater the risk of slippage and divergence loss (impermanent loss). Let take the previous token pair as an example of the impermanent loss in which token A is ETH and token B is a stablecoin:
At t0:
The initial ETH/B pool: x0= 10, y0= 1000
The price of ETH in terms of B: PB/ETH0 = 100
LP stakes 10%: 1 ETH and 100 B
k = 10 * 1000 = 10,000
At t1:
The price of ETH in terms of B PB/ETH1 = 200
Worth of the stake if holding: 1 * 200 + 100 = 300 B (1)
The transaction changes total reserves of the pool, if there is no trading fee:
The ETH/B pool: x1= k/PB/ETH1= 10,000/200 ≈ 7.07
y1 = k * PB/ETH1= 10,000*200 ≈ 1,414.21
10% stake of LP: 0.707 ETH and 141.421 B
Worth of the stake after the change: 0.707 * 200 + 141.421 = 282.821 B (2)
Compare (1) and (2), LP losses: 300 - 282.821 = 17.179 B
Impermanent loss: 17.179300× 100⁒ = 5.72⁒
The magnitude of the slippage, which is measured by the curvature of the pricing curve, influences the equilibrium results. The curvature of the pricing curve is based on k where k ∈ [0;1]. If k = 0, the pricing curve is a straight line and becomes the constant sum. The largest curvature of the pricing curve happens when k = 1 and the curve becomes a constant product (Fig. 12).
In contrast, the Constant Sum model (CSMM) is represented as x + y = k which has no slippage (Chainlink, 2020) but quickly depletes the liquidity pool because any arbitrageur might profit on current price variations by acquiring the entire pool without slippage (Johannes et al). Due to the fixed price and constrained liquidity, constant sum is only ideal for stablecoins and just a theoretical interest (Chainlink, 2020).
Liquidity Problem
The theory of AMM (Massimo et al, 2022) states that the reserves in funds must have not been exhausted to avoid the “liquidity freeze”. The aim of AMM is to incentivize the participation of Liquidity Providers. Agostino et al (2021) suggest a boundary k* of liquidity pool where k* ∈ (0,1) and the trade-off between the efficiency and liquidity provision of an AMM.
Rising in k for k ∈ [0, k*]
Reducing in k for k ∈ [k*, 1]
If k < k*, the exchange rate reacts slowly to the number of units exchanged, the slippage is minimal, and the curvature of the pricing curve is too narrow (it’s likely to expose to a constant sum state). In this situation, traders need to deposit a little amount of token A in exchange for token B, hence, the trading fee is quite little. The liquidity providers lose money, while the arbitrageurs can exploit these opportunities.
If k > k*, there are no longer arbitrageurs but slippage, the curvature of the pricing curve is too high. The higher the trading fee is, the more rewards liquidity providers get, paradoxically, traders become less willing to trade, fee revenue declines.
If k = k*, the pricing curve is at balance to maintain liquidity pool, which creates motivation for both liquidity providers and traders.
Additionally, in Uniswap V2, for each token pair A-B with liquidity pool (x,y), the change of k occurs after each transaction. If x1y1= k1 > x0y0 = k0, liquidity level at k1exceeds the liquidity level at k0. Vijay Mohan (2022) concludes an unreal state of liquidity pool in the CPMM of Uniswap:
Assume that a liquidity provider double the number of token availables in the pool
For the homogeneous function xy = k, we have: 4xy = 4k
It means that the constant k has quadrupled despite the fact that liquidity has only doubled for all manner of reasons due to the doubling of token volume. Normally, in a liquidity pool with the ratio 1:1, only 50% of the tokens have been accounted for by the LP, in this case of doubling token numbers, LP have received 75%. The design of the CPMM function is simple to execute efficient liquidity accumulation, but rather it implies that many of the assets in the pool are never utilized (Adams et al, 2021), in other words, capital inefficiency.
Challenges of CPMM model
In order for the equilibrium point, CPMM has suffered from the rebalancing cost (Vijay Mohan, 2022). LP must rely on trading fees to compensate for the loss. Tassy and White (2020) illustrate that rebalancing can help reduce the detrimental impact of losses on compounding in certain situations. Transaction fees play an important role in the problems of CPMM, such as the sandwich attacks referred to. The type of tokens being traded is also essential for establishing fees. Token with low volatility and stable price elasticity can afford a lower fee and encourage trading activity. The stability of price reduces the requirement for rebalancing. Increased trading fees profit liquidity providers and diminish exploitation, but they deter trade and arbitrage, lowering efficiency. Reduced fees have the opposite impact. Overall, determining the best fees for an AMM is difficult because all of these trade-offs must be considered (Tassy and White, 2020). Besides, most decentralized exchanges are deployed on Ethereum blockchain (defiprime.com) with the problems of high gas fee and pending time (Jose et al, 2020). Its high fees are a cause for concern for the entire crypto market due to its popularity. With Ethereum falling out of favor due to its persistently high fees, DEX platforms are poised to fill any gaps it may leave by deploying on other blockchains such as Binance Smart Chain, Polygon, Avalanche and recently Optimism (defiprime.com). Fee issues in both CPMM design and the underlying blockchain have a direct impact on the market liquidity of the Decentralized Exchanges.
So as to optimize the trading volume, AMM must find a balance between maximizing liquidity provider rewards and minimizing the trading costs (KPMG, 2021). The main factors affecting liquidity provider returns are impermanent loss and capital efficiency. The more the transaction price necessary to compensate liquidity providers, the greater the divergence loss or lower the capital efficiency.
Comments
Post a Comment