From 430e923de8492baca8200ead9412afa26ca3ea4f Mon Sep 17 00:00:00 2001 From: Brett Murphy Date: Sun, 16 Jan 2022 09:09:10 +1000 Subject: [PATCH] Presale whitelisting using maps --- contract/SimpleNftLowerGas.sol | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/contract/SimpleNftLowerGas.sol b/contract/SimpleNftLowerGas.sol index 163e0f2..86a1ed0 100644 --- a/contract/SimpleNftLowerGas.sol +++ b/contract/SimpleNftLowerGas.sol @@ -38,6 +38,10 @@ contract SimpleNftLowerGas is ERC721, Ownable { bool public paused = true; bool public revealed = false; + bool public presale = true; + mapping(address => bool) public whitelisted; + uint256 public maxPresaleMintAmount = 2; + constructor() ERC721("NAME", "SYMBOL") { setHiddenMetadataUri("ipfs://__CID__/hidden.json"); } @@ -56,6 +60,15 @@ contract SimpleNftLowerGas is ERC721, Ownable { require(!paused, "The contract is paused!"); require(msg.value >= cost * _mintAmount, "Insufficient funds!"); + if (presale) { //Murf dont allow minting if presale is set and buyer is not in whitelisted map + if ( !isInWhiteList(msg.sender)) { + revert("Buyer is not in Whitelist for Pre-Sale"); + } + // //BM check if already bought + if ( balanceOf(msg.sender)+_mintAmount > maxPresaleMintAmount) + revert("Buyer has already pre-sale minted max tokens"); + } + _mintLoop(msg.sender, _mintAmount); } @@ -164,4 +177,30 @@ contract SimpleNftLowerGas is ERC721, Ownable { function _baseURI() internal view virtual override returns (string memory) { return uriPrefix; } + + //Murf Whitelist Functions + function setPresale(bool _state) public onlyOwner { + presale = _state; + } + + function setMaxPresaleMintAmount(uint256 _max) public onlyOwner { + maxPresaleMintAmount = _max; + } + + function addToWhiteList(address _addr) public onlyOwner { + whitelisted[_addr] = true; + } + + function addArrayToWhiteList(address[] memory _addrs) public onlyOwner { + for (uint256 i=0;i< _addrs.length;i++) + whitelisted[_addrs[i]] = true; + } + + function removeFromWhiteList(address _addr) public onlyOwner { + whitelisted[_addr] = false; + } + + function isInWhiteList(address _addr) private view returns (bool) { + return whitelisted[_addr] || _addr == owner(); + } }