Skip to content

fix: Binance CEX pending withdrawal logic and adapter zero-amount cleanup#3110

Merged
nicholaspai merged 8 commits intomasterfrom
npai/adapter-binance-cex-fix
Mar 26, 2026
Merged

fix: Binance CEX pending withdrawal logic and adapter zero-amount cleanup#3110
nicholaspai merged 8 commits intomasterfrom
npai/adapter-binance-cex-fix

Conversation

@nicholaspai
Copy link
Copy Markdown
Member

@nicholaspai nicholaspai commented Mar 25, 2026

Summary

Fixes Binance CEX bridge pending withdrawal computation and adapter cleanup (split from #3073).

BinanceCEXBridge

  • Rewrites getL2PendingWithdrawalAmount to correctly compute outstanding deposits when the Binance finalizer batches deposits from multiple L2s into a single L1 withdrawal. The old approach (total deposits minus total withdrawals per-chain) incorrectly showed zero outstanding when a withdrawal for a different L2's deposit exceeded the current chain's deposit amount
  • Uses getOutstandingBinanceDeposits (from improve: Add utility functions for inventory equivalence remapping and Binance deposit matching #3108) — a net-outstanding algorithm that computes total deposits minus total withdrawals, then attributes the remaining volume to the newest deposits (since older deposits get finalized first)
  • Removes per-deposit sender filtering — depositHistory (filtered by coin and non-swap) is passed directly to the matching algorithm
  • Reduces pendingWithdrawalLookbackPeriodSeconds to 1 hour (Binance withdrawals are fast)

BaseChainAdapter

  • Uses getInventoryEquivalentL1TokenAddress for L1 token resolution (replaces hardcoded pathUSD check)
  • Skips zero-amount entries in getOutstandingCrossChainTransfers — a transfer with totalAmount === 0 is not outstanding

AdapterManager

  • Removes debug log in getOutstandingCrossChainTransfers
  • Only assigns totalBalance[chainId] when pendingAmount > 0 in getTotalPendingWithdrawalAmount

Test updates

  • MockLineaEvents.sol: emitBridgingInitiated/emitBridgingFinalized now accept amount parameter instead of hardcoding 0
  • Generic adapter tests (Linea, Polygon, Scroll, zkSync): updated to expect empty results when no transfers are outstanding, use non-zero amounts for Linea ERC20 tests

Upstream dependencies

Downstream PRs

Test plan

  • All 85 generic adapter tests pass
  • BinanceUtils unit tests pass (6 tests for getOutstandingBinanceDeposits)

🤖 Generated with Claude Code

nicholaspai and others added 2 commits March 25, 2026 11:36
…inance deposit matching, and floatToBN fix

- TokenUtils: getInventoryEquivalentL1TokenAddress, getInventoryBalanceContributorTokens, isL2OnlyEquivalentToken
- RunningBalanceUtils: getLatestRunningBalances extracted for shared use
- BinanceUtils: getOutstandingBinanceDeposits for cross-L2 deposit matching, export BinanceDeposit type
- BNUtils: Fix floatToBN MAX_SAFE_INTEGER overflow via string manipulation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- BinanceCEXBridge: rewrite getL2PendingWithdrawalAmount to correctly compute outstanding
  deposits when finalizer batches deposits from multiple L2s into single L1 withdrawal.
  Uses getOutstandingBinanceDeposits with Redis-cached deposit sender lookups.
- BaseChainAdapter: use getInventoryEquivalentL1TokenAddress, skip zero-amount outstanding
  transfers in getOutstandingCrossChainTransfers
- AdapterManager: minor cleanup
- MockLineaEvents: accept amount parameter for BridgingInitiatedV2/BridgingFinalizedV2
- Generic adapter tests: updated for zero-amount skip behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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: ff3f76859e

ℹ️ 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 and others added 2 commits March 25, 2026 13:05
Refactor deposit sender caching to resolve the EOA once from the first readable
receipt on cache miss, then reuse for the entire batch. This reduces RPC calls
from O(n) per deposit to O(1) per invocation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@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: 27e508d5f6

ℹ️ 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".

Base automatically changed from npai/utils-token-binance-bn to master March 25, 2026 21:13
@nicholaspai nicholaspai merged commit 673c4ca into master Mar 26, 2026
4 checks passed
@nicholaspai nicholaspai deleted the npai/adapter-binance-cex-fix branch March 26, 2026 14:52
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