I have my contract that uses multiple inheritance from several upgradeable contracts:
contract PolicyPool is
IPolicyPool,
ERC721Upgradeable,
ERC721EnumerableUpgradeable,
PausableUpgradeable,
AccessControlUpgradeable
{
My question is what is the best practice for doing my initialize function.
This alternative (calling parents _init):
function initialize(
string memory name_,
string memory symbol_,
IERC20 curreny_,
address treasury_,
address assetManager_
) public initializer {
__AccessControl_init();
__Pausable_init();
__ERC721_init(name_, symbol_);
__ERC721Enumerable_init();
__PolicyPool_init_unchained(currency_, treasury_, assetManager_);
}
If I call this way, some common ancestors like __Context_init_unchained
and __ERC165_init_unchained
will be called several times.
Or should I use a fully unchained alternative:
function initialize(
string memory name_,
string memory symbol_,
IERC20 curreny_,
address treasury_,
address assetManager_
) public initializer {
__Context_init_unchained();
__ERC165_init_unchained();
__ERC721_init_unchained(name_, symbol_);
__ERC721Enumerable_init_unchained();
__Pausable_init_unchained();
__AccessControl_init_unchained()
__PolicyPool_init_unchained(currency_, treasury_, assetManager_);
}
The problem I see with this alternative is I need to analyze the hierarchy of my contract’s parents.
The first one is more clean and perhaps I can live with some duplicate call or not?