Skip to content

Commit

Permalink
add ERC20UpgradeableToken contract
Browse files Browse the repository at this point in the history
  • Loading branch information
thurendous committed Aug 26, 2024
1 parent 2b21805 commit 745aab0
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/ERC20UpgradeableToken.sol
Original file line number Diff line number Diff line change
@@ -1 +1,88 @@
// SPDX-License-Identifier: BUSL-1.1
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity 0.8.24;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

/// @custom:security-contact [email protected]
contract ERC20UpgradeableToken is
Initializable,
ERC20Upgradeable,
ERC20BurnableUpgradeable,
ERC20PausableUpgradeable,
AccessControlUpgradeable,
ERC20PermitUpgradeable,
UUPSUpgradeable
{
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(
string memory name,
string memory symbol,
address defaultAdmin,
address pauser,
address minter,
address burner,
address upgrader
) public initializer {
__ERC20_init(name, symbol);
__ERC20Burnable_init();
__ERC20Pausable_init();
__AccessControl_init();
__ERC20Permit_init(name);
__UUPSUpgradeable_init();

_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
_grantRole(PAUSER_ROLE, pauser);
_grantRole(MINTER_ROLE, minter);
_grantRole(MINTER_ROLE, burner);
_grantRole(UPGRADER_ROLE, upgrader);
}

function pause() public onlyRole(PAUSER_ROLE) {
_pause();
}

function unpause() public onlyRole(PAUSER_ROLE) {
_unpause();
}

function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) {
_mint(to, amount);
}

/**
* @notice Burns a specific amount of tokens from a specified account.
* @dev This function can only be called by accounts with the BURNER_ROLE.
* @param account The address from which the tokens will be burned.
* @param amount The amount of tokens to burn.
*/
function burnFrom(address account, uint256 amount) public override onlyRole(BURNER_ROLE) {
_burn(account, amount);
}

function _authorizeUpgrade(address newImplementation) internal override onlyRole(UPGRADER_ROLE) {}

// The following functions are overrides required by Solidity.

function _update(address from, address to, uint256 value)
internal
override(ERC20Upgradeable, ERC20PausableUpgradeable)
{
super._update(from, to, value);
}
}

0 comments on commit 745aab0

Please sign in to comment.