Skip to content

Commit

Permalink
fix: Check condition before calling handleUnderSpending (gas)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximebrugel committed Nov 29, 2021
1 parent 4e931c6 commit 08e2689
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions contracts/NestedFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato
_decreaseHoldingAmount(_nftId, address(_inputToken), _inputTokenAmount);
}

_handleUnderSpending(_inputTokenAmount - feesAmount, amountSpent, _inputToken);
if (_inputTokenAmount - feesAmount - amountSpent > 0) {
_handleUnderSpending(_inputTokenAmount - feesAmount, amountSpent, _inputToken);
}

tokenSold = _inputToken;
}
Expand Down Expand Up @@ -412,7 +414,9 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato
_inputToken,
_outputToken
);
_handleUnderSpending(_amountToSpend, amounts[1], IERC20(_inputToken));
if (_amountToSpend - amounts[1] > 0) {
_handleUnderSpending(_amountToSpend, amounts[1], IERC20(_inputToken));
}
} else {
_safeTransferWithFees(IERC20(_inputToken), _amountToSpend, _msgSender(), _nftId);
}
Expand Down Expand Up @@ -478,10 +482,8 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato
uint256 _amountSpent,
IERC20 _token
) private {
if (_amountToSpent - _amountSpent > 0) {
ExchangeHelpers.setMaxAllowance(_token, address(feeSplitter));
feeSplitter.sendFees(_token, _amountToSpent - _amountSpent);
}
ExchangeHelpers.setMaxAllowance(_token, address(feeSplitter));
feeSplitter.sendFees(_token, _amountToSpent - _amountSpent);
}

/// @dev Send a fee to the FeeSplitter, royalties will be paid to the owner of the original asset
Expand Down

0 comments on commit 08e2689

Please sign in to comment.