Automated Market Making of Yield Token Pool
Last updated
Last updated
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.
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 Yield Space. 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.
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.
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 , where is dimension representing assets and is constant. When , which is the common practise by a range of protocols, AMM can be expressed as . Although it is not always true, tends to be twice differentiable and satisfies the following
monotonically decreasing, i.e. . This is because price is often defined as . A decreasing function ensures price to be positive.
convex, i.e. . This is equivalent to say that is a non-increasing function of . It is within the expectation of economic theory of demand and supply, as more reserve of means declining price.
After extensive research, we consider it possible for ALEX AMM to be connected to generalised mean defined as
In the rest of the paper, to be consistent with Yield Space, we employ notations below
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.
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 idea is inspired by concentrated liquidity in Uniswap v3.
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.
Solution to the above equations is
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.
See Appendix 3 for a detailed derivation of virtual, as well as actual token reserve.
We aim to show here how virtual token is able to assist liquidity providers to efficiently manage capital.
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%.
The last inequality holds because each component is positive.
Therefore
When d = 2,
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.
Therefore
As there are four unknown variables with four equations, solutions can be expressed as below
Solution to above is
Meanwhile, can usually be interpreted as a form of mean, for example, mStable relates to arithmetic mean, where (constant sum formula); one of the most popular platforms Uniswap relates to geometric mean, where (constant product formula); Balancer, which our collateral rebalancing pool employs, applies weighted geometric mean. Its AMM is where and are fixed weights. However, none of these three protocols consider time to maturity, which is essential in modern interest rate theory.
where . The expression might remind readers of -norm when . It is however not true when as triangle inequality doesn't hold.
When and is fixed, the core component of generalised mean is assumed constant as below.
This equation is regarded reasonable as AMM, because (i) function where is monotonically decreasing and convex; and (ii) The boundary value of and corresponds to constant sum and constant product formula respectively. When increases from 0 to 1, price gradually converges to 1. This is what ALEX hopes to achieve when forward becomes spot. This also means that is somehow related to time to maturity. Please refer to Appendix 1 for a detailed discussion.
In the benchmark research piece by Yield Space, the invariant function above is formalised from the perspective of zero coupon bond. is replaced by where is time to maturity and is a function of , so that
This is derived by solving the following differential equation when
: balance of the underlying Token
: balance of ayToken
: implied interest rate, defined as the natural logarithm of balance of ayToken and Token
: price of Token in terms of ayToken. The commonly quoted ayToken price is the inverse, i.e.
Using notations above, the invariant function is rewritten as with the differential equation . Unless specified, we assume constant and call it invariant constant. This means that is fixed and there is no minting or burning coins. In practise, liquidity providers can add or reduce liquidity, and needs to be recalibrated daily when changes.
Though purely theoretical at this stage, Appendix 2 maps to the liquidity distribution of Uniswap V3. This is motivated by an independent research from Paradigm.
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 after each transaction, ALEX counts the fee separately. This is consistent with Uniswap V3. Hence remains constant.
In order to purchase amount of ayToken from the pool, the buyer needs to deposit amount of Token. and satisfy the following
After each transaction, balance is updated as below: and . Balance of should not be less than that of to avoid negative interest rate, which will be discussed in detail later. Rearranging the formula results in
When transaction cost exists, the actual deposit to the pool is less than . Assuming is the actual amount and is the fee, above can now be expressed as
To keep constant, the updated balance is: and .
This is the opposite case to above. We are deriving from .
Sometimes, trader would like to adjust the price/yield, perhaps due to deviation of AMM price to the market value. Define the AMM price after rebalancing the Token and ayToken in the pool
Then, the added amount of can be calculated from the formula below
Denote and the current and trader's target interest rate respectively. Because and , the above equation can also be rewritten as
The formula below expresses regarding bid/offer imposed on interest rate , so that conversion in between the two is possible. Denote as the mid rate calculated from AMM
However, trader deposits rather than . Therefore, the bid rate when purchasing ayToken satisfies
is then the fee charged to the purchaser in the yield space,
Hence, can be expressed as a function of
Actual fee is using Taylor expansion to the first order. Thus .
It can be shown that the above equality also holds when redeeming ayToken for Token, except replaced by , where and . Here, is the offer rate when selling ayToken and is the corresponding fee charged to the seller in the yield space.
In the current setting, liquidity provider can make market on any rate between to . However, market participants might wish to impose certain constraint, for example no negative interest rate. One solution is to set up bounds on , 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%, = 0.5 and = 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.
This section only allows liquidity on non-negative interest rate. Concentrated liquidity is achieved by introducing virtual token reserves , which satisfies
Figure 1 illustrates the example above of = 0.5 and = 20 by displaying two sets of curves: Invariant Function Curve (āIFC") satisfying and Capital Efficiency Curve (āCEC") satisfying . Intuitively CEC is attained by lowering IFC by = 100.
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 .
Before liquidity expansion or reduction by minting or burning coins, assume that the old pool has Token and ayToken satisfying , where and and 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 and respectively. where is actual whereas virtual. They satisfy the following
This means and .
Assume = 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 = 20 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 . Billy needs to deposit 5 ayToken (), 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.
The above section can be extended to any constraint pool with upper interest rate and lower interest rate . If interest rate falls out of [,], swapping would be suspended as one of the tokens would have been depleted.
Denote , , and balance of actual Token, virtual Token, actual ayToken and virtual ayToken respectively. They satisfy invariant function on IFC, i.e. .
The amount of Token an ayToken can be expressed as a function of L and current interest rate .
Intuitively, when , ayToken is depleted; Similarly, when , Token is used up. Therefore,
Similar to the case of 0% floor, minting or burning coins would result in invariant constant changing from to . Meanwhile, both actual and virtual Token and ayToken would grow proportionally by , as they are linear function of .
In Figure 2, assume lower bound is 0%, whereas upper bound is 50%. We also set = 0.5 and = 20. If interest rate is 0%, = 20 means holding equal amount of Token and ayToken of 100 each . The figure compares actual holding of Token and ayToken with and without cap and floor.
ALEX's invariant function is It can be rearranged as . and should both be positive meaning the liquidity pool contains both tokens.
When , is monotonically decreasing and convex.
This is equivalent to prove and .
When = 1, it is straightward to see that the invariant function is constant sum. To show that the invariant function converges to constant product when = 0, we will show and prove an established result in a generalised dimensional setting.
. Applying L'Hospital rule to the exponent,which is 0 in both denominator and nominator when , we have
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 .
Uniswap V3 AMM can be expressed as a function of invariant constant with respect to price , . In terms of ALEX, as price p=e^{rt}, where is the implied interest rate, we have
In the previous sections, we express as
Figure 3 plots against interest rate regarding various levels of . When , is symmetric around 0% at which the maximum reaches . This is because
is symmetric around = 0% with minimum at 0% and the minimum value 1;
is a decreasing function of when is positive and power is negative. In our case, we have . Therefore, it is the maximum rather than minimum that achieves at 0.
Furthermore, the higher the , the flatter the liquidity distribution is. When approaches 1, i.e. AMM converges to the constant product formula, the liquidity distribution is close to a flat line. When approaches 0, the distribution concentrates around 0%. This makes sense, as forward price starts to converge to spot price upon expiration.
On CEC, there are two boundary points (,0) and (0,) corresponding to the lower and upper bound of interest rate and respectively. We assume is pre-determined, as liquidity provider knows the pool size. We aim to find , , and which satisfy the following equations
When , the pool is floored at 0%. This means that , , .
When the current interest rate is known and , we can calculate and satisfying the following equations. When , only one token exists and swapping activities are suspended.
At the boundary points, when , and ; when , and .