// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; /// @title RoseVault /// @notice Minimal reentrancy guard (inlined — keeps the vault dependency-free). abstract contract ReentrancyGuard { uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status = _NOT_ENTERED; error ReentrancyGuardReentrantCall(); modifier nonReentrant() { if (_status == _ENTERED) revert ReentrancyGuardReentrantCall(); _status = _ENTERED; _; _status = _NOT_ENTERED; } } /// @notice RoseVault — trustless BNB escrow for the CertiK audit fund for the Bad Decisions (BAD) token. /// @dev Donations are locked until the funding goal is met. The owner /// CANNOT withdraw before finalization. If the deadline passes without /// the goal being met, every donor can refund in full. /// No proxy, no upgrade, no backdoor — immutable by design. contract RoseVault is ReentrancyGuard { /// @notice The project wallet that receives funds on successful funding. address public immutable owner; /// @notice Funding goal in BNB wei (40 BNB ≈ $30k at $750/BNB). uint256 public immutable goal; /// @notice Unix timestamp after which donations close. uint256 public immutable deadline; /// @notice Total BNB donated (wei). uint256 public totalContributed; /// @notice True once the goal is met and funding is finalized. bool public finalized; /// @notice True once the owner has withdrawn (prevents double-withdraw). bool public withdrawn; /// @notice BNB donated per address (wei). mapping(address => uint256) public contributions; /// @notice Whether an address has already refunded. mapping(address => bool) public refunded; event Contributed(address indexed contributor, uint256 amount, uint256 total); event Finalized(uint256 total); event Withdrawn(address indexed owner, uint256 amount); event Refunded(address indexed contributor, uint256 amount); error AfterDeadline(); error BeforeDeadline(); error AlreadyFinalized(); error NotFinalized(); error GoalNotMet(); error GoalAlreadyMet(); error NothingToRefund(); error AlreadyRefunded(); error AlreadyWithdrawn(); error ZeroContribution(); error NotOwner(); /// @param _owner The project wallet receiving funds on success. /// @param _goalWei Funding goal in BNB wei. /// @param _deadline Unix timestamp closing contributions. constructor(address _owner, uint256 _goalWei, uint256 _deadline) { require(_owner != address(0), "zero owner"); require(_goalWei > 0, "zero goal"); require(_deadline > block.timestamp, "deadline in past"); owner = _owner; goal = _goalWei; deadline = _deadline; } /// @notice Donate BNB to the audit fund. Locked until finalization. function contribute() external payable nonReentrant { if (block.timestamp > deadline) revert AfterDeadline(); if (finalized) revert AlreadyFinalized(); if (msg.value == 0) revert ZeroContribution(); contributions[msg.sender] += msg.value; totalContributed += msg.value; emit Contributed(msg.sender, msg.value, totalContributed); } /// @notice Finalize the funding round once the goal is met. Anyone can call. /// @dev Locks in success — after this, only the owner can withdraw. function finalize() external nonReentrant { if (finalized) revert AlreadyFinalized(); if (totalContributed < goal) revert GoalNotMet(); finalized = true; emit Finalized(totalContributed); } /// @notice Owner withdraws all BNB after successful finalization. /// @dev Cannot be called before the goal is met. One-time only. function withdraw() external nonReentrant { if (msg.sender != owner) revert NotOwner(); if (!finalized) revert NotFinalized(); if (withdrawn) revert AlreadyWithdrawn(); withdrawn = true; uint256 amount = address(this).balance; (bool ok, ) = owner.call{value: amount}(""); require(ok, "withdraw failed"); emit Withdrawn(owner, amount); } /// @notice Refund a donation in full if the deadline passed and the goal was missed. /// @dev Only available when the funding round failed. One refund per address. function refund() external nonReentrant { if (block.timestamp <= deadline) revert BeforeDeadline(); if (finalized) revert AlreadyFinalized(); if (refunded[msg.sender]) revert AlreadyRefunded(); uint256 amount = contributions[msg.sender]; if (amount == 0) revert NothingToRefund(); refunded[msg.sender] = true; contributions[msg.sender] = 0; (bool ok, ) = msg.sender.call{value: amount}(""); require(ok, "refund failed"); emit Refunded(msg.sender, amount); } /// @notice Returns true if refunds are currently available. function refundsOpen() external view returns (bool) { return block.timestamp > deadline && !finalized; } /// @notice Returns true if the owner can currently withdraw. function withdrawable() external view returns (bool) { return finalized && !withdrawn; } }