Created
July 8, 2022 23:40
-
-
Save JuanXavier/6dd4a8b8434aa733641fe3cead0146a3 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 "../unstoppable/UnstoppableLender.sol"; | |
| import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | |
| contract ReceiverUnstoppable { | |
| UnstoppableLender private immutable pool; | |
| address private immutable owner; | |
| constructor(address poolAddress) { | |
| pool = UnstoppableLender(poolAddress); | |
| owner = msg.sender; | |
| } | |
| // Pool will call this function during the flash loan | |
| function receiveTokens(address tokenAddress, uint256 amount) external { | |
| require(msg.sender == address(pool), "Sender must be pool"); | |
| // Return all tokens to the pool | |
| require( | |
| IERC20(tokenAddress).transfer(msg.sender, amount), | |
| "Transfer of tokens failed" | |
| ); | |
| } | |
| function executeFlashLoan(uint256 amount) external { | |
| require(msg.sender == owner, "Only owner can execute flash loan"); | |
| pool.flashLoan(amount); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment