UNPKG

@nktkas/hyperliquid

Version:

Unofficial Hyperliquid API SDK for all major JS runtimes, written in TypeScript and provided with tests

1,001 lines 61.1 kB
import { type Hex, HyperliquidError, type MaybePromise } from "../base.js"; import type { IRequestTransport } from "../transports/base.js"; import type { ApproveAgentRequest, ApproveBuilderFeeRequest, BaseExchangeRequest, BatchModifyRequest, CancelByCloidRequest, CancelRequest, CDepositRequest, ConvertToMultiSigUserRequest_Signers, CreateSubAccountRequest, CreateVaultRequest, CSignerActionRequest_JailSelf, CSignerActionRequest_UnjailSelf, CValidatorActionRequest_ChangeProfile, CValidatorActionRequest_Register, CValidatorActionRequest_Unregister, CWithdrawRequest, EvmUserModifyRequest, ModifyRequest, MultiSigRequest, OrderRequest, PerpDeployRequest_RegisterAsset, PerpDeployRequest_SetOracle, PerpDexClassTransferRequest, RegisterReferrerRequest, ReserveRequestWeightRequest, ScheduleCancelRequest, SetDisplayNameRequest, SetReferrerRequest, SpotDeployRequest_Genesis, SpotDeployRequest_RegisterHyperliquidity, SpotDeployRequest_RegisterSpot, SpotDeployRequest_RegisterToken2, SpotDeployRequest_SetDeployerTradingFeeShare, SpotDeployRequest_UserGenesis, SpotSendRequest, SpotUserRequest, SubAccountSpotTransferRequest, SubAccountTransferRequest, TokenDelegateRequest, TwapCancelRequest, TwapOrderRequest, UpdateIsolatedMarginRequest, UpdateLeverageRequest, UsdClassTransferRequest, UsdSendRequest, VaultDistributeRequest, VaultModifyRequest, VaultTransferRequest, Withdraw3Request } from "../types/exchange/requests.js"; import type { CancelResponse, CreateSubAccountResponse, CreateVaultResponse, ErrorResponse, OrderResponse, SuccessResponse, TwapCancelResponse, TwapOrderResponse } from "../types/exchange/responses.js"; import { type AbstractWallet } from "../signing/mod.js"; /** Parameters for the {@linkcode ExchangeClient} constructor. */ export interface ExchangeClientParameters<T extends IRequestTransport = IRequestTransport, W extends AbstractWallet = AbstractWallet> { /** The transport used to connect to the Hyperliquid API. */ transport: T; /** The `viem`, `ethers.js`, or `window.ethereum` wallet used for signing transactions. */ wallet: W; /** * Specifies whether the client uses testnet. * * Defaults to `false`. */ isTestnet?: boolean; /** Sets a default vaultAddress to be used if no vaultAddress is explicitly passed to a method. */ defaultVaultAddress?: Hex; /** Sets a default expiresAfter to be used if no expiresAfter is explicitly passed to a method. */ defaultExpiresAfter?: number | (() => MaybePromise<number>); /** * The network that will be used to sign transactions. * Must match the network of the {@link wallet}. * * Defaults to trying to get the current wallet network. Otherwise `0xa4b1` for `isTestnet = false` or `0x66eee` for `isTestnet = true` will be used. */ signatureChainId?: Hex | (() => MaybePromise<Hex>); /** * Function to get the next nonce for signing transactions. * * Defaults to a function that returns the current timestamp or, if duplicated, increments the last nonce. */ nonceManager?: () => MaybePromise<number>; } /** Parameters for the {@linkcode ExchangeClient.approveAgent} method. */ export type ApproveAgentParameters = Omit<ApproveAgentRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">; /** Parameters for the {@linkcode ExchangeClient.approveBuilderFee} method. */ export type ApproveBuilderFeeParameters = Omit<ApproveBuilderFeeRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">; /** Parameters for the {@linkcode ExchangeClient.batchModify} method. */ export type BatchModifyParameters = Omit<BatchModifyRequest["action"], "type"> & Partial<Pick<BatchModifyRequest, "vaultAddress">> & Partial<Pick<BatchModifyRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.cancel} method. */ export type CancelParameters = Omit<CancelRequest["action"], "type"> & Partial<Pick<CancelRequest, "vaultAddress">> & Partial<Pick<CancelRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.cancelByCloid} method. */ export type CancelByCloidParameters = Omit<CancelByCloidRequest["action"], "type"> & Partial<Pick<CancelByCloidRequest, "vaultAddress">> & Partial<Pick<CancelByCloidRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.cDeposit} method. */ export type CDepositParameters = Omit<CDepositRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">; /** Parameters for the {@linkcode ExchangeClient.convertToMultiSigUser} method. */ export type ConvertToMultiSigUserParameters = ConvertToMultiSigUserRequest_Signers; /** Parameters for the {@linkcode ExchangeClient.createSubAccount} method. */ export type CreateSubAccountParameters = Omit<CreateSubAccountRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.createVault} method. */ export type CreateVaultParameters = Omit<CreateVaultRequest["action"], "type" | "nonce">; /** Parameters for the {@linkcode ExchangeClient.cSignerAction} method. */ export type CSignerActionParameters = CSignerActionParameters_JailSelf | CSignerActionParameters_UnjailSelf; /** One of the parameters for the {@linkcode ExchangeClient.cSignerAction} method. */ export type CSignerActionParameters_JailSelf = Omit<CSignerActionRequest_JailSelf["action"], "type"> & Partial<Pick<CSignerActionRequest_JailSelf, "expiresAfter">>; /** One of the parameters for the {@linkcode ExchangeClient.cSignerAction} method. */ export type CSignerActionParameters_UnjailSelf = Omit<CSignerActionRequest_UnjailSelf["action"], "type"> & Partial<Pick<CSignerActionRequest_UnjailSelf, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.cValidatorAction} method. */ export type CValidatorActionParameters = CValidatorActionParameters_ChangeProfile | CValidatorActionParameters_Register | CValidatorActionParameters_Unregister; /** One of the parameters for the {@linkcode ExchangeClient.cValidatorAction} method. */ export type CValidatorActionParameters_ChangeProfile = Omit<CValidatorActionRequest_ChangeProfile["action"], "type"> & Partial<Pick<CValidatorActionRequest_ChangeProfile, "expiresAfter">>; /** One of the parameters for the {@linkcode ExchangeClient.cValidatorAction} method. */ export type CValidatorActionParameters_Register = Omit<CValidatorActionRequest_Register["action"], "type"> & Partial<Pick<CValidatorActionRequest_Register, "expiresAfter">>; /** One of the parameters for the {@linkcode ExchangeClient.cValidatorAction} method. */ export type CValidatorActionParameters_Unregister = Omit<CValidatorActionRequest_Unregister["action"], "type"> & Partial<Pick<CValidatorActionRequest_Unregister, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.cWithdraw} method. */ export type CWithdrawParameters = Omit<CWithdrawRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">; /** Parameters for the {@linkcode ExchangeClient.evmUserModify} method. */ export type EvmUserModifyParameters = Omit<EvmUserModifyRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.modify} method. */ export type ModifyParameters = Omit<ModifyRequest["action"], "type"> & Partial<Pick<ModifyRequest, "vaultAddress">> & Partial<Pick<ModifyRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.multiSig} method. */ export type MultiSigParameters = Omit<MultiSigRequest["action"], "type" | "signatureChainId"> & Partial<Pick<MultiSigRequest, "vaultAddress">> & Partial<Pick<MultiSigRequest, "expiresAfter">> & { /** Must be the same for all signers. */ nonce: number; }; /** Parameters for the {@linkcode ExchangeClient.order} method. */ export type OrderParameters = Omit<OrderRequest["action"], "type"> & Partial<Pick<OrderRequest, "vaultAddress">> & Partial<Pick<OrderRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.perpDeploy} method. */ export type PerpDeployParameters = PerpDeployParameters_RegisterAsset | PerpDeployParameters_SetOracle; /** One of the parameters for the {@linkcode ExchangeClient.perpDeploy} method. */ export type PerpDeployParameters_RegisterAsset = Omit<PerpDeployRequest_RegisterAsset["action"], "type">; /** One of the parameters for the {@linkcode ExchangeClient.perpDeploy} method. */ export type PerpDeployParameters_SetOracle = Omit<PerpDeployRequest_SetOracle["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.perpDexClassTransfer} method. */ export type PerpDexClassTransferParameters = Omit<PerpDexClassTransferRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">; /** Parameters for the {@linkcode ExchangeClient.registerReferrer} method. */ export type RegisterReferrerParameters = Omit<RegisterReferrerRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.reserveRequestWeight} method. */ export type ReserveRequestWeightParameters = Omit<ReserveRequestWeightRequest["action"], "type"> & Partial<Pick<ReserveRequestWeightRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.scheduleCancel} method. */ export type ScheduleCancelParameters = Omit<ScheduleCancelRequest["action"], "type"> & Partial<Pick<ScheduleCancelRequest, "vaultAddress">> & Partial<Pick<ScheduleCancelRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.setDisplayName} method. */ export type SetDisplayNameParameters = Omit<SetDisplayNameRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.setReferrer} method. */ export type SetReferrerParameters = Omit<SetReferrerRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.spotDeploy} method. */ export type SpotDeployParameters = SpotDeployParameters_Genesis | SpotDeployParameters_RegisterHyperliquidity | SpotDeployParameters_RegisterSpot | SpotDeployParameters_RegisterToken2 | SpotDeployParameters_SetDeployerTradingFeeShare | SpotDeployParameters_UserGenesis; /** One of the parameters for the {@linkcode ExchangeClient.spotDeploy} method. */ export type SpotDeployParameters_Genesis = Omit<SpotDeployRequest_Genesis["action"], "type">; /** One of the parameters for the {@linkcode ExchangeClient.spotDeploy} method. */ export type SpotDeployParameters_RegisterHyperliquidity = Omit<SpotDeployRequest_RegisterHyperliquidity["action"], "type">; /** One of the parameters for the {@linkcode ExchangeClient.spotDeploy} method. */ export type SpotDeployParameters_RegisterSpot = Omit<SpotDeployRequest_RegisterSpot["action"], "type">; /** One of the parameters for the {@linkcode ExchangeClient.spotDeploy} method. */ export type SpotDeployParameters_RegisterToken2 = Omit<SpotDeployRequest_RegisterToken2["action"], "type">; /** One of the parameters for the {@linkcode ExchangeClient.spotDeploy} method. */ export type SpotDeployParameters_SetDeployerTradingFeeShare = Omit<SpotDeployRequest_SetDeployerTradingFeeShare["action"], "type">; /** One of the parameters for the {@linkcode ExchangeClient.spotDeploy} method. */ export type SpotDeployParameters_UserGenesis = Omit<SpotDeployRequest_UserGenesis["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.spotSend} method. */ export type SpotSendParameters = Omit<SpotSendRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "time">; /** Parameters for the {@linkcode ExchangeClient.spotUser} method. */ export type SpotUserParameters = Omit<SpotUserRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.subAccountSpotTransfer} method. */ export type SubAccountSpotTransferParameters = Omit<SubAccountSpotTransferRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.subAccountTransfer} method. */ export type SubAccountTransferParameters = Omit<SubAccountTransferRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.tokenDelegate} method. */ export type TokenDelegateParameters = Omit<TokenDelegateRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">; /** Parameters for the {@linkcode ExchangeClient.twapCancel} method. */ export type TwapCancelParameters = Omit<TwapCancelRequest["action"], "type"> & Partial<Pick<TwapCancelRequest, "vaultAddress">> & Partial<Pick<TwapCancelRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.twapOrder} method. */ export type TwapOrderParameters = TwapOrderRequest["action"]["twap"] & Partial<Pick<TwapOrderRequest, "vaultAddress">> & Partial<Pick<TwapOrderRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.updateIsolatedMargin} method. */ export type UpdateIsolatedMarginParameters = Omit<UpdateIsolatedMarginRequest["action"], "type"> & Partial<Pick<UpdateIsolatedMarginRequest, "vaultAddress">> & Partial<Pick<UpdateIsolatedMarginRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.updateLeverage} method. */ export type UpdateLeverageParameters = Omit<UpdateLeverageRequest["action"], "type"> & Partial<Pick<UpdateLeverageRequest, "vaultAddress">> & Partial<Pick<UpdateLeverageRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.usdClassTransfer} method. */ export type UsdClassTransferParameters = Omit<UsdClassTransferRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "nonce">; /** Parameters for the {@linkcode ExchangeClient.usdSend} method. */ export type UsdSendParameters = Omit<UsdSendRequest["action"], "type" | "hyperliquidChain" | "signatureChainId" | "time">; /** Parameters for the {@linkcode ExchangeClient.vaultDistribute} method. */ export type VaultDistributeParameters = Omit<VaultDistributeRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.vaultModify} method. */ export type VaultModifyParameters = Omit<VaultModifyRequest["action"], "type">; /** Parameters for the {@linkcode ExchangeClient.vaultTransfer} method. */ export type VaultTransferParameters = Omit<VaultTransferRequest["action"], "type"> & Partial<Pick<VaultTransferRequest, "expiresAfter">>; /** Parameters for the {@linkcode ExchangeClient.withdraw3} method. */ export type Withdraw3Parameters = Omit<Withdraw3Request["action"], "type" | "hyperliquidChain" | "signatureChainId" | "time">; /** Successful variant of {@linkcode CancelResponse} without error statuses. */ export type CancelResponseSuccess = CancelResponse & { response: { data: { statuses: Exclude<CancelResponse["response"]["data"]["statuses"][number], { error: string; }>[]; }; }; }; /** Successful variant of {@linkcode OrderResponse} without error statuses. */ export type OrderResponseSuccess = OrderResponse & { response: { data: { statuses: Exclude<OrderResponse["response"]["data"]["statuses"][number], { error: string; }>[]; }; }; }; /** Successful variant of {@linkcode TwapCancelResponse} without error status. */ export type TwapCancelResponseSuccess = TwapCancelResponse & { response: { data: { status: Exclude<TwapCancelResponse["response"]["data"]["status"], { error: string; }>; }; }; }; /** Successful variant of {@linkcode TwapOrderResponse} without error status. */ export type TwapOrderResponseSuccess = TwapOrderResponse & { response: { data: { status: Exclude<TwapOrderResponse["response"]["data"]["status"], { error: string; }>; }; }; }; /** Error thrown when the API returns an error response. */ export declare class ApiRequestError extends HyperliquidError { response: ErrorResponse | OrderResponse | CancelResponse | TwapOrderResponse | TwapCancelResponse; constructor(response: ErrorResponse | OrderResponse | CancelResponse | TwapOrderResponse | TwapCancelResponse); } /** * Exchange client for interacting with the Hyperliquid API. * @typeParam T The transport used to connect to the Hyperliquid API. * @typeParam W The wallet used for signing transactions. */ export declare class ExchangeClient<T extends IRequestTransport = IRequestTransport, W extends AbstractWallet = AbstractWallet> implements ExchangeClientParameters<T, W>, AsyncDisposable { transport: T; wallet: W; isTestnet: boolean; defaultVaultAddress?: Hex; defaultExpiresAfter?: number | (() => MaybePromise<number>); signatureChainId: Hex | (() => MaybePromise<Hex>); nonceManager: () => MaybePromise<number>; /** * Initialises a new instance. * @param args - The parameters for the client. * * @example Private key * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; * * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * ``` * * @example Private key via [viem](https://viem.sh/docs/clients/wallet#local-accounts-private-key-mnemonic-etc) * ```ts * import * as hl from "@nktkas/hyperliquid"; * import { privateKeyToAccount } from "viem/accounts"; * * const wallet = privateKeyToAccount("0x..."); * * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet, transport }); * ``` * * @example Private key via [ethers.js](https://docs.ethers.org/v6/api/wallet/#Wallet) or [ethers.js v5](https://docs.ethers.org/v5/api/signer/#Wallet) * ```ts * import * as hl from "@nktkas/hyperliquid"; * import { ethers } from "ethers"; * * const wallet = new ethers.Wallet("0x..."); * * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet, transport }); * ``` * * @example External wallet (e.g. MetaMask) via [viem](https://viem.sh/docs/clients/wallet#optional-hoist-the-account) * ```ts * import * as hl from "@nktkas/hyperliquid"; * import { createWalletClient, custom } from "viem"; * * const [account] = await window.ethereum.request({ method: "eth_requestAccounts" }); * const wallet = createWalletClient({ account, transport: custom(window.ethereum) }); * * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet, transport }); * ``` * * @example External wallet (e.g. MetaMask) via `window.ethereum` directly * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: window.ethereum, transport }); * ``` */ constructor(args: ExchangeClientParameters<T, W>); /** * Approve an agent to sign on behalf of the master account. * @param args - The parameters for the request. * @param signal - An optional abort signal * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-an-api-wallet * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.approveAgent({ agentAddress: "0x...", agentName: "agentName" }); * ``` */ approveAgent(args: ApproveAgentParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Approve a maximum fee rate for a builder. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-a-builder-fee * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.approveBuilderFee({ maxFeeRate: "0.01%", builder: "0x..." }); * ``` */ approveBuilderFee(args: ApproveBuilderFeeParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Modify multiple orders. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful variant of {@link OrderResponse} without error statuses. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.batchModify({ * modifies: [{ * oid: 123, * order: { * a: 0, // Asset index * b: true, // Buy order * p: "31000", // New price * s: "0.2", // New size * r: false, // Not reduce-only * t: { * limit: { * tif: "Gtc", // Good-til-cancelled * }, * }, * c: "0x...", // Client Order ID (optional) * }, * }], * }); * ``` */ batchModify(args: BatchModifyParameters, signal?: AbortSignal): Promise<OrderResponseSuccess>; /** * Cancel order(s). * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful variant of {@link CancelResponse} without error statuses. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.cancel({ * cancels: [{ * a: 0, // Asset index * o: 123, // Order ID * }], * }); * ``` */ cancel(args: CancelParameters, signal?: AbortSignal): Promise<CancelResponseSuccess>; /** * Cancel order(s) by cloid. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful variant of {@link CancelResponse} without error statuses. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.cancelByCloid({ * cancels: [ * { asset: 0, cloid: "0x..." }, * ], * }); * ``` */ cancelByCloid(args: CancelByCloidParameters, signal?: AbortSignal): Promise<CancelResponseSuccess>; /** * Transfer native token from the user's spot account into staking for delegating to validators. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-into-staking * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.cDeposit({ wei: 1 * 1e8 }); * ``` */ cDeposit(args: CDepositParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Claim rewards from referral program. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.claimRewards(); * ``` */ claimRewards(signal?: AbortSignal): Promise<SuccessResponse>; /** * Convert a single-signature account to a multi-signature account or vice versa. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.convertToMultiSigUser({ // convert to multi-sig user * authorizedUsers: ["0x...", "0x...", "0x..."], * threshold: 2, * }); * ``` */ convertToMultiSigUser(args: ConvertToMultiSigUserParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Create a sub-account. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Response for creating a sub-account. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.createSubAccount({ name: "subAccountName" }); * ``` */ createSubAccount(args: CreateSubAccountParameters, signal?: AbortSignal): Promise<CreateSubAccountResponse>; /** * Create a vault. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Response for creating a vault. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.createVault({ * name: "VaultName", * description: "Vault description", * initialUsd: 100 * 1e6, * }); * ``` */ createVault(args: CreateVaultParameters, signal?: AbortSignal): Promise<CreateVaultResponse>; /** * Jail or unjail self as a validator signer. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * // Jail self * const data = await exchClient.cSignerAction({ jailSelf: null }); * * // Unjail self * const data = await exchClient.cSignerAction({ unjailSelf: null }); * ``` */ cSignerAction(args: CSignerActionParameters_JailSelf, signal?: AbortSignal): Promise<SuccessResponse>; cSignerAction(args: CSignerActionParameters_UnjailSelf, signal?: AbortSignal): Promise<SuccessResponse>; /** * Action related to validator management. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * // Change validator profile * const data = await exchClient.cValidatorAction({ * changeProfile: { * name: "My Validator", * description: "Validator description", * unjailed: true, * } * }); * ``` */ cValidatorAction(args: CValidatorActionParameters_ChangeProfile, signal?: AbortSignal): Promise<SuccessResponse>; cValidatorAction(args: CValidatorActionParameters_Register, signal?: AbortSignal): Promise<SuccessResponse>; cValidatorAction(args: CValidatorActionParameters_Unregister, signal?: AbortSignal): Promise<SuccessResponse>; /** * Transfer native token from staking into the user's spot account. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#withdraw-from-staking * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.cWithdraw({ wei: 1 * 1e8 }); * ``` */ cWithdraw(args: CWithdrawParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Configure block type for EVM transactions. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Response for creating a sub-account. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/evm/dual-block-architecture * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.evmUserModify({ usingBigBlocks: true }); * ``` */ evmUserModify(args: EvmUserModifyParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Modify an order. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-an-order * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.modify({ * oid: 123, * order: { * a: 0, // Asset index * b: true, // Buy order * p: "31000", // New price * s: "0.2", // New size * r: false, // Not reduce-only * t: { * limit: { * tif: "Gtc", // Good-til-cancelled * }, * }, * c: "0x...", // Client Order ID (optional) * }, * }); * ``` */ modify(args: ModifyParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * A multi-signature request. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const multiSigUser = "0x..."; // Multi-sig user address * * const nonce = Date.now(); * const action = { type: "scheduleCancel", time: Date.now() + 10000 }; * * const signature = await hl.signL1Action({ * wallet, * action: [multiSigUser.toLowerCase(), signer1.address.toLowerCase(), action], * nonce, * isTestnet: true, * }); * * const data = await exchClient.multiSig({ * signatures: [signature], * payload: { * multiSigUser, * outerSigner: wallet.address, * action, * }, * nonce, * }); * ``` */ multiSig<T extends SuccessResponse | CancelResponseSuccess | CreateSubAccountResponse | CreateVaultResponse | OrderResponseSuccess | TwapOrderResponseSuccess | TwapCancelResponseSuccess>(args: MultiSigParameters, signal?: AbortSignal): Promise<T>; /** * Place an order(s). * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful variant of {@link OrderResponse} without error statuses. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.order({ * orders: [{ * a: 0, // Asset index * b: true, // Buy order * p: "30000", // Price * s: "0.1", // Size * r: false, // Not reduce-only * t: { * limit: { * tif: "Gtc", // Good-til-cancelled * }, * }, * c: "0x...", // Client Order ID (optional) * }], * grouping: "na", // No grouping * }); * ``` */ order(args: OrderParameters, signal?: AbortSignal): Promise<OrderResponseSuccess>; /** * Deploying HIP-3 assets. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/deploying-hip-3-assets * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.perpDeploy({ * registerAsset: { * maxGas: 1000000, * assetRequest: { * coin: "USDC", * szDecimals: 8, * oraclePx: "1", * marginTableId: 1, * onlyIsolated: false, * }, * dex: "test", * }, * }); * ``` */ perpDeploy(args: PerpDeployParameters_RegisterAsset, signal?: AbortSignal): Promise<SuccessResponse>; perpDeploy(args: PerpDeployParameters_SetOracle, signal?: AbortSignal): Promise<SuccessResponse>; /** * Transfer funds between Spot account and Perp dex account. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#transfer-from-spot-account-to-perp-account-and-vice-versa * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.perpDexClassTransfer({ * dex: "test", * token: "USDC", * amount: "1", * toPerp: true, * }); * ``` */ perpDexClassTransfer(args: PerpDexClassTransferParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Create a referral code. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.registerReferrer({ code: "TEST" }); * ``` */ registerReferrer(args: RegisterReferrerParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Reserve additional rate-limited actions for a fee. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#reserve-additional-actions * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.reserveRequestWeight({ weight: 10 }); * ``` */ reserveRequestWeight(args: ReserveRequestWeightParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Schedule a cancel-all operation at a future time. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#schedule-cancel-dead-mans-switch * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.scheduleCancel({ time: Date.now() + 3600000 }); * ``` */ scheduleCancel(args?: ScheduleCancelParameters, signal?: AbortSignal): Promise<SuccessResponse>; scheduleCancel(signal?: AbortSignal): Promise<SuccessResponse>; /** * Set the display name in the leaderboard. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.setDisplayName({ displayName: "My Name" }); * ``` */ setDisplayName(args: SetDisplayNameParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Set a referral code. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.setReferrer({ code: "TEST" }); * ``` */ setReferrer(args: SetReferrerParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Deploying HIP-1 and HIP-2 assets. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/deploying-hip-1-and-hip-2-assets * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.spotDeploy({ * registerToken2: { * spec: { * name: "USDC", * szDecimals: 8, * weiDecimals: 8, * }, * maxGas: 1000000, * fullName: "USD Coin", * }, * }); * ``` */ spotDeploy(args: SpotDeployParameters_Genesis, signal?: AbortSignal): Promise<SuccessResponse>; spotDeploy(args: SpotDeployParameters_RegisterHyperliquidity, signal?: AbortSignal): Promise<SuccessResponse>; spotDeploy(args: SpotDeployParameters_RegisterSpot, signal?: AbortSignal): Promise<SuccessResponse>; spotDeploy(args: SpotDeployParameters_RegisterToken2, signal?: AbortSignal): Promise<SuccessResponse>; spotDeploy(args: SpotDeployParameters_SetDeployerTradingFeeShare, signal?: AbortSignal): Promise<SuccessResponse>; spotDeploy(args: SpotDeployParameters_UserGenesis, signal?: AbortSignal): Promise<SuccessResponse>; /** * Send spot assets to another address. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-spot-transfer * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.spotSend({ * destination: "0x...", * token: "USDC:0xeb62eee3685fc4c43992febcd9e75443", * amount: "1", * }); * ``` */ spotSend(args: SpotSendParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Opt Out of Spot Dusting. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.spotUser({ toggleSpotDusting: { optOut: false } }); * ``` */ spotUser(args: SpotUserParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Transfer between sub-accounts (spot). * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.subAccountSpotTransfer({ * subAccountUser: "0x...", * isDeposit: true, * token: "USDC:0xeb62eee3685fc4c43992febcd9e75443", * amount: "1", * }); * ``` */ subAccountSpotTransfer(args: SubAccountSpotTransferParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Transfer between sub-accounts (perpetual). * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see null - no documentation * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.subAccountTransfer({ * subAccountUser: "0x...", * isDeposit: true, * usd: 1 * 1e6, * }); * ``` */ subAccountTransfer(args: SubAccountTransferParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Delegate or undelegate native tokens to or from a validator. * @param args - The parameters for the request. * @param signal - An optional abort signal. * @returns Successful response without specific data. * @throws {ApiRequestError} When the API returns an error response. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#delegate-or-undelegate-stake-from-validator * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const privateKey = "0x..."; // or `viem`, `ethers` * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport }); * * const data = await exchClient.tokenDelegate({ * validator: "0x...", * isUndelegate: true, * wei: 1 * 1e8, * });