{
    "Function": "tokensAvailableWithDelegation",
    "File": "contracts/staking/libs/Stakes.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "SafeMath",
        "SafeMath",
        "Stakes"
    ],
    "Internal Calls": [],
    "Library Calls": [
        "add",
        "sub",
        "tokensUsed"
    ],
    "Low-Level Calls": [],
    "Code": "function tokensAvailableWithDelegation(Stakes.Indexer memory stake, uint256 _delegatedCapacity)\n        internal\n        pure\n        returns (uint256)\n    {\n        uint256 tokensCapacity = stake.tokensStaked.add(_delegatedCapacity);\n        uint256 _tokensUsed = stake.tokensUsed();\n        // If more tokens are used than the current capacity, the indexer is overallocated.\n        // This means the indexer doesn't have available capacity to create new allocations.\n        // We can reach this state when the indexer has funds allocated and then any\n        // of these conditions happen:\n        // - The delegationCapacity ratio is reduced.\n        // - The indexer stake is slashed.\n        // - A delegator removes enough stake.\n        if (_tokensUsed > tokensCapacity) {\n            // Indexer stake is over allocated: return 0 to avoid stake to be used until\n            // the overallocation is restored by staking more tokens, unallocating tokens\n            // or using more delegated funds\n            return 0;\n        }\n        return tokensCapacity.sub(_tokensUsed);\n    }"
}