Created
July 9, 2022 20:29
-
-
Save JuanXavier/96ba0ed21bf4915a07b42db5095ac909 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/utils/Address.sol"; | |
| contract FlashLoanReceiver { | |
| using Address for address payable; | |
| address payable private pool; | |
| constructor(address payable poolAddress) { | |
| pool = poolAddress; | |
| } | |
| // Function called by the pool during flash loan | |
| function receiveEther(uint256 fee) public payable { | |
| require(msg.sender == pool, "Sender must be pool"); | |
| uint256 amountToBeRepaid = msg.value + fee; | |
| require( | |
| address(this).balance >= amountToBeRepaid, | |
| "Cannot borrow that much" | |
| ); | |
| _executeActionDuringFlashLoan(); | |
| // Return funds to pool | |
| pool.sendValue(amountToBeRepaid); | |
| } | |
| // Internal function where the funds received are used | |
| function _executeActionDuringFlashLoan() internal {} | |
| // Allow deposits of ETH | |
| receive() external payable {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment