Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Units & Constants

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.

The Rule

QuantityTypeScale
Prices, sizes, notionals, collateral, PnL, fees, rewards, bounties, funding indicesbigint18 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 ..._USDCbigint6 decimals: 1_000_000n is 1 USDC
Rates and fees in basis points (imrBp, maxSlippageBp)bigint10_000n is 100%
Rates in “extended” basis points (..._EBP)bigint1_000_000n is 100%
Funding rates per hour, terminal payout ratiosbigint18 decimals: 1e18 is 100%
Times (Unix seconds), durations (seconds), block numbers, counts, enum valuesnumber
An order spec’s expirationBlockbigintA 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 bpnumber

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.

Parsing and Formatting

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"
FunctionDoes
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).
parseDecimal(text, decimals = 18), formatDecimal(value, decimals = 18, maxDecimals?)The same at any number of decimals.
toNumber18(value)A JavaScript number, for display and charts only (loses precision past 2^53 / 1e18).
bpToFraction(bp)Basis points as a fraction (250n is 0.025), for display.

The format namespace has the formatters the SDK’s own messages use:

FunctionExample
format.formatUsd(amount)“$1,234.50”; amounts under a cent keep six decimals
format.formatPrice(price)“$3,012.50”, “$1.08765”, “$0.00001234”: decimals by magnitude
format.formatAmount(quantity, maxDecimals = 6)“1.25”, “12,000”
format.formatBp(bp)“2.5%”
format.formatEth(wei)“0.0001 ETH”
format.formatDuration(seconds)“45 s”, “50 min”, “3 h”, “13 days”
format.formatTime(unixSeconds, now?)“2026-11-08 14:00 UTC (in 3 h)”

USDC Conversions

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
FunctionDoes
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.

Constants

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.

Scales

ConstantValue
BAZAAR_SCALE10n ** 18n
BP_SCALE10_000n
EBP_SCALE1_000_000n
USDC_DECIMALS6
USDC_TO_BAZAAR10n ** 12n: 18 decimals carry twelve more than USDC
BAZAAR_EXPONENT-18: the oracle’s price exponent
MAX_UINT2562n ** 256n - 1n
ZERO_ADDRESS0x0000000000000000000000000000000000000000

Trading

ConstantValueMeaning
MAX_PRICE_STALENESS3Seconds a Pyth print may sit from the block’s timestamp.
LIMBO_LEAD6Seconds before a scheduled cutoff at which trading halts.
MIN_ORDER_AMOUNT5n * BAZAAR_SCALE$5: the smallest order notional (a full close is exempt).
MIN_COLLATERAL_DEPOSIT5n * BAZAAR_SCALE5 USDC: the smallest deposit.
MAX_WALK_STEPS32Resting orders an arriving order’s walk visits at most (the default budget).
MAX_TRIGGER_EXECS_PER_CALL20Trigger orders one executeTriggeredOrders fires.
MAX_CONFIDENCE_BP200n2%: the widest Pyth confidence the oracle accepts.
TRIGGER_PRICE_MASK2n ** 128n - 1nA trigger order’s price sits in the low 128 bits of its triggerPrice word, its keeper bounty in the high 128.
ETH_USD_FEED0x0000...0002Pyth Pro’s ETH/USD feed (feed 2, as a bytes32), used to price gas.

On the orders namespace:

ConstantValueMeaning
orders.MAX_SLIPPAGE_BP1000n10%: the widest slippage cap of a Market, TakeProfit or StopLoss order.
orders.MAX_PLACEMENT_DEVIATION_BP5000nA limit price must sit within ±50% of the oracle price.
orders.MIN_ORDER_LIFETIME_BLOCKS240About a minute of Arbitrum blocks: the shortest life of an order that rests.
orders.EXPIRY_LANDING_MARGIN_BLOCKS40Slack the SDK adds to the minimum when it checks an expiry.
orders.MAX_ORDER_LIFETIME_BLOCKS126_144_000About a year; a later expiry is clamped by the pair.
orders.NEVER_EXPIRE_BLOCK2n ** 64n - 1nThe expiry the pair stamps on TP and SL orders.
orders.L2_BLOCKS_PER_SECOND4Arbitrum’s block rate, for orders.blocksIn(seconds).
orders.MAX_ACTIVE_LIMIT_ORDERS_PER_USER32Live Limit (GTC) and StopLimit orders per account per market.
orders.MAX_AMENDS_PER_CALL32Amendments per amendOrders.
orders.MAX_CANCELS_PER_CALL200Order ids per cancelOrders.
orders.CLOSE_POSITIONMAX_UINT256The size of a TP or SL that closes the whole position.
orders.AMEND_BEST_EFFORT_BIT2n ** 192nThe flag in an amendment’s id word that skips rather than reverts.

Gasless Calls and Permits

