Skip to main content

Module utils

Module utils 

Source
Expand description

Helpers every Hyperliquid app needs: exact decimals, price and size rounding, asset ids, units, time, hex, nonces and signing primitives.

Re-exports§

pub use address::Address;
pub use address::BadAddress;
pub use asset::Asset;
pub use asset::AssetKind;
pub use asset::HIP3_ASSET_BASE;
pub use asset::HIP3_DEX_SPAN;
pub use asset::OUTCOME_ASSET_BASE;
pub use asset::OutcomeSide;
pub use asset::SPOT_ASSET_BASE;
pub use dec::BadDec;
pub use dec::Dec;
pub use dec::Round;
pub use figure::Figure;
pub use hex::BadHex;
pub use json::Json;
pub use nonce::NonceClock;
pub use rounding::Grid;
pub use rounding::MAX_SLIPPAGE;
pub use rounding::MINIMUM_ORDER_VALUE;
pub use rounding::PERP_PRICE_PLACES;
pub use rounding::SIGNIFICANT_FIGURES;
pub use rounding::SPOT_PRICE_PLACES;
pub use units::BadUnits;
pub use units::cut_units;
pub use units::exact_units;

Modules§

address
asset
Asset ids: the integer an order names its market by. Ids run perps on the main dex below 10000, spot pairs from 10000, HIP-3 perps from 100000 and HIP-4 outcomes from 100000000, so an id alone says what it names, and so which builder cap holds it.
dec
figure
A few reads send a number as a bare JSON float rather than a decimal string: vaultDetails writes "apr":0.037456007367970744. serde_json would put that through an f64 and keep whatever digits came back out; this reads the text the venue wrote instead.
hex
json
JSON that keeps what a signature depends on: keys in the order they were written and numbers as the digits they were written with. An L1 action is hashed as msgpack, which keeps key order, where serde_json sorts keys.
nonce
rounding
Where prices and sizes may sit on a perp or a spot pair: a price keeps at most 6 - szDecimals places on a perp and 8 - szDecimals on spot, then five significant figures unless it is whole; a size keeps szDecimals. HIP-4 outcomes have their own grid (crate::markets::outcomes::px).
sign
Signing primitives: keccak, msgpack, EIP-712, L1 actions and user-signed actions.
time
The calendar: instants and days in UTC, counted from 1970 in integers on the proleptic Gregorian calendar. There is no clock here: the caller passes now, in milliseconds.
units
Amounts an action carries as whole integers: USDC in millionths (vaultTransfer, subAccountTransfer), HYPE in 1e8 (cDeposit, tokenDelegate). The integer is what is signed, so it is made here, once.