mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Fixes tests on flashloans
This commit is contained in:
parent
048a2de7de
commit
56fa10bd8f
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user