feat(perps): add provider-routed Scale price normalization - #10021
Conversation
d088983 to
c0a896d
Compare
geositta
left a comment
There was a problem hiding this comment.
I reviewed this change against origin/main. Provider routing and Hyperliquid precision behavior are correct, and the shared normalizer keeps preview and placement formatting aligned. The two comments tighten TypeScript exhaustiveness and regression coverage without blocking this PR.
| | Readonly<{ | ||
| status: 'unavailable'; | ||
| providerId?: PerpsProviderType; | ||
| reason: OrderCapabilitiesUnavailableReason; |
There was a problem hiding this comment.
Could we define a Scale specific unavailable reason union? OrderCapabilitiesUnavailableReason includes strategy_market_unsupported, which this API cannot return and forces consumers to handle an impossible state.
| it('normalizes every rung with provider-owned market precision', async () => { | ||
| const { infoClient } = useStrategyClients(); | ||
|
|
||
| expect(await provider.getScalePriceLadder(params)).toStrictEqual({ |
There was a problem hiding this comment.
Could we add a parity test comparing fractional preview prices with the prices submitted by Scale placement? Preview covers fractional prices, while placement assertions use integers; exact preview and submission parity is this API’s primary contract.
Explanation
Adds the provider-neutral
PerpsController:getScalePriceLadderAPI.providerIdis optional: omitting it uses the active/default provider, while supplying it routes explicitly in aggregated mode.Providers own market metadata and venue formatting. HyperLiquid precision is no longer exposed through a public venue-specific helper.
References
Validation
@metamask/perps-controllersuite and coverage gatebfe5e685c6e8c54fb46b8c446380e28bb1c6baa7Checklist
Note
Low Risk
Additive read-only API with optional provider hooks; HyperLiquid scale placement only shares an internal normalization helper, so trading behavior should stay consistent while previews move off client-side venue formatting.
Overview
Adds
PerpsController:getScalePriceLadderso clients can preview Scale ladder prices through the same provider routing as order placement. OptionalproviderIdselects a venue in aggregated mode; otherwise the active/default provider is used. Results are areadypayload with venue-normalized price strings or a typedunavailablestatus (mirroring order-capabilities reasons).The
PerpsProviderinterface gains an optionalgetScalePriceLadderhook, with routing implemented onAggregatedPerpsProviderand a HyperLiquid implementation that resolves marketszDecimals, formats rungs, and rejects ladders whose prices collapse to duplicates. HyperLiquidgetOrderCapabilitiesis refactored to share market lookup with the ladder path, and scale placement reuses the same normalization helper so preview and submit stay aligned.Exports messenger action types plus
GetScalePriceLadderParams/PerpsScalePriceLadder; tests cover controller, aggregator, and HyperLiquid behavior.Reviewed by Cursor Bugbot for commit bfe5e68. Bugbot is set up for automated code reviews on this repo. Configure here.