🔴Borrow Module Flash Loan (Medium - Hard)
Taken✨ (3 weeks)
Flash loans are uncollateralized loans without borrowing limits in which a user borrows funds and returns them in the same transaction. If the user can’t repay the loan before the transaction is completed, a smart contract cancels the transaction and returns the money to the user.
Flash loans present many benefits, check the following article to know more
Many protocols have existing flash loan implementations, those include dYdX flash loans, Aave flash loans and Uniswap flash loans. Unfortunately the interface is different for all these. This is not only bad for the user of such flash loans, having to learn how to use a flash loan in each ecosystem newly. But it's also bad for security when everyone is trying to design a secure mechanism on their own.
That's why we have standards.
EIP-3156 is designed to support various different underlying mechanisms for repaying the loan. It concerns single asset borrow
EIP-3234 is the same for multi loan support
We want to implement a multi flash loan module, as described in the following
As Morphine works with isolated pool, you'll have to create sub FlashLenderManager. These contracts will make the link between each pool and the BtachFlashLender and BatchFlashBorrower. The singlePoolFlashLender contract shall contain borrow methods in order to transfer pool Liq to BatchFlashBorrower and Repay function to transfer borrowed amount + fees from BatchFlashBorrower to the pool. It should also contains view function to access borrow fees and flashBorrower/flashLender address. These parameters can be changed by Flash configurator associated, which is a contract used by admin to change parameters.
Once done, you'll have to build BatchFlashLender and BatchFlashBorrower following the EIP-3234 standard. The BatchFlashBorrower should be able to receive and execute multicall.
Task (Step 1):
Head to lib/morphine/borrowModules/flash and create singlePoolFlashLender.cairo as well as singlePoolFlashLenderConfigurator.cairo
Implement both contract
Once you are ready, setup integration test with protostar (you can copy the template script to setup the protocol infra with pools charged in liquidity).
Task (Step 2):
Head to lib/morphine/borrowModules/flash and create BatchFlashLender.cairo as well as BatchFlashBorrower.cairo
Implement both contracts following the EIP-3234
Once you are ready, setup integration test with protostar, you'll probably want to reuse the test script used in step 1
Last updated