Untitled
unknown
plain_text
4 years ago
8.3 kB
10
Indexable
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/finance/PaymentSplitter.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
contract RichDwarvesTribe is
ERC721Enumerable,
Ownable,
PaymentSplitter
{
using Strings for uint256;
using Counters for Counters.Counter;
uint256 public maxSupply = 4999;
uint256 public giftSupply = 3;
uint256 public totalNFT;
uint256 public totalMint;
string public baseURI;
string public notRevealedUri;
string public baseExtension = ".json";
bool public isBurnEnabled = false;
bool public paused = false;
bool public revealed = false;
bool public whitelistState = false;
bool public presaleState = false;
bool public publicState = false;
uint256 presaleAmountLimit = 100;
mapping(address => uint256) public _presaleClaimed;
uint256 _price = 200000000000000000; //0.2 ETH
bytes32 public whitelistRoot;
bytes32 public presaleRoot;
Counters.Counter private _tokenIds;
uint256[] private _teamShares = [50, 50];
address[] private _team = [
0x2b81104A9cb4C30b58702580fc142a49941be6E9,
0xF478E86fBa35DB853E6f569a9143Ed4Bd84a98a6
];
constructor()
ERC721("Rich Dwarves Tribe", "DWARF")
PaymentSplitter(_team, _teamShares)
{}
function changePauseState() public onlyOwner {
paused = !paused;
}
function changeWhitelistState() public onlyOwner {
whitelistState = !whitelistState;
}
function changePresaleState() public onlyOwner {
presaleState = !presaleState;
}
function changePublicState() public onlyOwner {
publicState = !publicState;
}
function setBaseURI(string calldata _tokenBaseURI) external onlyOwner {
baseURI = _tokenBaseURI;
}
function _baseURI() internal view override returns (string memory) {
return baseURI;
}
function reveal() public onlyOwner {
revealed = true;
}
function setIsBurnEnabled(bool _isBurnEnabled) external onlyOwner {
isBurnEnabled = _isBurnEnabled;
}
function giftMint(address[] calldata _addresses) external onlyOwner {
require(
totalNFT + _addresses.length <= maxSupply,
"Rich Dwarves Tribe: max total supply exceeded"
);
uint256 _newItemId;
for (uint256 ind = 0; ind < _addresses.length; ind++) {
require(
_addresses[ind] != address(0),
"Rich Dwarves Tribe: recepient is the null address"
);
_tokenIds.increment();
_newItemId = _tokenIds.current();
_safeMint(_addresses[ind], _newItemId);
totalNFT = totalNFT + 1;
}
}
function whitelistMint(uint256 _amount, bytes32[] memory proof) external payable {
require(whitelistState, "Rich Dwarves: Presale is OFF");
require(!paused, "Rich Dwarves Tribe: contract is paused");
require(
_amount <= presaleAmountLimit,
"Rich Dwarves Tribe: You can't mint so much tokens"
);
require(
_presaleClaimed[msg.sender] + _amount <= presaleAmountLimit,
"Rich Dwarves Tribe: You can't mint so much tokens"
);
require(verify(msg.sender, proof), "Rich Dwarves Tribe: You are not selected for the presale");
require(
totalMint + _amount <= maxSupply - giftSupply,
"Rich Dwarves Tribe: max supply exceeded"
);
require(
_price * _amount <= msg.value,
"Rich Dwarves Tribe: Ether value sent is not correct"
);
uint256 _newItemId;
for (uint256 ind = 0; ind < _amount; ind++) {
_tokenIds.increment();
_newItemId = _tokenIds.current();
_safeMint(msg.sender, _newItemId);
_presaleClaimed[msg.sender] = _presaleClaimed[msg.sender] + 1;
totalNFT = totalNFT + 1;
totalMint = totalMint + 1;
}
}
function presaleMint(uint256 _amount) external payable {
require(presaleState, "Rich Dwarves: Presale is OFF");
require(!paused, "Rich Dwarves Tribe: contract is paused");
require(
_amount <= 3,
"Rich Dwarves Tribe: You can't mint so much tokens"
);
require(
totalMint + _amount <= maxSupply - giftSupply,
"Rich Dwarves Tribe: max supply exceeded"
);
require(
_price * _amount <= msg.value,
"Rich Dwarves Tribe: Ether value sent is not correct"
);
uint256 _newItemId;
for (uint256 ind = 0; ind < _amount; ind++) {
_tokenIds.increment();
_newItemId = _tokenIds.current();
_safeMint(msg.sender, _newItemId);
_presaleClaimed[msg.sender] = _presaleClaimed[msg.sender] + 1;
totalNFT = totalNFT + 1;
totalMint = totalMint + 1;
}
}
function publicMint(uint256 _amount) external payable {
require(publicState, "Rich Dwarves: Public is OFF");
require(_amount > 0, "Rich Dwarves Tribe: zero amount");
require(
totalMint + _amount <= maxSupply - giftSupply,
"Rich Dwarves Tribe: max supply exceeded"
);
require(
_price * _amount <= msg.value,
"Rich Dwarves Tribe: Ether value sent is not correct"
);
require(!paused, "Rich Dwarves Tribe: contract is paused");
uint256 _newItemId;
for (uint256 ind = 0; ind < _amount; ind++) {
_tokenIds.increment();
_newItemId = _tokenIds.current();
_safeMint(msg.sender, _newItemId);
totalNFT = totalNFT + 1;
totalMint = totalMint +1;
}
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if (revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
function changeTotalSupply(uint256 _newSupply) public onlyOwner {
maxSupply = _newSupply;
}
function changeWhitelistRoot(bytes32 _whitelistRoot) public onlyOwner {
whitelistRoot = _whitelistRoot;
}
function changePresaleRoot(bytes32 _presaleRoot) public onlyOwner {
presaleRoot = _presaleRoot;
}
function burn(uint256 tokenId) external {
require(isBurnEnabled, "Rich Dwarves Tribe: burning disabled");
require(
_isApprovedOrOwner(msg.sender, tokenId),
"Rich Dwarves Tribe: burn caller is not owner nor approved"
);
_burn(tokenId);
totalNFT = totalNFT - 1;
}
function verify(address account, bytes32[] memory proof)
internal
view
returns (bool)
{
bytes32 leaf = keccak256(abi.encodePacked(account));
return MerkleProof.verify(proof, whitelistRoot, leaf);
}
}Editor is loading...