Liquidity Provision
Diving deep into the mechanics and calculations of Liquidity provision.
Liquidity Providers are counterparties to both Lenders and Borrowers. They can create pools with any parameters of their choice or add liquidity to the existing pools. They add both Collateral Claim tokens (CCT) and Bond tokens(BT) in the pool with a proportion that doesn't change the Interest Rate, thus maintaining the current state of the pool. Usually, the proportion of Total CCT (x+y) and BT(dz) in the pool is not the same because of varying demand on Lend/Borrow side, therefore LPs will have an excess of either CCT or BT tokens in their balance. Even if the interest rate stays the same, the amount of shorts(dz) to be deposited by Liquidity Providers decreases with time as 'd' decreases.
Liquidity Providers take some divergent loss whenever the ratio of (x+y) and z (different from Amount of BT) changes compared to when they added Liquidity, this divergent loss is similar to Uniswap V2 LPs. To minimize it, LPs should add/create liquidity at a fair market rate.
Incentives for Liquidity Providers by adding liquidity will be the transaction fees paid by both lenders and borrowers. Transaction fees are earned as Bond Tokens(BT) withdrawn (from Lenders) and Collateral Claim tokens (CCT) withdrawn(by Borrowers) in the pool.
Consider a USDC/ETH pool following the three variable AMM
Let Δx be the number of CCT ETH deposited into the pool.
Let Δy be the number of CCT USDC deposited into the pool.
Let Δz be the number of Bond tokens(BT) per second for the duration of the pool deposited into the pool.
Let d be the duration of the pool, thus d(Δz) is the total number of BT deposited into the pool.
The formula for Liquidity Provision transaction:
Let I be the marginal interest rate of the pool
While the ratio of (x+y)*z=k does not change with time, the amount of Bond tokens (dz) in the pool decrease as time passes and the duration is closer to the maturity of the pool. This is because z amount of BT are given to LPs every second.
Liquidity Providers receive ERC 1155 liquidity tokens (LT)
l
as a receipt of liquidity position. It represents their share of the liquidity pool. Here's how the amount of liquidity tokens received is calculated:
Suppose a Liquidity Provider wants to create USDC/ETH pool with 10% APR (I), 1000 USDC per ETH strike/transition (K), and 1 Year maturity (d) .
Here are some ratios and parameters we would need to create the pool:
where I is the annual marginal interest rate=10% annually= 10/100 annually
Marginal interest rate per second = (10/100)/d per second where, d is the duration of the pool, therefore,
where dz is the amount of Bond Tokens and (x+y) is the amount of CCT tokens
(seconds in 1 year which is the pool maturity in our example)
Depending on the state of the pool, LPs add either CCT ETH(
when K>S
) or CCT USDC(when S>K
). Liquidity Providers can add USDC/ETH or a proportion of both, Timeswap will utilize a DEX to make transactions efficient. Let's look at both the cases. NOTE: Liquidity Providers can add any amount of tokens by maintaining Marginal Interest 'I' or
ratio. Following examples have their values for simplicity purposes.
Case 1: If spot price (S) of ETH<1000 USDC (K) , say 900 USDC per ETH, then the pool parameters will look like:
(Create pool using CCT ETH since S<K)
Initial
Initial
Initial
Initial
Now, the above parameters indicate that Liquidity Provider needs 10 CCT ETH and 1 BT In order to create the pool.(They can also add less tokens but the ratio of
CCT ETH : BT
needs to be the same). Liquidity Provider can use 10 ETH to mint 10 CCT ETH and 10 BT.
Or
Liquidity Provider can use 9000 USDC to create the pool. In this case, 9000 USDC is first swapped for 10 ETH using a DEX which is then used to mint 10 CCT ETH and 10 BT.
After creating the pool, Liquidity Provider is left with excess of 9 Bond Tokens.
Liquidity tokens
received by the Liquidity Provider:
Case 2: If spot price (S) of ETH> 1000 USDC, say 1100 USDC per ETH, then the pool parameters will look like:
(Create pool using CCT USDC since S>K)
Initial x=0
Initial y=10
Initial z= 1/31557600 , (dz=1) ; duration of the pool (d) is 1 yr = 31557600 sec
Initial k= 0.000000316880878
Now, the above parameters indicate that Liquidity Provider needs 10000 CCT USDC(Since y= 10000 CCT USDC/K = 10,000/1,000) and 1 BT to create the pool.
Liquidity Provider can use 10000 USDC to mint 10000 CCT USDC and 10 BT.
Or
Liquidity Provider can use 9.091 ETH to create the pool. In this case, 9.091 ETH is first swapped for 10,000 USDC using a DEX and then used to mint 10,000 CCT USDC and 10 BT.
After creating the pool, Liquidity Provider is left with excess of 9 Bond tokens.(Representing a lend position of 9,000 USDC)
Liquidity tokens
received by the Liquidity Provider:
Case 1: If spot price of ETH<1000 USDC, say 900 USDC per ETH, then the transaction parameters will look like:
Δx=1
Δy=0
Δz=0.1/31557600
dΔz=0.1
Before:
After:
Before:
After:
Above parameters indicate that Alice adds 1 CCT ETH and 0.1 BT in the pool.
Alice can deposit 1 ETH to mint 1 CCT ETH and 1 BT. Alice holds a balance of 0.9 BT after adding liquidity.
Similarly, Alice can add 900 USDC in the pool wherein USDC is first swapped for 1 ETH using a DEX and the above functions are performed.
Liquidity tokens
received by the Liquidity Provider:
Case 2: If spot price of ETH> 1000 USDC, say 1100 USDC per ETH, then the transaction parameters will look like:
Δx=0
Δy=1
Δz=0.1/31557600
dΔz=0.1
Before:
After:
Before:
After:
Above parameters indicate that Alice adds 1000 CCT USDC(Since Δy= CCT USDC/K= 1000 CCT USDC/1000) and 0.1 BT in the pool.
Alice can deposit 1000 USDC to mint 1 CCT USDC and 1 BT. Alice has a balance of 0.9 BT after adding liquidity.
Similarly, Alice can deposit 0.9091 ETH which is first swapped for 1000 USDC using a DEX and then above functions are performed.
Liquidity tokens
received by the Liquidity Provider:
In both the cases, Alice will receive
BT every second for her duration of Liquidity Addition.
can change with change in Interest Rate.
Liquidity providers in Timeswap V2 can burn their Liquidity tokens
to remove their liquidity from the pool anytime. This is a significant improvement from Timeswap V1 where liquidity providers need to wait till maturity to withdraw their liquidity.
Keeping the above parameters in mind, here's how a liquidity removal Transaction will look like:
Where, Liquidity tokens
Value of (Δx+Δy) and Δz is calculated in a way that the proportion of CCT and Bond tokens in the pool does not change. In other words, liquidity removal should not affect the Interest rate of the pool.
In both the above cases, Alice holds
Alice added liquidity when I = (x+y)/z= 10%, let's say the interest rate was the same when she removed liquidity. Irrespective of weather S>K or K>S, this is how the AMM would look like:
Before:
After:
Alice receives 1000 CCT USDC or 1 CCT ETH + 0.1 BT tokens. She also has a Balance of 0.9 Bond tokens. Therefore, Alice holds a total of 1000 CCT USDC or 1 CCT ETH + 1 Bond tokens.
She can now burn both the tokens to withdraw 1 ETH or 1000 USDC. Alice also receives fees from lenders and borrowers in addition to her initial capital.
Here, if the Interest rate were to be different from 10%, say 20% or 5%, then she would've received CCT and Bond tokens in a different proportion, hence facing Divergence Loss.
Last modified 1mo ago