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

BUILDBEAR // TUTORIALS

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

BuildBear Logo

Bug Found 🐛: 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. 

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:

Untitled (35).png

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.

(c) 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:

  1. Where is the test with the Real World Data?
  2. Where is the real world Uniswap?
  3. 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?)
  4. 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

Untitled design (6).gif

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
Untitled (36).png

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

Untitled (37).png

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

VariableValue
The spot price of ARB1.16
Strike Price1.7
Days to Expiry23
Volatility of ARB(%)80
Int. Rate (%)1.05

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:

Option GreeksValue
DELTA-0.964
THETA-0
VEGA0
GAMMA0.3392
RHO0.001

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.
Untitled (39).png

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

Option GreeksValue
DELTA-0.9997
THETA-0
VEGA0
GAMMA0.0049
RHO0.0004

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).

Untitled design (5).gif
  • 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. 

Untitled (40).png

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.

Next, let's calculate the effective earnings:

  • On the borrow position, we paid out 15 ARB, which amounts to 17.4 USDC.
  • On the lend position, we received 135 USDC.

Hence, the net returns amounted to 117.6 USDC.

Quant traders often look to take delta-neutral positions with gamma variance and zero risk to profit from the volatility of the underlying asset. By creating a delta-neutral portfolio, traders can profit from changes in the asset price without being exposed to directional risk. This strategy is often used in options trading, where gamma represents the rate of change in delta with respect to the underlying asset price. By effectively managing the gamma of the portfolio, traders can minimize their risk while still taking advantage of market movements.

Conclusion

Thanks to the permissionless nature of Timeswap, we successfully implemented a delta-neutral trading strategy. By minimizing directional risk and capitalizing on asset volatility, our trades achieved a net Delta value close to zero. Through the strategic closure of the borrow position and claiming of the lend position, we secured a net return of 117.6 USDC.

Using BuildBear for your QA

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

  1. Create an internal QA Environment for your team, or
  2. 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.

Author: chandan

Let’s get started then, Shall we?