Create2FactoryV2

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "contracts/Create2FactoryV2.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Create2FactoryV2 {
    event Deployed(address indexed deployedAddress, bytes32 salt, address owner);

    // Role identifiers (fixed and known constants)
    bytes32 private constant DEFAULT_ADMIN_ROLE = bytes32(0);
    bytes32 private constant MINTER_ROLE =
        0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6;
    bytes32 private constant BURNER_ROLE =
        0x3c11d16cbaffd01df69ce1c404f6340ee057498f5f00246190ea54220576a848;

    function deployAndTransferOwnership(
        bytes32 salt,
        bytes memory bytecode,
        address owner
    ) external payable returns (address deployed) {
        assembly {
            deployed := create2(callvalue(), add(bytecode, 0x20), mload(bytecode), salt)
            if iszero(deployed) {
                revert(0, 0)
            }
        }

        (bool success, ) = deployed.call(
            abi.encodeWithSignature("setCCIPAdmin(address)", owner)
        );
        if (!success) {
            (success, ) = deployed.call(
                abi.encodeWithSignature("transferOwnership(address)", owner)
            );
        }

        {
            (bool ok, ) = deployed.call(
                abi.encodeWithSignature(
                    "grantRole(bytes32,address)",
                    DEFAULT_ADMIN_ROLE,
                    owner
                )
            );
            ok; // silence compiler warning
        }

        {
            (bool ok, ) = deployed.call(
                abi.encodeWithSignature(
                    "grantRole(bytes32,address)",
                    MINTER_ROLE,
                    owner
                )
            );
            ok;
        }

        {
            (bool ok, ) = deployed.call(
                abi.encodeWithSignature(
                    "grantRole(bytes32,address)",
                    BURNER_ROLE,
                    owner
                )
            );
            ok;
        }

        emit Deployed(deployed, salt, owner);
    }

    function computeAddress(bytes32 salt, bytes32 initCodeHash)
        external
        view
        returns (address)
    {
        return
            address(
                uint160(
                    uint256(
                        keccak256(
                            abi.encodePacked(
                                bytes1(0xff),
                                address(this),
                                salt,
                                initCodeHash
                            )
                        )
                    )
                )
            );
    }
}
"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 1000
    },
    "evmVersion": "paris",
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}}

Tags:
Factory|addr:0x3092650398cf38c548ea512c69564b086a357bcd|verified:true|block:23537459|tx:0x1918f3bfd38a3178ad759219d7d8ee0297ec3623f791686f07a39349f1c8d167|first_check:1759997725

Submitted on: 2025-10-09 10:15:25

Comments

Log in to comment.

No comments yet.