-
Notifications
You must be signed in to change notification settings - Fork 9
/
FlashLoanReceiverBase.sol
47 lines (37 loc) · 2.11 KB
/
FlashLoanReceiverBase.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
// Original: https://github.com/aave/aave-protocol/blob/master/contracts/flashloan/base/FlashLoanReceiverBase.sol
pragma solidity ^0.5.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/math/SafeMath.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/SafeERC20.sol";
import "https://github.com/mrdavey/ez-flashloan/blob/remix/contracts/aave/IFlashLoanReceiver.sol";
import "https://github.com/mrdavey/ez-flashloan/blob/remix/contracts/aave/ILendingPoolAddressesProvider.sol";
import "https://github.com/mrdavey/ez-flashloan/blob/remix/contracts/aave/EthAddressLib.sol";
import "https://github.com/mrdavey/ez-flashloan/blob/remix/contracts/utils/Withdrawable.sol";
contract FlashLoanReceiverBase is IFlashLoanReceiver, Withdrawable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
ILendingPoolAddressesProvider public addressesProvider;
constructor(address _addressProvider) public {
addressesProvider = ILendingPoolAddressesProvider(_addressProvider);
}
function() external payable { }
function transferFundsBackToPoolInternal(address _reserve, uint256 _amount) internal {
address payable core = addressesProvider.getLendingPoolCore();
transferInternal(core, _reserve, _amount);
}
function transferInternal(address payable _destination, address _reserve, uint256 _amount) internal {
if(_reserve == EthAddressLib.ethAddress()) {
//solium-disable-next-line
(bool success, )=_destination.call.value(_amount)("");
require(success == true, "Couldn't transfer ETH");
return;
}
IERC20(_reserve).safeTransfer(_destination, _amount);
}
function getBalanceInternal(address _target, address _reserve) internal view returns(uint256) {
if(_reserve == EthAddressLib.ethAddress()) {
return _target.balance;
}
return IERC20(_reserve).balanceOf(_target);
}
}