From 199d386b3e226e8dc5444457922b789264567ac0 Mon Sep 17 00:00:00 2001 From: andyk Date: Wed, 3 Jun 2020 15:51:17 +0300 Subject: [PATCH] removal of transferToReserve method --- contracts/lendingpool/LendingPool.sol | 25 +++++++++++------ contracts/lendingpool/LendingPoolCore.sol | 27 ------------------- .../LendingPoolLiquidationManager.sol | 9 +++++-- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index e8d0b337..0a209f24 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -315,8 +315,13 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable { //minting AToken to user 1:1 with the specific exchange rate aToken.mintOnDeposit(msg.sender, _amount); - //transfer to the core contract - core.transferToReserve{value: msg.value}(_reserve, msg.sender, _amount); + //transfer to the pool + if (!IERC20(_reserve).isETH()) { //TODO: review needed, most probably we can remove it + require( + msg.value == 0, + "User is sending ETH along with the ERC20 transfer." + ); + IERC20(_reserve).universalTransferFromSenderToThis(_amount); //solium-disable-next-line emit Deposit(_reserve, msg.sender, _amount, _referralCode, block.timestamp); @@ -623,13 +628,17 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable { } //sending the total msg.value if the transfer is ETH. - //the transferToReserve() function will take care of sending the + //the universalTransferFromSenderToThis() function will take care of sending the //excess ETH back to the caller - core.transferToReserve{ value: vars.isETH ? msg.value.sub(vars.originationFee) : 0 }( - _reserve, - msg.sender, - vars.paybackAmountMinusFees - ); + if (!IERC20(_reserve).isETH()) { //TODO: review needed, most probably we can remove it + require( + msg.value == 0, + "User is sending ETH along with the ERC20 transfer." + ); + } + IERC20(_reserve).universalTransferFromSenderToThis{ + value: vars.isETH ? msg.value.sub(vars.originationFee) : 0 + }(vars.paybackAmountMinusFees); emit Repay( _reserve, diff --git a/contracts/lendingpool/LendingPoolCore.sol b/contracts/lendingpool/LendingPoolCore.sol index c99c9743..5273d028 100644 --- a/contracts/lendingpool/LendingPoolCore.sol +++ b/contracts/lendingpool/LendingPoolCore.sol @@ -472,33 +472,6 @@ contract LendingPoolCore is VersionedInitializable { IERC20(_token).universalTransfer(_feeAddress, _amount); } - /** - * @dev transfers an amount from a user to the destination reserve - * @param _reserve the address of the reserve where the amount is being transferred - * @param _user the address of the user from where the transfer is happening - * @param _amount the amount being transferred - **/ - function transferToReserve(address _reserve, address payable _user, uint256 _amount) - external - payable - onlyLendingPool - { - IERC20 reserve = IERC20(_reserve); - - if (!reserve.isETH()) { - require( - msg.value == 0, - "User is sending ETH along with the ERC20 transfer." - ); - } else { - require( - msg.value >= _amount, - "The amount and the value sent to deposit do not match" - ); - } - reserve.universalTransferFrom(_user, address(this), _amount, true); - } - /** * @notice data access functions **/ diff --git a/contracts/lendingpool/LendingPoolLiquidationManager.sol b/contracts/lendingpool/LendingPoolLiquidationManager.sol index a5f9bea7..fb28f4c0 100644 --- a/contracts/lendingpool/LendingPoolLiquidationManager.sol +++ b/contracts/lendingpool/LendingPoolLiquidationManager.sol @@ -246,11 +246,16 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl //otherwise receives the underlying asset //burn the equivalent amount of atoken collateralAtoken.burnOnLiquidation(_user, maxCollateralToLiquidate); - core.transferToUser(_collateral, msg.sender, maxCollateralToLiquidate); + core.transferToUser(_collateral, msg.sender, maxCollateralToLiquidate); //TODO: update to universal transfer } //transfers the principal currency to the pool - core.transferToReserve{value: msg.value}(_reserve, msg.sender, vars.actualAmountToLiquidate); + IERC20(_reserve).universalTransferFrom( + msg.sender, + addressesProvider.getLendingPool(), + vars.actualAmountToLiquidate, + true + ); if (vars.feeLiquidated > 0) { //if there is enough collateral to liquidate the fee, first transfer burn an equivalent amount of