DEV Community

Cover image for Testing and Simulating Timeswap || Reporting a Front-End Bug
Chandan | Web3 for BuildBear

Posted on

Testing and Simulating Timeswap || Reporting a Front-End Bug

Timeswap is the first fully (i) permissionless, (ii) oracle-less, (iii) non-liquidatable, fixed-maturity lending & borrowing protocol.

Okay, that is a mouthful. So let’s break it down, dirty.

Permissionless Anyone using the platform can borrow or lend (fixed maturity) an ERC-20, using another ERC-20 token as collateral. Anyone can create a pool. This feature is coming soon on the UI.

Oracle-less Timeswap doesn’t (I really cannot emphasise this enough) depend on a price oracle to fetch the prices of the ERC-20 tokens, to take any action. It rather uses an AMM based on a mathematical function.

Non-liquidatable

There are no liquidations on Timeswap, so any interim volatility during the pool’s life doesn’t impact borrowers. Additionally, there is no hassle of maintaining the health factor.

As a borrower, you must come back before maturity in order to pay back your loans; otherwise, your collateral is distributed to lenders.

Key Features:

Image description

The benefits of these features are well explained in their documentation, so let me not re-invent the wheel.

Using Timeswap to implement Gamma Scalping

We implement Gamma Scalping, we liked, we wrote → that is what this article is; it our review of the dApp:

Timeswap Why? Timeswap is one such DeFi protocol which is completely market driven and has a unique design compared to what exists in the market.

This means there are multiple scenarios under which you need to test/simulate how the market functions. This makes Timeswap ideal for BuildBear to test it.

Please note, for a thorough review of Timeswap, it is imperative that we do a test which pretty much covers all the types of transactions that you will execute on Timeswap. That is: the (a) Lend and (b) Borrow transactions. However, it is not as simple as that, you need to be able to do the following also to review Timeswap:

(a) Pay back your loan to claim your collateral.

(b) Not pay back your loan and let go of the collateral.

© Claim back your lend position, pre-maturity.

(d) Claim back your lend position, post-maturity.

(e) Claim back your lend position when the borrowers have paid back.

(f) Claim back your lend position when the borrowers have NOT paid back. Check if the proportion of tokens received is correct.

so on and so forth (you get the drill).

All of this is NOT possible to be done on the Arbitrum Mainnet. Yes, I could simply tell you that we are testing on the Arbitrum Testnet, but then:

Where is the test with the Real World Data?
Where is the real world Uniswap?
Where are the real tokens? (Do I waste time in creating mock tokens?!?!?, if I must, should I also bother with the prices of these tokens?)
What about time? Do I wait till May 15 to test the other situations? and if I do, will this review be useful at all?
You get the drill again. Its basically a lock-out. Cannot use Arbitrum Mainnet or Arbitrum Testnet.

Thus, for this purpose, we created a Private Testnet of the Arbitrum Mainnet. This was made possible due to BuildBear.

Set-up before the testing: Using our Private Testnet Faucet to mint 40K USDC

Image description

Implementing Gamma scalping

We initiated a borrowing position and employed the Black-Scholes model to compute the option Greek Values. Subsequently, leveraging the Delta value, we executed an additional trade with the intention of achieving a net Delta value of zero, as outlined below.

Borrowed 20,000 ARB from the ARB/USDC pool by locking 34,025 USDC

Image description
As you can see, upon inserting the Amount to Borrow, the UI automatically computes the Collateral to lock.

Image description

This is a computation of simple laws of the economics of supply and demand. The more capital is available for lending in the market the cost to borrow thus reduces.

Calculating Option Greeks

Image description
Based on the pool condition, we have computed the option Greeks using the following online option Greeks calculator: https://www.niftytrader.in/option-pricing-calculator. Here are the results:

Image description

To establish a Delta-neutral position, we extensively explored various pools on Timeswap and successfully identified a trade that effectively neutralizes the Delta.

We lent 34,000 USDC on plsARB/USDC pool.

Image description

By considering the pool condition, we computed the option Greeks as follows

Image description

Option GreeksValue
The Delta value in the first trade is -0.964, while the Delta value in the second trade is 0.9997. As a result, the net Delta value is close to zero (0.03), effectively rendering our trades Delta-neutral.

Advanced the time by one day prior to Maturity (Using the BuildBear utility tools we were able to Advance time as shown below).
Image description

We closed the borrow position by making a payment of 20,013 ARB one day prior to maturity and received 34,025 USDC as collateral.
Discovered a Critical Bug While Claiming the Lending Position: [Read Below]
We encountered a bug during the process of claiming our Lending position in the PlsARB and USDC pool. Unfortunately, the claim amount was not being fetched. As soon as we discovered the issue, we promptly reported it to the TimeSwap Team. They swiftly identified the bug in the front end and resolved the issue.

If this issue had not been resolved, it would have prevented users from claiming their lending amount after maturity. This bug could have had significant implications for users claiming their funds.

After the maturity period, we claimed the lend position and received 34,135 USDC.
Read the Full article published at https://www.buildbear.io/resources/guides-and-tutorials/Timeswap_Borrowing_and_lending to learn about the Net amount we made and our final thoughts.

Using BuildBear for your QA

If you are DeFi Web3 App and you are looking to either

Create an internal QA Environment for your team, or
Creating a private testing environment for your community before releasing to the Mainnet, or
Come talk to us at team@buildbear.io We can help you create your own, 100% customized testing environment, so that you can use it without any hassle.

NOTE: Information in this article shouldn’t be taken as Finance Advice.

Top comments (0)