πŸ”¦Flash Loan

Flash Loan is a feature for developers. There is no page for users on Palmy Finance. Developers can borrow all available assets without collateral by borrowing and repaying in one transaction. Developers can implement a contract for Flash Loan, which allows more leveraged DeFi operations than features on palmy.finance.

Flash Loans are an advanced concept aimed at developers. You must have a good understanding of Blockchain, programming, and smart contracts to be able to use this feature.

Overview

Flash-loan allows users to access liquidity of the pool (only for reserves for which borrow is enabled) for one transaction as long as the amount taken plus fee is returned or (if allowed) debt position is opened by the end of the transaction.

Execution Flow

For developers, a helpful mental model to consider when developing your solution:

  1. Your contract calls the contract which is responsible for flashloan (LendingPool for EVM, FlashloanGateway for WASM), requesting a Flash Loan of a certain amount(s) of reserve(s) using flashLoan().

  2. After some sanity checks, the contract transfers the requested amounts of the reserves to your contract, then calls executeOperation() on receiver contract.

  3. Your contract, now holding the flash loaned amount(s), executes any arbitrary operation in its code. For all the reserves either depending on FLASHLOAN_PREMIUM_TOTAL passed for the asset, either the contract must be approved for flash loaned amount + fee or must or sufficient collateral or credit delegation should be available to open debt position.

    • If the amount owing is not available (due to a lack of balance or approval or insufficient collateral for debt), then the transaction is reverted.

  4. All of the above happens in 1 transaction (hence in a single block).

Flash loan fee

The flash loan fee is initialized at deployment to 0.09% and can be updated via Governance Vote. Use FLASHLOAN_PREMIUM_TOTAL to get current value.

EVM Implementation

Base Interfaces

If you want to execute Flash Loan, your contract should implement the interface below.

This is the base contract that implements the interface.

Example Contract

You can implement your contract by inheriting the base contract. In the executeOperation function, you can code what you want to do with the borrowed assets by Flash Loan.

Palmy Lending Pool Contract

LendingPool contract, which is provided by Palmy Finance, has the function to do Flash Loan.

LendingPool.sol

Last updated