Skip to content

PrecompileLib

A library to call HyperEVM precompiles, with additional functions to query data using EVM token addresses, removing the need to store or pass in the token/spot index.

It also provides functionality to retrieve spot market IDs from token IDs, and from EVM addresses, abstracting this complexity from the developer, allowing them to focus on building the core business logic of their contracts.

Why it's useful

Native precompiles often require token or spot market indices. These are not derivable onchain from the EVM address, forcing developers to manually store or pass in the token/spot index. PrecompileLib pairs with TokenRegistry to resolve indexes automatically.

Usage

Import

import { PrecompileLib } from "@hyper-evm-lib/src/PrecompileLib.sol";

Sample usage

uint64 uBTC_address = 0x9fdbda0a5e284c32744d2f17ee5c74b284993463;
uint64 spotIndex = PrecompileLib.getSpotIndex(uBTC_address);
 
// Equivalent ways of obtaining spot price (via index, or via address)
uint64 spotPrice = PrecompileLib.spotPx(spotIndex); // 1000000000000000000
uint64 spotPrice2 = PrecompileLib.spotPx(uBTC_address);