Skip to content

Instantly share code, notes, and snippets.

@zaryab2000
Created January 17, 2021 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaryab2000/852258edcfeda37034fd5cf22fdf1fac to your computer and use it in GitHub Desktop.
Save zaryab2000/852258edcfeda37034fd5cf22fdf1fac to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
contract TrusterLenderPool is ReentrancyGuard {
IERC20 public damnValuableToken;
constructor (address tokenAddress) public {
damnValuableToken = IERC20(tokenAddress);
}
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