UNPKG

@nktkas/hyperliquid

Version:

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

89 lines 4.55 kB
import * as v from "valibot"; // ============================================================ // API Schemas // ============================================================ import { Hex, UnsignedInteger } from "../../_schemas.js"; import { ErrorResponse, HyperliquidChainSchema, SignatureSchema, SuccessResponse } from "./_base/commonSchemas.js"; /** * Transfer native token from the user spot account into staking for delegating to validators. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-into-staking */ export const CDepositRequest = /* @__PURE__ */ (() => { return v.pipe(v.object({ /** Action to perform. */ action: v.pipe(v.object({ /** Type of action. */ type: v.pipe(v.literal("cDeposit"), v.description("Type of action.")), /** Chain ID in hex format for EIP-712 signing. */ signatureChainId: v.pipe(Hex, v.description("Chain ID in hex format for EIP-712 signing.")), /** HyperLiquid network type. */ hyperliquidChain: v.pipe(HyperliquidChainSchema, v.description("HyperLiquid network type.")), /** Amount of wei to deposit into staking balance (float * 1e8). */ wei: v.pipe(UnsignedInteger, v.minValue(1), v.description("Amount of wei to deposit into staking balance (float * 1e8).")), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: v.pipe(UnsignedInteger, v.description("Nonce (timestamp in ms) used to prevent replay attacks.")), }), v.description("Action to perform.")), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: v.pipe(UnsignedInteger, v.description("Nonce (timestamp in ms) used to prevent replay attacks.")), /** ECDSA signature components. */ signature: v.pipe(SignatureSchema, v.description("ECDSA signature components.")), }), v.description("Transfer native token from the user spot account into staking for delegating to validators.")); })(); /** * Successful response without specific data or error response. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-into-staking */ export const CDepositResponse = /* @__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 CDepositParameters = /* @__PURE__ */ (() => { return v.omit(v.object(CDepositRequest.entries.action.entries), ["type", "signatureChainId", "hyperliquidChain", "nonce"]); })(); /** EIP-712 types for the {@linkcode cDeposit} function. */ export const CDepositTypes = { "HyperliquidTransaction:CDeposit": [ { name: "hyperliquidChain", type: "string" }, { name: "wei", type: "uint64" }, { name: "nonce", type: "uint64" }, ], }; /** * Transfer native token from the user spot account into staking for delegating to validators. * * @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 { cDeposit } 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 cDeposit( * { transport, wallet }, * { wei: 1 * 1e8 }, * ); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-into-staking */ export function cDeposit(config, params, opts) { const action = v.parse(CDepositParameters, params); return executeUserSignedAction(config, { type: "cDeposit", ...action }, CDepositTypes, opts); } //# sourceMappingURL=cDeposit.js.map