Skip to content

Commit

Permalink
Add more comments to minters
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Sep 15, 2023
1 parent a3f9dac commit 77940d9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
27 changes: 22 additions & 5 deletions src/minters/CollectionPlusMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down
23 changes: 19 additions & 4 deletions src/minters/MerkleReserveMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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
Expand All @@ -158,6 +161,7 @@ contract MerkleReserveMinter is IMintStrategy {

(bool success, ) = treasury.call{ value: msg.value }("");

// Revert if transfer fails
if (!success) {
revert TRANSFER_FAILED();
}
Expand All @@ -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
Expand All @@ -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);
}

/// ///
Expand Down

0 comments on commit 77940d9

Please sign in to comment.