文件 1 的 14:Address.sol
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);
}
}
}
}
文件 2 的 14:Context.sol
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;
}
}
文件 3 的 14:ERC1155.sol
pragma solidity ^0.8.0;
import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.sol";
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address;
mapping(uint256 => mapping(address => uint256)) private _balances;
mapping(address => mapping(address => bool)) private _operatorApprovals;
string private _uri;
constructor(string memory uri_) {
_setURI(uri_);
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
}
function uri(uint256) public view virtual override returns (string memory) {
return _uri;
}
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: balance query for the zero address");
return _balances[id][account];
}
function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
public
view
virtual
override
returns (uint256[] memory)
{
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not owner nor approved"
);
_safeTransferFrom(from, to, id, amount, data);
}
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
function _safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
function _mint(
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}
function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
function _burn(
address from,
uint256 id,
uint256 amount
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
emit TransferSingle(operator, from, address(0), id, amount);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
function _burnBatch(
address from,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
}
emit TransferBatch(operator, from, address(0), ids, amounts);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC1155: setting approval status for self");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _afterTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}
文件 4 的 14:ERC1155Supply.sol
pragma solidity ^0.8.0;
import "../ERC1155.sol";
abstract contract ERC1155Supply is ERC1155 {
mapping(uint256 => uint256) private _totalSupply;
function totalSupply(uint256 id) public view virtual returns (uint256) {
return _totalSupply[id];
}
function exists(uint256 id) public view virtual returns (bool) {
return ERC1155Supply.totalSupply(id) > 0;
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] += amounts[i];
}
}
if (to == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 supply = _totalSupply[id];
require(supply >= amount, "ERC1155: burn amount exceeds totalSupply");
unchecked {
_totalSupply[id] = supply - amount;
}
}
}
}
}
文件 5 的 14:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 6 的 14:IERC1155.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
文件 7 的 14:IERC1155MetadataURI.sol
pragma solidity ^0.8.0;
import "../IERC1155.sol";
interface IERC1155MetadataURI is IERC1155 {
function uri(uint256 id) external view returns (string memory);
}
文件 8 的 14:IERC1155Receiver.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155Receiver is IERC165 {
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
文件 9 的 14:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 10 的 14:MerkleProof.sol
pragma solidity ^0.8.0;
library MerkleProof {
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (computedHash <= proofElement) {
computedHash = _efficientHash(computedHash, proofElement);
} else {
computedHash = _efficientHash(proofElement, computedHash);
}
}
return computedHash;
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
文件 11 的 14:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
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);
}
}
文件 12 的 14:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
文件 13 的 14:Strings.sol
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);
}
}
文件 14 的 14:Wardobe.sol
pragma solidity ^0.8.2;
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
interface IMetamon {
function metamonOwnership(address owner, uint256 requiredMetamon)
external
returns (bool);
}
struct ItemTypeInfo {
uint256 itemPrice;
uint256 maxMintable;
uint256 itemSupply;
uint256[] requiredMetamon;
bytes32 itemMerkleRoot;
string uri;
bool valid;
}
contract Wardrobe is ERC1155Supply, Ownable, ReentrancyGuard {
using Strings for uint256;
IMetamon public metamonContract;
address payable public paymentContractAddress;
string public name;
string public symbol;
mapping(uint256 => ItemTypeInfo) itemTypes;
mapping(address => mapping(uint256 => uint256)) itemsMinted;
uint256 numberOfItemTypes;
event ItemMinted(address _receiver, uint256 _tokenId, uint256 _quantity);
event ItemsMinted(address _receiver, uint256[] _tokenId, uint256[] _quantity);
constructor()
payable
ERC1155(
"https://gateway.pinata.cloud/ipfs/INSERT_IPFS_HASH_HERE/{id}.json"
)
{
name = "Metamon Wardrobe Collection";
symbol = "Minimetamon-WC";
}
modifier itemTypeCheck(uint256 _itemType) {
require(itemTypes[_itemType].valid, "Item Type out of scope!");
_;
}
modifier itemTypesCheck(uint256[] memory _itemTypes) {
for (uint i = 0; i < _itemTypes.length; i++) {
require(
itemTypes[_itemTypes[i]].valid,
"Item Type is out of scope!"
);
}
_;
}
modifier maxMintableCheck(uint256 _itemType, uint256 _quantity) {
require(
itemsMinted[msg.sender][_itemType] + _quantity <=
itemTypes[_itemType].maxMintable,
"User is trying to mint more than allocated."
);
require(
totalSupply(_itemType) + _quantity <=
itemTypes[_itemType].itemSupply,
"User is trying to mint more than total supply."
);
_;
}
modifier requiredMetamonCheck(uint256 _itemType) {
uint256[] memory requiredMetamon = itemTypes[_itemType].requiredMetamon;
for (uint256 i = 0; i < requiredMetamon.length; i++) {
if (
!metamonContract.metamonOwnership(
msg.sender,
requiredMetamon[i]
)
) {
revert("Required metamon not owned by sender");
}
}
_;
}
modifier requiredMetamonChecks(uint256[] memory _itemTypes) {
for (uint i = 0; i < _itemTypes.length; i++) {
uint256[] memory _requiredMetamon = itemTypes[_itemTypes[i]].requiredMetamon;
for (uint256 j = 0; j < _requiredMetamon.length; j++) {
if (
!metamonContract.metamonOwnership(
msg.sender,
_requiredMetamon[j]
)
) {
revert("Required metamon not owned by sender");
}
}
}
_;
}
function addWardrobeItem(
uint256 _itemType,
uint256 _itemPrice,
uint256 _maxMintable,
uint256 _itemSupply,
uint256[] memory _requiredMetamon,
bytes32 _itemMerkleRoot,
string memory _uri
) external onlyOwner {
require(
!itemTypes[_itemType].valid,
"Item type ID has already been used"
);
itemTypes[_itemType] = ItemTypeInfo(
_itemPrice,
_maxMintable,
_itemSupply,
_requiredMetamon,
_itemMerkleRoot,
_uri,
true
);
numberOfItemTypes++;
}
function setWardrobeItemValid(uint256 _itemType, bool _valid)
external
onlyOwner
{
itemTypes[_itemType].valid = _valid;
}
function setItemPrice(uint256 _newPrice, uint256 _itemType)
external
onlyOwner
itemTypeCheck(_itemType)
{
itemTypes[_itemType].itemPrice = _newPrice;
}
function getItemPrice(uint256 _itemType)
public
view
itemTypeCheck(_itemType)
returns (uint256)
{
return itemTypes[_itemType].itemPrice;
}
function setMaxMintable(uint256 _maxMintable, uint256 _itemType)
external
onlyOwner
itemTypeCheck(_itemType)
{
itemTypes[_itemType].maxMintable = _maxMintable;
}
function getMaxMintable(uint256 _itemType)
public
view
itemTypeCheck(_itemType)
returns (uint256)
{
return itemTypes[_itemType].maxMintable;
}
function setItemSupply(uint256 _itemSupply, uint256 _itemType)
external
onlyOwner
itemTypeCheck(_itemType)
{
itemTypes[_itemType].itemSupply = _itemSupply;
}
function getItemSupply(uint256 _itemType)
public
view
itemTypeCheck(_itemType)
returns (uint256)
{
return itemTypes[_itemType].itemSupply;
}
function setRequiredMetamon(
uint256[] memory _requiredMetamon,
uint256 _itemType
) external onlyOwner itemTypeCheck(_itemType) {
itemTypes[_itemType].requiredMetamon = _requiredMetamon;
}
function getRequiredMetamon(uint256 _itemType)
public
view
itemTypeCheck(_itemType)
returns (uint256[] memory)
{
return itemTypes[_itemType].requiredMetamon;
}
function setMerkleRoot(bytes32 _newMerkleRoot, uint256 _itemType)
external
onlyOwner
{
itemTypes[_itemType].itemMerkleRoot = _newMerkleRoot;
}
function getMerkleRoot(uint256 _itemType)
external
view
onlyOwner
returns (bytes32)
{
return itemTypes[_itemType].itemMerkleRoot;
}
function totalItemTypes() public view returns (uint256) {
return numberOfItemTypes;
}
function setMetamonContractAddress(address _metamonContractAddress)
external
onlyOwner
{
metamonContract = IMetamon(_metamonContractAddress);
}
function setPaymentAddress(
address payable _contractAddress
) external onlyOwner {
paymentContractAddress = _contractAddress;
}
function getPaymentAddress() public view onlyOwner returns (address){
return paymentContractAddress;
}
function mintSale(uint256 _itemType, uint256 _quantity)
external
payable
itemTypeCheck(_itemType)
maxMintableCheck(_itemType, _quantity)
nonReentrant
{
require(
itemTypes[_itemType].itemMerkleRoot == 0,
"User is trying to mint a whitelisted item through incorrect function call."
);
require(
itemTypes[_itemType].requiredMetamon.length == 0,
"User is trying to mint a wardrobe item with metamon requirements - Claim only!"
);
require(
msg.value == itemTypes[_itemType].itemPrice * _quantity,
"Not enough ETH"
);
itemsMinted[msg.sender][_itemType] += _quantity;
_mint(msg.sender, _itemType, _quantity, "");
emit ItemMinted(msg.sender, _itemType, _quantity);
}
function mintMultipleSale(
uint256[] memory _itemTypes,
uint256[] memory _quantity
) external payable itemTypesCheck(_itemTypes) nonReentrant {
uint256 totalMintCost;
for (uint i = 0; i < _itemTypes.length; i++) {
require(
itemTypes[_itemTypes[i]].itemMerkleRoot == 0,
"User is trying to mint a whitelisted item through incorrect function call."
);
require(
itemsMinted[msg.sender][_itemTypes[i]] + _quantity[i] <=
itemTypes[_itemTypes[i]].maxMintable,
"User is trying to mint more than allocated."
);
require(
totalSupply(_itemTypes[i]) + _quantity[i] <=
itemTypes[_itemTypes[i]].itemSupply,
"User is trying to mint more than total supply."
);
require(
itemTypes[_itemTypes[i]].requiredMetamon.length == 0,
"User is trying to mint a wardrobe item with metamon requirements - Claim only!"
);
totalMintCost += itemTypes[_itemTypes[i]].itemPrice * _quantity[i];
}
require(msg.value == totalMintCost, "Not enough ETH to mint!");
for (uint i = 0; i < _itemTypes.length; i++) {
itemsMinted[msg.sender][_itemTypes[i]] += _quantity[i];
}
_mintBatch(msg.sender, _itemTypes, _quantity, "");
emit ItemsMinted(msg.sender, _itemTypes, _quantity);
}
function mintSpecialItem(
uint256 _itemType,
uint256 _quantity,
bytes32[] calldata _merkleProof
)
external
payable
itemTypeCheck(_itemType)
maxMintableCheck(_itemType, _quantity)
nonReentrant
{
require(
MerkleProof.verify(
_merkleProof,
itemTypes[_itemType].itemMerkleRoot,
keccak256(abi.encodePacked(msg.sender))
),
"Caller not whitelisted"
);
require(
itemTypes[_itemType].requiredMetamon.length == 0,
"User is trying to mint a wardrobe item with metamon requirements - Claim only!"
);
require(
msg.value == itemTypes[_itemType].itemPrice * _quantity,
"Not enough ETH"
);
itemsMinted[msg.sender][_itemType] += _quantity;
_mint(msg.sender, _itemType, _quantity, "");
emit ItemMinted(msg.sender, _itemType, _quantity);
}
function claimCollectionReward(uint256 _itemType, uint256 _quantity)
external
itemTypeCheck(_itemType)
maxMintableCheck(_itemType, _quantity)
requiredMetamonCheck(_itemType)
nonReentrant
{
require(
itemTypes[_itemType].itemMerkleRoot == 0,
"User is trying to mint a whitelisted item through incorrect function call."
);
require(itemTypes[_itemType].itemPrice == 0, "must be a free mint");
itemsMinted[msg.sender][_itemType] += _quantity;
_mint(msg.sender, _itemType, _quantity, "");
emit ItemMinted(msg.sender, _itemType, _quantity);
}
function happyEnding(
address _user,
uint256 _itemType,
uint256 _quantity
)
external
itemTypeCheck(_itemType)
nonReentrant
{
require(msg.sender == address(metamonContract), "Caller not valid");
require(
itemsMinted[_user][_itemType] + _quantity <=
itemTypes[_itemType].maxMintable,
"User is trying to mint more than allocated."
);
require(
totalSupply(_itemType) + _quantity <=
itemTypes[_itemType].itemSupply,
"User is trying to mint more than total supply."
);
itemsMinted[_user][_itemType] += _quantity;
_mint(_user, _itemType, _quantity, "");
emit ItemMinted(_user, _itemType, _quantity);
}
function uri(uint256 _itemType) public view override returns (string memory) {
return (itemTypes[_itemType].uri);
}
function setTokenUri(uint256 _itemType, string memory newUri)
external
onlyOwner
{
itemTypes[_itemType].uri = newUri;
}
function withdraw() external onlyOwner nonReentrant {
(bool success, ) = paymentContractAddress.call{
value: address(this).balance
}("");
require(success, "Transfer failed.");
}
}
{
"compilationTarget": {
"Wardobe.sol": "Wardrobe"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"payable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"_tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_quantity","type":"uint256"}],"name":"ItemMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_receiver","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"_tokenId","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"_quantity","type":"uint256[]"}],"name":"ItemsMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"},{"internalType":"uint256","name":"_itemPrice","type":"uint256"},{"internalType":"uint256","name":"_maxMintable","type":"uint256"},{"internalType":"uint256","name":"_itemSupply","type":"uint256"},{"internalType":"uint256[]","name":"_requiredMetamon","type":"uint256[]"},{"internalType":"bytes32","name":"_itemMerkleRoot","type":"bytes32"},{"internalType":"string","name":"_uri","type":"string"}],"name":"addWardrobeItem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"},{"internalType":"uint256","name":"_quantity","type":"uint256"}],"name":"claimCollectionReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"getItemPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"getItemSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"getMaxMintable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"getMerkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPaymentAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"getRequiredMetamon","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"uint256","name":"_itemType","type":"uint256"},{"internalType":"uint256","name":"_quantity","type":"uint256"}],"name":"happyEnding","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"metamonContract","outputs":[{"internalType":"contract IMetamon","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_itemTypes","type":"uint256[]"},{"internalType":"uint256[]","name":"_quantity","type":"uint256[]"}],"name":"mintMultipleSale","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"},{"internalType":"uint256","name":"_quantity","type":"uint256"}],"name":"mintSale","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"},{"internalType":"uint256","name":"_quantity","type":"uint256"},{"internalType":"bytes32[]","name":"_merkleProof","type":"bytes32[]"}],"name":"mintSpecialItem","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paymentContractAddress","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newPrice","type":"uint256"},{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"setItemPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemSupply","type":"uint256"},{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"setItemSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxMintable","type":"uint256"},{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"setMaxMintable","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_newMerkleRoot","type":"bytes32"},{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"setMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_metamonContractAddress","type":"address"}],"name":"setMetamonContractAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_contractAddress","type":"address"}],"name":"setPaymentAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_requiredMetamon","type":"uint256[]"},{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"setRequiredMetamon","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"},{"internalType":"string","name":"newUri","type":"string"}],"name":"setTokenUri","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"},{"internalType":"bool","name":"_valid","type":"bool"}],"name":"setWardrobeItemValid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalItemTypes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_itemType","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]