update universalTransferFromSenderToThis with returnExcess

This commit is contained in:
andyk 2020-06-04 10:57:08 +03:00
parent 43b5c2c832
commit a281bdba97
5 changed files with 8 additions and 8 deletions

View File

@ -36,7 +36,7 @@ contract MockKyberProxy {
) external payable returns (uint256) { ) external payable returns (uint256) {
require(tokenToBurn.mint(1 ether), "TRADE_WITH_HINT. Reverted mint()"); require(tokenToBurn.mint(1 ether), "TRADE_WITH_HINT. Reverted mint()");
if (!_fromToken.isETH()) { if (!_fromToken.isETH()) {
_fromToken.universalTransferFromSenderToThis(_amount); _fromToken.universalTransferFromSenderToThis(_amount, true);
} }
tokenToBurn.universalTransfer(msg.sender, 1 ether); tokenToBurn.universalTransfer(msg.sender, 1 ether);
return 1 ether; return 1 ether;

View File

@ -55,7 +55,7 @@ contract MockOneSplit is IOneSplit {
) public override payable { ) public override payable {
require(tokenToBurn.mint(10000 ether), "TRADE_WITH_HINT. Reverted mint()"); require(tokenToBurn.mint(10000 ether), "TRADE_WITH_HINT. Reverted mint()");
if (!fromToken.isETH()) { if (!fromToken.isETH()) {
fromToken.universalTransferFromSenderToThis(amount); fromToken.universalTransferFromSenderToThis(amount, true);
} }
tokenToBurn.universalTransfer(msg.sender, 10000 ether); tokenToBurn.universalTransfer(msg.sender, 10000 ether);
} }

View File

@ -322,7 +322,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
"User is sending ETH along with the ERC20 transfer." "User is sending ETH along with the ERC20 transfer."
); );
} }
IERC20(_reserve).universalTransferFromSenderToThis(_amount); IERC20(_reserve).universalTransferFromSenderToThis(_amount, true);
//solium-disable-next-line //solium-disable-next-line
emit Deposit(_reserve, msg.sender, _amount, _referralCode, block.timestamp); emit Deposit(_reserve, msg.sender, _amount, _referralCode, block.timestamp);
@ -646,13 +646,13 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
"User is sending ETH along with the ERC20 transfer." "User is sending ETH along with the ERC20 transfer."
); );
} }
IERC20(_reserve).universalTransferFromSenderToThis(vars.paybackAmountMinusFees); IERC20(_reserve).universalTransferFromSenderToThis(vars.paybackAmountMinusFees, false);
if (vars.isETH) { if (vars.isETH) {
uint256 exceedAmount = msg.value uint256 exceedAmount = msg.value
.sub(vars.originationFee) .sub(vars.originationFee)
.sub(vars.paybackAmountMinusFees); .sub(vars.paybackAmountMinusFees);
//send excess ETH back to the caller in needed //send excess ETH back to the caller if needed
if (exceedAmount > 0) { if (exceedAmount > 0) {
IERC20(_reserve).universalTransfer(msg.sender, exceedAmount); IERC20(_reserve).universalTransfer(msg.sender, exceedAmount);
} }

View File

@ -256,7 +256,7 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
//transfers the principal currency to the pool //transfers the principal currency to the pool
IERC20(_reserve).universalTransferFromSenderToThis( IERC20(_reserve).universalTransferFromSenderToThis(
vars.actualAmountToLiquidate vars.actualAmountToLiquidate, true
); );
if (vars.feeLiquidated > 0) { if (vars.feeLiquidated > 0) {

View File

@ -99,7 +99,7 @@ library UniversalERC20 {
* @param token underlying asset address * @param token underlying asset address
* @param amount to move * @param amount to move
**/ **/
function universalTransferFromSenderToThis(IERC20 token, uint256 amount) function universalTransferFromSenderToThis(IERC20 token, uint256 amount, bool returnExcess)
internal internal
{ {
if (amount == 0) { if (amount == 0) {
@ -107,7 +107,7 @@ library UniversalERC20 {
} }
if (isETH(token)) { if (isETH(token)) {
if (msg.value > amount) { if (msg.value > amount && returnExcess) {
// Return remainder if exist // Return remainder if exist
(bool result, ) = msg.sender.call{ (bool result, ) = msg.sender.call{
value: msg.value.sub(amount), value: msg.value.sub(amount),