feat(perps-controller): add scaleSkew to Scale orders - #9919
Merged
Conversation
abretonc7s
enabled auto-merge
August 20, 2026 15:05
geositta
approved these changes
Aug 20, 2026
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.
Explanation
Adds optional size weighting to Scale orders with
OrderParams.scaleSkew.1atscaleMinPricetoscaleSkewatscaleMaxPricefor both buys and sells. Values above1put more size near the maximum price; values below1put more near the minimum.scaleSkew, or setting it to1, preserves the existing even split exactly.splitScaleSizesaccepts the same optional skew so client previews and submitted orders use one allocation algorithm. It allocates whole size-grid units with deterministic largest-remainder rounding, and the rung sizes always sum to the requested total.ORDER_SCALE_RANGE_INVALIDcode. Reusing this code keeps the exportedPerpsErrorCodeunion backward-compatible.The new fields are optional, so existing Scale orders and all other order types are unchanged.
Validation
@metamask/perps-controllertest suite passes.mm-harnessrecipe: 6/6 nodes passed, covering calculation, validation, provider submission, and public exports without a setup shim.The installed harness
metamask.perps.place_orderaction does not yet expose Scale parameters, so the recipe provides deterministic provider-level integration proof rather than a live signed testnet placement.References
Checklist
Note
Medium Risk
Changes how scale order sizes are allocated before they are signed and submitted. The even-split path is preserved, but incorrect skew math would place a different ladder than the caller previewed.
Overview
Scale orders can now weight size along the price ladder via optional
OrderParams.scaleSkew, instead of always splitting evenly.Weights ramp linearly from 1 at
scaleMinPricetoscaleSkewatscaleMaxPricefor both buys and sells. Omitted or1keeps the existing even split (leftover on the first rung). Skewed allocation floors each rung in size-grid units and gives leftovers to the largest discarded fractions (ties by index).splitScaleSizesis the single source of truth so client previews match placement.Invalid skews (
<= 0or non-finite) and skew on non-scaletypes are rejected before signing (ORDER_SCALE_RANGE_INVALID/ORDER_STRATEGY_PARAMS_NOT_SUPPORTED). A skew that zeros a rung or drops a rung under the venue minimum is refused with the existing size/notional errors.Reviewed by Cursor Bugbot for commit 14f5cd0. Bugbot is set up for automated code reviews on this repo. Configure here.