@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
1,316 lines • 76 kB
JavaScript
/**
* Client for the Hyperliquid Exchange API endpoint.
* @module
*/ // ============================================================
// Methods Imports
// ============================================================
import { agentEnableDexAbstraction } from "./_methods/agentEnableDexAbstraction.js";
import { agentSendAsset } from "./_methods/agentSendAsset.js";
import { agentSetAbstraction } from "./_methods/agentSetAbstraction.js";
import { approveAgent } from "./_methods/approveAgent.js";
import { approveBuilderFee } from "./_methods/approveBuilderFee.js";
import { authorizeAqav2Role } from "./_methods/authorizeAqav2Role.js";
import { batchModify } from "./_methods/batchModify.js";
import { borrowLend } from "./_methods/borrowLend.js";
import { cancel } from "./_methods/cancel.js";
import { cancelByCloid } from "./_methods/cancelByCloid.js";
import { cDeposit } from "./_methods/cDeposit.js";
import { claimRewards } from "./_methods/claimRewards.js";
import { convertToMultiSigUser } from "./_methods/convertToMultiSigUser.js";
import { createSubAccount } from "./_methods/createSubAccount.js";
import { createVault } from "./_methods/createVault.js";
import { cSignerAction } from "./_methods/cSignerAction.js";
import { cValidatorAction } from "./_methods/cValidatorAction.js";
import { cWithdraw } from "./_methods/cWithdraw.js";
import { evmUserModify } from "./_methods/evmUserModify.js";
import { finalizeEvmContract } from "./_methods/finalizeEvmContract.js";
import { gossipPriorityBid } from "./_methods/gossipPriorityBid.js";
import { hip3LiquidatorTransfer } from "./_methods/hip3LiquidatorTransfer.js";
import { linkStakingUser } from "./_methods/linkStakingUser.js";
import { modify } from "./_methods/modify.js";
import { noop } from "./_methods/noop.js";
import { order } from "./_methods/order.js";
import { perpDeploy } from "./_methods/perpDeploy.js";
import { registerReferrer } from "./_methods/registerReferrer.js";
import { reserveRequestWeight } from "./_methods/reserveRequestWeight.js";
import { scheduleCancel } from "./_methods/scheduleCancel.js";
import { sendAsset } from "./_methods/sendAsset.js";
import { sendToEvmWithData } from "./_methods/sendToEvmWithData.js";
import { setDisplayName } from "./_methods/setDisplayName.js";
import { setReferrer } from "./_methods/setReferrer.js";
import { spotDeploy } from "./_methods/spotDeploy.js";
import { spotSend } from "./_methods/spotSend.js";
import { spotUser } from "./_methods/spotUser.js";
import { stakingLinkDisableTradingUser } from "./_methods/stakingLinkDisableTradingUser.js";
import { subAccountModify } from "./_methods/subAccountModify.js";
import { subAccountSpotTransfer } from "./_methods/subAccountSpotTransfer.js";
import { subAccountTransfer } from "./_methods/subAccountTransfer.js";
import { tokenDelegate } from "./_methods/tokenDelegate.js";
import { topUpIsolatedOnlyMargin } from "./_methods/topUpIsolatedOnlyMargin.js";
import { twapCancel } from "./_methods/twapCancel.js";
import { twapOrder } from "./_methods/twapOrder.js";
import { updateIsolatedMargin } from "./_methods/updateIsolatedMargin.js";
import { updateLeverage } from "./_methods/updateLeverage.js";
import { usdClassTransfer } from "./_methods/usdClassTransfer.js";
import { usdSend } from "./_methods/usdSend.js";
import { userDexAbstraction } from "./_methods/userDexAbstraction.js";
import { userOutcome } from "./_methods/userOutcome.js";
import { userPortfolioMargin } from "./_methods/userPortfolioMargin.js";
import { userSetAbstraction } from "./_methods/userSetAbstraction.js";
import { validatorL1Stream } from "./_methods/validatorL1Stream.js";
import { vaultDistribute } from "./_methods/vaultDistribute.js";
import { vaultModify } from "./_methods/vaultModify.js";
import { vaultTransfer } from "./_methods/vaultTransfer.js";
import { withdraw3 } from "./_methods/withdraw3.js";
// ============================================================
// Client
// ============================================================
/**
* Execute actions: place orders, cancel orders, transfer funds, etc.
*
* Corresponds to the {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint | Exchange endpoint}.
*/ export class ExchangeClient {
config_;
/**
* Creates an instance of the ExchangeClient.
*
* @param config Configuration for Exchange API requests. See {@link ExchangeConfig}.
*
* @example [viem](https://viem.sh/docs/clients/wallet#local-accounts-private-key-mnemonic-etc)
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
*
* const client = new hl.ExchangeClient({ transport, wallet });
* ```
*
* @example [ethers.js](https://docs.ethers.org/v6/api/wallet/#Wallet)
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { ethers } from "npm:ethers";
*
* const wallet = new ethers.Wallet("0x...");
* const transport = new hl.HttpTransport();
*
* const client = new hl.ExchangeClient({ transport, wallet });
* ```
*
* @example Multi-sig
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
* import { ethers } from "npm:ethers";
*
* const signer1 = privateKeyToAccount("0x...");
* const signer2 = new ethers.Wallet("0x...");
* // ... and more signers
*
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
*
* const client = new hl.ExchangeClient({
* transport,
* signers: [signer1, signer2],
* multiSigUser: "0x...",
* });
* ```
*/ constructor(config){
this.config_ = config;
}
/**
* Enable HIP-3 DEX abstraction.
*
* Signing: L1 Action.
*
* @deprecated use {@linkcode agentSetAbstraction} instead.
*
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.agentEnableDexAbstraction();
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#enable-hip-3-dex-abstraction-agent
*/ agentEnableDexAbstraction(opts) {
return agentEnableDexAbstraction(this.config_, opts);
}
/**
* Transfer tokens on behalf of the principal via an agent wallet.
*
* Like {@link sendAsset} but signed as an L1 action by the agent wallet (instead of EIP-712 by the principal).
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const agentWallet = privateKeyToAccount("0x..."); // approved agent's private key
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet: agentWallet });
*
* await client.agentSendAsset({
* destination: "0x0000000000000000000000000000000000000001",
* sourceDex: "",
* destinationDex: "test",
* token: "USDC:0xeb62eee3685fc4c43992febcd9e75443",
* amount: "1",
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#agent-send-asset
*/ agentSendAsset(params, opts) {
return agentSendAsset(this.config_, params, opts);
}
/**
* Set user abstraction mode (method for agent wallet).
*
* Like {@link userSetAbstraction} but signed as an L1 action by the agent wallet (instead of EIP-712 by the principal).
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.agentSetAbstraction({ abstraction: "u" });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#set-user-abstraction-agent
*/ agentSetAbstraction(params, opts) {
return agentSetAbstraction(this.config_, params, opts);
}
/**
* Approve an agent to sign on behalf of the master account.
*
* Signing: User-Signed EIP-712.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example Basic usage
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.approveAgent({ agentAddress: "0x...", agentName: "myAgent" });
* ```
* @example With expiration timestamp
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* const expirationTimestamp = Date.now() + 24 * 60 * 60 * 1000;
* await client.approveAgent({
* agentAddress: "0x...",
* agentName: `myAgent valid_until ${expirationTimestamp}`,
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-an-api-wallet
*/ approveAgent(params, opts) {
return approveAgent(this.config_, params, opts);
}
/**
* Approve a maximum fee rate for a builder.
*
* Signing: User-Signed EIP-712.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.approveBuilderFee({ maxFeeRate: "0.01%", builder: "0x..." });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-a-builder-fee
*/ approveBuilderFee(params, opts) {
return approveBuilderFee(this.config_, params, opts);
}
/**
* Authorize an AQAv2 role.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.authorizeAqav2Role({
* token: 0,
* role: "technical",
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#authorize-aqav2-role
*/ authorizeAqav2Role(params, opts) {
return authorizeAqav2Role(this.config_, params, opts);
}
/**
* Modify multiple orders.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful variant of {@link OrderResponse} without error statuses.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* const data = await client.batchModify({
* modifies: [
* {
* oid: 123,
* order: {
* a: 0,
* b: true,
* p: "31000",
* s: "0.2",
* r: false,
* t: { limit: { tif: "Gtc" } },
* },
* },
* ],
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
*/ batchModify(params, opts) {
return batchModify(this.config_, params, opts);
}
/**
* Borrow or lend assets.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.borrowLend({ operation: "supply", token: 0, amount: "20" });
* ```
*
* @see null
*/ borrowLend(params, opts) {
return borrowLend(this.config_, params, opts);
}
/**
* Cancel order(s).
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful variant of {@link CancelResponse} without error statuses.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.cancel({ cancels: [{ a: 0, o: 123 }] });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
*/ cancel(params, opts) {
return cancel(this.config_, params, opts);
}
/**
* Cancel order(s) by cloid.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful variant of {@link CancelResponse} without error statuses.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.cancelByCloid({
* cancels: [
* { asset: 0, cloid: "0x..." },
* ],
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
*/ cancelByCloid(params, opts) {
return cancelByCloid(this.config_, params, opts);
}
/**
* Transfer native token from the user spot account into staking for delegating to validators.
*
* Signing: User-Signed EIP-712.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.cDeposit({ wei: 1 * 1e8 });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-into-staking
*/ cDeposit(params, opts) {
return cDeposit(this.config_, params, opts);
}
/**
* Claim rewards from referral program.
*
* Signing: L1 Action.
*
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.claimRewards();
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#claim-rewards
*/ claimRewards(opts) {
return claimRewards(this.config_, opts);
}
/**
* Convert a single-signature account to a multi-signature account or vice versa.
*
* Signing: User-Signed EIP-712.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example Convert to multi-sig
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.convertToMultiSigUser({
* signers: {
* authorizedUsers: ["0x...", "0x...", "0x..."],
* threshold: 2,
* },
* });
* ```
*
* @example Convert to single-sig
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.convertToMultiSigUser({ signers: null });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig
*/ convertToMultiSigUser(params, opts) {
return convertToMultiSigUser(this.config_, params, opts);
}
/**
* Create a sub-account.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Response for creating a sub-account.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* const data = await client.createSubAccount({ name: "..." });
* ```
*
* @see null
*/ createSubAccount(params, opts) {
return createSubAccount(this.config_, params, opts);
}
/**
* Create a vault.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Response for creating a vault.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* const data = await client.createVault({
* name: "...",
* description: "...",
* initialUsd: 100 * 1e6,
* });
* ```
*
* @see null
*/ createVault(params, opts) {
return createVault(this.config_, params, opts);
}
/**
* Jail or unjail self as a validator signer.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example Jail self
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.cSignerAction({ jailSelf: null });
* ```
*
* @example Unjail self
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.cSignerAction({ unjailSelf: null });
* ```
*
* @see null
*/ cSignerAction(params, opts) {
return cSignerAction(this.config_, params, opts);
}
/**
* Action related to validator management.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.cValidatorAction({
* changeProfile: {
* node_ip: { Ip: "1.2.3.4" },
* name: "...",
* description: "...",
* unjailed: true,
* disable_delegations: false,
* commission_bps: null,
* signer: null,
* },
* });
* ```
*
* @see null
*/ cValidatorAction(params, opts) {
return cValidatorAction(this.config_, params, opts);
}
/**
* Transfer native token from staking into the user's spot account.
*
* Signing: User-Signed EIP-712.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.cWithdraw({ wei: 1 * 1e8 });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#withdraw-from-staking
*/ cWithdraw(params, opts) {
return cWithdraw(this.config_, params, opts);
}
/**
* Configure block type for EVM transactions.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.evmUserModify({ usingBigBlocks: true });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/hyperevm/dual-block-architecture
*/ evmUserModify(params, opts) {
return evmUserModify(this.config_, params, opts);
}
/**
* Finalize the link between a HyperCore spot token and an ERC-20 contract on the HyperEVM.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example Finalize from an EOA-deployed contract
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.finalizeEvmContract({ token: 200, input: { create: { nonce: 0 } } });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/hyperevm/hypercore-less-than-greater-than-hyperevm-transfers
*/ finalizeEvmContract(params, opts) {
return finalizeEvmContract(this.config_, params, opts);
}
/**
* Bid in a gossip priority Dutch auction to receive prioritized mempool data for an IP.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.gossipPriorityBid({
* slotId: 0,
* ip: "1.2.3.4",
* maxGas: 100_000_000, // 1 HYPE
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/priority-fees
*/ gossipPriorityBid(params, opts) {
return gossipPriorityBid(this.config_, params, opts);
}
/**
* Deposit into or withdraw from the HIP-3 DEX backstop liquidator.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.hip3LiquidatorTransfer({
* dex: "test",
* ntl: 1_000_000_000, // 1000 quote tokens (1e-6 units)
* isDeposit: true,
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-or-withdraw-from-an-hip-3-dexs-backstop-liquidator
*/ hip3LiquidatorTransfer(params, opts) {
return hip3LiquidatorTransfer(this.config_, params, opts);
}
/**
* Link staking and trading accounts for fee discount attribution.
*
* Signing: User-Signed EIP-712.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.linkStakingUser({ user: "0x...", isFinalize: false });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/trading/fees#staking-linking
*/ linkStakingUser(params, opts) {
return linkStakingUser(this.config_, params, opts);
}
/**
* Modify an order.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.modify({
* oid: 123,
* order: {
* a: 0,
* b: true,
* p: "31000",
* s: "0.2",
* r: false,
* t: { limit: { tif: "Gtc" } },
* },
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-an-order
*/ modify(params, opts) {
return modify(this.config_, params, opts);
}
/**
* Place an order(s).
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful variant of {@link OrderResponse} without error statuses.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* const data = await client.order({
* orders: [
* {
* a: 0,
* b: true,
* p: "30000",
* s: "0.1",
* r: false,
* t: { limit: { tif: "Gtc" } },
* },
* ],
* grouping: "na",
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
*/ order(params, opts) {
return order(this.config_, params, opts);
}
/**
* This action does not do anything (no operation), but causes the nonce to be marked as used.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.noop({ nonce: 1730000000000 });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#invalidate-pending-nonce-noop
*/ noop(params, opts) {
return noop(this.config_, params, opts);
}
/**
* Deploying HIP-3 assets.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.perpDeploy({
* registerAsset: {
* maxGas: 1000000,
* assetRequest: {
* coin: "USDC",
* szDecimals: 8,
* oraclePx: "1",
* marginTableId: 1,
* onlyIsolated: false,
* },
* dex: "test",
* schema: null,
* },
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/hip-3-deployer-actions
*/ perpDeploy(params, opts) {
return perpDeploy(this.config_, params, opts);
}
/**
* Create a referral code.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.registerReferrer({ code: "..." });
* ```
*
* @see null
*/ registerReferrer(params, opts) {
return registerReferrer(this.config_, params, opts);
}
/**
* Reserve additional rate-limited actions for a fee.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.reserveRequestWeight({ weight: 10 });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#reserve-additional-actions
*/ reserveRequestWeight(params, opts) {
return reserveRequestWeight(this.config_, params, opts);
}
scheduleCancel(paramsOrOpts, maybeOpts) {
const isFirstArgParams = paramsOrOpts && "time" in paramsOrOpts;
const params = isFirstArgParams ? paramsOrOpts : {};
const opts = isFirstArgParams ? maybeOpts : paramsOrOpts;
return scheduleCancel(this.config_, params, opts);
}
/**
* Transfer tokens between different perp DEXs, spot balance, users, and/or sub-accounts.
*
* Like {@link agentSendAsset} but signed via EIP-712 by the principal (instead of as an L1 action by the agent wallet).
*
* Signing: User-Signed EIP-712.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.sendAsset({
* destination: "0x0000000000000000000000000000000000000001",
* sourceDex: "",
* destinationDex: "test",
* token: "USDC:0xeb62eee3685fc4c43992febcd9e75443",
* amount: "1",
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#send-asset
*/ sendAsset(params, opts) {
return sendAsset(this.config_, params, opts);
}
/**
* Transfer tokens from Core to EVM with an additional data payload for `ICoreReceiveWithData` contracts.
*
* Signing: User-Signed EIP-712.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.sendToEvmWithData({
* token: "USDC",
* amount: "1",
* sourceDex: "spot",
* destinationRecipient: "0x...",
* addressEncoding: "hex",
* destinationChainId: 42161,
* gasLimit: 200000,
* data: "0x",
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#send-to-evm-with-data
*/ sendToEvmWithData(params, opts) {
return sendToEvmWithData(this.config_, params, opts);
}
/**
* Set the display name in the leaderboard.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.setDisplayName({ displayName: "..." });
* ```
*
* @see null
*/ setDisplayName(params, opts) {
return setDisplayName(this.config_, params, opts);
}
/**
* Set a referral code.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.setReferrer({ code: "..." });
* ```
*
* @see null
*/ setReferrer(params, opts) {
return setReferrer(this.config_, params, opts);
}
/**
* Deploying HIP-1 and HIP-2 assets.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.spotDeploy({
* registerToken2: {
* spec: {
* name: "USDC",
* szDecimals: 8,
* weiDecimals: 8,
* },
* maxGas: 1000000,
* fullName: "USD Coin",
* },
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/deploying-hip-1-and-hip-2-assets
*/ spotDeploy(params, opts) {
return spotDeploy(this.config_, params, opts);
}
/**
* Send spot assets to another address.
*
* Signing: User-Signed EIP-712.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportError} When the transport layer throws an error.
* @throws {ApiRequestError} When the API returns an unsuccessful response.
*
* @example
* ```ts
* import * as hl from "@nktkas/hyperliquid";
* import { privateKeyToAccount } from "npm:viem/accounts";
*
* const wallet = privateKeyToAccount("0x..."); // viem or ethers
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
* const client = new hl.ExchangeClient({ transport, wallet });
*
* await client.spotSend({
* destination: "0x...",
* token: "USDC:0xeb62eee3685fc4c43992febcd9e75443",
* amount: "1",
* });
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-spot-transfer
*/ spotSend(params, opts) {
return spotSend(this.config_, params, opts);
}
/**
* Opt out of spot dusting.
*
* Signing: L1 Action.
*
* @param params Parameters specific to the API request.
* @param opts Request execution options.
* @return Successful response without specific data.
*
* @throws {ValidationError} When the request parameters fail validation (before sending).
* @throws {TransportE