UNPKG

@nktkas/hyperliquid

Version:

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

74 lines 3.29 kB
import * as v from "valibot"; // ============================================================ // API Schemas // ============================================================ import { UnsignedInteger } from "../../_schemas.js"; import { ErrorResponse, Nonce, Signature, SuccessResponse } from "./_base/schemas.js"; /** Set the display name in the leaderboard. */ export const SetDisplayNameRequest = /* @__PURE__ */ (() => { return v.pipe(v.object({ /** Action to perform. */ action: v.pipe(v.object({ /** Type of action. */ type: v.pipe(v.literal("setDisplayName"), v.description("Type of action.")), /** * Display name. * * Set to an empty string to remove the display name. */ displayName: v.pipe(v.string(), v.description("Display name." + "\n\nSet to an empty string to remove the display name.")), }), v.description("Action to perform.")), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: Nonce, /** ECDSA signature components. */ signature: Signature, /** Expiration time of the action. */ expiresAfter: v.pipe(v.optional(UnsignedInteger), v.description("Expiration time of the action.")), }), v.description("Set the display name in the leaderboard.")); })(); /** Successful response without specific data or error response. */ export const SetDisplayNameResponse = /* @__PURE__ */ (() => { return v.pipe(v.union([SuccessResponse, ErrorResponse]), v.description("Successful response without specific data or error response.")); })(); // ============================================================ // Execution Logic // ============================================================ import { executeL1Action } from "./_base/execute.js"; /** Schema for user-provided action parameters (excludes system fields). */ const SetDisplayNameParameters = /* @__PURE__ */ (() => { return v.omit(v.object(SetDisplayNameRequest.entries.action.entries), ["type"]); })(); /** * Set the display name in the leaderboard. * * @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 { setDisplayName } 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 setDisplayName( * { transport, wallet }, * { displayName: "..." }, * ); * ``` */ export function setDisplayName(config, params, opts) { const action = v.parse(SetDisplayNameParameters, params); return executeL1Action(config, { type: "setDisplayName", ...action }, opts); } //# sourceMappingURL=setDisplayName.js.map