Blended Automated Market Makers - bAMM

AB Research introduces a novel parameterized family of functions that generalize and blend Automated Market Makers.

Motivation

The first work of combining the best worlds of different constant function market makers was the one of Stableswap [2], which introduced the idea of the “amplification coefficient”. In a way, this coefficient defines the blending level between two types of markets: constant sum and constant product market makers. Specifically, this coefficient χ generates an invariant which is the constant-product when χ = 0, the constant-sum when χ = ∞  and an “in-between” formula when 0<χ <∞.

Top: Plot comparison of StableSwap invariant with Uniswap (constant-product) and constant sum invariants. Bottom: Stableswap’s invariant formula.

This idea of 1) non-static and also 2) mixed Constant Function Markets seems to be a very promising area where still much work needs to be done in order to discover its full potential.

In this article, we will investigate a specific mixing strategy inspired by Yieldspace’s “constant power sum formula” and evaluate its performance regarding impermanent loss and slippage.

But first, let’s give some background on Constant Function Markets!

Background

The most exciting advance in DeFi has been the development of Decentralized Exchanges (DEXs) and particularly the ones of Automated Market Makers (AMMs). The concept of AMMs has been studied extensively starting from the algorithmic game theory field, and the logarithmic market scoring rule - LMSR [2] of Hanson. These DEXs, such as Bancor [3], Uniswap [4] [5], and StableSwap/Curve [6], have become very popular and the research community seems to be really keen on discovering new properties and formulations of them.

The most popular case of AMMs, which is widely applied in decentralized applications - dApps [7],  is the one of Constant Function Market Makers (CFMMs). CFMMs provide decentralized exchanges of digital assets based on a pre-defined mathematical function (curve), which can potentially allow for a wide range of exchange prices. The fundamental idea of CFMMs is the liquidity pool, a smart contract that holds the tokens of a trading pair in a certain ratio, which allows for gas-efficient, on-chain trading. The liquidity pool concept is also the difference between AMMs and traditional centralized exchanges, which depend on a third party to keep track of all the bids and asks in an order book setting.

The AMM game

Naturally, we can think of AMMs as a “game” between two players. The Traders, who exchange assets on the liquidity pool, and the Liquidity Providers (LPs), who are willing to provide (mint) or extract (burn) assets in the pool and accept trades in exchange for a fee. There is also a special case of traders, the Arbitrageurs who exploit differences in the price of a reference market and the pool price of an asset to make a profit for free. For example, if the pool price is less than the reference market price, arbitrageurs will buy the asset on the pool and sell it on an order book-based exchange for a profit.

Constant Product Market Makers

A constant product market maker, first implemented by Uniswap satisfies the equation:

where x > 0 and y > 0 are reserves of assets X and Y respectively and k is a constant.

Constant Sum Market Makers

The simplest CFMM is the constant sum market maker (CSMM). For reserves x, y for X and Y assets a CSMM holds the sum of the reserves constant:

Constant Mean Market Makers

A constant mean market maker is a generalization of a constant product market maker, allowing for more than two assets of equal weights. First introduced in Balancer [8], constant mean markets satisfy the following nD equation:

where xi  are the reserves of asset  x1, x2, …, xn, w ∈ Rn are the weights associated with each asset and k ∈ R the constant product.

The constant mean markets ensure that the weighted geometric mean of the reserves, xi for i = 1, …, n, stays constant. In this case, the weights should all satisfy w ≥ 0 and i =1nwi=1.

In all the cases above when trading an amount of ∆x for an amount ∆y the reserves must change in a way that their product will remain equal to the constant k.

For example for the Constant Product formula, trading Δχ amount of an asset X for some amount Δy of an asset Y then the following

trading function holds (in the presence of trading fees γ):

Metrics

In the CFMM game there are two metrics that each player cares for: Slippage (traders) and Impermanent Loss (Liquidity providers). Slippage as a function expresses the difference between the spot price of an asset in the pool and the effective price obtained after the completion of the trade. Specifically, suppose a trader wants to exchange ∆x units of an asset X when the pool state is (x0, y0). After the completion of the trade the new pool state will be (xn, yn), where xn = x0 + ∆x then slippage is defined as:

Impermanent loss, on the other hand, occurs when liquidity providers pull out assets from the pool during a large price swing. In this case they will suffer a loss of total asset value, compared to simply holding the assets. As we saw before, when a trade occurs the price of an asset may change as we move from p0 in the (x0, y0) state to pnto the new state (xn, yn). This potential decrease of the pool’s value is the impermanent loss and is given by the following formula (for the derivation process see [9]):

Where pX is the price of an asset X in terms of an asset Y given by the following equation:

The blended AMM

We recall the Constant Sum-Power formula of the YieldSpace protocol [1]. In the original paper the authors introduce a new invariant that is optimized for market-making between fyTokens and their target tokens, defined as follows:

where y represents the reserves of the fyToken (such as fyDai), x represents the reserves of the target token (such as Dai) and t represents time to maturity.

They also state that such an invariant should be treated as a pricing formula in “yield space,” rather than “price space” and it has the unique property that the marginal interest rate of fyDai that is offered by the pool at any time is equal to the ratio of the fyDai reserves to the Dai reserves.

