Mater Smart Contract Code

Contract 0x5B4B330C5488Cbde25F0740C8DAB73CE44e950A8

/**
 *Submitted for verification at Etherscan.io on 2023-09-23
*/

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

contract Ownable {
    address private _owner;
    
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    
    constructor() {
        _owner = msg.sender;
        emit OwnershipTransferred(address(0), _owner);
    }
    
    modifier onlyOwner() {
        require(msg.sender == _owner, "Ownable: caller is not the owner");
        _;
    }
    
    function owner() public view returns (address) {
        return _owner;
    }
    
    function renounceOwnership() public onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }
    
    function transferOwnership(address newOwner) public onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

contract MaterToken is IERC20, Ownable {
    string public name = "Mater";
    string public symbol = "MATER";
    uint8 public decimals = 18;
    uint256 private _totalSupply;
    address public feeAddress;
    uint256 public maxTransferFeeRate = 2;
    uint256 public maxBurnFeeRate = 2;
    uint256 public maxTransferAmount = 10000000000 * 10**uint256(decimals);
    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;
    mapping(address => bool) public isExcludedFromFees;
    uint256 public transferFeeRate = 2;
    uint256 public burnFeeRate = 1;
    uint256 public globalMaxBalance; // Global maximum balance limit for all addresses
    mapping(address => bool) public isExcludedFromMaxBalance; // Addresses excluded from global maximum balance limit

    constructor(uint256 initialSupply, address _feeAddress) {
        _totalSupply = initialSupply * 10**uint256(decimals);
        _balances[msg.sender] = _totalSupply;
        feeAddress = _feeAddress;
        emit Transfer(address(0), msg.sender, _totalSupply);
    }

    function totalSupply() public view override returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address account) public view override returns (uint256) {
        return _balances[account];
    }

    function transfer(address recipient, uint256 amount) public override returns (bool) {
        require(amount <= maxTransferAmount, "Amount exceeds maximum transfer amount");
        require(_balances[msg.sender] >= amount, "ERC20: transfer amount exceeds balance");
        uint256 fee = (amount * transferFeeRate) / 100;
        uint256 burnAmount = (amount * burnFeeRate) / 100;
        uint256 transferAmount = amount - fee;
        
        require(recipient != address(0), "ERC20: transfer to the zero address");
        require(fee <= (amount * maxTransferFeeRate) / 100, "Transfer fee exceeds maximum");
        require(burnAmount <= (amount * maxBurnFeeRate) / 100, "Burn fee exceeds maximum");

        // Check if recipient's balance plus transferAmount exceeds the global maximum balance limit
        require(_balances[recipient] + transferAmount <= globalMaxBalance, "Recipient's balance would exceed the maximum allowed");

        _balances[msg.sender] -= amount;
        _balances[recipient] += transferAmount;
        _burn(msg.sender, burnAmount);
        _transferFee(fee);
        emit Transfer(msg.sender, recipient, transferAmount);
        return true;
    }

    function allowance(address owner, address spender) public view override returns (uint256) {
        return _allowances[owner][spender];
    }

    function approve(address spender, uint256 amount) public override returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }

    function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
        require(amount <= maxTransferAmount, "Amount exceeds maximum transfer amount");
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");
        require(_balances[sender] >= amount, "ERC20: transfer amount exceeds balance");
        require(_allowances[sender][msg.sender] >= amount, "ERC20: transfer amount exceeds allowance");
        uint256 fee = (amount * transferFeeRate) / 100;
        uint256 burnAmount = (amount * burnFeeRate) / 100;
        uint256 transferAmount = amount - fee;

        require(fee <= (amount * maxTransferFeeRate) / 100, "Transfer fee exceeds maximum");
        require(burnAmount <= (amount * maxBurnFeeRate) / 100, "Burn fee exceeds maximum");

        // Check if recipient's balance plus transferAmount exceeds the global maximum balance limit
        require(_balances[recipient] + transferAmount <= globalMaxBalance, "Recipient's balance would exceed the maximum allowed");

        _balances[sender] -= amount;
        _balances[recipient] += transferAmount;
        _burn(sender, burnAmount);
        _transferFee(fee);
        _approve(sender, msg.sender, _allowances[sender][msg.sender] - amount);
        emit Transfer(sender, recipient, transferAmount);
        return true;
    }

    function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
        _approve(msg.sender, spender, _allowances[msg.sender][spender] + addedValue);
        return true;
    }

    function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
        uint256 currentAllowance = _allowances[msg.sender][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        _approve(msg.sender, spender, currentAllowance - subtractedValue);
        return true;
    }

    function _approve(address owner, address spender, uint256 amount) internal {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");
        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    function _burn(address account, uint256 amount) internal {
        require(account != address(0), "ERC20: burn from the zero address");
        require(_balances[account] >= amount, "ERC20: burn amount exceeds balance");
        _totalSupply -= amount;
        _balances[account] -= amount;
        emit Transfer(account, address(0), amount);
    }

    function _transferFee(uint256 fee) internal {
        require(feeAddress != address(0), "Fee address not set");
        _balances[feeAddress] += fee;
        emit Transfer(msg.sender, feeAddress, fee);
    }

    function setTransferFeeRate(uint256 newFeeRate) public onlyOwner {
        require(newFeeRate <= 2, "Fee rate cannot exceed 2%");
        transferFeeRate = newFeeRate;
    }

    function setBurnFeeRate(uint256 newBurnFeeRate) public onlyOwner {
        require(newBurnFeeRate <= 2, "Burn fee rate cannot exceed 2%");
        burnFeeRate = newBurnFeeRate;
    }

    function setFeeAddress(address newFeeAddress) public onlyOwner {
        require(newFeeAddress != address(0), "Fee address cannot be the zero address");
        feeAddress = newFeeAddress;
    }

    function excludeFromFees(address account) public onlyOwner {
        isExcludedFromFees[account] = true;
    }

    function includeInFees(address account) public onlyOwner {
        isExcludedFromFees[account] = false;
    }

    function setMaxTransferAmount(uint256 newMaxTransferAmount) public onlyOwner {
        maxTransferAmount = newMaxTransferAmount;
    }

    function setGlobalMaxBalance(uint256 newGlobalMaxBalance) public onlyOwner {
        globalMaxBalance = newGlobalMaxBalance;
    }

    function excludeFromMaxBalance(address account) public onlyOwner {
        isExcludedFromMaxBalance[account] = true;
    }

    function includeInMaxBalance(address account) public onlyOwner {
        isExcludedFromMaxBalance[account] = false;
    }
}

