Skip to content

[codex] Extend Binance rebalancer routes for WETH#3160

Draft
nicholaspai wants to merge 7 commits intomasterfrom
npai/codex/rebalancer-binance-weth
Draft

[codex] Extend Binance rebalancer routes for WETH#3160
nicholaspai wants to merge 7 commits intomasterfrom
npai/codex/rebalancer-binance-weth

Conversation

@nicholaspai
Copy link
Copy Markdown
Member

@nicholaspai nicholaspai commented Apr 6, 2026

What changed

  • moved built-in rebalance route generation into src/rebalancer/buildRebalanceRoutes.ts
  • refactored route construction around token-keyed BINANCE_NETWORKS_BY_SYMBOL and REBALANCE_CHAINS_BY_SYMBOL maps so Binance venue support and rebalancer enablement are configured separately
  • expanded Binance routes to support WETH <-> USDC, WETH <-> USDT, and direct WETH <-> WETH transfers on direct Binance ETH networks
  • added same-asset Binance routes for USDC <-> USDC and USDT <-> USDT so they can compete on estimated cost against CCTP and OFT routes
  • colocated the same-asset Binance route generation with the CCTP/OFT route blocks and only emit those Binance routes when both chains are direct Binance networks for that asset
  • taught the Binance adapter to treat on-chain WETH as Binance ETH, skip the swap leg for same-coin transfers, and avoid intermediate bridge legs for assets that cannot use them
  • added helper coverage for Binance route math and route-generation coverage for the new WETH and same-asset stablecoin families
  • documented the new route construction and Binance operational constraints in the rebalancer README

Why

The existing rebalancer/Binance flow was effectively limited to USDC and USDT swap routes. These changes open the path for WETH support and also let Binance compete directly with CCTP/OFT when the source and destination asset are already the same, while still avoiding same-asset Binance routes on chains that would require intermediate bridge legs.

The token-keyed network maps also make it easier to distinguish between:

  • chains Binance currently supports for a token
  • chains this repo currently wants the rebalancer to use for that token

Impact

Rebalancer route construction now exposes WETH-capable Binance families plus same-asset Binance stablecoin routes on direct Binance networks, and the Binance adapter can process both swap-backed routes and same-coin withdrawals safely.

Validation

  • yarn build
  • yarn test test/BinanceAdapter.helpers.ts test/RebalancerClient.buildRebalanceRoutes.ts

return toBNWei(truncate(convertedAmount, outputDecimals), outputDecimals);
}

function resolveStepPrecision(stepSize: string): number {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this function should be better commented its unclear what's going on here and what its intended purpose is

private spotMarketMetaPromiseByRoute = new Map<string, Promise<SPOT_MARKET_META>>();

REDIS_PREFIX = "binance-stablecoin-swap:";
private static readonly ORDER_BOOK_CACHE_TTL_MS = 30_000;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

what does this hardcoded class variable do?

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