vProtocol Docs
  • Introduction
    • Welcome To vProtocol
    • Protocol Overview
    • Key Features and Benefits
    • Use Case
    • Ecosystem Partners
  • USER GUIDE
    • For Lenders
      • Supply Assets
    • For Borrower
      • Depositing Collateral
      • Borrowing From The Lending Pool
    • For Trader & Developers
      • Using FlashLoans
      • Example Implementation
  • Protocol Architecture
    • Diamond Standard Implementation
    • Core Component
    • Smart Contract Structure
Powered by GitBook
On this page
  • What Are Flash Loans?
  • Use Cases
  • Implementing a Flash Loan Receiver
  • Flash Loan Fee Structure
  • Flash Loan Execution
  • Flash Loan Limitations
  1. USER GUIDE
  2. For Trader & Developers

Using FlashLoans

Flash loans allow you to borrow assets without collateral, as long as the loan is borrowed and repaid within a single transaction.

What Are Flash Loans?

Flash loans are uncollateralized loans that leverage the atomic nature of blockchain transactions - either the entire transaction succeeds (including loan repayment) or it reverts completely.

Use Cases

  • Arbitrage: Profit from price differences between platforms

  • Collateral Swaps: Replace one collateral type with another

  • Liquidations: Provide capital for liquidating positions

  • Self-Liquidation: Save on liquidation fees by self-liquidating

  • Complex DeFi Strategies: Execute multi-step DeFi operations

Implementing a Flash Loan Receiver

To use a flash loan, you must create a contract that implements the IFlashLoanReceiver interface:

interface IFlashLoanReceiver {
    function executeOperation(
        address[] calldata tokens,
        uint256[] calldata amounts,
        uint256[] calldata fees,
        address initiator,
        bytes calldata params
    ) external returns (bool);
}

Your implementation must:

  1. Perform your desired operations

  2. Approve the Five Protocol contract to withdraw the borrowed amount plus fees

  3. Return true if successful

Flash Loan Fee Structure

Flash loans in Five Protocol incur a fee that is added to the repayment amount:

  • Current fee: 0.09% of the borrowed amount

  • Fee is configurable

  • Fees generated contribute to protocol revenue

Flash Loan Execution

To execute a flash loan:

  1. Deploy your receiver contract that implements IFlashLoanReceiver

  2. Call the flashLoan function on the Five Protocol contract:

function flashLoan(
    address receiver,
    address[] calldata tokens,
    uint256[] calldata amounts,
    bytes calldata params
) external returns (bool success);

Where:

  • receiver: Your contract address that implements IFlashLoanReceiver

  • tokens: Array of token addresses to borrow

  • amounts: Array of amounts to borrow

  • params: Additional parameters to pass to your receiver contract

Flash Loan Limitations

  • Maximum loan amount is limited by the available liquidity in the protocol

  • All borrowed assets must be repaid in the same transaction

  • You cannot perform multiple flash loans in the same transaction

PreviousFor Trader & DevelopersNextExample Implementation

Last updated 2 months ago