1
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.

2
  • What are DaoRegistry, _createClone and identityAddress? Provide the source code if they are contracts.
    – Ismael
    Jan 23, 2022 at 17:50
  • The source is here. The same pattern is used here
    – Edgeseer
    Jan 24, 2022 at 0:28

1 Answer 1

1

The _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;
    ..
}
2
  • So the first line 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.
    – Edgeseer
    Jan 24, 2022 at 23:23
  • @Edgeseer Sorry for the late reply. The function _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.
    – Ismael
    Feb 2, 2022 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.