// SPDX-License-Identifier: MIT pragma solidity ^0.8.26; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {KibbleConstants as K} from "./libraries/KibbleConstants.sol"; /// @title KibbleToken /// @notice $KIBBLE, ERC-20, 18 decimals (docs §2, §11). Mint restricted to `Emission` (mining rewards) and to the /// one-time genesis mint by `Genesis`. Anyone can burn their own tokens. No owner, no admin. contract KibbleToken is ERC20 { error NotEmission(); error NotGenesis(); error GenesisAlreadyMinted(); error MaxSupplyExceeded(); /// @notice The only address allowed to mint mining rewards (docs §11). address public immutable emission; /// @notice The only address allowed to perform the 1,000,000 genesis mint (docs §6). address public immutable genesis; /// @notice True once the genesis mint happened. bool public genesisMinted; /// @notice Total ever minted (genesis + emission). Never exceeds MAX_SUPPLY. uint256 public totalMinted; /// @notice Total ever burned through `burn` (protocol burns and user burns). uint256 public totalBurned; constructor(address emission_, address genesis_) ERC20("KIBBLE", "KIBBLE") { emission = emission_; genesis = genesis_; } /// @notice Max supply, docs §2: 10,000,000 KIBBLE. function maxSupply() external pure returns (uint256) { return K.MAX_SUPPLY; } /// @notice Mints mining rewards. Only `Emission` (docs §11 "mint restricted to Emission"). function mint(address to, uint256 amount) external { if (msg.sender != emission) revert NotEmission(); _mintCapped(to, amount); } /// @notice One-time genesis mint of 1,000,000 KIBBLE to seed the pool (docs §6). Only `Genesis`. function mintGenesis(address to) external { if (msg.sender != genesis) revert NotGenesis(); if (genesisMinted) revert GenesisAlreadyMinted(); genesisMinted = true; _mintCapped(to, K.GENESIS_SUPPLY); } /// @notice Burns `amount` of the caller's KIBBLE (docs §11 "public burn"). function burn(uint256 amount) external { _burn(msg.sender, amount); totalBurned += amount; } function _mintCapped(address to, uint256 amount) private { uint256 minted = totalMinted + amount; if (minted > K.MAX_SUPPLY) revert MaxSupplyExceeded(); totalMinted = minted; _mint(to, amount); } }