{
    "Function": "_processExpiredLocks",
    "File": "contracts/AuraLocker.sol",
    "Parent Contracts": [
        "contracts/Interfaces.sol",
        "node_modules/@openzeppelin/contracts-0.8/access/Ownable.sol",
        "node_modules/@openzeppelin/contracts-0.8/utils/Context.sol",
        "node_modules/@openzeppelin/contracts-0.8/security/ReentrancyGuard.sol"
    ],
    "High-Level Calls": [
        "AuraMath",
        "AuraMath112",
        "AuraMath",
        "AuraMath112",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "SafeERC20",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath112",
        "SafeERC20",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath",
        "AuraMath"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "delegates",
        "updateReward",
        "_checkpointDelegate",
        "require(bool,string)",
        "_lock"
    ],
    "Library Calls": [
        "mul",
        "div",
        "safeTransfer",
        "add",
        "mul",
        "mul",
        "div",
        "safeTransfer",
        "div",
        "sub",
        "sub",
        "min",
        "to32",
        "mul",
        "to112",
        "sub",
        "sub",
        "sub",
        "div",
        "min",
        "div",
        "div",
        "add",
        "add",
        "mul",
        "sub",
        "sub",
        "mul",
        "sub"
    ],
    "Low-Level Calls": [],
    "Code": "function _processExpiredLocks(\n        address _account,\n        bool _relock,\n        address _rewardAddress,\n        uint256 _checkDelay\n    ) internal updateReward(_account) {\n        LockedBalance[] storage locks = userLocks[_account];\n        Balances storage userBalance = balances[_account];\n        uint112 locked;\n        uint256 length = locks.length;\n        uint256 reward = 0;\n        uint256 expiryTime = _checkDelay == 0 && _relock\n            ? block.timestamp.add(rewardsDuration)\n            : block.timestamp.sub(_checkDelay);\n        require(length > 0, \"no locks\");\n        // e.g. now = 16\n        // if contract is shutdown OR latest lock unlock time (e.g. 17) <= now - (1)\n        // e.g. 17 <= (16 + 1)\n        if (isShutdown || locks[length - 1].unlockTime <= expiryTime) {\n            //if time is beyond last lock, can just bundle everything together\n            locked = userBalance.locked;\n\n            //dont delete, just set next index\n            userBalance.nextUnlockIndex = length.to32();\n\n            //check for kick reward\n            //this wont have the exact reward rate that you would get if looped through\n            //but this section is supposed to be for quick and easy low gas processing of all locks\n            //we'll assume that if the reward was good enough someone would have processed at an earlier epoch\n            if (_checkDelay > 0) {\n                uint256 currentEpoch = block.timestamp.sub(_checkDelay).div(rewardsDuration).mul(rewardsDuration);\n                uint256 epochsover = currentEpoch.sub(uint256(locks[length - 1].unlockTime)).div(rewardsDuration);\n                uint256 rRate = AuraMath.min(kickRewardPerEpoch.mul(epochsover + 1), denominator);\n                reward = uint256(locks[length - 1].amount).mul(rRate).div(denominator);\n            }\n        } else {\n            //use a processed index(nextUnlockIndex) to not loop as much\n            //deleting does not change array length\n            uint32 nextUnlockIndex = userBalance.nextUnlockIndex;\n            for (uint256 i = nextUnlockIndex; i < length; i++) {\n                //unlock time must be less or equal to time\n                if (locks[i].unlockTime > expiryTime) break;\n\n                //add to cumulative amounts\n                locked = locked.add(locks[i].amount);\n\n                //check for kick reward\n                //each epoch over due increases reward\n                if (_checkDelay > 0) {\n                    uint256 currentEpoch = block.timestamp.sub(_checkDelay).div(rewardsDuration).mul(rewardsDuration);\n                    uint256 epochsover = currentEpoch.sub(uint256(locks[i].unlockTime)).div(rewardsDuration);\n                    uint256 rRate = AuraMath.min(kickRewardPerEpoch.mul(epochsover + 1), denominator);\n                    reward = reward.add(uint256(locks[i].amount).mul(rRate).div(denominator));\n                }\n                //set next unlock index\n                nextUnlockIndex++;\n            }\n            //update next unlock index\n            userBalance.nextUnlockIndex = nextUnlockIndex;\n        }\n        require(locked > 0, \"no exp locks\");\n\n        //update user balances and total supplies\n        userBalance.locked = userBalance.locked.sub(locked);\n        lockedSupply = lockedSupply.sub(locked);\n\n        //checkpoint the delegatee\n        _checkpointDelegate(delegates(_account), 0, 0);\n\n        emit Withdrawn(_account, locked, _relock);\n\n        //send process incentive\n        if (reward > 0) {\n            //reduce return amount by the kick reward\n            locked = locked.sub(reward.to112());\n\n            //transfer reward\n            stakingToken.safeTransfer(_rewardAddress, reward);\n            emit KickReward(_rewardAddress, _account, reward);\n        }\n\n        //relock or return to user\n        if (_relock) {\n            _lock(_account, locked);\n        } else {\n            stakingToken.safeTransfer(_account, locked);\n        }\n    }"
}