- python3 version 3.6 or greater, python3-dev
- ganache-cli - tested with version 6.10.1
- brownie version 1.11.6 or greater
Install all necessary packages with
yarn install
Function signature for bZx flash loan
function flashBorrow(
uint256 borrowAmount,
address borrower,
address target,
string calldata signature,
bytes calldata data
) external payable returns (bytes memory);
- borrowAmount - amount you want to flash borrow
- borrower - receiver of the flash borrow call
- target - target address for flash borrow callback
- signature - function signature to be encoded with
abi.encodePacked(bytes4(keccak256(bytes(signature))), data)
, if not provideddata
will be used as callData instead - data - target address function arguments.
- returns signature funciton operation results.
To take a flash loan in USDC you need to call flashBorrow
on the iUSDC contract. List of iToken contracts can be found here
BZxFlashLoaner
is an example contract that takes opportunity of the bZx flash loans. it does so in several steps:
- Transaction entry point
doStuffWithFlashLoan
- Loan initialization
initiateFlashLoanBzx
- operation with loaned money
executeOperation
- return loaned money before executeOperation end
repayFlashLoan
- final checks
doStuffWithFlashLoan
. you can actually revert a transaction at this time if you consider your transaction not profitable for example
Flash Loans are uncolaterized loans that are required to be returned in the same transaction. There is no real world analogy. the closes you can compare is with overnight market
or Repurchase Agreement
but without collateral.
Please note currently bZx flash loans are FREE. you pay ZERO fees for taking a flash loan.
There are a couple of use cases where someone might use flash loans:
- Arbitrage
- Liquidations
- re-finance exiting loans
- other
For any dev related questions and support please join our Discord #dev channel. We have a very active community.
To run the tests, first install the developer dependencies:
pip install -r requirements.txt
Make sure you have environemtn variables setup for ETHERSCAN and INFIRA
export ETHERSCAN_TOKEN= ...
export WEB3_INFURA_PROJECT_ID= ...
Run the all tests with:
brownie test --network mainnet-fork
This project is licensed under the Apache License, Version 2.0.