ALEXGO
  • 😀What is ALEX?
  • 📈Automated Market Making
    • Our Design
  • 🧙‍♀️Bitcoin Oracle
    • What is the Bitcoin Oracle
  • 🩸XLink
    • XLink
  • 🚅Orderbook
    • What is the Orderbook?
    • Understanding the Orderbook
  • 🚀Launchpad
    • What is the Launchpad
  • 📚Whitepaper
    • Automated Market Making of Trading Pool
    • Automated Market Making of Yield Token Pool
    • Automated Market Making of Collateral Rebalancing Pool
    • Dive Into Collateral Rebalancing Pool!
  • 🎮Developers
    • Networks
      • Mainnet
      • Testnet
    • Protocol Contracts
      • amm-pool-v2-01.clar
      • amm-registry-v2-01.clar
      • amm-vault-v2-01.clar
      • farming-campaign-v2-02.clar
      • amm-pool-v3.clar
      • self-listing-helper-v3a.clar
    • REST API
Powered by GitBook
On this page
  • Abstract
  • Introduction
  • AMM and Invariant Function
  • Properties of AMM
  • ALEX AMM
  • Trading Formulae
  • Out-Given-In
  • In-Given-Out
  • In-Given-Price / Yield
  • Transaction Cost on Notional and Yield
  • Concentrated Liquidity
  • Pool with interest rate floored at zero
  • Range-bound Pool
  • Appendix 1: Generalised Mean when d=2
  • Appendix 2: Liquidity Mapping to Uniswap v3
  • Appendix 3: Derivation of Actual and Virtual Token Reserve
  1. Whitepaper

Automated Market Making of Yield Token Pool

PreviousAutomated Market Making of Trading PoolNextAutomated Market Making of Collateral Rebalancing Pool

Last updated 1 year ago

Abstract

ALEX aims to provide a fixed rate borrowing and lending service with pre-determined maturity in the world of decentralised finance (DeFi). We include forward contracts in our trading pool, with Automated Market Making (AMM) engine in association with generalised mean. While we formalise the trading practise swapping forward contracts with underlying asset, we incorporate the latest innovation in the industry - concentrated liquidity. Consequently, liquidity provider of ALEX can save decent amount of capital by making markets on a selected range of interest rate.

Introduction

ALEX stands for Automated Liquidity EXchange. It is a hybrid of automated market making and on-chain loanable fund built on Stacks blockchain network. While lenders and borrowers can minimise uncertainty by securing the loan with fixed rate and tenor, liquidity providers are able to take advantage of our capital efficiency mechanism by imposing cap and floor on the interest rate. This allows liquidity to be offered on parts of the curve that contains majority of trading activities and leads to efficient capital management.

On ALEX, lending and borrowing activities are facilitated by a forward contract based token “ayToken”. It is similar to an OTC bilateral forward contract in the conventional financial market, which specifies underlying asset “Token” and expiry date. This paper assumes ayToken is minted and ready to be exchanged. Lenders purchase ayToken at a discount to the spot Token price when the contract is initiated and reclaim underlying asset upon expiration when forward price converges to spot price. Borrowers sell ayToken in return for Token on day one and return Token upon expiration. Implied interest rate depends on how much discount that the forward price is to the spot price at the time of transaction, which is executed on AMM.

Last but not least, ALEX hopes to bridge the gap between Defi and conventional finance by applying an AMM protocol derived from one of the basic instruments in fixed income market - zero coupon bond firstly proposed by . This empowers ALEX to learn from the fiat world and offer more decentralised financial products in the future.

This paper focuses on technical aspects of AMM and is the first of a series of ALEX papers unveiling all exciting features and applications of ALEX development.

AMM and Invariant Function

ALEX AMM is built on three beliefs: (i) it is mathematically neat and reflect economic demand and supply; (ii) it is a type of mean, like other AMMs; and (iii) it is derived and can be interpreted in terms of yield and is somehow related to conventional finance, where research has been conducted for decades.

We will firstly review some desirable features of AMM that ALEX hopes to exhibit.

Properties of AMM

AMM protocol, which provides liquidity algorithmically, is the core engine of Defi. In the liquidity pool, two or more assets are deposited and subsequently swapped resulting in both reserve and price movement. The protocol follows an invariant function f(X)=Lf(X)=Lf(X)=L, where X=(x1,x2,…,xd)X=\left(x_1,x_2,\dots,x_d\right)X=(x1​,x2​,…,xd​) is ddd dimension representing ddd assets and LLL is constant. When d=2d=2d=2, which is the common practise by a range of protocols, AMM f(x1,x2)=Lf(x_1,x_2)=Lf(x1​,x2​)=L can be expressed as x2=g(x1)x_2=g(x_1)x2​=g(x1​). Although it is not always true, ggg tends to be twice differentiable and satisfies the following

  • monotonically decreasing, i.e. dg(x1)dx1<0\frac{dg(x_1)}{dx_1}<0dx1​dg(x1​)​<0. This is because price is often defined as −dg(x1)dx1-\frac{dg(x_1)}{dx_1}−dx1​dg(x1​)​. A decreasing function ensures price to be positive.

  • convex, i.e. d2g(x1)dx12≥0\frac{d^2g(x_1)}{dx_1^2} \geq 0dx12​d2g(x1​)​≥0. This is equivalent to say that −dg(x1)dx1-\frac{dg(x_1)}{dx_1}−dx1​dg(x1​)​ is a non-increasing function of x1x_1x1​. It is within the expectation of economic theory of demand and supply, as more reserve of x1x_1x1​ means declining price.

