Skip to content

Commit

Permalink
Optimize dutchAuctionMint() (0xfoobar#2)
Browse files Browse the repository at this point in the history
* dutchAuctionNextId: Limit the use of state variable

Signed-off-by: Jagadish Krishnamoorthy <[email protected]>

* fix eof
  • Loading branch information
jaglinux authored Jul 7, 2022
1 parent 875e1b4 commit 0b9daa5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BoredAndDangerousTest:testDutchAuctionMint() (gas: 119021)
BoredAndDangerousTest:testDutchAuctionRefund() (gas: 196403971)
BoredAndDangerousTest:testOwnerMint() (gas: 77918)
BoredAndDangerousTest:testWritelistApes() (gas: 276)
BoredAndDangerousTest:testWritelistMintGiveawayBatch() (gas: 15753000)
BoredAndDangerousTest:testWritelistMintGiveawayMass() (gas: 15528566)
BoredAndDangerousTest:testWritelistMintWritersRoom() (gas: 253)
8 changes: 5 additions & 3 deletions src/BoredAndDangerous.sol
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ contract BoredAndDangerous is ERC721, ERC2981 {
revert ExceededUserMintCap();
}

uint256 _dutchAuctionNextId = dutchAuctionNextId;
// Enforce global mint cap
if (dutchAuctionNextId + amount > DUTCH_AUCTION_END_ID + 1) {
if (_dutchAuctionNextId + amount > DUTCH_AUCTION_END_ID + 1) {
revert DutchAuctionOver();
}

Expand Down Expand Up @@ -242,15 +243,16 @@ contract BoredAndDangerous is ERC721, ERC2981 {
price: newPrice
});
for (uint i = 0; i < amount; ++i) {
_mint(msg.sender, dutchAuctionNextId++);
_mint(msg.sender, _dutchAuctionNextId++);
}
totalSupply += amount;
if (dutchAuctionNextId > DUTCH_AUCTION_END_ID) {
if (_dutchAuctionNextId > DUTCH_AUCTION_END_ID) {
dutchEnd = DutchAuctionFinalization({
price: uint128(price),
time: uint128(block.timestamp)
});
}
dutchAuctionNextId = _dutchAuctionNextId;
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/RefundableDutchAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ contract RefundableDutchAuction is ERC721 {
revert ExceededUserMintCap();
}

uint256 _dutchAuctionNextId = dutchAuctionNextId;
// Enforce global mint cap
if (dutchAuctionNextId + amount > DUTCH_AUCTION_END_ID + 1) {
if (_dutchAuctionNextId + amount > DUTCH_AUCTION_END_ID + 1) {
revert DutchAuctionOver();
}

Expand Down Expand Up @@ -146,15 +147,16 @@ contract RefundableDutchAuction is ERC721 {
price: newPrice
});
for (uint i = 0; i < amount; ++i) {
_mint(msg.sender, dutchAuctionNextId++);
_mint(msg.sender, _dutchAuctionNextId++);
}
totalSupply += amount;
if (dutchAuctionNextId > DUTCH_AUCTION_END_ID) {
if (_dutchAuctionNextId > DUTCH_AUCTION_END_ID) {
dutchEnd = DutchAuctionFinalization({
price: uint128(price),
time: uint128(block.timestamp)
});
}
dutchAuctionNextId = _dutchAuctionNextId;
}
}

Expand Down Expand Up @@ -275,4 +277,5 @@ contract RefundableDutchAuction is ERC721 {
function tokenURI(uint256 tokenId) public view override returns (string memory) {
return string(abi.encodePacked(baseTokenURI, Strings.toString(tokenId)));
}
}
}

0 comments on commit 0b9daa5

Please sign in to comment.