Understanding Flash Loan Smart Contract
Developer guide to execute Unilend Flashloan
SETTING UP FLASHLOAN
Please note that executing a flash loan is a complex transaction and the user should have a sound understanding of Solidity to fully comprehend the structure and models used within the smart contracts.
Overview of cycle to execute flash loan:
Your contract
_receiver
calls the Unilend smart contract, requesting loan of certain_amount
from the_reserve
.Unilend smart contract runs some sanity check and then transfer the
_amount
from the
_reserve
to your contract_receiver
.Your contract
_receiver
holding the_amount
execute implementation of your code.Once your code is executed you transfer the flash loan
_amount
to_reserve
along with_fee
.
1. Create your flash loan contract
To develop your own flash loan contract, start building contract interface over Unilend library UnilendFlashLoanReceiverBase
2. Executing flash loan
Create a executeOperation()
function within the contract for implementing your arbitary logic and requesting fund with local function transferInternal()
3. Calling flash loan
Define a flashloanCall()
function inside your smart contract taking relevant parameters as _asset
and _amount
that would be passed to local function flashLoan()
of UnilendFlashLoanRecieverBase
4. Completing flash loan transaction
Once you have performed your logic with the flash loaned assets (in your executeOperation()
function), you will need to pay back the flash loaned amounts. In the payback cycle ensure that *your contract* has enough of funds to pay the _fee
Last updated