Skip to content

Instantly share code, notes, and snippets.

@CoolCatsNFTPublic
Created July 27, 2021 08:47
Show Gist options
  • Save CoolCatsNFTPublic/43d5deddc2676a14de1778be51ebbcff to your computer and use it in GitHub Desktop.
Save CoolCatsNFTPublic/43d5deddc2676a14de1778be51ebbcff to your computer and use it in GitHub Desktop.
Some changes to help stonercats out - NEEDS testing
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
// @title: Stoner Cats
// @author: bighead.club
////////////////////////////////////////////////////////////////////////
// //
// __ =^..^= //
// =^._.^= (u u). =^..^= //
// (_)--\_) ( \ =^..^=___. ,--. //--//(,------.,------, //
// / _ / |'--b..b__)( u u).-.\| \ | |) | .---'| ---`' //
// \_..`--. `--. .--'( _) | | || . '| |d | '--. | |_.' | //
// .-._) \ | | \| | | || |\ | | .--' | . .' //
// \ / | | ' '-' '| | \ | | `---.| |\ \ //
// `-----' `--' `-----' `--' `--' `------'`--' '--' //
// //
// (((( //
// ,-----. ,----. _=^..^= __∫ _____ .,, (((((( .//. //
// / .--./ | /`. \ | uu...u_) ___/ /(((( `(((/. ((((( //
// | =^..^= '-'|_.' |`--. .--'\_..`--. (((((. ..,. /(((/ //
// | |u u )(| .-. | | | .-._) \ ,,```. ((((((./(' /(\ //
// ' '--'\ | | | | | | \ / ((((,, .((/((((. '(((( //
// `-----' `--' `--' `--' `-----' .((/,..(((((((((( *((, //
// (////(((((( //
// ((//((/) //
// //
////////////////////////////////////////////////////////////////////////
// OpenZeppelin
import "./token/ERC721/ERC721.sol";
import "./access/Ownable.sol";
import "./security/ReentrancyGuard.sol";
import "./introspection/ERC165.sol";
import "./utils/Strings.sol";
import "./access/Ownable.sol";
contract StonerCats is ERC721, Ownable, ReentrancyGuard {
using SafeMath for uint8;
using SafeMath for uint256;
using Strings for string;
// Price, so we can change it if needed
uint public PRICE = 0.35 ether;
// Max transaction limit, so we can change it it needed
uint public MAX_TRANS_AMOUNT = 20;
// Max NFTs total. Due to burning this won't be the max tokenId
uint public constant MAX_TOKENS = 13420;
// Max at launch before ltd edition chars unlock
uint public constant MAX_TOKENS_INIT = 10420;
// Track current supply cap in range [MAX_TOKENS_INIT, MAX_TOKENS]
uint internal CURR_SUPPLY_CAP = MAX_TOKENS_INIT;
// Allow for starting/pausing sale
bool public hasSaleStarted = false;
// Effectively a UUID. Only increments to avoid collisions
// possible if we were reusing token IDs
uint internal nextTokenId = 0;
/*
* Set up the basics
*
* @dev It will NOT be ready to start sale immediately upon deploy
*/
constructor(string memory baseURI) ERC721("Stoner Cats","TOKEn") {
setBaseURI(baseURI);
}
/*
* Get the tokens owned by _owner
*/
function tokensOfOwner(address _owner) external view returns(uint256[] memory ) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 index;
for (index = 0; index < tokenCount; index++) {
result[index] = tokenOfOwnerByIndex(_owner, index);
}
return result;
}
}
/*
* Main function for the NFT sale
*
* Prerequisites
* - Not at max supply
* - Sale has started
*/
function mewnt(uint256 numTokens) external payable nonReentrant {
// Save users gas
// - only call totalSupply once
uint256 supply = totalSupply();
require( hasSaleStarted == true, "Sale paused" );
// Save users gas
// - no one will be dumb enough to mint 0
require( num <= MAX_TRANS_AMOUNT, "Exceeds max transaction value" );
// Save users gas
// - no need for totalSupply() < CURR_SUPPLY_CAP when you have to following
require( supply + numTokens <= CURR_SUPPLY_CAP, "Exceeds maximum Cats supply" );
// Save users gas
// - no need for safeMaths with something so simple
// - no need for the price function
require( msg.value >= PRICE * num, "Ether sent is not correct" );
// Cleaned up loop
// - uint i defaults to 0
for (uint i; i < numTokens; i++) {
uint mintId = nextTokenId++;
_safeMint(msg.sender, mintId);
_setTokenURI(mintId, Strings.strConcat(Strings.uint2str(mintId), "/index.json"));
}
}
/*
* Only valid before the sales starts, for giveaways/team thank you's
*/
function reserveGiveaway(uint256 numTokens) public onlyOwner {
// Save users gas
// - only call totalSupply once
uint256 currentSupply = totalSupply();
// Save users gas
// - with a magic number you dont need <=, just up the value by 1
require( currentSupply + numTokens < 101, "Exceeded giveaway supply" );
require( hasSaleStarted == false, "Sale has already started" );
// Cleaned up loop
// - no need for uint index, just add it to the the for loop
// Reserved for people who helped this project and giveaways
for (uint index; index < numTokens; index++) {
nextTokenId++;
_safeMint(owner(), currentSupply + index);
_setTokenURI(currentSupply + index,
Strings.strConcat(Strings.uint2str(currentSupply + index), "/index.json"));
}
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view override(ERC165) returns (bool) {
return ERC165.supportsInterface(interfaceId);
}
// Admin functions
/*
* @dev Under the max of 13420, new characters from future episodes may
* get their own tokens. This makes room for those new ones,
* but still cannot go past the supply cap.
*/
function addCharacter(uint numTokens) public onlyOwner {
require(CURR_SUPPLY_CAP + numTokens <= MAX_TOKENS,
"Can't add new character NFTs. Would exceed MAX_TOKENS");
CURR_SUPPLY_CAP = CURR_SUPPLY_CAP + numTokens;
}
function getCurrentSupplyCap() public view returns(uint) {
return CURR_SUPPLY_CAP;
}
function setBaseURI(string memory baseURI) public onlyOwner {
_setBaseURI(baseURI);
}
// Simplified to a single function
function hasSaleStarted(bool value) public onlyOwner {
hasSaleStarted = value;
}
function setPrice(uint newPrice) public onlyOwner {
PRICE = newPrice;
}
function setMaxTransAmount(uint newAmount) public onlyOwner {
MAX_TRANS_AMOUNT = newAmount;
}
function withdrawAll() public payable onlyOwner {
require(payable(msg.sender).send(address(this).balance));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment