Skip to content
Verified contractExactMIT

RetiumSeatPresaleV2

Address0x28b4ea8039b1b23fcc992aa8ebeb1788c3c6bfde
Balance

0 ETH

 

Transactions

2

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,145,690
Creation transaction
0xac3244aa21…46a967c155

src/RetiumSeatPresaleV2.sol

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

import "./interfaces/IERC20.sol";

/// @notice The only call made to the first-round contract (RetiumSeatPresale).
interface IPreviousSeatRound {
    function getSeat(address buyer) external view returns (uint8 role, uint40 timestamp);
}

/**
 * @title RetiumSeatPresaleV2
 * @notice Second Early Validator Round. Same contract as RetiumSeatPresale
 *         (first round, 2026-08-28) with two changes:
 *         1. Monthly price tiers, fixed in code, ending 31 January 2027.
 *         2. A wallet that already holds a first-round seat cannot buy here.
 *
 * Price tiers (UTC, 6-decimal USD amounts, see _tierPrices):
 *   start       .. 31 Oct 2026   Worker  200   Suit  2000
 *   1 Nov 2026  .. 30 Nov 2026   Worker  400   Suit  4000
 *   1 Dec 2026  .. 31 Dec 2026   Worker  800   Suit  8000
 *   1 Jan 2027  .. 31 Jan 2027   Worker  900   Suit  9000
 * The sale closes for good after 31 Jan 2027 23:59:59 UTC (END_TIME).
 *
 * Seat semantics (unchanged from the first round):
 * - The exact payment amount selects the role and must equal the CURRENT tier
 *   price. Anything else reverts, so a purchase signed in one tier and mined
 *   in the next fails instead of charging a different price.
 * - One wallet = one seat, across both rounds. Enforced again on Retium at claim.
 * - No token or NFT is minted on Ethereum; the paying address is the proof of
 *   purchase.
 * - Single shared hard cap, first come first served.
 *
 * Key properties (unchanged):
 * - Funds are forwarded immediately to treasury (no custody, nothing refundable)
 * - No minting, no withdrawals, no ETH acceptance
 * - Sale is permanently locked after END_TIME
 * - Token transfers tolerate non-standard ERC-20s like mainnet USDT
 */
