Skip to content

Commit 9558e54

Browse files
0xVolosnikovAmxx
andauthored
Remove redundant memory usage in ERC2981 royaltyInfo (#4538)
Co-authored-by: Hadrien Croubois <[email protected]>
1 parent d398d68 commit 9558e54

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

contracts/token/common/ERC2981.sol

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@ abstract contract ERC2981 is IERC2981, ERC165 {
5959
* @inheritdoc IERC2981
6060
*/
6161
function royaltyInfo(uint256 tokenId, uint256 salePrice) public view virtual returns (address, uint256) {
62-
RoyaltyInfo memory royalty = _tokenRoyaltyInfo[tokenId];
62+
RoyaltyInfo storage _royaltyInfo = _tokenRoyaltyInfo[tokenId];
63+
address royaltyReceiver = _royaltyInfo.receiver;
64+
uint96 royaltyFraction = _royaltyInfo.royaltyFraction;
6365

64-
if (royalty.receiver == address(0)) {
65-
royalty = _defaultRoyaltyInfo;
66+
if (royaltyReceiver == address(0)) {
67+
royaltyReceiver = _defaultRoyaltyInfo.receiver;
68+
royaltyFraction = _defaultRoyaltyInfo.royaltyFraction;
6669
}
6770

68-
uint256 royaltyAmount = (salePrice * royalty.royaltyFraction) / _feeDenominator();
71+
uint256 royaltyAmount = (salePrice * royaltyFraction) / _feeDenominator();
6972

70-
return (royalty.receiver, royaltyAmount);
73+
return (royaltyReceiver, royaltyAmount);
7174
}
7275

7376
/**

0 commit comments

Comments
 (0)