Skip to content
Verified contractExactMIT

OneMailbox

Address0x723deeb5003a53e465a3ed36fcbf8ddccf4c8a01
Balance

0 ETH

 

Transactions

3

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 1,000,000 runs
EVM version
cancun
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,472,177
Creation transaction
0x4bb8055c66…4ea3d69df7

src/OneMailbox.sol

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

import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";

/// @title OneMailbox
/// @notice Carries ONS Mail: each message is one `Mail` event with an opaque tag and opaque
///         (encrypted) data. Nothing is stored and neither sender nor recipient is recorded;
///         the sender is proven inside the encryption, so any account may submit a message.
/// @dev Owner powers, and nothing else: set the per-message fee (never above MAX_FEE) and the
///      fee recipient. The owner cannot stop, read, alter or remove mail. Not upgradeable.
contract OneMailbox is Ownable2Step {
    /// @notice Hard cap of the per-message fee.
    uint256 public constant MAX_FEE = 0.0001 ether;
    /// @notice Largest accepted message data, in bytes.
    uint256 public constant MAX_DATA = 8192;

    /// @notice Fee per message, in wei. `send` must be paid exactly this.
    uint256 public fee;
    address public feeRecipient;

    error ZeroAddress();
    error FeeAboveCap();
    error WrongFee(uint256 expected);
    error DataTooLarge();
    error EmptyData();
    error EmptyBatch();
    error LengthMismatch();
    error NothingToWithdraw();
    error WithdrawFailed();

    event Mail(bytes32 indexed tag, bytes data);
    event FeeSet(uint256 fee);
    event FeeRecipientSet(address indexed feeRecipient);
    event FeesWithdrawn(address indexed to, uint256 amount);

    constructor(address owner_, address feeRecipient_, uint256 fee_) {
        if (owner_ == address(0) || feeRecipient_ == address(0)) revert ZeroAddress();
        if (fee_ > MAX_FEE) revert FeeAboveCap();
        _transferOwnership(owner_);
        feeRecipient = feeRecipient_;
        fee = fee_;
        emit FeeRecipientSet(feeRecipient_);
        emit FeeSet(fee_);
    }

    /// @notice Posts one message. `msg.value` must equal `fee`.
    function send(bytes32 tag, bytes calldata data) external payable {
        if (msg.value != fee) revert WrongFee(fee);
        _post(tag, data);
    }

    /// @notice Posts several messages. `msg.value` must equal `fee` times their number.
    function sendMany(bytes32[] calldata tags, bytes[] calldata data) external payable {
        uint256 n = tags.length;
        if (n == 0) revert EmptyBatch();
        if (data.length != n) revert LengthMismatch();
        uint256 expected = fee * n;
        if (msg.value != expected) revert WrongFee(expected);
        for (uint256 i = 0; i < n; i++) {
            _post(tags[i], data[i]);
        }
    }

    function setFee(uint256 fee_) external onlyOwner {
        if (fee_ > MAX_FEE) revert FeeAboveCap();
        fee = fee_;
        emit FeeSet(fee_);
    }

    function setFeeRecipient(address feeRecipient_) external onlyOwner {
        if (feeRecipient_ == address(0)) revert ZeroAddress();
        feeRecipient = feeRecipient_;
        emit FeeRecipientSet(feeRecipient_);
    }

    /// @notice Sends the whole balance to `feeRecipient`. Callable by anyone.
    function withdrawFees() external {
        uint256 amount = address(this).balance;
        if (amount == 0) revert NothingToWithdraw();
        address to = feeRecipient;
        emit FeesWithdrawn(to, amount);
        (bool ok,) = to.call{value: amount}("");
        if (!ok) revert WithdrawFailed();
    }

    function _post(bytes32 tag, bytes calldata data) private {
        if (data.length == 0) revert EmptyData();
        if (data.length > MAX_DATA) revert DataTooLarge();
        emit Mail(tag, data);
    }
}

../lib/openzeppelin-contracts/contracts/access/Ownable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

../lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.0;

import "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
        _transferOwnership(sender);
    }
}

../lib/openzeppelin-contracts/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 1000000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=../lib/openzeppelin-contracts/contracts/",
    "forge-std/=../lib/forge-std/src/",
    "buffer/=../lib/buffer/contracts/",
    "ds-test/=/opt/One/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "ens-contracts/=../lib/ens-contracts/contracts/",
    "erc4626-tests/=/opt/One/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "openzeppelin-contracts/=/opt/One/lib/openzeppelin-contracts/contracts/",
    "openzeppelin/=/opt/One/lib/openzeppelin-contracts/contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.