UNPKG

@nktkas/hyperliquid

Version:

Hyperliquid API SDK for all major JS runtimes, written in TypeScript.

104 lines 4.77 kB
import * as v from "valibot"; // ============================================================ // API Schemas // ============================================================ import { Address } from "../../_schemas.js"; import { ErrorResponse, HyperliquidChain, Nonce, Signature, SignatureChainId, SuccessResponse, } from "./_base/schemas.js"; /** * Link staking and trading accounts for fee discount attribution. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/trading/fees#staking-linking */ export const LinkStakingUserRequest = /* @__PURE__ */ (() => { return v.pipe(v.object({ /** Action to perform. */ action: v.pipe(v.object({ /** Type of action. */ type: v.pipe(v.literal("linkStakingUser"), v.description("Type of action.")), /** Chain ID in hex format for EIP-712 signing. */ signatureChainId: SignatureChainId, /** HyperLiquid network type. */ hyperliquidChain: HyperliquidChain, /** * Target account address. * - Trading user initiating: enter staking account address. * - Staking user finalizing: enter trading account address. */ user: v.pipe(Address, v.description("Target account address." + "\n- Trading user initiating: enter staking account address." + "\n- Staking user finalizing: enter trading account address.")), /** * Link phase. * - `false` = trading user initiates link request. * - `true` = staking user finalizes permanent link. */ isFinalize: v.pipe(v.boolean(), v.description("Link phase." + "\n- `false` = trading user initiates link request." + "\n- `true` = staking user finalizes permanent link.")), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: Nonce, }), v.description("Action to perform.")), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: Nonce, /** ECDSA signature components. */ signature: Signature, }), v.description("")); })(); /** * Successful response without specific data or error response. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/trading/fees#staking-linking */ export const LinkStakingUserResponse = /* @__PURE__ */ (() => { return v.pipe(v.union([SuccessResponse, ErrorResponse]), v.description("Successful response without specific data or error response.")); })(); // ============================================================ // Execution Logic // ============================================================ import { executeUserSignedAction } from "./_base/execute.js"; /** Schema for user-provided action parameters (excludes system fields). */ const LinkStakingUserParameters = /* @__PURE__ */ (() => { return v.omit(v.object(LinkStakingUserRequest.entries.action.entries), ["type", "signatureChainId", "hyperliquidChain", "nonce"]); })(); /** EIP-712 types for the {@linkcode linkStakingUser} function. */ export const LinkStakingUserTypes = { "HyperliquidTransaction:LinkStakingUser": [ { name: "hyperliquidChain", type: "string" }, { name: "user", type: "address" }, { name: "isFinalize", type: "bool" }, { name: "nonce", type: "uint64" }, ], }; /** * Link staking and trading accounts for fee discount attribution. * * @param config - General configuration for Exchange API requests. * @param params - Parameters specific to the API request. * @param opts - Request execution options. * * @returns Successful response without specific data. * * @throws {ValiError} 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 { HttpTransport } from "@nktkas/hyperliquid"; * import { linkStakingUser } from "@nktkas/hyperliquid/api/exchange"; * import { privateKeyToAccount } from "npm:viem/accounts"; * * const wallet = privateKeyToAccount("0x..."); // viem or ethers * const transport = new HttpTransport(); // or `WebSocketTransport` * * await linkStakingUser( * { transport, wallet }, * { user: "0x...", isFinalize: false }, * ); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/trading/fees#staking-linking */ export function linkStakingUser(config, params, opts) { const action = v.parse(LinkStakingUserParameters, params); return executeUserSignedAction(config, { type: "linkStakingUser", ...action }, LinkStakingUserTypes, opts); } //# sourceMappingURL=linkStakingUser.js.map