Created
July 10, 2022 05:43
-
-
Save JuanXavier/57ed97541392cb81570dfb0f72bc9128 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.0; | |
| import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | |
| import "@openzeppelin/contracts/utils/Address.sol"; | |
| import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | |
| contract TrusterLenderPool is ReentrancyGuard { | |
| using Address for address; | |
| IERC20 public immutable damnValuableToken; | |
| constructor(address tokenAddress) { | |
| 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); | |
| target.functionCall(data); | |
| 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