communities-contracts/contracts/tokens/CommunityERC20.sol

61 lines
1.6 KiB
Solidity
Raw Normal View History

2023-06-12 11:24:47 +00:00
// SPDX-License-Identifier: Mozilla Public License 2.0
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/Context.sol";
contract CommunityERC20 is Context, Ownable, ERC20 {
2023-06-12 11:24:47 +00:00
/**
* If we want unlimited total supply we should set maxSupply to 2^256-1.
*/
uint256 public maxSupply;
2023-06-23 08:53:08 +00:00
uint8 private customDecimals;
2023-06-12 11:24:47 +00:00
constructor(
string memory _name,
string memory _symbol,
2023-06-23 08:53:08 +00:00
uint8 _decimals,
2023-06-12 11:24:47 +00:00
uint256 _maxSupply
)
ERC20(_name, _symbol)
{
2023-06-12 11:24:47 +00:00
maxSupply = _maxSupply;
2023-06-23 08:53:08 +00:00
customDecimals = _decimals;
2023-06-12 11:24:47 +00:00
}
// Events
// External functions
function setMaxSupply(uint256 newMaxSupply) external onlyOwner {
require(newMaxSupply >= totalSupply(), "MAX_SUPPLY_LOWER_THAN_TOTAL_SUPPLY");
maxSupply = newMaxSupply;
}
/**
* @dev Mint tokens for each address in `addresses` each one with
* an amount specified in `amounts`.
*
*/
function mintTo(address[] memory addresses, uint256[] memory amounts) external onlyOwner {
2023-06-12 11:27:56 +00:00
require(addresses.length == amounts.length, "WRONG_LENGTHS");
2023-06-12 11:24:47 +00:00
for (uint256 i = 0; i < addresses.length; i++) {
uint256 amount = amounts[i];
require(totalSupply() + amount <= maxSupply, "MAX_SUPPLY_REACHED");
_mint(addresses[i], amount);
}
}
// Public functions
2023-06-23 08:53:08 +00:00
function decimals() public view virtual override returns (uint8) {
return customDecimals;
}
2023-06-12 11:24:47 +00:00
// Internal functions
// Private functions
}