// SPDX-License-Identifier: MIT pragma solidity 0.8.30; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; /// @notice FYNX with a block-based issuance schedule and six fixed allocation wallets. contract FynxEmission is ERC20, AccessControl { bytes32 public constant EMISSION_ROLE = keccak256("EMISSION_ROLE"); uint256 public constant CAP = 1_000_000_000 ether; uint256 public constant LAST_ELIGIBLE_OFFSET = 591_718_750; uint256 public immutable startBlock; uint256 public lastProcessedBlock; address[6] public allocationWallets; error InvalidConfiguration(); error InvalidBatch(); error InvalidBlockAnchor(); event EmissionBatch( uint256 indexed firstBlock, uint256 indexed lastBlock, bytes32 indexed blockHash, uint256 amount ); constructor(uint256 firstEligibleBlock, address[6] memory wallets, address admin, address operator) ERC20("FynEx Ecosystem Token", "FYNX") { if (firstEligibleBlock == 0 || admin == address(0) || operator == address(0)) { revert InvalidConfiguration(); } for (uint256 i; i < wallets.length; ++i) { if (wallets[i] == address(0) || wallets[i] == address(this)) revert InvalidConfiguration(); for (uint256 j; j < i; ++j) { if (wallets[i] == wallets[j]) revert InvalidConfiguration(); } allocationWallets[i] = wallets[i]; } startBlock = firstEligibleBlock; // A historical start accrues entitlement; only an operator batch can mint it. lastProcessedBlock = firstEligibleBlock - 1; _grantRole(DEFAULT_ADMIN_ROLE, admin); _grantRole(EMISSION_ROLE, operator); } function previewAccrued(uint256 height) public view returns (uint256) { if (height < startBlock) return 0; uint256 eligible = height - startBlock + 1; if (eligible <= 120_000_000) return eligible * 2.5 ether; if (eligible <= 240_000_000) return 300_000_000 ether + (eligible - 120_000_000) * 2 ether; if (eligible <= 360_000_000) return 540_000_000 ether + (eligible - 240_000_000) * 1.6 ether; if (eligible <= 480_000_000) return 732_000_000 ether + (eligible - 360_000_000) * 1.28 ether; if (eligible >= LAST_ELIGIBLE_OFFSET) return CAP; return 885_600_000 ether + (eligible - 480_000_000) * 1.024 ether; } function previewMintable(uint256 height) external view returns (uint256 total, uint256[6] memory parts) { total = _mintable(height); parts = _split(total); } /// @dev The operator submits only heights confirmed by HDWallet as finalized. /// The EVM blockhash check additionally binds the batch to a recent canonical header. function mintAccruedBatch(uint256 expectedPrevious, uint256 height, bytes32 finalizedHash) external onlyRole(EMISSION_ROLE) returns (uint256 amount) { if (expectedPrevious != lastProcessedBlock || height <= expectedPrevious) revert InvalidBatch(); if (height >= block.number || finalizedHash == bytes32(0) || blockhash(height) != finalizedHash) { revert InvalidBlockAnchor(); } amount = _mintable(height); if (amount == 0) revert InvalidBatch(); lastProcessedBlock = height; uint256[6] memory parts = _split(amount); for (uint256 i; i < parts.length; ++i) { _mint(allocationWallets[i], parts[i]); } emit EmissionBatch(expectedPrevious + 1, height, finalizedHash, amount); } function _mintable(uint256 height) private view returns (uint256) { if (height <= lastProcessedBlock) return 0; return previewAccrued(height) - previewAccrued(lastProcessedBlock); } function _split(uint256 total) private pure returns (uint256[6] memory) { return [total * 35 / 100, total * 30 / 100, total * 15 / 100, total * 10 / 100, total * 5 / 100, total * 5 / 100]; } }