{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/SherBuy.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract SherBuy {\n  using SafeERC20 for IERC20;\n\n  error InvalidSender();\n  error InvalidAmount();\n  error ZeroArgument();\n  error InvalidState();\n  error SoldOut();\n\n  /// @notice Emitted when SHER purchase is executed\n  /// @param buyer Account that bought SHER tokens\n  /// @param amount How much SHER tokens are bought\n  /// @param staked How much USDC is staked\n  /// @param paid How much USDC is paid\n  event Purchase(address indexed buyer, uint256 amount, uint256 staked, uint256 paid);\n\n  // The staking period used for the staking USDC\n  uint256 public constant PERIOD = 26 weeks;\n  // Allows purchases in steps of 0.01 SHER\n  uint256 internal constant SHER_STEPS = 10**16;\n  // Allows stakeRate and buyRate with steps of 0.01 USDC\n  uint256 internal constant RATE_STEPS = 10**4;\n  // SHER has 18 decimals\n  uint256 internal constant SHER_DECIMALS = 10**18;\n\n  // SHER token address (18 decimals)\n  IERC20 public immutable sher;\n  // USDC token address (6 decimals)\n  IERC20 public immutable usdc;\n\n  // 10**6 means for every 1 SHER token you want to buy, you will stake 1 USDC (10**7 means 1 SHER for 10 USDC)\n  uint256 public immutable stakeRate;\n  // 10**6 means for every 1 SHER token you want to buy, you will pay 1 USDC (10**7 means 1 SHER for 10 USDC)\n  uint256 public immutable buyRate;\n  // The `Sherlock.sol` contract that is a ERC721\n  ISherlock public immutable sherlockPosition;\n  // Address receiving the USDC payments\n  address public immutable receiver;\n  // Contract to claim SHER at\n  ISherClaim public immutable sherClaim;\n\n  /// @notice Construct BuySher contract\n  /// @param _sher ERC20 contract for SHER token\n  /// @param _usdc ERC20 contract for USDC token\n  /// @param _stakeRate Rate at which SHER tokens translate to the amount of USDC needed to be staked\n  /// @param _buyRate Rate at which SHER tokens translate to the amount of USDC needed to be paid\n  /// @param _sherlockPosition ERC721 contract of Sherlock positions\n  /// @param _receiver Address that receives USDC from purchases\n  /// @param _sherClaim Contract that keeps the SHER timelocked\n  constructor(\n    IERC20 _sher,\n    IERC20 _usdc,\n    uint256 _stakeRate,\n    uint256 _buyRate,\n    ISherlock _sherlockPosition,\n    address _receiver,\n    ISherClaim _sherClaim\n  ) {\n    if (address(_sher) == address(0)) revert ZeroArgument();\n    if (address(_usdc) == address(0)) revert ZeroArgument();\n    if (_stakeRate == 0) revert ZeroArgument();\n    if (_stakeRate % RATE_STEPS != 0) revert InvalidState();\n    if (_buyRate == 0) revert ZeroArgument();\n    if (_buyRate % RATE_STEPS != 0) revert InvalidState();\n    if (address(_sherlockPosition) == address(0)) revert ZeroArgument();\n    if (_receiver == address(0)) revert ZeroArgument();\n    if (address(_sherClaim) == address(0)) revert ZeroArgument();\n\n    // Verify is PERIOD is active\n    // Theoretically this period can be disabled during the lifetime of this contract, which will cause issues\n    if (_sherlockPosition.stakingPeriods(PERIOD) == false) revert InvalidState();\n\n    sher = _sher;\n    usdc = _usdc;\n    stakeRate = _stakeRate;\n    buyRate = _buyRate;\n    sherlockPosition = _sherlockPosition;\n    receiver = _receiver;\n    sherClaim = _sherClaim;\n\n    // Do max approve in constructor as this contract will not hold any USDC\n    usdc.approve(address(sherlockPosition), type(uint256).max);\n  }\n\n  /// @notice Check if the liquidity event is active\n  /// @dev SHER tokens can run out while event is active\n  /// @return True if the liquidity event is active\n  function active() public view returns (bool) {\n    // The claim contract will become active once the liquidity event is inactive\n    return block.timestamp < sherClaim.claimableAt();\n  }\n\n  /// @notice View the capital requirements needed to buy up until `_sherAmountWant`\n  /// @dev Will adjust to remaining SHER if `_sherAmountWant` exceeds that\n  /// @return sherAmount Will adjust to remining SHER if `_sherAmountWant` exceeds that\n  /// @return stake How much USDC needs to be staked for `PERIOD` of time to buy `sherAmount` SHER\n  /// @return price How much USDC needs to be paid to buy `sherAmount` SHER\n  function viewCapitalRequirements(uint256 _sherAmountWant)\n    public\n    view\n    returns (\n      uint256 sherAmount,\n      uint256 stake,\n      uint256 price\n    )\n  {\n    // Only allow if liquidity event is active\n    if (active() == false) revert InvalidState();\n    // Zero isn't allowed\n    if (_sherAmountWant == 0) revert ZeroArgument();\n\n    // View how much SHER is still available to be sold\n    uint256 available = sher.balanceOf(address(this));\n    // If remaining SHER is 0 it's sold out\n    if (available == 0) revert SoldOut();\n\n    // Use remaining SHER if it's less then `_sherAmountWant`, otherwise go for `_sherAmountWant`\n    // Remaining SHER will only be assigned on the last sale of this contract, `SoldOut()` error will be thrown after\n    // sherAmount is not able to be zero as both 'available' and '_sherAmountWant' will be bigger than 0\n    sherAmount = available < _sherAmountWant ? available : _sherAmountWant;\n    // Only allows SHER amounts with certain precision steps\n    // To ensure there is no rounding error at loss for the contract in stake / price calculation\n    // Theoretically, if `available` is used, the function can fail if '% SHER_STEPS != 0' will be true\n    // This can be caused by a griefer sending a small amount of SHER to the contract\n    // Realistically, no SHER tokens will be on the market when this function is active\n    // So it can only be caused if the admin sends too small amounts (documented at top of file with @dev)\n    if (sherAmount % SHER_STEPS != 0) revert InvalidAmount();\n\n    // Calculate how much USDC needs to be staked to buy `sherAmount`\n    stake = (sherAmount * stakeRate) / SHER_DECIMALS;\n    // Calculate how much USDC needs to be paid to buy `sherAmount`\n    price = (sherAmount * buyRate) / SHER_DECIMALS;\n  }\n\n  /// @notice Buy up until `_sherAmountWant`\n  /// @param _sherAmountWant The maximum amount of SHER the user wants to buy\n  /// @dev Bought SHER tokens are moved to a timelock contract (SherClaim)\n  /// @dev Will revert if liquidity event is inactive because of the viewCapitalRequirements call\n  function execute(uint256 _sherAmountWant) external {\n    // Calculate the capital requirements\n    // Check how much SHER can actually be bought\n    (uint256 sherAmount, uint256 stake, uint256 price) = viewCapitalRequirements(_sherAmountWant);\n\n    // Transfer usdc from user to this, for staking (max is approved in constructor)\n    usdc.safeTransferFrom(msg.sender, address(this), stake);\n    // Transfer usdc from user to receiver, for payment of the SHER\n    usdc.safeTransferFrom(msg.sender, receiver, price);\n\n    // Stake usdc and send NFT to user\n    sherlockPosition.initialStake(stake, PERIOD, msg.sender);\n    // Approve in function as this contract will hold SHER tokens\n    sher.approve(address(sherClaim), sherAmount);\n    // Add bought SHER tokens to timelock for user\n    sherClaim.add(msg.sender, sherAmount);\n\n    // Emit event about the purchase\n    emit Purchase(msg.sender, sherAmount, stake, price);\n  }\n\n  /// @notice Rescue remaining ERC20 tokens when liquidity event is inactive\n  /// @param _tokens Array of ERC20 tokens to rescue\n  /// @dev Can only be called by `receiver`\n  function sweepTokens(IERC20[] memory _tokens) external {\n    if (msg.sender != receiver) revert InvalidSender();\n    if (active()) revert InvalidState();\n\n    // Loops through the extra tokens (ERC20) provided and sends all of them to the sender address\n    for (uint256 i; i < _tokens.length; i++) {\n      IERC20 token = _tokens[i];\n      token.safeTransfer(msg.sender, token.balanceOf(address(this)));\n    }\n  }\n}"
}