{
    "Function": "viewCapitalRequirements",
    "File": "contracts/SherBuy.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "IERC20"
    ],
    "Internal Calls": [
        "revert InvalidState()",
        "revert ZeroArgument()",
        "active",
        "revert InvalidAmount()",
        "revert SoldOut()"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "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  }"
}