Skip to content

Commit

Permalink
emit last bonding curve price transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
arr00 committed Jan 22, 2024
1 parent 27f4a19 commit eea374a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 13 deletions.
18 changes: 18 additions & 0 deletions contracts/authorities/BondingCurveAuthority.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract BondingCurveAuthority {
address indexed buyer,
uint256[] tokenIds,
uint256 totalPrice,
uint256 lastBondingCurvePrice,
uint256 partyDaoFee,
uint256 treasuryFee,
uint256 creatorFee
Expand All @@ -45,6 +46,7 @@ contract BondingCurveAuthority {
address indexed seller,
uint256[] tokenIds,
uint256 sellerProceeds,
uint256 lastBondingCurvePrice,
uint256 partyDaoFee,
uint256 treasuryFee,
uint256 creatorFee
Expand Down Expand Up @@ -306,11 +308,19 @@ contract BondingCurveAuthority {
tokenIds[i] = party.mint(msg.sender, PARTY_CARD_VOTING_POWER, initialDelegate);
}

uint256 lastBondingCurvePrice = _getBondingCurvePrice(
partyInfo.supply + amount - 1,
1,
partyInfo.a,
partyInfo.b
);

emit PartyCardsBought(
party,
msg.sender,
tokenIds,
totalCost,
lastBondingCurvePrice,
partyDaoFee,
treasuryFee,
creatorFee
Expand Down Expand Up @@ -397,11 +407,19 @@ contract BondingCurveAuthority {

partyDaoFeeClaimable += partyDaoFee.safeCastUint256ToUint96();

uint256 lastBondingCurvePrice = _getBondingCurvePrice(
partyInfo.supply - amount,
1,
partyInfo.a,
partyInfo.b
);

emit PartyCardsSold(
party,
msg.sender,
tokenIds,
sellerProceeds,
lastBondingCurvePrice,
partyDaoFee,
treasuryFee,
creatorFee
Expand Down
60 changes: 47 additions & 13 deletions test/authorities/BondingCurveAuthority.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract BondingCurveAuthorityTest is SetupPartyHelper {
address indexed buyer,
uint256[] tokenIds,
uint256 totalPrice,
uint256 lastBondingCurvePrice,
uint256 partyDaoFee,
uint256 treasuryFee,
uint256 creatorFee
Expand All @@ -29,6 +30,7 @@ contract BondingCurveAuthorityTest is SetupPartyHelper {
address indexed seller,
uint256[] tokenIds,
uint256 sellerProceeds,
uint256 lastBondingCurvePrice,
uint256 partyDaoFee,
uint256 treasuryFee,
uint256 creatorFee
Expand Down Expand Up @@ -392,18 +394,26 @@ contract BondingCurveAuthorityTest is SetupPartyHelper {

buyer = _randomAddress();
vm.deal(buyer, expectedPriceToBuy);
vm.prank(buyer);

{
uint256[] memory tokenIds = new uint256[](10);
for (uint256 i = 0; i < 10; i++) tokenIds[i] = i + 2;

uint256 lastBondingCurvePrice = authority.getBondingCurvePrice(
10,
1,
50_000,
uint80(0.001 ether)
);

vm.prank(buyer);
vm.expectEmit(true, true, true, true);
emit PartyCardsBought(
party,
buyer,
tokenIds,
expectedPriceToBuy,
lastBondingCurvePrice,
expectedPartyDaoFee,
expectedTreasuryFee,
expectedCreatorFee
Expand Down Expand Up @@ -493,13 +503,21 @@ contract BondingCurveAuthorityTest is SetupPartyHelper {
uint256[] memory tokenIds = new uint256[](10);
for (uint256 i = 0; i < 10; i++) tokenIds[i] = i + 2;

uint256 lastBondingCurvePrice = authority.getBondingCurvePrice(
10,
1,
50_000,
uint80(0.001 ether)
);

uint256 balanceBefore = address(this).balance;
vm.expectEmit(true, true, true, true);
emit PartyCardsBought(
party,
address(this),
tokenIds,
priceToBuy,
lastBondingCurvePrice,
expectedPartyDaoFee,
expectedTreasuryFee,
expectedCreatorFee
Expand Down Expand Up @@ -557,21 +575,29 @@ contract BondingCurveAuthorityTest is SetupPartyHelper {
uint256 beforePartyBalance = address(party).balance;
uint256 beforeCreatorBalance = creator.balance;

vm.prank(buyer);
{
uint256 lastBondingCurvePrice = authority.getBondingCurvePrice(
1,
1,
50_000,
uint80(0.001 ether)
);

vm.expectEmit(true, true, true, true);
emit PartyCardsSold(
party,
buyer,
tokenIds,
expectedSaleProceeds,
expectedPartyDaoFee,
expectedTreasuryFee,
expectedCreatorFee
);
vm.prank(buyer);
vm.expectEmit(true, true, true, true);
emit PartyCardsSold(
party,
buyer,
tokenIds,
expectedSaleProceeds,
lastBondingCurvePrice,
expectedPartyDaoFee,
expectedTreasuryFee,
expectedCreatorFee
);
}

authority.sellPartyCards(party, tokenIds, 0);

(, uint80 supply, , , ) = authority.partyInfos(party);

assertEq(supply, 1);
Expand Down Expand Up @@ -681,13 +707,21 @@ contract BondingCurveAuthorityTest is SetupPartyHelper {
uint256 expectedPartyDaoFee = (expectedBondingCurvePrice * PARTY_DAO_FEE_BPS) / 1e4;
uint256 expectedTreasuryFee = (expectedBondingCurvePrice * TREASURY_FEE_BPS) / 1e4;

uint256 lastBondingCurvePrice = authority.getBondingCurvePrice(
1,
1,
50_000,
uint80(0.001 ether)
);

vm.prank(buyer);
vm.expectEmit(true, true, true, true);
emit PartyCardsSold(
party,
buyer,
tokenIds,
saleProceeds,
lastBondingCurvePrice,
expectedPartyDaoFee,
expectedTreasuryFee,
0
Expand Down

0 comments on commit eea374a

Please sign in to comment.