Precision Contract
Status: M1 verified Last verified: 2026-07-19
Official sources: HL.DOC.TICK_LOT.2026-07-19, HL.DOC.SIGNING.2026-07-19
Fixture sources: HL.LIVE.MAINNET.M1.2026-07-19, HL.LIVE.TESTNET.M1.2026-07-19
hl.precision.decimal.canonicalize v1
Source ID: HLM.SPEC.PRECISION.CANONICAL_DECIMAL.V1
- Input is exactly
{ value: string }; unknown fields are invalid input. - Grammar is
^-?\d+(?:\.\d+)?$. - The raw decimal spelling is limited to 256 characters by the package-wide resource budget.
- Reject exponent notation,
+, whitespace, non-finite tokens,.5, and1.. - Normalize leading integer zeroes, remove insignificant fractional zeroes, emit no exponent, and map every signed zero to
0. - No protocol rounding occurs;
roundingis empty. - Authority is
local-exact; maturity isstable. - External Hyperliquid/Python/live oracles are
not-supportedbecause this is the package's own serialization contract.
hl.precision.price.quantize v1
Source ID: HLM.SPEC.PRECISION.PRICE.V1
- Input is exactly
{ value, marketKind, szDecimals, rounding }. valueis a positive plain decimal string.marketKindisperporspot;roundingis explicitlydownorup. Math does not infer an order side or execution strategy.szDecimalsis a non-negative safe integer no greater than6for perps or8for spot.- First round to at most
MAX_DECIMALS - szDecimalsdecimal places, whereMAX_DECIMALSis6for perps and8for spot. If the result is not an integer, round it to at most five significant figures using the same explicit direction. Integer results are exempt from the significant-figure limit. - Because prices are positive,
downis toward zero andupis away from zero. A result that quantizes to zero is invalid input because it cannot represent a positive protocol price. - The public result is
MathResult<{ value: string; precisionChanged: boolean }>:- valid input returns
{ status: "ok", data: { value, precisionChanged } }; - invalid shape, enum, integer bound, decimal grammar, non-positive input, or a result rounded to zero returns
{ status: "invalid-input", issues }; - this total deterministic operation never returns
not-applicableorindeterminate.
- valid input returns
valueis canonical, has no exponent or trailing zeroes, andprecisionChangedcompares numeric value rather than source spelling.- Trace uses formula ID
hl.precision.price.quantize, version1, the two spec/official source references, and theDECIMALJS.10.6.0implementation source. A changed output records each applied decimal-place or significant-figure decision intrace.rounding; unchanged output records none. - Authority is
local-exact; maturity isstable. The acceptance limits are official protocol facts. Rounding direction is an explicit caller-provided local calculation, not a claim about server rounding.
hl.precision.size.quantize v1
Source ID: HLM.SPEC.PRECISION.SIZE.V1
- Input is exactly
{ value, szDecimals }. valueis a positive plain decimal string.szDecimalsis a non-negative safe integer no greater than8. This is the v1 supported-range ceiling observed in the dated mainnet/testnet fixtures, not an official protocol-wide maximum. Metadata above that ceiling remains unsupported until a versioned contract extends the bound; the local guard prevents unbounded Decimal quantization.- Quantize to
szDecimalsdecimal places usingdown. Size is unsigned, so this never increases the requested exposure. - A result that quantizes to zero is invalid input.
- The public result is
MathResult<{ value: string; precisionChanged: boolean }>with canonical trailing-zero-free serialization:- valid input returns
okwith that data; - invalid shape, integer bound, decimal grammar, non-positive input, or a result rounded to zero returns
invalid-inputwith issues; - the operation never returns
not-applicableorindeterminate.
- valid input returns
- Trace uses formula ID
hl.precision.size.quantize, version1, the spec/official source references, andDECIMALJS.10.6.0. A changed output records onedowndecision; unchanged output records none. - Authority is
local-exact; maturity isstable.
Oracle boundary
- The pinned official Python SDK canonicalizes valid numeric order values to wire strings, strips trailing zeroes, and rejects values that would require wire rounding, but it does not own a full protocol tick/lot validator. The M1 harness covers valid fixture values only, so it is partial wire-string evidence rather than a quantization oracle.
- Live L2/meta fixtures prove real
szDecimalsand accepted response spelling. They do not prove how the server would round an invalid submitted order, so live precision coverage is partial.
M0 trace budget
For hl.precision.decimal.canonicalize v1, the median public-facade/internal-kernel ratio is at most 35 and the serialized valid result is at most 640 UTF-8 bytes under scripts/benchmark.mjs. The repository records portable ceilings, not machine-specific timings. Increasing either ceiling requires a reviewed architecture rationale and fresh benchmark evidence.