Skip to content

Commit

Permalink
additional tests. Identical math
Browse files Browse the repository at this point in the history
  • Loading branch information
arr00 committed Jan 3, 2024
1 parent 5413bbd commit e365208
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
22 changes: 10 additions & 12 deletions contracts/authorities/BondingCurveAuthority.sol
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ contract BondingCurveAuthority {
party,
msg.sender,
tokenIds,
msg.value,
totalCost,
partyDaoFee,
treasuryFee,
creatorFee
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down
36 changes: 35 additions & 1 deletion test/authorities/BondingCurveAuthority.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e365208

Please sign in to comment.