// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract PriceFeed { uint256 public constant MAX_AGE = 3 days; struct Price { uint256 priceUsd18; uint256 updatedAt; } address public admin; mapping(address => bool) public reporters; mapping(address => mapping(uint256 => Price)) internal prices; event PricePosted(address indexed collection, uint256 indexed tokenId, uint256 priceUsd18); event ReporterSet(address indexed reporter, bool ok); constructor(address admin_) { require(admin_ != address(0), "admin zero"); admin = admin_; } function setReporter(address r, bool ok) external { require(msg.sender == admin, "not admin"); reporters[r] = ok; emit ReporterSet(r, ok); } function post(address collection, uint256[] calldata tokenIds, uint256[] calldata pricesUsd18) external { require(reporters[msg.sender], "not reporter"); require(tokenIds.length == pricesUsd18.length, "length mismatch"); for (uint256 i = 0; i < tokenIds.length; i++) { prices[collection][tokenIds[i]] = Price(pricesUsd18[i], block.timestamp); emit PricePosted(collection, tokenIds[i], pricesUsd18[i]); } } function priceOf(address collection, uint256 tokenId) external view returns (uint256 priceUsd18, uint256 updatedAt) { Price memory p = prices[collection][tokenId]; return (p.priceUsd18, p.updatedAt); } function freshPrice(address collection, uint256 tokenId) external view returns (uint256) { Price memory p = prices[collection][tokenId]; require(p.priceUsd18 > 0, "no price"); require(block.timestamp - p.updatedAt <= MAX_AGE, "stale price"); return p.priceUsd18; } }