-
Notifications
You must be signed in to change notification settings - Fork 23
/
ERC20MintModule.sol
85 lines (78 loc) · 3.01 KB
/
ERC20MintModule.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "../../security/AuthorizationModule.sol";
import "../../../interfaces/ICCIPToken.sol";
/**
* @title ERC20Mint module.
* @dev
*
* Contains all mint functions, inherits from ERC-20
*/
abstract contract ERC20MintModule is ERC20Upgradeable, ICCIPMintERC20, AuthorizationModule {
/* ============ State Variables ============ */
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
/* ============ Events ============ */
/**
* @notice Emitted when the specified `value` amount of new tokens are created and
* allocated to the specified `account`.
*/
event Mint(address indexed account, uint256 value);
/* ============ Initializer Function ============ */
function __ERC20MintModule_init_unchained() internal onlyInitializing {
// no variable to initialize
}
/*//////////////////////////////////////////////////////////////
PUBLIC/EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0)
* @param account token receiver
* @param value amount of tokens
* @dev
* See {OpenZeppelin ERC20-_mint}.
* Emits a {Mint} event.
* Emits a {Transfer} event with `from` set to the zero address (emits inside _mint).
*
* Requirements:
* - `account` cannot be the zero address (check made by _mint).
* - The caller must have the `MINTER_ROLE`.
*/
function mint(address account, uint256 value) public onlyRole(MINTER_ROLE) {
_mint(account, value);
emit Mint(account, value);
}
/**
*
* @notice batch version of {mint}
* @dev
* See {OpenZeppelin ERC20-_mint} and {OpenZeppelin ERC1155_mintBatch}.
*
* For each mint action:
* - Emits a {Mint} event.
* - Emits a {Transfer} event with `from` set to the zero address (emits inside _mint).
*
* Requirements:
* - `accounts` and `values` must have the same length
* - `accounts` cannot contain a zero address (check made by _mint).
* - the caller must have the `MINTER_ROLE`.
*/
function mintBatch(
address[] calldata accounts,
uint256[] calldata values
) public onlyRole(MINTER_ROLE) {
if (accounts.length == 0) {
revert Errors.CMTAT_MintModule_EmptyAccounts();
}
// We do not check that values is not empty since
// this require will throw an error in this case.
if (bool(accounts.length != values.length)) {
revert Errors.CMTAT_MintModule_AccountsValueslengthMismatch();
}
// No need of unchecked block since Soliditiy 0.8.22
for (uint256 i = 0; i < accounts.length; ++i ) {
_mint(accounts[i], values[i]);
emit Mint(accounts[i], values[i]);
}
}
}