// SPDX-License-Identifier: MIT pragma solidity 0.8.24; interface IERC20Min { function transferFrom(address from, address to, uint256 amount) external returns (bool); function balanceOf(address account) external view returns (uint256); } /// @title HashfortPlans: Pro and Team plans for Hashfort, paid in USDG on Robinhood Chain. /// @notice No admin and no upgrade. The token, the treasury and both prices are fixed at deployment, so nobody can /// change what a plan costs or where the money goes. Paying moves USDG straight from the payer to the treasury /// (this contract never holds funds) and extends the account's plan by 30 days per month bought. /// Anyone may pay for any account (a friend, a team lead, or a vault paying for itself). /// Team includes everything in Pro. Holding at least `holderThreshold` of the HASHFORT token also gives Pro, /// with no payment: planOf() reads the account's HASHFORT balance on chain, so the token's utility is checkable here. contract HashfortPlans { uint8 public constant PRO = 1; uint8 public constant TEAM = 2; uint32 public constant PERIOD = 30 days; uint32 public constant MAX_MONTHS = 24; IERC20Min public immutable token; address public immutable treasury; uint256 public immutable proPrice; // per 30 days, in token units uint256 public immutable teamPrice; // per 30 days, in token units IERC20Min public immutable hashfort; // the HASHFORT token uint256 public immutable holderThreshold; // HASHFORT (in its smallest units) that gives Pro without paying mapping(address => uint64) public proUntil; mapping(address => uint64) public teamUntil; event Purchased(address indexed account, uint8 indexed plan, uint32 months, uint256 paid, uint64 until, address indexed payer); error BadPlan(); error BadMonths(); error PaymentFailed(); constructor(IERC20Min token_, address treasury_, uint256 proPrice_, uint256 teamPrice_, IERC20Min hashfort_, uint256 holderThreshold_) { require(address(token_) != address(0) && treasury_ != address(0) && proPrice_ > 0 && teamPrice_ > 0, "config"); require(address(hashfort_) != address(0) && holderThreshold_ > 0, "holder config"); hashfort = hashfort_; holderThreshold = holderThreshold_; token = token_; treasury = treasury_; proPrice = proPrice_; teamPrice = teamPrice_; } /// @notice Buy `months` x 30 days of `plan` (1 = Pro, 2 = Team) for `account`. Approve the token first. function buy(address account, uint8 plan, uint32 months) external returns (uint64 until) { if (plan != PRO && plan != TEAM) revert BadPlan(); if (months == 0 || months > MAX_MONTHS) revert BadMonths(); uint256 amount = (plan == PRO ? proPrice : teamPrice) * months; (bool ok, bytes memory r) = address(token).call(abi.encodeWithSelector(IERC20Min.transferFrom.selector, msg.sender, treasury, amount)); if (!ok || (r.length != 0 && !abi.decode(r, (bool)))) revert PaymentFailed(); mapping(address => uint64) storage m = plan == PRO ? proUntil : teamUntil; uint64 start = m[account] > block.timestamp ? m[account] : uint64(block.timestamp); until = start + uint64(PERIOD) * months; m[account] = until; emit Purchased(account, plan, months, amount, until, msg.sender); } /// @return plan 0 = Free, 1 = Pro, 2 = Team (Team wins), and when it ends (type(uint64).max = while holding HASHFORT). function planOf(address account) external view returns (uint8 plan, uint64 until) { if (teamUntil[account] > block.timestamp) return (TEAM, teamUntil[account]); if (proUntil[account] > block.timestamp) return (PRO, proUntil[account]); if (isHolder(account)) return (PRO, type(uint64).max); return (0, 0); } /// @return true when the account holds at least holderThreshold HASHFORT right now. function isHolder(address account) public view returns (bool) { (bool ok, bytes memory r) = address(hashfort).staticcall(abi.encodeWithSelector(IERC20Min.balanceOf.selector, account)); return ok && r.length >= 32 && abi.decode(r, (uint256)) >= holderThreshold; } }