FlashLoan

Introduction

There are numerous ways to grow profit by participating in the DeFi ecosystem. However, most opportunities such as staking, loan arbitrage, and liquidation are limited to the amount of capital one initially has. But now, there is another opportunity in DeFi that allow users to utilize their capital without limits using flash loans, opening up new financial strategies never imagined before.

BiFi offers both flash loans and traditional lending. Flash loans allow users to trade with leverage without any collateral as long as it executes both the borrowing and the repayment of loans in one block transaction. Maximize your profits and pursue a myriad of strategies you were unable to before with BiFi FlashLoan.

You can use BiFi FlashLoans in two ways:

  1. BIFI-X: As an extension of BiFi, users are able to use BiFi FlashLoan most effectively through yield farming or long/short position strategies. BiFi's flash loans allow users to leverage their capital, completing both the borrowing and loan repayment in a single transaction.

  2. Direct use: One groundbreaking feature of BiFi FlashLoan is that users can borrow uncollateralized loans. However, this is only possible through developing smart contracts. BiFi-X automates this arduous process, but in order to use BiFi FlashLoan, users need to be able to develop smart contracts.

In addition, users must pay fees to use BiFi FlashLoan. However, users who hold BiFi tokens will receive discount in fees according to the amount they hold (BiFi tokens can be earned as a reward from using the BiFi lending platform). Learn how to calculate BiFi FlashLoan fee below.

Calculating FlashLoan Fee

BiFi FlashLoan Fee is calculated according to a fixed rate (feeRate) of the loan. If the user owns BiFi tokens, a discount rate is applied to the fee according to the number of tokens.

FlashLoan Fee Calculation Formula

// calculate fee
discountRate = 0.1 + 0.9 * min(1, discountBase / bifiAmount)
FlashLoan Fee = flashLoanAmount * feeRate * discountRate
  • discountRate: The final discount rate. It is changed according to the number of user's BiFi tokens(bifiAmount). The more you have, the higher the discount rate. (maximum discountBase)

  • feeRate: Basic rate of BiFi FlashLoan fee

Using BiFi FlashLoan

BiFi X Service

BiFi-X platform is where you can use the BiFi FlashLoan service the most effectively. Maximize your profits by leveraging your own capital with BiFi FlashLoan.

Direct Usage Of Smart Contracts

BiFi FlashLoan service is provided by the interaction between the FlashLoan Receiver Contract created by the user and the FlashLoan Contract, which provides a FlashLoan service using the BiFi token pool.

  • FlashLoan Contract: This is a system contract that provides the liquidity of BiFi FlashLoan upon request from users using the liquidity of BiFi.

  • FlashLoanReceiver Contract: Functions as a Smart Wallet to receive a loan from BiFi FlashLoan and perform tasks. Users should request a FlashLoan by using the flashloan() function provided by the FlashLoan Contract and implement their tasks in the executeOperation() function. This executeOperation() function must follow the strict rule of repaying the loan with a fee after the users pursue their needs.

Flashloan Template Tutorial

Preparation of FlashLoan

  1. The user deploys the FlashloanReceiver contract with the FlashLoan contract address as an imput value.

    // _managerAddr : FlashLoan contract address
    constructor(address _managerAddr)
  2. User sends coins equal to FlashLoan Fee to FlashLoanReceiver Contract.

Steps to launch FlashLoan

  1. User calls the flashloan function of the FlashLoanReceiver Contract.

    // handlerID : ID of handler to borrow asset via Flashloan
    // amount : Amount of cryptocurrencies to be lended by Flashloan
    **// The standard of amount is unifiedAmount(10**18), not Decimal of each token.**
    // params : Encoded parameters to pass to Flashloan's executeOperation function터
    function flashloan(uint256 handlerID, uint256 amount, bytes calldata params)
  2. FlashLoanReceiver Contract calls the flashloan function of FlashLoan Contract.

    // handlerID, amount, params :Factors passed in step (1)
    // receiverAddress: Address to recieve flashLoan
    function flashloan(uint256 handlerID, address receiverAddress, uint256 amount, bytes calldata params) external returns (bool)
  3. FlashLoan Contract calls executeFlashloan of HandlerProxy Contract to request execution of flashLoan.

  4. The HandlerProxy Contract sends tokens to the FlashLoanReceiver Contract equal to the amount of requested FlashLoan.

  5. FlashLoan Contract calls the executeOperation function of FlashLoanReceiver.

    // reserve****:**** Address of asset (Token) borrowed through Flashloan
    // amount: Number of assets (cryptocurrenices) borrowed through Flashloan
    // fee: Number of fees of Flashloan
    // params: Encoded parameters passed through the flashloan function
    function executeOperation(address reserve, uint256 amount, uint256 fee, bytes calldata params)
  6. After executing the user-defined logic, the FlashLoanReceiver Contract performs Repay as much as the sum of the amount and fee, the imput value of step (5).

Appendix: Contract Information

The FlashLoan Contract information to use the FlashLoan service is as follows.

FlashLoan Contract List

The list of tokens and HandlerIDs that can be loaned within the FlashLoan service are as follows.

HandlerID List

Last updated