|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
interface IERC20 {
|
|
|
|
|
|
|
|
function totalSupply() external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
function balanceOf(address account) external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function transfer(address to, uint256 amount) external returns (bool);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function allowance(address owner, address spender) external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function approve(address spender, uint256 amount) external returns (bool);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function transferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 amount
|
|
) external returns (bool);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
event Transfer(address indexed from, address indexed to, uint256 value);
|
|
|
|
|
|
|
|
|
|
|
|
event Approval(address indexed owner, address indexed spender, uint256 value);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
library Strings {
|
|
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
|
|
|
|
|
|
|
|
|
|
function toString(uint256 value) internal pure returns (string memory) {
|
|
|
|
|
|
|
|
if (value == 0) {
|
|
return "0";
|
|
}
|
|
uint256 temp = value;
|
|
uint256 digits;
|
|
while (temp != 0) {
|
|
digits++;
|
|
temp /= 10;
|
|
}
|
|
bytes memory buffer = new bytes(digits);
|
|
while (value != 0) {
|
|
digits -= 1;
|
|
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
|
|
value /= 10;
|
|
}
|
|
return string(buffer);
|
|
}
|
|
|
|
|
|
|
|
|
|
function toHexString(uint256 value) internal pure returns (string memory) {
|
|
if (value == 0) {
|
|
return "0x00";
|
|
}
|
|
uint256 temp = value;
|
|
uint256 length = 0;
|
|
while (temp != 0) {
|
|
length++;
|
|
temp >>= 8;
|
|
}
|
|
return toHexString(value, length);
|
|
}
|
|
|
|
|
|
|
|
|
|
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
|
|
bytes memory buffer = new bytes(2 * length + 2);
|
|
buffer[0] = "0";
|
|
buffer[1] = "x";
|
|
for (uint256 i = 2 * length + 1; i > 1; --i) {
|
|
buffer[i] = _HEX_SYMBOLS[value & 0xf];
|
|
value >>= 4;
|
|
}
|
|
require(value == 0, "Strings: hex length insufficient");
|
|
return string(buffer);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.9;
|
|
|
|
|
|
|
|
|
|
|
|
library MerkleProof {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Strings for uint256;
|
|
|
|
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
|
|
bytes32 computedHash = leaf;
|
|
for (uint256 i = 0; i < proof.length; i++) {
|
|
bytes32 proofElement = proof[i];
|
|
if (computedHash <= proofElement) {
|
|
|
|
computedHash = keccak256(abi.encodePacked(i.toString(), computedHash, proofElement));
|
|
} else {
|
|
|
|
computedHash = keccak256(abi.encodePacked(i.toString(), proofElement, computedHash));
|
|
}
|
|
}
|
|
|
|
return computedHash == root;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.1;
|
|
|
|
|
|
|
|
|
|
library Address {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isContract(address account) internal view returns (bool) {
|
|
|
|
|
|
|
|
|
|
return account.code.length > 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sendValue(address payable recipient, uint256 amount) internal {
|
|
require(address(this).balance >= amount, "Address: insufficient balance");
|
|
|
|
(bool success, ) = recipient.call{value: amount}("");
|
|
require(success, "Address: unable to send value, recipient may have reverted");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
|
|
return functionCall(target, data, "Address: low-level call failed");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionCall(
|
|
address target,
|
|
bytes memory data,
|
|
string memory errorMessage
|
|
) internal returns (bytes memory) {
|
|
return functionCallWithValue(target, data, 0, errorMessage);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionCallWithValue(
|
|
address target,
|
|
bytes memory data,
|
|
uint256 value
|
|
) internal returns (bytes memory) {
|
|
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionCallWithValue(
|
|
address target,
|
|
bytes memory data,
|
|
uint256 value,
|
|
string memory errorMessage
|
|
) internal returns (bytes memory) {
|
|
require(address(this).balance >= value, "Address: insufficient balance for call");
|
|
require(isContract(target), "Address: call to non-contract");
|
|
|
|
(bool success, bytes memory returndata) = target.call{value: value}(data);
|
|
return verifyCallResult(success, returndata, errorMessage);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
|
|
return functionStaticCall(target, data, "Address: low-level static call failed");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionStaticCall(
|
|
address target,
|
|
bytes memory data,
|
|
string memory errorMessage
|
|
) internal view returns (bytes memory) {
|
|
require(isContract(target), "Address: static call to non-contract");
|
|
|
|
(bool success, bytes memory returndata) = target.staticcall(data);
|
|
return verifyCallResult(success, returndata, errorMessage);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
|
|
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionDelegateCall(
|
|
address target,
|
|
bytes memory data,
|
|
string memory errorMessage
|
|
) internal returns (bytes memory) {
|
|
require(isContract(target), "Address: delegate call to non-contract");
|
|
|
|
(bool success, bytes memory returndata) = target.delegatecall(data);
|
|
return verifyCallResult(success, returndata, errorMessage);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function verifyCallResult(
|
|
bool success,
|
|
bytes memory returndata,
|
|
string memory errorMessage
|
|
) internal pure returns (bytes memory) {
|
|
if (success) {
|
|
return returndata;
|
|
} else {
|
|
|
|
if (returndata.length > 0) {
|
|
|
|
|
|
assembly {
|
|
let returndata_size := mload(returndata)
|
|
revert(add(32, returndata), returndata_size)
|
|
}
|
|
} else {
|
|
revert(errorMessage);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IERC721Receiver {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onERC721Received(
|
|
address operator,
|
|
address from,
|
|
uint256 tokenId,
|
|
bytes calldata data
|
|
) external returns (bytes4);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract Context {
|
|
function _msgSender() internal view virtual returns (address) {
|
|
return msg.sender;
|
|
}
|
|
|
|
function _msgData() internal view virtual returns (bytes calldata) {
|
|
return msg.data;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract Ownable is Context {
|
|
address private _owner;
|
|
|
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
_transferOwnership(_msgSender());
|
|
}
|
|
|
|
|
|
|
|
|
|
function owner() public view virtual returns (address) {
|
|
return _owner;
|
|
}
|
|
|
|
|
|
|
|
|
|
modifier onlyOwner() {
|
|
require(owner() == _msgSender(), "Ownable: caller is not the owner");
|
|
_;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function renounceOwnership() public virtual onlyOwner {
|
|
_transferOwnership(address(0));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function transferOwnership(address newOwner) public virtual onlyOwner {
|
|
require(newOwner != address(0), "Ownable: new owner is the zero address");
|
|
_transferOwnership(newOwner);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _transferOwnership(address newOwner) internal virtual {
|
|
address oldOwner = _owner;
|
|
_owner = newOwner;
|
|
emit OwnershipTransferred(oldOwner, newOwner);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract Pausable is Context {
|
|
|
|
|
|
|
|
event Paused(address account);
|
|
|
|
|
|
|
|
|
|
event Unpaused(address account);
|
|
|
|
bool private _paused;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
_paused = false;
|
|
}
|
|
|
|
|
|
|
|
|
|
function paused() public view virtual returns (bool) {
|
|
return _paused;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modifier whenNotPaused() {
|
|
require(!paused(), "Pausable: paused");
|
|
_;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modifier whenPaused() {
|
|
require(paused(), "Pausable: not paused");
|
|
_;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _pause() internal virtual whenNotPaused {
|
|
_paused = true;
|
|
emit Paused(_msgSender());
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _unpause() internal virtual whenPaused {
|
|
_paused = false;
|
|
emit Unpaused(_msgSender());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IERC165 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function supportsInterface(bytes4 interfaceId) external view returns (bool);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.9;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract PublicPrivateVoucherMinter is Ownable {
|
|
|
|
|
|
event MinterCreated(address _address);
|
|
event PublicMint (address _address, uint256 _amount, uint256 _value);
|
|
event PrivateMint(address _address, uint256 id, uint256 _amount, uint256 _value);
|
|
event VoucherMint(address _address, uint256 id, uint256 _amount, uint256 _value);
|
|
event ProjectMint(address _address, uint256 _amount, string _reason);
|
|
|
|
|
|
struct MinterConfig {
|
|
bool isPublicMintActive;
|
|
bool isPrivateMintActive;
|
|
bool isVoucherMintActive;
|
|
uint256 publicMintPrice;
|
|
uint256 privateMintPrice;
|
|
uint256 maxPublicMintAmount;
|
|
uint256 maxPrivateMintAmount;
|
|
uint256 maxTotalSupply;
|
|
uint256 maxPrivateMintSupply;
|
|
}
|
|
|
|
|
|
uint256 public totalPublicSold;
|
|
uint256 public totalPrivateSold;
|
|
uint256 public totalVoucherClaimed;
|
|
uint256 public totalVoucherIssued;
|
|
uint256 public totalProjectMint;
|
|
|
|
address public beneficiary;
|
|
|
|
bytes32 private _merkleRoot;
|
|
uint256 private _proofLength;
|
|
|
|
|
|
mapping(uint256 => uint256) private _amountUsed;
|
|
|
|
|
|
address private _operator;
|
|
|
|
MinterConfig public minterConfig;
|
|
|
|
constructor (MinterConfig memory config, address payable _beneficiary) {
|
|
setMinterConfig(config);
|
|
setBeneficiary(_beneficiary);
|
|
setOperator(_msgSender());
|
|
}
|
|
|
|
function setMinterConfig(MinterConfig memory config) public onlyOwner {
|
|
minterConfig = config;
|
|
}
|
|
|
|
|
|
function setBeneficiary(address payable _beneficiary) public onlyOwner {
|
|
require(_beneficiary != address(0), "Not the zero address");
|
|
beneficiary = _beneficiary;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _mintTo(address to, uint256 amount) internal virtual;
|
|
|
|
function toggleZeroPublicMintActive() external onlyOwnerAndOperator {
|
|
minterConfig.isPublicMintActive = !minterConfig.isPublicMintActive;
|
|
}
|
|
|
|
function toggleZeroPrivateMintActive() external onlyOwnerAndOperator {
|
|
minterConfig.isPrivateMintActive = !minterConfig.isPrivateMintActive;
|
|
}
|
|
|
|
function togglePublicMintActive() external onlyOwnerAndOperator {
|
|
require (minterConfig.publicMintPrice > 0, "Public Mint Price is zero");
|
|
minterConfig.isPublicMintActive = !minterConfig.isPublicMintActive;
|
|
}
|
|
|
|
function togglePrivateMintActive() external onlyOwnerAndOperator {
|
|
require (minterConfig.privateMintPrice > 0, "Private Mint Price is zero");
|
|
minterConfig.isPrivateMintActive = !minterConfig.isPrivateMintActive;
|
|
}
|
|
|
|
function toggleVoucherMintActive() external onlyOwnerAndOperator {
|
|
minterConfig.isVoucherMintActive = !minterConfig.isVoucherMintActive;
|
|
}
|
|
|
|
function totalSold() external view returns (uint256) {
|
|
return totalPublicSold + totalPrivateSold + totalVoucherClaimed;
|
|
}
|
|
|
|
|
|
function setMaxTotalSupply(uint256 supply) external onlyOwnerAndOperator {
|
|
minterConfig.maxTotalSupply = supply;
|
|
}
|
|
|
|
|
|
function setPublicMintDetail(uint256 price, uint256 amount) external onlyOwnerAndOperator {
|
|
require(!minterConfig.isPublicMintActive, "Public mint is active");
|
|
minterConfig.publicMintPrice = price;
|
|
minterConfig.maxPublicMintAmount = amount;
|
|
}
|
|
|
|
|
|
function setPrivateMintDetail(uint256 price, uint256 amount, uint256 supply) external onlyOwnerAndOperator {
|
|
require(!minterConfig.isPrivateMintActive, "Private mint is active");
|
|
minterConfig.privateMintPrice = price;
|
|
minterConfig.maxPrivateMintAmount = amount;
|
|
minterConfig.maxPrivateMintSupply = supply;
|
|
}
|
|
|
|
|
|
function setVoucherDetail(bytes32 merkleRoot, uint256 proofLength, uint256 voucherAmount) external onlyOwnerAndOperator {
|
|
_merkleRoot = merkleRoot;
|
|
_proofLength = proofLength;
|
|
totalVoucherIssued = voucherAmount;
|
|
}
|
|
|
|
function publicMint(uint256 amount) public payable {
|
|
require(minterConfig.isPublicMintActive,"Public mint is closed");
|
|
require(amount > 0,"Amount is zero");
|
|
require(amount <= minterConfig.maxPublicMintAmount,"Amount is greater than maximum");
|
|
require(totalProjectMint + totalPublicSold + totalPrivateSold + totalVoucherIssued + amount <= minterConfig.maxTotalSupply,"Exceed maxTotalSupply");
|
|
require(minterConfig.publicMintPrice * amount <= msg.value, "Insufficient fund");
|
|
|
|
address to = _msgSender();
|
|
|
|
_mintTo(to, amount);
|
|
totalPublicSold += amount;
|
|
emit PublicMint(to, amount, msg.value);
|
|
}
|
|
|
|
function privateMint( uint256 amount,
|
|
uint256 whitelistedId, uint256 whitelistedAmount, bytes32[] calldata proof ) public payable {
|
|
|
|
require(minterConfig.isPrivateMintActive,"Private mint is closed");
|
|
|
|
address to = _msgSender();
|
|
bytes32 hash = keccak256(abi.encodePacked(whitelistedId, address(this), 'W', to, whitelistedAmount));
|
|
require(proof.length == _proofLength,"Invalid whitelisted detail");
|
|
require(MerkleProof.verify(proof, _merkleRoot, hash),"Invalid whitelisted detail");
|
|
require(_amountUsed[whitelistedId] == 0, "Whielisted has been used");
|
|
if (whitelistedAmount == 0) {
|
|
require(amount <= minterConfig.maxPrivateMintAmount,"Amount is greater than maximum");
|
|
} else {
|
|
require(amount <= whitelistedAmount,"Amount is greater than maximum");
|
|
}
|
|
require(amount > 0,"Amount is zero");
|
|
require(totalPrivateSold + amount <= minterConfig.maxPrivateMintSupply,"Exceed maxPrivateMintSupply");
|
|
require(minterConfig.privateMintPrice * amount <= msg.value, "Insufficient fund");
|
|
|
|
_mintTo(to, amount);
|
|
|
|
_amountUsed[whitelistedId] = amount;
|
|
totalPrivateSold += amount;
|
|
emit PrivateMint(to, whitelistedId, amount, msg.value);
|
|
}
|
|
|
|
function voucherMint( uint256 amount,
|
|
uint256 voucherId, uint256 voucherAmount, uint256 voucherPrice, bytes32[] calldata proof) public payable {
|
|
|
|
require(minterConfig.isVoucherMintActive,"Voucher mint is closed");
|
|
|
|
address to = _msgSender();
|
|
bytes32 hash = keccak256(abi.encodePacked(voucherId, address(this), 'V', to, voucherAmount, voucherPrice));
|
|
require(proof.length == _proofLength,"Invalid whitelisted detail");
|
|
require(MerkleProof.verify(proof, _merkleRoot, hash),"Invalid voucher detail");
|
|
require(_amountUsed[voucherId] + amount <= voucherAmount,"Ammount is greater than voucher");
|
|
require(amount > 0,"Amount is zero");
|
|
require(voucherPrice * amount <= msg.value, "Insufficient fund");
|
|
|
|
_mintTo(to, amount);
|
|
|
|
_amountUsed[voucherId] += amount;
|
|
totalVoucherClaimed += amount;
|
|
emit VoucherMint(to, voucherId, amount, msg.value);
|
|
}
|
|
|
|
function _projectMint(address to, uint256 amount, string memory reason) internal {
|
|
_mintTo(to, amount);
|
|
totalProjectMint += amount;
|
|
emit ProjectMint(to, amount, reason);
|
|
}
|
|
|
|
function getAmountUsed(uint256 voucherId) external view returns (uint256) {
|
|
return _amountUsed[voucherId];
|
|
}
|
|
|
|
|
|
|
|
|
|
function withdraw() external onlyOwner {
|
|
uint256 _balance = address(this).balance;
|
|
Address.sendValue(payable(beneficiary), _balance);
|
|
}
|
|
|
|
function withdraw(uint256 balance) external onlyOwner {
|
|
Address.sendValue(payable(beneficiary), balance);
|
|
}
|
|
|
|
function transferERC20(IERC20 token) external onlyOwner {
|
|
uint256 balance = token.balanceOf(address(this));
|
|
token.transfer(beneficiary, balance);
|
|
}
|
|
|
|
function transferERC20(IERC20 token, uint256 amount) external onlyOwner {
|
|
token.transfer(beneficiary, amount);
|
|
}
|
|
|
|
function donate() external payable {
|
|
|
|
}
|
|
|
|
|
|
function setOperator(address operator) public onlyOwner {
|
|
require(operator != address(0), "Not the zero address");
|
|
_operator = operator;
|
|
}
|
|
|
|
function minterStatus() public view returns (
|
|
bool isPublicMintActive_,
|
|
bool isPrivateMintActive_,
|
|
bool isVoucherMintActive_,
|
|
uint256 publicMintPrice_,
|
|
uint256 privateMintPrice_,
|
|
uint256 maxPublicMintAmount_,
|
|
uint256 maxPrivateMintAmount_,
|
|
uint256 maxTotalSupply_,
|
|
uint256 maxPrivateMintSupply_,
|
|
uint256 totalPublicSold_,
|
|
uint256 totalPrivateSold_,
|
|
uint256 totalVoucherClaimed_,
|
|
uint256 totalVoucherIssued_,
|
|
uint256 totalProjectMint_
|
|
)
|
|
{
|
|
isPublicMintActive_ = minterConfig.isPublicMintActive;
|
|
isPrivateMintActive_ = minterConfig.isPrivateMintActive;
|
|
isVoucherMintActive_ = minterConfig.isVoucherMintActive;
|
|
publicMintPrice_ = minterConfig.publicMintPrice;
|
|
privateMintPrice_ = minterConfig.privateMintPrice;
|
|
maxPublicMintAmount_ = minterConfig.maxPublicMintAmount;
|
|
maxPrivateMintAmount_ = minterConfig.maxPrivateMintAmount;
|
|
maxTotalSupply_ = minterConfig.maxTotalSupply;
|
|
maxPrivateMintSupply_ = minterConfig.maxPrivateMintSupply;
|
|
totalPublicSold_ = totalPublicSold;
|
|
totalPrivateSold_ = totalPrivateSold;
|
|
totalVoucherClaimed_ = totalVoucherClaimed;
|
|
totalVoucherIssued_ = totalVoucherIssued;
|
|
totalProjectMint_ = totalProjectMint;
|
|
}
|
|
|
|
|
|
|
|
|
|
modifier onlyOwnerAndOperator() {
|
|
require( _msgSender() == owner() || _msgSender() == _operator, "Caller is not the operator");
|
|
_;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
interface IERC721 is IERC165 {
|
|
|
|
|
|
|
|
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
|
|
|
|
|
|
|
|
|
|
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
|
|
|
|
|
|
|
|
|
|
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
|
|
|
|
|
|
|
|
|
|
function balanceOf(address owner) external view returns (uint256 balance);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ownerOf(uint256 tokenId) external view returns (address owner);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function transferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function approve(address to, uint256 tokenId) external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getApproved(uint256 tokenId) external view returns (address operator);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setApprovalForAll(address operator, bool _approved) external;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isApprovedForAll(address owner, address operator) external view returns (bool);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes calldata data
|
|
) external;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IERC721Enumerable is IERC721 {
|
|
|
|
|
|
|
|
function totalSupply() external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
|
|
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
|
|
function tokenByIndex(uint256 index) external view returns (uint256);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IERC721Metadata is IERC721 {
|
|
|
|
|
|
|
|
function name() external view returns (string memory);
|
|
|
|
|
|
|
|
|
|
function symbol() external view returns (string memory);
|
|
|
|
|
|
|
|
|
|
function tokenURI(uint256 tokenId) external view returns (string memory);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IERC2981 is IERC165 {
|
|
|
|
|
|
|
|
|
|
function royaltyInfo(uint256 tokenId, uint256 salePrice)
|
|
external
|
|
view
|
|
returns (address receiver, uint256 royaltyAmount);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract ERC165 is IERC165 {
|
|
|
|
|
|
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
return interfaceId == type(IERC165).interfaceId;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contract ERC721S is Context, ERC165, IERC721, IERC721Metadata {
|
|
|
|
using Address for address;
|
|
using Strings for uint256;
|
|
|
|
|
|
struct TokenDetail {
|
|
|
|
address owner;
|
|
|
|
uint32 allTokensIndex;
|
|
|
|
uint32 ownedTokensIndex;
|
|
|
|
uint32 reserved;
|
|
}
|
|
|
|
|
|
string private _name;
|
|
|
|
|
|
string private _symbol;
|
|
|
|
|
|
mapping(uint256 => TokenDetail) private _tokenDetail;
|
|
|
|
|
|
mapping(uint256 => address) private _tokenApprovals;
|
|
|
|
|
|
mapping(address => mapping(address => bool)) private _operatorApprovals;
|
|
|
|
|
|
mapping(address => uint32[]) private _ownedTokens;
|
|
|
|
|
|
uint32[] private _allTokens;
|
|
|
|
|
|
uint32 private _currentIndex;
|
|
|
|
|
|
|
|
|
|
constructor(string memory name_, string memory symbol_) {
|
|
_name = name_;
|
|
_symbol = symbol_;
|
|
_currentIndex = _startTokenId();
|
|
}
|
|
|
|
|
|
|
|
|
|
function _startTokenId() internal view virtual returns (uint32) {
|
|
return 1;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _totalMinted() internal view returns (uint256) {
|
|
|
|
|
|
unchecked {
|
|
return _currentIndex - _startTokenId();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function _totalBurned() internal view returns (uint256) {
|
|
unchecked {
|
|
return _totalMinted() - _allTokens.length;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
|
|
return
|
|
interfaceId == type(IERC721).interfaceId ||
|
|
interfaceId == type(IERC721Metadata).interfaceId ||
|
|
interfaceId == type(IERC721Enumerable).interfaceId ||
|
|
super.supportsInterface(interfaceId);
|
|
}
|
|
|
|
|
|
|
|
|
|
function balanceOf(address owner) public view virtual override returns (uint256) {
|
|
require(owner != address(0), "ERC721: balance query for the zero address");
|
|
return _ownedTokens[owner].length;
|
|
}
|
|
|
|
|
|
|
|
|
|
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
|
|
address owner = _tokenDetail[tokenId].owner;
|
|
require(owner != address(0), "ERC721: owner query for nonexistent token");
|
|
return owner;
|
|
}
|
|
|
|
|
|
|
|
|
|
function name() public view virtual override returns (string memory) {
|
|
return _name;
|
|
}
|
|
|
|
|
|
|
|
|
|
function symbol() public view virtual override returns (string memory) {
|
|
return _symbol;
|
|
}
|
|
|
|
|
|
|
|
|
|
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
|
|
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
|
|
string memory baseURI = _baseURI();
|
|
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _baseURI() internal view virtual returns (string memory) {
|
|
return "";
|
|
}
|
|
|
|
|
|
|
|
|
|
function approve(address to, uint256 tokenId) public virtual override {
|
|
address owner = ERC721S.ownerOf(tokenId);
|
|
require(to != owner, "ERC721: approval to current owner");
|
|
require(
|
|
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
|
|
"ERC721: approve caller is not owner nor approved for all"
|
|
);
|
|
_approve(to, tokenId);
|
|
}
|
|
|
|
|
|
|
|
|
|
function getApproved(uint256 tokenId) public view virtual override returns (address) {
|
|
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
|
|
return _tokenApprovals[tokenId];
|
|
}
|
|
|
|
|
|
|
|
|
|
function setApprovalForAll(address operator, bool approved) public virtual override {
|
|
_setApprovalForAll(_msgSender(), operator, approved);
|
|
}
|
|
|
|
|
|
|
|
|
|
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
|
|
return _operatorApprovals[owner][operator];
|
|
}
|
|
|
|
|
|
|
|
|
|
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
|
|
|
|
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
|
|
_transfer(from, to, tokenId);
|
|
}
|
|
|
|
|
|
|
|
|
|
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
|
|
safeTransferFrom(from, to, tokenId, "");
|
|
}
|
|
|
|
|
|
|
|
|
|
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
|
|
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
|
|
_safeTransfer(from, to, tokenId, _data);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
|
|
_transfer(from, to, tokenId);
|
|
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _exists(uint256 tokenId) internal view virtual returns (bool) {
|
|
return _tokenDetail[tokenId].owner != address(0);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
|
|
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
|
|
address owner = ERC721S.ownerOf(tokenId);
|
|
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _safeMint(address to) internal virtual {
|
|
_safeMint(to, "");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _safeMint(address to, bytes memory _data) internal virtual {
|
|
uint256 tokenId = uint256(_currentIndex);
|
|
_mint(to);
|
|
require(
|
|
_checkOnERC721Received(address(0), to, tokenId, _data),
|
|
"ERC721: transfer to non ERC721Receiver implementer"
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _mint(address to) internal virtual {
|
|
require(to != address(0), "ERC721: mint to the zero address");
|
|
|
|
uint32 tokenId = _currentIndex;
|
|
|
|
_beforeTokenTransfer(address(0), to, tokenId);
|
|
|
|
uint32[] storage toTokenList = _ownedTokens[to];
|
|
TokenDetail storage tokenDetail = _tokenDetail[tokenId];
|
|
|
|
tokenDetail.owner = to;
|
|
tokenDetail.ownedTokensIndex = uint32(toTokenList.length);
|
|
tokenDetail.allTokensIndex = uint32(_allTokens.length);
|
|
|
|
toTokenList.push(tokenId);
|
|
_allTokens.push(tokenId);
|
|
|
|
_currentIndex += 1;
|
|
|
|
emit Transfer(address(0), to, tokenId);
|
|
|
|
_afterTokenTransfer(address(0), to, tokenId);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _burn(uint256 tokenId) internal virtual {
|
|
address owner = ERC721S.ownerOf(tokenId);
|
|
|
|
_beforeTokenTransfer(owner, address(0), tokenId);
|
|
|
|
|
|
_approve(address(0), tokenId);
|
|
|
|
TokenDetail storage tokenDetail = _tokenDetail[tokenId];
|
|
uint32[] storage fromTokenList = _ownedTokens[owner];
|
|
|
|
|
|
uint32 tokenIndex = tokenDetail.ownedTokensIndex;
|
|
uint32 lastToken = fromTokenList[fromTokenList.length - 1];
|
|
if (lastToken != uint32(tokenId)) {
|
|
fromTokenList[tokenIndex] = lastToken;
|
|
_tokenDetail[lastToken].ownedTokensIndex = tokenIndex;
|
|
}
|
|
fromTokenList.pop();
|
|
|
|
|
|
uint32 lastAllToken = _allTokens[_allTokens.length - 1];
|
|
uint32 allTokensIndex = tokenDetail.allTokensIndex;
|
|
_allTokens[allTokensIndex] = lastAllToken;
|
|
_tokenDetail[lastAllToken].allTokensIndex = allTokensIndex;
|
|
|
|
tokenDetail.owner = address(0);
|
|
tokenDetail.allTokensIndex = 0;
|
|
tokenDetail.ownedTokensIndex = 0;
|
|
|
|
_allTokens.pop();
|
|
|
|
emit Transfer(owner, address(0), tokenId);
|
|
|
|
_afterTokenTransfer(owner, address(0), tokenId);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _transfer(address from, address to, uint256 tokenId) internal virtual {
|
|
require(ERC721S.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
|
|
require(to != address(0), "ERC721: transfer to the zero address");
|
|
|
|
_beforeTokenTransfer(from, to, tokenId);
|
|
|
|
|
|
_approve(address(0), tokenId);
|
|
|
|
_tokenDetail[tokenId].owner = to;
|
|
|
|
|
|
uint32[] storage fromTokenList = _ownedTokens[from];
|
|
TokenDetail storage tokenDetail = _tokenDetail[tokenId];
|
|
uint32 tokenIndex = tokenDetail.ownedTokensIndex;
|
|
uint32 lastToken = fromTokenList[fromTokenList.length - 1];
|
|
fromTokenList[tokenIndex] = lastToken;
|
|
_tokenDetail[lastToken].ownedTokensIndex = tokenIndex;
|
|
fromTokenList.pop();
|
|
|
|
|
|
uint32[] storage toTokenList = _ownedTokens[to];
|
|
tokenDetail.ownedTokensIndex = uint32(toTokenList.length);
|
|
toTokenList.push(uint32(tokenId));
|
|
|
|
emit Transfer(from, to, tokenId);
|
|
|
|
_afterTokenTransfer(from, to, tokenId);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _approve(address to, uint256 tokenId) internal virtual {
|
|
_tokenApprovals[tokenId] = to;
|
|
emit Approval(ERC721S.ownerOf(tokenId), to, tokenId);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
|
|
require(owner != operator, "ERC721: approve to caller");
|
|
_operatorApprovals[owner][operator] = approved;
|
|
emit ApprovalForAll(owner, operator, approved);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) {
|
|
if (to.isContract()) {
|
|
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
|
|
return retval == IERC721Receiver.onERC721Received.selector;
|
|
} catch (bytes memory reason) {
|
|
if (reason.length == 0) {
|
|
revert("ERC721: transfer to non ERC721Receiver implementer");
|
|
} else {
|
|
assembly {
|
|
revert(add(32, reason), mload(reason))
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual returns (uint256) {
|
|
require(index < ERC721S.balanceOf(owner), "Owner index out of bounds");
|
|
return uint256(_ownedTokens[owner][index]);
|
|
}
|
|
|
|
function ownedBy(address owner) external view returns (uint256[] memory) {
|
|
uint256 balance = balanceOf(owner);
|
|
uint256[] memory tokens = new uint256[](balance);
|
|
uint32[] storage ownedTokens = _ownedTokens[owner];
|
|
|
|
for (uint256 i; i < balance; i++) {
|
|
tokens[i] = uint256(ownedTokens[i]);
|
|
}
|
|
|
|
return tokens;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function totalSupply() public view virtual returns (uint256) {
|
|
return _allTokens.length;
|
|
}
|
|
|
|
|
|
|
|
|
|
function tokenByIndex(uint256 index) public view virtual returns (uint256) {
|
|
require(index < ERC721S.totalSupply(), "Global index out of bounds");
|
|
return uint256(_allTokens[index]);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _afterTokenTransfer(address from, address to, uint256 tokenId) internal virtual {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual {}
|
|
|
|
}
|
|
|
|
|
|
|
|
pragma solidity >=0.8.10 <0.9.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contract JCCPixieVoucher is
|
|
ERC721S,
|
|
PublicPrivateVoucherMinter,
|
|
Pausable
|
|
{
|
|
using Strings for uint256;
|
|
|
|
|
|
uint256 public maxSupply = 999;
|
|
|
|
string public baseURI;
|
|
string public notRevealedURI = "https://assets.jokercharlie.com/jccpixie/default.json";
|
|
string public baseExtension = ".json";
|
|
|
|
bool public revealed;
|
|
|
|
constructor (address payable beneficiary)
|
|
ERC721S("JCCPixie Voucher", "JCCPIX")
|
|
PublicPrivateVoucherMinter(
|
|
PublicPrivateVoucherMinter.MinterConfig({
|
|
isPublicMintActive : false, // can call publicMint only when isPublicMintActive is true
|
|
isPrivateMintActive: true, // can call privateMint only when isPrivateMintActive is true
|
|
isVoucherMintActive: false, // can call voucherMint only when isVoucherMintActive is true
|
|
publicMintPrice: 0 ether, // price for publicMint
|
|
privateMintPrice: 0 ether, // price for privateMint
|
|
maxPublicMintAmount: 1, // maximum amount per publicMint transaction
|
|
maxPrivateMintAmount: 1, // default maximum amount per privateMint transaction
|
|
maxTotalSupply: 999, // maximum supply
|
|
maxPrivateMintSupply: 999 // maximum supply for previate mint
|
|
}),
|
|
beneficiary
|
|
)
|
|
{
|
|
require(beneficiary != address(0), "Not the zero address");
|
|
}
|
|
|
|
function reveal()
|
|
external
|
|
onlyOwner
|
|
{
|
|
revealed = true;
|
|
}
|
|
|
|
function pause() external onlyOwner {
|
|
_pause();
|
|
}
|
|
|
|
function unpause() external onlyOwner {
|
|
_unpause();
|
|
}
|
|
|
|
function _mintTo(address to, uint256 amount) internal override
|
|
{
|
|
|
|
require(totalSupply() + amount <= maxSupply, "Max supply limit exceed");
|
|
for (uint256 i; i < amount; i++) {
|
|
_safeMint(to);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function setBaseTokenURI(string calldata uri)
|
|
external
|
|
onlyOwner
|
|
{
|
|
baseURI = uri;
|
|
}
|
|
|
|
function setNotRevealedURI(string calldata uri)
|
|
external
|
|
onlyOwner
|
|
{
|
|
notRevealedURI = uri;
|
|
}
|
|
|
|
function _baseURI() internal view virtual override returns (string memory) {
|
|
return baseURI;
|
|
}
|
|
|
|
function baseTokenURI(uint256 tokenId) public view returns (string memory) {
|
|
string memory currentBaseURI = _baseURI();
|
|
return bytes(currentBaseURI).length > 0
|
|
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
|
|
: "";
|
|
}
|
|
|
|
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;
|
|
} else {
|
|
return baseTokenURI(tokenId);
|
|
}
|
|
}
|
|
|
|
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override {
|
|
require(!paused(), "Contract is paused");
|
|
super._beforeTokenTransfer(from, to, tokenId);
|
|
}
|
|
|
|
} |