Перейти к содержимому
Проверенный контрактТочноеMIT

GridMinter

Адрес0xae27c9a79e287d8ab976c2401015b0aa67863bba
Баланс

0 ETH

 

Транзакций

102

 

Компилятор

solc 0.8.28

 

Тот же код

Только этот контракт

 

Подробности

Компилятор
solc 0.8.28+commit.7893614a
Язык
solidity
Оптимизация
Да, 200 прогонов
Версия EVM
prague
Лицензия
MIT
Совпадение
Точноекод создания: да, код в сети: да
Проверен на Sourcify
Создан в блоке
26 336 962
Транзакция создания
0x3e0933e431…8b30757e41

src/GridMinter.sol

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

import {IAbxEditionMint} from "abx-contracts/src/interfaces/IAbxEditionMint.sol";


/// Sealed-pick minter for one board. Picks are committed during the window as
/// keccak256(abi.encode(square, salt, wallet, boardId)) plus a drand tlock ciphertext
/// of (square, salt), and opened by anyone after close until the open deadline.
/// Opening mints one copy of the square on the ABX ERC-1155 edition: token id = square, so a
/// square's supply is its edition. Picks not opened by then never mint and are not refunded.
contract GridMinter {
    uint256 public constant OPEN_PERIOD = 7 days;

    struct Pick {
        bytes32 hash;
        uint64 order; // 1-based commit order
        bool opened;
    }

    /// One minted copy, with who picked it and when. Packs into a single slot.
    struct Print {
        uint16 square;
        uint64 order;
        address wallet;
    }

    IAbxEditionMint public immutable edition;
    uint256 public immutable boardId;
    uint256 public immutable squares;
    uint64 public immutable openTime;
    uint64 public immutable closeTime;
    uint256 public immutable price;
    address public immutable payee;

    mapping(address wallet => Pick) public picks;
    uint64 public commitCount;

    mapping(uint256 square => Print[]) internal _squarePrints;

    event Committed(address indexed wallet, bytes32 hash, bytes ciphertext);
    event Opened(address indexed wallet, uint256 square);

    error WindowClosed();
    error NotClosed();
    error OpenPeriodOver();
    error WrongPrice();
    error AlreadyCommitted();
    error EmptyHash();
    error NoCommit();
    error AlreadyOpened();
    error BadSquare();
    error HashMismatch();
    error PayoutFailed();
    error CannotReceive();

    constructor(
        address edition_,
        uint256 boardId_,
        uint256 squares_,
        uint64 openTime_,
        uint64 closeTime_,
        uint256 price_,
        address payee_
    ) {
        require(edition_ != address(0) && payee_ != address(0));
        require(squares_ > 0 && squares_ <= type(uint16).max && openTime_ < closeTime_);
        edition = IAbxEditionMint(edition_);
        boardId = boardId_;
        squares = squares_;
        openTime = openTime_;
        closeTime = closeTime_;
        price = price_;
        payee = payee_;
    }

    function commit(bytes32 hash, bytes calldata ciphertext) external payable {
        if (block.timestamp < openTime || block.timestamp >= closeTime) revert WindowClosed();
        if (msg.value != price) revert WrongPrice();
        if (hash == bytes32(0)) revert EmptyHash();
        if (picks[msg.sender].hash != bytes32(0)) revert AlreadyCommitted();
        // An ERC-1155 mint to a contract (a smart wallet, or an EOA with EIP-7702 code) reverts unless
        // it accepts the token. Refuse such a wallet now, before it pays, rather than strand its pick.
        if (msg.sender.code.length != 0 && !_accepts1155(msg.sender)) revert CannotReceive();

        picks[msg.sender] = Pick({hash: hash, order: ++commitCount, opened: false});
        emit Committed(msg.sender, hash, ciphertext);
    }

    /// Anyone may open any wallet's commit between close and close + OPEN_PERIOD.
    function open(address wallet, uint256 square, bytes32 salt) external {
        if (block.timestamp < closeTime) revert NotClosed();
        if (block.timestamp >= closeTime + OPEN_PERIOD) revert OpenPeriodOver();
        Pick storage p = picks[wallet];
        if (p.hash == bytes32(0)) revert NoCommit();
        if (p.opened) revert AlreadyOpened();
        if (square >= squares) revert BadSquare();
        if (keccak256(abi.encode(square, salt, wallet, boardId)) != p.hash) revert HashMismatch();

        p.opened = true;
        edition.mint(wallet, square, 1);
        _squarePrints[square].push(Print({square: uint16(square), order: p.order, wallet: wallet}));
        emit Opened(wallet, square);
    }

    /// Asks `wallet` the same question the edition's mint will: operator = this minter, from = 0.
    /// The id is still sealed, so 0 stands in for it. A STATICCALL, so the wallet can't change
    /// state or call back in; a low-level one, so a reply that doesn't decode is a "no", not a revert.
    function _accepts1155(address wallet) internal view returns (bool) {
        bytes4 sel = bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"));
        (bool ok, bytes memory ret) =
            wallet.staticcall(abi.encodeWithSelector(sel, address(this), address(0), uint256(0), uint256(1), ""));
        return ok && ret.length >= 32 && bytes4(ret) == sel;
    }

    /// Sends collected ETH to the payee. Anyone may call; nothing is ever refunded.
    function withdraw() external {
        (bool ok,) = payee.call{value: address(this).balance}("");
        if (!ok) revert PayoutFailed();
    }

    /// Number of copies of `square` minted so far (its edition); final once the open period ends.
    function editionOf(uint256 square) external view returns (uint256) {
        return _squarePrints[square].length;
    }

    /// Every print of `square`, in the order they were opened (not pick order).
    function printsOf(uint256 square) external view returns (Print[] memory) {
        return _squarePrints[square];
    }
}

