// Vulnerability label: DC1
{{
  "language": "Solidity",
  "sources": {
    "contracts/pools/loss/MasterPool.sol": {
      "content": "// SPDX-License-Identifier: Apache-2.0\n\n/**\n *Submitted for verification at Etherscan.io on 2021-05-13\n */\n\n// SPDX-License-Identifier: MIT\n\n// Special Thanks to @BoringCrypto for his ideas and patience\n\npragma solidity =0.6.12;\npragma experimental ABIEncoderV2;\n\n// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SignedSafeMath.sol\nlibrary SignedSafeMath {\n    int256 private constant _INT256_MIN = -2**255;\n\n    /**\n     * @dev Returns the multiplication of two signed integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(int256 a, int256 b) internal pure returns (int256) {\n        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n        // benefit is lost if 'b' is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n        if (a == 0) {\n            return 0;\n        }\n\n        require(\n            !(a == -1 && b == _INT256_MIN),\n            \"SignedSafeMath: multiplication overflow\"\n        );\n\n        int256 c = a * b;\n        require(c / a == b, \"SignedSafeMath: multiplication overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two signed integers. Reverts on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(int256 a, int256 b) internal pure returns (int256) {\n        require(b != 0, \"SignedSafeMath: division by zero\");\n        require(\n            !(b == -1 && a == _INT256_MIN),\n            \"SignedSafeMath: division overflow\"\n        );\n\n        int256 c = a / b;\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two signed integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(int256 a, int256 b) internal pure returns (int256) {\n        int256 c = a - b;\n        require(\n            (b >= 0 && c <= a) || (b < 0 && c > a),\n            \"SignedSafeMath: subtraction overflow\"\n        );\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the addition of two signed integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(int256 a, int256 b) internal pure returns (int256) {\n        int256 c = a + b;\n        require(\n            (b >= 0 && c >= a) || (b < 0 && c < a),\n            \"SignedSafeMath: addition overflow\"\n        );\n\n        return c;\n    }\n\n    function toUInt256(int256 a) internal pure returns (uint256) {\n        require(a >= 0, \"Integer < 0\");\n        return uint256(a);\n    }\n}\n\n/// @notice A library for performing overflow-/underflow-safe math,\n/// updated with awesomeness from of DappHub (https://github.com/dapphub/ds-math).\nlibrary BoringMath {\n    function add(uint256 a, uint256 b) internal pure returns (uint256 c) {\n        require((c = a + b) >= b, \"BoringMath: Add Overflow\");\n    }\n\n    function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {\n        require((c = a - b) <= a, \"BoringMath: Underflow\");\n    }\n\n    function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {\n        require(b == 0 || (c = a * b) / b == a, \"BoringMath: Mul Overflow\");\n    }\n\n    function to128(uint256 a) internal pure returns (uint128 c) {\n        require(a <= uint128(-1), \"BoringMath: uint128 Overflow\");\n        c = uint128(a);\n    }\n\n    function to64(uint256 a) internal pure returns (uint64 c) {\n        require(a <= uint64(-1), \"BoringMath: uint64 Overflow\");\n        c = uint64(a);\n    }\n\n    function to32(uint256 a) internal pure returns (uint32 c) {\n        require(a <= uint32(-1), \"BoringMath: uint32 Overflow\");\n        c = uint32(a);\n    }\n}\n\n/// @notice A library for performing overflow-/underflow-safe addition and subtraction on uint128.\nlibrary BoringMath128 {\n    function add(uint128 a, uint128 b) internal pure returns (uint128 c) {\n        require((c = a + b) >= b, \"BoringMath: Add Overflow\");\n    }\n\n    function sub(uint128 a, uint128 b) internal pure returns (uint128 c) {\n        require((c = a - b) <= a, \"BoringMath: Underflow\");\n    }\n}\n\ncontract BoringOwnableData {\n    address public owner;\n    address public pendingOwner;\n}\n\ncontract BoringOwnable is BoringOwnableData {\n    event OwnershipTransferred(\n        address indexed previousOwner,\n        address indexed newOwner\n    );\n\n    /// @notice `owner` defaults to msg.sender on construction.\n    constructor() public {\n        owner = msg.sender;\n        emit OwnershipTransferred(address(0), msg.sender);\n    }\n\n    /// @notice Transfers ownership to `newOwner`. Either directly or claimable by the new pending owner.\n    /// Can only be invoked by the current `owner`.\n    /// @param newOwner Address of the new owner.\n    /// @param direct True if `newOwner` should be set immediately. False if `newOwner` needs to use `claimOwnership`.\n    /// @param renounce Allows the `newOwner` to be `address(0)` if `direct` and `renounce` is True. Has no effect otherwise.\n    function transferOwnership(\n        address newOwner,\n        bool direct,\n        bool renounce\n    ) public onlyOwner {\n        if (direct) {\n            // Checks\n            require(\n                newOwner != address(0) || renounce,\n                \"Ownable: zero address\"\n            );\n\n            // Effects\n            emit OwnershipTransferred(owner, newOwner);\n            owner = newOwner;\n            pendingOwner = address(0);\n        } else {\n            // Effects\n            pendingOwner = newOwner;\n        }\n    }\n\n    /// @notice Needs to be called by `pendingOwner` to claim ownership.\n    function claimOwnership() public {\n        address _pendingOwner = pendingOwner;\n\n        // Checks\n        require(\n            msg.sender == _pendingOwner,\n            \"Ownable: caller != pending owner\"\n        );\n\n        // Effects\n        emit OwnershipTransferred(owner, _pendingOwner);\n        owner = _pendingOwner;\n        pendingOwner = address(0);\n    }\n\n    /// @notice Only allows the `owner` to execute the function.\n    modifier onlyOwner() {\n        require(msg.sender == owner, \"Ownable: caller is not the owner\");\n        _;\n    }\n}\n\ninterface IERC20 {\n    function totalSupply() external view returns (uint256);\n\n    function balanceOf(address account) external view returns (uint256);\n\n    function allowance(address owner, address spender)\n        external\n        view\n        returns (uint256);\n\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    event Transfer(address indexed from, address indexed to, uint256 value);\n    event Approval(\n        address indexed owner,\n        address indexed spender,\n        uint256 value\n    );\n\n    /// @notice EIP 2612\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n}\n\nlibrary BoringERC20 {\n    bytes4 private constant SIG_SYMBOL = 0x95d89b41; // symbol()\n    bytes4 private constant SIG_NAME = 0x06fdde03; // name()\n    bytes4 private constant SIG_DECIMALS = 0x313ce567; // decimals()\n    bytes4 private constant SIG_TRANSFER = 0xa9059cbb; // transfer(address,uint256)\n    bytes4 private constant SIG_TRANSFER_FROM = 0x23b872dd; // transferFrom(address,address,uint256)\n\n    function returnDataToString(bytes memory data)\n        internal\n        pure\n        returns (string memory)\n    {\n        if (data.length >= 64) {\n            return abi.decode(data, (string));\n        } else if (data.length == 32) {\n            uint8 i = 0;\n            while (i < 32 && data[i] != 0) {\n                i++;\n            }\n            bytes memory bytesArray = new bytes(i);\n            for (i = 0; i < 32 && data[i] != 0; i++) {\n                bytesArray[i] = data[i];\n            }\n            return string(bytesArray);\n        } else {\n            return \"???\";\n        }\n    }\n\n    /// @notice Provides a safe ERC20.symbol version which returns '???' as fallback string.\n    /// @param token The address of the ERC-20 token contract.\n    /// @return (string) Token symbol.\n    function safeSymbol(IERC20 token) internal view returns (string memory) {\n        (bool success, bytes memory data) = address(token).staticcall(\n            abi.encodeWithSelector(SIG_SYMBOL)\n        );\n        return success ? returnDataToString(data) : \"???\";\n    }\n\n    /// @notice Provides a safe ERC20.name version which returns '???' as fallback string.\n    /// @param token The address of the ERC-20 token contract.\n    /// @return (string) Token name.\n    function safeName(IERC20 token) internal view returns (string memory) {\n        (bool success, bytes memory data) = address(token).staticcall(\n            abi.encodeWithSelector(SIG_NAME)\n        );\n        return success ? returnDataToString(data) : \"???\";\n    }\n\n    /// @notice Provides a safe ERC20.decimals version which returns '18' as fallback value.\n    /// @param token The address of the ERC-20 token contract.\n    /// @return (uint8) Token decimals.\n    function safeDecimals(IERC20 token) internal view returns (uint8) {\n        (bool success, bytes memory data) = address(token).staticcall(\n            abi.encodeWithSelector(SIG_DECIMALS)\n        );\n        return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;\n    }\n\n    /// @notice Provides a safe ERC20.transfer version for different ERC-20 implementations.\n    /// Reverts on a failed transfer.\n    /// @param token The address of the ERC-20 token.\n    /// @param to Transfer tokens to.\n    /// @param amount The token amount.\n    function safeTransfer(\n        IERC20 token,\n        address to,\n        uint256 amount\n    ) internal {\n        (bool success, bytes memory data) = address(token).call(\n            abi.encodeWithSelector(SIG_TRANSFER, to, amount)\n        );\n        require(\n            success && (data.length == 0 || abi.decode(data, (bool))),\n            \"BoringERC20: Transfer failed\"\n        );\n    }\n\n    /// @notice Provides a safe ERC20.transferFrom version for different ERC-20 implementations.\n    /// Reverts on a failed transfer.\n    /// @param token The address of the ERC-20 token.\n    /// @param from Transfer tokens from.\n    /// @param to Transfer tokens to.\n    /// @param amount The token amount.\n    function safeTransferFrom(\n        IERC20 token,\n        address from,\n        address to,\n        uint256 amount\n    ) internal {\n        (bool success, bytes memory data) = address(token).call(\n            abi.encodeWithSelector(SIG_TRANSFER_FROM, from, to, amount)\n        );\n        require(\n            success && (data.length == 0 || abi.decode(data, (bool))),\n            \"BoringERC20: TransferFrom failed\"\n        );\n    }\n}\n\ncontract BaseBoringBatchable {\n    /// @dev Helper function to extract a useful revert message from a failed call.\n    /// If the returned data is malformed or not correctly abi encoded then this call can fail itself.\n    function _getRevertMsg(bytes memory _returnData)\n        internal\n        pure\n        returns (string memory)\n    {\n        // If the _res length is less than 68, then the transaction failed silently (without a revert message)\n        if (_returnData.length < 68) return \"Transaction reverted silently\";\n\n        assembly {\n            // Slice the sighash.\n            _returnData := add(_returnData, 0x04)\n        }\n        return abi.decode(_returnData, (string)); // All that remains is the revert string\n    }\n\n    /// @notice Allows batched call to self (this contract).\n    /// @param calls An array of inputs for each call.\n    /// @param revertOnFail If True then reverts after a failed call and stops doing further calls.\n    /// @return successes An array indicating the success of a call, mapped one-to-one to `calls`.\n    /// @return results An array with the returned data of each function call, mapped one-to-one to `calls`.\n    // F1: External is ok here because this is the batch function, adding it to a batch makes no sense\n    // F2: Calls in the batch may be payable, delegatecall operates in the same context, so each call in the batch has access to msg.value\n    // C3: The length of the loop is fully under user control, so can't be exploited\n    // C7: Delegatecall is only used on the same contract, so it's safe\n    function batch(bytes[] calldata calls, bool revertOnFail)\n        external\n        payable\n        returns (bool[] memory successes, bytes[] memory results)\n    {\n        successes = new bool[](calls.length);\n        results = new bytes[](calls.length);\n        for (uint256 i = 0; i < calls.length; i++) {\n            (bool success, bytes memory result) = address(this).delegatecall(\n                calls[i]\n            );\n            require(success || !revertOnFail, _getRevertMsg(result));\n            successes[i] = success;\n            results[i] = result;\n        }\n    }\n}\n\ncontract BoringBatchable is BaseBoringBatchable {\n    /// @notice Call wrapper that performs `ERC20.permit` on `token`.\n    /// Lookup `IERC20.permit`.\n    // F6: Parameters can be used front-run the permit and the user's permit will fail (due to nonce or other revert)\n    //     if part of a batch this could be used to grief once as the second call would not need the permit\n    function permitToken(\n        IERC20 token,\n        address from,\n        address to,\n        uint256 amount,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) public {\n        token.permit(from, to, amount, deadline, v, r, s);\n    }\n}\n\ninterface IRewarder {\n    using BoringERC20 for IERC20;\n\n    function onSushiReward(\n        uint256 pid,\n        address user,\n        address recipient,\n        uint256 sushiAmount,\n        uint256 newLpAmount\n    ) external;\n\n    function pendingTokens(\n        uint256 pid,\n        address user,\n        uint256 sushiAmount\n    ) external view returns (IERC20[] memory, uint256[] memory);\n}\n\ninterface IMigratorChef {\n    // Take the current LP token address and return the new LP token address.\n    // Migrator should have full access to the caller's LP token.\n    function migrate(IERC20 token) external returns (IERC20);\n}\n\ninterface IMasterChef {\n    using BoringERC20 for IERC20;\n    struct UserInfo {\n        uint256 amount; // How many LP tokens the user has provided.\n        uint256 rewardDebt; // Reward debt. See explanation below.\n    }\n\n    struct PoolInfo {\n        IERC20 lpToken; // Address of LP token contract.\n        uint256 allocPoint; // How many allocation points assigned to this pool. SUSHI to distribute per block.\n        uint256 lastRewardBlock; // Last block number that SUSHI distribution occurs.\n        uint256 accSushiPerShare; // Accumulated SUSHI per share, times 1e12. See below.\n    }\n\n    function poolInfo(uint256 pid)\n        external\n        view\n        returns (IMasterChef.PoolInfo memory);\n\n    function totalAllocPoint() external view returns (uint256);\n\n    function deposit(uint256 _pid, uint256 _amount) external;\n}\n\n/// @notice The (older) MasterChef contract gives out a constant number of SUSHI tokens per block.\n/// It is the only address with minting rights for SUSHI.\n/// The idea for this MasterChef V2 (MCV2) contract is therefore to be the owner of a dummy token\n/// that is deposited into the MasterChef V1 (MCV1) contract.\n/// The allocation point for this pool on MCV1 is the total allocation point for all pools that receive double incentives.\ncontract MasterPool is BoringOwnable, BoringBatchable {\n    using BoringMath for uint256;\n    using BoringMath128 for uint128;\n    using BoringERC20 for IERC20;\n    using SignedSafeMath for int256;\n\n    /// @notice Info of each MCV2 user.\n    /// `amount` LP token amount the user has provided.\n    /// `rewardDebt` The amount of SUSHI entitled to the user.\n    struct UserInfo {\n        uint256 amount;\n        int256 rewardDebt;\n    }\n\n    /// @notice Info of each MCV2 pool.\n    /// `allocPoint` The amount of allocation points assigned to the pool.\n    /// Also known as the amount of SUSHI to distribute per block.\n    struct PoolInfo {\n        uint128 accSushiPerShare;\n        uint64 lastRewardBlock;\n        uint64 allocPoint;\n    }\n\n    /// @notice Address of SUSHI contract.\n    IERC20 public immutable SUSHI;\n    // @notice The migrator contract. It has a lot of power. Can only be set through governance (owner).\n    IMigratorChef public migrator;\n\n    /// @notice Info of each MCV2 pool.\n    PoolInfo[] public poolInfo;\n    /// @notice Address of the LP token for each MCV2 pool.\n    IERC20[] public lpToken;\n    /// @notice Address of each `IRewarder` contract in MCV2.\n    IRewarder[] public rewarder;\n\n    /// @notice Info of each user that stakes LP tokens.\n    mapping(uint256 => mapping(address => UserInfo)) public userInfo;\n    /// @dev Total allocation points. Must be the sum of all allocation points in all pools.\n    uint256 public totalAllocPoint;\n    uint256 private MASTERCHEF_SUSHI_PER_BLOCK;\n    uint256 private constant ACC_SUSHI_PRECISION = 1e12;\n\n    event Deposit(\n        address indexed user,\n        uint256 indexed pid,\n        uint256 amount,\n        address indexed to\n    );\n    event Withdraw(\n        address indexed user,\n        uint256 indexed pid,\n        uint256 amount,\n        address indexed to\n    );\n    event EmergencyWithdraw(\n        address indexed user,\n        uint256 indexed pid,\n        uint256 amount,\n        address indexed to\n    );\n    event Harvest(address indexed user, uint256 indexed pid, uint256 amount);\n    event LogPoolAddition(\n        uint256 indexed pid,\n        uint256 allocPoint,\n        IERC20 indexed lpToken,\n        IRewarder indexed rewarder\n    );\n    event LogSetPool(\n        uint256 indexed pid,\n        uint256 allocPoint,\n        IRewarder indexed rewarder,\n        bool overwrite\n    );\n    event LogSetPoolAddress(\n        uint256 indexed pid,\n        IERC20 indexed lpToken\n    );\n    event LogUpdatePool(\n        uint256 indexed pid,\n        uint64 lastRewardBlock,\n        uint256 lpSupply,\n        uint256 accSushiPerShare\n    );\n    event LogUpdateReward(uint256 reward);\n    event LogInit();\n\n    /// @param _sushi The SUSHI token contract address.\n    constructor(IERC20 _sushi) public {\n        //MASTER_CHEF = _MASTER_CHEF;\n        SUSHI = _sushi;\n        MASTERCHEF_SUSHI_PER_BLOCK = 1e20;\n        //MASTER_PID = _MASTER_PID;\n    }\n\n    function setRewardPerBlock(uint256 _reward) public onlyOwner {\n        MASTERCHEF_SUSHI_PER_BLOCK = _reward;\n        emit LogUpdateReward(MASTERCHEF_SUSHI_PER_BLOCK);\n    }\n\n    /// @notice Deposits a dummy token to `MASTER_CHEF` MCV1. This is required because MCV1 holds the minting rights for SUSHI.\n    /// Any balance of transaction sender in `dummyToken` is transferred.\n    /// The allocation point for the pool on MCV1 is the total allocation point for all pools that receive double incentives.\n    function init() external {\n        //uint256 balance = dummyToken.balanceOf(msg.sender);\n        //require(balance != 0, \"MasterChefV2: Balance must exceed 0\");\n        //dummyToken.safeTransferFrom(msg.sender, address(this), balance);\n        //dummyToken.approve(address(MASTER_CHEF), balance);\n        //MASTER_CHEF.deposit(MASTER_PID, balance);\n        emit LogInit();\n    }\n\n    /// @notice Returns the number of MCV2 pools.\n    function poolLength() public view returns (uint256 pools) {\n        pools = poolInfo.length;\n    }\n\n    /// @notice Add a new LP to the pool. Can only be called by the owner.\n    /// DO NOT add the same LP token more than once. Rewards will be messed up if you do.\n    /// @param allocPoint AP of the new pool.\n    /// @param _lpToken Address of the LP ERC-20 token.\n    /// @param _rewarder Address of the rewarder delegate.\n    function add(\n        uint256 allocPoint,\n        IERC20 _lpToken,\n        IRewarder _rewarder\n    ) public onlyOwner {\n        uint256 lastRewardBlock = block.number;\n        totalAllocPoint = totalAllocPoint.add(allocPoint);\n        lpToken.push(_lpToken);\n        rewarder.push(_rewarder);\n\n        poolInfo.push(\n            PoolInfo({\n                allocPoint: allocPoint.to64(),\n                lastRewardBlock: lastRewardBlock.to64(),\n                accSushiPerShare: 0\n            })\n        );\n        emit LogPoolAddition(\n            lpToken.length.sub(1),\n            allocPoint,\n            _lpToken,\n            _rewarder\n        );\n    }\n\n    /// @notice Update the given pool's SUSHI allocation point and `IRewarder` contract. Can only be called by the owner.\n    /// @param _pid The index of the pool. See `poolInfo`.\n    /// @param _allocPoint New AP of the pool.\n    /// @param _rewarder Address of the rewarder delegate.\n    /// @param overwrite True if _rewarder should be `set`. Otherwise `_rewarder` is ignored.\n    function set(\n        uint256 _pid,\n        uint256 _allocPoint,\n        IRewarder _rewarder,\n        bool overwrite\n    ) public onlyOwner {\n        totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(\n            _allocPoint\n        );\n        poolInfo[_pid].allocPoint = _allocPoint.to64();\n        if (overwrite) {\n            rewarder[_pid] = _rewarder;\n        }\n        emit LogSetPool(\n            _pid,\n            _allocPoint,\n            overwrite ? _rewarder : rewarder[_pid],\n            overwrite\n        );\n    }\n\n\n    /// @notice Update the given pool's SUSHI allocation point and `IRewarder` contract. Can only be called by the owner.\n    /// @param _pid The index of the pool. See `poolInfo`.\n    /// @param _pool New pool to set\n    function setPoolAddr(\n        uint256 _pid,\n        IERC20 _pool\n    ) public onlyOwner {\n        lpToken[_pid] = _pool;\n        emit LogSetPoolAddress(\n            _pid,\n            _pool\n        );\n    }\n\n    /// @notice Set the `migrator` contract. Can only be called by the owner.\n    /// @param _migrator The contract address to set.\n    function setMigrator(IMigratorChef _migrator) public onlyOwner {\n        migrator = _migrator;\n    }\n\n    /// @notice Migrate LP token to another LP contract through the `migrator` contract.\n    /// @param _pid The index of the pool. See `poolInfo`.\n    function migrate(uint256 _pid) public {\n        require(\n            address(migrator) != address(0),\n            \"MasterChefV2: no migrator set\"\n        );\n        IERC20 _lpToken = lpToken[_pid];\n        uint256 bal = _lpToken.balanceOf(address(this));\n        _lpToken.approve(address(migrator), bal);\n        IERC20 newLpToken = migrator.migrate(_lpToken);\n        require(\n            bal == newLpToken.balanceOf(address(this)),\n            \"MasterChefV2: migrated balance must match\"\n        );\n        lpToken[_pid] = newLpToken;\n    }\n\n    /// @notice View function to see pending SUSHI on frontend.\n    /// @param _pid The index of the pool. See `poolInfo`.\n    /// @param _user Address of user.\n    /// @return pending SUSHI reward for a given user.\n    function pendingSushi(uint256 _pid, address _user)\n        external\n        view\n        returns (uint256 pending)\n    {\n        PoolInfo memory pool = poolInfo[_pid];\n        UserInfo storage user = userInfo[_pid][_user];\n        uint256 accSushiPerShare = pool.accSushiPerShare;\n        uint256 lpSupply = lpToken[_pid].balanceOf(address(this));\n        if (block.number > pool.lastRewardBlock && lpSupply != 0) {\n            uint256 blocks = block.number.sub(pool.lastRewardBlock);\n            uint256 sushiReward = blocks.mul(sushiPerBlock()).mul(\n                pool.allocPoint\n            ) / totalAllocPoint;\n            accSushiPerShare = accSushiPerShare.add(\n                sushiReward.mul(ACC_SUSHI_PRECISION) / lpSupply\n            );\n        }\n        pending = int256(\n            user.amount.mul(accSushiPerShare) / ACC_SUSHI_PRECISION\n        ).sub(user.rewardDebt).toUInt256();\n    }\n\n    /// @notice Update reward variables for all pools. Be careful of gas spending!\n    /// @param pids Pool IDs of all to be updated. Make sure to update all active pools.\n    function massUpdatePools(uint256[] calldata pids) external {\n        uint256 len = pids.length;\n        for (uint256 i = 0; i < len; ++i) {\n            updatePool(pids[i]);\n        }\n    }\n\n    /// @notice Calculates and returns the `amount` of SUSHI per block.\n    function sushiPerBlock() public view returns (uint256 amount) {\n        amount = uint256(MASTERCHEF_SUSHI_PER_BLOCK);\n    }\n\n    /// @notice Update reward variables of the given pool.\n    /// @param pid The index of the pool. See `poolInfo`.\n    /// @return pool Returns the pool that was updated.\n    function updatePool(uint256 pid) public returns (PoolInfo memory pool) {\n        pool = poolInfo[pid];\n        if (block.number > pool.lastRewardBlock) {\n            uint256 lpSupply = lpToken[pid].balanceOf(address(this));\n            if (lpSupply > 0) {\n                uint256 blocks = block.number.sub(pool.lastRewardBlock);\n                uint256 sushiReward = blocks.mul(sushiPerBlock()).mul(\n                    pool.allocPoint\n                ) / totalAllocPoint;\n                pool.accSushiPerShare = pool.accSushiPerShare.add(\n                    (sushiReward.mul(ACC_SUSHI_PRECISION) / lpSupply).to128()\n                );\n            }\n            pool.lastRewardBlock = block.number.to64();\n            poolInfo[pid] = pool;\n            emit LogUpdatePool(\n                pid,\n                pool.lastRewardBlock,\n                lpSupply,\n                pool.accSushiPerShare\n            );\n        }\n    }\n\n    /// @notice Deposit LP tokens to MCV2 for SUSHI allocation.\n    /// @param pid The index of the pool. See `poolInfo`.\n    /// @param amount LP token amount to deposit.\n    /// @param to The receiver of `amount` deposit benefit.\n    function deposit(\n        uint256 pid,\n        uint256 amount,\n        address to\n    ) public {\n        PoolInfo memory pool = updatePool(pid);\n        UserInfo storage user = userInfo[pid][to];\n\n        // Effects\n        user.amount = user.amount.add(amount);\n        user.rewardDebt = user.rewardDebt.add(\n            int256(amount.mul(pool.accSushiPerShare) / ACC_SUSHI_PRECISION)\n        );\n\n        // Interactions\n        IRewarder _rewarder = rewarder[pid];\n        if (address(_rewarder) != address(0)) {\n            _rewarder.onSushiReward(pid, to, to, 0, user.amount);\n        }\n\n        lpToken[pid].safeTransferFrom(msg.sender, address(this), amount);\n\n        emit Deposit(msg.sender, pid, amount, to);\n    }\n\n    /// @notice Withdraw LP tokens from MCV2.\n    /// @param pid The index of the pool. See `poolInfo`.\n    /// @param amount LP token amount to withdraw.\n    /// @param to Receiver of the LP tokens.\n    function withdraw(\n        uint256 pid,\n        uint256 amount,\n        address to\n    ) public {\n        PoolInfo memory pool = updatePool(pid);\n        UserInfo storage user = userInfo[pid][msg.sender];\n\n        // Effects\n        user.rewardDebt = user.rewardDebt.sub(\n            int256(amount.mul(pool.accSushiPerShare) / ACC_SUSHI_PRECISION)\n        );\n        user.amount = user.amount.sub(amount);\n\n        // Interactions\n        IRewarder _rewarder = rewarder[pid];\n        if (address(_rewarder) != address(0)) {\n            _rewarder.onSushiReward(pid, msg.sender, to, 0, user.amount);\n        }\n\n        lpToken[pid].safeTransfer(to, amount);\n\n        emit Withdraw(msg.sender, pid, amount, to);\n    }\n\n    /// @notice Harvest proceeds for transaction sender to `to`.\n    /// @param pid The index of the pool. See `poolInfo`.\n    /// @param to Receiver of SUSHI rewards.\n    function harvest(uint256 pid, address to) public {\n        PoolInfo memory pool = updatePool(pid);\n        UserInfo storage user = userInfo[pid][msg.sender];\n        int256 accumulatedSushi = int256(\n            user.amount.mul(pool.accSushiPerShare) / ACC_SUSHI_PRECISION\n        );\n        uint256 _pendingSushi = accumulatedSushi\n            .sub(user.rewardDebt)\n            .toUInt256();\n\n        // Effects\n        user.rewardDebt = accumulatedSushi;\n\n        // Interactions\n        if (_pendingSushi != 0) {\n            SUSHI.safeTransfer(to, _pendingSushi);\n        }\n\n        IRewarder _rewarder = rewarder[pid];\n        if (address(_rewarder) != address(0)) {\n            _rewarder.onSushiReward(\n                pid,\n                msg.sender,\n                to,\n                _pendingSushi,\n                user.amount\n            );\n        }\n\n        emit Harvest(msg.sender, pid, _pendingSushi);\n    }\n\n    /// @notice Withdraw LP tokens from MCV2 and harvest proceeds for transaction sender to `to`.\n    /// @param pid The index of the pool. See `poolInfo`.\n    /// @param amount LP token amount to withdraw.\n    /// @param to Receiver of the LP tokens and SUSHI rewards.\n    function withdrawAndHarvest(\n        uint256 pid,\n        uint256 amount,\n        address to\n    ) public {\n        PoolInfo memory pool = updatePool(pid);\n        UserInfo storage user = userInfo[pid][msg.sender];\n        int256 accumulatedSushi = int256(\n            user.amount.mul(pool.accSushiPerShare) / ACC_SUSHI_PRECISION\n        );\n        uint256 _pendingSushi = accumulatedSushi\n            .sub(user.rewardDebt)\n            .toUInt256();\n\n        // Effects\n        user.rewardDebt = accumulatedSushi.sub(\n            int256(amount.mul(pool.accSushiPerShare) / ACC_SUSHI_PRECISION)\n        );\n        user.amount = user.amount.sub(amount);\n\n        // Interactions\n        SUSHI.safeTransfer(to, _pendingSushi);\n\n        IRewarder _rewarder = rewarder[pid];\n        if (address(_rewarder) != address(0)) {\n            _rewarder.onSushiReward(\n                pid,\n                msg.sender,\n                to,\n                _pendingSushi,\n                user.amount\n            );\n        }\n\n        lpToken[pid].safeTransfer(to, amount);\n\n        emit Withdraw(msg.sender, pid, amount, to);\n        emit Harvest(msg.sender, pid, _pendingSushi);\n    }\n\n    /*\n    /// @notice Harvests SUSHI from `MASTER_CHEF` MCV1 and pool `MASTER_PID` to this MCV2 contract.\n    function harvestFromMasterChef() public {\n        MASTER_CHEF.deposit(MASTER_PID, 0);\n    }\n*/\n\n    /// @notice Withdraw without caring about rewards. EMERGENCY ONLY.\n    /// @param pid The index of the pool. See `poolInfo`.\n    /// @param to Receiver of the LP tokens.\n    function emergencyWithdraw(uint256 pid, address to) public {\n        UserInfo storage user = userInfo[pid][msg.sender];\n        uint256 amount = user.amount;\n        user.amount = 0;\n        user.rewardDebt = 0;\n\n        IRewarder _rewarder = rewarder[pid];\n        if (address(_rewarder) != address(0)) {\n            _rewarder.onSushiReward(pid, msg.sender, to, 0, 0);\n        }\n\n        // Note: transfer can fail or succeed if `amount` is zero.\n        lpToken[pid].safeTransfer(to, amount);\n        emit EmergencyWithdraw(msg.sender, pid, amount, to);\n    }\n}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 65866
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "metadata": {
      "useLiteralContent": true
    },
    "libraries": {}
  }
}}