github.com/cwntr/go-defi@v0.0.0-20210629134751-07f9ec2f7e66/contracts/handlers/aave/FlashLoanReceiverBase.sol (about) 1 pragma solidity ^0.5.0; 2 3 import "./ILendingPoolAddressesProvider.sol"; 4 import "@openzeppelin/contracts/math/SafeMath.sol"; 5 import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 6 import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 7 8 9 contract FlashLoanReceiverBase { 10 using SafeERC20 for IERC20; 11 using SafeMath for uint256; 12 13 address constant PROVIDER = 0x24a42fD28C976A61Df5D00D0599C34c4f90748c8; 14 address constant ETHADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; 15 16 function transferFundsBackToPoolInternal(address _reserve, uint256 _amount) 17 internal 18 { 19 address payable core = ILendingPoolAddressesProvider(PROVIDER) 20 .getLendingPoolCore(); 21 22 transferInternal(core, _reserve, _amount); 23 } 24 25 function transferInternal( 26 address payable _destination, 27 address _reserve, 28 uint256 _amount 29 ) internal { 30 if (_reserve == ETHADDRESS) { 31 _destination.call.value(_amount)(""); 32 return; 33 } 34 IERC20(_reserve).safeTransfer(_destination, _amount); 35 } 36 37 function getBalanceInternal(address _target, address _reserve) 38 internal 39 view 40 returns (uint256) 41 { 42 if (_reserve == ETHADDRESS) { 43 return _target.balance; 44 } 45 return IERC20(_reserve).balanceOf(_target); 46 } 47 }