@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
92 lines • 4.29 kB
JavaScript
import * as v from "valibot";
// ============================================================
// API Schemas
// ============================================================
import { Address, Percent } from "../../_schemas.js";
import { ErrorResponse, HyperliquidChain, Nonce, Signature, SignatureChainId, SuccessResponse, } from "./_base/schemas.js";
/**
* Approve a maximum fee rate for a builder.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-a-builder-fee
*/
export const ApproveBuilderFeeRequest = /* @__PURE__ */ (() => {
return v.pipe(v.object({
/** Action to perform. */
action: v.pipe(v.object({
/** Type of action. */
type: v.pipe(v.literal("approveBuilderFee"), v.description("Type of action.")),
/** Chain ID in hex format for EIP-712 signing. */
signatureChainId: SignatureChainId,
/** HyperLiquid network type. */
hyperliquidChain: HyperliquidChain,
/** Max fee rate (e.g., "0.01%"). */
maxFeeRate: v.pipe(Percent, v.description('Max fee rate (e.g., "0.01%").')),
/** Builder address. */
builder: v.pipe(Address, v.description("Builder address.")),
/** 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("Approve a maximum fee rate for a builder."));
})();
/**
* Successful response without specific data or error response.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-a-builder-fee
*/
export const ApproveBuilderFeeResponse = /* @__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 ApproveBuilderFeeParameters = /* @__PURE__ */ (() => {
return v.omit(v.object(ApproveBuilderFeeRequest.entries.action.entries), ["type", "signatureChainId", "hyperliquidChain", "nonce"]);
})();
/** EIP-712 types for the {@linkcode approveBuilderFee} function. */
export const ApproveBuilderFeeTypes = {
"HyperliquidTransaction:ApproveBuilderFee": [
{ name: "hyperliquidChain", type: "string" },
{ name: "maxFeeRate", type: "string" },
{ name: "builder", type: "address" },
{ name: "nonce", type: "uint64" },
],
};
/**
* Approve a maximum fee rate for a builder.
*
* @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 { approveBuilderFee } 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 approveBuilderFee(
* { transport, wallet },
* { maxFeeRate: "0.01%", builder: "0x..." },
* );
* ```
*
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-a-builder-fee
*/
export function approveBuilderFee(config, params, opts) {
const action = v.parse(ApproveBuilderFeeParameters, params);
return executeUserSignedAction(config, { type: "approveBuilderFee", ...action }, ApproveBuilderFeeTypes, opts);
}
//# sourceMappingURL=approveBuilderFee.js.map