From 9d215eff15ffa9b78f0ed57724f231d627939fca Mon Sep 17 00:00:00 2001 From: dcccrypto Date: Wed, 15 Jul 2026 11:32:43 +0100 Subject: [PATCH] fix(trade): make the receipt's margin row say what it shows The row labeled "Margin req." actually displayed account capital -> capital-minus-margin (a balance readout), so the actual requirement never appeared as a number and the label misdescribed the row. Split it: "Margin" now shows what this order reserves, and "Available to trade" shows before -> after on the same available basis as the account strip (capital minus already-locked margin) so the two readouts always agree. Co-Authored-By: Claude Fable 5 --- app/components/trade/OrderTicket.tsx | 31 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/app/components/trade/OrderTicket.tsx b/app/components/trade/OrderTicket.tsx index c0b304c4..faedff22 100644 --- a/app/components/trade/OrderTicket.tsx +++ b/app/components/trade/OrderTicket.tsx @@ -549,12 +549,17 @@ const OrderTicketInner: FC<{ slabAddress: string }> = ({ slabAddress }) => { const beforeLiqPrice = userAccount && userAccount.account.positionSize !== 0n && existingEntryPriceE6 > 0n ? computeLiqPrice(existingEntryPriceE6, capital, userAccount.account.positionSize, maintenanceMarginBps) : 0n; - // BUG 9 fix: opening a position RESERVES margin from existing capital — it is - // not a deposit — so this must show capital -> capital MINUS the reserved - // margin (what's left available), never capital + marginNative, which - // fabricated a higher post-trade balance (e.g. "100 -> 120 USDC"). - const beforeMargin = capital; - const afterMargin = beforeMargin > marginNative ? beforeMargin - marginNative : 0n; + // BUG 9 fix + copy clarity: opening a position RESERVES margin from + // existing capital — it is not a deposit. The old receipt row was labeled + // "Margin req." but actually showed capital -> capital-minus-margin (a + // balance readout), so the actual requirement never appeared as a number + // and the label lied about the row. The receipt now shows BOTH, on the + // same "available" basis as the account strip above (capital minus margin + // already locked by an open position) so the two readouts can't disagree: + // Margin — what THIS order reserves (the requirement) + // Available to trade — before -> after reserving it + const beforeAvailable = availableBalance; + const afterAvailable = beforeAvailable > marginNative ? beforeAvailable - marginNative : 0n; // Slippage: distance between the mark and the worst acceptable fill // (same computeLimitPriceE6 useTrade itself uses to derive the on-chain // limit when the caller doesn't supply one explicitly). @@ -983,10 +988,16 @@ setEngineLockError(null); tooltip="Worst acceptable fill price sent on-chain - the trade reverts rather than fill worse than this." /> + )}