Skip to content

refactor(utils)!: rework price and size formatting#144

Merged
nktkas merged 1 commit into
mainfrom
refactor/price-size-formatting
Jun 16, 2026
Merged

refactor(utils)!: rework price and size formatting#144
nktkas merged 1 commit into
mainfrom
refactor/price-size-formatting

Conversation

@nktkas

@nktkas nktkas commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Reworks price and size formatting on decimal.js and unifies the thrown errors under FormatError.

Breaking changes

  • formatPrice/formatSize throw FormatError instead of TypeError/RangeError.

New

  • decimal.js is now a runtime dependency, confined to the @nktkas/hyperliquid/utils entry.

Fixes

  • Integer prices written with a trailing decimal zero are no longer mispriced: formatPrice("100001.0", 0)"100001" (was: "100000").
  • Large decimal prices keep full precision: formatPrice("1234567890123456789.0000000001", 0)"1234567890123456789" (was: "1234500000000000000").
  • number inputs that stringify to exponential notation now format: formatPrice(1e-7, 0, "spot")"0.0000001" (was: TypeError).
  • The Decimal/UnsignedDecimal schemas drop a ReDoS in decimal-string normalization.

Type of change

  • Bug fix
  • New API method / feature
  • Schema/type update to match the Hyperliquid API
  • Breaking change

- Replace the hand-rolled arbitrary-precision string math with `decimal.js`
- Add `FormatError`, thrown by `formatPrice`/`formatSize` instead of `TypeError`/`RangeError`
- Drop a ReDoS in the schema decimal normalizer

BREAKING CHANGE: `formatPrice`/`formatSize` throw `FormatError` instead of `TypeError`/`RangeError`

---

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@nktkas
nktkas merged commit 3950f4f into main Jun 16, 2026
4 checks passed
@nktkas
nktkas deleted the refactor/price-size-formatting branch June 16, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant