Skip to main content
The SDK moves every monetary and quantity value as a DecimalString. A number appears only inside display math. This page describes the contract, the three tiers of numeric helpers, and the verbs that name them.

The DecimalString contract

Every monetary or quantity value that crosses a package, provider, or network boundary is a DecimalString from @lifi/perps-types. It matches DECIMAL_PATTERN: an optional leading -, digits, and an optional . with digits. It has no grouping, exponent, currency sign, or whitespace.
  • isDecimalString(value) tests a value against the pattern.
  • truncateDecimal, decimalToBaseUnits, and the account-side wire/ helpers throw PerpsError with ValidationError for a string that fails the pattern. calculateOrderAmounts gives null for one.
  • baseUnitsToDecimal throws PerpsError with ValidationError for an amount that is not an integer string, such as '1.5' or '1e3'.
  • No exported signature carries a Big. The SDK and the providers compute with big.js internally, and give back a DecimalString or a number.
  • A number is for display math and small integers only, such as leverage, decimals, percentages, and chart values. A number never goes to a venue.
  • A producer that builds a DecimalString from a number writes plain notation, never exponent notation. numberToDecimalString does this.

Three tiers

The numeric helpers sit in three tiers. Each tier has one input type, one output type, and one rule. A value for a venue comes from wire/ or from a provider field. A value for a screen goes through parseDecimal, then math/, then format*.

Vocabulary

One verb names one kind of transformation. No function in decimal/, math/, or wire/ uses a derive, predict, or convert verb, or a bare noun as its name. See Utilities for the signature and an example of each helper.