Skip to content

Commit

Permalink
feat(billboard): allow to enable/disable board whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Aug 15, 2024
1 parent 115eab6 commit 61774f0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 40 deletions.
79 changes: 40 additions & 39 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,52 @@ ACLManagerTest:testRoles() (gas: 15393)
ACLManagerTest:testTransferRole() (gas: 21528)
BillboardTest:testApproveAndTransfer() (gas: 258088)
BillboardTest:testCalculateTax() (gas: 539668)
BillboardTest:testCannnotWithdrawTaxIfZero() (gas: 20140)
BillboardTest:testCannnotWithdrawTaxIfZero() (gas: 20118)
BillboardTest:testCannotApproveByAttacker() (gas: 224347)
BillboardTest:testCannotCalculateTax() (gas: 218883)
BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 255578)
BillboardTest:testCannotClearAuctionIfClosed() (gas: 252770)
BillboardTest:testCannotClearAuctionIfNoBid() (gas: 260744)
BillboardTest:testCannotGetBlockFromEpoch() (gas: 8600)
BillboardTest:testCannotGetEpochFromBlock() (gas: 18393)
BillboardTest:testCannotPlaceBidIfAuctionEnded() (gas: 278628)
BillboardTest:testCannotPlaceBidIfClosed() (gas: 252692)
BillboardTest:testCannotPlaceBidIfNotWhitelisted() (gas: 463880)
BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 255623)
BillboardTest:testCannotClearAuctionIfClosed() (gas: 252826)
BillboardTest:testCannotClearAuctionIfNoBid() (gas: 260800)
BillboardTest:testCannotGetBlockFromEpoch() (gas: 8645)
BillboardTest:testCannotGetEpochFromBlock() (gas: 18305)
BillboardTest:testCannotPlaceBidIfAuctionEnded() (gas: 283099)
BillboardTest:testCannotPlaceBidIfClosed() (gas: 252700)
BillboardTest:testCannotPlaceBidIfNotWhitelisted() (gas: 465606)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 221503)
BillboardTest:testCannotSetBoardByAttacker() (gas: 229566)
BillboardTest:testCannotSetBoardByOwner() (gas: 362072)
BillboardTest:testCannotSetClosedByAttacker() (gas: 228454)
BillboardTest:testCannotSetBoardByAttacker() (gas: 229501)
BillboardTest:testCannotSetBoardByOwner() (gas: 361920)
BillboardTest:testCannotSetClosedByAttacker() (gas: 228521)
BillboardTest:testCannotSetWhitelistByAttacker() (gas: 228664)
BillboardTest:testCannotTransferByOperator() (gas: 226749)
BillboardTest:testCannotTransferToZeroAddress() (gas: 222236)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 9105)
BillboardTest:testCannotWithdrawBidIfAuctionNotEndedOrCleared(uint96) (runs: 256, μ: 630648, ~: 630648)
BillboardTest:testCannotWithdrawBidIfNotFound(uint96) (runs: 256, μ: 748156, ~: 748156)
BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 1024014, ~: 1024014)
BillboardTest:testCannotWithdrawBidTwice(uint96) (runs: 256, μ: 1108455, ~: 1108455)
BillboardTest:testClearAuction(uint96) (runs: 256, μ: 729526, ~: 729526)
BillboardTest:testClearAuctionIfAlreadyCleared() (gas: 736674)
BillboardTest:testClearAuctions() (gas: 1310672)
BillboardTest:testGetBidderBids(uint8,uint8,uint8) (runs: 256, μ: 1505979, ~: 1138329)
BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 8242518, ~: 6452578)
BillboardTest:testGetBlockFromEpoch() (gas: 16849)
BillboardTest:testGetEpochFromBlock() (gas: 17968)
BillboardTest:testGetTokenURI() (gas: 391497)
BillboardTest:testMintBoard() (gas: 585644)
BillboardTest:testPlaceBid(uint96) (runs: 256, μ: 837564, ~: 838186)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 1009249, ~: 1009253)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 906263, ~: 907196)
BillboardTest:testPlaceBidZeroPrice() (gas: 430502)
BillboardTest:testSafeTransferByOperator() (gas: 235301)
BillboardTest:testSetBidURIs() (gas: 657544)
BillboardTest:testSetBoardByCreator() (gas: 342349)
BillboardTest:testSetClosed() (gas: 240866)
BillboardTest:testSetWhitelist() (gas: 245316)
BillboardTest:testUpgradeRegistry() (gas: 3708725)
BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 1096420, ~: 1096420)
BillboardTest:testWithdrawBidIfClosed(uint96) (runs: 256, μ: 694679, ~: 694679)
BillboardTest:testWithdrawTax(uint96) (runs: 256, μ: 734859, ~: 734859)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 9061)
BillboardTest:testCannotWithdrawBidIfAuctionNotEndedOrCleared(uint96) (runs: 256, μ: 632897, ~: 632897)
BillboardTest:testCannotWithdrawBidIfNotFound(uint96) (runs: 256, μ: 750415, ~: 750415)
BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 1026497, ~: 1026497)
BillboardTest:testCannotWithdrawBidTwice(uint96) (runs: 256, μ: 1110939, ~: 1110939)
BillboardTest:testClearAuction(uint96) (runs: 256, μ: 731784, ~: 731784)
BillboardTest:testClearAuctionIfAlreadyCleared() (gas: 738943)
BillboardTest:testClearAuctions() (gas: 1315188)
BillboardTest:testGetBidderBids(uint8,uint8,uint8) (runs: 256, μ: 1508380, ~: 1140352)
BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 8175186, ~: 6266659)
BillboardTest:testGetBlockFromEpoch() (gas: 17344)
BillboardTest:testGetEpochFromBlock() (gas: 17704)
BillboardTest:testGetTokenURI() (gas: 391476)
BillboardTest:testMintBoard() (gas: 585623)
BillboardTest:testPlaceBid(uint96) (runs: 256, μ: 839990, ~: 840612)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 1011369, ~: 1011373)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 908689, ~: 909622)
BillboardTest:testPlaceBidZeroPrice() (gas: 432704)
BillboardTest:testSafeTransferByOperator() (gas: 235237)
BillboardTest:testSetBidURIs() (gas: 659724)
BillboardTest:testSetBoardByCreator() (gas: 342307)
BillboardTest:testSetBoardWhitelistDisabled() (gas: 244291)
BillboardTest:testSetClosed() (gas: 240956)
BillboardTest:testSetWhitelist() (gas: 245250)
BillboardTest:testUpgradeRegistry() (gas: 3788318)
BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 1098903, ~: 1098903)
BillboardTest:testWithdrawBidIfClosed(uint96) (runs: 256, μ: 696905, ~: 696905)
BillboardTest:testWithdrawTax(uint96) (runs: 256, μ: 737095, ~: 737095)
CurationTest:testCannotCurateERC20CurateZeroAmount() (gas: 12194)
CurationTest:testCannotCurateERC20EmptyURI() (gas: 15797)
CurationTest:testCannotCurateERC20IfNotApproval() (gas: 21624)
Expand Down
10 changes: 9 additions & 1 deletion src/Billboard/Billboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ contract Billboard is IBillboard {
// tokenId => address => whitelisted
mapping(uint256 => mapping(address => bool)) public whitelist;

// tokenId => disabled
mapping(uint256 => bool) public isBoardWhitelistDisabled;

// tokenId => closed
mapping(uint256 => bool) public closed;

Expand Down Expand Up @@ -49,7 +52,7 @@ contract Billboard is IBillboard {
}

modifier isFromWhitelist(uint256 tokenId_) {
require(whitelist[tokenId_][msg.sender], "Whitelist");
require(isBoardWhitelistDisabled[tokenId_] || whitelist[tokenId_][msg.sender], "Whitelist");
_;
}

Expand Down Expand Up @@ -87,6 +90,11 @@ contract Billboard is IBillboard {
whitelist[tokenId_][account_] = whitelisted;
}

/// @inheritdoc IBillboard
function setBoardWhitelistDisabled(uint256 tokenId_, bool disabled) external isFromCreator(tokenId_) {
isBoardWhitelistDisabled[tokenId_] = disabled;
}

/// @inheritdoc IBillboard
function setClosed(uint256 tokenId_, bool closed_) external isFromCreator(tokenId_) {
closed[tokenId_] = closed_;
Expand Down
8 changes: 8 additions & 0 deletions src/Billboard/IBillboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ interface IBillboard {
*/
function setWhitelist(uint256 tokenId_, address account_, bool whitelisted) external;

/**
* @notice Enable or disable a board whitelist feature
*
* @param tokenId_ Token ID.
* @param disabled Disabled or not.
*/
function setBoardWhitelistDisabled(uint256 tokenId_, bool disabled) external;

/**
* @notice Open or close a board.
*
Expand Down
16 changes: 16 additions & 0 deletions src/test/Billboard/BillboardTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ contract BillboardTest is BillboardTestBase {
operator.setWhitelist(_tokenId, USER_B, false);
}

function testSetBoardWhitelistDisabled() public {
(uint256 _tokenId, ) = _mintBoard();

vm.startPrank(ADMIN);

assertEq(operator.isBoardWhitelistDisabled(_tokenId), false);

// disable
operator.setBoardWhitelistDisabled(_tokenId, true);
assertEq(operator.isBoardWhitelistDisabled(_tokenId), true);

// enable
operator.setBoardWhitelistDisabled(_tokenId, false);
assertEq(operator.whitelist(_tokenId, USER_A), false);
}

function testSetClosed() public {
(uint256 _tokenId, ) = _mintBoard();

Expand Down

0 comments on commit 61774f0

Please sign in to comment.