Conversation
Implements MYX order placement via SDK createIncreaseOrder and fixes a
critical decimal scaling bug in the read path. Validated end-to-end on
Linea Sepolia testnet (standalone script + in-app CDP).
Write path:
- MYXProvider.placeOrder(): symbol→pool→market→fees→order flow
- MYXClientService: createIncreaseOrder/DecreaseOrder, getUserTradingFeeRate
- MYXWalletService: EIP-1193 transport with gas param passthrough,
sync getAddress() (SDK calls without await)
- Metro resolver: force @myx-trade/sdk ethers imports to bundled v6
(project uses v5, SDK needs v6 BrowserProvider/Contract)
Decimal fix:
- REST API returns human-readable strings ("73485.10", "0.00136"),
not 18-decimal scaled integers
- Switched read path from fromMYXSize/fromMYXCollateral (÷10^18)
to fromMYXApiSize/fromMYXApiCollateral (parseFloat)
- Collateral decimals now per-network: USDT/BNB=18, USDC/Linea=6
(verified on-chain)
Key SDK gotchas addressed:
- positionId must be '' (falsy) for new positions, not '0'
- Market order price must not be zero — fetch ticker + 5% buffer
- Gas params from SDK must be passed through transport to chain
Consolidated key findings from MYX SDK integration: ethers v5/v6 conflict, decimal scaling, gas params, and other SDK gotchas.
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Validated MYX write integration on testnet: - showAccount: correct balance formula (freeAmount + walletBalance) - closeOrder: close position via createDecreaseOrder + cancel via cancelOrder - placeOrder: open position via createIncreaseOrder - listMarkets/listOrders: market discovery and order listing - SDK reference docs and inconsistency notes
Balance fix (3 bugs): - getAccountInfo returns 7-element tuple, not keyed object - First pool may return 0x (no deposits) — iterate pools until valid - Tuple values in token-native decimals — use fromMYXCollateral not parseFloat - subscribeToAccount was hardcoded to zeros — now REST polls via getAccountState closePosition: mirrors placeOrder via createDecreaseOrder with 5% slippage cancelOrder: wraps SDK client.order.cancelOrder MYXClientService: added cancelOrder, fixed getAccountInfo return type
- adaptMarketFromMYX: use Math.max(poolMin, static floor) * buffer for minimumOrderSize, preventing unreliable pool config values from setting too-low minimums - MYXProvider.getMarkets: fetch per-pool configs in parallel, pass to adapter - usePerpsOrderForm: default amount = max(networkDefault, market minimum), reset hasSetInitialAmount when market data loads async - Documented testnet finding: getPoolLevelConfig reports $10 min but on-chain rejects below ~$55 notional — $100 static floor is correct
- Fix hallucinated LevelConfig property access (level/levelName are on PoolLevelConfig, not LevelConfig) - Add scripts/perps/myx-poc to .eslintignore (PoC scripts use their own tsconfig, not the root one)
- Remove Metro ethers v5→v6 resolution hack (SDK no longer bundles ethers) - Use SignerLike type for auth (remove as any casts) - Fix recent activity decimal formatting (formatPositionSize) - Fix oracle price fallback (pipe markPrice through stats) - Fix volume to use USD from getBaseDetail (not token-denominated ticker) - Fix fallback display values (-- instead of $0.00) - Fix account balance (SDK renamed freeAmount → freeMargin) - Add getOraclePrice, createPositionTpSlOrder, adjustCollateral, cancelOrders - Implement updatePositionTPSL, updateMargin, batchCancelOrders - Fix getTradeFlow namespace (Account → Api in SDK 1.0.2) - Update test mocks for SDK 1.0.2 type changes
MYX has no exchange-defined size step (unlike HyperLiquid). Use DECIMAL_PRECISION_CONFIG.FallbackSizeDecimals (6) for szDecimals instead of the on-chain 18-decimal precision. Fixes raw 18-decimal sizes showing in close position screen and other size displays.
…ions SDK 1.0.2 uses viem getContract() which calls client.request() for estimateContractGas/writeContract. Our adapter only had transport.request. Add request, getAddresses, signMessage, sendTransaction to satisfy WalletClientLike + viem Client interface. Also add MYX agentic recipes, validation flows doc, PerpsCard size formatting fix, and websocket gaps update.
SDK 1.0.2 + viem pass BigInt values through JSON.stringify internally. Add BigInt.prototype.toJSON polyfill to common.ts for PoC script compat.
Controller returns providerId (not provider) on market/position/order objects. Also align field names: margin→marginUsed, volume24h→volume, add leverage to position snapshots.
…ion fix - Switch getOpenOrders() from filtering getOrderHistory() to using getPoolOpenOrders() API — returns only pending limit/trigger orders (TP/SL), matching Hyperliquid parity. Fixes stale PartialFilled market orders showing permanently in the UI. - Add PartialFilled → 'filled' status mapping in adaptOrderFromMYX so partially-filled orders no longer fall through to 'open' in order history views. - Fix string precision in closePosition/placeOrder: pass size as string through toMYXSize() to avoid parseFloat precision loss that caused dust on 18-decimal reconstruction. - Fix nullish coalescing (|| → ??) for closeSizeStr.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
…integration # Conflicts: # app/controllers/perps/utils/myxAdapter.ts
- Add 9 CDP validation recipes (myx-validation/) for sequential write flow testing - Fix validate-recipe.sh recipe_ref to support namespaced refs (myx/auth) - Add addMargin.ts PoC script (adjustCollateral SDK path) - Add editOrder.ts PoC script (updateOrderTpSl SDK path) - Add validation tracker with double-validation approach (PoC + CDP)
…document broker revenue Replace magic fee fallback values (1000, 55000) with named constants (MYX_DEFAULT_TAKER_FEE_RATE, MYX_FEE_RATE_PRECISION). Make calculateFees() fetch dynamic rates from the MYX API with static fallback. Fix fee rate from incorrect 0.05% to actual 0.055%. Document the broker referral rebate model in MYX-SDK-REFERENCE.md. Also includes MYXClientService enhancements, editOrder PoC updates, and tracker updates.
…ons and cache errors - Add MYX_PROVIDER_ID constant; replace 'myx' literals with this.protocolId / MYX_PROVIDER_ID - Use CLOSE_POSITION_CONFIG.UsdDecimalPlaces instead of magic .toFixed(2) - closePositions: omit size param so closePosition resolves fresh position via #resolvePositionForSymbol - #refreshMarketDetails: delete stale cache on fetch error instead of keeping indefinitely
The MYX SDK returns on-chain contract data with bigint fields (e.g. freeMargin: 553959075n). parseAccountTuple's str() helper only handled string and number types, causing all BigInt values to fall through to '0' — resulting in zero balances displayed.
PerpsCancelAllOrdersView references this key but it was never added to the locale file, showing a raw key string in the UI.
…ubscriptions MYX WS subscriptions for positions and orders were not receiving events due to incorrect auth pattern. The SDK expects walletClient-only auth (no signer, no getAccessToken callback, no sdk. token prefix). Production changes: - MYXClientService: simplify auth to walletClient-only, remove dead token generation code (#generateAccessToken, #sha256Hex, sdk. prefix) - MYXProvider: replace hybrid WS+REST polling with WS-only push for positions and orders. WS events trigger a full REST fetch to deliver complete data to callbacks. OrderFills and Account remain REST-polled (no WS channel exists for those). PoC changes: - common.ts: authenticateClient() uses walletClient-only auth - wsSubscriptions.ts: added WS diagnostics, ticker control group, inline trade placement for end-to-end validation Validated via PoC (3 WS events received) and agentic recipe 15 (9/9 steps passed including full trade cycle).
…criptions MYX WS does not send initial snapshot on subscribe and does not push continuous position updates (mark price, PnL). REST polling handles continuous data refresh. WS fires instantly on state changes (trade placed, filled, closed) triggering an immediate extra fetch so the UI updates without waiting for the next poll cycle. Also adds WS open event listener for reconnect tracking and fixes test mock to include subscription.on/off methods.
Truthy check treated 0 as missing data, showing "--" instead of "$0.00" for markets with genuinely zero volume or open interest.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
…in spec - Update WebSocket status: positions/orders confirmed working (event-driven, no initial snapshot), account has no WS (MYX confirmed polling only) - Document EIP-712 domain spec from MYX team: name="Broker", version="1.0" - Add setUserFeeData PoC script with corrected domain (still NotBrokerSigner on testnet — awaiting MYX team for testnet-specific guidance) - Update fee model: 1e8 precision confirmed stable - Update comparison table and protocol limitations to reflect WS status
…cdf1) Add Number.isFinite() guard before the inline usdAmount comparison in placeOrder so that NaN values from non-numeric params.usdAmount are caught instead of silently bypassing the minimum order size validation.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Tag Selection Rationale:
No other test suites are impacted - changes are isolated to the Perps feature area (MYX provider, PerpsController, Perps UI hooks). No changes to Engine initialization, navigation, shared modals, or other controller systems that would affect other test suites. Performance Test Selection: |
|
|
✅ E2E Fixture Validation — Schema is up to date |




