Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeArena] - [L-13] : Make _calculateFees inline #38

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions contracts/NestedFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato

// Amount calculation to send fees and tokens
uint256 amountBought = _buyToken.balanceOf(address(this)) - buyTokenInitialBalance;
uint256 amountFees = _calculateFees(_msgSender(), amountBought);
uint256 amountFees = amountBought / 100;
amountBought = amountBought - amountFees;

_transferFeeWithRoyalty(amountFees, _buyToken, _nftId);
Expand Down Expand Up @@ -295,7 +295,7 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato
for (uint256 i = 0; i < _orders.length; i++) {
amountSpent += _submitOrder(address(_inputToken), _orders[i].token, _nftId, _orders[i], _reserved);
}
feesAmount = _calculateFees(_msgSender(), amountSpent);
feesAmount = amountSpent / 100;
assert(amountSpent <= _inputTokenAmount - feesAmount); // overspent

// If input is from the reserve, update the records
Expand Down Expand Up @@ -353,7 +353,7 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato
}

amountBought = _outputToken.balanceOf(address(this)) - _outputTokenInitialBalance;
feesAmount = _calculateFees(_msgSender(), amountBought);
feesAmount = amountBought / 100;

if (_reserved) {
_transferToReserveAndStore(_outputToken, amountBought - feesAmount, _nftId);
Expand Down Expand Up @@ -540,16 +540,8 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato
address _dest,
uint256 _nftId
) private {
uint256 feeAmount = _calculateFees(_dest, _amount);
uint256 feeAmount = _amount / 100;
_transferFeeWithRoyalty(feeAmount, _token, _nftId);
_token.safeTransfer(_dest, _amount - feeAmount);
}

/// @dev Calculate the fees for a specific user and amount (1%)
/// @param _user The user address
/// @param _amount The amount
/// @return The fees amount
function _calculateFees(address _user, uint256 _amount) private view returns (uint256) {
return _amount / 100;
}
}