Skip to content

Commit

Permalink
feat: membership sale (#328)
Browse files Browse the repository at this point in the history
* add `SellPartyCardsAuthority`

* update deploy

* add a few tests

* update events and add helper functions

* update relevant abis

* fix tests

* add more tests

* add more tests

* update `isSaleActive` logic

* move Contributed event

* merge `AboveMaximumContributionsError` and `BelowMinimumContributionsError`

* remove redundant initial delegate check

* fix compile errors

* transfer contribution to Party and fix totalContribution

* update `ContributionRouter`

* fix `isSaleActive`

* fix tests and increase coverage

* fix test

* update contribute event

* fix event and tests

* tweaks

* increase coverage

* perf: optimize and refactor `SellPartyCardsAuthority` (#30)

* fix tests

* update delegate comments

* ensure contract is an authority before sale creation

* fix deploy

* emit `Finalized` if not enough room for another contribution

* style: rename `delegate` to `initialDelegate`

* fix(`SellPartyCardsAuthority`): mitigations (#329)

* Fix merge conflict

---------

Co-authored-by: Brian Le <[email protected]>
  • Loading branch information
arr00 and 0xble authored Nov 30, 2023
1 parent 6a1d972 commit de1b8f7
Show file tree
Hide file tree
Showing 7 changed files with 1,379 additions and 5 deletions.
670 changes: 670 additions & 0 deletions contracts/authorities/SellPartyCardsAuthority.sol

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions contracts/crowdfund/ContributionRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.20;
import { LibAddress } from "../utils/LibAddress.sol";
import { LibRawResult } from "../utils/LibRawResult.sol";
import { InitialETHCrowdfund } from "../crowdfund/InitialETHCrowdfund.sol";
import { SellPartyCardsAuthority } from "../../contracts/authorities/SellPartyCardsAuthority.sol";

contract ContributionRouter {
using LibRawResult for bytes;
Expand Down Expand Up @@ -75,11 +76,13 @@ contract ContributionRouter {
assembly {
target := shr(96, calldataload(sub(calldatasize(), 20)))
}
if (msg.sig == InitialETHCrowdfund.batchContributeFor.selector) {
if (
msg.sig == InitialETHCrowdfund.batchContributeFor.selector ||
msg.sig == SellPartyCardsAuthority.batchContributeFor.selector
) {
uint256 numOfMints;
assembly {
// 196 is the offset of the length of `tokenIds` in the
// calldata.
// 196 is the offset of the array length in the calldata.
numOfMints := calldataload(196)
}
feeAmount *= numOfMints;
Expand Down
15 changes: 15 additions & 0 deletions contracts/utils/LibSafeCast.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ library LibSafeCast {
error Uint256ToInt128CastOutOfRangeError(uint256 u256);
error Uint256ToUint128CastOutOfRangeError(uint256 u256);
error Uint256ToUint40CastOutOfRangeError(uint256 u256);
error Uint96ToUint16CastOutOfRange(uint96 u96);

function safeCastUint256ToUint96(uint256 v) internal pure returns (uint96) {
if (v > uint256(type(uint96).max)) {
Expand All @@ -23,13 +24,27 @@ library LibSafeCast {
return uint128(v);
}

function safeCastUint256ToUint160(uint256 v) internal pure returns (uint160) {
if (v > uint256(type(uint160).max)) {
revert Uint256ToUint128CastOutOfRangeError(v);
}
return uint160(v);
}

function safeCastUint256ToInt192(uint256 v) internal pure returns (int192) {
if (v > uint256(uint192(type(int192).max))) {
revert Uint256ToInt192CastOutOfRange(v);
}
return int192(uint192(v));
}

function safeCastUint96ToUint16(uint96 v) internal pure returns (uint16) {
if (v > uint96(type(uint16).max)) {
revert Uint96ToUint16CastOutOfRange(v);
}
return uint16(v);
}

function safeCastUint96ToInt192(uint96 v) internal pure returns (int192) {
return int192(uint192(v));
}
Expand Down
17 changes: 16 additions & 1 deletion deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import "../contracts/market-wrapper/NounsMarketWrapper.sol";
import { AtomicManualParty } from "../contracts/crowdfund/AtomicManualParty.sol";
import { ContributionRouter } from "../contracts/crowdfund/ContributionRouter.sol";
import { AddPartyCardsAuthority } from "../contracts/authorities/AddPartyCardsAuthority.sol";
import { SellPartyCardsAuthority } from "../contracts/authorities/SellPartyCardsAuthority.sol";
import { SSTORE2MetadataProvider } from "../contracts/renderers/SSTORE2MetadataProvider.sol";
import { BasicMetadataProvider } from "../contracts/renderers/BasicMetadataProvider.sol";
import "./LibDeployConstants.sol";
Expand Down Expand Up @@ -81,6 +82,7 @@ abstract contract Deploy {
AtomicManualParty public atomicManualParty;
ContributionRouter public contributionRouter;
AddPartyCardsAuthority public addPartyCardsAuthority;
SellPartyCardsAuthority public sellPartyCardsAuthority;

function deploy(LibDeployConstants.DeployConstants memory deployConstants) public virtual {
_switchDeployer(DeployerRole.Default);
Expand Down Expand Up @@ -349,6 +351,15 @@ abstract contract Deploy {
_trackDeployerGasAfter();
console.log(" Deployed - AddPartyCardsAuthority", address(addPartyCardsAuthority));

// DEPLOY_SELL_PARTY_CARDS_AUTHORITY
console.log("");
console.log("### SellPartyCardsAuthority");
console.log(" Deploying - SellPartyCardsAuthority");
_trackDeployerGasBefore();
sellPartyCardsAuthority = new SellPartyCardsAuthority();
_trackDeployerGasAfter();
console.log(" Deployed - SellPartyCardsAuthority", address(sellPartyCardsAuthority));

// DEPLOY_BATCH_BUY_OPERATOR
console.log("");
console.log("### CollectionBatchBuyOperator");
Expand Down Expand Up @@ -685,7 +696,7 @@ contract DeployScript is Script, Deploy {
Deploy.deploy(deployConstants);
vm.stopBroadcast();

AddressMapping[] memory addressMapping = new AddressMapping[](28);
AddressMapping[] memory addressMapping = new AddressMapping[](29);
addressMapping[0] = AddressMapping("Globals", address(globals));
addressMapping[1] = AddressMapping("TokenDistributor", address(tokenDistributor));
addressMapping[2] = AddressMapping(
Expand Down Expand Up @@ -741,6 +752,10 @@ contract DeployScript is Script, Deploy {
"AddPartyCardsAuthority",
address(addPartyCardsAuthority)
);
addressMapping[28] = AddressMapping(
"SellPartyCardsAuthority",
address(sellPartyCardsAuthority)
);

console.log("");
console.log("### Deployed addresses");
Expand Down
Loading

0 comments on commit de1b8f7

Please sign in to comment.