feat: Perps max order error messaging #20559
Merged
+434
−0
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.
Description
Hyperliquid contracts have limitations on the amount of margin for each token
Contract specs: https://hyperliquid.gitbook.io/hyperliquid-docs/trading/contract-specifications
Market orders:
$15,000,000 for max leverage >= 25
$5,000,000 for max leverage in [20, 25)
$2,000,000 for max leverage in [10, 20)
otherwise $500,000
Limit orders:
10 * maximum market order value
Changelog
CHANGELOG entry: Add max order error messaging
Related issues
Fixes:
Manual testing steps
Best way to test this is by manually hardcoding available balance in
hyperLiquidAdapter
to100000000
and then attempting to submit an order with max leverages that fit the above constraints. Not all perps have max 40x leverage. So you'll need to go through various perps to catch all cases.Screenshots/Recordings
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Adds leverage-based max order value checks for HyperLiquid orders, with new constants, validation logic, tests, and localized error messaging.
getMaxOrderValue(maxLeverage, orderType)
inutils/hyperLiquidValidation.ts
to compute order value caps (limit = 10× market cap).HyperLiquidProvider.validateOrder
usinggetMaxOrderValue
andformatPerpsFiat
.HYPERLIQUID_ORDER_LIMITS
inconstants/perpsConfig.ts
(market caps by leverage tier; limit multiplier = 10).perps.order.validation.max_order_value
string inen.json
.hyperLiquidValidation.test.ts
with comprehensive cases forgetMaxOrderValue
across leverage tiers, order types, and edge conditions.Written by Cursor Bugbot for commit 33d4511. This will update automatically on new commits. Configure here.