Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

HyperCore Precompiles

The AlphaHYPEManager integrates with Hyperliquid's core through precompiled contracts. These precompiles provide read and write access to the Hyperliquid state.

Overview

LibraryPurposePrecompile Range
L1ReadQuery Hyperliquid state0x0800 - 0x080F
L1WriteMutate Hyperliquid state0x3333...3333

L1Read - Read Operations

Precompile Addresses

address constant DELEGATOR_SUMMARY = 0x0000000000000000000000000000000000000800;
address constant SPOT_BALANCE = 0x0000000000000000000000000000000000000801;
address constant POSITION = 0x0000000000000000000000000000000000000802;
// ... additional addresses

delegatorSummary

Get staking delegation summary for an address.

function delegatorSummary(address user) internal view returns (DelegatorSummary memory)
Returns:
struct DelegatorSummary {
    uint64 delegated;           // Total delegated stake
    uint64 undelegated;         // Stake being undelegated
    uint64 totalPendingWithdrawals;  // Pending withdrawal amount
    uint64 nDelegations;        // Number of active delegations
}

Used for: Calculating underlying HYPE backing from staked amounts.


spotBalance

Get spot balance for a token.

function spotBalance(address user, uint64 token) internal view returns (SpotBalance memory)
Parameters:
NameTypeDescription
useraddressAddress to query
tokenuint64Token index on Hyperliquid Spot
Returns:
struct SpotBalance {
    uint64 total;    // Total balance
    uint64 hold;     // Amount on hold
}

Used for: Calculating underlying HYPE in Spot holdings.


delegations

Get all delegations for an address.

function delegations(address user) internal view returns (Delegation[] memory)
Returns:
struct Delegation {
    address validator;
    uint64 amount;
    uint64 lockedUntil;  // Unlock timestamp
}

Additional Read Functions

FunctionDescription
position(address, uint16)Get perpetual position
tokenSupply(uint32)Get token supply info
tokenInfo(uint32)Get token metadata
markPrice(uint16)Get perpetual mark price
oraclePrice(uint16)Get oracle price

L1Write - Write Operations

CoreWriter Interface

All write operations go through the CoreWriter precompile:

address constant CORE_WRITER = 0x3333333333333333333333333333333333333333;
 
interface CoreWriter {
    function write(bytes memory action) external;
}

tokenDelegate

Delegate or undelegate HYPE to a validator.

function tokenDelegate(address validator, uint256 amount, bool isUndelegate) internal
Parameters:
NameTypeDescription
validatoraddressValidator address
amountuint256Amount to delegate/undelegate
isUndelegatebooltrue to undelegate, false to delegate

Action Type: TokenDelegate


stakingDeposit

Deposit HYPE to staking.

function stakingDeposit(uint64 amount) internal
Parameters:
NameTypeDescription
amountuint64Amount to deposit (8 decimals)

Action Type: CDeposit


stakingWithdraw

Withdraw HYPE from staking.

function stakingWithdraw(uint64 amount) internal
Parameters:
NameTypeDescription
amountuint64Amount to withdraw (8 decimals)

Action Type: CWithdraw


spotSend

Bridge HYPE between Spot and EVM.

function spotSend(address destination, uint256 token, uint256 amount) internal
Parameters:
NameTypeDescription
destinationaddressRecipient address
tokenuint256Token index
amountuint256Amount to send

Action Type: SpotSend


System Addresses

// HYPE system bridge address - transfers to this address move HYPE between core and EVM
address constant HYPE_SYSTEM_ADDRESS = 0x2222222222222222222222222222222222222222;

Usage in AlphaHYPEManager

Reading State

// Get delegation info
L1Read.DelegatorSummary memory summary = L1Read.delegatorSummary(address(this));
uint256 stakedHype = summary.delegated + summary.undelegated + summary.totalPendingWithdrawals;
 
// Get spot balance
L1Read.SpotBalance memory spot = L1Read.spotBalance(address(this), hypeTokenIndex);
uint256 spotHype = spot.total;

Writing State

// Delegate to validator
L1Write.tokenDelegate(validator, amount, false);
 
// Undelegate from validator
L1Write.tokenDelegate(validator, amount, true);
 
// Deposit to staking pool
L1Write.stakingDeposit(uint64(amount));
 
// Withdraw from staking pool
L1Write.stakingWithdraw(uint64(amount));
 
// Bridge from Spot to EVM
L1Write.spotSend(address(this), hypeTokenIndex, amount);

Precision Handling

ContextDecimalsNotes
EVM native HYPE18Standard wei
L1Read amounts8Hyperliquid standard
L1Write amounts8Must convert from wei
αHYPE token8Matches Hyperliquid
Conversion constant:
uint256 constant SCALE_18_TO_8 = 1e10;
 
// Wei to 8 decimals
uint256 scaled = weiAmount / SCALE_18_TO_8;
 
// 8 decimals to wei
uint256 wei = scaledAmount * SCALE_18_TO_8;