UNPKG

@nktkas/hyperliquid

Version:

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

69 lines 3.28 kB
import * as v from "valibot"; // ============================================================ // API Schemas // ============================================================ import { UnsignedInteger } from "../../_schemas.js"; import { ErrorResponse, SignatureSchema, SuccessResponse } from "./_base/commonSchemas.js"; /** Create a referral code. */ export const RegisterReferrerRequest = /* @__PURE__ */ (() => { return v.pipe(v.object({ /** Action to perform. */ action: v.pipe(v.object({ /** Type of action. */ type: v.pipe(v.literal("registerReferrer"), v.description("Type of action.")), /** Referral code to create. */ code: v.pipe(v.string(), v.minLength(1), v.maxLength(20), v.description("Referral code to create.")), }), 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.")), /** Expiration time of the action. */ expiresAfter: v.pipe(v.optional(UnsignedInteger), v.description("Expiration time of the action.")), }), v.description("Create a referral code.")); })(); /** Successful response without specific data or error response. */ export const RegisterReferrerResponse = /* @__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 RegisterReferrerParameters = /* @__PURE__ */ (() => { return v.omit(v.object(RegisterReferrerRequest.entries.action.entries), ["type"]); })(); /** * Create a referral code. * * @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 { registerReferrer } 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 registerReferrer( * { transport, wallet }, * { code: "..." }, * ); * ``` */ export function registerReferrer(config, params, opts) { const action = v.parse(RegisterReferrerParameters, params); return executeL1Action(config, { type: "registerReferrer", ...action }, opts); } //# sourceMappingURL=registerReferrer.js.map