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] : Gas optimizations fixes #101

Merged
merged 13 commits into from
Feb 20, 2022
Merged

Conversation

@maximebrugel maximebrugel added the To review Let people know this PR is ready for a review label Feb 18, 2022
@@ -138,7 +137,7 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, OwnableProxyDelegatio
/// @inheritdoc INestedFactory
function unlockTokens(IERC20 _token) external override onlyOwner {
uint256 amount = _token.balanceOf(address(this));
_token.safeTransfer(owner(), amount);
SafeERC20.safeTransfer(_token, msg.sender, amount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ The logic has changed here. Is that on purpose?
Previous logic was sending tokens to the owner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is onlyOwner, so msg.sender = owner(). It was better to user msg.sender instead of calling the function.

Comment on lines +234 to +235
_transferFeeWithRoyalty(amountFees, _buyToken, _nftId);
_safeTransferAndUnwrap(_buyToken, amountBought, _msgSender());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the gas opt worth doing something like this?
From what I read in the documentation, it should be safe to englobe the rest of the function in the unchecked scope but it still makes me a bit uncomfortable while reading the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the function calls inside the unchecked block because they need to reach the two variables (amountBought and amountFees ), everything declared inside a block is not reachable (unchecked {...} or simply {...}).
However, It will not effect the _transferFeeWithRoyalty and _transferFeeWithRoyalty that will stay checked, it only affect arithmetic operations :
image

doc

@adrien-supizet adrien-supizet removed the To review Let people know this PR is ready for a review label Feb 20, 2022
@maximebrugel maximebrugel merged commit d1cb432 into master Feb 20, 2022
@maximebrugel maximebrugel deleted the gas-optimizations branch February 20, 2022 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants