Skip to content
Verified contractExactMIT

LayaMintFactory

Address0x5a536b92a89f1834ea0cb307ef405285bc480a65
Balance

0 ETH

 

Transactions

3

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,420,106
Creation transaction
0x7cd20d6508…b8d25fd2b1

LayaMintFactory.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./LayaStandardERC20.sol";

contract LayaMintFactory {
    address public immutable feeRecipient;
    uint256 public immutable feeWei;
    uint256 public createCount;
    uint256 private _lock;

    event TokenCreated(
        address indexed token,
        address indexed creator,
        address indexed tokenOwner,
        uint256 feePaid
    );

    constructor(address feeRecipient_, uint256 feeWei_) {
        require(feeRecipient_ != address(0), "recipient");
        feeRecipient = feeRecipient_;
        feeWei = feeWei_;
    }

    function createToken(
        string calldata name_,
        string calldata symbol_,
        uint8 decimals_,
        address[] calldata recipients,
        uint256[] calldata amounts,
        bool mintable,
        bool keepOwner
    ) external payable returns (address token) {
        require(_lock == 0, "lock");
        _lock = 1;
        require(msg.value == feeWei, "fee");
        require(!mintable || keepOwner, "owner");
        if (feeWei > 0) {
            (bool ok, ) = feeRecipient.call{value: msg.value}("");
            require(ok, "pay");
        }
        address tokenOwner = keepOwner ? msg.sender : address(0);
        uint256 n;
        unchecked {
            n = ++createCount;
        }
        bytes32 salt = keccak256(abi.encode(block.chainid, n, msg.sender));
        token = address(
            new LayaStandardERC20{salt: salt}(
                name_,
                symbol_,
                decimals_,
                recipients,
                amounts,
                tokenOwner,
                mintable
            )
        );
        emit TokenCreated(token, msg.sender, tokenOwner, msg.value);
        _lock = 0;
    }

    receive() external payable {
        revert("direct");
    }

    fallback() external payable {
        revert("direct");
    }
}

LayaStandardERC20.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract LayaStandardERC20 {
    string public name;
    string public symbol;
    uint8 public immutable decimals;
    bool public immutable mintable;
    uint256 public totalSupply;
    address public owner;

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    modifier onlyOwner() {
        require(owner != address(0) && msg.sender == owner, "owner");
        _;
    }

    constructor(
        string memory name_,
        string memory symbol_,
        uint8 decimals_,
        address[] memory recipients,
        uint256[] memory amounts,
        address owner_,
        bool mintable_
    ) {
        require(recipients.length == amounts.length, "len");
        require(recipients.length > 0 && recipients.length <= 20, "recipients");
        require(bytes(name_).length != 0 && bytes(name_).length <= 192, "name");
        require(bytes(symbol_).length != 0 && bytes(symbol_).length <= 11, "symbol");
        require(decimals_ <= 18, "decimals");
        require(!mintable_ || owner_ != address(0), "mint");
        name = name_;
        symbol = symbol_;
        decimals = decimals_;
        mintable = mintable_;
        owner = owner_;
        if (owner_ != address(0)) {
            emit OwnershipTransferred(address(0), owner_);
        }
        uint256 supply;
        for (uint256 i = 0; i < recipients.length; i++) {
            address to = recipients[i];
            require(to != address(0), "recipient");
            require(amounts[i] > 0, "amount");
            for (uint256 j = 0; j < i; j++) {
                require(recipients[j] != to, "dup");
            }
            supply += amounts[i];
            balanceOf[to] += amounts[i];
            emit Transfer(address(0), to, amounts[i]);
        }
        require(supply > 0, "supply");
        totalSupply = supply;
    }

    function mint(address to, uint256 amount) external onlyOwner {
        require(mintable, "mint");
        require(to != address(0), "to");
        require(amount > 0, "amount");
        totalSupply += amount;
        balanceOf[to] += amount;
        emit Transfer(address(0), to, amount);
    }

    function transferOwnership(address newOwner) external onlyOwner {
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }

    function approve(address spender, uint256 amount) external returns (bool) {
        allowance[msg.sender][spender] = amount;
        emit Approval(msg.sender, spender, amount);
        return true;
    }

    function transfer(address to, uint256 amount) external returns (bool) {
        _transfer(msg.sender, to, amount);
        return true;
    }

    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        uint256 allowed = allowance[from][msg.sender];
        if (allowed != type(uint256).max) {
            require(allowed >= amount, "allowance");
            unchecked {
                allowance[from][msg.sender] = allowed - amount;
            }
        }
        _transfer(from, to, amount);
        return true;
    }

    function _transfer(address from, address to, uint256 amount) internal {
        require(to != address(0), "to");
        uint256 bal = balanceOf[from];
        require(bal >= amount, "balance");
        unchecked {
            balanceOf[from] = bal - amount;
            balanceOf[to] += amount;
        }
        emit Transfer(from, to, amount);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.