DaoRegistry dao = DaoRegistry(_createClone(identityAddress));
_createClone() returns a payable address, but the DaoRegistry constructor is empty. I haven't been able to find an explanation for what is going on here.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityThe _createClone
functions deploy an EIP 1167 - minimal proxy that target identityAddress
.
The contract's bytecode is deployed but the contract's storage is not initialized.
The magic is in the initialize
function called by createDao
function createDao(string calldata daoName, address creator) external {
..
DaoRegistry dao = DaoRegistry(_createClone(identityAddress));
..
dao.initialize(creator, msg.sender);
..
}
The initialize
works here as the "constructor", it is a very common patter used in proxy contracts.
function initialize(address creator, address payer) external {
require(!initialized, "dao already initialized");
initialized = true;
..
}
DaoRegistry dao = DaoRegistry(_createClone(identityAddress));
says dao is a DaoRegistry at the addreess that _createClone returns. That makes sense. I don't know where that's indicated in the solidity documentation though.
_createClone()
creates a proxy to the contract at identityAddress, it return the proxy address. It has no idea what the target contract do, it just deploys the proxy bytecode and returns. This line DaoRegistry dao = DaoRegistry(proxyAddress)
is just a casting from address
to DaoRegistry
. It doesn't call the constructor.
DaoRegistry
,_createClone
andidentityAddress
? Provide the source code if they are contracts.