From 292835ae5586ca7f56d3a05922dd7fd7faebf760 Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Fri, 24 Nov 2023 11:48:37 +0800 Subject: [PATCH] feat(billboard): use getBoard instead of destructing --- .gas-snapshot | 52 ++++++++++++++++++------------------- src/Billboard/Billboard.sol | 22 ++++++++-------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 1aa269d..f6dd653 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -12,52 +12,52 @@ ACLManagerTest:testTransferRole() (gas: 21528) BillboardTest:testAddToWhitelist() (gas: 37205) BillboardTest:testApproveAndTransfer() (gas: 162735) BillboardTest:testCalculateTax() (gas: 29439) -BillboardTest:testCannnotWithdrawTaxIfSmallAmount(uint8) (runs: 256, μ: 417758, ~: 431155) -BillboardTest:testCannnotWithdrawTaxIfZero() (gas: 383624) +BillboardTest:testCannnotWithdrawTaxIfSmallAmount(uint8) (runs: 256, μ: 418314, ~: 431711) +BillboardTest:testCannnotWithdrawTaxIfZero() (gas: 384181) BillboardTest:testCannotAddToWhitelistByAttacker() (gas: 11137) BillboardTest:testCannotApproveByAttacker() (gas: 130388) -BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 585072) -BillboardTest:testCannotClearAuctionOnNewBoard() (gas: 136029) +BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 587279) +BillboardTest:testCannotClearAuctionOnNewBoard() (gas: 136576) BillboardTest:testCannotMintBoardByAttacker() (gas: 13332) BillboardTest:testCannotPlaceBidByAttacker() (gas: 141747) -BillboardTest:testCannotPlaceBidTwice(uint96) (runs: 256, μ: 631625, ~: 637856) +BillboardTest:testCannotPlaceBidTwice(uint96) (runs: 256, μ: 633286, ~: 639517) BillboardTest:testCannotRemoveToWhitelistByAttacker() (gas: 11204) BillboardTest:testCannotSafeTransferByAttacker() (gas: 127555) -BillboardTest:testCannotSetBoardProprtiesByAttacker() (gas: 156298) +BillboardTest:testCannotSetBoardProprtiesByAttacker() (gas: 157909) BillboardTest:testCannotSetIsOpenedByAttacker() (gas: 11094) BillboardTest:testCannotSetTaxRateByAttacker() (gas: 11106) BillboardTest:testCannotTransferByOperator() (gas: 132888) BillboardTest:testCannotTransferToZeroAddress() (gas: 128375) BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 11228) -BillboardTest:testCannotWithBidTwice(uint96) (runs: 256, μ: 912727, ~: 912727) -BillboardTest:testCannotWithdrawBidIfAuctionNotCleared(uint96) (runs: 256, μ: 751566, ~: 751566) -BillboardTest:testCannotWithdrawBidIfAuctionNotEnded(uint96) (runs: 256, μ: 626363, ~: 626363) -BillboardTest:testCannotWithdrawBidIfNotFound() (gas: 419127) -BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 719175, ~: 719175) +BillboardTest:testCannotWithBidTwice(uint96) (runs: 256, μ: 914945, ~: 914945) +BillboardTest:testCannotWithdrawBidIfAuctionNotCleared(uint96) (runs: 256, μ: 753227, ~: 753227) +BillboardTest:testCannotWithdrawBidIfAuctionNotEnded(uint96) (runs: 256, μ: 627476, ~: 627476) +BillboardTest:testCannotWithdrawBidIfNotFound() (gas: 419684) +BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 720845, ~: 720845) BillboardTest:testCannotWithdrawTaxByAttacker() (gas: 18774) -BillboardTest:testClearAuctionIfAuctionEnded() (gas: 630598) -BillboardTest:testClearAuctionsIfAuctionEnded() (gas: 1168298) -BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 2888923, ~: 1434807) +BillboardTest:testClearAuctionIfAuctionEnded() (gas: 632267) +BillboardTest:testClearAuctionsIfAuctionEnded() (gas: 1171641) +BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 2900467, ~: 1438660) BillboardTest:testGetTokenURI() (gas: 155303) BillboardTest:testMintBoard() (gas: 225987) BillboardTest:testMintBoardByWhitelist() (gas: 157167) BillboardTest:testMintBoardIfOpened() (gas: 130861) -BillboardTest:testPlaceBidByWhitelist() (gas: 467779) -BillboardTest:testPlaceBidIfAuctionEnded() (gas: 915778) -BillboardTest:testPlaceBidOnNewBoard(uint96) (runs: 256, μ: 517306, ~: 527498) -BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 747909, ~: 754983) -BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 745880, ~: 757556) -BillboardTest:testPlaceBidZeroPrice() (gas: 357842) +BillboardTest:testPlaceBidByWhitelist() (gas: 468335) +BillboardTest:testPlaceBidIfAuctionEnded() (gas: 917448) +BillboardTest:testPlaceBidOnNewBoard(uint96) (runs: 256, μ: 517862, ~: 528054) +BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 749336, ~: 756644) +BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 747541, ~: 759217) +BillboardTest:testPlaceBidZeroPrice() (gas: 358399) BillboardTest:testRemoveToWhitelist() (gas: 24957) BillboardTest:testSafeTransferByOperator() (gas: 141354) -BillboardTest:testSetBoardProperties() (gas: 305524) -BillboardTest:testSetBoardPropertiesAfterTransfer() (gas: 334252) +BillboardTest:testSetBoardProperties() (gas: 307136) +BillboardTest:testSetBoardPropertiesAfterTransfer() (gas: 337474) BillboardTest:testSetIsOpened() (gas: 15978) BillboardTest:testSetTaxRate() (gas: 27263) -BillboardTest:testSomethin() (gas: 1641191) -BillboardTest:testUpgradeRegistry() (gas: 2725044) -BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 914023, ~: 914023) -BillboardTest:testWithdrawTax(uint96) (runs: 256, μ: 507001, ~: 507001) +BillboardTest:testSomethin() (gas: 1646208) +BillboardTest:testUpgradeRegistry() (gas: 2672107) +BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 916241, ~: 916241) +BillboardTest:testWithdrawTax(uint96) (runs: 256, μ: 507557, ~: 507557) 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 4f2cd1b..80cb9d9 100644 --- a/src/Billboard/Billboard.sol +++ b/src/Billboard/Billboard.sol @@ -42,8 +42,8 @@ contract Billboard is IBillboard { } modifier isFromBoardCreator(uint256 tokenId_) { - (address _boardCreator, , , , , ) = registry.boards(tokenId_); - require(_boardCreator == msg.sender, "Creator"); + IBillboardRegistry.Board memory _board = registry.getBoard(tokenId_); + require(_board.creator == msg.sender, "Creator"); _; } @@ -136,8 +136,8 @@ contract Billboard is IBillboard { /// @inheritdoc IBillboard function clearAuction(uint256 tokenId_) public { // revert if board not found - (address _boardCreator, , , , , ) = registry.boards(tokenId_); - require(_boardCreator != address(0), "Board not found"); + IBillboardRegistry.Board memory _board = registry.getBoard(tokenId_); + require(_board.creator != address(0), "Board not found"); // revert if it's a new board uint256 _nextAuctionId = registry.nextBoardAuctionId(tokenId_); @@ -150,12 +150,12 @@ contract Billboard is IBillboard { // reclaim ownership to board creator if no auction address _prevOwner = registry.ownerOf(tokenId_); - if (_nextAuction.startAt == 0 && _prevOwner != _boardCreator) { - registry.safeTransferByOperator(_prevOwner, _boardCreator, tokenId_); + if (_nextAuction.startAt == 0 && _prevOwner != _board.creator) { + registry.safeTransferByOperator(_prevOwner, _board.creator, tokenId_); return; } - _clearAuction(tokenId_, _boardCreator, _nextAuctionId); + _clearAuction(tokenId_, _board.creator, _nextAuctionId); } /// @inheritdoc IBillboard @@ -207,8 +207,8 @@ contract Billboard is IBillboard { /// @inheritdoc IBillboard function placeBid(uint256 tokenId_, uint256 amount_) external payable isFromWhitelist { - (address _boardCreator, , , , , ) = registry.boards(tokenId_); - require(_boardCreator != address(0), "Board not found"); + IBillboardRegistry.Board memory _board = registry.getBoard(tokenId_); + require(_board.creator != address(0), "Board not found"); uint256 _nextAuctionId = registry.nextBoardAuctionId(tokenId_); IBillboardRegistry.Auction memory _nextAuction = registry.getAuction(tokenId_, _nextAuctionId); @@ -218,7 +218,7 @@ contract Billboard is IBillboard { // then clear auction and transfer ownership to the bidder immediately. if (_nextAuction.startAt == 0) { uint256 _auctionId = _newAuctionAndBid(tokenId_, amount_, uint64(block.timestamp)); - _clearAuction(tokenId_, _boardCreator, _auctionId); + _clearAuction(tokenId_, _board.creator, _auctionId); return; } @@ -226,7 +226,7 @@ contract Billboard is IBillboard { // clear auction first, // then create new auction and new bid if (block.timestamp >= _nextAuction.endAt) { - _clearAuction(tokenId_, _boardCreator, _nextAuctionId); + _clearAuction(tokenId_, _board.creator, _nextAuctionId); _newAuctionAndBid(tokenId_, amount_, uint64(block.timestamp + registry.leaseTerm())); return; }