{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/managers/SherDistributionManager.sol",
    "Parent Contracts": [
        "contracts/managers/Manager.sol",
        "node_modules/@openzeppelin/contracts/security/Pausable.sol",
        "node_modules/@openzeppelin/contracts/access/Ownable.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol",
        "contracts/interfaces/managers/ISherDistributionManager.sol",
        "contracts/interfaces/managers/IManager.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract SherDistributionManager is ISherDistributionManager, Manager {\n  using SafeERC20 for IERC20;\n\n  uint256 internal constant DECIMALS = 10**6;\n\n  // The TVL at which max SHER rewards STOP i.e. 100M USDC\n  uint256 internal immutable maxRewardsEndTVL;\n\n  // The TVL at which SHER rewards stop entirely i.e. 600M USDC\n  uint256 internal immutable zeroRewardsStartTVL;\n\n  // The SHER tokens paid per USDC staked per second at the max rate\n  uint256 internal immutable maxRewardsRate;\n\n  // SHER token contract address\n  IERC20 public immutable sher;\n\n  /// @dev With `_maxRewardsRate` being 10**18, 1 USDC == 1 SHER per second (on flat part of curve)\n  constructor(\n    uint256 _maxRewardsEndTVL,\n    uint256 _zeroRewardsStartTVL,\n    uint256 _maxRewardsRate,\n    IERC20 _sher\n  ) {\n    if (_maxRewardsEndTVL >= _zeroRewardsStartTVL) revert InvalidArgument();\n    if (_maxRewardsRate == 0) revert ZeroArgument();\n    if (address(_sher) == address(0)) revert ZeroArgument();\n\n    maxRewardsEndTVL = _maxRewardsEndTVL;\n    zeroRewardsStartTVL = _zeroRewardsStartTVL;\n    maxRewardsRate = _maxRewardsRate;\n    sher = _sher;\n\n    emit Initialized(_maxRewardsEndTVL, _zeroRewardsStartTVL, _maxRewardsRate);\n  }\n\n  // This function is called (by core Sherlock contracrt) as soon as a staker stakes\n  // Calculates the SHER tokens owed to the stake, then transfers the SHER to the Sherlock core contract\n  // Staker won't actually receive these SHER tokens until the lockup has expired though\n  /// @notice Caller will receive `_sher` SHER tokens based on `_amount` and `_period`\n  /// @param _amount Amount of tokens (in USDC) staked\n  /// @param _period Period of time for stake, in seconds\n  /// @param _id ID for this NFT position\n  /// @param _receiver Address that will be linked to this position\n  /// @return _sher Amount of SHER tokens sent to Sherlock core contract\n  /// @dev Calling contract will depend on before + after balance diff and return value\n  /// @dev INCLUDES stake in calculation, function expects the `_amount` to be deposited already\n  /// @dev If tvl=50 and amount=50, this means it is calculating SHER rewards for the first 50 tokens going in\n  /// @dev Doesn't include whenNotPaused modifier as it's onlySherlockCore where pause is captured\n  /// @dev `_id` and `_receiver` are unused in this implementation\n  function pullReward(\n    uint256 _amount,\n    uint256 _period,\n    uint256 _id,\n    address _receiver\n  ) external override onlySherlockCore returns (uint256 _sher) {\n    // Uses calcReward() to get the SHER tokens owed to this stake\n    // Subtracts the amount from the total token balance to get the pre-stake USDC TVL\n    _sher = calcReward(sherlockCore.totalTokenBalanceStakers() - _amount, _amount, _period);\n    // Sends the SHER tokens to the core Sherlock contract where they are held until the unlock period for the stake expires\n    if (_sher != 0) sher.safeTransfer(msg.sender, _sher);\n  }\n\n  /// @notice Calculates how many `_sher` SHER tokens are owed to a stake position based on `_amount` and `_period`\n  /// @param _tvl TVL to use for reward calculation (pre-stake TVL)\n  /// @param _amount Amount of tokens (USDC) staked\n  /// @param _period Stake period (in seconds)\n  /// @return _sher Amount of SHER tokens owed to this stake position\n  /// @dev EXCLUDES `_amount` of stake, this will be added on top of TVL (_tvl is excluding _amount)\n  /// @dev If tvl=0 and amount=50, it would calculate for the first 50 tokens going in (different from pullReward())\n  function calcReward(\n    uint256 _tvl,\n    uint256 _amount,\n    uint256 _period\n  ) public view override returns (uint256 _sher) {\n    if (_amount == 0) return 0;\n\n    // Figures out how much of this stake should receive max rewards\n    // _tvl is the pre-stake TVL (call it $80M) and maxRewardsEndTVL could be $100M\n    // If maxRewardsEndTVL is bigger than the pre-stake TVL, then some or all of the stake could receive max rewards\n    // In this case, the amount of the stake to receive max rewards is maxRewardsEndTVL - _tvl\n    // Otherwise, the pre-stake TVL could be bigger than the maxRewardsEndTVL, in which case 0 max rewards are available\n    uint256 maxRewardsAvailable = maxRewardsEndTVL > _tvl ? maxRewardsEndTVL - _tvl : 0;\n\n    // Same logic as above for the TVL at which all SHER rewards end\n    // If the pre-stake TVL is lower than the zeroRewardsStartTVL, then SHER rewards are still available to all or part of the stake\n    // The starting point of the slopeRewards is calculated using max(maxRewardsEndTVL, tvl).\n    // The starting point is either the beginning of the slope --> maxRewardsEndTVL\n    // Or it's the current amount of TVL in case the point on the curve is already on the slope.\n    uint256 slopeRewardsAvailable = zeroRewardsStartTVL > _tvl\n      ? zeroRewardsStartTVL - Math.max(maxRewardsEndTVL, _tvl)\n      : 0;\n\n    // If there are some max rewards available...\n    if (maxRewardsAvailable != 0) {\n      // And if the entire stake is still within the maxRewardsAvailable amount\n      if (_amount <= maxRewardsAvailable) {\n        // Then the entire stake amount should accrue max SHER rewards\n        return (_amount * maxRewardsRate * _period) / DECIMALS;\n      } else {\n        // Otherwise, the stake takes all the maxRewardsAvailable left and the calc continues\n        // We add the maxRewardsAvailable amount to the TVL (now _tvl should be equal to maxRewardsEndTVL)\n        _tvl += maxRewardsAvailable;\n        // We subtract the amount of the stake that received max rewards\n        _amount -= maxRewardsAvailable;\n\n        // We accrue the max rewards available at the max rewards rate for the stake period to the SHER balance\n        // This could be: $20M of maxRewardsAvailable which gets paid .01 SHER per second (max rate) for 3 months worth of seconds\n        // Calculation continues after this\n        _sher = (maxRewardsAvailable * maxRewardsRate * _period) / DECIMALS;\n      }\n    }\n\n    // If there are SHER rewards still available (we didn't surpass zeroRewardsStartTVL)...\n    if (slopeRewardsAvailable != 0) {\n      // If the amount left is greater than the slope rewards available, we take all the remaining slope rewards\n      if (_amount > slopeRewardsAvailable) _amount = slopeRewardsAvailable;\n\n      // We take the average position on the slope that the stake amount occupies\n      // This excludes any stake amount <= maxRewardsEndTVL or >= zeroRewardsStartTVL_\n      // e.g. if tvl = 100m (and maxRewardsEndTVL is $100M), 50m is deposited, point at 125m is taken\n      uint256 position = _tvl + (_amount / 2);\n\n      // Calc SHER rewards based on position on the curve\n      // (zeroRewardsStartTVL - position) divided by (zeroRewardsStartTVL - maxRewardsEndTVL) gives the % of max rewards the amount should get\n      // Multiply this percentage by maxRewardsRate to get the rate at which this position should accrue SHER\n      // Multiply by the _amount to get the full SHER amount earned per second\n      // Multiply by the _period to get the total SHER amount owed to this position\n      _sher +=\n        (((zeroRewardsStartTVL - position) * _amount * maxRewardsRate * _period) /\n          (zeroRewardsStartTVL - maxRewardsEndTVL)) /\n        DECIMALS;\n    }\n  }\n\n  /// @notice Function used to check if this is the current active distribution manager\n  /// @return Boolean indicating it's active\n  /// @dev If inactive the owner can pull all ERC20s and ETH\n  /// @dev Will be checked by calling the sherlock contract\n  function isActive() public view override returns (bool) {\n    return address(sherlockCore.sherDistributionManager()) == address(this);\n  }\n\n  // Only contract owner can call this\n  // Sends all specified tokens in this contract to the receiver's address (as well as ETH)\n  function sweep(address _receiver, IERC20[] memory _extraTokens) external onlyOwner {\n    if (_receiver == address(0)) revert ZeroArgument();\n    // This contract must NOT be the current assigned distribution manager contract\n    if (isActive()) revert InvalidConditions();\n    // Executes the sweep for ERC-20s specified in _extraTokens as well as for ETH\n    _sweep(_receiver, _extraTokens);\n  }\n}"
}