Skip to content
Verified contractExactMIT

RetiumSeatPresaleV3

Address0x29de86c7f3a00bfdabbb88106fe0d187dc7dd3ff
Balance

0 ETH

 

Transactions

1

 

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,424,816
Creation transaction
0x03e677b408…a93cef23a6

src/RetiumSeatPresaleV3.sol

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

import "./interfaces/IERC20.sol";

/// @notice The only call made to the earlier round contracts.
interface IEarlierSeatRound {
    function getSeat(address buyer) external view returns (uint8 role, uint40 timestamp);
}

/**
 * @title RetiumSeatPresaleV3
 * @notice Early Validator Round, replacement for RetiumSeatPresaleV2 (round 2,
 *         2026-10-08). Same contract with two changes:
 *         1. A fixed event price from 27 to 30 November 2026.
 *         2. A wallet that holds a seat in round 1 OR in round 2 cannot buy here.
 *
 * Price tiers (UTC, 6-decimal USD amounts, see _tierPrices):
 *   start        .. 26 Nov 2026   Worker  400   Suit  4000
 *   27 Nov 2026  .. 30 Nov 2026   Worker  200   Suit  2000   (event)
 *   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 earlier rounds):
 * - 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 all 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 RetiumSeatPresaleV3 {
    // ============ Seat Configuration ============

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

    // Tier boundaries (unix seconds, UTC midnight)
    uint256 public constant EVENT_START = 1795737600; // 2026-11-27 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_NOV = 400_000000;
    uint256 public constant WORKER_PRICE_EVENT = 200_000000;
    uint256 public constant WORKER_PRICE_DEC = 800_000000;
    uint256 public constant WORKER_PRICE_JAN = 900_000000;
    uint256 public constant SUIT_PRICE_NOV = 4000_000000;
    uint256 public constant SUIT_PRICE_EVENT = 2000_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)
    IEarlierSeatRound public immutable round1; // RetiumSeatPresale
    IEarlierSeatRound public immutable round2; // RetiumSeatPresaleV2

    // ============ 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 earlier rounds so the claim indexer decodes all three
    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 (in the future, before EVENT_START)
     * @param _hardCapUSD Maximum USD to raise (6 decimals), multiple of PRICE_UNIT
     * @param _admin Admin address for emergency pause + finalize
     * @param _round1 First-round RetiumSeatPresale; its buyers are refused
     * @param _round2 Second-round RetiumSeatPresaleV2; its buyers are refused
     */
    constructor(
        address _usdc,
        address _usdt,
        address _treasury,
        uint256 _startTime,
        uint256 _hardCapUSD,
        address _admin,
        address _round1,
        address _round2
    ) {
        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(_startTime < EVENT_START, "Start must be before event");
        require(_hardCapUSD > 0, "Invalid hard cap");
        require(_hardCapUSD % PRICE_UNIT == 0, "Cap not multiple of price unit");
        require(_admin != address(0), "Invalid admin");
        require(_round1.code.length > 0, "Invalid round 1");
        require(_round2.code.length > 0, "Invalid round 2");
        require(_round1 != _round2, "Rounds must differ");

        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;
        round1 = IEarlierSeatRound(_round1);
        round2 = IEarlierSeatRound(_round2);

        // Fails the deploy if an address does not answer getSeat
        round1.getSeat(address(0));
        round2.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 < EVENT_START) return (WORKER_PRICE_NOV, SUIT_PRICE_NOV, EVENT_START - 1);
        if (t < DEC_START) return (WORKER_PRICE_EVENT, SUIT_PRICE_EVENT, 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();
        if (_hasEarlierSeat(msg.sender)) 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 any round)
    function canBuy(address buyer) external view returns (bool) {
        if (purchases[buyer].role != Role.None) return false;
        return !_hasEarlierSeat(buyer);
    }

    /// @dev True if `buyer` holds a seat in round 1 or round 2
    function _hasEarlierSeat(address buyer) private view returns (bool) {
        (uint8 role1, ) = round1.getSeat(buyer);
        if (role1 != 0) return true;
        (uint8 role2, ) = round2.getSeat(buyer);
        return role2 != 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.