{
    "Function": "claimRewards",
    "File": "contracts/ExtraRewardStashV1.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "SafeERC20",
        "IRewardFactory",
        "IERC20",
        "IStaker",
        "IStaker",
        "SafeERC20",
        "IRewardFactory",
        "IDeposit",
        "IRewardFactory",
        "IDeposit",
        "IRewardFactory",
        "IERC20",
        "IDeposit"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "setToken"
    ],
    "Library Calls": [
        "safeTransfer",
        "safeTransfer"
    ],
    "Low-Level Calls": [],
    "Code": "function claimRewards() external returns (bool) {\n        require(msg.sender == operator, \"!authorized\");\n        //first time init\n        if (tokenInfo.token == address(0)) {\n            setToken();\n        }\n\n        if (tokenInfo.token != address(0)) {\n            uint256 before = IERC20(tokenInfo.token).balanceOf(staker);\n            IDeposit(operator).claimRewards(pid, gauge);\n            uint256 newbalance = IERC20(tokenInfo.token).balanceOf(staker);\n            if (newbalance > before) {\n                IStaker(staker).withdraw(tokenInfo.token);\n                tokenInfo.lastActiveTime = block.timestamp;\n\n                //make sure this pool is in active list,\n                IRewardFactory(rewardFactory).addActiveReward(tokenInfo.token, pid);\n\n                //check if other stashes are also active, and if so, send to arbitrator\n                //do this here because processStash will have tokens from the arbitrator\n                uint256 activeCount = IRewardFactory(rewardFactory).activeRewardCount(\n                    tokenInfo.token\n                );\n                if (activeCount > 1) {\n                    //send to arbitrator\n                    address arb = IDeposit(operator).rewardArbitrator();\n                    if (arb != address(0)) {\n                        IERC20(tokenInfo.token).safeTransfer(arb, newbalance);\n                    }\n                }\n            } else {\n                //check if this reward has been inactive too long\n                if (block.timestamp > tokenInfo.lastActiveTime + WEEK) {\n                    //set as inactive\n                    IRewardFactory(rewardFactory).removeActiveReward(tokenInfo.token, pid);\n                } else {\n                    //edge case around reward ending periods\n                    if (newbalance > 0) {\n                        // - recently active pool\n                        // - rewards claimed to staker contract via someone manually calling claim_rewards() on the gauge\n                        // - rewards ended before the above call, which claimed the last available tokens\n                        // - thus claimRewards doesnt see any new rewards, but there are rewards on the staker contract\n                        // - i think its safe to assume claim will be called within the timeframe, or else these rewards\n                        //     will be unretrievable until some pool starts rewards again\n\n                        //claim the tokens\n                        IStaker(staker).withdraw(tokenInfo.token);\n\n                        uint256 activeCount = IRewardFactory(rewardFactory).activeRewardCount(\n                            tokenInfo.token\n                        );\n                        if (activeCount > 1) {\n                            //send to arbitrator\n                            address arb = IDeposit(operator).rewardArbitrator();\n                            if (arb != address(0)) {\n                                IERC20(tokenInfo.token).safeTransfer(arb, newbalance);\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        return true;\n    }"
}