This page is the reference for the SDK’s units: which type and scale each kind of quantity uses, the
functions that convert between them, the constants a frontend or a bot needs (with their values), and
the values of order types, time in force and market status.
Prices, sizes, notionals, collateral, PnL, fees, rewards, bounties, funding indices
bigint
18 decimals (“BAZAAR precision”): 1e18 is $1, or one unit of the traded asset
USDC as the token counts it: wallet balances, allowances, approvals, permits, bonds named ..._USDC
bigint
6 decimals: 1_000_000n is 1 USDC
Rates and fees in basis points (imrBp, maxSlippageBp)
bigint
10_000n is 100%
Rates in “extended” basis points (..._EBP)
bigint
1_000_000n is 100%
Funding rates per hour, terminal payout ratios
bigint
18 decimals: 1e18 is 100%
Times (Unix seconds), durations (seconds), block numbers, counts, enum values
number
An order spec’s expirationBlock
bigint
A block number, but a bigint: take-profit and stop-loss orders carry 2^64 − 1 (“never”), which a number cannot hold
Display ratios: margin ratio, leverage, confidence in bp
number
The pair takes and reports amounts in 18 decimals and floors what it moves to whole micro-USDC
(multiples of 1e12). A name says USDC when an amount is in 6 decimals; any other amount is in 18.
bigint values do not survive JSON.stringify: convert them to decimal strings first.
parseUnits18("12.5"); // 12500000000000000000n
parseUnits18("-0.75"); // -750000000000000000n
parseDecimal("2.5", 6); // 2500000n: any number of decimals
try {
parseUnits18("1e-3"); // exponents, commas, "+", and more than 18 decimals are refused
} catch (e) {
if (e instanceof UnitError) console.log(e.message); // "\"1e-3\" is not a decimal number"
}
formatUnits18(12_345_678_900_000_000_000n); // "12.3456789"
formatUnits18(12_345_678_900_000_000_000n, 2); // "12.34": cut toward zero, never rounded up
formatDecimal(2_500_000n, 6); // "2.5"
toNumber18(parseUnits18("0.1")); // 0.1, for charts and arithmetic on screen only
bpToFraction(250n); // 0.025
format.formatUsd(parseUnits18("1234.5")); // "$1,234.50"
format.formatPrice(parseUnits18("1.08765")); // "$1.08765"
format.formatBp(250n); // "2.5%"
format.formatDuration(3000); // "50 min"
Function
Does
parseUnits18(text)
A decimal string (“12.5”, “-0.75”, “.5”) to 18 decimals. Throws UnitError on anything else: an exponent, a +, a thousands separator, more than 18 decimals. Surrounding spaces are ignored.
formatUnits18(value, maxDecimals?)
18 decimals to a decimal string, trailing zeros trimmed; maxDecimals cuts toward zero (never rounds up).
const amount = parseUnits18("10.0000005"); // more precision than USDC has
floorToUsdc(amount); // 10000000000000000000n: what the pair actually moves (whole micro-USDC)
toUsdcUnits(amount); // 10000000n: floored, as the pair floors it
toUsdcUnitsCeil(amount); // 10000001n: rounded up, for an allowance or a permit that must cover it
fromUsdcUnits(10_000_000n); // 10000000000000000000n
Function
Does
toUsdcUnits(amount)
18 decimals to USDC units, floored as the pair floors it.
toUsdcUnitsCeil(amount)
18 decimals to USDC units, rounded up: for an allowance or a permit that must cover a pull.
fromUsdcUnits(units)
USDC units to 18 decimals.
floorToUsdc(amount)
18 decimals floored to a multiple of 1e12: what the pair actually moves.
allowance.formatUsdcUnits(units)
USDC units as a decimal string (“12.5”).
PreparedCall.pullsUsdc is in 18 decimals; allowance.usdcFunding(owner, pair, pull) converts it and
compares it with the wallet’s balance and allowance.
Exported from the package, each named after the Bazaar constant it copies. The SDK reads a value from
the chain wherever the lens exposes it; these are for planning, validation and display.