import type { Signer } from '@chorus-one/signer'; import type { HyperliquidChain, UnsignedTx } from './types.d'; import { type DelegatorSummary, type Delegation, type StakingReward, type DelegationHistoryEvent, type SpotBalance } from './schemas'; /** * Request queue that ensures sequential execution of async functions. * Prevents network-level race conditions by forcing requests to execute in order. * This is critical for Hyperliquid's nonce-based transaction ordering, as concurrent * requests may arrive at the server out of order due to network timing variations. */ export declare class RequestQueue { private queue; /** * Enqueues an async function to execute after all previous functions complete. * @param fn - The async function to execute * @returns Promise that resolves with fn's result */ enqueue(fn: () => Promise): Promise; } /** * HyperliquidStaker - TypeScript SDK for Hyperliquid staking operations * * This class provides the functionality to stake, delegate, and manage staking on Hyperliquid. * It uses the Hyperliquid REST API for both read and write operations, with EIP-712 signing for transactions. */ export declare class HyperliquidStaker { private readonly hyperliquidChain; private readonly signatureChainId; private readonly apiUrl; private readonly nonceManager; private readonly requestQueue; /** * This **static** method is used to derive an address from a public key. * * It can be used for signer initialization, e.g. `FireblocksSigner` or `LocalSigner`. * * @returns Returns an array containing the derived address with '0x' prefix. */ static getAddressDerivationFn: () => (publicKey: Uint8Array) => Promise>; /** * Creates a HyperliquidStaker instance. * * chain - The Hyperliquid chain to use ('Mainnet' or 'Testnet') * * @returns An instance of HyperliquidStaker. */ constructor({ chain }: { chain: HyperliquidChain; }); /** * Makes a request to the Hyperliquid Info endpoint. * https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint * * @param request - The request object * @param schema - Zod schema for runtime validation * @returns The response data */ private makeInfoRequest; /** * Makes a request to the Hyperliquid Exchange endpoint. * https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint * * @param request - The exchange request object * @returns The response data */ private makeExchangeRequest; /** * Gets the staking summary for a delegator. * * @param params - Query parameters * @param params.delegatorAddress - The delegator's address * * @returns A promise that resolves to the delegator's staking summary, * including delegated and undelegated amounts */ getStakingSummary(params: { delegatorAddress: string; }): Promise; /** * Gets all active delegations for a delegator. * * @param params - Query parameters * @param params.delegatorAddress - The delegator's address * * @returns A promise that resolves to an array of active delegations */ getDelegations(params: { delegatorAddress: string; }): Promise; /** * Gets the staking rewards history for a delegator. * * @param params - Query parameters * @param params.delegatorAddress - The delegator's address * * @returns A promise that resolves to an array of staking rewards */ getDelegatorRewards(params: { delegatorAddress: string; }): Promise; /** * Gets the delegation history for a delegator. * * @param params - Query parameters * @param params.delegatorAddress - The delegator's address * * @returns A promise that resolves to an array of delegation history events */ getDelegatorHistory(params: { delegatorAddress: string; }): Promise; /** * Gets the spot account balances for a user. * * @param params - Query parameters * @param params.delegatorAddress - The user's address * * @returns A promise that resolves to an array of spot balances for different assets(e.g. HYPE, USDC) */ getSpotBalances(params: { delegatorAddress: string; }): Promise<{ balances: SpotBalance[]; }>; /** * Builds a transaction to move tokens from spot account to staking balance. * * @param params - Transaction parameters * @param params.amount - Amount to deposit in HYPE (e.g., "1.5") * * @returns Returns a promise that resolves to a DepositToStakingAction */ buildSpotToStakingTx(params: { amount: string; }): Promise<{ tx: UnsignedTx; }>; /** * Builds a transaction to withdraw tokens from staking balance to spot account. * Note: Withdrawals go through a 7-day unstaking queue. * * @param params - Transaction parameters * @param params.amount - Amount to withdraw in tokens (e.g., "1.5") * * @returns Returns a promise that resolves to a WithdrawFromStakingAction */ buildWithdrawFromStakingTx(params: { amount: string; }): Promise<{ tx: UnsignedTx; }>; /** * Builds a transaction to delegate tokens to a validator. * Note: Delegations have a 1-day lockup period per validator. * * @param params - Transaction parameters * @param params.validatorAddress - Address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 * @param params.amount - Amount to delegate in HYPE (e.g., "1.5") * * @returns Returns a promise that resolves to a DelegateAction */ buildStakeTx(params: { validatorAddress: `0x${string}`; amount: string; }): Promise<{ tx: UnsignedTx; }>; /** * Builds a transaction to undelegate tokens from a validator. * Note: Undelegations have a 1-day lockup period. * * @param params - Transaction parameters * @param params.validatorAddress - Address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000 * @param params.amount - Amount to undelegate in HYPE (e.g., "1.5") * * @returns Returns a promise that resolves to a DelegateAction */ buildUnstakeTx(params: { validatorAddress: `0x${string}`; amount: string; }): Promise<{ tx: UnsignedTx; }>; /** * Signs a transaction using EIP-712 structured data signing. * * @param params - Signing parameters * @param params.signer - The signer instance * @param params.signerAddress - The address of the signer * @param params.tx - The unsigned transaction * * @returns A promise that resolves to the signed transaction */ sign(params: { signer: Signer; signerAddress: string; tx: UnsignedTx; }): Promise<{ signedTx: string; }>; /** * Builds EIP-712 typed data for signing. * * @param action - The action to sign * @returns The EIP-712 typed data object */ private buildEIP712TypedData; /** * Broadcasts a signed transaction to the Hyperliquid network. * * Uses a request queue to ensure transactions are sent sequentially, preventing * network-level race conditions that could cause out-of-order nonce errors. * * @param params - Broadcasting parameters * @param params.signedTx - The signed transaction (JSON string) * * @returns A promise that resolves to the transaction hash */ broadcast(params: { signedTx: string; delegatorAddress: `0x${string}`; }): Promise<{ txHash: string; }>; }