dependencies/abx-contracts-3.0.0/src/interfaces/IAbxEditionMint.sol

// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.28;

/// @title IAbxEditionMint — the canonical mint primitive an external minter targets, ERC-1155
/// @notice The ERC-1155 twin of `IAbxSequentialMint`: a *different* target shape for a
///         *different* mint primitive — identified ids, per-mint amounts — not a generalization
///         of the sequential primitive. The caller names the id (there is no natural
///         "next in order" cursor once amounts-per-id are in play); the token still enforces its
///         own id-space and per-id supply-cap guards.
/// @dev A **capability interface, not an extension** — no version, no beacon signal — but it *is*
///      ERC-165-advertised, so a minter (or tooling) can verify a target is mintable
///      (`IERC165(token).supportsInterface(type(IAbxEditionMint).interfaceId)`) before
///      configuring a sale, turning a would-be raw revert into a clear, up-front error. Same
///      token-side auth as `IAbxSequentialMint`: the owner always may; the assigned minter only
///      while unpaused. No `mintMany` — every ABX token is `Multicallable`, so batching many
///      ids/amounts is multicall's job, not the primitive's.
///      [`OneOfOneEdition`](../tokens/OneOfOneEdition.sol) keeps this same uniform signature but
///      reverts unless `id == 0` — its id space is fixed to the single work. How a minter
///      *uses* this — price, allocation, ETH vs ERC-20, sale events — is a separate sale-contract
///      concern; see the maintained minting documentation.
interface IAbxEditionMint {
    /// @notice Mint `amount` copies of `id` to `to`.
    /// @param to Recipient of the freshly minted copies.
    /// @param id The edition id to mint (the caller names it; not an auto-assigned cursor).
    /// @param amount Number of copies of `id` to mint (must be > 0).
    function mint(address to, uint256 id, uint256 amount) external;
}
Настройки компилятораПоказать
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "abx-contracts/=dependencies/abx-contracts-3.0.0/",
    "solady/=dependencies/solady-0.1.26/src/",
    "forge-std/=lib/forge-std/src/",
    "abx-contracts-3.0.0/=dependencies/abx-contracts-3.0.0/src/",
    "solady-0.1.26/=dependencies/solady-0.1.26/src/"
  ]
}

Исходный код и метаданные: Sourcify.

Исходный код принадлежит авторам контракта.