Certainly, here's a detailed explanation of the MaterToken contract:

  1. Token Information:

    • name: "Mater" - The name of the token.

    • symbol: "MATER" - The symbol of the token.

    • decimals: 18 - The number of decimal places used for the token, allowing for precise fractional values.

  2. Ownership Management:

    • The contract implements the Ownable pattern, allowing for secure ownership management.

    • The contract creator is set as the initial owner.

    • The owner can renounce ownership or transfer ownership to another address.

    • Various functions are restricted to the owner using the onlyOwner modifier.

  3. Total Supply:

    • The total token supply is set during contract deployment.

    • Tokens are created with 18 decimal places precision (common for Ethereum tokens).

  4. Fee Collection:

    • feeAddress: An address where transaction fees are collected. This address is set during contract deployment.

    • Transaction fees are collected and transferred to the feeAddress when tokens are transferred.

  5. Fee Management:

    • maxTransferFeeRate: Sets the maximum transaction fee rate (in percentage) for transfers. Default is 2%.

    • maxBurnFeeRate: Sets the maximum fee rate (in percentage) for burning tokens. Default is 2%.

    • transferFeeRate: The actual transaction fee rate for transfers. Default is 2%.

    • burnFeeRate: The actual fee rate for burning tokens. Default is 1%.

  6. Maximum Transfer Amount:

    • maxTransferAmount: Sets the maximum amount of tokens that can be transferred in a single transaction. Default is 10 billion tokens.

  7. Balances and Allowances:

    • _balances: A mapping that stores the token balances of all addresses.

    • _allowances: A mapping that tracks the approved allowances for token transfers.

  8. Exclusion from Fees:

    • isExcludedFromFees: A mapping that allows certain addresses to be excluded from transaction fees.

  9. Global Maximum Balance Limit:

    • globalMaxBalance: A variable that sets a global maximum balance limit for all addresses.

    • excludeFromMaxBalance: A mapping that allows specific addresses to be excluded from the global maximum balance limit.

  10. Constructor:

    • The constructor initializes the token contract with an initial supply and sets the fee collection address.

  11. ERC20 Functions:

    • The contract implements standard ERC20 functions including totalSupply, balanceOf, transfer, transferFrom, approve, allowance, increaseAllowance, and decreaseAllowance.

  12. Internal Functions:

    • _approve: An internal function to approve a spender to spend a specific amount on behalf of the owner.

    • _burn: An internal function to burn a specific amount of tokens from an account.

    • _transferFee: An internal function to transfer a fee to the fee address.

  13. Owner-Only Functions:

    • Several functions are restricted to the contract owner, including:

      • setTransferFeeRate: Set the transaction fee rate (in percentage).

      • setBurnFeeRate: Set the burn fee rate (in percentage).

      • setFeeAddress: Set the fee collection address.

      • excludeFromFees: Exclude an address from transaction fees.

      • includeInFees: Include an address in transaction fees.

      • setMaxTransferAmount: Set the maximum transfer amount per transaction.

      • setGlobalMaxBalance: Set the global maximum balance limit for all addresses.

      • excludeFromMaxBalance: Exclude an address from the global maximum balance limit.

      • includeInMaxBalance: Include an address in the global maximum balance limit.

  14. Global Maximum Balance Limit Enforcement:

    • The contract enforces a global maximum balance limit for all addresses, ensuring that no address can hold more tokens than the specified limit.

  15. Exclusion from Global Maximum Balance Limit:

    • Specific addresses can be excluded from the global maximum balance limit to allow for exceptions.

This contract provides control over various token parameters, transaction fees, burning, and maximum balance limits, allowing for flexibility and customization in managing the Mater token (MATER) on the Ethereum blockchain.

Last updated