Skip to content

Feat/mtoken min balance - #242

Open
kostyamospan wants to merge 21 commits into
mainfrom
feat/mtoken-min-balance
Open

Feat/mtoken min balance#242
kostyamospan wants to merge 21 commits into
mainfrom
feat/mtoken-min-balance

Conversation

@kostyamospan

Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new minimum balance check feature for mTokens, implementing mTokenMinBalance and mTokenPermissionedMinBalance along with corresponding tests, deployment scripts, and configuration updates. The review feedback highlights a high-severity issue where hardcoding 1 ether as the minimum balance assumes 18 decimals, which would break usability for tokens with fewer decimals (such as 6 or 8 decimals). Additionally, a minor copy-paste typo was identified in the docstring of _afterTokenTransfer in mTokenPermissionedMinBalance.sol.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +55 to +61
function _validateMinBalance(address user) private view {
uint256 balance = balanceOf(user);
require(
balance == 0 || balance >= 1 ether,
"MTMB: min balance not met"
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Hardcoding "1 ether" (which is "10**18") as the minimum balance assumes that all tokens using this contract will have 18 decimals and require exactly a 1-token minimum balance. If a token has fewer decimals (e.g., 6 decimals for USDC-pegged tokens or 8 decimals for BTC-pegged tokens), "1 ether" translates to an extremely large minimum balance (e.g., "10^12" or "10^10" tokens), making the token practically unusable.

To support tokens with different decimals and allow customization of the minimum balance, consider defining a virtual function "_minBalance()" that defaults to "10 ** decimals()" (or a customizable value) and can be overridden by specific token implementations.

    function _validateMinBalance(address user) private view {
        uint256 balance = balanceOf(user);
        require(
            balance == 0 || balance >= _minBalance(),
            "MTMB: min balance not met"
        );
    }

    /**
     * @dev returns the minimum balance required for non-exempt users
     */
    function _minBalance() internal view virtual returns (uint256) {
        return 10 ** decimals();
    }

Comment on lines +33 to +36
/**
* @dev overrides _beforeTokenTransfer function to call the parent hooks
*/
function _afterTokenTransfer(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The docstring/comment for "_afterTokenTransfer" incorrectly states that it overrides "_beforeTokenTransfer". This is a copy-paste typo from the function above it.

    /**
     * @dev overrides _afterTokenTransfer function to call the parent hooks
     */
    function _afterTokenTransfer(

@kostyamospan
kostyamospan marked this pull request as ready for review July 17, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants