How it works
Explainer on how Timeswap V2 AMM functions underneath.
- Timeswap V2 design is a modified version of v1 and continues to be inspired by Uniswap's constant product equation for price discovery. Timeswap works on a duration weighted constant product automated market maker (AMM) with one of the variables following a constant sum.
- Since Timeswap offers fixed income style non-liquidatable loans its working can also be compared to how options works.
- By design, no borrower is ever liquidated & has the option to either repay his debt or default before maturity. When a borrower defaults his collateral is forfeited and distributed to the lenders. Whereas lenders on the other side receive full interest payments when all borrowers repay or get insurance in the event of borrowers deciding to default
At the fundamental level every Timeswap loan can be compared to an option-based design where the borrower buys a put option on selling his collateral to the lenders at maturity in asset terms at a fixed strike price. Premium is the interest paid by the borrowers in the form of collateral locked at the start of taking the loan
- Transition / Strike Price (K) : The price at which a borrower decides whether or not he wants to exercise his right to sell the locked collateral to the lenders is what we are calling the transition price, which in the context of the options is simply the strike price.
The transition price is set by the liquidity provider at the time of pool creation. The farther the spot price relative to transition price the higher the collateral to be locked by borrowers(insurance coverage for lenders) and vice versa.
- Spot/Market price (S): It is the present market exchange price of the collateral with the asset
- Asset Pool and Timeswap: Its the borrower who is swapping tokens in time based on the transition/strike price K. Timeswap pools are designed in such a way that the swap price of the two tokens, for e.g., in the ETH/USDC pool, is always fixed such that ETH=K*USDC and vice versa, followed by an interest component. Because of this fixed swap price (Transition Price) design, the pool will always have only one asset at a time for swapping. This is due to the arbitrage process, which we are calling rebalancing
1) S<K, Only ETH exists in the pool due to rebalancing Deposit USDC as collateral to borrow ETH. 2) S>K, Only USDC exists in the pool due to rebalancing Deposit ETH as collateral to borrow USDC.
This is because of the Transition/Strike price design. Whenever the user wants to lend or borrow an asset that is not in the pool a DEX will be used to swap the asset in the pool to the other token from a DEX to enable lending/borrowing.
The swapping mechanism ensures that the asset value you get out of the pool is always less than what the borrower deposit as collateral. Hence ensuring that the CDP is always >100% (overcollateralized)
In a USDC-ETH pool say K < S -> Fundamentally ETH is available cheaper on Timeswap(K*USDC = 1 ETH) than in the market/DEXes(S*USDC = 1 ETH), thereby, arbitrageurs will withdraw all ETH completely with USDC & pocket the price difference, leaving only USDC in the pool.
- It is expected that only either ETH or USDC (whichever has a cheaper value) exists in the USDC-ETH pool at all times
- This is because of the Transition/Strike price design. Whenever the user wants to lend or borrow an asset that is not in the pool a DEX will be used to swap the asset in the pool to the other token from a DEX to enable lending/borrowing.
Say K > S: ETH is available cheaper in the market than Timeswap therefore arbitrageurs will replace USDC with ETH &
Note - The example is for the USDC-ETH pool ; K is the Transition/Strike Price of the pool ; S is the Spot Price of present market.
Therefore it is expected that only either ETH or USDC (whichever has a cheaper value) exists in the USDC-ETH pool at all times.
Let's take example of an ETH/USDC pool and understand the mechanics of our AMM equation
X= reserves of Collateral Claim token Token-A(CCT ETH) in the pool
Y= reserves of Collateral Claim token Token-B (CCT USDC) in the pool
Z= reserves of Bond tokens(BT) per second in the pool
K= constant product invariant
Z/(X+Y)= Interest rate per second
Holding CCT ETH and CCT USDC means leveraging ETH and USDC as collateral while borrowing. So if a borrower wants to use ETH as collateral to get a USDC loan, he will hold CCT ETH, and the same rule applies to having CCT USDC to borrow ETH while leveraging USDC.
The variable (X+Y) is a constant sum such that the sum of X and Y is always constant. Variable Z is the number of Bond tokens in the pool such that ratio Z/(X+Y) represents the interest rate per second.
The borrowers hold Collateral Claim Tokens (CCT ETH, CCT USDC), and lenders are the counterparty to them, and hold Bond tokens. Hence borrower holds either CCT ETH or CCT USDC based on his collateral. Lenders, on the other hand, have Bond Tokens(BT).
For simplicity, we will refer to an ETH/USDC pool for all future explanations, such that X is CCT ETH and Y is CCT USDC. Due to Rebalancing, Timeswap pools will always have either ETH or USDC in the pool, which means that the pools will either have CCT ETH or CCT USDC tokens.
This makes v2 AMM eventually a constant product AMM like Uniswap V2 AMM with a duration component because, at any given point, it is expected that either x or y = 0,
x*z = K (y=0, K USDC > 1 ETH), hence the contract will mint CCT ETH
Such that CCT ETH -> K CCT USDC by locking K*USDC to get ETH out
y*z = K (x=0, K USDC < 1 ETH), hence the contract will mint CCT USDC
Such that K CCT USDC -> CCT ETH by locking 1 ETH to get K*USDC
If Spot price (S) > Strike price (K) before maturity ->
y*z = K (x=0, K USDC < 1 ETH), The contract will mint CCT USDC
If Spot price (S) < Strike price (K) before maturity ->
x*z = K (y=0, K USDC > 1 ETH, The contract will mint CCT ETH)
- Borrowing Transaction: - Borrow ETH with USDC - Lock K*USDC + K*d*Δz USDC as collateral and get ETH - Borrow USDC with ETH- Lock ETH + dΔz ETH as collateral to get S*USDC