feat: Add Binance price feed adapter to PriceClient - #1493
Open
droplet-rl wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
binance.PriceFeed, a new PriceClient adapter sourcing prices from Binance market data (data-api.binance.vision, the public mirror —api.binance.comis 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)/2from/api/v3/ticker/bookTicker) resolves its price. Default mappings:1.01 / 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.tsso 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.updatePricesalready 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:Custom pairs can be added via the
mappingsconstructor 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
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.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