Background: I'm using an opezeppellin Erc20 contract. but i want to use it for minimal proxy pattern(eip-1167). so for that reason i cannot use constructor and have to use the initialize method. Now I'm unsure how to translate this constructor into initialize method.
constructor(uint256 initial_supply) ERC20("Solderse", "SOLD") {
_mint(msg.sender, initial_supply * 10 ** uint256(decimals()));
}
so I opt out to hack around which is as follows.
string private _myName;
string private _mySymbol;
bool private _initialized;
constructor() ERC20("", "") {
_initialized = false;
}
function initialize(string memory _name, string memory _symbol, uint256 initial_supply) external {
require(!_initialized, "Already initialized"); // Ensure it's not initialized yet
_myName = _name;
_mySymbol = _symbol;
_initialized = true;
_mint(msg.sender, initial_supply * 10 ** uint256(decimals()));
}
Here I'm initializing my child contract with blank ERC20 constructor to silent off the errors and using an initialize method where I'm setting a name and symbol.
Now another issue arises as in Erc20 implementation the name and symbol are private variables so I cannot change them so I opt in with another hack which is to create two override public function who can change the name and symbol so I made these two functions.
function name() public view override returns (string memory) {
return _myName;
}
function symbol() public view override returns (string memory) {
return _mySymbol;
}
And I can write tests to check the name and symbol are returning the values correctly but these hacks are not what I'm looking for as far as i know ERC20 storage values have not changed at any case and i find it not very much sophisticated. so basically my question is
Can we override the private variables from child Contract or How can I implement a basic er20 in minimal proxy pattern?