Here we will use the Constant Sum Power formula as inspiration in order to introduce the idea of a generalized and parametrized family of constant function markets: The blended Automated Market Maker - bAMM. Furthermore, we will show that one can derive some of the traditional constant function market makers from it as special cases.

Suppose we have a pool of two assets X  and Y, then the bAMM formula is defined as follows:

where x and y are the respective reserves of the assets, α and β are the weights associated with each asset and t [0,1) is the blending parameter.

The pricing function of an asset X in terms of an asset Y follows the constant mean formula pricing logic and is given by the following equation:

Popular AMMs as special cases

One can easily see that we can retrieve the constant sum, mean and product invariants given certain values of t in the bAMM formula. Specifically,

  • For t=0 we get the Constant Sum invariant.
  • For t → 1 we get the Constant Mean invariant.
  • For t → 1 and α=β=1/2 we get the Constant Product invariant.

Although the Constant Sum derivation is straightforward, the derivation of the Constant Mean may not seem really easy at first glance however, it follows the same logic as the one in YieldSpace formula. Thus we encourage the reader to go through Appendix D in the original paper [1]. Finally as for the Constant Product derivation, it is an immediate consequence of the Constant Mean proof.

Consequently, a natural way to think of t is the blending level between CSMM and CMMM Specifically, t = 0 or t → 1 indicates no blending as they converge the bAMM formula to the two extremes, whereas t = 0.5 indicates their maximum blending level i.e. you have 50% of each.

Liquidity curves for asset swaps for multiple values of t on the bAMM formula. For t=0.99 the curve represents the constant mean (weighted product) function and for t=0 the constant sum function. The intermediate curves increase their curvature as t→1. Here, the value of the constant k is fixed.

Metrics on bAMM

Cumulative Impermanent Loss variation (y-axis) for different values of t between a subset of blocks (x-axis) throughout a trading period. Top: The non-stablecoin case of USDC-WETH pool. Bottom: The stablecoin case of USDC-USDT.

By performing a grid-search for different values of t in the [0,1) range over a trading period based on the input/output volume of each trade, we compute the new pool state and also the impermanent loss based on the closed form we have introduced above. We track its variation on a sequence of trading blocks of the chain and we observe that different values of t lead to different traces on the plot indicating the different effect of the blending level for each pool.

Specifically, we can see that for stable pools (USDC/USDT, DAI/USDT), when the value of t increases then the the impermanent loss follows accordingly. However, for the non-stable pools (USDC/WETH, USDT/WETH), we notice that the opposite happens.

Average Slippage for 1000 values of t in the [0,1)  range for the USDC/WETH non-stable pool.

Another interesting plot here shows that regarding slippage for the USDC/WETH pool, values of t that lie on the (0.4, 0.6) area return the minimum average slippage across the trading period. Thus, it is obvious that there are cases where the traditional Constant Sum and Constant Mean/Product settings are suboptimal regarding certain metrics. More practically, in the example above a higher blending level (close to 0.5) of CSMM and CMMM could lead to more beneficial trading experience for the users.

And now what?

cIt is obvious that such a generalised family of functions as the one of bAMM could potentially create mutual profits for both the traders and the liquidity providers by adjusting its formula given certain features.

The dynamic design of AMM functions is an idea that has been around the field for the last two years but no finalized DEX has come out as a product. It would be interesting to see AMMs as bAMM that given certain features, could be able to self-adjust their parameters and simultaneously benefit multiple players of the AMM game when given certain metrics such as slippage, portfolio value, impermanent loss, etc.

References

[1] Allan Niemerg, Dan Robinson, and Lev Livnev, Yieldspace: An automated liquidity provider for fixed yield tokens, (2020).

[2] R. Hanson, “Logarithmic markets scoring rules for modular combinatorial information aggregation,” The Journal of Prediction Markets, vol. 1, no. 1, pp. 3–15, 2007.

[3] E. Hertzog, G. Benartzi, and G. Benartzi, “Bancor protocol: continuous liquidity for cryptographic tokens through their smart contracts,” tech. rep., 2018.

[4] H. Adams, N. Zinsmeister, and D. Robinson, “Uniswap v2 core,” tech. rep., 2020.

[5] Hayden Adams, Noah Zinsmeister, Moody Salem, River Keefer, and Dan Robinson. Uniswap v3 core. Technical report, 2021.

[6] Michael Egorov. StableSwap - efficient mechanism for Stablecoin liquidity (2019).

[7] W. Cai, Z. Wang, J. B. Ernst, Z. Hong, C. Feng and V. C. M. Leung, ”Decentralized Applications: The Blockchain-Empowered Software System,” in IEEE Access, vol. 6, pp. 53019-53033, 2018.

[8] F. Martinelli and N. Mushegian, “Balancer: A non-custodial portfolio manager, liquidity provider, and price sensor,” 2019.

[9]  Understanding the XYK model of pooled liquidity: https://medium.com/phoenix-finance/understanding-the-xyk-model-of-pooled-liquidity-7340fdc20d9c