{
    "Function": "lockTokens",
    "File": "contracts/staking/libs/Stakes.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "MathUtils",
        "SafeMath",
        "SafeMath",
        "MathUtils"
    ],
    "Internal Calls": [],
    "Library Calls": [
        "weightedAverage",
        "add",
        "diffOrZero",
        "add"
    ],
    "Low-Level Calls": [],
    "Code": "function lockTokens(\n        Stakes.Indexer storage stake,\n        uint256 _tokens,\n        uint256 _period\n    ) internal {\n        // Take into account period averaging for multiple unstake requests\n        uint256 lockingPeriod = _period;\n        if (stake.tokensLocked > 0) {\n            lockingPeriod = MathUtils.weightedAverage(\n                MathUtils.diffOrZero(stake.tokensLockedUntil, block.number), // Remaining thawing period\n                stake.tokensLocked, // Weighted by remaining unstaked tokens\n                _period, // Thawing period\n                _tokens // Weighted by new tokens to unstake\n            );\n        }\n\n        // Update balances\n        stake.tokensLocked = stake.tokensLocked.add(_tokens);\n        stake.tokensLockedUntil = block.number.add(lockingPeriod);\n    }"
}