Created
January 16, 2021 18:11
-
-
Save zaryab2000/6b97c3a94719789a53ed9232e4f5e178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flashLoan( | |
uint256 borrowAmount, | |
address borrower, | |
address target, | |
bytes calldata data | |
) | |
external | |
nonReentrant | |
{ | |
uint256 balanceBefore = damnValuableToken.balanceOf(address(this)); | |
require(balanceBefore >= borrowAmount, "Not enough tokens in pool"); | |
damnValuableToken.transfer(borrower, borrowAmount); | |
(bool success, ) = target.call(data); | |
require(success, "External call failed"); | |
uint256 balanceAfter = damnValuableToken.balanceOf(address(this)); | |
require(balanceAfter >= balanceBefore, "Flash loan hasn't been paid back"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment