```\ncontracts/user/UserManager.sol\n\n function unstake(uint96 amount) external whenNotPaused nonReentrant {\n       Staker storage staker = stakers[msg.sender];\n       // Stakers can only unstaked stake balance that is unlocked. Stake balance\n       // becomes locked when it is used to underwrite a borrow.\n       if (staker.stakedAmount - staker.locked < amount) revert InsufficientBalance();\n       comptroller.withdrawRewards(msg.sender, stakingToken);\n       uint256 remaining = IAssetManager(assetManager).withdraw(stakingToken, msg.sender, amount);\n       if (uint96(remaining) > amount) {\n           revert AssetManagerWithdrawFailed();\n       }\n       uint96 actualAmount = amount - uint96(remaining);\n       _updateStakedCoinAge(msg.sender, staker);\n       staker.stakedAmount -= actualAmount;\n       totalStaked -= actualAmount;\n       emit LogUnstake(msg.sender, actualAmount);\n   }\n```\n