2020-05-29 16:45:37 +00:00
|
|
|
// SPDX-License-Identifier: agpl-3.0
|
|
|
|
pragma solidity ^0.6.8;
|
|
|
|
|
|
|
|
import "@openzeppelin/contracts/math/SafeMath.sol";
|
|
|
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
|
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
|
|
|
import "../interfaces/IFlashLoanReceiver.sol";
|
|
|
|
import "../../interfaces/ILendingPoolAddressesProvider.sol";
|
|
|
|
import "../../libraries/EthAddressLib.sol";
|
|
|
|
|
|
|
|
abstract contract FlashLoanReceiverBase is IFlashLoanReceiver {
|
|
|
|
|
|
|
|
using SafeERC20 for IERC20;
|
|
|
|
using SafeMath for uint256;
|
|
|
|
|
|
|
|
ILendingPoolAddressesProvider public addressesProvider;
|
|
|
|
|
|
|
|
constructor(ILendingPoolAddressesProvider _provider) public {
|
|
|
|
addressesProvider = _provider;
|
|
|
|
}
|
|
|
|
|
|
|
|
receive() external payable {}
|
|
|
|
|
|
|
|
function transferFundsBackToPoolInternal(address _reserve, uint256 _amount) internal {
|
|
|
|
|
2020-06-20 23:40:03 +00:00
|
|
|
address payable pool = payable(addressesProvider.getLendingPool());
|
2020-05-29 16:45:37 +00:00
|
|
|
|
2020-06-20 23:40:03 +00:00
|
|
|
transferInternal(pool,_reserve, _amount);
|
2020-05-29 16:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function transferInternal(address payable _destination, address _reserve, uint256 _amount) internal {
|
|
|
|
if(_reserve == EthAddressLib.ethAddress()) {
|
|
|
|
//solium-disable-next-line
|
|
|
|
_destination.call{value: _amount}("");
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|