From 77940d91cc44010317feb0e253cfd34a076a6d89 Mon Sep 17 00:00:00 2001 From: neokry Date: Fri, 15 Sep 2023 16:58:01 +0900 Subject: [PATCH] Add more comments to minters --- src/minters/CollectionPlusMinter.sol | 27 ++++++++++++++++++++++----- src/minters/MerkleReserveMinter.sol | 23 +++++++++++++++++++---- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/minters/CollectionPlusMinter.sol b/src/minters/CollectionPlusMinter.sol index bb10be1..e3cfd5a 100644 --- a/src/minters/CollectionPlusMinter.sol +++ b/src/minters/CollectionPlusMinter.sol @@ -100,6 +100,7 @@ contract CollectionPlusMinter is IMintStrategy { /// @notice Checks if the caller is the token contract or the owner of the token contract /// @param tokenContract Token contract to check modifier onlyTokenOwner(address tokenContract) { + // Revert if sender is not the token contract owner if (!_isContractOwner(msg.sender, tokenContract)) { revert NOT_TOKEN_OWNER(); } @@ -146,9 +147,13 @@ contract CollectionPlusMinter is IMintStrategy { bytes calldata signature, uint256 deadline ) public payable { + // Load settings from storage CollectionPlusSettings memory settings = allowedCollections[tokenContract]; + + // Cache token count uint256 tokenCount = tokenIds.length; + // Validate params _validateParams(settings, tokenCount); // Keep track of the ERC6551 accounts for delegation step @@ -190,9 +195,13 @@ contract CollectionPlusMinter is IMintStrategy { uint256[] calldata tokenIds, bytes calldata initData ) public payable { + // Load settings from storage CollectionPlusSettings memory settings = allowedCollections[tokenContract]; + + // Cache token count uint256 tokenCount = tokenIds.length; + // Validate params _validateParams(settings, tokenCount); unchecked { @@ -279,8 +288,17 @@ contract CollectionPlusMinter is IMintStrategy { // @notice Sets the minter settings from the token contract with generic data /// @param data Encoded settings to set function setMintSettings(bytes calldata data) external { + // Decode settings data CollectionPlusSettings memory settings = abi.decode(data, (CollectionPlusSettings)); - _setMintSettings(msg.sender, settings); + + // Cache sender + address sender = msg.sender; + + // Set new collection settings + _setMintSettings(sender, settings); + + // Emit event for new settings + emit MinterSet(sender, settings); } /// @notice Sets the minter settings for a token @@ -289,6 +307,9 @@ contract CollectionPlusMinter is IMintStrategy { function setMintSettings(address tokenContract, CollectionPlusSettings memory settings) external onlyTokenOwner(tokenContract) { // Set new collection settings _setMintSettings(tokenContract, settings); + + // Emit event for new settings + emit MinterSet(tokenContract, settings); } /// @notice Resets the minter settings for a token @@ -302,11 +323,7 @@ contract CollectionPlusMinter is IMintStrategy { } function _setMintSettings(address tokenContract, CollectionPlusSettings memory settings) internal { - // Set new collection settings allowedCollections[tokenContract] = settings; - - // Emit event for new settings - emit MinterSet(tokenContract, settings); } function _isContractOwner(address caller, address tokenContract) internal view returns (bool) { diff --git a/src/minters/MerkleReserveMinter.sol b/src/minters/MerkleReserveMinter.sol index 0b7e6c3..5b08c08 100644 --- a/src/minters/MerkleReserveMinter.sol +++ b/src/minters/MerkleReserveMinter.sol @@ -93,6 +93,7 @@ contract MerkleReserveMinter is IMintStrategy { /// @notice Checks if the caller is the token contract or the owner of the token contract /// @param tokenContract Token contract to check modifier onlyTokenOwner(address tokenContract) { + // Revert if sender is not the token contract owner if (!_isContractOwner(msg.sender, tokenContract)) { revert NOT_TOKEN_OWNER(); } @@ -118,6 +119,7 @@ contract MerkleReserveMinter is IMintStrategy { MerkleMinterSettings memory settings = allowedMerkles[tokenContract]; uint256 claimCount = claims.length; + // Ensure claims are not empty if (claimCount == 0) { revert INVALID_CLAIM_COUNT(); } @@ -140,6 +142,7 @@ contract MerkleReserveMinter is IMintStrategy { // Mint tokens unchecked { for (uint256 i = 0; i < claimCount; ++i) { + // Load claim in memory MerkleClaim memory claim = claims[i]; // Requires one proof per tokenId to handle cases where users want to partially claim @@ -158,6 +161,7 @@ contract MerkleReserveMinter is IMintStrategy { (bool success, ) = treasury.call{ value: msg.value }(""); + // Revert if transfer fails if (!success) { revert TRANSFER_FAILED(); } @@ -171,20 +175,34 @@ contract MerkleReserveMinter is IMintStrategy { /// @notice Sets the minter settings from the token contract with generic data /// @param data Encoded settings to set function setMintSettings(bytes calldata data) external { + // Decode settings data MerkleMinterSettings memory settings = abi.decode(data, (MerkleMinterSettings)); - _setMintSettings(msg.sender, settings); + + // Cache sender + address sender = msg.sender; + + // Set new collection settings + _setMintSettings(sender, settings); + + // Emit event for new settings + emit MinterSet(sender, settings); } /// @notice Sets the minter settings for a token /// @param tokenContract Token contract to set settings for /// @param settings Settings to set function setMintSettings(address tokenContract, MerkleMinterSettings memory settings) external onlyTokenOwner(tokenContract) { + // Set new collection settings _setMintSettings(tokenContract, settings); + + // Emit event for new settings + emit MinterSet(tokenContract, settings); } /// @notice Resets the minter settings for a token /// @param tokenContract Token contract to reset settings for function resetMintSettings(address tokenContract) external onlyTokenOwner(tokenContract) { + // Reset collection settings to null delete allowedMerkles[tokenContract]; // Emit event with null settings @@ -193,9 +211,6 @@ contract MerkleReserveMinter is IMintStrategy { function _setMintSettings(address tokenContract, MerkleMinterSettings memory settings) internal { allowedMerkles[tokenContract] = settings; - - // Emit event for new settings - emit MinterSet(tokenContract, settings); } /// ///