Skip to content

fix: recover stuck terminal wallet accounts#62

Open
kenny019 wants to merge 1 commit intodevfrom
fix/stuck-terminal-wallet-recovery
Open

fix: recover stuck terminal wallet accounts#62
kenny019 wants to merge 1 commit intodevfrom
fix/stuck-terminal-wallet-recovery

Conversation

@kenny019
Copy link
Copy Markdown
Owner

@kenny019 kenny019 commented Apr 2, 2026

Summary

  • persist terminal trade accounts as recoverable before queued cleanup runs
  • use terminal trade margin for wallet-side manual recovery and surface previously silent transfer failures
  • add focused helper tests for recovery amount selection, persisted terminal state, and cleanup-failure dedupe

Verification

  • pnpm vitest run lib/state/local/accounts.test.ts lib/state/local/trade.test.ts lib/utils/tradeRecovery.test.ts
  • pnpm exec tsc --noEmit

Note

Medium Risk
Touches trade cleanup and wallet transfer flows that move funds between ZK subaccounts and the funding/trading accounts; incorrect amounts or state updates could block recovery or transfer the wrong balance.

Overview
Fixes recovery for terminal trade subaccounts (e.g. SETTLED/CANCELLED) by persisting a recoverable ZkAccount state (type + rounded availableMargin) before queued cleanup attempts to merge funds back into the master trading account.

Updates the wallet’s “Transfer to Funding” flow to compute the recovery transfer amount from terminal trade availableMargin (instead of stale zkAccount.value) and surfaces previously silent failures with explicit error toasts.

Adds lib/utils/tradeRecovery.ts helpers plus focused unit tests covering terminal-account persistence, manual recovery amount selection, and deduped cleanup-failure notifications.

Written by Cursor Bugbot for commit 77da21b. This will update automatically on new commits. Configure here.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
twilight-pool Ready Ready Preview, Comment Apr 2, 2026 1:41pm

Request Review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

const zkAccountToSettle: ZkAccount = {
...currentZkAccount,
value: newBalance,
type: accountType,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused accountType variable after refactor to helper

Low Severity

The accountType variable is now dead code. It was previously consumed when constructing zkAccountToSettle inline, but that logic was replaced by buildPersistedTerminalTradeAccount, which derives the type internally. The variable is assigned but never read.

Fix in Cursor Fix in Web

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