Skip to content
Verified contractPartialMIT

MonkeyToken

Address0xe330bd3141be4893274d65ab301278a200000000
Balance

0 ETH

 

Transactions

1,181

 

Compiler

solc 0.8.20

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 200 runs
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,355,007
Creation transaction
0x10a78b3522…793b64fb94

MonkeyToken.sol

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

contract MonkeyToken {
    string public name;
    string public symbol;
    uint8 public constant decimals = 0;
    uint256 public totalSupply;

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

    uint256 private _locked = 1;

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

    modifier nonReentrant() {
        require(_locked == 1, "ReentrancyGuard: reentered");
        _locked = 2;
        _;
        _locked = 1;
    }

    constructor(string memory _name, string memory _symbol, address _deployer) {
        name = _name;
        symbol = _symbol;
        uint256 supply = 1e36;
        totalSupply = supply;
        balanceOf[_deployer] = supply;
        emit Transfer(address(0), _deployer, supply);
    }

    function transfer(address to, uint256 amount) external nonReentrant returns (bool) {
        require(amount <= balanceOf[msg.sender], "Transfer amount exceeds balance");
        balanceOf[msg.sender] -= amount;
        unchecked {
            balanceOf[to] += amount;
        }
        emit Transfer(msg.sender, to, amount);
        return true;
    }

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

    function transferFrom(address from, address to, uint256 amount) external nonReentrant returns (bool) {
        uint256 allowed = allowance[from][msg.sender];
        require(allowed >= amount, "Transfer amount exceeds allowance");
        require(balanceOf[from] >= amount, "Transfer amount exceeds balance");
        unchecked {
            allowance[from][msg.sender] = allowed - amount;
        }
        balanceOf[from] -= amount;
        unchecked {
            balanceOf[to] += amount;
        }
        emit Transfer(from, to, amount);
        return true;
    }

    function burn(uint256 amount) external nonReentrant {
        require(amount > 0, "Burn amount is zero");
        require(balanceOf[msg.sender] >= amount, "Burn amount exceeds balance");
        unchecked {
            balanceOf[msg.sender] -= amount;
        }
        totalSupply -= amount;
        emit Transfer(msg.sender, address(0), amount);
    }

    function burnFrom(address from, uint256 amount) external nonReentrant {
        require(amount > 0, "Burn amount is zero");
        uint256 allowed = allowance[from][msg.sender];
        require(allowed >= amount, "Burn amount exceeds allowance");
        require(balanceOf[from] >= amount, "Burn amount exceeds balance");
        unchecked {
            allowance[from][msg.sender] = allowed - amount;
        }
        balanceOf[from] -= amount;
        totalSupply -= amount;
        emit Transfer(from, address(0), amount);
    }
}

contract MonkeyFactory {
    bytes private constant _TOKEN_NAME = "Monkey";
    bytes private constant _TOKEN_SYMBOL = "MONKEY";
    bytes private _tokenBytecode;

    event TokenDeployed(address indexed tokenAddress, bytes32 salt);

    constructor() {
        _tokenBytecode = type(MonkeyToken).creationCode;
    }

    function deployToken(bytes32 salt) external returns (address tokenAddress) {
        bytes memory initCode = abi.encodePacked(
            _tokenBytecode,
            abi.encode(_TOKEN_NAME, _TOKEN_SYMBOL, msg.sender)
        );

        bytes32 initCodeHash = keccak256(initCode);
        tokenAddress = address(
            uint160(
                uint256(
                    keccak256(
                        abi.encodePacked(
                            bytes1(0xff),
                            address(this),
                            salt,
                            initCodeHash
                        )
                    )
                )
            )
        );

        assembly {
            tokenAddress := create2(0, add(initCode, 0x20), mload(initCode), salt)
        }
        require(tokenAddress != address(0), "Factory: CREATE2 deployment failed");

        emit TokenDeployed(tokenAddress, salt);
    }

    function predictTokenAddress(bytes32 salt) external view returns (address) {
        bytes memory initCode = abi.encodePacked(
            _tokenBytecode,
            abi.encode(_TOKEN_NAME, _TOKEN_SYMBOL, msg.sender)
        );
        bytes32 initCodeHash = keccak256(initCode);
        return address(
            uint160(
                uint256(
                    keccak256(
                        abi.encodePacked(
                            bytes1(0xff),
                            address(this),
                            salt,
                            initCodeHash
                        )
                    )
                )
            )
        );
    }
}
Compiler settingsShow
{
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.