diff --git a/src/ProtocolRewards.sol b/src/ProtocolRewards.sol index 11b4fd0..35622c7 100644 --- a/src/ProtocolRewards.sol +++ b/src/ProtocolRewards.sol @@ -145,7 +145,6 @@ contract ProtocolRewards is IProtocolRewards, EIP712 { unchecked { withdrawHash = keccak256(abi.encode(WITHDRAW_TYPEHASH, owner, amount, nonces[owner]++, deadline)); } - bytes32 digest = _hashTypedDataV4(withdrawHash); diff --git a/src/abstract/ERC1155/ERC1155RewardsStorageV1.sol b/src/abstract/ERC1155/ERC1155RewardsStorageV1.sol index ef881c1..f2007bd 100644 --- a/src/abstract/ERC1155/ERC1155RewardsStorageV1.sol +++ b/src/abstract/ERC1155/ERC1155RewardsStorageV1.sol @@ -3,4 +3,4 @@ pragma solidity 0.8.17; contract ERC1155RewardsStorageV1 { mapping(uint256 => address) public createReferrals; -} \ No newline at end of file +} diff --git a/src/abstract/RewardSplits.sol b/src/abstract/RewardSplits.sol index 745685c..ad36809 100644 --- a/src/abstract/RewardSplits.sol +++ b/src/abstract/RewardSplits.sol @@ -3,6 +3,14 @@ pragma solidity 0.8.17; import {IProtocolRewards} from "../interfaces/IProtocolRewards.sol"; +struct RewardsSettings { + uint256 creatorReward; + uint256 mintReferralReward; + uint256 createReferralReward; + uint256 firstMinterReward; + uint256 zoraReward; +} + abstract contract RewardSplits { error CREATOR_FUNDS_RECIPIENT_NOT_SET(); error INVALID_ADDRESS_ZERO(); @@ -38,33 +46,30 @@ abstract contract RewardSplits { return numTokens * TOTAL_REWARD_PER_MINT; } - function computeFreeMintRewards( - uint256 numTokens - ) public pure returns (uint256 creatorReward, uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) { - creatorReward = numTokens * CREATOR_REWARD; - mintReferralReward = numTokens * MINT_REFERRAL_FREE_MINT_REWARD; - createReferralReward = numTokens * CREATE_REFERRAL_FREE_MINT_REWARD; - firstMinterReward = numTokens * FIRST_MINTER_REWARD; - zoraReward = numTokens * ZORA_FREE_MINT_REWARD; + function computeFreeMintRewards(uint256 numTokens) public pure returns (RewardsSettings memory) { + return + RewardsSettings({ + creatorReward: numTokens * CREATOR_REWARD, + mintReferralReward: numTokens * MINT_REFERRAL_FREE_MINT_REWARD, + createReferralReward: numTokens * CREATE_REFERRAL_FREE_MINT_REWARD, + firstMinterReward: numTokens * FIRST_MINTER_REWARD, + zoraReward: numTokens * ZORA_FREE_MINT_REWARD + }); } - function computePaidMintRewards( - uint256 numTokens - ) public pure returns (uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) { - mintReferralReward = numTokens * MINT_REFERRAL_PAID_MINT_REWARD; - createReferralReward = numTokens * CREATE_REFERRAL_PAID_MINT_REWARD; - firstMinterReward = numTokens * FIRST_MINTER_REWARD; - zoraReward = numTokens * ZORA_PAID_MINT_REWARD; + function computePaidMintRewards(uint256 numTokens) public pure returns (RewardsSettings memory) { + return + RewardsSettings({ + creatorReward: 0, + mintReferralReward: numTokens * MINT_REFERRAL_PAID_MINT_REWARD, + createReferralReward: numTokens * CREATE_REFERRAL_PAID_MINT_REWARD, + firstMinterReward: numTokens * FIRST_MINTER_REWARD, + zoraReward: numTokens * ZORA_PAID_MINT_REWARD + }); } function _depositFreeMintRewards(uint256 totalReward, uint256 numTokens, address creator, address mintReferral, address createReferral) internal { - ( - uint256 creatorReward, - uint256 mintReferralReward, - uint256 createReferralReward, - uint256 firstMinterReward, - uint256 zoraReward - ) = computeFreeMintRewards(numTokens); + RewardsSettings memory settings = computeFreeMintRewards(numTokens); if (mintReferral == address(0)) { mintReferral = zoraRewardRecipient; @@ -76,20 +81,20 @@ abstract contract RewardSplits { protocolRewards.depositRewards{value: totalReward}( creator, - creatorReward, + settings.creatorReward, mintReferral, - mintReferralReward, + settings.mintReferralReward, createReferral, - createReferralReward, + settings.createReferralReward, creator, - firstMinterReward, + settings.firstMinterReward, zoraRewardRecipient, - zoraReward + settings.zoraReward ); } function _depositPaidMintRewards(uint256 totalReward, uint256 numTokens, address creator, address mintReferral, address createReferral) internal { - (uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = computePaidMintRewards(numTokens); + RewardsSettings memory settings = computePaidMintRewards(numTokens); if (mintReferral == address(0)) { mintReferral = zoraRewardRecipient; @@ -103,13 +108,13 @@ abstract contract RewardSplits { address(0), 0, mintReferral, - mintReferralReward, + settings.mintReferralReward, createReferral, - createReferralReward, + settings.createReferralReward, creator, - firstMinterReward, + settings.firstMinterReward, zoraRewardRecipient, - zoraReward + settings.zoraReward ); } } diff --git a/test/unit/ERC1155Rewards.t.sol b/test/unit/ERC1155Rewards.t.sol index fb2a552..037d039 100644 --- a/test/unit/ERC1155Rewards.t.sol +++ b/test/unit/ERC1155Rewards.t.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.17; import "../ProtocolRewardsTest.sol"; +import {RewardsSettings} from "../../src/abstract/RewardSplits.sol"; contract ERC1155RewardsTest is ProtocolRewardsTest { MockERC1155 internal mockERC1155; @@ -24,14 +25,13 @@ contract ERC1155RewardsTest is ProtocolRewardsTest { vm.prank(collector); mockERC1155.mintWithRewards{value: totalReward}(collector, 0, numTokens, mintReferral); - (uint256 creatorReward, uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC1155 - .computeFreeMintRewards(numTokens); + RewardsSettings memory settings = mockERC1155.computeFreeMintRewards(numTokens); assertEq(protocolRewards.totalSupply(), totalReward); - assertEq(protocolRewards.balanceOf(creator), creatorReward + firstMinterReward); - assertEq(protocolRewards.balanceOf(mintReferral), mintReferralReward); - assertEq(protocolRewards.balanceOf(createReferral), createReferralReward); - assertEq(protocolRewards.balanceOf(zora), zoraReward); + assertEq(protocolRewards.balanceOf(creator), settings.creatorReward + settings.firstMinterReward); + assertEq(protocolRewards.balanceOf(mintReferral), settings.mintReferralReward); + assertEq(protocolRewards.balanceOf(createReferral), settings.createReferralReward); + assertEq(protocolRewards.balanceOf(zora), settings.zoraReward); } function test1155PaidMintDeposit(uint16 numTokens, uint256 pricePerToken) public { @@ -49,15 +49,13 @@ contract ERC1155RewardsTest is ProtocolRewardsTest { vm.prank(collector); mockERC1155.mintWithRewards{value: totalValue}(collector, 0, numTokens, mintReferral); - (uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC1155.computePaidMintRewards( - numTokens - ); + RewardsSettings memory settings = mockERC1155.computePaidMintRewards(numTokens); assertEq(protocolRewards.totalSupply(), totalReward); - assertEq(protocolRewards.balanceOf(creator), firstMinterReward); - assertEq(protocolRewards.balanceOf(mintReferral), mintReferralReward); - assertEq(protocolRewards.balanceOf(createReferral), createReferralReward); - assertEq(protocolRewards.balanceOf(zora), zoraReward); + assertEq(protocolRewards.balanceOf(creator), settings.firstMinterReward); + assertEq(protocolRewards.balanceOf(mintReferral), settings.mintReferralReward); + assertEq(protocolRewards.balanceOf(createReferral), settings.createReferralReward); + assertEq(protocolRewards.balanceOf(zora), settings.zoraReward); } function test1155FreeMintNullReferralRecipients(uint16 numTokens) public { @@ -72,12 +70,11 @@ contract ERC1155RewardsTest is ProtocolRewardsTest { vm.prank(collector); mockERC1155.mintWithRewards{value: totalReward}(collector, 0, numTokens, address(0)); - (uint256 creatorReward, uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC1155 - .computeFreeMintRewards(numTokens); + RewardsSettings memory settings = mockERC1155.computeFreeMintRewards(numTokens); assertEq(protocolRewards.totalSupply(), totalReward); - assertEq(protocolRewards.balanceOf(creator), creatorReward + firstMinterReward); - assertEq(protocolRewards.balanceOf(zora), zoraReward + mintReferralReward + createReferralReward); + assertEq(protocolRewards.balanceOf(creator), settings.creatorReward + settings.firstMinterReward); + assertEq(protocolRewards.balanceOf(zora), settings.zoraReward + settings.mintReferralReward + settings.createReferralReward); } function test1155PaidMintNullReferralRecipient(uint16 numTokens, uint256 pricePerToken) public { @@ -97,13 +94,11 @@ contract ERC1155RewardsTest is ProtocolRewardsTest { vm.prank(collector); mockERC1155.mintWithRewards{value: totalValue}(collector, 0, numTokens, address(0)); - (uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC1155.computePaidMintRewards( - numTokens - ); + RewardsSettings memory settings = mockERC1155.computePaidMintRewards(numTokens); assertEq(protocolRewards.totalSupply(), totalReward); - assertEq(protocolRewards.balanceOf(creator), firstMinterReward); - assertEq(protocolRewards.balanceOf(zora), zoraReward + mintReferralReward + createReferralReward); + assertEq(protocolRewards.balanceOf(creator), settings.firstMinterReward); + assertEq(protocolRewards.balanceOf(zora), settings.zoraReward + settings.mintReferralReward + settings.createReferralReward); } function testRevert1155FreeMintInvalidEth(uint16 numTokens) public { diff --git a/test/unit/ERC721Rewards.t.sol b/test/unit/ERC721Rewards.t.sol index 07a955a..f0bdeb8 100644 --- a/test/unit/ERC721Rewards.t.sol +++ b/test/unit/ERC721Rewards.t.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.17; import "../ProtocolRewardsTest.sol"; +import {RewardsSettings} from "../../src/abstract/RewardSplits.sol"; contract ERC721RewardsTest is ProtocolRewardsTest { MockERC721 internal mockERC721; @@ -17,10 +18,13 @@ contract ERC721RewardsTest is ProtocolRewardsTest { function testValidateFreeMintTotalComputation(uint16 numTokens) public { uint256 expectedTotal = mockERC721.computeTotalReward(numTokens); - (uint256 creatorReward, uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC721 - .computeFreeMintRewards(numTokens); + RewardsSettings memory settings = mockERC721.computeFreeMintRewards(numTokens); - uint256 actualTotal = creatorReward + mintReferralReward + createReferralReward + firstMinterReward + zoraReward; + uint256 actualTotal = settings.creatorReward + + settings.mintReferralReward + + settings.createReferralReward + + settings.firstMinterReward + + settings.zoraReward; assertEq(expectedTotal, actualTotal); } @@ -28,11 +32,9 @@ contract ERC721RewardsTest is ProtocolRewardsTest { function testValidatePaidMintTotalComputation(uint32 numTokens) public { uint256 expectedTotal = mockERC721.computeTotalReward(numTokens); - (uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC721.computePaidMintRewards( - numTokens - ); + RewardsSettings memory settings = mockERC721.computePaidMintRewards(numTokens); - uint256 actualTotal = mintReferralReward + createReferralReward + firstMinterReward + zoraReward; + uint256 actualTotal = settings.mintReferralReward + settings.createReferralReward + settings.firstMinterReward + settings.zoraReward; assertEq(expectedTotal, actualTotal); } @@ -47,14 +49,13 @@ contract ERC721RewardsTest is ProtocolRewardsTest { vm.prank(collector); mockERC721.mintWithRewards{value: totalReward}(collector, numTokens, mintReferral); - (uint256 creatorReward, uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC721 - .computeFreeMintRewards(numTokens); + RewardsSettings memory settings = mockERC721.computeFreeMintRewards(numTokens); assertEq(protocolRewards.totalSupply(), totalReward); - assertEq(protocolRewards.balanceOf(creator), creatorReward + firstMinterReward); - assertEq(protocolRewards.balanceOf(mintReferral), mintReferralReward); - assertEq(protocolRewards.balanceOf(createReferral), createReferralReward); - assertEq(protocolRewards.balanceOf(zora), zoraReward); + assertEq(protocolRewards.balanceOf(creator), settings.creatorReward + settings.firstMinterReward); + assertEq(protocolRewards.balanceOf(mintReferral), settings.mintReferralReward); + assertEq(protocolRewards.balanceOf(createReferral), settings.createReferralReward); + assertEq(protocolRewards.balanceOf(zora), settings.zoraReward); } function test721PaidMintDeposit(uint16 numTokens, uint256 pricePerToken) public { @@ -72,15 +73,13 @@ contract ERC721RewardsTest is ProtocolRewardsTest { vm.prank(collector); mockERC721.mintWithRewards{value: totalValue}(collector, numTokens, mintReferral); - (uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC721.computePaidMintRewards( - numTokens - ); + RewardsSettings memory settings = mockERC721.computePaidMintRewards(numTokens); assertEq(protocolRewards.totalSupply(), totalReward); - assertEq(protocolRewards.balanceOf(creator), firstMinterReward); - assertEq(protocolRewards.balanceOf(mintReferral), mintReferralReward); - assertEq(protocolRewards.balanceOf(createReferral), createReferralReward); - assertEq(protocolRewards.balanceOf(zora), zoraReward); + assertEq(protocolRewards.balanceOf(creator), settings.firstMinterReward); + assertEq(protocolRewards.balanceOf(mintReferral), settings.mintReferralReward); + assertEq(protocolRewards.balanceOf(createReferral), settings.createReferralReward); + assertEq(protocolRewards.balanceOf(zora), settings.zoraReward); } function test721FreeMintNullReferralRecipients(uint16 numTokens) public { @@ -95,12 +94,11 @@ contract ERC721RewardsTest is ProtocolRewardsTest { vm.prank(collector); mockERC721.mintWithRewards{value: totalReward}(collector, numTokens, address(0)); - (uint256 creatorReward, uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC721 - .computeFreeMintRewards(numTokens); + RewardsSettings memory settings = mockERC721.computeFreeMintRewards(numTokens); assertEq(protocolRewards.totalSupply(), totalReward); - assertEq(protocolRewards.balanceOf(creator), creatorReward + firstMinterReward); - assertEq(protocolRewards.balanceOf(zora), zoraReward + mintReferralReward + createReferralReward); + assertEq(protocolRewards.balanceOf(creator), settings.creatorReward + settings.firstMinterReward); + assertEq(protocolRewards.balanceOf(zora), settings.zoraReward + settings.mintReferralReward + settings.createReferralReward); } function test721PaidMintNullReferralRecipient(uint16 numTokens, uint256 pricePerToken) public { @@ -120,13 +118,11 @@ contract ERC721RewardsTest is ProtocolRewardsTest { vm.prank(collector); mockERC721.mintWithRewards{value: totalValue}(collector, numTokens, address(0)); - (uint256 mintReferralReward, uint256 createReferralReward, uint256 firstMinterReward, uint256 zoraReward) = mockERC721.computePaidMintRewards( - numTokens - ); + RewardsSettings memory settings = mockERC721.computePaidMintRewards(numTokens); assertEq(protocolRewards.totalSupply(), totalReward); - assertEq(protocolRewards.balanceOf(creator), firstMinterReward); - assertEq(protocolRewards.balanceOf(zora), zoraReward + mintReferralReward + createReferralReward); + assertEq(protocolRewards.balanceOf(creator), settings.firstMinterReward); + assertEq(protocolRewards.balanceOf(zora), settings.zoraReward + settings.mintReferralReward + settings.createReferralReward); } function testRevert721CreatorFundsRecipientNotSet(uint16 numTokens) public {