ALEX AMM

After extensive research, we consider it possible for ALEX AMM to be connected to generalised mean defined as

(1d∑i=1dxip)1p\left( \frac{1}{d} \sum _{i=1}^{d} x_i^p \right)^{\frac{1}{p}}(d1​i=1∑d​xip​)p1​

where 0≤p≤10 \leq p \leq 10≤p≤1. The expression might remind readers of ppp-norm when xi≥0x_i \geq 0xi​≥0. It is however not true when p<1p<1p<1 as triangle inequality doesn't hold.

When d=2d=2d=2 and ppp is fixed, the core component of generalised mean is assumed constant as below.

x1p+x2p=Lx_1^p+x_2^p=Lx1p​+x2p​=L
x11−t+x21−t=L(t)x_1^{1-t}+x_2^{1-t}=L\left(t\right)x11−t​+x21−t​=L(t)

This is derived by solving the following differential equation when t≠1t \neq 1t=1

−dx2dx1=(x2x1)t-\frac{dx_2}{dx_1}=\left(\frac{x_2}{x_1} \right)^t−dx1​dx2​​=(x1​x2​​)t
  • xxx : balance of the underlying Token

  • yyy : balance of ayToken

  • rrr : implied interest rate, defined as the natural logarithm of balance of ayToken and Token

r=log(yx)r=log \left( \frac{y}{x} \right)r=log(xy​)
  • ppp : price of Token in terms of ayToken. The commonly quoted ayToken price is the inverse, i.e. 1p\frac{1}{p}p1​

p=(yx)t=ertp=\left(\frac{y}{x} \right)^t=e^{rt}p=(xy​)t=ert

ALEX's implied interest rate is compound. Not only does the compound rate allow us to derive mathematical formulas throughout the paper, we can also conduct further research and offer more products by referring to vast amount of literatures and applications in conventional finance, which is largely built on Black-Scholes model with compound rate employed as the discounting factor.

Using notations above, the invariant function is rewritten as x1−t+y1−t=Lx^{1-t}+y^{1-t}=Lx1−t+y1−t=L with the differential equation −dydx=(yx)t-\frac{dy}{dx}=\left(\frac{y}{x} \right)^t−dxdy​=(xy​)t. Unless specified, we assume LLL constant and call it invariant constant. This means that ttt is fixed and there is no minting or burning coins. In practise, liquidity providers can add or reduce liquidity, and LLL needs to be recalibrated daily when ttt changes.

Trading Formulae

Out-Given-In

In order to purchase Δy\Delta yΔy amount of ayToken from the pool, the buyer needs to deposit Δx\Delta xΔx amount of Token. Δx\Delta xΔx and Δy\Delta yΔy satisfy the following

(x+Δx)1−t+(y−Δy)1−t=x1−t+y1−t(x+\Delta x)^{1-t}+(y-\Delta y)^{1-t}=x^{1-t}+y^{1-t}(x+Δx)1−t+(y−Δy)1−t=x1−t+y1−t

After each transaction, balance is updated as below: x→x+Δxx\rightarrow x+\Delta xx→x+Δx and y→y−Δyy\rightarrow y-\Delta yy→y−Δy. Balance of yyy should not be less than that of xxx to avoid negative interest rate, which will be discussed in detail later. Rearranging the formula results in

Δy=y−[x1−t+y1−t−(x+Δx)1−t]11−t\Delta y=y-\left[x^{1-t}+y^{1-t}-(x+\Delta x)^{1-t}\right]^{\frac{1}{1-t}}Δy=y−[x1−t+y1−t−(x+Δx)1−t]1−t1​

When transaction cost exists, the actual deposit to the pool is less than Δx\Delta xΔx. Assuming λΔx\lambda\Delta xλΔx is the actual amount and (1−λ)Δx(1-\lambda)\Delta x(1−λ)Δx is the fee, above can now be expressed as

(x+λΔx)1−t+(y−Δy)1−t=x1−t+y1−tΔy=y−[x1−t+y1−t−(x+λΔx)1−t]11−t\begin{split} &(x+\lambda\Delta x)^{1-t}+(y-\Delta y)^{1-t}=x^{1-t}+y^{1-t}\\ &\Delta y=y-\left[x^{1-t}+y^{1-t}-(x+\lambda\Delta x)^{1-t}\right]^{\frac{1}{1-t}} \end{split}​(x+λΔx)1−t+(y−Δy)1−t=x1−t+y1−tΔy=y−[x1−t+y1−t−(x+λΔx)1−t]1−t1​​

To keep LLL constant, the updated balance is: x→x+λΔxx\rightarrow x+\lambda\Delta xx→x+λΔx and y→y−Δyy\rightarrow y-\Delta yy→y−Δy.

In-Given-Out

This is the opposite case to above. We are deriving Δx\Delta xΔx from Δy\Delta yΔy.