contract RetiumSeatPresaleV2 {
    // ============ Seat Configuration ============

    enum Role {
        None,   // sentinel: address has not purchased
        Worker,
        Suit
    }

    // Tier boundaries (unix seconds, UTC midnight)
    uint256 public constant NOV_START = 1793491200;   // 2026-11-01 00:00:00 UTC
    uint256 public constant DEC_START = 1796083200;   // 2026-12-01 00:00:00 UTC
    uint256 public constant JAN_START = 1798761600;   // 2027-01-01 00:00:00 UTC
    uint256 public constant END_TIME = 1801439999;    // 2027-01-31 23:59:59 UTC (inclusive)

    // Tier prices (USD, 6 decimals)
    uint256 public constant WORKER_PRICE_OCT = 200_000000;
    uint256 public constant WORKER_PRICE_NOV = 400_000000;
    uint256 public constant WORKER_PRICE_DEC = 800_000000;
    uint256 public constant WORKER_PRICE_JAN = 900_000000;
    uint256 public constant SUIT_PRICE_OCT = 2000_000000;
    uint256 public constant SUIT_PRICE_NOV = 4000_000000;
    uint256 public constant SUIT_PRICE_DEC = 8000_000000;
    uint256 public constant SUIT_PRICE_JAN = 9000_000000;

    // Every price is a multiple of this, so the cap must be too
    uint256 public constant PRICE_UNIT = 100_000000;

    struct Purchase {
        Role role;
        uint40 timestamp;
    }

    // ============ Immutable Configuration ============

    IERC20 public immutable usdc;
    IERC20 public immutable usdt; // optional; address(0) when not accepted
    address public immutable treasury;
    uint256 public immutable startTime;
    uint256 public immutable hardCapUSD;     // In USDC decimals (6)
    IPreviousSeatRound public immutable previousRound;

    // ============ State ============

    mapping(address => Purchase) public purchases;   // one wallet = one seat

    uint256 public totalRaisedUSD;    // USDC decimals (6)
    uint256 public workerSeatsSold;   // counters for status/indexer coverage, NOT caps
    uint256 public suitSeatsSold;
    bool public finalized;
    bool public paused;

    address public immutable admin;

    // ============ Events ============

    // Same signature as the first round so the claim indexer decodes both
    event SeatPurchased(
        address indexed buyer,
        uint8 indexed role,
        uint256 timestamp
    );

    event SaleFinalized(uint256 totalRaised, uint256 timestamp);
    event SalePaused(uint256 timestamp);
    event SaleUnpaused(uint256 timestamp);

    // ============ Errors ============

    error SaleNotStarted();
    error SaleEnded();
    error SaleIsFinalized();
    error SaleIsPaused();
    error HardCapExceeded();
    error InvalidAmount();
    error AlreadyPurchased();
    error AlreadyPurchasedInPreviousRound();
    error TransferFailed();
    error TokenNotAccepted();
    error Unauthorized();
    error AlreadyFinalized();
    error SaleNotEnded();
    error ETHNotAccepted();

    // ============ Modifiers ============

    modifier onlyAdmin() {
        if (msg.sender != admin) revert Unauthorized();
        _;
    }

    modifier whenNotPaused() {
        if (paused) revert SaleIsPaused();
        _;
    }

    modifier whenSaleActive() {
        if (block.timestamp < startTime) revert SaleNotStarted();
        if (block.timestamp > END_TIME) revert SaleEnded();
        if (finalized) revert SaleIsFinalized();
        _;
    }

    // ============ Constructor ============

    /**
     * @param _usdc USDC token address
     * @param _usdt USDT token address, or address(0) to accept USDC only
     * @param _treasury Treasury address (receives funds immediately)
     * @param _startTime Unix timestamp when sale starts (before END_TIME)
     * @param _hardCapUSD Maximum USD to raise (6 decimals), multiple of PRICE_UNIT
     * @param _admin Admin address for emergency pause + finalize
     * @param _previousRound First-round RetiumSeatPresale; its buyers are refused
     */
    constructor(
        address _usdc,
        address _usdt,
        address _treasury,
        uint256 _startTime,
        uint256 _hardCapUSD,
        address _admin,
        address _previousRound
    ) {
        require(_usdc != address(0), "Invalid USDC");
        require(_treasury != address(0), "Invalid treasury");
        require(_startTime > block.timestamp, "Start must be future");
        require(_startTime < END_TIME, "Start must be before end");
        require(_hardCapUSD > 0, "Invalid hard cap");
        require(_hardCapUSD % PRICE_UNIT == 0, "Cap not multiple of price unit");
        require(_admin != address(0), "Invalid admin");
        require(_previousRound.code.length > 0, "Invalid previous round");

        require(IERC20(_usdc).decimals() == 6, "USDC must be 6 decimals");
        if (_usdt != address(0)) {
            require(IERC20(_usdt).decimals() == 6, "USDT must be 6 decimals");
        }

        usdc = IERC20(_usdc);
        usdt = IERC20(_usdt);
        treasury = _treasury;
        startTime = _startTime;
        hardCapUSD = _hardCapUSD;
        admin = _admin;
        previousRound = IPreviousSeatRound(_previousRound);

        // Fails the deploy if the address does not answer getSeat
        previousRound.getSeat(address(0));
    }

    // ============ Pricing ============

    /// @dev Prices for the tier containing `t`. Before start this is the first
    ///      tier, after END_TIME the last one (purchases are blocked anyway).
    function _tierPrices(uint256 t)
        private
        pure
        returns (uint256 worker, uint256 suit, uint256 tierEnd)
    {
        if (t < NOV_START) return (WORKER_PRICE_OCT, SUIT_PRICE_OCT, NOV_START - 1);
        if (t < DEC_START) return (WORKER_PRICE_NOV, SUIT_PRICE_NOV, DEC_START - 1);
        if (t < JAN_START) return (WORKER_PRICE_DEC, SUIT_PRICE_DEC, JAN_START - 1);
        return (WORKER_PRICE_JAN, SUIT_PRICE_JAN, END_TIME);
    }

    /**
     * @notice Current seat prices
     * @return workerPrice Worker seat price now (6 decimals)
     * @return suitPrice Suit seat price now (6 decimals)
     * @return priceValidUntil Last second (inclusive) these prices apply
     */
    function getPrices()
        external
        view
        returns (uint256 workerPrice, uint256 suitPrice, uint256 priceValidUntil)
    {
        return _tierPrices(block.timestamp);
    }

    // ============ Purchase Functions ============

    /**
     * @notice Purchase a validator seat with USDC
     * @param usdAmount Exactly the current Worker or Suit price
     */
    function buySeatUSDC(uint256 usdAmount) external {
        _buySeat(usdc, usdAmount);
    }

    /**
     * @notice Purchase a validator seat with USDT (only if USDT is configured)
     * @param usdAmount Exactly the current Worker or Suit price
     */
    function buySeatUSDT(uint256 usdAmount) external {
        if (address(usdt) == address(0)) revert TokenNotAccepted();
        _buySeat(usdt, usdAmount);
    }

    function _buySeat(IERC20 token, uint256 usdAmount) private whenNotPaused whenSaleActive {
        if (purchases[msg.sender].role != Role.None) revert AlreadyPurchased();
        (uint8 previousRole, ) = previousRound.getSeat(msg.sender);
        if (previousRole != 0) revert AlreadyPurchasedInPreviousRound();

        (uint256 workerPrice, uint256 suitPrice, ) = _tierPrices(block.timestamp);
        Role role;
        if (usdAmount == workerPrice) {
            role = Role.Worker;
        } else if (usdAmount == suitPrice) {
            role = Role.Suit;
        } else {
            revert InvalidAmount();
        }

        if (totalRaisedUSD + usdAmount > hardCapUSD) revert HardCapExceeded();

        // Update state before external call (CEI pattern)
        purchases[msg.sender] = Purchase({ role: role, timestamp: uint40(block.timestamp) });
        totalRaisedUSD += usdAmount;
        if (role == Role.Worker) {
            workerSeatsSold += 1;
        } else {
            suitSeatsSold += 1;
        }

        _safeTransferFrom(token, msg.sender, treasury, usdAmount);

        emit SeatPurchased(msg.sender, uint8(role), block.timestamp);
    }

    /**
     * @dev SafeERC20-style transferFrom. Accepts tokens that return bool (USDC)
     *      and tokens that return nothing (mainnet USDT); reverts on an explicit
     *      false, a reverting token, or an address without code.
     */
    function _safeTransferFrom(IERC20 token, address from, address to, uint256 value) private {
        if (address(token).code.length == 0) revert TransferFailed();
        (bool success, bytes memory returndata) = address(token).call(
            abi.encodeWithSelector(token.transferFrom.selector, from, to, value)
        );
        if (!success || (returndata.length != 0 && !abi.decode(returndata, (bool)))) {
            revert TransferFailed();
        }
    }

    // ============ Finalization ============

    /// @notice Finalize the sale (irreversible), admin only, after END_TIME
    function finalizeSale() external onlyAdmin {
        if (finalized) revert AlreadyFinalized();
        if (block.timestamp <= END_TIME) revert SaleNotEnded();

        finalized = true;

        emit SaleFinalized(totalRaisedUSD, block.timestamp);
    }

    // ============ Emergency Controls ============

    function emergencyPause() external onlyAdmin {
        if (finalized) revert AlreadyFinalized();
        paused = true;
        emit SalePaused(block.timestamp);
    }

    function emergencyUnpause() external onlyAdmin {
        if (finalized) revert AlreadyFinalized();
        paused = false;
        emit SaleUnpaused(block.timestamp);
    }

    // ============ View Functions ============

    /// @notice A buyer's seat in THIS round (0 = none, 1 = Worker, 2 = Suit)
    function getSeat(address buyer) external view returns (uint8 role, uint40 timestamp) {
        Purchase memory p = purchases[buyer];
        return (uint8(p.role), p.timestamp);
    }

    /// @notice Whether `buyer` can still buy here (no seat in either round)
    function canBuy(address buyer) external view returns (bool) {
        if (purchases[buyer].role != Role.None) return false;
        (uint8 previousRole, ) = previousRound.getSeat(buyer);
        return previousRole == 0;
    }

    function getSaleStatus()
        external
        view
        returns (
            bool isActive,
            bool isPaused,
            bool isFinalized,
            uint256 raised,
            uint256 cap,
            uint256 remaining,
            uint256 workerSeats,
            uint256 suitSeats
        )
    {
        isActive = block.timestamp >= startTime &&
                   block.timestamp <= END_TIME &&
                   !finalized &&
                   !paused;
        isPaused = paused;
        isFinalized = finalized;
        raised = totalRaisedUSD;
        cap = hardCapUSD;
        remaining = hardCapUSD > totalRaisedUSD ? hardCapUSD - totalRaisedUSD : 0;
        workerSeats = workerSeatsSold;
        suitSeats = suitSeatsSold;
    }

    function getTimeInfo()
        external
        view
        returns (
            uint256 start,
            uint256 end,
            uint256 current,
            bool hasStarted,
            bool hasEnded
        )
    {
        return (
            startTime,
            END_TIME,
            block.timestamp,
            block.timestamp >= startTime,
            block.timestamp > END_TIME
        );
    }

    // ============ Fallback ============

    receive() external payable {
        revert ETHNotAccepted();
    }

    fallback() external payable {
        revert ETHNotAccepted();
    }
}

src/interfaces/IERC20.sol

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

interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    function decimals() external view returns (uint8);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=lib/forge-std/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.