Skip to main content

df_hyperliquid_core/client/evm/precompiles/
mod.rs

1//! HyperCore's read precompiles: HyperCore state read from HyperEVM by an
2//! `eth_call` to `0x...0800` through `0x...0814`, as `L1Read.sol` in
3//! Hyperliquid's docs declares them.
4//!
5//! **The calldata is the ABI-encoded arguments with no selector.**
6//! `L1Read.sol` calls each as `ADDRESS.staticcall(abi.encode(...))`, so a
7//! selector would be read as part of the first argument.
8//!
9//! The numbers are HyperCore's integers, unscaled:
10//! - a perp's `markPx`, `oraclePx` and `bbo` are in `10^-(6 - szDecimals)`
11//!   ([`perp_price`]), a spot pair's `spotPx` and `bbo` in
12//!   `10^-(8 - szDecimals)` of its base token ([`spot_price`]);
13//! - a position's `szi` is in the perp's size decimals;
14//! - USDC amounts (`entryNtl`, `equity`, `withdrawable`, margins) are 1e6;
15//! - token balances are in the token's `weiDecimals`, HYPE staking in 1e8;
16//! - an outcome's `settledValue` is 1e8 for 1.0.
17//!
18//! An invalid input (an unknown asset or vault) is refused and uses all the
19//! gas given. Gas is `2000 + 65 * (input + output bytes)`.
20
21pub mod account;
22pub mod assets;
23mod fields;
24pub mod lending;
25pub mod outcomes;
26pub mod prices;
27pub mod read;
28pub mod staking;
29pub mod table;
30
31pub use account::{
32    AccountMarginSummary, Position, SpotBalance, UserVaultEquity, account_margin_summary, core_user_exists, position,
33    position2, spot_balance, user_vault_equity, withdrawable,
34};
35pub use assets::{
36    PerpAssetInfo, SpotInfo, TokenInfo, TokenSupply, UserBalance, perp_asset_info, spot_info, token_info, token_supply,
37};
38pub use lending::{
39    BasisAndValue, BorrowLendReserveState, BorrowLendUserState, borrow_lend_reserve_state, borrow_lend_user_state,
40};
41pub use outcomes::{OutcomeState, OutcomeStatus, SETTLED_DECIMALS, outcome_status};
42pub use prices::{Bbo, bbo, l1_block_number, mark_px, oracle_px, perp_price, spot_price, spot_px};
43pub use read::{Read, ReadError};
44pub use staking::{Delegation, DelegatorSummary, delegations, delegator_summary};
45pub use table::{ALL, Spec, address, spec};
46
47#[cfg(test)]
48#[path = "tests/support.rs"]
49mod support;