From e36520819f0a325366c10bd01966cc1723284428 Mon Sep 17 00:00:00 2001 From: Arr00 <13561405+arr00@users.noreply.github.com> Date: Wed, 3 Jan 2024 15:01:33 -0500 Subject: [PATCH] additional tests. Identical math --- .../authorities/BondingCurveAuthority.sol | 22 ++++++------ test/authorities/BondingCurveAuthority.t.sol | 36 ++++++++++++++++++- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/contracts/authorities/BondingCurveAuthority.sol b/contracts/authorities/BondingCurveAuthority.sol index 1dead07c..3645481c 100644 --- a/contracts/authorities/BondingCurveAuthority.sol +++ b/contracts/authorities/BondingCurveAuthority.sol @@ -300,7 +300,7 @@ contract BondingCurveAuthority { party, msg.sender, tokenIds, - msg.value, + totalCost, partyDaoFee, treasuryFee, creatorFee @@ -412,15 +412,12 @@ contract BondingCurveAuthority { partyInfo.a, partyInfo.b ); + uint256 partyDaoFee = (bondingCurvePrice * partyDaoFeeBps) / BPS; + uint256 treasuryFee = (bondingCurvePrice * treasuryFeeBps) / BPS; + uint256 creatorFee = (bondingCurvePrice * (partyInfo.creatorFeeOn ? creatorFeeBps : 0)) / + BPS; // Note: 1 is subtracted for each NFT to account for rounding errors - return - (bondingCurvePrice * - (BPS - - partyDaoFeeBps - - treasuryFeeBps - - (partyInfo.creatorFeeOn ? creatorFeeBps : 0))) / - BPS - - amount; + return bondingCurvePrice - partyDaoFee - treasuryFee - creatorFee - amount; } /** @@ -458,9 +455,10 @@ contract BondingCurveAuthority { bool creatorFeeOn ) public view returns (uint256) { uint256 bondingCurvePrice = _getBondingCurvePrice(supply, amount, a, b); - return - (bondingCurvePrice * - (BPS + partyDaoFeeBps + treasuryFeeBps + (creatorFeeOn ? creatorFeeBps : 0))) / BPS; + uint256 partyDaoFee = (bondingCurvePrice * partyDaoFeeBps) / BPS; + uint256 treasuryFee = (bondingCurvePrice * treasuryFeeBps) / BPS; + uint256 creatorFee = (bondingCurvePrice * (creatorFeeOn ? creatorFeeBps : 0)) / BPS; + return bondingCurvePrice + partyDaoFee + treasuryFee + creatorFee; } /** diff --git a/test/authorities/BondingCurveAuthority.t.sol b/test/authorities/BondingCurveAuthority.t.sol index ac430051..d80e727f 100644 --- a/test/authorities/BondingCurveAuthority.t.sol +++ b/test/authorities/BondingCurveAuthority.t.sol @@ -424,9 +424,28 @@ contract BondingCurveAuthorityTest is SetupPartyHelper { (Party party, , ) = _createParty(1, true); uint256 priceToBuy = authority.getPriceToBuy(party, 10); + uint256 expectedBondingCurvePrice = (priceToBuy * 1e4) / + (1e4 + TREASURY_FEE_BPS + PARTY_DAO_FEE_BPS + CREATOR_FEE_BPS); + uint256 expectedPartyDaoFee = (expectedBondingCurvePrice * PARTY_DAO_FEE_BPS) / 1e4; + uint256 expectedTreasuryFee = (expectedBondingCurvePrice * TREASURY_FEE_BPS) / 1e4; + uint256 expectedCreatorFee = (expectedBondingCurvePrice * CREATOR_FEE_BPS) / 1e4; + + uint256[] memory tokenIds = new uint256[](10); + for (uint256 i = 0; i < 10; i++) tokenIds[i] = i + 2; uint256 balanceBefore = address(this).balance; - authority.buyPartyCards{ value: priceToBuy + 1 }(party, 10, address(0)); + vm.expectEmit(true, true, true, true); + emit PartyCardsBought( + party, + address(this), + tokenIds, + priceToBuy, + expectedPartyDaoFee, + expectedTreasuryFee, + expectedCreatorFee + ); + + authority.buyPartyCards{ value: priceToBuy + 100 }(party, 10, address(0)); assertEq(address(this).balance, balanceBefore - priceToBuy); } @@ -729,6 +748,21 @@ contract BondingCurveAuthorityTest is SetupPartyHelper { authority.claimPartyDaoFees(); } + function test_claimPartyDaoFees_revertIfTransferFails() public { + _createParty(1, true); + + uint256 expectedBondingCurvePrice = 0.001 ether; + uint256 expectedPartyDaoFee = (expectedBondingCurvePrice * PARTY_DAO_FEE_BPS) / 1e4; + + // Cause transfer to fail + vm.etch(address(globalDaoWalletAddress), address(authority).code); + vm.prank(globalDaoWalletAddress); + vm.expectRevert(BondingCurveAuthority.EthTransferFailed.selector); + authority.claimPartyDaoFees(); + + assertEq(authority.partyDaoFeeClaimable(), expectedPartyDaoFee); + } + function test_buyThenSellPartyCards() public { address buyer1 = _randomAddress(); address buyer2 = _randomAddress();