aave-protocol-v2/contracts/flashloan/base/FlashLoanReceiverBase.sol

52 lines
1.4 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.8;
2020-07-13 08:54:08 +00:00
import '@openzeppelin/contracts/math/SafeMath.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '../interfaces/IFlashLoanReceiver.sol';
import '../../interfaces/ILendingPoolAddressesProvider.sol';
import '../../libraries/UniversalERC20.sol';
abstract contract FlashLoanReceiverBase is IFlashLoanReceiver {
2020-07-13 08:54:08 +00:00
using UniversalERC20 for IERC20;
using SafeMath for uint256;
2020-07-13 08:54:08 +00:00
ILendingPoolAddressesProvider public addressesProvider;
2020-07-13 08:54:08 +00:00
constructor(ILendingPoolAddressesProvider _provider) public {
addressesProvider = _provider;
}
2020-07-13 08:54:08 +00:00
receive() external payable {}
function transferFundsBackInternal(
address _reserve,
address _destination,
uint256 _amount
) internal {
transferInternal(payable(_destination), _reserve, _amount);
2020-07-13 08:54:08 +00:00
}
2020-07-13 08:54:08 +00:00
function transferInternal(
address payable _destination,
address _reserve,
uint256 _amount
) internal {
if (IERC20(_reserve).isETH()) {
//solium-disable-next-line
_destination.call{value: _amount}('');
return;
}
2020-07-13 08:54:08 +00:00
IERC20(_reserve).universalTransfer(_destination, _amount);
}
2020-07-13 08:54:08 +00:00
function getBalanceInternal(address _target, address _reserve) internal view returns (uint256) {
if (IERC20(_reserve).isETH()) {
return _target.balance;
}
2020-07-13 08:54:08 +00:00
return IERC20(_reserve).balanceOf(_target);
}
2020-06-02 14:16:22 +00:00
}