Feat/mtoken min balance - #242
Conversation
There was a problem hiding this comment.
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.
| function _validateMinBalance(address user) private view { | ||
| uint256 balance = balanceOf(user); | ||
| require( | ||
| balance == 0 || balance >= 1 ether, | ||
| "MTMB: min balance not met" | ||
| ); | ||
| } |
There was a problem hiding this comment.
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();
}
| /** | ||
| * @dev overrides _beforeTokenTransfer function to call the parent hooks | ||
| */ | ||
| function _afterTokenTransfer( |
There was a problem hiding this comment.
fix: collect redemption fees before burning mTokens
No description provided.