Skip to content

Commit

Permalink
Make tests for all other incentives
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Nov 6, 2023
1 parent 2e1143a commit 95cfcf6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 29 deletions.
4 changes: 2 additions & 2 deletions contracts/modules/SuperMinterV1_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
80 changes: 53 additions & 27 deletions tests/modules/SuperMinterV1_1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -850,30 +867,38 @@ 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.
vm.prank(c.platform);
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]);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 95cfcf6

Please sign in to comment.