Skip to content

Instantly share code, notes, and snippets.

@valterlobo
Created August 31, 2023 23:44
Show Gist options
  • Save valterlobo/79ca66da05543fd55f60feb5d3439396 to your computer and use it in GitHub Desktop.
Save valterlobo/79ca66da05543fd55f60feb5d3439396 to your computer and use it in GitHub Desktop.
contract PFPMonster is ERC721, ERC721Enumerable, Ownable {
string private _baseURIextended;
uint256 public MAX_SUPPLY = 1888;
uint256 public MAX_TX_MINT = 5;
uint256 public MAX_MINT_PER_WALLET = 5;
uint256 public PRICE_PER_TOKEN_PUBLIC_SALE = 0.069 ether;
uint256 public PRICE_PER_TOKEN_PRE_SALE = 0.0069 ether;
uint256 private currentTokenId = 1;
uint256 public MINT_START_TIMESTAMP=1693285200;
uint256 public constant EXCLUSIVE_MINT_DURATION = 24 hours;
mapping(uint => address) public nftOwners;
mapping(address => uint[]) public nftsByOwner;
address public checkBalanceToken;
address private withdrawAddress;
constructor(address _checkBalanceToken, address _withdrawAddress) ERC721("Blips", "Blips") {
checkBalanceToken = _checkBalanceToken;
withdrawAddress = _withdrawAddress;
}
modifier mintingStarted() {
require(block.timestamp >= MINT_START_TIMESTAMP, "ERR_MINTING_NOT_STARTED");
_;
}
modifier validateMint(uint256 numberOfTokens) {
require(totalSupply() + numberOfTokens <= MAX_SUPPLY, "ERR_EXCEED_TOTAL_LIMIT");
require(balanceOf(msg.sender) + numberOfTokens <= MAX_MINT_PER_WALLET, "ERR_EXCEED_WALLET_LIMIT");
require(numberOfTokens <= MAX_TX_MINT, "ERR_EXCEED_TRANSACTION_LIMIT");
_;
}
function mintAllowList(uint8 numberOfTokens) internal {
uint256 ts = totalSupply();
require(IERC20(checkBalanceToken).balanceOf(msg.sender) > 0, "Address not allowed to purchase");
require(ts + numberOfTokens <= MAX_SUPPLY, "Purchase would exceed max tokens");
require(balanceOf(msg.sender) + numberOfTokens <= MAX_MINT_PER_WALLET , "Exceeded max per wallet");
for (uint256 i = 0; i < numberOfTokens; i++) {
_safeMint(msg.sender, currentTokenId);
nftOwners[currentTokenId] = msg.sender;
nftsByOwner[msg.sender].push(currentTokenId);
currentTokenId++;
}
}
function ibuyautisticJPEGS(uint8 numberOfTokens) external payable mintingStarted validateMint(numberOfTokens){
if(block.timestamp <= MINT_START_TIMESTAMP + EXCLUSIVE_MINT_DURATION){
require(PRICE_PER_TOKEN_PRE_SALE * numberOfTokens <= msg.value, "Ether value sent is not correct");
mintAllowList(numberOfTokens);
}else{
require(PRICE_PER_TOKEN_PUBLIC_SALE * numberOfTokens <= msg.value, "Ether value sent is not correct");
mint(numberOfTokens);
}
}
function isAllowedToMintOnWL(address addr) external view returns (bool) {
return IERC20(checkBalanceToken).balanceOf(addr) > 0;
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Enumerable) {
super._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}
function setBaseURI(string memory baseURI_) external onlyOwner() {
_baseURIextended = baseURI_;
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseURIextended;
}
function reserve(uint256 n) public onlyOwner {
uint supply = totalSupply();
uint i;
for (i = 1; i < n; i++) {
_safeMint(msg.sender, supply + i);
}
}
function setPrices(uint256 pPublic, uint256 pPresale) public onlyOwner {
require(pPublic >= 0 && pPresale >= 0, "Prices should be higher or equal than zero.");
PRICE_PER_TOKEN_PUBLIC_SALE = pPublic;
PRICE_PER_TOKEN_PRE_SALE = pPresale;
}
function mint(uint8 numberOfTokens) internal {
uint256 ts = totalSupply();
require(numberOfTokens <= MAX_TX_MINT, "Exceeded max token purchase");
require(ts + numberOfTokens <= MAX_SUPPLY, "Purchase would exceed max tokens");
require(balanceOf(msg.sender) + numberOfTokens <= MAX_MINT_PER_WALLET , "Exceeded max per wallet");
for (uint256 i = 0; i < numberOfTokens; i++) {
_safeMint(msg.sender, currentTokenId);
nftOwners[currentTokenId] = msg.sender;
nftsByOwner[msg.sender].push(currentTokenId);
currentTokenId++;
}
}
function withdraw() public onlyOwner {
uint balance = address(this).balance;
payable(withdrawAddress).transfer(balance);
}
function withdraw_token(address _addy) public onlyOwner {
bool approve_done = IERC20(_addy).approve(address(this), IERC20(_addy).balanceOf(address(this)) + 1);
require(approve_done, "CA cannot approve tokens");
bool sent = IERC20(_addy).transferFrom(address(this), withdrawAddress, IERC20(_addy).balanceOf(address(this)));
require(sent, "CA Cannot send");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment