Fixes tests on flashloans

This commit is contained in:
The3D 2020-07-13 15:19:47 +02:00
parent 048a2de7de
commit 56fa10bd8f
4 changed files with 27 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '../interfaces/IFlashLoanReceiver.sol';
import '../../interfaces/ILendingPoolAddressesProvider.sol';
import '../../libraries/UniversalERC20.sol';
import '@nomiclabs/buidler/console.sol';
abstract contract FlashLoanReceiverBase is IFlashLoanReceiver {
using UniversalERC20 for IERC20;
@ -32,12 +33,6 @@ abstract contract FlashLoanReceiverBase is IFlashLoanReceiver {
address _reserve,
uint256 _amount
) internal {
if (IERC20(_reserve).isETH()) {
//solium-disable-next-line
_destination.call{value: _amount}('');
return;
}
IERC20(_reserve).universalTransfer(_destination, _amount);
}

View File

@ -710,7 +710,11 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
vars.protocolFee
);
IERC20(_reserve).universalTransfer(addressesProvider.getTokenDistributor(), vars.protocolFee);
//transfer funds to the receiver
AToken(vars.aTokenAddress).transferUnderlyingTo(
addressesProvider.getTokenDistributor(),
vars.protocolFee
);
//solium-disable-next-line
emit FlashLoan(_receiver, _reserve, _amount, vars.amountFee, vars.protocolFee, block.timestamp);

View File

@ -50,8 +50,10 @@ contract MockFlashLoanReceiver is FlashLoanReceiverBase {
if (!IERC20(_reserve).isETH()) {
token.mint(_fee);
}
//returning amount + fee to the destination
transferFundsBackInternal(_reserve, _destination, _amount.add(_fee));
emit ExecutedWithSuccess(_reserve, _amount, _fee);
}
}

View File

@ -639,15 +639,30 @@ contract AToken is ERC20 {
}
}
function transferUnderlyingTo(address _user, uint256 _amount)
/**
* @dev transfers the underlying asset to the target. Used by the lendingpool to transfer
* assets in borrow(), redeem() and flashLoan()
* @param _target the target of the transfer
* @param _amount the amount to transfer
* @return the amount transferred
**/
function transferUnderlyingTo(address _target, uint256 _amount)
external
onlyLendingPool
returns (uint256)
{
ERC20(underlyingAssetAddress).universalTransfer(_user, _amount);
ERC20(underlyingAssetAddress).universalTransfer(_target, _amount);
return _amount;
}
receive() external payable{
require(ERC20(underlyingAssetAddress).isETH(), "Transfers are only allowed if the underlying asset is ETH");
/**
* @dev receive() function for aTokens who hold ETH as the underlying asset
**/
receive() external payable {
require(
ERC20(underlyingAssetAddress).isETH(),
'Transfers are only allowed if the underlying asset is ETH'
);
}
}