Skip to content

feat(rebalancer): add Matcha adapter for on-chain DEX swaps via 0x API#3125

Draft
nicholaspai wants to merge 7 commits intomasterfrom
0x-rebalancer-adapter
Draft

feat(rebalancer): add Matcha adapter for on-chain DEX swaps via 0x API#3125
nicholaspai wants to merge 7 commits intomasterfrom
0x-rebalancer-adapter

Conversation

@nicholaspai
Copy link
Copy Markdown
Member

@nicholaspai nicholaspai commented Mar 27, 2026

Summary

  • Introduces MatchaSwapAdapter for on-chain DEX-aggregated USDT↔USDC swaps via the 0x Swap API, supporting Ethereum, BSC, Arbitrum, and Base
  • Extracts shared bridge-routing logic from Binance/Hyperliquid into SwapAdapterBase, reducing ~400 lines of duplication across swap adapters
  • Adds MatchaUtils helper for 0x Swap API quote/swap interactions with gas cost estimation
  • Adapters are now conditionally registered: Binance requires BINANCE_API_KEY, Matcha requires ZERO_X_API_KEY
  • Adds _estimateGasCostInSourceToken to BaseAdapter for on-chain gas cost estimation in stablecoin terms

Test plan

  • Verify Matcha adapter initializes correctly with ZERO_X_API_KEY set
  • Verify adapter is skipped when ZERO_X_API_KEY is unset
  • Test Matcha swap flow end-to-end on a supported chain (e.g., Arbitrum USDT→USDC)
  • Verify Binance/Hyperliquid adapters still work after SwapAdapterBase refactor
  • Verify pending-order tracking and sweep behavior for Matcha orders

Copy link
Copy Markdown
Member Author

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

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

@codex please respond to comments

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: d54d723baf

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

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: d54d723baf

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

@chatgpt-codex-connector
Copy link
Copy Markdown

Summary

  • Addressed the CCTP gas-estimation review by replacing the fixed 65_000 assumption with a conservative, configurable constant CCTP_DEPOSIT_FOR_BURN_GAS_UNITS (default 140_000) in getEstimatedCost().
  • Addressed the Hyperliquid gas-units review by introducing configurable constants for both legs and updating the withdrawal estimate to include intrinsic tx overhead (default 45_000 instead of 20_000).
  • Addressed the Matcha ordering/crash-recovery review by persisting swapTxHash before transitioning/creating PENDING_SWAP, and added an explicit comment to keep this ordering consistent in status updates.
  • Added targeted documentation for the new optional gas-estimation tuning env vars in the rebalancer README.

Testing

  • yarn -s tsc --noEmit (invalid Yarn invocation in this repo’s Yarn version; command form was incorrect).
  • ⚠️ yarn run tsc --noEmit (environment/workspace limitation: Yarn reports workspace package/lockfile linkage missing, so TypeScript check could not run).

View task →

@nicholaspai nicholaspai changed the title feat(RebalancerClient): add Matcha (0x) DEX swap adapter feat(rebalancer): add Matcha adapter for on-chain DEX swaps via 0x API Mar 28, 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