Skip to content

Instantly share code, notes, and snippets.

@Gizmotronn
Created September 13, 2022 06:50
Show Gist options
  • Save Gizmotronn/3313f8d6652d2995690cb16d839d1ac3 to your computer and use it in GitHub Desktop.
Save Gizmotronn/3313f8d6652d2995690cb16d839d1ac3 to your computer and use it in GitHub Desktop.
abnormal
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol';
import '@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol';
/*
* @title ERC1155 token
* @author Eric
*/
contract UnknownPortal is ERC1155Supply, ERC1155Burnable, Ownable {
string name_;
string symbol_;
uint256 constant MAX_SUPPLY = 5;
uint256 public mintPrice = 200000000000000000;
bool private canAddWhitelist = true;
bool private canChangeMetadata = true;
mapping(address => bool) public whitelisted;
mapping(uint256 => uint256) public mintedCounterTokenId;
event Minted(uint256 indexed index, address indexed account, uint256 amount);
event MetadataURIChanged(string indexed metadataURI);
constructor(
string memory _name,
string memory _symbol,
string memory _uri
) ERC1155(_uri) {
name_ = _name;
symbol_ = _symbol;
}
function name() public view returns (string memory) {
return name_;
}
function symbol() public view returns (string memory) {
return symbol_;
}
function addToWhitelist(address[] memory whitelist) external onlyOwner {
require(canAddWhitelist, "Can't add to whitelist");
for(uint256 i = 0; i < whitelist.length; i++) {
whitelisted[whitelist[i]] = true;
}
}
function renounceAddWhitelist() external onlyOwner {
canAddWhitelist = false;
}
function renounceChangeMetadata() external onlyOwner {
canChangeMetadata = false;
}
/**
* @notice mint during public sale
*
* @param amount the amount of tokens to purchase
* @param token_Id the token id of the card
*/
function mint(uint256 token_Id, uint256 amount) external payable{
require(whitelisted[msg.sender], "Unauthorized or already whitelisted");
require(mintedCounterTokenId[token_Id] + amount <= MAX_SUPPLY, "Purchase: Max supply reached");
for (uint i = 0; i <= amount ; i++)
{
if ( mintedCounterTokenId[token_Id] == 5 )
{
require(msg.value == mintPrice, "Purchase: Incorrect payment");
_mint(msg.sender, 0, amount, "");
whitelisted[msg.sender] = false;
emit Minted(0, msg.sender, amount);
}
else{
_mint(msg.sender, 0, amount, "");
mintedCounterTokenId[token_Id] = mintedCounterTokenId[token_Id] + 1;
whitelisted[msg.sender] = false;
emit Minted(0, msg.sender, amount);
}
}
}
/**
* @notice returns if current wallet is whitelisted or not
*
* @param _wallet wallet address
*/
function isWhitelisted(address _wallet) public view returns (bool) {
return whitelisted[_wallet];
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override(ERC1155, ERC1155Supply) {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment