From 95cfcf6227b1ebacce840bd5934565fcbfcd39dd Mon Sep 17 00:00:00 2001 From: Vectorized Date: Mon, 6 Nov 2023 18:47:07 +0000 Subject: [PATCH] Make tests for all other incentives --- contracts/modules/SuperMinterV1_1.sol | 4 +- tests/modules/SuperMinterV1_1.t.sol | 80 ++++++++++++++++++--------- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/contracts/modules/SuperMinterV1_1.sol b/contracts/modules/SuperMinterV1_1.sol index b5770df2..1216ff7f 100644 --- a/contracts/modules/SuperMinterV1_1.sol +++ b/contracts/modules/SuperMinterV1_1.sol @@ -334,6 +334,7 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 { TotalPriceAndFees memory f = _totalPriceAndFees(p.tier, d, p.quantity, p.signedPrice); MintedLogData memory l; + l.affiliate = p.to == p.affiliate ? address(0) : p.affiliate; // Yeah, we know it's left curved. unchecked { if (msg.value != f.total) revert WrongPayment(msg.value, f.total); // Require exact payment. @@ -342,7 +343,7 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 { l.finalPlatformFee = f.platformFee; // Initialize to the platform fee. // Affiliate fee workflow. - if (l.affiliated = _isAffiliatedWithProof(d, p.affiliate, p.affiliateProof)) { + if (l.affiliated = _isAffiliatedWithProof(d, l.affiliate, p.affiliateProof)) { l.finalArtistFee -= f.affiliateFee; l.finalPlatformFee -= f.affiliateIncentive; l.finalAffiliateFee = f.affiliateFee + f.affiliateIncentive; @@ -378,7 +379,6 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 { l.allowlisted = p.allowlisted; l.allowlistedQuantity = p.allowlistedQuantity; l.signedClaimTicket = p.signedClaimTicket; - l.affiliate = p.affiliate; l.requiredEtherValue = f.total; l.unitPrice = f.unitPrice; diff --git a/tests/modules/SuperMinterV1_1.t.sol b/tests/modules/SuperMinterV1_1.t.sol index cbeee8a3..5c17dbfe 100644 --- a/tests/modules/SuperMinterV1_1.t.sol +++ b/tests/modules/SuperMinterV1_1.t.sol @@ -757,7 +757,7 @@ contract SuperMinterV1_1Tests is TestConfigV2 { } } - function testMintWithAffiliateIncentive(uint256) public { + function testMintWithIncentives(uint256) public { SuperMinterV1_1Constants memory smc = _superMinterConstants(); address[] memory feeRecipients = _twoRandomUniqueAddresses(); @@ -781,6 +781,10 @@ contract SuperMinterV1_1Tests is TestConfigV2 { pfc.perMintFlat = uint96(_bound(_random(), 0, smc.MAX_PLATFORM_PER_MINT_FLAT_FEE)); pfc.perMintBPS = uint16(_bound(_random(), 0, smc.MAX_PLATFORM_PER_MINT_FEE_BPS)); pfc.affiliateIncentive = uint96(_bound(_random(), 0, pfc.perMintFlat)); + pfc.freeMintIncentive = uint96(_bound(_random(), 0, pfc.perMintFlat - pfc.affiliateIncentive)); + pfc.firstCollectorIncentive = uint96( + _bound(_random(), 0, pfc.perMintFlat - pfc.affiliateIncentive - pfc.freeMintIncentive) + ); pfc.active = true; vm.prank(c.platform); sm.setPlatformFeeConfig(1, pfc); @@ -811,23 +815,31 @@ contract SuperMinterV1_1Tests is TestConfigV2 { vm.expectEmit(true, true, true, true); ISuperMinterV1_1.MintedLogData memory l; - l.quantity = p.quantity; - l.fromTokenId = 1; - l.affiliate = p.affiliate; - l.affiliated = true; - l.requiredEtherValue = tpaf.total; - l.unitPrice = tpaf.unitPrice; - l.finalArtistFee = tpaf.total - tpaf.platformFee - tpaf.affiliateFee; - l.finalPlatformFee = tpaf.platformFee - tpaf.affiliateIncentive; - l.finalAffiliateFee = tpaf.affiliateFee + tpaf.affiliateIncentive; - l.finalFreeMintFee = 0; - l.finalFirstCollectorFee = 0; + { + l.quantity = p.quantity; + l.fromTokenId = 1; + l.affiliate = p.affiliate; + l.affiliated = true; + l.requiredEtherValue = tpaf.total; + l.unitPrice = tpaf.unitPrice; + uint256 finalFreeMintFee = tpaf.unitPrice == 0 ? tpaf.freeMintIncentive : 0; + l.finalArtistFee = tpaf.total - tpaf.platformFee - tpaf.affiliateFee + finalFreeMintFee; + l.finalPlatformFee = + tpaf.platformFee - + tpaf.affiliateIncentive - + finalFreeMintFee - + tpaf.firstCollectorIncentive; + l.finalAffiliateFee = tpaf.affiliateFee + tpaf.affiliateIncentive; + l.finalFreeMintFee = finalFreeMintFee; + l.finalFirstCollectorFee = tpaf.firstCollectorIncentive; + } emit Minted(address(edition), 1, 0, address(this), l, 0); sm.mintTo{ value: tpaf.total }(p); assertEq(sm.platformFeesAccrued(c.platform), l.finalPlatformFee); assertEq(sm.affiliateFeesAccrued(p.affiliate), l.finalAffiliateFee); - assertEq(address(sm).balance, l.finalPlatformFee + l.finalAffiliateFee); + assertEq(sm.firstCollectorFeesAccrued(p.to), l.finalFirstCollectorFee); + assertEq(address(sm).balance, l.finalPlatformFee + l.finalAffiliateFee + l.finalFirstCollectorFee); assertEq(address(edition).balance, l.finalArtistFee); // Perform the withdrawals and check if the balances tally. @@ -838,6 +850,11 @@ contract SuperMinterV1_1Tests is TestConfigV2 { uint256 balanceBefore = address(p.affiliate).balance; sm.withdrawForAffiliate(p.affiliate); assertEq(address(p.affiliate).balance, balanceBefore + l.finalAffiliateFee); + assertEq(address(sm).balance, l.finalPlatformFee + l.finalFirstCollectorFee); + + balanceBefore = address(p.to).balance; + sm.withdrawForFirstCollector(p.to); + assertEq(address(p.to).balance, balanceBefore + l.finalFirstCollectorFee); assertEq(address(sm).balance, l.finalPlatformFee); balanceBefore = address(feeRecipients[0]).balance; @@ -850,22 +867,25 @@ contract SuperMinterV1_1Tests is TestConfigV2 { vm.expectEmit(true, true, true, true); ISuperMinterV1_1.MintedLogData memory l; - l.quantity = p.quantity; - l.fromTokenId = 1; - l.affiliate = address(0); - l.affiliated = false; - l.requiredEtherValue = tpaf.total; - l.unitPrice = tpaf.unitPrice; - l.finalArtistFee = tpaf.total - tpaf.platformFee; - l.finalPlatformFee = tpaf.platformFee; - l.finalAffiliateFee = 0; - l.finalFreeMintFee = 0; - l.finalFirstCollectorFee = 0; + { + l.quantity = p.quantity; + l.fromTokenId = 1; + l.affiliate = address(0); + l.affiliated = false; + l.requiredEtherValue = tpaf.total; + l.unitPrice = tpaf.unitPrice; + uint256 finalFreeMintFee = tpaf.unitPrice == 0 ? tpaf.freeMintIncentive : 0; + l.finalArtistFee = tpaf.total - tpaf.platformFee + finalFreeMintFee; + l.finalPlatformFee = tpaf.platformFee - finalFreeMintFee - tpaf.firstCollectorIncentive; + l.finalAffiliateFee = 0; + l.finalFreeMintFee = finalFreeMintFee; + l.finalFirstCollectorFee = tpaf.firstCollectorIncentive; + } emit Minted(address(edition), 1, 0, address(this), l, 0); - sm.mintTo{ value: tpaf.total }(p); + sm.mintTo{ value: tpaf.total }(p); assertEq(sm.platformFeesAccrued(c.platform), l.finalPlatformFee); - assertEq(address(sm).balance, l.finalPlatformFee); + assertEq(address(sm).balance, l.finalPlatformFee + l.finalFirstCollectorFee); assertEq(address(edition).balance, l.finalArtistFee); // Perform the withdrawals and check if the balances tally. @@ -873,7 +893,12 @@ contract SuperMinterV1_1Tests is TestConfigV2 { sm.setPlatformFeeAddress(feeRecipients[0]); assertEq(sm.platformFeeAddress(c.platform), feeRecipients[0]); - uint256 balanceBefore = address(feeRecipients[0]).balance; + uint256 balanceBefore = address(p.to).balance; + sm.withdrawForFirstCollector(p.to); + assertEq(address(p.to).balance, balanceBefore + l.finalFirstCollectorFee); + assertEq(address(sm).balance, l.finalPlatformFee); + + balanceBefore = address(feeRecipients[0]).balance; sm.withdrawForPlatform(c.platform); assertEq(address(feeRecipients[0]).balance, balanceBefore + l.finalPlatformFee); assertEq(sm.platformFeeAddress(c.platform), feeRecipients[0]); @@ -940,6 +965,7 @@ contract SuperMinterV1_1Tests is TestConfigV2 { p.signedClaimTicket = uint32(_bound(_random(), 0, type(uint32).max)); p.signedDeadline = type(uint32).max; p.affiliate = _randomNonZeroAddress(); + while (p.affiliate == p.to) p.affiliate = _randomNonZeroAddress(); p.signature = _generateSignature(p, privateKey); vm.deal(address(this), type(uint192).max);