2

Is there any way to calculate the deterministic address of a contract cloned by a Factory through create2?

I have this contract Factory

contract ForwarderFactory {

    function cloneForwarder(address payable forwarder, uint256 salt)
        public
        returns (Forwarder clonedForwarder)
    {
        address payable clonedAddress = createClone(forwarder, salt);
        clonedForwarder = Forwarder(clonedAddress);
        clonedForwarder.init(Forwarder(forwarder).owner());
        emit Deployed(clonedAddress, msg.sender);
    }

    function createClone(address payable target, uint256 salt)
        private
        returns (address payable result)
    {
        bytes20 targetBytes = bytes20(target);
        assembly {
            let clone := mload(0x40)
            mstore(
                clone,
                0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
            )
            mstore(add(clone, 0x14), targetBytes)
            mstore(
                add(clone, 0x28),
                0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
            )
            result := create2(0, clone, 0x37, salt)
        }
    }
}

How can I know before creating the clone which address will it have?

3

0

Browse other questions tagged or ask your own question.