Five Minutes to Understand the AMM-Based Non-Clearing Lending Protocol Timeswap

Foresight News
2022-05-01 10:55:56
Collection
Lending is just the beginning; Timeswap aims to establish an AMM-based money market.

Written by: iambabywhale.eth, ForesightNews

Currently, the launch of every new public chain in the market is almost accompanied by the establishment of two types of DeFi protocols: one is an AMM-based DEX, and the other is lending. The liquidity required by both accumulates early capital for the new public chain and promotes the subsequent construction of economic infrastructure. Among these, most DEXs have achieved transaction processing using joint curves, and the simple mathematical model makes the logic of DEXs rarely vulnerable. However, the lending protocols next door are at risk of being attacked due to more complex components like oracles.

So is it possible to use joint curves to establish a lending market? Timeswap on Polygon provides a solution.

Protocol Overview

Timeswap is a non-liquidation lending protocol based on AMM built on Polygon. We will detail the protocol's mechanism later; first, let's look at the basic information about Timeswap.

Timeswap went live on the mainnet on March 22, 2022. The current team occasionally opens small lending markets to test the protocol, allowing users to lend their USDC on Polygon or collateralize MATIC to borrow USDC for experimentation. Timeswap announced the completion of its seed round financing in October 2021 but did not disclose the amount raised. Investors participating in this round include Multicoin Capital, Mechanism Capital, and Defiance Capital.

The founding team of Timeswap is mainly composed of Filipinos, including founder Ricsson Ngo, who holds a master's degree in financial mathematics from Ateneo de Manila University and was also the founder of the local community education platform Einstar; co-founder Harshita Singh previously served as the supply chain manager at Walmart in India; another co-founder, Ameeth Devadas, was a product manager at an investment platform linking projects and capital and is notably an angel investor in Polygon. Other members of the founding team include Dipesh Sukhani, founder of Zapper.fi, and Keyur Shah, former Vice President of Finance at Polygon.

Implementation Mechanism

The current lending protocol model is mostly based on liquidity providers supplying a borrowing pool, where borrowers over-collateralize another token to borrow from the pool, and liquidity providers earn interest from borrowers. When the value of the collateral falls below a certain threshold, the collateral will be sold for liquidation, partially compensating LPs for their losses, while the remainder becomes the profit for the liquidator.

Timeswap achieves automated lending through joint curves, eliminating the need for oracles to feed prices and avoiding collateral liquidation. In the previously mentioned lending protocol model, there have been incidents where oracles providing price feeds for certain assets were manipulated, leading to attacks on the protocol. Timeswap aims to establish an open lending market that is immune to oracle attacks and does not require permission, ultimately growing into a large currency market.

The function currently implementing its lending protocol is XYZ=k, where X represents the amount of principal tokens, Y represents the yield per second, Z represents the amount of collateral tokens, and k is a constant, similar to the XY=k model in Uniswap.

For example, when I want to set up a DAI-ETH borrowing pool for 6 months with an initial fund of 10,000 DAI, an expected initial annual yield of 15%, and a collateralization rate of 167%, at this point X=10000, and an annual yield of 15% means that the yield per second Y is 0.0000475 DAI. Assuming the price of Ethereum is 4000 DAI, Z would be 10000*1.67/4000=4.175, so the initial curve formula is:

XYZ=100000.00004754.175=1.98=k

Once the pool is set up, there will be three types of users in the market: LPs who want to continue adding liquidity, lenders, and borrowers. The principle is similar to liquidity providers and traders in Uniswap. When adding or withdrawing liquidity, the parameters increase or decrease proportionally, and the k value changes; when new lenders or borrowers enter or exit the market, the parameters automatically adjust with the increases and decreases of X and Z.

Timeswap achieves all of this by issuing ERC-20 and ERC-721 tokens representing different shares in the pool to each type of participant, and after the market closes, the remaining funds in the pool are distributed proportionally to different participants.

Lenders

Lenders are users who add borrowable assets to the protocol. After transferring borrowable assets, these users will receive four types of tokens: Bond Principal Token (BPT), Bond Interest Token (BIT), Insurance Principal Token (IPT), and Insurance Interest Token (IIT).

BPT represents the share of the borrowable funds pool, which is the total amount of initial borrowable assets plus the funds deposited by lenders minus the funds borrowed by borrowers; BIT represents the share of the interest pool, which is the pool of all interest paid by borrowers; IPT represents the share of unrealized assets within the insurance coverage held by the lender's bond tokens; IIT represents the share of unrealized assets of the bond interest tokens.

Borrowers

Borrowers deposit collateral assets to borrow funds and receive a Collateral Debt Token (CDT) in ERC-721 format, which records the interest the borrower must pay and the information about the locked collateral. Before the due date, if the borrower repays the debt, the token will be destroyed and the collateral released; otherwise, the collateral will be allocated to the lender.

