{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/UpsideStaking.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/access/Ownable.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract UpsideStaking is Ownable {\n    using SafeERC20 for IERC20Metadata;\n\n    event Claimed(address metaCoinAddress, uint256 rewardTokenAmount);\n    event Unstaked(address metaCoinAddress, uint256 tokenAmount);\n    event Staked(address metaCoinAddress, uint256 tokenAmount);\n    event RewardDistributed(address metaCoinAddress, uint256 rewardTokenAmount, bool distributed);\n    event ProtocolFeeRecipientSet(address oldRecipient, address newRecipient);\n    event ProtocolFeeClaimed(address metaCoinAddress, uint256 tokenAmountClaimed);\n    event WhitelistSet(address metaCoinAddress);\n\n    uint256 private constant MULTIPLIER = 1e18;\n\n    mapping(address metaCoinAddress => bool allowed) public whitelistedStakingTokens;\n    mapping(address metaCoinAddress => mapping(address walletAddress => uint256 stakedBalance)) public balanceOf;\n    mapping(address metaCoinAddress => uint256 totalSupply) public totalSupplies;\n    mapping(address metaCoinAddress => uint256 rewardIndexValue) public rewardIndex;\n    mapping(address metaCoinAddress => mapping(address => uint256)) public rewardIndexOf;\n    mapping(address metaCoinAddress => mapping(address => uint256)) public earned;\n    mapping(address metaCoinAddress => uint256 totalClaimable) public protocolFees;\n\n    address public protocolFeeRecipient;\n\n    error Unauthorised();\n    error TokenNotWhitelisted();\n\n    /// @notice Constructor that sets the owner and the protocol fee recipient\n    /// @param _owner The address of the contract owner\n    /// @param _protocolFeeRecipient The initial protocol fee recipient\n    constructor(address _owner, address _protocolFeeRecipient) Ownable(_owner) {\n        protocolFeeRecipient = _protocolFeeRecipient;\n        emit ProtocolFeeRecipientSet(address(0), _protocolFeeRecipient);\n    }\n\n    /// @notice Distributes rewards to stakers or as protocol fees if no one is staked\n    /// @param _metaCoinAddress The address of the token for which rewards are distributed\n    /// @param _rewardTokenAmount The amount of tokens to distribute as rewards\n    function distributeRewards(address _metaCoinAddress, uint256 _rewardTokenAmount) external {\n        if (!whitelistedStakingTokens[_metaCoinAddress]) revert TokenNotWhitelisted();\n\n        uint256 _totalSupply = totalSupplies[_metaCoinAddress];\n        if (_totalSupply == 0) {\n            // If no tokens are staked, add the reward amount to protocol fees.\n            protocolFees[_metaCoinAddress] += _rewardTokenAmount;\n            emit RewardDistributed(_metaCoinAddress, _rewardTokenAmount, false);\n        } else {\n            // Otherwise, update the reward index for the token.\n            rewardIndex[_metaCoinAddress] += (_rewardTokenAmount * MULTIPLIER) / _totalSupply;\n            emit RewardDistributed(_metaCoinAddress, _rewardTokenAmount, true);\n        }\n        IERC20Metadata(_metaCoinAddress).safeTransferFrom(msg.sender, address(this), _rewardTokenAmount);\n    }\n\n    /// @notice Calculates the rewards for a staker based on their staked amount\n    /// @param _metaCoinAddress The token address\n    /// @param _account The staker's address\n    /// @return The reward amount calculated\n    function _calculateRewards(address _metaCoinAddress, address _account) private view returns (uint256) {\n        uint256 _shares = balanceOf[_metaCoinAddress][_account];\n        return (_shares * (rewardIndex[_metaCoinAddress] - rewardIndexOf[_metaCoinAddress][_account])) / MULTIPLIER;\n    }\n\n    /// @notice Returns the total rewards earned by an account for a given token\n    /// @param _metaCoinAddress The token address\n    /// @param _account The staker's address\n    /// @return The total rewards earned\n    function calculateRewardsEarned(address _metaCoinAddress, address _account) external view returns (uint256) {\n        return earned[_metaCoinAddress][_account] + _calculateRewards(_metaCoinAddress, _account);\n    }\n\n    /// @notice Updates the reward information for a staker\n    /// @param _metaCoinAddress The token address\n    /// @param _account The staker's address\n    function _updateRewards(address _metaCoinAddress, address _account) private {\n        earned[_metaCoinAddress][_account] += _calculateRewards(_metaCoinAddress, _account);\n        rewardIndexOf[_metaCoinAddress][_account] = rewardIndex[_metaCoinAddress];\n    }\n\n    /// @notice Stakes a specified amount of tokens\n    /// @param _metaCoinAddress The token address to stake\n    /// @param _amount The amount of tokens to stake\n    function stake(address _metaCoinAddress, uint256 _amount) external {\n        if (!whitelistedStakingTokens[_metaCoinAddress]) revert TokenNotWhitelisted();\n\n        _updateRewards(_metaCoinAddress, msg.sender);\n        balanceOf[_metaCoinAddress][msg.sender] += _amount;\n        totalSupplies[_metaCoinAddress] += _amount;\n\n        emit Staked(_metaCoinAddress, _amount);\n        IERC20Metadata(_metaCoinAddress).safeTransferFrom(msg.sender, address(this), _amount);\n    }\n\n    /// @notice Unstakes a specified amount of tokens\n    /// @param _metaCoinAddress The token address to unstake\n    /// @param _amount The amount of tokens to unstake\n    function unstake(address _metaCoinAddress, uint256 _amount) external {\n        if (!whitelistedStakingTokens[_metaCoinAddress]) revert TokenNotWhitelisted();\n\n        _updateRewards(_metaCoinAddress, msg.sender);\n        balanceOf[_metaCoinAddress][msg.sender] -= _amount;\n        totalSupplies[_metaCoinAddress] -= _amount;\n\n        emit Unstaked(_metaCoinAddress, _amount);\n        IERC20Metadata(_metaCoinAddress).safeTransfer(msg.sender, _amount);\n    }\n\n    /// @notice Claims rewards for multiple token addresses\n    /// @param _metaCoinAddresses The array of token addresses to claim rewards for\n    /// @return _rewards An array containing the reward amounts for each token\n    function claim(address[] calldata _metaCoinAddresses) external returns (uint256[] memory _rewards) {\n        _rewards = new uint256[](_metaCoinAddresses.length);\n\n        for (uint256 i = 0; i < _metaCoinAddresses.length; ++i) {\n            _updateRewards(_metaCoinAddresses[i], msg.sender);\n\n            uint256 _reward = earned[_metaCoinAddresses[i]][msg.sender];\n            earned[_metaCoinAddresses[i]][msg.sender] = 0;\n\n            _rewards[i] = _reward;\n            emit Claimed(_metaCoinAddresses[i], _reward);\n\n            IERC20Metadata(_metaCoinAddresses[i]).safeTransfer(msg.sender, _reward);\n        }\n\n        return _rewards;\n    }\n\n    /// @notice Sets a new protocol fee recipient\n    /// @param _newRecipient The address of the new protocol fee recipient\n    function setProtocolFeeRecipient(address _newRecipient) external {\n        if (msg.sender != protocolFeeRecipient) revert Unauthorised();\n        emit ProtocolFeeRecipientSet(protocolFeeRecipient, _newRecipient);\n        protocolFeeRecipient = _newRecipient;\n    }\n\n    /// @notice Claims accumulated protocol fees for multiple token addresses\n    /// @param _metaCoinAddresses The array of token addresses to claim protocol fees from\n    function claimProtocolFees(address[] calldata _metaCoinAddresses) external {\n        if (msg.sender != protocolFeeRecipient) revert Unauthorised();\n        for (uint256 i; i < _metaCoinAddresses.length; ++i) {\n            uint256 _reward = protocolFees[_metaCoinAddresses[i]];\n            protocolFees[_metaCoinAddresses[i]] = 0;\n            emit ProtocolFeeClaimed(_metaCoinAddresses[i], _reward);\n            IERC20Metadata(_metaCoinAddresses[i]).safeTransfer(protocolFeeRecipient, _reward);\n        }\n    }\n\n    /// @notice Whitelists a token for staking\n    /// @param _metaCoinAddress The token address to whitelist\n    function whitelistStakingToken(address _metaCoinAddress) external onlyOwner {\n        whitelistedStakingTokens[_metaCoinAddress] = true;\n        emit WhitelistSet(_metaCoinAddress);\n    }\n}"
}