mirror of
https://github.com/luxfi/uma.git
synced 2026-07-27 05:11:41 +00:00
96 lines
3.0 KiB
Solidity
96 lines
3.0 KiB
Solidity
// SPDX-License-Identifier: AGPL-3.0-only
|
|
pragma solidity ^0.8.0;
|
|
|
|
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
import "./MultiRole.sol";
|
|
import "../interfaces/ExpandedIERC20.sol";
|
|
|
|
/**
|
|
* @title An ERC20 with permissioned burning and minting. The contract deployer will initially
|
|
* be the owner who is capable of adding new roles.
|
|
*/
|
|
contract ExpandedERC20 is ExpandedIERC20, ERC20, MultiRole {
|
|
enum Roles {
|
|
// Can set the minter and burner.
|
|
Owner,
|
|
// Addresses that can mint new tokens.
|
|
Minter,
|
|
// Addresses that can burn tokens that address owns.
|
|
Burner
|
|
}
|
|
|
|
uint8 _decimals;
|
|
|
|
/**
|
|
* @notice Constructs the ExpandedERC20.
|
|
* @param _tokenName The name which describes the new token.
|
|
* @param _tokenSymbol The ticker abbreviation of the name. Ideally < 5 chars.
|
|
* @param _tokenDecimals The number of decimals to define token precision.
|
|
*/
|
|
constructor(
|
|
string memory _tokenName,
|
|
string memory _tokenSymbol,
|
|
uint8 _tokenDecimals
|
|
) ERC20(_tokenName, _tokenSymbol) {
|
|
_decimals = _tokenDecimals;
|
|
_createExclusiveRole(uint256(Roles.Owner), uint256(Roles.Owner), msg.sender);
|
|
_createSharedRole(uint256(Roles.Minter), uint256(Roles.Owner), new address[](0));
|
|
_createSharedRole(uint256(Roles.Burner), uint256(Roles.Owner), new address[](0));
|
|
}
|
|
|
|
function decimals() public view virtual override(ERC20) returns (uint8) {
|
|
return _decimals;
|
|
}
|
|
|
|
/**
|
|
* @dev Mints `value` tokens to `recipient`, returning true on success.
|
|
* @param recipient address to mint to.
|
|
* @param value amount of tokens to mint.
|
|
* @return True if the mint succeeded, or False.
|
|
*/
|
|
function mint(address recipient, uint256 value)
|
|
external
|
|
override
|
|
onlyRoleHolder(uint256(Roles.Minter))
|
|
returns (bool)
|
|
{
|
|
_mint(recipient, value);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @dev Burns `value` tokens owned by `msg.sender`.
|
|
* @param value amount of tokens to burn.
|
|
*/
|
|
function burn(uint256 value) external override onlyRoleHolder(uint256(Roles.Burner)) {
|
|
_burn(msg.sender, value);
|
|
}
|
|
|
|
/**
|
|
* @notice Add Minter role to account.
|
|
* @dev The caller must have the Owner role.
|
|
* @param account The address to which the Minter role is added.
|
|
*/
|
|
function addMinter(address account) external virtual override {
|
|
addMember(uint256(Roles.Minter), account);
|
|
}
|
|
|
|
/**
|
|
* @notice Add Burner role to account.
|
|
* @dev The caller must have the Owner role.
|
|
* @param account The address to which the Burner role is added.
|
|
*/
|
|
function addBurner(address account) external virtual override {
|
|
addMember(uint256(Roles.Burner), account);
|
|
}
|
|
|
|
/**
|
|
* @notice Reset Owner role to account.
|
|
* @dev The caller must have the Owner role.
|
|
* @param account The new holder of the Owner role.
|
|
*/
|
|
function resetOwner(address account) external virtual override {
|
|
resetMember(uint256(Roles.Owner), account);
|
|
}
|
|
}
|