Skip to content

Limit orders display base-unit amounts for sub-dollar tokens #12222

@premiumjibles

Description

@premiumjibles

Problem

When placing limit orders for sub-dollar tokens (e.g. ARB → USDC), SellAmount shows a massive base-unit number like "230,000,000,000..." instead of human-readable amounts. Users could sign orders with wildly wrong amounts.

tk ticket: sa-lhbw
Repro: Place a limit order for ARB → USDC (or any sub-dollar token).

Root Cause

Server-side code is structurally correct (summary.sellAsset.amount uses human-readable values). The bug is most likely an LLM reasoning error for sub-dollar tokens where:

  1. LLM passes base-unit value as sellAmount after seeing precision: 18
  2. orderParams.sellAmount (base unit) leaks into LLM's text response
  3. LLM inverts limitPrice for sub-dollar tokens, producing enormous numbers

Fix

  1. Input validation — reject sellAmount with >15 digits (defense in depth)
  2. Sanity check — validate sellAmount * limitPrice vs market price (>1000x = error)
  3. Schema description — explicit base-unit warning with sub-dollar token examples
  4. Reduce leakage — filter orderParams from LLM-visible output
  5. Apply to all tools — same fixes for createStopLoss.ts and createTwap.ts

Key Files

  • apps/agentic-server/src/tools/limitOrder/createLimitOrder.ts
  • apps/agentic-server/src/tools/stopLoss/createStopLoss.ts
  • apps/agentic-server/src/tools/twap/createTwap.ts
  • apps/agentic-server/src/routes/chat.ts

Acceptance Criteria

  • Input validation rejects >15 digit sellAmount values
  • Sanity check on sellAmount * limitPrice vs market price
  • Schema descriptions warn about base-unit vs human-readable
  • Manual test: ARB → USDC limit order shows correct amounts

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions