Tokens Contract#
LLA Token#
Contract Overview#
LLA Token is an upgradeable ERC20 token contract based on OpenZeppelin, supporting the following core functions:
Role-based Access Control: Manages ADMIN_ROLE, PAUSER_ROLE, MINTER_ROLE, UPGRADER_ROLE through AccessControl
Upgradeability: Implements secure upgrades through UUPS pattern
Token Pausability: Supports global pause/unpause of token transfers
Token Minting and Burning: Supports controlled minting and burning
Fixed Total Supply: Set total supply at 100,000,000 LLA
Core Variables and Configuration#
Role Definitions#
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
Other Configurations#
string public constant version = "v1.0";
uint256 public constant TOTAL_SUPPLY = 100_0000_0000 * 1e18; // 100,000,000 LLA
Core Functions Explained#
1. Initialization Function#
function initialize(
address defaultAdmin,
address pauser,
address minter,
address upgrader
) public initializer {
if (defaultAdmin == address(0)) revert InvalidAddress(defaultAdmin);
// ... other address validations
__ERC20_init("LLA", "LLA");
__ERC20Burnable_init();
__ERC20Pausable_init();
__AccessControl_init();
__UUPSUpgradeable_init();
_grantRole(ADMIN_ROLE, defaultAdmin);
_grantRole(PAUSER_ROLE, pauser);
_grantRole(MINTER_ROLE, minter);
_grantRole(UPGRADER_ROLE, upgrader);
}
Purpose: Initialize contract and assign roles
Key Points:
Validate all address legitimacy
Initialize parent contracts (ERC20, Access Control, Upgradeable)
Grant initial role permissions
2. Token Minting#
function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) {
if (amount == 0) revert InvalidAmount(amount);
if (to == address(0)) revert InvalidAddress(to);
_mint(to, amount);
}
Purpose: Mint new tokens
Restrictions:
Only callable by MINTER_ROLE
Prevent minting to zero address or zero amount
3. Pause and Unpause#
function pause() public onlyRole(PAUSER_ROLE) {
_pause();
}
function unpause() public onlyRole(PAUSER_ROLE) {
_unpause();
}
Purpose: Global pause/unpause of token transfers
Impact:
No transfers or approvals during pause
4. Token Burning#
function burn(uint256 amount) public override {
if (amount == 0) revert InvalidAmount(amount);
_burn(msg.sender, amount);
}
Purpose: Burn user’s own tokens
Enhancement:
Validate burn amount is not zero
5. Upgrade Control#
function _authorizeUpgrade(
address _newImplementation
) internal view override onlyRole(UPGRADER_ROLE) {
if (_newImplementation == address(0)) revert InvalidAddress(_newImplementation);
}
Purpose: Authorize upgrade to new implementation contract
Restrictions:
Only callable by UPGRADER_ROLE
Prevent upgrade to zero address
6. Role Management#
function addRole(bytes32 role, address account) external onlyRole(ADMIN_ROLE) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public override onlyRole(ADMIN_ROLE) {
_revokeRole(role, account);
}
Purpose: Admin management of role permissions
Permissions:
Only ADMIN_ROLE can add/revoke roles
7. Custom Errors#
error InvalidAddress(address addr);
error InvalidAmount(uint amount);
Usage: Enhance error message readability
Function Workflows#
Scenario: Minting and Distributing Tokens#
Deploy contract and call initialize function:
LLAToken.initialize(admin, pauser, minter, upgrader);
Call mint function to mint tokens:
LLAToken.mint(userAddress, 1000 * 1e18); // Mint 1000 LLA
Scenario: Pausing Token Trading#
Call pause function to pause contract:
LLAToken.pause(); // Must be called by PAUSER_ROLE
No transfers or approvals possible during pause
Events and Errors#
Events#
ERC20 Standard Events: Transfer, Approval
Access Control Events: RoleGranted, RoleRevoked
Errors#
error InvalidAddress(address addr);
error InvalidAmount(uint amount);
LLAX Token#
Contract Overview#
LLAXToken is an ERC20 token based on the OpenZeppelin upgradeable contract, supporting upgradability, pausing, burning, and role-based access control.
The contract uses multi-role permission management and is suitable for mainstream DeFi, DAO, and Web3 project scenarios.
Main Features#
Upgradeable: UUPS upgrade pattern
Access Control: Multi-role permission management based on AccessControl
Pausable: Supports emergency pause/resume
Burnable: Supports token burning
Total Supply Cap: Maximum supply limit
Events & Errors: Custom errors and events for tracking and debugging
Role Description#
Role Name |
Identifier |
Permission Description |
---|---|---|
Admin |
ADMIN_ROLE |
Grant/revoke roles, manage contract |
Pauser |
PAUSER_ROLE |
Pause/resume the contract |
Minter |
MINTER_ROLE |
Mint new tokens |
Upgrader |
UPGRADER_ROLE |
Upgrade the contract |
Constants#
string public constant version = “v1.0”; Contract version
uint256 public constant TOTAL_SUPPLY = 6_5000_0000 * 1e18; Maximum token supply (650 million)
Custom Errors#
InvalidAddress(address addr) Thrown when an invalid address is provided
InvalidAmount(uint amount) Thrown when an invalid amount is provided
Main Functions#
Initialization#
function initialize(
address defaultAdmin,
address pauser,
address minter,
address upgrader
) public initializer
Initializes the contract, assigns roles, and sets token name and symbol.
Pause and Resume#
function pause() public onlyRole(PAUSER_ROLE)
function unpause() public onlyRole(PAUSER_ROLE)
Only callable by PAUSER_ROLE, pauses/resumes all transfer-related operations.
Minting and Burning#
function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE)
function burn(uint256 amount) public override
mint: Only callable by MINTER_ROLE, mints new tokens to the specified address, and will not exceed the maximum supply.
burn: Burns tokens from the caller’s account.
Role Management#
function addRole(bytes32 role, address account) external onlyRole(ADMIN_ROLE)
function revokeRole(bytes32 role, address account) public override onlyRole(ADMIN_ROLE)
Admin can assign/revoke roles for any address.
Approve Operation#
function approve(address spender, uint256 amount) public override whenNotPaused returns (bool)
Can only approve when not paused.
Internal Methods#
function _update(address from, address to, uint256 value) internal override(ERC20Upgradeable, ERC20PausableUpgradeable)
Handles internal state updates during transfers, compatible with pause logic.
Security Notes#
All sensitive operations are permission-controlled
Minting, burning, and upgrading are strictly checked
Supports contract pausing for emergency handling
Hard cap on total supply to prevent over-issuance
Deployment and Upgrade#
Recommended to use OpenZeppelin Upgrades plugin for deployment and upgrade
Initialization parameters must provide all role addresses and none can be zero address
Typical Usage Examples#
// Mint tokens
llaxToken.mint(user, 1000 * 1e18);
// Burn tokens
llaxToken.burn(500 * 1e18);
// Pause the contract
llaxToken.pause();
// Grant role
llaxToken.addRole(llaxToken.MINTER_ROLE(), newMinter);
Version Info#
Contract version: v1.0
Compatible with OpenZeppelin Contracts ^5.0.0
Solidity version: ^0.8.28
License#
MIT License