Flash Loans

Flash Loans offered by Aqualoan allow users to instantly borrow an asset without requiring any collateral upfront, as long as the exact amount borrowed is returned within the same transaction block. Because everything happens atomically within one blockchain transaction, no traditional analogy exists—this is a uniquely blockchain-native feature.

Note: Flash Loans are an advanced concept tailored for experienced developers with a thorough understanding of the EVM, smart contract development, and blockchain mechanics.

Overview Aqualoan’s flash loans grant temporary access to the liquidity available in our protocol’s reserves for a single transaction, provided that the borrowed amount is fully returned by the end of it. Unlike many other protocols, Aqualoan charges absolutely no fees on these instant loans. You can borrow multiple assets at once or just a single asset depending on the method you choose.

Aqualoan offers two primary ways to initiate a flash loan:

multiAssetFlashLoan() Allows borrowers to draw liquidity from several reserves within one call. Developers can also opt to turn the flash loan into a standard variable-rate borrowing position if they meet collateral requirements or utilize credit delegation. Since Aqualoan does not charge fees, there is no need for fee approval.

singleAssetFlashLoan() Enables borrowing a single asset for quick, simple operations. This streamlined method is gas-efficient and suitable if you only need one asset. Again, as our flash loans are free, you do not have to worry about fee overhead.

Execution Flow To better understand how to integrate flash loans into your projects, consider this general sequence:

  1. Your contract (the “receiver”) requests a flash loan from the Aqualoan LiquidityPool contract by calling either singleAssetFlashLoan() or multiAssetFlashLoan(), specifying the desired amount(s).

  2. After verification checks, the LiquidityPool transfers the requested asset(s) to your contract, then immediately triggers the executeOperation() (or similarly named) callback function on your receiver contract.

  3. Now holding the borrowed assets, your contract can perform any logic you’ve programmed—such as complex arbitrage, liquidation strategies, or atomic financial transactions—within the same transaction.

  4. Upon completion, your contract must ensure the borrowed amount is ready to be returned. In Aqualoan’s flash loan model, no additional fees are required, so you simply ensure the full borrowed principal is still available.

  5. If the borrowed amount isn’t repaid (due to insufficient balance, missing approvals, or lack of collateral if you intended to open a loan position), the entire transaction is reverted, ensuring no partial states are committed.

All of this occurs in a single transaction (one blockchain block).

Applications of Flash Loans Because Aqualoan’s flash loans are fee-free, developers can more economically implement various strategies:

  • Execute complex arbitrage opportunities between DeFi platforms without needing starting capital.

  • Perform liquidations efficiently, using instant borrowed funds and repaying them all within the same block.

  • Experiment with creative on-chain financial engineering without incurring extra costs.

Step-by-step Guide

  1. Setting Up Your contract that receives and handles the flash loan must implement the appropriate interface (for example, IAqualoanReceiver) to guarantee it can handle the callback function that the LiquidityPool will invoke. Since the LiquidityPool will pull the returned funds automatically, your contract must grant it the necessary token approvals.

  2. Calling the Flash Loan Methods To trigger a flash loan, you can:

    • Send a transaction from an externally owned account (EOA) directly calling multiAssetFlashLoan() or singleAssetFlashLoan() on the LiquidityPool, specifying your receiver contract’s address.

    • Call the flash loan methods from another contract you control, making sure the receiverAddress is set to your designated receiver contract.

    • Use the same contract for receiving and requesting by passing address(this) as the receiverAddress.

    It’s strongly advised not to store significant funds permanently in your receiver contract due to potential griefing attacks.

  3. Completing the Flash Loan Operation Once executeOperation() is invoked, perform your desired logic using the borrowed funds. When you finish, ensure the LiquidityPool can pull back the exact borrowed amount. Because Aqualoan does not charge fees, you need only return the same principal.

    If you’ve chosen a mode that incurs a debt position (i.e., converting part of the flash loan into a standard borrow), ensure the appropriate collateral or credit delegation setup is in place. The debt will be opened on behalf of the address you specified, assuming they’ve authorized you to do so.

By following these steps, developers can seamlessly integrate free, instantaneous flash loans from Aqualoan into their decentralized applications, unlocking new realms of on-chain financial possibilities.

Last updated