Skip to content

feat: Add Binance price feed adapter to PriceClient - #1493

Open
droplet-rl wants to merge 1 commit into
masterfrom
droplet/C0A538XAY8Z-1783701461-binance-feed
Open

feat: Add Binance price feed adapter to PriceClient#1493
droplet-rl wants to merge 1 commit into
masterfrom
droplet/C0A538XAY8Z-1783701461-binance-feed

Conversation

@droplet-rl

Copy link
Copy Markdown
Contributor

What

Adds binance.PriceFeed, a new PriceClient adapter sourcing prices from Binance market data (data-api.binance.vision, the public mirror — api.binance.com is geo-restricted).

Binance quotes pairs (base/quote), not USD legs, so the adapter maps each supported token address either to a fixed USD anchor or to a listed pair whose top-of-book mid ((bid+ask)/2 from /api/v3/ticker/bookTicker) resolves its price. Default mappings:

  • USDC (mainnet) → anchored at 1.0
  • USDT (mainnet) → 1 / mid(USDCUSDT)

This preserves the exact Binance USDT/USDC ratio — the quantity stablecoin swap-fill profitability checks consume. Conventions (host, bookTicker mid, USDCUSDT inversion) deliberately mirror quote-api's api/_binance.ts so API quoting and relayer-side checks share a common reference.

Fall-through for unmapped tokens: addresses without a mapping are omitted from the response, which PriceClient.updatePrices already treats as "skipped → try the next feed" (covered by existing tests). The adapter can therefore be installed ahead of the general-purpose USD feeds to pin specific tokens to Binance pricing, e.g. in the relayer's ProfitClient:

new PriceClient(logger, [
  new binance.PriceFeed(),          // USDT/USDC at Binance rates; everything else falls through
  new acrossApi.PriceFeed(...),
  new coingecko.PriceFeed(...),
  new defiLlama.PriceFeed(),
]);

Custom pairs can be added via the mappings constructor arg.

Why

The API quotes AVAX USDT → Base USDC internalized swaps at Binance + 5 bps, but the relayer prices profitability off Across API/CoinGecko/DefiLlama — feed skew between the two can reject (or accept) fills the quote intended. Per Slack discussion, this adapter is the building block for the relayer to probe Binance directly. Wiring it into the relayer's ProfitClient is a follow-up in across-protocol/relayer.

Testing

  • New test/priceClient.binance.test.ts: 10 cases covering default/custom mappings, inversion math, case-insensitive address lookups, unmapped-address omission + PriceClient fall-through, malformed/non-positive responses, non-USD rejection, and the no-HTTP-for-fixed-anchor path. All pass.
  • Existing priceClient.test.ts (9 cases) still passes; tsc --noEmit, eslint, and prettier clean on changed files.

Slack context: https://umaproject.slack.com/archives/C0A538XAY8Z/p1783701461063109

🤖 Generated with Claude Code

Adds a Binance adapter for the PriceClient so consumers (notably the
relayer ProfitClient) can source stablecoin cross rates from Binance
rather than CoinGecko-family feeds.

Binance quotes pairs rather than USD legs, so each supported token maps
either to a fixed USD anchor or to a listed pair mid. The default
mapping anchors USDC at 1.0 and prices USDT as 1/mid(USDCUSDT) from the
top-of-book (bid+ask)/2 - preserving the exact Binance USDT/USDC ratio
that stablecoin swap-fill profitability checks consume. This mirrors
the quote-api Binance client (same data-api.binance.vision host,
bookTicker mid, USDCUSDT inversion) so API quoting and relayer checks
share a common reference.

Unmapped addresses are omitted from responses, which the PriceClient
already treats as a fall-through to the next configured feed - so the
adapter can be installed ahead of general-purpose USD feeds to pin
specific tokens to Binance pricing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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