UNPKG

@deeeed/hyperliquid-node20

Version:

Unofficial Hyperliquid API SDK for all major JS runtimes, written in TypeScript. Fork with Node.js 20.18.0+ compatibility.

1,049 lines 64.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, PerpDexTransferRequest, RegisterReferrerRequest, ReserveRequestWeightRequest, ScheduleCancelRequest, SetDisplayNameRequest, SetReferrerRequest, SpotDeployRequest_Genesis, SpotDeployRequest_RegisterHyperliquidity, SpotDeployRequest_RegisterSpot, SpotDeployRequest_RegisterToken2, SpotDeployRequest_SetDeployerTradingFeeShare, SpotDeployRequest_UserGenesis, SpotSendRequest, SpotUserRequest, SubAccountModifyRequest, 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, actionSorter } 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>; } type ExtractRequestParameters<T extends BaseExchangeRequest> = (T["action"] extends { signatureChainId: unknown; } ? Omit<T["action"], "type" | "signatureChainId" | "hyperliquidChain" | "nonce" | "time"> : Omit<T["action"], "type">) & (T["vaultAddress"] extends undefined ? {} : Pick<T, "vaultAddress">) & (T["expiresAfter"] extends undefined ? {} : Pick<T, "expiresAfter">); /** Parameters for the {@linkcode ExchangeClient.approveAgent} method. */ export type ApproveAgentParameters = ExtractRequestParameters<ApproveAgentRequest>; /** Parameters for the {@linkcode ExchangeClient.approveBuilderFee} method. */ export type ApproveBuilderFeeParameters = ExtractRequestParameters<ApproveBuilderFeeRequest>; /** Parameters for the {@linkcode ExchangeClient.batchModify} method. */ export type BatchModifyParameters = ExtractRequestParameters<BatchModifyRequest>; /** Parameters for the {@linkcode ExchangeClient.cancel} method. */ export type CancelParameters = ExtractRequestParameters<CancelRequest>; /** Parameters for the {@linkcode ExchangeClient.cancelByCloid} method. */ export type CancelByCloidParameters = ExtractRequestParameters<CancelByCloidRequest>; /** Parameters for the {@linkcode ExchangeClient.cDeposit} method. */ export type CDepositParameters = ExtractRequestParameters<CDepositRequest>; /** Parameters for the {@linkcode ExchangeClient.convertToMultiSigUser} method. */ export type ConvertToMultiSigUserParameters = ConvertToMultiSigUserRequest_Signers; /** Parameters for the {@linkcode ExchangeClient.createSubAccount} method. */ export type CreateSubAccountParameters = ExtractRequestParameters<CreateSubAccountRequest>; /** Parameters for the {@linkcode ExchangeClient.createVault} method. */ export type CreateVaultParameters = ExtractRequestParameters<CreateVaultRequest>; /** Parameters for the {@linkcode ExchangeClient.cSignerAction} method. */ export type CSignerActionParameters = ExtractRequestParameters<CSignerActionRequest_JailSelf> | ExtractRequestParameters<CSignerActionRequest_UnjailSelf>; /** Parameters for the {@linkcode ExchangeClient.cValidatorAction} method. */ export type CValidatorActionParameters = ExtractRequestParameters<CValidatorActionRequest_ChangeProfile> | ExtractRequestParameters<CValidatorActionRequest_Register> | ExtractRequestParameters<CValidatorActionRequest_Unregister>; /** Parameters for the {@linkcode ExchangeClient.cWithdraw} method. */ export type CWithdrawParameters = ExtractRequestParameters<CWithdrawRequest>; /** Parameters for the {@linkcode ExchangeClient.evmUserModify} method. */ export type EvmUserModifyParameters = ExtractRequestParameters<EvmUserModifyRequest>; /** Parameters for the {@linkcode ExchangeClient.modify} method. */ export type ModifyParameters = ExtractRequestParameters<ModifyRequest>; /** Parameters for the {@linkcode ExchangeClient.multiSig} method. */ export type MultiSigParameters = ExtractRequestParameters<MultiSigRequest> & { /** Must be the same for all signers. */ nonce: number; }; /** Parameters for the {@linkcode ExchangeClient.order} method. */ export type OrderParameters = ExtractRequestParameters<OrderRequest>; /** Parameters for the {@linkcode ExchangeClient.perpDeploy} method. */ export type PerpDeployParameters = ExtractRequestParameters<PerpDeployRequest_RegisterAsset> | ExtractRequestParameters<PerpDeployRequest_SetOracle>; /** Parameters for the {@linkcode ExchangeClient.perpDexClassTransfer} method. */ export type PerpDexClassTransferParameters = ExtractRequestParameters<PerpDexClassTransferRequest>; /** Parameters for the {@linkcode ExchangeClient.perpDexTransfer} method. */ export type PerpDexTransferParameters = ExtractRequestParameters<PerpDexTransferRequest>; /** Parameters for the {@linkcode ExchangeClient.registerReferrer} method. */ export type RegisterReferrerParameters = ExtractRequestParameters<RegisterReferrerRequest>; /** Parameters for the {@linkcode ExchangeClient.reserveRequestWeight} method. */ export type ReserveRequestWeightParameters = ExtractRequestParameters<ReserveRequestWeightRequest>; /** Parameters for the {@linkcode ExchangeClient.scheduleCancel} method. */ export type ScheduleCancelParameters = ExtractRequestParameters<ScheduleCancelRequest>; /** Parameters for the {@linkcode ExchangeClient.setDisplayName} method. */ export type SetDisplayNameParameters = ExtractRequestParameters<SetDisplayNameRequest>; /** Parameters for the {@linkcode ExchangeClient.setReferrer} method. */ export type SetReferrerParameters = ExtractRequestParameters<SetReferrerRequest>; /** Parameters for the {@linkcode ExchangeClient.spotDeploy} method. */ export type SpotDeployParameters = ExtractRequestParameters<SpotDeployRequest_Genesis> | ExtractRequestParameters<SpotDeployRequest_RegisterHyperliquidity> | ExtractRequestParameters<SpotDeployRequest_RegisterSpot> | ExtractRequestParameters<SpotDeployRequest_RegisterToken2> | ExtractRequestParameters<SpotDeployRequest_SetDeployerTradingFeeShare> | ExtractRequestParameters<SpotDeployRequest_UserGenesis>; /** Parameters for the {@linkcode ExchangeClient.spotSend} method. */ export type SpotSendParameters = ExtractRequestParameters<SpotSendRequest>; /** Parameters for the {@linkcode ExchangeClient.spotUser} method. */ export type SpotUserParameters = ExtractRequestParameters<SpotUserRequest>; /** Parameters for the {@linkcode ExchangeClient.subAccountModify} method. */ export type SubAccountModifyParameters = ExtractRequestParameters<SubAccountModifyRequest>; /** Parameters for the {@linkcode ExchangeClient.subAccountSpotTransfer} method. */ export type SubAccountSpotTransferParameters = ExtractRequestParameters<SubAccountSpotTransferRequest>; /** Parameters for the {@linkcode ExchangeClient.subAccountTransfer} method. */ export type SubAccountTransferParameters = ExtractRequestParameters<SubAccountTransferRequest>; /** Parameters for the {@linkcode ExchangeClient.tokenDelegate} method. */ export type TokenDelegateParameters = ExtractRequestParameters<TokenDelegateRequest>; /** Parameters for the {@linkcode ExchangeClient.twapCancel} method. */ export type TwapCancelParameters = ExtractRequestParameters<TwapCancelRequest>; /** Parameters for the {@linkcode ExchangeClient.twapOrder} method. */ export type TwapOrderParameters = ExtractRequestParameters<TwapOrderRequest>; /** Parameters for the {@linkcode ExchangeClient.updateIsolatedMargin} method. */ export type UpdateIsolatedMarginParameters = ExtractRequestParameters<UpdateIsolatedMarginRequest>; /** Parameters for the {@linkcode ExchangeClient.updateLeverage} method. */ export type UpdateLeverageParameters = ExtractRequestParameters<UpdateLeverageRequest>; /** Parameters for the {@linkcode ExchangeClient.usdClassTransfer} method. */ export type UsdClassTransferParameters = ExtractRequestParameters<UsdClassTransferRequest>; /** Parameters for the {@linkcode ExchangeClient.usdSend} method. */ export type UsdSendParameters = ExtractRequestParameters<UsdSendRequest>; /** Parameters for the {@linkcode ExchangeClient.vaultDistribute} method. */ export type VaultDistributeParameters = ExtractRequestParameters<VaultDistributeRequest>; /** Parameters for the {@linkcode ExchangeClient.vaultModify} method. */ export type VaultModifyParameters = ExtractRequestParameters<VaultModifyRequest>; /** Parameters for the {@linkcode ExchangeClient.vaultTransfer} method. */ export type VaultTransferParameters = ExtractRequestParameters<VaultTransferRequest>; /** Parameters for the {@linkcode ExchangeClient.withdraw3} method. */ export type Withdraw3Parameters = ExtractRequestParameters<Withdraw3Request>; type ExtractSuccessResponse<T> = T extends { response: { data: { statuses: (infer U)[]; }; }; } ? T & { response: { data: { statuses: Exclude<U, { error: string; }>[]; }; }; } : T extends { response: { data: { status: infer S; }; }; } ? T & { response: { data: { status: Exclude<S, { error: string; }>; }; }; } : never; /** Successful variant of {@linkcode CancelResponse} without errors. */ export type CancelResponseSuccess = ExtractSuccessResponse<CancelResponse>; /** Successful variant of {@linkcode OrderResponse} without errors. */ export type OrderResponseSuccess = ExtractSuccessResponse<OrderResponse>; /** Successful variant of {@linkcode TwapCancelResponse} without errors. */ export type TwapCancelResponseSuccess = ExtractSuccessResponse<TwapCancelResponse>; /** Successful variant of {@linkcode TwapOrderResponse} without errors. */ export type TwapOrderResponseSuccess = ExtractSuccessResponse<TwapOrderResponse>; /** 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 directly * ```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 [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 account = privateKeyToAccount("0x..."); * * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: account, transport }); * ``` * * @example [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) * ```ts * import * as hl from "@nktkas/hyperliquid"; * import { createWalletClient, custom } from "viem"; * * const ethereum = (window as any).ethereum; * const [account] = await ethereum.request({ method: "eth_requestAccounts" }); * const wallet = createWalletClient({ account, transport: custom(ethereum) }); * * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet, transport }); * ``` * * @example External wallet (e.g. MetaMask) via [`window.ethereum`](https://eips.ethereum.org/EIPS/eip-1193) * ```ts * import * as hl from "@nktkas/hyperliquid"; * * const ethereum = (window as any).ethereum; * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet: 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * await exchClient.approveAgent({ agentAddress: "0x...", 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful variant of {@link OrderResponse} without error statuses. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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, * b: true, * p: "31000", * s: "0.2", * r: false, * t: { limit: { tif: "Gtc" } }, * }, * }, * ], * }); * ``` */ batchModify(args: BatchModifyParameters, signal?: AbortSignal): Promise<OrderResponseSuccess>; /** * Cancel order(s). * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful variant of {@link CancelResponse} without error statuses. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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, o: 123 }, * ], * }); * ``` */ cancel(args: CancelParameters, signal?: AbortSignal): Promise<CancelResponseSuccess>; /** * Cancel order(s) by cloid. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful variant of {@link CancelResponse} without error statuses. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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 }); * * 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * // Convert to multi-sig user * await exchClient.convertToMultiSigUser({ * authorizedUsers: ["0x...", "0x...", "0x..."], * threshold: 2, * }); * * // Convert to single-sig user * await exchClient.convertToMultiSigUser(null); * ``` */ convertToMultiSigUser(args: ConvertToMultiSigUserParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Create a sub-account. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Response for creating a sub-account. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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: "..." }); * ``` */ createSubAccount(args: CreateSubAccountParameters, signal?: AbortSignal): Promise<CreateSubAccountResponse>; /** * Create a vault. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Response for creating a vault. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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: "...", * description: "...", * initialUsd: 100 * 1e6, * nonce: Date.now(), * }); * ``` */ 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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 * await exchClient.cSignerAction({ jailSelf: null }); * * // Unjail self * await exchClient.cSignerAction({ unjailSelf: null }); * ``` */ cSignerAction(args: CSignerActionParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Action related to validator management. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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 * await exchClient.cValidatorAction({ * changeProfile: { * name: "...", * description: "...", * unjailed: true, * } * }); * * // Register a new validator * await exchClient.cValidatorAction({ * register: { * profile: { * node_ip: { Ip: "1.2.3.4" }, * name: "...", * description: "...", * delegations_disabled: true, * commission_bps: 1, * signer: "0x...", * }, * unjailed: false, * initial_wei: 1, * }, * }); * * // Unregister a validator * await exchClient.cValidatorAction({ unregister: null }); * ``` */ cValidatorAction(args: CValidatorActionParameters, 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Response for creating a sub-account. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * await exchClient.modify({ * oid: 123, * order: { * a: 0, * b: true, * p: "31000", * s: "0.2", * r: false, * t: { limit: { tif: "Gtc" } }, * c: "0x...", * }, * }); * ``` */ modify(args: ModifyParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * A multi-signature request. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Any successful response. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig * @example * ```ts * import * as hl from "@nktkas/hyperliquid"; * import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing"; * import { privateKeyToAccount } from "viem/accounts"; * * const wallet = privateKeyToAccount("0x..."); // or any other wallet libraries * const multiSigUser = "0x..."; * * const transport = new hl.HttpTransport(); // or `WebSocketTransport` * const exchClient = new hl.ExchangeClient({ wallet, transport }); * * const nonce = Date.now(); * const action = { * type: "scheduleCancel", * time: Date.now() + 10000, * } as const; * * // Create the required number of signatures * const signature = await signL1Action({ * wallet, * action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), actionSorter[action.type](action)], * nonce, * }); * * 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful variant of {@link OrderResponse} without error statuses. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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, * b: true, * p: "30000", * s: "0.1", * r: false, * t: { limit: { tif: "Gtc" } }, * c: "0x...", * }, * ], * grouping: "na", * }); * ``` */ order(args: OrderParameters, signal?: AbortSignal): Promise<OrderResponseSuccess>; /** * Deploying HIP-3 assets. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * await exchClient.perpDeploy({ * registerAsset: { * maxGas: 1000000, * assetRequest: { * coin: "USDC", * szDecimals: 8, * oraclePx: "1", * marginTableId: 1, * onlyIsolated: false, * }, * dex: "test", * }, * }); * ``` */ perpDeploy(args: PerpDeployParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Transfer funds between Spot account and Perp dex account. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * await exchClient.perpDexClassTransfer({ dex: "test", token: "USDC", amount: "1", toPerp: true }); * ``` */ perpDexClassTransfer(args: PerpDexClassTransferParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Transfer collateral tokens between different perp dexes for the same user. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#transfer-from-perp-account-to-perp-account-for-builder-deployed-dex * @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 }); * * await exchClient.perpDexTransfer({ sourceDex: "", destinationDex: "test", amount: "1" }); * ``` */ perpDexTransfer(args: PerpDexTransferParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Create a referral code. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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 }); * * await exchClient.registerReferrer({ code: "..." }); * ``` */ 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * await exchClient.scheduleCancel({ time: Date.now() + 10_000 }); * ``` */ 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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 }); * * await exchClient.setDisplayName({ displayName: "..." }); * ``` */ setDisplayName(args: SetDisplayNameParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Set a referral code. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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 }); * * await exchClient.setReferrer({ code: "..." }); * ``` */ 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * await exchClient.spotDeploy({ * registerToken2: { * spec: { * name: "USDC", * szDecimals: 8, * weiDecimals: 8, * }, * maxGas: 1000000, * fullName: "USD Coin", * }, * }); * ``` */ spotDeploy(args: SpotDeployParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Send spot assets to another address. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @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 }); * * await exchClient.spotSend({ * destination: "0x...", * token: "USDC:0xeb62eee3685fc4c43992febcd9e75443", * amount: "1", * }); * ``` */ spotSend(args: SpotSendParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Modify a sub-account's. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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 }); * * await exchClient.subAccountModify({ subAccountUser: "0x...", name: "..." }); * ``` */ subAccountModify(args: SubAccountModifyParameters, signal?: AbortSignal): Promise<SuccessResponse>; /** * Opt Out of Spot Dusting. * @param args - The parameters for the request. * @param signal - An optional [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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 }); * * 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @throws {ApiRequestError} When the API returns an unsuccessful response. * @throws {TransportError} When the transport layer throws an error. * * @see null * @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 }); * * 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 [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). * @returns Successful response without specific data. * * @th