@@ -5,6 +5,7 @@ pragma solidity 0.8.26;
55import { ERC20Extended } from "../lib/common/src/ERC20Extended.sol " ;
66import { UIntMath } from "../lib/common/src/libs/UIntMath.sol " ;
77import { Migratable } from "../lib/common/src/Migratable.sol " ;
8+ import { Bytes32String } from "../lib/common/src/libs/Bytes32String.sol " ;
89
910import { IERC20 } from "../lib/common/src/interfaces/IERC20.sol " ;
1011
@@ -16,12 +17,29 @@ import { IMToken } from "./interfaces/IMToken.sol";
1617import { ContinuousIndexing } from "./abstract/ContinuousIndexing.sol " ;
1718import { ContinuousIndexingMath } from "./libs/ContinuousIndexingMath.sol " ;
1819
20+ abstract contract MTokenStorageLayout {
21+ /// @custom:storage-location erc7201:m0.storage.MToken
22+ struct MTokenStorage {
23+ bytes32 name;
24+ bytes32 symbol;
25+ }
26+
27+ // keccak256(abi.encode(uint256(keccak256("m0.storage.MToken")) - 1)) & ~bytes32(uint256(0xff))
28+ bytes32 private constant _M_TOKEN_STORAGE_SLOT = 0x93466981a55ce4da70da67506024f05bd15faf7fdab908fab669c24c9fb04d00 ;
29+
30+ function _getMTokenStorage () internal pure returns (MTokenStorage storage $) {
31+ assembly {
32+ $.slot := _M_TOKEN_STORAGE_SLOT
33+ }
34+ }
35+ }
36+
1937/**
2038 * @title MToken
21- * @author M^0 Labs
39+ * @author M0 Labs
2240 * @notice ERC20 M Token living on other chains.
2341 */
24- contract MToken is IMToken , ContinuousIndexing , ERC20Extended , Migratable {
42+ contract MToken is IMToken , ContinuousIndexing , ERC20Extended , Migratable , MTokenStorageLayout {
2543 /* ============ Structs ============ */
2644
2745 /**
@@ -70,9 +88,9 @@ contract MToken is IMToken, ContinuousIndexing, ERC20Extended, Migratable {
7088 * @param registrar_ The address of the Registrar contract.
7189 * @param migrationAdmin_ The address of a migration admin.
7290 */
73- constructor (address registrar_ , address migrationAdmin_ ) ContinuousIndexing () ERC20Extended ("M by M^0 " , "M " , 6 ) {
91+ constructor (address registrar_ , address migrationAdmin_ ) ContinuousIndexing () ERC20Extended ("M by M0 " , "M " , 6 ) {
7492 _disableInitializers ();
75-
93+
7694 if ((registrar = registrar_) == address (0 )) revert ZeroRegistrar ();
7795 if ((portal = RegistrarReader.getPortal (registrar_)) == address (0 )) revert ZeroPortal ();
7896 if ((migrationAdmin = migrationAdmin_) == address (0 )) revert ZeroMigrationAdmin ();
@@ -81,8 +99,13 @@ contract MToken is IMToken, ContinuousIndexing, ERC20Extended, Migratable {
8199 /* ============ Initializer ============ */
82100
83101 /// @inheritdoc IMToken
84- function initialize () external initializer {
102+ function initialize (string memory name_ , string memory symbol_ ) external initializer {
85103 _initialize ();
104+
105+ MTokenStorage storage $ = _getMTokenStorage ();
106+
107+ $.name = Bytes32String.toBytes32 (name_);
108+ $.symbol = Bytes32String.toBytes32 (symbol_);
86109 }
87110
88111 /* ============ Interactive Functions ============ */
@@ -138,6 +161,15 @@ contract MToken is IMToken, ContinuousIndexing, ERC20Extended, Migratable {
138161 }
139162
140163 /* ============ View/Pure Functions ============ */
164+ /// @inheritdoc IERC20
165+ function name () external view override (IERC20 , ERC20Extended ) returns (string memory name_ ) {
166+ return Bytes32String.toString (_getMTokenStorage ().name);
167+ }
168+
169+ /// @inheritdoc IERC20
170+ function symbol () external view override (IERC20 , ERC20Extended ) returns (string memory symbol_ ) {
171+ return Bytes32String.toString (_getMTokenStorage ().symbol);
172+ }
141173
142174 /// @inheritdoc IMToken
143175 function totalEarningSupply () public view returns (uint240 totalEarningSupply_ ) {
0 commit comments