ConstantValueMeaning
signing.MAX_RELAYER_FEEBAZAAR_SCALE$1: the most a relayer may charge per action.
signing.MAX_DEADLINE_WINDOW10Seconds a gasless signature may be valid past chain time.
signing.MAX_CLOCK_SKEW120Seconds this device’s clock may differ from the chain’s before signing is refused.
permits.DEFAULT_PERMIT_WINDOW1800Seconds a USDC permit is valid by default.

Markets and Prices

ConstantValueMeaning
markets.VENUE_CLOSED_AFTER15Seconds without a print before a trading-hours venue counts as closed.
markets.MAX_FUNDING_RATE_CONTINUOUSBAZAAR_SCALE / 1000n0.1% an hour: the funding cap on 24/7 markets.
markets.MAX_FUNDING_RATE_SESSIONBAZAAR_SCALE / 200n0.5% an hour: the cap on trading-hours markets.
priceFeeds.BROWSER_FUTURE_SKEW120Seconds a live print may be dated ahead of this device’s clock.
MAX_FUTURE_SKEW5The same, for PriceService (the keeper’s default).

Liquidation, ADL, Settlement

Mostly the keeper’s concern, exported for completeness:

ConstantValueMeaning
LIQUIDATION_FEE_EBP200n2 bp.
MIN_LIQUIDATOR_REWARDBAZAAR_SCALE / 20n$0.05.
MAX_LIQUIDATION_PRICE_AGE600Seconds a stored price may be old and still seize collateral.
UNLOAD_BOUNTY_MINBAZAAR_SCALE / 4n$0.25.
UNLOAD_BOUNTY_MIN_NOTIONAL1_250n * BAZAAR_SCALE$1,250.
UNLOAD_FLOOR_DECAY180Seconds.
ADL_AUCTION_DURATION600Seconds the ADL score threshold takes to decay to its floor.
ADL_MAX_SCORE25n * BAZAAR_SCALE
ADL_TIMEOUT_DURATION86_400Seconds an ADL window may stay open.
ADL_TERMINATION_GRACE1_800Seconds after an ADL timeout before it may terminate the pair.
MAX_ADL_WINNERS_PER_BATCH25
REFRESH_BOUNTYBAZAAR_SCALE / 10n$0.10.
REFRESH_BOUNTY_MIN_GAP300Seconds.
REFRESH_BOUNTY_HEARTBEAT86_400Seconds.
REFRESH_BOUNTY_FAST_MIN_INSURANCE5_000n * BAZAAR_SCALE$5,000.
REFRESH_BOUNTY_HEARTBEAT_MIN_INSURANCE1_000n * BAZAAR_SCALE$1,000.
TERMINAL_SETTLEMENT_TIPBAZAAR_SCALE / 20n$0.05 per position settled.
TERMINAL_SETTLEMENT_ESCAPE14 * 86_400Seconds: the longest a settlement window lasts.
ORACLE_DEAD_THRESHOLD21 * 86_400Seconds without a stored price before a pair counts as stale.
SETTLEMENT_SAMPLE_COUNT, SETTLEMENT_SAMPLE_SPACING5, 600The chain rule’s samples and their spacing (seconds).
SETTLE_NOTHING, SETTLE_TICK, SETTLE_CHAIN, SETTLE_AWAIT_VERDICT0 to 3Settlement rules.

What each of these governs is in Bazaar’s Parameters.

Order Types, Time in Force, Status

OrderType.Limit; // 1
ORDER_TYPE_NAMES[OrderType.StopLoss]; // "StopLoss"
orders.TimeInForce.FOK; // 2
orders.TIF_NAMES[orders.TimeInForce.IOC]; // "IOC"
orders.CLOSE_POSITION; // a TakeProfit or StopLoss of this size closes the whole position
const notional = (parseUnits18("0.002") * parseUnits18("2400")) / BAZAAR_SCALE; // $4.80
notional >= MIN_ORDER_AMOUNT; // false: the minimum is $5
OrderTypeValueAlso exported as
Market0MARKET
Limit1LIMIT
StopLimit2STOP_LIMIT
TakeProfit3TAKE_PROFIT
StopLoss4STOP_LOSS

ORDER_TYPE_NAMES[type] gives the name; TRIGGER_TYPES lists the three trigger types.

orders.TimeInForceValueMeaning
GTC0Rest the remainder in the book (only Limit and StopLimit rest). The default.
IOC1Fill what crosses on arrival, cancel the rest. Limit only.
FOK2Fill the whole size on arrival or revert. Limit and Market only.

orders.TIF_NAMES[tif] gives the name. The rules for each are in Orders.

StatusValue
Status.Live"live"
Status.Adl"adl"
Status.Limbo"limbo"
Status.Settling"settling"
Status.Terminated"terminated"

What each status means is on Markets.