UNPKG

@nktkas/hyperliquid

Version:

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

70 lines (69 loc) 3.03 kB
import * as v from "valibot"; // ============================================================ // API Schemas // ============================================================ import { Hex, UnsignedInteger } from "../../_schemas.js"; /** * Enable HIP-3 DEX abstraction. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#enable-hip-3-dex-abstraction-agent */ export const AgentEnableDexAbstractionRequest = /* @__PURE__ */ (()=>{ return v.object({ /** Action to perform. */ action: v.object({ /** Type of action. */ type: v.literal("agentEnableDexAbstraction") }), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: UnsignedInteger, /** ECDSA signature components. */ signature: v.object({ /** First 32-byte component. */ r: v.pipe(Hex, v.length(66)), /** Second 32-byte component. */ s: v.pipe(Hex, v.length(66)), /** Recovery identifier. */ v: v.picklist([ 27, 28 ]) }), /** Expiration time of the action. */ expiresAfter: v.optional(UnsignedInteger) }); })(); // ============================================================ // Execution Logic // ============================================================ import { parse } from "../../../_base.js"; import { canonicalize } from "../../../signing/mod.js"; import { executeL1Action } from "./_base/mod.js"; /** Schema for action fields (excludes request-level system fields). */ const AgentEnableDexAbstractionActionSchema = /* @__PURE__ */ (()=>{ return v.object(AgentEnableDexAbstractionRequest.entries.action.entries); })(); /** * Enable HIP-3 DEX abstraction. * * Signing: L1 Action. * * @deprecated use {@linkcode agentSetAbstraction} instead. * * @param config General configuration for Exchange API requests. * @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 { HttpTransport } from "@nktkas/hyperliquid"; * import { agentEnableDexAbstraction } 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 agentEnableDexAbstraction({ transport, wallet }); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#enable-hip-3-dex-abstraction-agent */ export function agentEnableDexAbstraction(config, opts) { const action = canonicalize(AgentEnableDexAbstractionActionSchema, parse(AgentEnableDexAbstractionActionSchema, { type: "agentEnableDexAbstraction" })); return executeL1Action(config, action, opts); } //# sourceMappingURL=agentEnableDexAbstraction.js.map