Bunny Crosschain Farming Development

Bunny Finance
8 min readFeb 17, 2021

--

Team Bunny Introduces Crosschain Farming

Background

In 2020, the DeFi market experienced remarkable quantitative and qualitative growth in TVL and transaction volumes on the Ethereum network. At the same time, everyday investors experience difficulties due to the rising transaction costs that have accompanied the exponential increase of DeFi. And the high transaction fees on the Ethereum network have also become a barrier to smart contract development projects and small, early-stage DeFi projects.

At Team Bunny, we have focused on developing and launching a Yield Farming Dapp on BSC, and our experience on BSC has been extremely valuable for a number of important reasons:

  1. BSC development environment is identical to that of the ETH network;
  2. Transaction fees are inexpensive; and
  3. We can deliver higher yields/returns to liquidity providers on BSC vs. the ETH network. (Thank you PancakeSwap!)

However, despite its many advantages, BSC still suffers from comparatively low accessibility vs. ETH for a couple of reasons:

  1. Moving assets from ETH chain to BSC chain is highly burdensome; and
  2. BSC network setting must be done manually on wallets such as Metamask

That’s why Team Bunny is proud to announce a new crosschain farming solution that enables ETH users to farm liquidity yields directly on BSC.

Introduction to Bunny Crosschain

Team Bunny‘s new crosschain farming function double-farms PancakeSwap LP tokens using Uniswap LP tokens as collateral in 12 Steps.

STEP 1. (ETH) A user stakes LP token in ETH collateral vault from Uniswap ETH/USDT pool.

STEP 2. (Cross) Relayer sends request to BSC.

STEP 3. (BSC) Farming Vault Contract borrows Uni-LP collateral worth of BNB from BNB vault.

STEP 4. (BSC) Borrowed BNB is converted to USDT/BNB LP on PancakeSwap and staked (CAKE farming).

STEP 5. (ETH) (after some time) User requests withdrawal of LP.

STEP 6. (Cross) Relayer sends LP withdrawal request to BSC.

STEP 7. (BSC) The staked LP and CAKE profits are withdrawn from PancakeSwap.

STEP 8. (BSC) Both LP and CAKE are swapped for BNB.

STEP 9. (BSC) Swapped BNB used to repay BNB vault and pay interest.

STEP 10. (BSC) After repaying borrowed BNB to BNBVault, all profits are swapped to ETH and staked on ETH vault.

STEP 11. (Cross) Relayer sends profit/loss info from BSC to ETH

STEP 12. (ETH) LP token is returned to user. If there was a profit in BSC, we pay profits in ETH. If there was a loss, the loss is deducted from the LP that was staked and the rest of the funds are returned.

At launch, Bunny Crosschain will only support USDT/ETH, USDC/ETH, DAI/ETH LP tokens.

Crosschain Farming Actors

1. (Uniswap) LP provider for ETH

2. BNB provider for BSC

3. Bunny Relayer; Bunny Oracle

4. Liquidation Requester

1. Uniswap LP Provider

Uniswap LP providers are investors who take risks such as IL to increase their returns.

*** These users borrow and invest BNB from BSC, so if the price of BNB increases by the time of payment, it can result in a loss. ***

When depositing LPs, users can specify the BNB ratio to borrow on the BSC side. The default ratio is 100%, i.e. borrowing an amount of BNB equal to 100% of the collateral value for investment in the PancakeSwap LP on BSC. The user does not directly interact with BSC’s contacts, and all interactions are with the Ethereum network. Interaction with BSC is handled by the Bunny Relayer. The LP contracts have a Timelock function that protects the user’s collateral by allowing the safe withdrawal of deposited LPs if Relayers have not interacted with BSC for over 72 hours.

The minimum deposit value for an LP is $100. The is aimed at preventing spam deposits by malicious users/contracts. On the other hand, the maximum deposit of LPs is limited to about $100,000. There is no limitation if you are interacting with the contract directly, but the UI restricts users from depositing larger amounts. This limitation is due to the size of the USDT/BNB pool in PancakeSwap being approximately $20M as of February 2021. If the USDT/BNB pool becomes larger or smaller, the maximum deposit amount can also be adjusted.

The reason why the maximum deposit amount is limited is that due to the nature of AMM, making USDT/BNB LPs with large funds all at once can cause loss due to slippage.

[Security]

To protect the security of users who supply LPs from Ethereum, the LP Collateral Contract has a Timelock function, which we refer to as our Hashed Timelock Contract for development (the HTLC is a function launched in Bitcoin’s Lightning network.). If the Relayer does not interact for 72 hours, the user can run the Emergency Exit function, a function that enables safe withdrawal of their LPs.

[State Machine]

To implement crosschain transactions at the Dapp level, we devised a Finite State Machine for individual users on the Ethereum LP contract.

1. Idle — A user who has not deposited can only execute the deposit function.

2. Depositing — state when Uniswap LP tokens are deposited but pending or in a state of waiting after sending a deposit request on BSC. In this state, all functions cannot be executed. However, after over 72 hours of deposit (when BSC has not responded), the emergencyExit function may be executed

