/**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has creator and mint functionality,
* and supports useful standards from OpenZeppelin,
* like _exists(), name(), symbol(), and totalSupply()
*/
contract ERC1155Tradable is ContextMixin, ERC1155, NativeMetaTransaction, Ownable {
using Strings for uint256;
using SafeMath for uint256;
address public proxyRegistryAddress;
address public minterAddress;
mapping(uint256 => address) public creators;
mapping(uint256 => uint256) public tokenSupply;
mapping(uint256 => uint256) public maxSupply;
mapping(uint256 => string) private customUri;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Event emit when new token created
* @param creator address of the first owner of the token
* @param initialOwner address of the first owner of the token
* @param id The id of the token to create (must not currenty exist).
* @param initialSupply amount to supply the first owner
* @param maxSupply max supply of the new token
* @param uri Optional URI for this token type
*/
event CreatedSingle(
uint256 id,
address creator,
address initialOwner,
uint256 initialSupply,
uint256 maxSupply,
string uri
);
/**
* @dev Require _msgSender() to be the creator of the token id
*/
modifier onlyCreator(uint256 _id) {
require(creators[_id] == _msgSender(), "ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require _msgSender() to be the creator of the token id or minter
*/
modifier onlyMinable(uint256 _id) {
require(creators[_id] == _msgSender() || minterAddress == _msgSender(), "ONLY_CREATOR_OR_MINTER_ALLOWED");
_;
}
/**
* @dev Require _msgSender() to own more than 0 of the token id
*/
modifier onlyHolder(uint256 _id) {
require(balanceOf(_msgSender(), _id) > 0, "ONLY_HOLDER_ALLOWED");
_;
}
function setMinter(address _minterAddress) public onlyOwner {
minterAddress = _minterAddress;
}
function setProxy(address _proxyAddress) public onlyOwner {
proxyRegistryAddress = _proxyAddress;
}
Assistant
The contract does not properly check for the existence of an operator address before allowing it to be whitelisted.
The contract does not have any restrictions on who can be set as the minter or proxy, allowing anyone to potentially gain control over the contract.
The contract does not have any safeguards against the unauthorized creation of new tokens.
The contract does not have any limits on the total supply of tokens that can be created.
The contract does not properly check for the existence of a given token before allowing operations on it.
The contract does not properly check for the ownership of a given token before allowing operations on it.
function uri(uint256 _id) public view override returns (string memory) {
require(_exists(_id), "ERC1155Tradable#uri: NONEXISTENT_TOKEN");
// We have to convert string to bytes to check for existence
bytes memory customUriBytes = bytes(customUri[_id]);
if (customUriBytes.length > 0) {
return customUri[_id];
} else {
return string(abi.encodePacked(super.uri(_id), _id.toString()));
}
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(uint256 _id) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Sets a new URI for all token types, by relying on the token type ID
* substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
* @param _newURI New URI for all tokens
*/
function setURI(string memory _newURI) public onlyOwner {
_setURI(_newURI);
}
/**
* @dev Will update the base URI for the token
* @param _tokenId The token to update. _msgSender() must be its creator.
* @param _newURI New URI for the token.
*/
function setCustomURI(uint256 _tokenId, string memory _newURI) public onlyCreator(_tokenId) {
customUri[_tokenId] = _newURI;
emit URI(_newURI, _tokenId);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on
* your contract (which may change your IDs)
* NOTE: The token id must be passed. This allows lazy creation of tokens or
* creating NFTs by setting the id's high bits with the method
* described in ERC1155 or to use ids representing values other than
* successive small integers. If you wish to create ids as successive
* small integers you can either subclass this class to count onchain
* or maintain the offchain cache of identifiers recommended in
* ERC1155 and calculate successive ids from that.
* @param _initialOwner address of the first owner of the token
* @param _id The id of the token to create (must not currenty exist).
* @param _initialSupply amount to supply the first owner
* @param _maxSupply max supply of the new token
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return mewToken The newly created token ID
*/
function create(
address _initialOwner,
uint256 _id,
uint256 _initialSupply,
uint256 _maxSupply,
address _creator,
string memory _uri,
bytes memory _data
) public onlyMinter returns (uint256) {
require(!_exists(_id), "token _id already exists");
require(_initialSupply <= _maxSupply || _maxSupply == 0, "ERC1155Tradable#create: maxSupply limit exceeded");
creators[_id] =_creator;
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public virtual onlyMinable(_id) {
require(
tokenSupply[_id].add(_quantity) <= maxSupply[_id] || maxSupply[_id] == 0,
"MAXSUPPLY_LIMIT_EXCEEDED"
);
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == _msgSender(), "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_mintBatch(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(address _to, uint256[] memory _ids) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* get creator of tokenId
*/
function getCreator(uint256 _id) public view returns (address creator) {
return creators[_id];
}
/**
* check weather operator is able to mint
*/
function canMint(address _operator, uint256 _id) public view returns (bool isOperator) {
require(address(0) != _operator, "INVALID_OPERATOR");
require(_exists(_id), "TOKEN_NOT_EXITS");
return creators[_id] == _operator;
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(address _owner, address _operator) public view override returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal onlyCreator(_id) {
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(uint256 _id) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* This is used instead of msg.sender as transactions won't be sent by the original token owner, but by OpenSea.
*/
function _msgSender() internal view override returns (address sender) {
return ContextMixin.msgSender();
}
}
The contract does not properly check for the authorization of the minter or creator before allowing minting or creation of new tokens.
The contract does not properly handle overflows or underflows in its mathematical operations.
The contract's constructor and setter functions are not marked as "internal" or "private", allowing them to be called by any external contract.
The contract's event emissions do not include all relevant information, potentially leading to incomplete or inaccurate data.
The contract does not have any mechanism for revoking the minter or creator privileges of a given address.
The contract does not have any mechanism for updating the URI of a given token.
The contract does not properly validate the inputs to its functions, potentially allowing for malicious attacks.
The contract does not have any mechanism for enforcing a minimum or maximum amount of tokens that can be transferred in a single transaction.
The contract does not have any mechanism for ensuring the correctness of its internal data structures, potentially leading to inconsistencies or errors.
The contract does not properly handle the case where the proxy registry address is unset or invalid.