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 201b6e8
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 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 All @@ -409,6 +410,7 @@ IERC4906
* @custom:event {WaveSetup}
*/
function setPublicMint() external onlyOwner {
// @dev maxSupply <= totalSupply, see: _checkTotalNotReached
_setupWave(maxSupply - totalSupply, mintingDefaults.maxPublicTokensPerWallet, mintingDefaults.mintPrice);
}

Expand All @@ -435,7 +437,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 +466,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 +834,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 +1018,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 +1027,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 201b6e8

Please sign in to comment.