Create2Factory

0x17da64d619235f5fd708258615f6a08cbca6aa94

Verification
Verified
v0.8.20+commit.a1b79de6
Type
Contract
11,357 bytes
ABI entries
5
1 read · 2 write
License
none

Contract information

Address
0x17da64d619235f5fd708258615f6a08cbca6aa94
Chain
Robinhood Chain (4663)
Compiler
v0.8.20+commit.a1b79de6
Optimization
Enabled
Creation tx
0x06406ba885…ff511d8302

Token

Not a token

This contract does not expose ERC-20 metadata.

Read contract (1)

computeAddress(bytes32, bytes32)address

Events (1)

Deployed

ABI

[
  {
    "inputs": [],
    "name": "TaxValueOutOfRange",
    "type": "error"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "address",
        "name": "addr",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "bytes32",
        "name": "salt",
        "type": "bytes32"
      }
    ],
    "name": "Deployed",
    "type": "event"
  },
  {
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "salt",
        "type": "bytes32"
      },
      {
        "internalType": "bytes32",
        "name": "bytecodeHash",
        "type": "bytes32"
      }
    ],
    "name": "computeAddress",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "salt",
        "type": "bytes32"
      },
      {
        "internalType": "bytes",
        "name": "bytecode",
        "type": "bytes"
      }
    ],
    "name": "deploy",
    "outputs": [
      {
        "internalType": "address",
        "name": "addr",
        "type": "address"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "salt",
        "type": "bytes32"
      },
      {
        "internalType": "string",
        "name": "name",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "symbol",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "supply",
        "type": "uint256"
      },
      {
        "internalType": "address",
        "name": "router",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "weth",
        "type": "address"
      },
      {
        "internalType": "address[]",
        "name": "taxRecipients",
        "type": "address[]"
      },
      {
        "internalType": "uint256[]",
        "name": "taxPercents",
        "type": "uint256[]"
      },
      {
        "internalType": "uint256",
        "name": "totalTax",
        "type": "uint256"
      },
      {
        "internalType": "address",
        "name": "recipient",
        "type": "address"
      }
    ],
    "name": "deployGenesisToken",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  }
]

Source code

// src/CreateFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {GenesisToken} from "./GenesisToken.sol";

contract Create2Factory {
    error TaxValueOutOfRange();

    event Deployed(address addr, bytes32 salt);

    function deploy(
        bytes32 salt,
        bytes memory bytecode
    ) external returns (address addr) {
        require(bytecode.length > 0, "Empty bytecode");

        assembly {
            addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
            if iszero(extcodesize(addr)) {
                revert(0, 0)
            }
        }

        emit Deployed(addr, salt);
    }

    function computeAddress(
        bytes32 salt,
        bytes32 bytecodeHash
    ) external view returns (address) {
        return
            address(
                uint160(
                    uint(
                        keccak256(
                            abi.encodePacked(
                                bytes1(0xff),
                                address(this),
                                salt,
                                bytecodeHash
                            )
                        )
                    )
                )
            );
    }

    function deployGenesisToken(
        bytes32 salt,
        string calldata name,
        string calldata symbol,
        uint256 supply,
        address router,
        address weth,
        address[] calldata taxRecipients,
        uint256[] calldata taxPercents,
        uint256 totalTax,
        address recipient
    ) external returns (address) {
        if (totalTax > 500) {
            revert TaxValueOutOfRange();
        }
        uint16[] memory tokenTaxPercents = new uint16[](taxPercents.length);
        for (uint256 i; i < taxPercents.length; i++) {
            if (taxPercents[i] > type(uint16).max) {
                revert TaxValueOutOfRange();
            }
            tokenTaxPercents[i] = uint16(taxPercents[i]);
        }

        bytes memory bytecode = abi.encodePacked(
            type(GenesisToken).creationCode,
            abi.encode(
                name,
                symbol,
                supply,
                router,
                weth,
                taxRecipients,
                tokenTaxPercents,
                uint16(totalTax),
                recipient
            )
        );

        return this.deploy(salt, bytecode);
    }
}
Chain explorer3892msChain node74ms