Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: free first party card bonding curve #373

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions contracts/authorities/BondingCurveAuthority.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract BondingCurveAuthority {
error SellZeroPartyCards();
error DistributionsNotSupported();
error NeedAtLeastOneHost();
error InvalidDiscount();

event BondingCurvePartyCreated(
Party indexed party,
Expand Down Expand Up @@ -94,6 +95,8 @@ contract BondingCurveAuthority {
// The value of b in the bonding curve formula 1 ether * x ** 2 / a + b
// used by the Party to price cards
uint80 b;
// Discount when buying/selling the first card in the party
uint80 firstCardDiscount;
}

/// @notice Struct containing info stored for a party
Expand All @@ -110,6 +113,8 @@ contract BondingCurveAuthority {
// The value of b in the bonding curve formula 1 ether * x ** 2 / a + b
// used by the Party to price cards
uint80 b;
// Discount when buying/selling the first card in the party
uint80 firstCardDiscount;
}

modifier onlyPartyDao() {
Expand Down Expand Up @@ -153,6 +158,10 @@ contract BondingCurveAuthority {
address[] memory authorities = new address[](1);
authorities[0] = address(this);

if (partyOpts.firstCardDiscount > partyOpts.b) {
revert InvalidDiscount();
}

_validateGovernanceOpts(partyOpts.opts);

party = partyOpts.partyFactory.createParty(
Expand All @@ -173,7 +182,8 @@ contract BondingCurveAuthority {
supply: 0,
creatorFeeOn: partyOpts.creatorFeeOn,
a: partyOpts.a,
b: partyOpts.b
b: partyOpts.b,
firstCardDiscount: partyOpts.firstCardDiscount
});

emit BondingCurvePartyCreated(party, msg.sender, partyOpts);
Expand All @@ -198,6 +208,10 @@ contract BondingCurveAuthority {
address[] memory authorities = new address[](1);
authorities[0] = address(this);

if (partyOpts.firstCardDiscount > partyOpts.b) {
revert InvalidDiscount();
}

_validateGovernanceOpts(partyOpts.opts);

party = partyOpts.partyFactory.createPartyWithMetadata(
Expand All @@ -220,7 +234,8 @@ contract BondingCurveAuthority {
supply: 0,
creatorFeeOn: partyOpts.creatorFeeOn,
a: partyOpts.a,
b: partyOpts.b
b: partyOpts.b,
firstCardDiscount: partyOpts.firstCardDiscount
});

emit BondingCurvePartyCreated(party, msg.sender, partyOpts);
Expand Down Expand Up @@ -278,7 +293,8 @@ contract BondingCurveAuthority {
partyInfo.supply,
amount,
partyInfo.a,
partyInfo.b
partyInfo.b,
partyInfo.firstCardDiscount
);
uint256 partyDaoFee = (bondingCurvePrice * partyDaoFeeBps) / BPS;
uint256 treasuryFee = (bondingCurvePrice * treasuryFeeBps) / BPS;
Expand Down Expand Up @@ -321,7 +337,8 @@ contract BondingCurveAuthority {
partyInfo.supply + amount - 1,
1,
partyInfo.a,
partyInfo.b
partyInfo.b,
partyInfo.firstCardDiscount
);

emit PartyCardsBought(
Expand Down Expand Up @@ -365,7 +382,8 @@ contract BondingCurveAuthority {
partyInfo.supply - amount,
amount,
partyInfo.a,
partyInfo.b
partyInfo.b,
partyInfo.firstCardDiscount
);
uint256 partyDaoFee = (bondingCurvePrice * partyDaoFeeBps) / BPS;
uint256 treasuryFee = (bondingCurvePrice * treasuryFeeBps) / BPS;
Expand Down Expand Up @@ -420,7 +438,8 @@ contract BondingCurveAuthority {
partyInfo.supply - amount,
1,
partyInfo.a,
partyInfo.b
partyInfo.b,
partyInfo.firstCardDiscount
);

emit PartyCardsSold(
Expand All @@ -447,7 +466,8 @@ contract BondingCurveAuthority {
partyInfo.supply - amount,
amount,
partyInfo.a,
partyInfo.b
partyInfo.b,
partyInfo.firstCardDiscount
);
uint256 partyDaoFee = (bondingCurvePrice * partyDaoFeeBps) / BPS;
uint256 treasuryFee = (bondingCurvePrice * treasuryFeeBps) / BPS;
Expand All @@ -470,7 +490,8 @@ contract BondingCurveAuthority {
amount,
partyInfo.a,
partyInfo.b,
partyInfo.creatorFeeOn
partyInfo.creatorFeeOn,
partyInfo.firstCardDiscount
);
}

Expand All @@ -488,9 +509,10 @@ contract BondingCurveAuthority {
uint80 amount,
uint32 a,
uint80 b,
bool creatorFeeOn
bool creatorFeeOn,
uint80 firstCardDiscount
) public view returns (uint256) {
uint256 bondingCurvePrice = _getBondingCurvePrice(supply, amount, a, b);
uint256 bondingCurvePrice = _getBondingCurvePrice(supply, amount, a, b, firstCardDiscount);
uint256 partyDaoFee = (bondingCurvePrice * partyDaoFeeBps) / BPS;
uint256 treasuryFee = (bondingCurvePrice * treasuryFeeBps) / BPS;
uint256 creatorFee = (bondingCurvePrice * (creatorFeeOn ? creatorFeeBps : 0)) / BPS;
Expand All @@ -510,8 +532,10 @@ contract BondingCurveAuthority {
uint256 lowerSupply,
uint256 amount,
uint32 a,
uint80 b
uint80 b,
uint80 firstCardDiscount
) internal pure returns (uint256) {
uint256 discount = lowerSupply == 0 ? firstCardDiscount : 0;
// Using the function 1 ether * x ** 2 / a + b
uint256 amountSquared = amount * amount;
return
Expand All @@ -525,7 +549,8 @@ contract BondingCurveAuthority {
6)) /
uint256(a) +
amount *
uint256(b);
uint256(b) -
discount;
}

/**
Expand Down
Loading
Loading