Skip to content

feat(staking): add emergencyWithdraw to MultiTokenStaking#5366

Closed
michaelxmchn wants to merge 1 commit into
ClankerNation:mainfrom
michaelxmchn:fix/multitoken-emergency-withdraw-195
Closed

feat(staking): add emergencyWithdraw to MultiTokenStaking#5366
michaelxmchn wants to merge 1 commit into
ClankerNation:mainfrom
michaelxmchn:fix/multitoken-emergency-withdraw-195

Conversation

@michaelxmchn

Copy link
Copy Markdown

Summary

Add emergencyWithdraw(uint256 pid) to MultiTokenStaking — allows users to recover staked tokens without rewards during any contract state.

function emergencyWithdraw(uint256 pid) external nonReentrant {
    PoolInfo storage pool = poolInfo[pid];
    UserInfo storage user = userInfo[pid][msg.sender];
    uint256 amount = user.amount;
    require(amount > 0, "Nothing to withdraw");
    user.amount = 0;
    user.rewardDebt = 0;
    pool.totalStaked -= amount;
    pool.stakeToken.safeTransfer(msg.sender, amount);
    emit EmergencyWithdraw(msg.sender, pid, amount);
}

Details

  • No reward distribution on emergency withdrawal (only returns principal)
  • Resets reward debt to zero
  • Decrements pool totalStaked for correct accounting
  • Emits EmergencyWithdraw event (user, pid, amount)
  • SafeERC20 for token transfer

Test Plan

7 tests 7/7 PASS:

  • Revert when nothing staked
  • Returns all staked tokens
  • Resets user amount and rewardDebt to 0
  • Decrements pool totalStaked
  • Does not distribute rewards
  • Emits correct event
  • Works during any contract state (even with pending rewards)

🤖 Generated with Claude Code

- Add emergencyWithdraw(pid) that returns staked tokens without rewards
- Reset user amount and rewardDebt to zero
- Decrement pool totalStaked correctly
- Emit EmergencyWithdraw event
- 7 tests covering: empty stake revert, token return, storage reset,
  totalStaked decrement, no reward on emergency, event emission, any-state safety

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Unfortunately the changes in this PR didn't fully resolve the issue. Please rework your solution and submit a new pull request within 2 hours.

Make sure to review the acceptance criteria in the linked issue and verify all conditions are met before resubmitting.

@github-actions github-actions Bot closed this Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant