Verified contractExactMIT
RetiumSeatPresale
Address0x14504f76216f741aea2ec392260500f15f2e95d9
- Balance
0 ETH
- Transactions
29
- 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
- 25,850,368
- Creation transaction
- 0xdb080a5115…bdf9751302
2 files
- src/RetiumSeatPresale.solmain13.47 KB
- src/interfaces/IERC20.sol763 B
src/RetiumSeatPresale.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./interfaces/IERC20.sol";
/**
* @title RetiumSeatPresale
* @notice Single-purpose, minimal, immutable presale contract for Retium
* validator seat licenses. Fork of RetiumPresale (token round) with the
* entitlement math removed and seat semantics added.
* @dev Accepts USDC and (optionally) USDT. Both are 6-decimal, 1:1-USD
* stablecoins, so contributions sum into the same 6-decimal accounting.
* Deploy with `usdt = address(0)` for USDC-only, or pass mainnet USDT to
* also accept it. USDT is immutable, decide at deploy time.
*
* Seat semantics:
* - Exactly 100 USDC buys a Worker seat; exactly 1000 USDC buys a Suit seat.
* Any other amount reverts — no change given, no partial seats.
* - One wallet = one seat, forever. A second purchase from the same address
* reverts regardless of role. (Enforced again on the Retium side at claim.)
* - No token or NFT is minted on Ethereum; the paying address is the proof of
* purchase. Nothing on the ETH side is transferable — resale exists only on
* Retium after claim (SeatTransfer).
* - Single shared hard cap, first come first served — no per-role allocation.
* Both prices are multiples of $100 and the cap must be too, so the
* remainder is always sellable: once remaining < $1000 only Workers fit.
*
* Key properties (inherited from the token-round contract):
* - Funds are forwarded immediately to treasury (no custody, nothing refundable)
* - This contract is accounting-only, never holds funds
* - No minting, no withdrawals, no ETH acceptance
* - Sale is permanently locked after endTime
* - F-8: token transfers use a SafeERC20-style call that tolerates
* non-standard ERC-20s like mainnet USDT (whose transferFrom returns no value)
*/
contract RetiumSeatPresale {
// ============ Seat Configuration ============
enum Role {
None, // sentinel: address has not purchased
Worker,
Suit
}
uint256 public constant WORKER_PRICE_USD = 100_000000; // 100 USDC (6 decimals)
uint256 public constant SUIT_PRICE_USD = 1000_000000; // 1000 USDC (6 decimals)
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 endTime;
uint256 public immutable hardCapUSD; // In USDC decimals (6)
// ============ 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 ============
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();
// Note: distinct from the SaleFinalized/SalePaused *events* above — Solidity
// does not allow an error and an event to share a name.
error SaleIsFinalized();
error SaleIsPaused();
error HardCapExceeded();
error InvalidAmount();
error AlreadyPurchased();
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 > endTime) 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 multisig address (receives funds immediately)
* @param _startTime Unix timestamp when sale starts
* @param _endTime Unix timestamp when sale ends
* @param _hardCapUSD Maximum USD to raise (in USDC decimals, 6); must be a
* multiple of WORKER_PRICE_USD so the pot can always sell out exactly
* @param _admin Admin address for emergency pause
*/
constructor(
address _usdc,
address _usdt,
address _treasury,
uint256 _startTime,
uint256 _endTime,
uint256 _hardCapUSD,
address _admin
) {
require(_usdc != address(0), "Invalid USDC");
require(_treasury != address(0), "Invalid treasury");
require(_startTime > block.timestamp, "Start must be future");
require(_endTime > _startTime, "End must be after start");
require(_hardCapUSD > 0, "Invalid hard cap");
// A cap that is not a multiple of the Worker price would strand an
// unsellable remainder below the smallest seat price.
require(_hardCapUSD % WORKER_PRICE_USD == 0, "Cap not multiple of seat price");
require(_admin != address(0), "Invalid admin");
// F-27: the accounting hard-codes the 6-decimal, 1:1-USD stablecoin
// assumption. A misconfigured token with different decimals would let a
// buyer pay the wrong real-world price for a seat, so enforce 6 decimals
// at construction for every accepted token.
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); // optional; address(0) disables USDT purchases
treasury = _treasury;
startTime = _startTime;
endTime = _endTime;
hardCapUSD = _hardCapUSD;
admin = _admin;
}
// ============ Purchase Functions ============
/**
* @notice Purchase a validator seat with USDC
* @param usdAmount Exactly WORKER_PRICE_USD (Worker) or SUIT_PRICE_USD (Suit)
* @dev Funds are immediately forwarded to treasury
*/
function buySeatUSDC(uint256 usdAmount) external {
_buySeat(usdc, usdAmount);
}
/**
* @notice Purchase a validator seat with USDT (only if USDT is configured)
* @param usdAmount Exactly WORKER_PRICE_USD (Worker) or SUIT_PRICE_USD (Suit)
* @dev Funds are immediately forwarded to treasury
*/
function buySeatUSDT(uint256 usdAmount) external {
if (address(usdt) == address(0)) revert TokenNotAccepted();
_buySeat(usdt, usdAmount);
}
/**
* @dev Shared purchase logic for any accepted 6-decimal, 1:1-USD stablecoin.
* The exact payment amount selects the role; anything else reverts.
*/
function _buySeat(IERC20 token, uint256 usdAmount) private whenNotPaused whenSaleActive {
if (purchases[msg.sender].role != Role.None) revert AlreadyPurchased();
Role role;
if (usdAmount == WORKER_PRICE_USD) {
role = Role.Worker;
} else if (usdAmount == SUIT_PRICE_USD) {
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;
}
// Transfer the stablecoin directly to treasury (no custody). Uses a
// SafeERC20-style call so non-standard tokens (mainnet USDT returns no
// value from transferFrom) work as well as standard ones (USDC).
_safeTransferFrom(token, msg.sender, treasury, usdAmount);
emit SeatPurchased(msg.sender, uint8(role), block.timestamp);
}
/**
* @dev SafeERC20-style transferFrom without the OpenZeppelin dependency.
* Reverts unless: the token has contract code, the low-level call
* succeeds, and any returned data decodes to `true`. This accepts both
* standard ERC-20s (return bool, e.g. USDC) and non-standard ones that
* return nothing (e.g. mainnet USDT), while still reverting on an
* explicit `false` or a reverting token.
*/
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)
* @dev Can only be called after endTime, and only by the admin.
* F-29: previously permissionless — a griefer could finalize the instant
* endTime passed, permanently disabling emergencyPause/Unpause. Gating to
* the admin keeps finalization timing under the operator's control.
*/
function finalizeSale() external onlyAdmin {
if (finalized) revert AlreadyFinalized();
if (block.timestamp <= endTime) revert SaleNotEnded();
finalized = true;
emit SaleFinalized(totalRaisedUSD, block.timestamp);
}
// ============ Emergency Controls ============
/**
* @notice Pause the sale (emergency only)
* @dev Blocked once the sale is finalized. Purchases are already blocked
* after endTime regardless of pause state.
*/
function emergencyPause() external onlyAdmin {
if (finalized) revert AlreadyFinalized();
paused = true;
emit SalePaused(block.timestamp);
}
/**
* @notice Unpause the sale
*/
function emergencyUnpause() external onlyAdmin {
if (finalized) revert AlreadyFinalized();
paused = false;
emit SaleUnpaused(block.timestamp);
}
// ============ View Functions ============
/**
* @notice Get a buyer's seat purchase
* @param buyer Address to query
* @return role Purchased role (0 = none, 1 = Worker, 2 = Suit)
* @return timestamp Purchase timestamp (0 if none)
*/
function getSeat(address buyer) external view returns (uint8 role, uint40 timestamp) {
Purchase memory p = purchases[buyer];
return (uint8(p.role), p.timestamp);
}
/**
* @notice Get current sale status
* @return isActive Whether purchases are currently allowed
* @return isPaused Whether sale is paused
* @return isFinalized Whether sale is finalized
* @return raised Total USD raised
* @return cap Hard cap in USD
* @return remaining USD remaining until hard cap
* @return workerSeats Worker seats sold so far
* @return suitSeats Suit seats sold so far
*/
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 <= endTime &&
!finalized &&
!paused;
isPaused = paused;
isFinalized = finalized;
raised = totalRaisedUSD;
cap = hardCapUSD;
remaining = hardCapUSD > totalRaisedUSD ? hardCapUSD - totalRaisedUSD : 0;
workerSeats = workerSeatsSold;
suitSeats = suitSeatsSold;
}
/**
* @notice Get time information
* @return start Sale start timestamp
* @return end Sale end timestamp
* @return current Current block timestamp
* @return hasStarted Whether sale has started
* @return hasEnded Whether sale has ended
*/
function getTimeInfo()
external
view
returns (
uint256 start,
uint256 end,
uint256 current,
bool hasStarted,
bool hasEnded
)
{
return (
startTime,
endTime,
block.timestamp,
block.timestamp >= startTime,
block.timestamp > endTime
);
}
// ============ Fallback ============
/// @notice Reject any ETH sent directly to contract
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.