Δx=1λ[x1−t+y1−t−(y−Δy)1−t]11−t−x\Delta x=\frac{1}{\lambda}{\left[x^{1-t}+y^{1-t}-(y-\Delta y)^{1-t}\right]^{\frac{1}{1-t}}-x}Δx=λ1​[x1−t+y1−t−(y−Δy)1−t]1−t1​−x

In-Given-Price / Yield

Sometimes, trader would like to adjust the price/yield, perhaps due to deviation of AMM price to the market value. Define p′p'p′ the AMM price after rebalancing the Token and ayToken in the pool

p′=(y−Δyx+λΔx)tp'=\left(\frac{y-\Delta y}{x+\lambda\Delta x}\right)^{t}p′=(x+λΔxy−Δy​)t

Then, the added amount of Δx\Delta xΔx can be calculated from the formula below

(x+λΔx)1−t+(y−Δy)1−t=x1−t+y1−t1+(yx)1−t=(1+λΔxx)1−t+(y−Δyx)1−t1+p1−tt=(1+λΔxx)1−t+p′1−tt(1+λΔxx)1−tΔx=xλ[(1+p1−tt1+p′1−tt)11−t−1]\begin{split} &(x+\lambda\Delta x)^{1-t}+(y-\Delta y)^{1-t}=x^{1-t}+y^{1-t}\\ &1+\left(\frac{y}{x}\right)^{1-t}=\left(1+\lambda\frac{\Delta x}{x}\right)^{1-t}+(\frac{y-\Delta y}{x})^{1-t}\\ &1+p^{\frac{1-t}{t}}=\left(1+\lambda\frac{\Delta x}{x}\right)^{1-t}+p'^{\frac{1-t}{t}}\left(1+\lambda\frac{\Delta x}{x}\right)^{1-t}\\ &\Delta x=\frac{x}{\lambda}\left[\left(\frac{1+p^{\frac{1-t}{t}}}{1+p'^{\frac{1-t}{t}}}\right)^{\frac{1}{1-t}}-1\right]\\ \end{split}​(x+λΔx)1−t+(y−Δy)1−t=x1−t+y1−t1+(xy​)1−t=(1+λxΔx​)1−t+(xy−Δy​)1−t1+pt1−t​=(1+λxΔx​)1−t+p′t1−t​(1+λxΔx​)1−tΔx=λx​​(1+p′t1−t​1+pt1−t​​)1−t1​−1​​

Denote rrr and r′r'r′ the current and trader's target interest rate respectively. Because p=ertp=e^{rt}p=ert and p′=er′tp'=e^{r't}p′=er′t, the above equation can also be rewritten as

