Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create2 factory with initial call #81

Closed
noyyyy opened this issue Oct 30, 2022 · 2 comments
Closed

create2 factory with initial call #81

noyyyy opened this issue Oct 30, 2022 · 2 comments

Comments

@noyyyy
Copy link

noyyyy commented Oct 30, 2022

I suggest a new factory contract that can pass initial call bytes, like

    function deployWithInitCall(
        uint256 value,
        bytes32 salt,
        bytes memory code,
        bytes memory initCall
    ) public whenNotPaused {
        Create2.deploy(value, salt, code);

        if (_initCall.length > 0) {
            (bool success, bytes memory reason) = addr.call(_initCall);
            require(success, string(reason));
        }
    }

more can be seen here. wighawag/hardhat-deploy#383

@pcaversaccio
Copy link
Owner

pcaversaccio commented Oct 30, 2022

I see where you are coming from but this can be solved within the contract itself rather by changing the create2deployer contract. The only purpose of the create2deployer is to execute CREATE2 deployments and not to conduct further actions. Whatever you want to do can be achieved via constructor arguments. So for the owner<>msg.sender problem you can for instance do the following:

contract mainContract is Ownable {
    constructor(address owner) {
        _transferOwnership(owner);
    }
    ...
}

This will lead to 2 events emitted during the contract creation transaction (the first owner will be transferred to msg.sender and the second thereafter to the set address in the main constructor). The reason why this can be done is due to the linearization pattern of multiple inheritance in Solidity (see here).

For the AccessControl control case it would look like this:

contract mainContract is AccessControl {
    constructor(address admin) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
    }
    ...
}

@pcaversaccio pcaversaccio closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2022
@noyyyy
Copy link
Author

noyyyy commented Oct 30, 2022

Thanks for your comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants