{
    "Function": "slitherConstructorVariables",
    "File": "contracts/ExtraRewardStashV1.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract ExtraRewardStashV1 {\n    using SafeERC20 for IERC20;\n    using Address for address;\n    using SafeMath for uint256;\n\n    uint256 private constant WEEK = 7 * 86400;\n    uint256 private constant maxRewards = 8;\n\n    uint256 public pid;\n    address public operator;\n    address public staker;\n    address public gauge;\n    address public rewardFactory;\n\n    uint256 public historicalRewards = 0;\n\n    struct TokenInfo {\n        address token;\n        address rewardAddress;\n        uint256 lastActiveTime;\n    }\n    TokenInfo public tokenInfo;\n\n    constructor(\n        uint256 _pid,\n        address _operator,\n        address _staker,\n        address _gauge,\n        address _rFactory\n    ) {\n        pid = _pid;\n        operator = _operator;\n        staker = _staker;\n        gauge = _gauge;\n        rewardFactory = _rFactory;\n    }\n\n    function getName() external pure returns (string memory) {\n        return \"ExtraRewardStashV1\";\n    }\n\n    function setToken() internal {\n        address token = IGauge(gauge).rewarded_token();\n\n        if (token != address(0)) {\n            //set token address\n            tokenInfo.token = token;\n\n            //create new reward contract\n            (, , , address mainRewardContract, , ) = IDeposit(operator).poolInfo(pid);\n            address rewardContract = IRewardFactory(rewardFactory).CreateTokenRewards(\n                token,\n                mainRewardContract\n            );\n            tokenInfo.rewardAddress = rewardContract;\n            tokenInfo.lastActiveTime = block.timestamp;\n        }\n    }\n\n    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    }\n\n    //pull assigned tokens from staker to stash\n    function stashRewards() external pure returns (bool) {\n        //stashRewards() is also called on deposit\n        //so dont need to try withdrawing here for v1\n        // -> move withdraw() call to processStash() which is only called during reward claiming\n        return true;\n    }\n\n    //send all extra rewards to their reward contracts\n    function processStash() external returns (bool) {\n        require(msg.sender == operator, \"!authorized\");\n\n        address token = tokenInfo.token;\n        if (token == address(0)) return true;\n\n        //send to rewards\n        uint256 amount = IERC20(token).balanceOf(address(this));\n        if (amount > 0) {\n            historicalRewards = historicalRewards.add(amount);\n            //add to reward contract\n            address rewards = tokenInfo.rewardAddress;\n            if (rewards == address(0)) return true;\n            IERC20(token).safeTransfer(rewards, amount);\n            IRewards(rewards).queueNewRewards(amount);\n        }\n        return true;\n    }\n}"
}