-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleFlashLoan.sol
49 lines (39 loc) · 1.38 KB
/
simpleFlashLoan.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import "@aave/core-v3/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
import "@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol";
import "@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol";
contract SimpleFlashLoan is FlashLoanSimpleReceiverBase {
address payable owner;
constructor(
address _addressProvider
) FlashLoanSimpleReceiverBase(IPoolAddressesProvider(_addressProvider)) {}
function fn_RequestFlashLoan(address _token, uint256 _amount) public {
address receiverAddress = address(this);
address asset = _token;
uint256 amount = _amount;
bytes memory params = "";
uint16 referralCode = 0;
POOL.flashLoanSimple(
receiverAddress,
asset,
amount,
params,
referralCode
);
}
//This function is called after your contract has received the flash loaned amount
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address initiator,
bytes calldata params
) external override returns (bool) {
//Logic goes here
uint256 totalAmount = amount + premium;
IERC20(asset).approve(address(POOL), totalAmount);
return true;
}
receive() external payable {}
}