communities-contracts/contracts/tokens/CommunityERC20.sol

75 lines
2.2 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;
2023-10-03 07:06:10 +00:00
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Context } from "@openzeppelin/contracts/utils/Context.sol";
import { CommunityOwnable } from "../CommunityOwnable.sol";
2023-06-12 11:24:47 +00:00
contract CommunityERC20 is Context, Ownable, ERC20, CommunityOwnable {
error CommunityERC20_MaxSupplyLowerThanTotalSupply();
error CommunityERC20_MaxSupplyReached();
error CommunityERC20_MismatchingAddressesAndAmountsLengths();
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;
uint8 private immutable customDecimals;
2023-06-23 08:53:08 +00:00
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,
uint256 _maxSupply,
address _ownerToken,
address _masterToken
)
ERC20(_name, _symbol)
CommunityOwnable(_ownerToken, _masterToken)
{
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 onlyCommunityOwnerOrTokenMaster {
if (newMaxSupply < totalSupply()) {
revert CommunityERC20_MaxSupplyLowerThanTotalSupply();
}
2023-06-12 11:24:47 +00:00
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 onlyCommunityOwnerOrTokenMaster {
if (addresses.length != amounts.length) {
revert CommunityERC20_MismatchingAddressesAndAmountsLengths();
}
2023-06-12 11:27:56 +00:00
2023-06-12 11:24:47 +00:00
for (uint256 i = 0; i < addresses.length; i++) {
uint256 amount = amounts[i];
if (totalSupply() + amount > maxSupply) {
revert CommunityERC20_MaxSupplyReached();
}
2023-06-12 11:24:47 +00:00
_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
}