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

Address

Chain

ETHEREUM

BINANCE

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

HandlerID List

HandlerID

Name

Address

Chain

0

ETHER

X

ETHEREUM

1

USDT

0xdac17f958d2ee523a2206206994597c13d831ec7

ETHEREUM

2

DAI

0x6b175474e89094c44da98b954eedeac495271d0f

ETHEREUM

3

LINK

0x514910771af9ca656af840dff83e8264ecf986ca

ETHEREUM

4

USDC

0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48

ETHEREUM

5

WBTC

0x2260fac5e5542a773aa44fbcfedf7c193bc2c599

ETHEREUM

0

BNB

X

BINANCE

1

ETHER

0xf86d8218BCC15874f5D25c191FdDd43F2334c3EB

BINANCE

2

USDT

0x2A29598cbc17BA112C8Fd0E07Fbf5402eF57E6b8

BINANCE

3

DAI

0xB67C5433d234d656002f12664d15ab4b40666D9B

BINANCE

4

USDC

0xBA9De5a8FD91408826616f2d6d7470A11E34c9F0

BINANCE

5

BTCB

0x26d0E4707af1c1DAAd8e9BA21b99cDa7Fd24c40B

BINANCE

6

BUSD

0x829ED2a2BeF8b72e648f92CBF01587C7E12e8c1e

BINANCE

Last updated