Address ERC1155 changes (#2267)
* Make holder fns public * Add context, remove msg.sender from check * Fix location of Holder arguments * Add beforeTransfer hook * Minor test improvements * Add ERC1155Burnable and tests * Add ERC1155Pausable * Add ERC1155PresetMinterPauser.sol * Add uri constructors * Improved revert reasons * Initial docs improvements * Add missing docs * Improve acceptance checks revert reasons * Apply suggestions from code review Co-authored-by: Francisco Giordano <frangio.1@gmail.com> * Remove note about 1155 preset uri in mint * Add rquirements to balanceOfBatch * Add note about URI and uri * Fix list in docs * Fix lint errors * Use natural sorting for API titles * Fix doc references * Escape {id} references to remove docgen warnings * Added intro docs, fixed links * Apply suggestions from code review Co-authored-by: Francisco Giordano <frangio.1@gmail.com> * Add changelog entry Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
104
contracts/presets/ERC1155PresetMinterPauser.sol
Normal file
104
contracts/presets/ERC1155PresetMinterPauser.sol
Normal file
@ -0,0 +1,104 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
import "../access/AccessControl.sol";
|
||||
import "../GSN/Context.sol";
|
||||
import "../token/ERC1155/ERC1155.sol";
|
||||
import "../token/ERC1155/ERC1155Burnable.sol";
|
||||
import "../token/ERC1155/ERC1155Pausable.sol";
|
||||
|
||||
/**
|
||||
* @dev {ERC1155} token, including:
|
||||
*
|
||||
* - ability for holders to burn (destroy) their tokens
|
||||
* - a minter role that allows for token minting (creation)
|
||||
* - a pauser role that allows to stop all token transfers
|
||||
*
|
||||
* This contract uses {AccessControl} to lock permissioned functions using the
|
||||
* different roles - head to its documentation for details.
|
||||
*
|
||||
* The account that deploys the contract will be granted the minter and pauser
|
||||
* roles, as well as the default admin role, which will let it grant both minter
|
||||
* and pauser roles to other accounts.
|
||||
*/
|
||||
contract ERC1155PresetMinterPauser is Context, AccessControl, ERC1155Burnable, ERC1155Pausable {
|
||||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
|
||||
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
|
||||
|
||||
/**
|
||||
* @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE`, and `PAUSER_ROLE` to the account that
|
||||
* deploys the contract.
|
||||
*/
|
||||
constructor(string memory uri) public ERC1155(uri) {
|
||||
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
|
||||
|
||||
_setupRole(MINTER_ROLE, _msgSender());
|
||||
_setupRole(PAUSER_ROLE, _msgSender());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Creates `amount` new tokens for `to`, of token type `id`.
|
||||
*
|
||||
* See {ERC1155-_mint}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - the caller must have the `MINTER_ROLE`.
|
||||
*/
|
||||
function mint(address to, uint256 id, uint256 amount, bytes memory data) public virtual {
|
||||
require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint");
|
||||
|
||||
_mint(to, id, amount, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] variant of {mint}.
|
||||
*/
|
||||
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public virtual {
|
||||
require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint");
|
||||
|
||||
_mintBatch(to, ids, amounts, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Pauses all token transfers.
|
||||
*
|
||||
* See {ERC1155Pausable} and {Pausable-_pause}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - the caller must have the `PAUSER_ROLE`.
|
||||
*/
|
||||
function pause() public virtual {
|
||||
require(hasRole(PAUSER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have pauser role to pause");
|
||||
_pause();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Unpauses all token transfers.
|
||||
*
|
||||
* See {ERC1155Pausable} and {Pausable-_unpause}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - the caller must have the `PAUSER_ROLE`.
|
||||
*/
|
||||
function unpause() public virtual {
|
||||
require(hasRole(PAUSER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have pauser role to unpause");
|
||||
_unpause();
|
||||
}
|
||||
|
||||
function _beforeTokenTransfer(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256[] memory ids,
|
||||
uint256[] memory amounts,
|
||||
bytes memory data
|
||||
)
|
||||
internal virtual override(ERC1155, ERC1155Pausable)
|
||||
{
|
||||
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ import "../token/ERC20/ERC20Pausable.sol";
|
||||
*
|
||||
* The account that deploys the contract will be granted the minter and pauser
|
||||
* roles, as well as the default admin role, which will let it grant both minter
|
||||
* and pauser roles to other accounts
|
||||
* and pauser roles to other accounts.
|
||||
*/
|
||||
contract ERC20PresetMinterPauser is Context, AccessControl, ERC20Burnable, ERC20Pausable {
|
||||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
|
||||
|
||||
@ -22,7 +22,7 @@ import "../token/ERC721/ERC721Pausable.sol";
|
||||
*
|
||||
* The account that deploys the contract will be granted the minter and pauser
|
||||
* roles, as well as the default admin role, which will let it grant both minter
|
||||
* and pauser roles to other accounts
|
||||
* and pauser roles to other accounts.
|
||||
*/
|
||||
contract ERC721PresetMinterPauserAutoId is Context, AccessControl, ERC721Burnable, ERC721Pausable {
|
||||
using Counters for Counters.Counter;
|
||||
|
||||
@ -11,3 +11,5 @@ TIP: Intermediate and advanced users can use these as starting points when writi
|
||||
{{ERC20PresetMinterPauser}}
|
||||
|
||||
{{ERC721PresetMinterPauserAutoId}}
|
||||
|
||||
{{ERC1155PresetMinterPauser}}
|
||||
|
||||
Reference in New Issue
Block a user