Skip to content
Verified contractExactMIT

CkullsNFT2

Address0x11812857c4c672113cf0c96488c5446388bfcd14
Balance

0 ETH

 

Transactions

1,157

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 200 runs
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,390,817
Creation transaction
0xee9b4239b6…9456e936f9

CkullsNFT2.sol

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

/// @title Ckulls — 3,333 tiny pixel skeletons on Ethereum mainnet. (v2)
/// @notice PUBLIC mint — no Agent ID gate, no allowlist. Two lanes run
///         SIMULTANEOUSLY from openMint() until sellout, both drawing from
///         the shared 3,333 supply:
///         - FREE batch lane: free slots open in BATCHES of 3. A batch is
///           live from `batchOpenBlock`; while any of its 3 slots is
///           unclaimed, NO new slots appear — unclaimed slots wait, they
///           never pile up. When the 3rd slot of a batch is taken, the next
///           batch opens BATCH_GAP (1) block later. Max 1 free mint per
///           wallet, ever.
///         - PAID instant lane: exactly 0.0002 ETH per token, mint any time,
///           max 5 paid per wallet. A wallet can hold 1 free + 5 paid = 6.
///         There is NO mint window: the mint ends only at sellout.
/// @dev v2 replaces v1's accumulating time-based drip (allowance grew by 3
///      every 3 blocks whether taken or not) with the batch model above.
///      Everything else — seeded-shuffle id dealing, prices, caps, royalty —
///      is identical to v1. The rules are constants — they cannot be changed
///      by anyone, owner included. Token ids are dealt from a seeded
///      shuffle: the constructor seed drives a lazy Fisher-Yates permutation
///      of ids 1..3333, so the n-th mint (across both lanes, in mint order)
///      receives a pseudo-random but fully deterministic id. The permutation
///      is a bijection by construction — every id is dealt exactly once.
contract CkullsNFT2 {
    string public name = "Ckulls";
    string public symbol = "CKULL";

    uint256 public constant MAX_SUPPLY = 3333;
    uint256 public constant PRICE = 0.0002 ether; // 200000000000000 wei — FIXED, no setter
    uint256 public constant MAX_PAID_PER_WALLET = 5;
    uint256 public constant MAX_FREE_PER_WALLET = 1;
    uint256 public constant BATCH_SIZE = 3; // free slots per batch
    uint256 public constant BATCH_GAP = 1; // blocks between a batch selling out and the next opening
    uint96 public constant DEFAULT_ROYALTY_BPS = 500; // 5%

    address public owner;
    string public baseURI;
    bool public mintOpen;
    uint256 public startBlock; // block.number recorded by openMint()
    uint256 public totalSupply;

    uint256 public freeCount; // free mints so far (batch lane only)

    // --- Batch lane state ---
    uint256 public batchOpenBlock; // first block at which the current batch can be claimed
    uint256 public batchMinted; // free mints already taken from the current batch

    /// @notice Shuffle seed, fixed at deployment. The id permutation is a
    /// deterministic function of this seed — anyone can recompute the full
    /// deal order off-chain once the seed is known.
    uint256 public shuffleSeed;

    mapping(address => bool) public freeMinted; // free lane: once per wallet, ever
    mapping(address => uint256) public paidMintedCount; // paid lane counter

    // Lazy Fisher-Yates state: virtual array position p holds id
    // (_idAt[p] == 0 ? p + 1 : _idAt[p]). Only positions touched by a swap
    // are ever written.
    mapping(uint256 => uint256) private _idAt;

    // ERC-2981 royalty (owner-settable; constructor default 500 bps to owner)
    address public royaltyReceiver;
    uint96 public royaltyBps;

    // --- ERC721 storage ---
    mapping(uint256 => address) private _owners;
    mapping(address => uint256) private _balances;
    mapping(uint256 => address) private _tokenApprovals;
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
    event Approval(address indexed owner_, address indexed approved, uint256 indexed tokenId);
    event ApprovalForAll(address indexed owner_, address indexed operator, bool approved);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    event MintOpened(uint256 startBlock);
    event Minted(address indexed to, uint256 indexed tokenId, bool free);
    event RoyaltySet(address receiver, uint96 bps);

    modifier onlyOwner() {
        require(msg.sender == owner, "not owner");
        _;
    }

    constructor(uint256 shuffleSeed_) {
        require(shuffleSeed_ != 0, "zero seed");
        shuffleSeed = shuffleSeed_;
        owner = msg.sender;
        royaltyReceiver = msg.sender;
        royaltyBps = DEFAULT_ROYALTY_BPS;
        emit OwnershipTransferred(address(0), msg.sender);
        emit RoyaltySet(msg.sender, DEFAULT_ROYALTY_BPS);
    }

    // --- Admin ---
    /// @notice Opens the public mint exactly once. The first free batch is
    /// available immediately (batchOpenBlock = the openMint block). There is
    /// no closing time: the mint runs until sellout and can never be
    /// reopened because it never closes.
    function openMint() external onlyOwner {
        require(!mintOpen, "already opened");
        mintOpen = true;
        startBlock = block.number;
        batchOpenBlock = block.number;
        batchMinted = 0;
        emit MintOpened(block.number);
    }

    function setBaseURI(string calldata uri) external onlyOwner {
        baseURI = uri;
    }

    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "zero address");
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }

    function withdraw() external onlyOwner {
        (bool ok, ) = payable(owner).call{value: address(this).balance}("");
        require(ok, "withdraw failed");
    }

    /// @notice Update the ERC-2981 royalty. bps is in basis points
    /// (500 = 5%); it can never exceed 10,000 (100%).
    function setRoyalty(address receiver, uint96 bps) external onlyOwner {
        require(receiver != address(0), "zero address");
        require(bps <= 10000, "bps too high");
        royaltyReceiver = receiver;
        royaltyBps = bps;
        emit RoyaltySet(receiver, bps);
    }

    // --- Batch lane math ---
    /// @notice Free slots claimable right now: the unclaimed remainder of
    /// the live batch (BATCH_SIZE − batchMinted), capped by the supply
    /// remaining for BOTH lanes (the lanes share one supply). 0 before
    /// openMint, and 0 while waiting for the next batch to open.
    function dripAvailable() public view returns (uint256) {
        if (!mintOpen) return 0;
        if (block.number < batchOpenBlock) return 0;
        uint256 inBatch = BATCH_SIZE - batchMinted;
        uint256 remaining = MAX_SUPPLY - totalSupply;
        return inBatch < remaining ? inBatch : remaining;
    }

    /// @notice Blocks until the next batch opens. 0 when a batch is live
    /// (or the mint is not open yet).
    function nextBatchIn() public view returns (uint256) {
        if (!mintOpen) return 0;
        if (block.number >= batchOpenBlock) return 0;
        return batchOpenBlock - block.number;
    }

    // --- Seeded shuffle (id assignment) ---
    /// @notice Deal the next token id. `n` is the 0-based count of tokens
    /// already dealt (= totalSupply at call time). The swap partner r is
    /// derived from keccak256(shuffleSeed, n) inside [n, MAX_SUPPLY).
    function _drawId() internal returns (uint256) {
        uint256 n = totalSupply;
        uint256 span = MAX_SUPPLY - n;
        uint256 r = n + (uint256(keccak256(abi.encode(shuffleSeed, n))) % span);
        uint256 idAtN = _idAt[n] == 0 ? n + 1 : _idAt[n];
        uint256 idAtR = _idAt[r] == 0 ? r + 1 : _idAt[r];
        if (r != n) _idAt[r] = idAtN;
        _idAt[n] = idAtR;
        return idAtR;
    }

    // --- Public mint ---
    /// @notice Free mint — max 1 per wallet, ever. Requires an unclaimed
    /// slot in the live batch. Taking the last slot of a batch schedules
    /// the next batch BATCH_GAP blocks later; unclaimed slots never
    /// accumulate beyond one batch (FCFS).
    function mintFree() external {
        require(mintOpen, "mint not open");
        require(!freeMinted[msg.sender], "free already minted");
        require(totalSupply < MAX_SUPPLY, "sold out");
        require(dripAvailable() > 0, "drip not available");
        freeMinted[msg.sender] = true;
        freeCount += 1;
        batchMinted += 1;
        if (batchMinted == BATCH_SIZE) {
            batchMinted = 0;
            batchOpenBlock = block.number + BATCH_GAP;
        }
        uint256 id = _drawId();
        totalSupply += 1;
        _safeMint(msg.sender, id);
        emit Minted(msg.sender, id, true);
    }

    /// @notice Paid mint — open from openMint(), simultaneously with the
    /// free lane, until sellout. Exactly PRICE (0.0002 ETH) per token,
    /// max 5 paid per wallet. The free mint does not count against this cap
    /// (and paid mints do not consume the free mint or any batch slot).
    function mintPaid(uint256 qty) external payable {
        require(mintOpen, "mint not open");
        require(qty > 0, "zero qty");
        require(paidMintedCount[msg.sender] + qty <= MAX_PAID_PER_WALLET, "paid cap");
        require(totalSupply + qty <= MAX_SUPPLY, "sold out");
        require(msg.value == PRICE * qty, "wrong value");
        paidMintedCount[msg.sender] += qty;
        for (uint256 i = 0; i < qty; i++) {
            uint256 id = _drawId();
            totalSupply += 1;
            _safeMint(msg.sender, id);
            emit Minted(msg.sender, id, false);
        }
    }

    // --- Views for the mint page ---
    function maxSupply() external pure returns (uint256) {
        return MAX_SUPPLY;
    }

    function phase() external view returns (uint8) {
        if (!mintOpen) return 0; // not opened
        if (totalSupply >= MAX_SUPPLY) return 2; // sold out
        return 1; // open (both lanes live; free subject to batch)
    }

    /// @notice Front-end / agent helper: everything needed to mint in one call.
    function status(address a) external view returns (
        bool open,
        uint256 supply,
        uint256 max,
        uint256 price,
        uint256 start,
        uint256 dripAvail,
        bool callerFreeMinted,
        uint256 callerPaidMinted,
        uint256 callerPaidLeft
    ) {
        open = mintOpen;
        supply = totalSupply;
        max = MAX_SUPPLY;
        price = PRICE;
        start = startBlock;
        dripAvail = dripAvailable();
        callerFreeMinted = freeMinted[a];
        callerPaidMinted = paidMintedCount[a];
        callerPaidLeft = MAX_PAID_PER_WALLET - paidMintedCount[a];
    }

    // --- ERC2981 ---
    function royaltyInfo(uint256, uint256 salePrice) external view returns (address, uint256) {
        return (royaltyReceiver, (salePrice * royaltyBps) / 10000);
    }

    // --- ERC721 ---
    function balanceOf(address account) external view returns (uint256) {
        require(account != address(0), "zero address");
        return _balances[account];
    }

    function ownerOf(uint256 tokenId) public view returns (address) {
        address o = _owners[tokenId];
        require(o != address(0), "nonexistent token");
        return o;
    }

    function tokenURI(uint256 tokenId) external view returns (string memory) {
        require(_owners[tokenId] != address(0), "nonexistent token");
        return string(abi.encodePacked(baseURI, _toString(tokenId), ".json"));
    }

    function approve(address to, uint256 tokenId) external {
        address o = ownerOf(tokenId);
        require(msg.sender == o || _operatorApprovals[o][msg.sender], "not authorized");
        _tokenApprovals[tokenId] = to;
        emit Approval(o, to, tokenId);
    }

    function getApproved(uint256 tokenId) external view returns (address) {
        require(_owners[tokenId] != address(0), "nonexistent token");
        return _tokenApprovals[tokenId];
    }

    function setApprovalForAll(address operator, bool approved) external {
        _operatorApprovals[msg.sender][operator] = approved;
        emit ApprovalForAll(msg.sender, operator, approved);
    }

    function isApprovedForAll(address account, address operator) external view returns (bool) {
        return _operatorApprovals[account][operator];
    }

    function transferFrom(address from, address to, uint256 tokenId) public {
        require(_isAuthorized(msg.sender, tokenId), "not authorized");
        require(ownerOf(tokenId) == from, "wrong from");
        require(to != address(0), "zero address");
        delete _tokenApprovals[tokenId];
        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;
        emit Transfer(from, to, tokenId);
    }

    function safeTransferFrom(address from, address to, uint256 tokenId) external {
        safeTransferFrom(from, to, tokenId, "");
    }

    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public {
        transferFrom(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, data), "unsafe recipient");
    }

    function _isAuthorized(address spender, uint256 tokenId) internal view returns (bool) {
        address o = _owners[tokenId];
        return spender == o || _tokenApprovals[tokenId] == spender || _operatorApprovals[o][spender];
    }

    function _safeMint(address to, uint256 tokenId) internal {
        require(to != address(0), "zero address");
        require(_owners[tokenId] == address(0), "already minted");
        _balances[to] += 1;
        _owners[tokenId] = to;
        emit Transfer(address(0), to, tokenId);
        require(_checkOnERC721Received(address(0), to, tokenId, ""), "unsafe recipient");
    }

    function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private returns (bool) {
        if (to.code.length == 0) return true;
        try IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, data) returns (bytes4 retval) {
            return retval == IERC721Receiver.onERC721Received.selector;
        } catch {
            return false;
        }
    }

    function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
        return interfaceId == 0x01ffc9a7 // ERC165
            || interfaceId == 0x80ac58cd // ERC721
            || interfaceId == 0x5b5e139f // ERC721Metadata
            || interfaceId == 0x2a55205a; // ERC2981
    }

    function _toString(uint256 value) internal pure returns (string memory) {
        if (value == 0) return "0";
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) { digits++; temp /= 10; }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + (value % 10)));
            value /= 10;
        }
        return string(buffer);
    }
}

interface IERC721Receiver {
    function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.