-
Notifications
You must be signed in to change notification settings - Fork 6
/
FlashLoanReceiverBase.sol
44 lines (35 loc) · 1.73 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
pragma solidity ^0.6.6;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/docs-v3.x/contracts/math/SafeMath.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/docs-v3.x/contracts/token/ERC20/IERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/docs-v3.x/contracts/token/ERC20/SafeERC20.sol";
import "./IFlashLoanReceiver.sol";
import "./ILendingPoolAddressesProvider.sol";
import "./Withdrawable.sol";
abstract contract FlashLoanReceiverBaseV1 is IFlashLoanReceiverV1, Withdrawable {
using SafeERC20 for IERC20;
using SafeMath for uint256;
address constant ethAddress = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
ILendingPoolAddressesProviderV1 public addressesProvider;
constructor(address _addressProvider) public {
addressesProvider = ILendingPoolAddressesProviderV1(_addressProvider);
}
receive() payable external {}
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 == ethAddress) {
(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 == ethAddress) {
return _target.balance;
}
return IERC20(_reserve).balanceOf(_target);
}
}