Skip to content

Commit

Permalink
feat: split limit checks to batch minting is better
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Adjimann committed Aug 9, 2024
1 parent 4c92102 commit 658133a
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions packages/avatar/contracts/nft-collection/NFTCollection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ IERC4906
* @custom:event {WaveSetup}
*/
function setAllowListMint() external onlyOwner {
// @dev maxSupply <= totalSupply, see: _checkTotalNotReached
_setupWave(maxSupply - totalSupply, mintingDefaults.maxAllowListTokensPerWallet, mintingDefaults.mintPrice);
}

Expand Down Expand Up @@ -435,7 +436,8 @@ IERC4906
_checkAndSetSignature({_address : _wallet, _signatureId : _signatureId, _signature : _signature});

require(_checkWaveNotComplete(_amount), "NFTCollection: wave completed");
require(_checkLimitNotReached(_wallet, _amount), "NFTCollection: max allowed");
require(_checkLimitPerWalletNotReached(_wallet, _amount), "NFTCollection: max allowed");
require(_checkTotalNotReached(_amount), "NFTCollection: max reached");

uint256 _price = price(_amount);
if (_price > 0) {
Expand Down Expand Up @@ -463,10 +465,11 @@ IERC4906
require(_amount > 0, "NFTCollection: wallets length cannot be 0");

require(_checkWaveNotComplete(_amount), "NFTCollection: wave completed");
require(_checkTotalNotReached(_amount), "NFTCollection: max reached");

for (uint256 i; i < _amount; i++) {
address _wallet = _wallets[i];
require(_checkLimitNotReached(_wallet, 1), "NFTCollection: max allowed");
require(_checkLimitPerWalletNotReached(_wallet, 1), "NFTCollection: max allowed");
// @dev safeMint already checks the destination address
// @dev start with tokenId = 1
_safeMint(_wallet, totalSupply + i + 1);
Expand Down Expand Up @@ -830,7 +833,11 @@ IERC4906
* @return if can mint or not
*/
function checkMintAllowed(address _wallet, uint256 _amount) external view returns (bool) {
return _checkWaveNotComplete(_amount) && _checkLimitNotReached(_wallet, _amount);
return _amount > 0
&& _checkWaveNotComplete(_amount)
&& _checkLimitPerWalletNotReached(_wallet, _amount)
&& _checkTotalNotReached(_amount);

}

/**
Expand Down Expand Up @@ -1010,7 +1017,7 @@ IERC4906
* @return if wave can mint the indicated amount
*/
function _checkWaveNotComplete(uint256 _amount) internal view returns (bool) {
return _amount > 0 && waveTotalMinted + _amount <= waveMaxTokensOverall;
return waveTotalMinted + _amount <= waveMaxTokensOverall;
}

/**
Expand All @@ -1019,12 +1026,18 @@ IERC4906
* @param _amount number of tokens to mint
* @return if amount can be safely minted
*/
function _checkLimitNotReached(address _wallet, uint256 _amount) internal view returns (bool) {
return
waveOwnerToClaimedCounts[_wallet][indexWave - 1] + _amount <= waveMaxTokensPerWallet &&
totalSupply + _amount <= maxSupply;
function _checkLimitPerWalletNotReached(address _wallet, uint256 _amount) internal view returns (bool) {
return waveOwnerToClaimedCounts[_wallet][indexWave - 1] + _amount <= waveMaxTokensPerWallet;
}

/**
* @notice checks if the total supply was not reached
* @param _amount number of tokens to mint
* @return if amount can be safely minted
*/
function _checkTotalNotReached(uint256 _amount) internal view returns (bool) {
return totalSupply + _amount <= maxSupply;
}
/**
* @notice actually updates the variables that store the personalization traits per token.
* @dev no checks are done on input validations. Calling functions are expected to do them
Expand Down

0 comments on commit 658133a

Please sign in to comment.