Liquidity Providers

Liquidity providers will receive LP tokens after providing liquidity and will earn profits through the interest rate spread between borrowers and lenders. The CDT tokens received by liquidity providers, as indicated in the official documentation, may represent a share of the profits or may simply be an error.

Data Changes When Lending Occurs

When lending occurs or liquidity increases or decreases, the change in the share of liquidity providers is easy to calculate, as they will only receive LP tokens. The most complex calculations involve lenders and borrowers, and we will use data from the official documentation as an example.

It should be noted in advance that regardless of whether users choose to borrow or lend, they can independently select the relationship between yield and collateral assets. For example, lenders can lower the yield to increase the proportion of their lent assets covered by the borrower's collateral; borrowers can also reduce borrowing interest by increasing the amount of collateral. However, even so, the impact on borrowers is still minimal, as they only need to pay interest based on the data at the time of the transaction.

Lenders

Now, let's assume that the initial parameters of a DAI/ETH lending pool are X=10000, Y=0.0000475 (annual interest rate 15%), Z=4.16, k=1.979, with a term of 1 year. Suppose A deposits 1000 DAI into this pool one month before the term ends, choosing a 10% annual yield. At this point, x=1000, and A's maximum yield when z=0 can be understood as the case where there is no yield insurance, so y=0.00000425, with a maximum yield of about 13.41%. Timeswap defines the minimum yield as 1/16 of the maximum yield, which is 0.84%, ensuring that lenders will have some yield.

A's principal is 1000 DAI, so they will receive 1000 BPT tokens. A 10% annual yield over 30 days will yield approximately 8.19 DAI, so A will receive 8.19 BIT tokens.

Next, we calculate the number of IPT and IIT tokens A will receive. The number of IPT tokens A will receive is the change in Z when Y remains constant, which in this case is 0.37, meaning A will receive 0.37 IPT tokens. Now, substituting the 10% yield into the calculation, the change in Z is z=0.1, and the calculation for IIT is z*30 days in seconds / 2^25=0.0077, meaning A will receive 0.0077 IIT tokens.

At the final settlement, if either the principal or yield is insufficient, the corresponding insurance tokens will be used for repayment. If the tokens in the DAI pool are sufficient to repay the lenders, there is no need to draw from the Ethereum token pool.

Borrowers

With the lender as an example, the calculation for borrowers follows naturally, simply reversing the changes in X that trigger changes in Y and Z to changes in Z that trigger changes in X and Y.

Assuming B wants to borrow 1000 DAI at a 10% interest rate in the same lending pool at the same time, using the same calculation method, B will ultimately need to repay 1008.19 DAI to reclaim the collateral, and the calculation of their collateral is key. First, we calculate the minimum collateral amount, where Y remains constant, and when X decreases by 1000, the change in Z is 0.469. Then, calculating the change in z at a 10% interest rate gives us 0.18, and 0.18*30 days in seconds / 2^25=0.139, so B needs to collateralize a total of 0.4829 ETH to borrow DAI, with a collateralization rate exceeding 190%.

Conclusion

Timeswap uses three variable parameters to process data in the lending pool in real-time. The advantage of this solution is that it avoids issues related to oracle price feeds, thus not being vulnerable to attacks due to oracle manipulation, which also means that long-tail assets can freely establish markets on Timeswap. However, as a decentralized market, Timeswap also has some issues. In lending markets like Aave, the possibility of lenders losing money is almost nonexistent, as collateral assets will be liquidated when they fall below a certain level to compensate the funds invested by lenders. Timeswap is still a periodic lending market, and if there is significant market volatility at the time of maturity, causing the price of collateral assets to fall below that of borrowed assets, lenders may receive collateral as compensation but still incur losses in fiat terms.

Additionally, Timeswap separates principal and yield tokens because previous tests did not distinguish between the two. This means that lenders allocated final funds based on the proportion of principal, which led to situations where, in extreme cases of very high APRs over short periods, lenders could receive a large amount of principal tokens, allowing them to take away most of the tokens from the pool, causing some early lenders to even suffer principal losses. Therefore, setting up two types of tokens can help ensure the safety of lenders' principal, and insurance is also in a state where principal and yield are insured separately.

Timeswap has made an interesting attempt and will gradually enrich its products based on the current lending platform, establishing a large decentralized currency market.

Related tags
ChainCatcher reminds readers to view blockchain rationally, enhance risk awareness, and be cautious of various virtual token issuances and speculations. All content on this site is solely market information or related party opinions, and does not constitute any form of investment advice. If you find sensitive information in the content, please click "Report", and we will handle it promptly.
banner
ChainCatcher Building the Web3 world with innovators