Static ReadonlyfixedThe exact bigint scale for 18-decimal fixed-point values, 1000000000000000000n.
Static ReadonlyfixedThe exact bigint scale for 9-decimal fixed-point values, 1000000000n.
Static ReadonlyfixedThe JavaScript-number scale for 18-decimal fixed-point values, 1e18.
JavaScript numbers do not represent every integer at this magnitude exactly.
Static ReadonlyfixedThe JavaScript-number scale for 9-decimal fixed-point values, 1e9.
Static ReadonlycastNormalizes a raw balance and converts it to the 18-decimal local scale.
The method multiplies amount by decimalsScalar, converts the product to
a JavaScript number, and divides by fixedOneN. Large products can lose
precision during the number conversion.
The token's scale factor as a bigint.
The raw on-chain balance.
The normalized local value as a number.
Static ReadonlycomplementReturns a clamped complement of a local number.
For 0 <= n <= 1, the result is 1 - n. Negative inputs are treated as
zero before subtraction, and inputs greater than 1 produce 0 after the
result is clamped. NaN is not validated and produces NaN.
The local number to complement.
A value no less than 0 for finite inputs.
Static ReadonlyconvertConverts a raw on-chain bigint to a JavaScript number without scaling.
Values larger than JavaScript's safe integer range can lose precision.
The raw on-chain integer.
The raw value as a JavaScript number.
Static ReadonlyconvertConverts a JavaScript number to a raw on-chain bigint without scaling.
The method applies Math.floor, so negative fractional values round toward
negative infinity rather than toward zero. NaN and infinite values throw
during the bigint conversion.
The local number to convert.
The floored value as a bigint.
Static ReadonlydirectConverts an 18-decimal fixed-point bigint to a JavaScript number.
The method divides by fixedOneN; large values can lose precision when
converted to number.
The 18-decimal fixed-point integer.
The unscaled local number.
Static ReadonlydirectConverts a JavaScript number to an 18-decimal fixed-point bigint.
The method multiplies by fixedOneN and applies Math.floor before the
bigint conversion. Negative fractional values therefore floor toward
negative infinity, and JavaScript number precision applies before flooring.
The local number to scale.
The scaled value as a bigint.
Static ReadonlynormalizeMultiplies a raw balance by a token decimal scalar.
For a token with 9 decimals, pass 1000000000n as the scalar. The
multiplication remains exact because both operands are bigint values.
The token's scale factor, such as 1000000000n.
The raw on-chain balance.
The normalized balance as a bigint.
Static ReadonlyuncastConverts an 18-decimal local value back to a raw balance.
The method first multiplies by fixedOneN and floors to a bigint, then
divides by decimalsScalar. The first step is subject to JavaScript number
precision; the second step discards any bigint remainder toward zero.
The token's scale factor as a bigint.
The local value in the 18-decimal domain.
The raw balance as a bigint.
Static ReadonlyunnormalizeDivides a normalized bigint by a token decimal scalar.
Bigint division discards a remainder toward zero. A zero scalar throws a division-by-zero error.
The token's scale factor as a bigint.
The normalized balance.
The raw balance as a bigint.
Provides fixed-point conversions and token-decimal normalization.
Direct fixed-point conversions use an 18-decimal scale. Normalization uses the caller-supplied token decimal scalar and keeps on-chain amounts as
bigintvalues until a direct cast produces a JavaScriptnumber.