From 9558e546d9996d533eeb5151569a52d611eca08b Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Mon, 25 Mar 2024 17:06:28 +0100 Subject: [PATCH] Remove redundant memory usage in ERC2981 royaltyInfo (#4538) Co-authored-by: Hadrien Croubois --- contracts/token/common/ERC2981.sol | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/contracts/token/common/ERC2981.sol b/contracts/token/common/ERC2981.sol index b61c09d28..70e8f4691 100644 --- a/contracts/token/common/ERC2981.sol +++ b/contracts/token/common/ERC2981.sol @@ -59,15 +59,18 @@ abstract contract ERC2981 is IERC2981, ERC165 { * @inheritdoc IERC2981 */ function royaltyInfo(uint256 tokenId, uint256 salePrice) public view virtual returns (address, uint256) { - RoyaltyInfo memory royalty = _tokenRoyaltyInfo[tokenId]; + RoyaltyInfo storage _royaltyInfo = _tokenRoyaltyInfo[tokenId]; + address royaltyReceiver = _royaltyInfo.receiver; + uint96 royaltyFraction = _royaltyInfo.royaltyFraction; - if (royalty.receiver == address(0)) { - royalty = _defaultRoyaltyInfo; + if (royaltyReceiver == address(0)) { + royaltyReceiver = _defaultRoyaltyInfo.receiver; + royaltyFraction = _defaultRoyaltyInfo.royaltyFraction; } - uint256 royaltyAmount = (salePrice * royalty.royaltyFraction) / _feeDenominator(); + uint256 royaltyAmount = (salePrice * royaltyFraction) / _feeDenominator(); - return (royalty.receiver, royaltyAmount); + return (royaltyReceiver, royaltyAmount); } /**