// SPDX-License-Identifier: MIT pragma solidity ^0.8.26; import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import {KibbleToken} from "./KibbleToken.sol"; import {Oracle} from "./Oracle.sol"; import {PoolSwapper} from "./libraries/PoolSwapper.sol"; /// @title Burner /// @notice Receives consumed HYPE power, swaps it for KIBBLE in the pool and burns it; also burns the KIBBLE /// consumed as power directly (docs §4, §9, §11). /// @dev `burn()` is public. Buybacks stop at TWAP × (1 + 10%) (MAX_TWAP_DEVIATION_BPS) so a public burn cannot be /// sandwiched at an arbitrary price; HYPE not spent stays here for the next call. contract Burner is PoolSwapper, ReentrancyGuard { /// @notice docs §11. `hypeSpent` = 0 for KIBBLE burned directly (power paid in KIBBLE, dust). event Burned(uint256 kibbleAmount, uint256 hypeSpent); Oracle public immutable oracle; /// @notice Total KIBBLE burned by the protocol (direct burns + buybacks). uint256 public totalBurned; /// @notice KIBBLE burned directly (power paid in KIBBLE, genesis / zap dust). uint256 public totalBurnedDirect; /// @notice KIBBLE bought back with HYPE and burned. uint256 public totalBurnedBuyback; /// @notice HYPE spent on buybacks. uint256 public totalHypeSpent; constructor(IPoolManager poolManager_, KibbleToken kibble_, Oracle oracle_) PoolSwapper(poolManager_, address(kibble_)) { oracle = oracle_; } receive() external payable {} /// @notice Burns all KIBBLE held, then buys back KIBBLE with all HYPE held (within the TWAP band) and burns it. /// Anyone can call (docs §4 "100% of the HYPE consumed is used for KIBBLE buyback and burn"). function burn() external nonReentrant returns (uint256 burnedDirect, uint256 bought, uint256 hypeSpent) { KibbleToken k = KibbleToken(kibbleToken); burnedDirect = k.balanceOf(address(this)); if (burnedDirect > 0) { k.burn(burnedDirect); totalBurned += burnedDirect; totalBurnedDirect += burnedDirect; emit Burned(burnedDirect, 0); } if (!oracle.initialized()) return (burnedDirect, 0, 0); oracle.update(); uint256 hype = address(this).balance; if (hype == 0) return (burnedDirect, 0, 0); (hypeSpent, bought) = _swapExactIn(true, hype, _buyLimit(oracle.twap())); if (bought > 0) { k.burn(bought); totalBurned += bought; totalBurnedBuyback += bought; totalHypeSpent += hypeSpent; emit Burned(bought, hypeSpent); } } /// @notice HYPE waiting to be spent on buybacks. function pendingHype() external view returns (uint256) { return address(this).balance; } }