{
    "Function": "slitherConstructorConstantVariables",
    "File": "src/kuma-protocol/KIBToken.sol",
    "Parent Contracts": [
        "lib/openzeppelin-contracts/contracts/proxy/utils/UUPSUpgradeable.sol",
        "lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Upgrade.sol",
        "lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/ERC20PermitUpgradeable.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/EIP712Upgradeable.sol",
        "src/kuma-protocol/interfaces/IKIBToken.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/IERC20PermitUpgradeable.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/IERC20MetadataUpgradeable.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/IERC20Upgradeable.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract KIBToken is IKIBToken, ERC20PermitUpgradeable, UUPSUpgradeable {\n    using Roles for bytes32;\n    using WadRayMath for uint256;\n\n    uint256 public constant MAX_YIELD = 1e29;\n    uint256 public constant MAX_EPOCH_LENGTH = 365 days;\n    uint256 public constant MIN_YIELD = WadRayMath.RAY;\n\n    IKUMAAddressProvider private _KUMAAddressProvider;\n    bytes32 private _riskCategory;\n    uint256 private _yield;\n    uint256 private _previousEpochCumulativeYield;\n    uint256 private _cumulativeYield;\n    uint256 private _lastRefresh;\n    uint256 private _epochLength;\n\n    uint256 private _totalBaseSupply; // Underlying assets supply (does not include rewards)\n\n    mapping(address => uint256) private _baseBalances; // (does not include rewards)\n    mapping(address => mapping(address => uint256)) private _allowances;\n\n    modifier onlyRole(bytes32 role) {\n        if (!_KUMAAddressProvider.getAccessController().hasRole(role, msg.sender)) {\n            revert Errors.ACCESS_CONTROL_ACCOUNT_IS_MISSING_ROLE(msg.sender, role);\n        }\n        _;\n    }\n\n    constructor() initializer {}\n\n    /**\n     * @notice The default value of {decimals} is 18. To select a different value for\n     * {decimals} you should overload it.\n     * @param name Token name.\n     * @param symbol Tokne symbol.\n     * @param epochLength Rebase intervals in seconds.\n     * @param KUMAAddressProvider KUMAAddressProvider.\n     */\n    function initialize(\n        string memory name,\n        string memory symbol,\n        uint256 epochLength,\n        IKUMAAddressProvider KUMAAddressProvider,\n        bytes4 currency,\n        bytes4 country,\n        uint64 term\n    ) external override initializer {\n        if (epochLength == 0) {\n            revert Errors.EPOCH_LENGTH_CANNOT_BE_ZERO();\n        }\n        if (address(KUMAAddressProvider) == address(0)) {\n            revert Errors.CANNOT_SET_TO_ADDRESS_ZERO();\n        }\n        if (currency == bytes4(0) || country == bytes4(0) || term == 0) {\n            revert Errors.WRONG_RISK_CATEGORY();\n        }\n        _yield = MIN_YIELD;\n        _epochLength = epochLength;\n        _lastRefresh = block.timestamp % epochLength == 0\n            ? block.timestamp\n            : (block.timestamp / epochLength) * epochLength + epochLength;\n        _cumulativeYield = MIN_YIELD;\n        _previousEpochCumulativeYield = MIN_YIELD;\n        _KUMAAddressProvider = KUMAAddressProvider;\n        _riskCategory = keccak256(abi.encode(currency, country, term));\n        __ERC20_init(name, symbol);\n        __ERC20Permit_init(name);\n\n        emit CumulativeYieldUpdated(0, MIN_YIELD);\n        emit EpochLengthSet(0, epochLength);\n        emit KUMAAddressProviderSet(address(KUMAAddressProvider));\n        emit PreviousEpochCumulativeYieldUpdated(0, MIN_YIELD);\n        emit RiskCategorySet(_riskCategory);\n        emit YieldUpdated(0, MIN_YIELD);\n    }\n\n    /**\n     * @param epochLength New rebase interval.\n     */\n    function setEpochLength(uint256 epochLength) external override onlyRole(Roles.KUMA_SET_EPOCH_LENGTH_ROLE) {\n        if (epochLength == 0) {\n            revert Errors.EPOCH_LENGTH_CANNOT_BE_ZERO();\n        }\n        if (epochLength > MAX_EPOCH_LENGTH) {\n            revert Errors.NEW_EPOCH_LENGTH_TOO_HIGH();\n        }\n        if (epochLength > _epochLength) {\n            _refreshCumulativeYield();\n            _refreshYield();\n        }\n        emit EpochLengthSet(_epochLength, epochLength);\n        _epochLength = epochLength;\n    }\n\n    /**\n     * @notice Updates yield based on current yield and oracle reference rate.\n     */\n    function refreshYield() external override {\n        _refreshCumulativeYield();\n        _refreshYield();\n    }\n\n    /**\n     * @dev See {ERC20-_mint}.\n     * @notice Following logic has been added/updated :\n     * - Cumulative yield refresh\n     */\n    function mint(address account, uint256 amount)\n        external\n        override\n        onlyRole(Roles.KUMA_MINT_ROLE.toGranularRole(_riskCategory))\n    {\n        if (block.timestamp < _lastRefresh) {\n            revert Errors.START_TIME_NOT_REACHED();\n        }\n        if (account == address(0)) {\n            revert Errors.ERC20_MINT_TO_THE_ZERO_ADDRESS();\n        }\n        _refreshCumulativeYield();\n        _refreshYield();\n\n        uint256 newAccountBalance = this.balanceOf(account) + amount;\n        uint256 newBaseBalance = WadRayMath.wadToRay(newAccountBalance).rayDiv(_previousEpochCumulativeYield); // Store baseAmount in 27 decimals\n\n        if (amount > 0) {\n            _totalBaseSupply += newBaseBalance - _baseBalances[account];\n            _baseBalances[account] = newBaseBalance;\n        }\n\n        emit Transfer(address(0), account, amount);\n    }\n\n    /**\n     * @dev See {ERC20-_burn}.\n     * @notice Following logic has been added/updated :\n     * - Cumulative yield refresh\n     * - Destroy baseAmount instead of amount\n     */\n    function burn(address account, uint256 amount)\n        external\n        override\n        onlyRole(Roles.KUMA_BURN_ROLE.toGranularRole(_riskCategory))\n    {\n        if (account == address(0)) {\n            revert Errors.ERC20_BURN_FROM_THE_ZERO_ADDRESS();\n        }\n        _refreshCumulativeYield();\n        _refreshYield();\n\n        uint256 startingAccountBalance = this.balanceOf(account);\n        if (startingAccountBalance < amount) {\n            revert Errors.ERC20_BURN_AMOUNT_EXCEEDS_BALANCE();\n        }\n\n        uint256 newAccountBalance = startingAccountBalance - amount;\n        uint256 newBaseBalance = WadRayMath.wadToRay(newAccountBalance).rayDiv(_previousEpochCumulativeYield);\n        if (amount > 0) {\n            _totalBaseSupply -= _baseBalances[account] - newBaseBalance;\n            _baseBalances[account] = newBaseBalance;\n        }\n\n        emit Transfer(account, address(0), amount);\n    }\n\n    function getKUMAAddressProvider() external view returns (IKUMAAddressProvider) {\n        return _KUMAAddressProvider;\n    }\n\n    function getRiskCategory() external view returns (bytes32) {\n        return _riskCategory;\n    }\n\n    /**\n     * @return Current yield\n     */\n    function getYield() external view override returns (uint256) {\n        return _yield;\n    }\n\n    /**\n     * @return Timestamp of last rebase.\n     */\n    function getLastRefresh() external view override returns (uint256) {\n        return _lastRefresh;\n    }\n\n    /**\n     * @return Current baseTotalSupply.\n     */\n    function getTotalBaseSupply() external view override returns (uint256) {\n        return _totalBaseSupply;\n    }\n\n    /**\n     * @return User base balance\n     */\n    function getBaseBalance(address account) external view override returns (uint256) {\n        return _baseBalances[account];\n    }\n\n    /**\n     * @return Current epoch length.\n     */\n    function getEpochLength() external view override returns (uint256) {\n        return _epochLength;\n    }\n\n    /**\n     * @return Last updated cumulative yield\n     */\n    function getCumulativeYield() external view override returns (uint256) {\n        return _cumulativeYield;\n    }\n\n    /**\n     * @return Cumulative yield calculated at last epoch\n     */\n    function getUpdatedCumulativeYield() external view override returns (uint256) {\n        return _calculatePreviousEpochCumulativeYield();\n    }\n\n    /**\n     * @return Timestamp rounded down to the previous epoch length.\n     */\n    function getPreviousEpochTimestamp() external view returns (uint256) {\n        return _getPreviousEpochTimestamp();\n    }\n\n    /**\n     * @dev See {ERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view override(ERC20Upgradeable, IERC20Upgradeable) returns (uint256) {\n        return WadRayMath.rayToWad(_baseBalances[account].rayMul(_calculatePreviousEpochCumulativeYield()));\n    }\n\n    /**\n     * @dev See {ERC20-symbol}.\n     */\n    function totalSupply() public view override(ERC20Upgradeable, IERC20Upgradeable) returns (uint256) {\n        return WadRayMath.rayToWad(_totalBaseSupply.rayMul(_calculatePreviousEpochCumulativeYield()));\n    }\n\n    /**\n     * @dev See {ERC20-_transfer}.\n     */\n    function _transfer(address from, address to, uint256 amount) internal override {\n        if (from == address(0)) {\n            revert Errors.ERC20_TRANSFER_FROM_THE_ZERO_ADDRESS();\n        }\n        if (to == address(0)) {\n            revert Errors.ERC20_TRANSER_TO_THE_ZERO_ADDRESS();\n        }\n        _refreshCumulativeYield();\n        _refreshYield();\n\n        uint256 startingFromBalance = this.balanceOf(from);\n        if (startingFromBalance < amount) {\n            revert Errors.ERC20_TRANSFER_AMOUNT_EXCEEDS_BALANCE();\n        }\n        uint256 newFromBalance = startingFromBalance - amount;\n        uint256 newToBalance = this.balanceOf(to) + amount;\n\n        uint256 previousEpochCumulativeYield_ = _previousEpochCumulativeYield;\n        uint256 newFromBaseBalance = WadRayMath.wadToRay(newFromBalance).rayDiv(previousEpochCumulativeYield_);\n        uint256 newToBaseBalance = WadRayMath.wadToRay(newToBalance).rayDiv(previousEpochCumulativeYield_);\n\n        if (amount > 0) {\n            _totalBaseSupply -= (_baseBalances[from] - newFromBaseBalance);\n            _totalBaseSupply += (newToBaseBalance - _baseBalances[to]);\n            _baseBalances[from] = newFromBaseBalance;\n            _baseBalances[to] = newToBaseBalance;\n        }\n\n        emit Transfer(from, to, amount);\n    }\n\n    /**\n     * @notice Updates the internal state variables after accounting for newly received tokens.\n     */\n    function _refreshCumulativeYield() private {\n        uint256 newPreviousEpochCumulativeYield = _calculatePreviousEpochCumulativeYield();\n        uint256 newCumulativeYield = _calculateCumulativeYield();\n\n        if (newPreviousEpochCumulativeYield != _previousEpochCumulativeYield) {\n            emit PreviousEpochCumulativeYieldUpdated(_previousEpochCumulativeYield, newPreviousEpochCumulativeYield);\n            _previousEpochCumulativeYield = newPreviousEpochCumulativeYield;\n        }\n        if (newCumulativeYield != _cumulativeYield) {\n            emit CumulativeYieldUpdated(_cumulativeYield, newCumulativeYield);\n            _cumulativeYield = newCumulativeYield;\n        }\n\n        _lastRefresh = block.timestamp;\n    }\n\n    /**\n     * @notice Updates yield based on current yield and oracle reference rate.\n     */\n    function _refreshYield() private {\n        IKUMASwap KUMASwap = IKUMASwap(_KUMAAddressProvider.getKUMASwap(_riskCategory));\n        uint256 yield_ = _yield;\n        if (KUMASwap.isExpired() || KUMASwap.isDeprecated()) {\n            _yield = MIN_YIELD;\n            emit YieldUpdated(yield_, MIN_YIELD);\n            return;\n        }\n        uint256 referenceRate = IMCAGRateFeed(_KUMAAddressProvider.getRateFeed()).getRate(_riskCategory);\n        uint256 minCoupon = KUMASwap.getMinCoupon();\n        uint256 lowestYield = referenceRate < minCoupon ? referenceRate : minCoupon;\n        if (lowestYield != yield_) {\n            _yield = lowestYield;\n            emit YieldUpdated(yield_, lowestYield);\n        }\n    }\n\n    /**\n     * @return Timestamp rounded down to the previous epoch length.\n     */\n    function _getPreviousEpochTimestamp() private view returns (uint256) {\n        uint256 epochLength = _epochLength;\n        uint256 epochTimestampRemainder = block.timestamp % epochLength;\n        if (epochTimestampRemainder == 0) {\n            return block.timestamp;\n        }\n        return (block.timestamp / epochLength) * epochLength;\n    }\n\n    /**\n     * @notice Helper function to calculate cumulativeYield at call timestamp.\n     * @return Updated cumulative yield\n     */\n    function _calculateCumulativeYield() private view returns (uint256) {\n        uint256 timeElapsed = block.timestamp - _lastRefresh;\n        if (timeElapsed == 0) return _cumulativeYield;\n        return _yield.rayPow(timeElapsed).rayMul(_cumulativeYield);\n    }\n\n    /**\n     * @notice Helper function to calculate previousEpochCumulativeYield at call timestamp.\n     * @return Updated previous epoch cumulative yield.\n     */\n    function _calculatePreviousEpochCumulativeYield() private view returns (uint256) {\n        uint256 previousEpochTimestamp = _getPreviousEpochTimestamp();\n        if (previousEpochTimestamp < _lastRefresh) {\n            return _previousEpochCumulativeYield;\n        }\n        uint256 timeElapsedToEpoch = previousEpochTimestamp - _lastRefresh;\n        return _yield.rayPow(timeElapsedToEpoch).rayMul(_cumulativeYield);\n    }\n\n    function _authorizeUpgrade(address newImplementation) internal view override onlyRole(Roles.KUMA_MANAGER_ROLE) {}\n}"
}