Skip to content

fix: [codex] Handle failed Binance withdrawals#3175

Merged
nicholaspai merged 6 commits intonpai/codex/binance-completed-withdrawal-filteringfrom
npai/codex/binance-withdraw-failure-handling
Apr 8, 2026
Merged

fix: [codex] Handle failed Binance withdrawals#3175
nicholaspai merged 6 commits intonpai/codex/binance-completed-withdrawal-filteringfrom
npai/codex/binance-withdraw-failure-handling

Conversation

@nicholaspai
Copy link
Copy Markdown
Member

@nicholaspai nicholaspai commented Apr 7, 2026

What changed

  • treat Binance withdrawal statuses CANCELLED, REJECTED, and FAILURE as terminal failures in the rebalancer Binance adapter
  • if a submitted withdrawal later fails, clear the saved Binance withdrawal id and move the order from PENDING_WITHDRAWAL back to PENDING_SWAP
  • leave the existing PENDING_SWAP -> PENDING_WITHDRAWAL transition in place after a successful withdraw() submission
  • add a focused unit test for Binance withdrawal failure classification

Why

A successful withdraw() response only means Binance accepted the withdrawal request for processing. It can still later fail.

Before this change, the adapter only looked for completed withdrawals onchain and otherwise treated the withdrawal as still pending. That meant terminal Binance withdrawal failures could get stuck in PENDING_WITHDRAWAL indefinitely.

This patch keeps the current state machine intact, but adds the minimal recovery path needed for failed withdrawals.

Validation

  • yarn test test/BinanceAdapter.withdrawals.ts
  • yarn eslint src/rebalancer/adapters/binance.ts test/BinanceAdapter.withdrawals.ts
  • yarn build

Stack

@nicholaspai nicholaspai marked this pull request as ready for review April 7, 2026 21:16
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b669fa4d49

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nicholaspai
Copy link
Copy Markdown
Member Author

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52931079e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nicholaspai nicholaspai force-pushed the npai/codex/binance-withdraw-failure-handling branch from bebd3b1 to 5438b3d Compare April 7, 2026 22:02
@nicholaspai nicholaspai changed the base branch from npai/codex/binance-server-time-sync to master April 7, 2026 22:02
@nicholaspai nicholaspai force-pushed the npai/codex/binance-withdraw-failure-handling branch from 5438b3d to 253c860 Compare April 7, 2026 22:04
@nicholaspai nicholaspai changed the base branch from master to npai/codex/binance-completed-withdrawal-filtering April 7, 2026 22:04
… npai/codex/binance-withdraw-failure-handling
… npai/codex/binance-withdraw-failure-handling
@nicholaspai nicholaspai merged commit 9fd9ca1 into npai/codex/binance-completed-withdrawal-filtering Apr 8, 2026
3 checks passed
@nicholaspai nicholaspai deleted the npai/codex/binance-withdraw-failure-handling branch April 8, 2026 13:40
nicholaspai added a commit that referenced this pull request Apr 8, 2026
* filter callers to completed Binance withdrawals

* fix: [codex] Handle failed Binance withdrawals (#3175)

* handle failed Binance withdrawals

* preserve failed Binance withdrawal tags

* match only terminal Binance withdrawals

* reuse Binance withdrawal status enum
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.

2 participants