Description
Add MYX as the second perpetual futures provider alongside HyperLiquid. This PR implements all write operations (place/close/cancel/edit orders, TP/SL, margin adjustment) and completes the full provider integration using
@myx-trade/sdkv1.0.6.MYX is a permissionless perpetual futures DEX on BNB Chain (mainnet) and Linea Sepolia (testnet). All provider-specific logic is encapsulated in
MYXProvider.ts, following the sameAggregatedPerpsProviderarchitecture as HyperLiquid.What's included
Core provider layer:
MYXProvider-- 39 fully implementedPerpsProviderinterface methods (market/limit orders, TP/SL, cancel, close, margin, batch operations)MYXClientService-- SDK wrapper for REST calls, auth, price polling, WebSocket klinesMYXWalletService-- signing integration via MetaMask KeyringControllermyxAdapter-- SDK type to PerpsProvider type adaptersmyxConfig-- constants (fees, contracts, collateral config)Key architectural decisions:
Validation:
docs/perps/myx/MYX-INTEGRATION-TRACKER.mdTests:
Changelog
CHANGELOG entry: null
Related issues
Fixes: TAT-2461, TAT-2462, TAT-2471, TAT-2472, TAT-2473, TAT-2474, TAT-2475, TAT-2477, TAT-2478, TAT-2508, TAT-2524, TAT-2531, TAT-2532, TAT-2533, TAT-2534, TAT-2580
Manual testing steps
Screenshots/Recordings
Before
N/A -- MYX provider did not exist before this PR.
After
01-read-markets.mp4
02-read-account.mp4
03-calculate-fees.mp4
04-validate-order.mp4
05-read-fills.mp4
06-place-market-order.mp4
07-update-tpsl.mp4
08-add-margin.mp4
09-close-position.mp4
10-place-and-close-all.mp4
11-place-limit-order.mp4
12-cancel-order.mp4
13-edit-order.mp4
Pre-merge author checklist
Pre-merge reviewer checklist
Note
High Risk
High risk because it adds on-chain MYX order execution/cancel/edit/close and margin/TP-SL flows, plus new validation and polling logic that directly affects trading correctness and user funds.
Overview
Adds full MYX write-path support in
MYXProvider(place/edit/cancel/batch cancel/close/batch close, TP/SL trigger orders, and margin adjustment), including authenticated context setup, per-pool min order sizing with buffer, dynamic fee-rate fetching, and hybrid WS-triggered refresh + REST polling for orders/positions/account.Expands MYX configuration (
myxConfig) with network-specific collateral decimals/addresses, contract + explorer metadata, CAIP asset IDs, contract-price conversions, caching TTLs, and fee precision defaults; exports new API parsing helpers for MYX REST values.Tightens order validation plumbing by returning
minimumRequiredfromvalidateOrderthroughPerpsController/UI hooks, updates UI formatting/fallback displays (position size formatting, oracle price display fallback, market stats--defaults), and adjusts close-position sizing semantics (treat full close assize: undefined).Written by Cursor Bugbot for commit 287571e. This will update automatically on new commits. Configure here.