Δx=xλ[(1+er(1−t)1+er′(1−t))11−t−1]\Delta x=\frac{x}{\lambda}\left[\left(\frac{1+e^{r(1-t)}}{1+e^{r'(1-t)}}\right)^{\frac{1}{1-t}}-1\right]Δx=λx​[(1+er′(1−t)1+er(1−t)​)1−t1​−1]

Transaction Cost on Notional and Yield

In the previous sections, fee is in proportion to the notional amount. This is consistent with AMM such as Uniswap. However, it could be hard to interpret in the yield space, as market participants tend to think of borrowing or lending activity in terms of rate.

The formula below expresses λ\lambdaλ regarding bid/offer imposed on interest rate rrr, so that conversion in between the two is possible. Denote rmr_mrm​ as the mid rate calculated from AMM

erm=ΔyλΔxe^{r_m}=\frac{\Delta y}{\lambda\Delta x}erm​=λΔxΔy​

However, trader deposits Δx\Delta xΔx rather than λΔx\lambda\Delta xλΔx. Therefore, the bid rate rbr_brb​ when purchasing ayToken satisfies

erb=ΔyΔxe^{r_b}=\frac{\Delta y}{\Delta x}erb​=ΔxΔy​

Δrb=rm−rb\Delta r_b=r_m-r_bΔrb​=rm​−rb​ is then the fee charged to the purchaser in the yield space,

eΔrb=1λe^{\Delta r_b}=\frac{1}{\lambda}eΔrb​=λ1​

Hence, λ\lambdaλ can be expressed as a function of Δrb\Delta r_bΔrb​

λ=e−Δrb\lambda=e^{-\Delta r_b}λ=e−Δrb​

Actual fee is 1−λ=1−e−Δrb≈Δrb1- \lambda=1-e^{-\Delta r_b} \approx \Delta r_b1−λ=1−e−Δrb​≈Δrb​ using Taylor expansion to the first order. Thus λ≈1−Δrb\lambda \approx 1-\Delta r_bλ≈1−Δrb​ .

It can be shown that the above equality also holds when redeeming ayToken for Token, except Δrb\Delta r_bΔrb​ replaced by Δro=ro−rm\Delta r_o=r_o-r_mΔro​=ro​−rm​, where erm=λΔyΔxe^{r_m}=\frac{\lambda\Delta y}{\Delta x}erm​=ΔxλΔy​ and ero=ΔyΔxe^{r_o}=\frac{\Delta y}{\Delta x}ero​=ΔxΔy​. Here, ror_oro​ is the offer rate when selling ayToken and Δro\Delta r_oΔro​ is the corresponding fee charged to the seller in the yield space.

Concentrated Liquidity

In the current setting, liquidity provider can make market on any rate between −∞-\infty−∞ to +∞+\infty+∞. However, market participants might wish to impose certain constraint, for example no negative interest rate. One solution is to set up bounds on yx\frac{y}{x}xy​, which are related to the rate. In the case of positive rate, this means balance of ayToken always larger than Token. Although it solves the problem, the amount of ayToken lower than Token would be excluded from trading activities in any means. We are proposing an alternative approach by introducing virtual tokens.

Virtual tokens constitute part of the trading pool reserve that would never be touched hence underutilised. Liquidity providers should not be required to maintain this part of the pool and we are therefore set them as virtual. For example, when rate is floored at 0%, ttt= 0.5 and LLL= 20, liquidity providers will never face the situation of ayToken balance falling below 100, which can then be regarded as virtual to save the actual capital cost.

The idea is inspired by concentrated liquidity in Uniswap v3.

Pool with interest rate floored at zero

This section only allows liquidity on non-negative interest rate. Concentrated liquidity is achieved by introducing virtual token reserves yvy_vyv​, which satisfies

x1−t+(y+yv)1−t=Lx^{1-t}+(y+y_{v})^{1-t}=Lx1−t+(y+yv​)1−t=L

Figure 1 illustrates the example above of ttt= 0.5 and LLL= 20 by displaying two sets of curves: Invariant Function Curve (“IFC") satisfying x1−t+y1−t=Lx^{1-t}+y^{1-t}=Lx1−t+y1−t=L and Capital Efficiency Curve (“CEC") satisfying x1−t+(y+yv)1−t=Lx^{1-t}+(y+y_v)^{1-t}=Lx1−t+(y+yv​)1−t=L. Intuitively CEC is attained by lowering IFC by yvy_vyv​= 100.

Initialisation

Instead of contributing equal amount of Token and ayToken to initialise the pool with interest rate 0%, liquidity provider only needs to contribute x amount of Token. This is because virtual token yv=x=(12L)11−ty_v=x=\left(\frac{1}{2}L\right)^{\frac{1}{1-t}}yv​=x=(21​L)1−t1​.

Trading

Balance of Token and ayToken, including both actual and virtual, still satisfy the invariant function. However, once the actual ayToken is depleted and only Token is left in the pool, trading would be ceased until more ayToken is deposited.

Minting and Burning

Before liquidity expansion or reduction by minting or burning coins, assume that the old pool has Token xxx and ayToken yyy satisfying x1−t+y1−t=Lx^{1-t}+y^{1-t}=Lx1−t+y1−t=L, where y=ya+yvy=y_a+y_vy=ya​+yv​ and yay_aya​ and yvy_vyv​ are balance of actual and virtual ayToken respectively.

Minting and burning should not affect price and interest rate. This means that newly added or withdrawn coins would be in proportion to x and y. Denote new amount of Token and ayToken as x′=kxx'=kxx′=kx and y′=kyy'=kyy′=ky respectively. y′=ya′+yv′y'=y'_a+y'_vy′=ya′​+yv′​ where ya′y'_aya′​ is actual whereas yv′y'_vyv′​ virtual. They satisfy the following

ya′+yv′=ky2yv′1−t=k1−tL\begin{split} &y'_a+y'_v=ky\\ &2y'^{1-t}_v=k^{1-t}L \end{split}​ya′​+yv′​=ky2yv′1−t​=k1−tL​

Solution to the above equations is

ya′=ky−yv′yv′=(12L)11−tk\begin{split} &y'_{a}=ky-y'_{v}\\y'_{v} &=\left(\frac{1}{2}L\right)^{\frac{1}{1-t}}k \end{split}yv′​​ya′​=ky−yv′​=(21​L)1−t1​k​

This means yv′=kyvy'_v=ky_vyv′​=kyv​ and ya′=kyay'_a=ky_aya′​=kya​.

Example

Assume ttt= 0.5. Rachel initialises a liquidity pool of 0% interest rate with 100 Token on CEC. Although there is no actual ayToken, 0% rate implies 100 virtual tokens and LLL= 20 on IFC.

Suppose Rachel then sells 50 ayToken to the pool on the same day. On IFC, this means ayToken amount of 150 (50 actual and 100 virtual) and the amount of 60.10 Token remaining on IFC.

Now suppose Billy wants to mint 10% of the liquidity pool. This means that Billy needs to deposit 6.01 (10% of 60.10) Token. Virtual balance is updated to (12×20)10.5×1.1=110\left(\frac{1}{2}\times20\right)^{\frac{1}{0.5}}\times1.1=110(21​×20)0.51​×1.1=110. Billy needs to deposit 5 ayToken (1.1×150−110−501.1\times150-110-501.1×150−110−50), so that the summation of actual and virtual ayToken is 165. Interest rate remains the same before and after Billy's participation. Note that both actual and virtual ayToken balance increase by 10%, which is the same proportion as the growth of liquidity pool.

Range-bound Pool

The above section can be extended to any constraint pool with upper interest rate rur_{u}ru​ and lower interest rate rlr_{l}rl​. If interest rate falls out of [rlr_{l}rl​,rur_{u}ru​], swapping would be suspended as one of the tokens would have been depleted.

Denote xax_{a}xa​, xvx_{v}xv​, yay_{a}ya​ and yvy_{v}yv​ balance of actual Token, virtual Token, actual ayToken and virtual ayToken respectively. They satisfy invariant function on IFC, i.e. (xa+xv)1−t+(ya+yv)1−t=L(x{a}+x{v})^{1-t}+(y{a}+y{v})^{1-t}=L(xa+xv)1−t+(ya+yv)1−t=L.

The amount of Token an ayToken can be expressed as a function of L and current interest rate rc=ya+yvxa+xvr_{c}=\frac{y_{a}+y_{v}}{x_{a}+x_{v}}rc​=xa​+xv​ya​+yv​​.

\begin{split} &x_{a}+x_{v}&=\left[\frac{L}{1+e^{(1-t)r_{c}}}\right]^{\frac{1}{1-t}}\\ &y_{a}+y_{v}&=\left[\frac{L}{1+e^{-(1-t)r_{c}}}\right]^{\frac{1}{1-t}} \end{split}

Intuitively, when rc=rlr_{c}=r_{l}rc​=rl​, ayToken is depleted; Similarly, when rc=rur_{c}=r_{u}rc​=ru​, Token is used up. Therefore,

xv=[L1+e(1−t)ru]11−tyv=[L1+e−(1−t)rl]11−t\begin{split} &x_{v}=\left[\frac{L}{1+e^{(1-t)r_{u}}}\right]^{\frac{1}{1-t}}\\ &y_{v}=\left[\frac{L}{1+e^{-(1-t)r_{l}}}\right]^{\frac{1}{1-t}} \end{split}​xv​=[1+e(1−t)ru​L​]1−t1​yv​=[1+e−(1−t)rl​L​]1−t1​​

Similar to the case of 0% floor, minting or burning coins would result in invariant constant changing from LLL to k1−tLk^{1-t}Lk1−tL. Meanwhile, both actual and virtual Token and ayToken would grow proportionally by kkk, as they are linear function of L11−tL^{\frac{1}{1-t}}L1−t1​.

Example

We aim to show here how virtual token is able to assist liquidity providers to efficiently manage capital.

In Figure 2, assume lower bound is 0%, whereas upper bound is 50%. We also set ttt= 0.5 and LLL= 20. If interest rate is 0%, LLL= 20 means holding equal amount of Token and ayToken of 100 each (1000.5+1000.5=20)\left(100^{0.5}+100^{0.5}=20\right)(1000.5+1000.5=20). The figure compares actual holding of Token and ayToken with and without cap and floor.

According to the figure, when current implied interest rate is 10%, without capital efficiency, liquidity provider is required to deposit 95.06 Token and 105.06 ayToken. This is in comparison with 18.39 Token and 5.06 ayToken after imposing cap and floor. In this example, the capital saving is at least 77%.

Appendix 1: Generalised Mean when d=2

ALEX's invariant function is f(x1,x2;p)=x1p+x2p=L.f(x_{1},x_{2};p)=x{_1}^{p}+x_{2}^{p}=L.f(x1​,x2​;p)=x1​p+x2p​=L. It can be rearranged as x2=g(x1)=(L−x1p)1px{2}=g(x_{1})=(L-x_{1}^{p})^{\frac{1}{p}}x2=g(x1​)=(L−x1p​)p1​. x1x_{1}x1​ and x2x_{2}x2​ should both be positive meaning the liquidity pool contains both tokens.

Theorem

When 0<p<10<p<10<p<1, g(x1)g\left(x_{1}\right)g(x1​) is monotonically decreasing and convex.

Proof

This is equivalent to prove dg(x1)dx1<0\frac{dg(x_{1})}{dx_{1}}<0dx1​dg(x1​)​<0 and d2g(x1)dx12≥0\frac{d^{2}g(x_{1})}{dx_{1}^{2}}\geq0dx12​d2g(x1​)​≥0.

dg(x1)dx1=1p(L−x1p)1p−1(−px1p−1)=−(L−x1px1p)1−pp<0d2g(x1)dx12=−1−pp(L−x1px1p)1−2pp[−px1p−1x1p−(L−x1p)pxp−1x12p]=L(1−p)(x2x1)1−2px1−p−1≥0\begin{split} &\frac{dg(x_{1})}{dx_{1}}=\frac{1}{p}(L-x_{1}^{p})^{\frac{1}{p}-1}\left(-px_{1}^{p-1}\right)=-\left(\frac{L-x_{1}^{p}}{x_{1}^{p}}\right)^{\frac{1-p}{p}}<0\\ &\frac{d^{2}g(x_{1})}{dx_{1}^{2}}=-\frac{1-p}{p}\left(\frac{L-x_{1}^{p}}{x_{1}^{p}}\right)^{\frac{1-2p}{p}}\left[\frac{-px_{1}^{p-1}x_{1}^{p}-(L-x_{1}^{p})px^{p-1}}{x_{1}^{2}p}\right]\\ &=L(1-p)\left(\frac{x_{2}}{x_{1}}\right)^{1-2p}x_{1}^{-p-1}\geq0 \end{split}​dx1​dg(x1​)​=p1​(L−x1p​)p1​−1(−px1p−1​)=−(x1p​L−x1p​​)p1−p​<0dx12​d2g(x1​)​=−p1−p​(x1p​L−x1p​​)p1−2p​[x12​p−px1p−1​x1p​−(L−x1p​)pxp−1​]=L(1−p)(x1​x2​​)1−2px1−p−1​≥0​

The last inequality holds because each component is positive.

When ppp= 1, it is straightward to see that the invariant function is constant sum. To show that the invariant function converges to constant product when ppp= 0, we will show and prove an established result in a generalised ddd dimensional setting.

Theorem

lim⁡p→0(1d∑i=1dxip)1p=(∏i=1dxi)1d\lim_{p\rightarrow0}\left(\frac{1}{d}\sum_{i=1}^{d}x_{i}^{p}\right)^{\frac{1}{p}}=({\prod_{i=1}^{d}x_{i}})^{\frac{1}{d}}p→0lim​(d1​i=1∑d​xip​)p1​=(i=1∏d​xi​)d1​

Proof

(1d∑i=1dxip)1p=exp[log(1d∑i=1dxip)p]\left(\frac{1}{d}\sum{i=1}^{d}x_{i}^{p}\right)^{\frac{1}{p}}=\text{exp}\left[\frac{\text{log}\left(\frac{1}{d}\sum{i=1}^{d}x_{i}^{p}\right)}{p}\right](d1​∑i=1dxip​)p1​=exp[plog(d1​∑i=1dxip​)​]. Applying L'Hospital rule to the exponent,which is 0 in both denominator and nominator when p→0p\rightarrow0p→0, we have

lim⁡p→0log(1d∑i=1dxip)p=lim⁡p→0∑i=1dlog(xi)∑j=1d(xjxi)p=∑i=1dlog(xi)d\lim_{p\rightarrow0}\frac{\text{log}\left(\frac{1}{d}\sum_{i=1}^{d}x_{i}^{p}\right)}{p}=\lim_{p\rightarrow0}\sum_{i=1}^{d}\frac{\text{log}(x_{i})}{\sum_{j=1}^{d}\left(\frac{x_{j}}{x_{i}}\right)^{p}}=\frac{\sum_{i=1}^{d}\text{log}(x_{i})}{d}p→0lim​plog(d1​∑i=1d​xip​)​=p→0lim​i=1∑d​∑j=1d​(xi​xj​​)plog(xi​)​=d∑i=1d​log(xi​)​

Therefore

lim⁡p→0(1d∑i=1dxip)1p=lim⁡p→0exp∑i=1dlog(xi)d=(∏i=1dxi)1d\lim_{p\rightarrow0}\left(\frac{1}{d}\sum_{i=1}^{d}x_{i}^{p}\right)^{\frac{1}{p}}=\lim_{p\rightarrow0}\text{exp}\frac{\sum_{i=1}^{d}\text{log}(x_{i})}{d}=({\prod_{i=1}^{d}x_{i}})^{\frac{1}{d}}p→0lim​(d1​i=1∑d​xip​)p1​=p→0lim​expd∑i=1d​log(xi​)​=(i=1∏d​xi​)d1​

Corollary

When d = 2,

x1x2=lim⁡p→0[12(x1p+x2p)]2px_{1}x_{2}=\lim_{p\rightarrow0}\left[\frac{1}{2}(x_{1}^{p}+x_{2}^{p})\right]^{\frac{2}{p}}x1​x2​=p→0lim​[21​(x1p​+x2p​)]p2​

Proof of the corollary is trivial, as it is a direct application of the theorem. It shows that generalised mean AMM implies constant product AMM when p→0p\rightarrow0p→0.

Appendix 2: Liquidity Mapping to Uniswap v3

As Uniswap v3 is able to simulate liquidity curve of any AMM, we are interested in exploring the connection between ALEX's AMM and that of Uniswap's. Interesting questions include: what is the shape of the liquidity distribution? Which point(s) has the highest liquidity? We acknowledge that the section is more of a theoretical study for now.

Uniswap V3 AMM can be expressed as a function of invariant constant LLL with respect to price ppp, LUniswap=dydpL_{\text{Uniswap}}=\frac{dy}{d\sqrt{p}}LUniswap​=dp​dy​. In terms of ALEX, as price p=e^{rt}, where rrr is the implied interest rate, we have

LUniswap=dydp=2te−12rtdydrL_{\text{Uniswap}}=\frac{dy}{d\sqrt{p}}=\frac{2}{t}e^{-\frac{1}{2}rt}\frac{dy}{dr}LUniswap​=dp​dy​=t2​e−21​rtdrdy​

In the previous sections, we express yyy as

y=[L1+e−(1−t)r]11−ty=\left[\frac{L}{1+e^{-(1-t)r}}\right]^{\frac{1}{1-t}}y=[1+e−(1−t)rL​]1−t1​

Therefore

dydr=L11−te−(1−t)r(1+e−(1−t)r)2−t1−tLUniswap=2tL11−t(er(1−t)2+e−r(1−t)2)−2+t1−t=2tL11−t{2cosh⁡[r(1−t)2]}−2+t1−t\begin{split} &\frac{dy}{dr}=L^{\frac{1}{1-t}}\frac{e^{-(1-t)r}}{(1+e^{-(1-t)r})^{\frac{2-t}{1-t}}}\\ &L_{\text{Uniswap}}=\frac{2}{t}L^{\frac{1}{1-t}}\left(e^{\frac{r(1-t)}{2}}+e^{\frac{-r(1-t)}{2}}\right)^{\frac{-2+t}{1-t}}\\ &=\frac{2}{t}L^{\frac{1}{1-t}}\big\{2\cosh\left[\frac{r(1-t)}{2}\right]\big\}^{\frac{-2+t}{1-t}} \end{split}​drdy​=L1−t1​(1+e−(1−t)r)1−t2−t​e−(1−t)r​LUniswap​=t2​L1−t1​(e2r(1−t)​+e2−r(1−t)​)1−t−2+t​=t2​L1−t1​{2cosh[2r(1−t)​]}1−t−2+t​​

Figure 3 plots LUniswapL_{\text{Uniswap}}LUniswap​ against interest rate rrr regarding various levels of ttt. When 0<t<10<t<10<t<1, LUniswapL_{\text{Uniswap}}LUniswap​ is symmetric around 0% at which the maximum reaches . This is because

  1. cosh⁡[(r(1−t)2)]\cosh\left[(\frac{r(1-t)}{2})\right]cosh[(2r(1−t)​)] is symmetric around rrr= 0% with minimum at 0% and the minimum value 1;

  2. xzx^zxz is a decreasing function of xxx when xxx is positive and power zzz is negative. In our case, we have z=−2+t1−t<−1z=-2+t1-t<-1z=−2+t1−t<−1. Therefore, it is the maximum rather than minimum that LUniswapL_{\text{Uniswap}}LUniswap​ achieves at 0.

Furthermore, the higher the ttt, the flatter the liquidity distribution is. When ttt approaches 1, i.e. AMM converges to the constant product formula, the liquidity distribution is close to a flat line. When ttt approaches 0, the distribution concentrates around 0%. This makes sense, as forward price starts to converge to spot price upon expiration.

Appendix 3: Derivation of Actual and Virtual Token Reserve

On CEC, there are two boundary points (xbx_{b}xb​,0) and (0,yby_{b}yb​) corresponding to the lower and upper bound of interest rate rlr_{l}rl​ and rur_{u}ru​ respectively. We assume LLL is pre-determined, as liquidity provider knows the pool size. We aim to find xbx_{b}xb​, yby_{b}yb​, xvx_{v}xv​ and yvy_{v}yv​ which satisfy the following equations

(xb+xv)1−t+yv1−t=Lxv1−t+(yb+yv)1−t=Lyvxb+xv=erlyb+yvxv=eru\begin{split} &(x_{b}+x_{v})^{1-t}+y_{v}^{1-t}=L\\ &x_{v}^{1-t}+(y_{b}+y_{v})^{1-t}=L\\ &\frac{y_{v}}{x_{b}+x_{v}}=e^{r_{l}}\\ &\frac{y_{b}+y_{v}}{x_{v}}=e^{r_{u}} \end{split}​(xb​+xv​)1−t+yv1−t​=Lxv1−t​+(yb​+yv​)1−t=Lxb​+xv​yv​​=erl​xv​yb​+yv​​=eru​​

As there are four unknown variables with four equations, solutions can be expressed as below

xv=[L1+e(1−t)ru]11−tyv=[L1+e−(1−t)rl]11−txb=yve−rl−xv=[L1+erl(1−t)]11−t−[L1+eru(1−t)]11−tyb=xveru−yv=[L1+e−ru(1−t)]11−t−[L1+e−rl(1−t)]11−t\begin{split} &x_{v}=\left[\frac{L}{1+e^{(1-t)r_{u}}}\right]^{\frac{1}{1-t}}\\ &y_{v}=\left[\frac{L}{1+e^{-(1-t)r_{l}}}\right]^{\frac{1}{1-t}}\\ &x_{b}=y_{v}e^{-r_{l}}-x_{v}=\left[\frac{L}{1+e^{r_{l}(1-t)}}\right]^{\frac{1}{1-t}}-\left[\frac{L}{1+e^{r_{u}(1-t)}}\right]^{\frac{1}{1-t}}\\ &y_{b}=x_{v}e^{r_{u}}-y_{v}=\left[\frac{L}{1+e^{-r_{u}(1-t)}}\right]^{\frac{1}{1-t}}-\left[\frac{L}{1+e^{-r_{l}(1-t)}}\right]^{\frac{1}{1-t}} \end{split}​xv​=[1+e(1−t)ru​L​]1−t1​yv​=[1+e−(1−t)rl​L​]1−t1​xb​=yv​e−rl​−xv​=[1+erl​(1−t)L​]1−t1​−[1+eru​(1−t)L​]1−t1​yb​=xv​eru​−yv​=[1+e−ru​(1−t)L​]1−t1​−[1+e−rl​(1−t)L​]1−t1​​

When rl=0r_{l}=0rl​=0, the pool is floored at 0%. This means that xv=0x_{v}=0xv​=0, yv=(12L)11−ty_{v}=\left(\frac{1}{2}L\right)^{\frac{1}{1-t}}yv​=(21​L)1−t1​, xb=yvx_{b}=y_{v}xb​=yv​.

When the current interest rate rcr_{c}rc​ is known and rc∈[rl,ru]r_{c}\in[r_{l},r_{u}]rc​∈[rl​,ru​], we can calculate xax_{a}xa​ and yay_{a}ya​ satisfying the following equations. When rc∉[rl,ru]r_{c} \notin[r_{l},r_{u}]rc​∈/[rl​,ru​], only one token exists and swapping activities are suspended.

(xv+xa)1−t+(yv+ya)1−t=Lyv+yaxv+xa=erc\begin{split} &(x_{v}+x_{a})^{1-t}+(y_{v}+y_{a})^{1-t}=L\\ &\frac{y_{v}+y_{a}}{x_{v}+x_{a}}=e^{r_{c}} \end{split}​(xv​+xa​)1−t+(yv​+ya​)1−t=Lxv​+xa​yv​+ya​​=erc​​

Solution to above is

xa=[L1+erc(1−t)]11−t−xv=[L1+erc(1−t)]11−t−[L1+eru(1−t)]11−tya=[L1+e−rc(1−t)]11−t−yv=[L1+e−rc(1−t)]11−t−[L1+e−rl(1−t)]11−t\begin{split} &x_{a}=\left[\frac{L}{1+e^{r_{c}(1-t)}}\right]^{\frac{1}{1-t}}-x_{v}=\left[\frac{L}{1+e^{r_{c}(1-t)}}\right]^{\frac{1}{1-t}}-\left[\frac{L}{1+e^{r_{u}(1-t)}}\right]^{\frac{1}{1-t}}\\ &y_{a}=\left[\frac{L}{1+e^{-r_{c}(1-t)}}\right]^{\frac{1}{1-t}}-y_{v}=\left[\frac{L}{1+e^{-r_{c}(1-t)}}\right]^{\frac{1}{1-t}}-\left[\frac{L}{1+e^{-r_{l}(1-t)}}\right]^{\frac{1}{1-t}} \end{split}​xa​=[1+erc​(1−t)L​]1−t1​−xv​=[1+erc​(1−t)L​]1−t1​−[1+eru​(1−t)L​]1−t1​ya​=[1+e−rc​(1−t)L​]1−t1​−yv​=[1+e−rc​(1−t)L​]1−t1​−[1+e−rl​(1−t)L​]1−t1​​

At the boundary points, when rc=rlr_{c}=r_{l}rc​=rl​, xa=xbx_{a}=x_{b}xa​=xb​ and ya=0y_{a}=0ya​=0; when rc=rur_{c}=r_{u}rc​=ru​, xa=0x_{a}=0xa​=0 and ya=yby_{a}=y_{b}ya​=yb​.

Meanwhile, fff can usually be interpreted as a form of mean, for example, relates to arithmetic mean, where x1+x2=Lx_1+x_2=Lx1​+x2​=L (constant sum formula); one of the most popular platforms relates to geometric mean, where x1x2=Lx_1 x_2=Lx1​x2​=L (constant product formula); , which our collateral rebalancing pool employs, applies weighted geometric mean. Its AMM is x1w1x2w2=Lx_1^{w_1} x_2^{w_2}=Lx1w1​​x2w2​​=L where w1w_1w1​ and w2w_2w2​ are fixed weights. However, none of these three protocols consider time to maturity, which is essential in modern interest rate theory.

This equation is regarded reasonable as AMM, because (i) function ggg where x2=g(x1)x_2=g(x_1)x2​=g(x1​) is monotonically decreasing and convex; and (ii) The boundary value of p=1p=1p=1 and p=0p=0p=0 corresponds to constant sum and constant product formula respectively. When ppp increases from 0 to 1, price −dg(x1)x1-\frac{dg(x_1)}{x_1}−x1​dg(x1​)​ gradually converges to 1. This is what ALEX hopes to achieve when forward becomes spot. This also means that ppp is somehow related to time to maturity. Please refer to for a detailed discussion.

In the benchmark research piece by , the invariant function above is formalised from the perspective of zero coupon bond. ppp is replaced by 1−t1-t1−t where ttt is time to maturity and LLL is a function of ttt, so that

In the rest of the paper, to be consistent with , we employ notations below

Though purely theoretical at this stage, maps LLL to the liquidity distribution of . This is motivated by an independent research from .

Market transaction, which involves exchange of Token and ayToken, satisfies the invariant function. While fee is deposited back to the liquidity pool in some protocols, such as Uniswap V2, resulting in slight increase of LLL after each transaction, ALEX counts the fee separately. This is consistent with . Hence LLL remains constant.

See for a detailed derivation of virtual, as well as actual token reserve.

📚
Yield Space
mStable
Uniswap
Balancer
Appendix 1
Yield Space
Yield Space
Appendix 2
Uniswap V3
Paradigm
Uniswap V3
Appendix 3
Figure 1
Figure 2
Figure 3