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

Contract size optimization - remove unused royalty fetcher to reduce contract size #140

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
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
13 changes: 0 additions & 13 deletions src/royalties/CreatorRoyaltiesControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ abstract contract CreatorRoyaltiesControl is CreatorRoyaltiesStorageV1, SharedBa
receiver = config.royaltyRecipient;
}

/// @notice Returns the supply royalty information for a given token.
/// @param tokenId The token ID to get the royalty information for.
/// @param mintAmount The amount of tokens being minted.
/// @param totalSupply The total supply of the token,
function supplyRoyaltyInfo(uint256 tokenId, uint256 totalSupply, uint256 mintAmount) public view returns (address receiver, uint256 royaltyAmount) {
RoyaltyConfiguration memory config = getRoyalties(tokenId);
if (config.royaltyMintSchedule == 0) {
return (config.royaltyRecipient, 0);
}
uint256 totalRoyaltyMints = (mintAmount + (totalSupply % config.royaltyMintSchedule)) / (config.royaltyMintSchedule - 1);
return (config.royaltyRecipient, totalRoyaltyMints);
}

function _updateRoyalties(uint256 tokenId, RoyaltyConfiguration memory configuration) internal {
// Don't allow 100% supply royalties
if (configuration.royaltyMintSchedule == 1) {
Expand Down
19 changes: 16 additions & 3 deletions test/royalties/CreatorRoyaltiesControl.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ contract CreatorRoyaltiesControlTest is Test {
response = new bytes[](0);
}

/// @notice Returns the supply royalty information for a given token.
/// @param tokenId The token ID to get the royalty information for.
/// @param mintAmount The amount of tokens being minted.
/// @param totalSupply The total supply of the token,
function supplyRoyaltyInfo(uint256 tokenId, uint256 totalSupply, uint256 mintAmount) public view returns (address receiver, uint256 royaltyAmount) {
ICreatorRoyaltiesControl.RoyaltyConfiguration memory config = target.getRoyalties(tokenId);
if (config.royaltyMintSchedule == 0) {
return (config.royaltyRecipient, 0);
}
uint256 totalRoyaltyMints = (mintAmount + (totalSupply % config.royaltyMintSchedule)) / (config.royaltyMintSchedule - 1);
return (config.royaltyRecipient, totalRoyaltyMints);
}

function test_GetsRoyaltiesInfoGlobalDefault() external {
address royaltyPayout = address(0x999);

Expand All @@ -44,7 +57,7 @@ contract CreatorRoyaltiesControlTest is Test {
uint256 tokenId = target.setupNewToken("test", 100);

(address royaltyRecipient, uint256 amount) = target.royaltyInfo(tokenId, 1 ether);
(, uint256 supplyAmount) = target.supplyRoyaltyInfo(tokenId, 0, 100);
(, uint256 supplyAmount) = supplyRoyaltyInfo(tokenId, 0, 100);
assertEq(amount, 0.001 ether);
assertEq(royaltyRecipient, royaltyPayout);
assertEq(supplyAmount, 11);
Expand All @@ -66,13 +79,13 @@ contract CreatorRoyaltiesControlTest is Test {
vm.stopPrank();

(address royaltyRecipient, uint256 amount) = target.royaltyInfo(tokenIdFirst, 1 ether);
(, uint256 supplyAmount) = target.supplyRoyaltyInfo(tokenIdFirst, 0, 100);
(, uint256 supplyAmount) = supplyRoyaltyInfo(tokenIdFirst, 0, 100);
assertEq(amount, 0.001 ether);
assertEq(supplyAmount, 1);
assertEq(royaltyRecipient, royaltyPayout);

(address royaltyRecipientSecond, uint256 amountSecond) = target.royaltyInfo(tokenIdSecond, 1 ether);
(, uint256 supplyAmountSecond) = target.supplyRoyaltyInfo(tokenIdSecond, 0, 100);
(, uint256 supplyAmountSecond) = supplyRoyaltyInfo(tokenIdSecond, 0, 100);
assertEq(amountSecond, 0.01 ether);
assertEq(supplyAmountSecond, 11);
assertEq(royaltyRecipientSecond, address(0x992));
Expand Down