From 61774f06866888c5aac9944898e437527ee904a3 Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:14:01 +0800 Subject: [PATCH] feat(billboard): allow to enable/disable board whitelist --- .gas-snapshot | 79 +++++++++++++------------- src/Billboard/Billboard.sol | 10 +++- src/Billboard/IBillboard.sol | 8 +++ src/test/Billboard/BillboardTest.t.sol | 16 ++++++ 4 files changed, 73 insertions(+), 40 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 8f28159..28b66a3 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -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) diff --git a/src/Billboard/Billboard.sol b/src/Billboard/Billboard.sol index 0102c93..815c3a1 100644 --- a/src/Billboard/Billboard.sol +++ b/src/Billboard/Billboard.sol @@ -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; @@ -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"); _; } @@ -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_; diff --git a/src/Billboard/IBillboard.sol b/src/Billboard/IBillboard.sol index 09cf895..0309aac 100644 --- a/src/Billboard/IBillboard.sol +++ b/src/Billboard/IBillboard.sol @@ -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. * diff --git a/src/test/Billboard/BillboardTest.t.sol b/src/test/Billboard/BillboardTest.t.sol index ae95514..ed6e9a3 100644 --- a/src/test/Billboard/BillboardTest.t.sol +++ b/src/test/Billboard/BillboardTest.t.sol @@ -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();