-
Notifications
You must be signed in to change notification settings - Fork 0
/
bZxFlashLoan.sol
58 lines (51 loc) · 1.53 KB
/
bZxFlashLoan.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
50
51
52
53
54
55
56
57
58
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
// "SPDX-License-Identifier: Apache-2.0"
import "./lib/openzeppelin/IERC20.sol";
import "./lib/bzx/IToken.sol";
import "./ScriptRunner.sol";
contract BZxFlashLoaner {
function initiateFlashLoan(
address loanToken,
address iToken,
uint256 flashLoanAmount
) internal returns (bytes memory success) {
IToken iTokenContract = IToken(iToken);
return
iTokenContract.flashBorrow(
flashLoanAmount,
address(this),
address(this),
"",
abi.encodeWithSignature(
"executeOperation(address,address,uint256)",
loanToken,
iToken,
flashLoanAmount
)
);
}
function repayFlashLoan(
address loanToken,
address iToken,
uint256 loanAmount
) internal {
IERC20(loanToken).transfer(iToken, loanAmount);
}
function executeOperation(
address loanToken,
address iToken,
uint256 loanAmount
) external returns (bytes memory success) {
emit BalanceOf(IERC20(loanToken).balanceOf(address(this)));
emit ExecuteOperation(loanToken, iToken, loanAmount);
repayFlashLoan(loanToken, iToken, loanAmount);
return bytes("1");
}
event ExecuteOperation(
address loanToken,
address iToken,
uint256 loanAmount
);
event BalanceOf(uint256 balance);
}