3. Farming — state when BSC deposit is completed and liquidity is provided to Pancakeswap by borrowing BNB on BSC. In this state, there are three functions that may be executed: 1) updateLeverage, 2) withdrawAll, 3) liquidate (when debt ratio is above 80%)

4. UpdateLeverage — state when BSC investment ratio adjustment is requested but pending. In this state, all functions cannot be executed. However, after over 72 hours of deposit (when BSC has not responded), the emergencyExit function may be executed.

5. Withdrawing — state when waiting after withdrawal request on BSC. In this state, all functions cannot be executed. However, after over 72 hours of deposit (when BSC has not responded), the emergencyExit function may be executed.

6. Liquidating — state when waiting after liquidation request on BSC. In this state, all functions cannot be executed. However, after over 72 hours of deposit (when BSC has not responded), the emergencyExit function may be executed.

[Investor Protection — Liquidation]

The user’s LP may be liquidated if the debt ratio is above 80%. The collateral ratio calculation is BNB value / ( Uniswap LP value + Pancakeswap LP value ) borrowed from BSC. The user may adjust the BNB loan ratio or provide additional collateral for the LP.

[Investor Protection — Slippage]

There will be a transaction fee for making BNB into LP or swapping LPs to BNB. If the trading volume is large compared to liquidity, slippage can occur. Bunny limits the value of USDT-BNB liquidity which can be deposited at once to within 0.5% of the BSC Pancakeswap pool liquidity. ($100,000 as of February 2021)

[Fee]

There is no performance fee in the event of a loss in BSC. A 10% performance fee will be charged only if a profit occurs in BSC. Fees are converted into BUNNY/BNB LP tokens and deposited in the Treasury fund, to later be managed by governance.

2. BNB Provider

This BNB Vault is for users who want to earn interest safely without losing their BNB principal.

The loan interest rate model follows TripleSlopeModel. (Source code for AlphaHomora v1 was forked and partially modified.)

  1. 0%-50% utilization has interest rate of 10%
  2. 50%-95% utilization has interest rate of 10%-25%
  3. 95%-100% utilization has interest rate of 25%-100%

[Protection/Security]

The supplied BNB can only be borrowed from the BSC FlipVault contract (Farming Vault) in Bunny.

[Fee]

10% of the loan interest paid by the borrower is deposited in the treasury fund.

3. Bunny Relayer

All requests from Ethereum to BSC networks are stored in Relayer contracts.

Bunny’s script only conveys the requests recorded in this contract. To ensure irreversible data on both chains, the Ethereum chain and the BSC chain both deliver requests when the confirmation number is greater than 12.* Thus, it takes at least five minutes for a transaction initiated from Ethereum to complete, with 15sec * 12 confirmations + 3sec * 12 confirmations.

(* Why 12 confirmations? Vitalik Buterin replies: https://ethereum.stackexchange.com/questions/183/how-should-i-handle-blockchain-forks-inmy-dapp/203#203)

The Request Forwarder role of Relayer Contract is currently only available in Bunny. Users can compare Relayer contracts on both chains to monitor/audit Bunny’s transactions on both chains.

Other info: Revenue from the BSC is stored as ETH on BSC’s ETH Vault and delivered daily at UTC 00:00 via Binance Panama Bridge.

[Risks]

Relayer script only executes on Google Firebase Functions, and the RPC endpoint used in it is the official RPC endpoint provided by Binance.

(https://docs.binance.org/smart-chain/developer/rpc.html)

Thus problems in Google Cloud or RPC endpoint may delay transaction delivery.

Bunny Oracle

The BNB price and ETH price use the chainlink contract. The price of USDT is treated the same as USD. LP prices use the Fair Price method proposed by Alpha Homora https://blog.alphafinance.io/fair-lp-token-pricing/

BNB, ETH and LP prices are updated every time the Relayer delivers transactions to the opposite chain. BNB Vault’s borrowable asset information is recorded in the Ethereum chain every time a transaction is completed.

4. Liquidation Requester

If the value of Ethereum LPs goes down and the price of borrowed BNBs goes up, users may lack collateral. For assets of users with a collateral ratio of above 80%, the requestor for liquidation may request liquidation of the insolvent LP. When liquidation occurs, the liquidated user will pay a 5% penalty fee out of the assets. The liquidation requester will receive 70% of the penalty fee and 30% will be deposited in the treasury fund.

Future Plans

Look forward to the following functions in future versions of Bunny Crosschain:

  1. (ETH) More diverse forms of collateral: enables collateralization of single assets such as BTC and ETH
  2. (BSC) Neutral position in BNB: Farm without taking a BNB short position. Theoretically, if ⅔ of the borrowed BNB is deposited in Venus, it can be used to borrow USDT in an amount equal to ⅓ of the borrowed BNB, and USDT-BNB LP tokens could be created without selling BNB. *** But IL would be inevitable in this case too. ***

Team Bunny’s goal is bring Defi to the casual, mass market . Team Bunny pledges to continuously endeavor to facilitate and popularize access and utilization of the power of DeFi. Come and join us in our journey! Thank you for your support!

--

--

Bunny Finance

One of the most popular auto-compounding yield aggregators on the Binance Smart Chain. https://pancakebunny.finance/