• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nktkas / hyperliquid / 19405103680

16 Nov 2025 11:46AM UTC coverage: 94.726% (-0.6%) from 95.329%
19405103680

push

github

nktkas
test(info): adapt command execution for Deno and Node.js environments

368 of 581 branches covered (63.34%)

Branch coverage included in aggregate %.

11667 of 12124 relevant lines covered (96.23%)

951.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.67
/src/api/exchange/createSubAccount.ts
1
import * as v from "valibot";
353✔
2
import { Address, type DeepImmutable, parser, UnsignedInteger } from "../_base.ts";
353✔
3
import {
353✔
4
  type ExchangeRequestConfig,
5
  executeL1Action,
353✔
6
  type ExtractRequestAction,
7
  type ExtractRequestOptions,
8
  type MultiSignRequestConfig,
9
  Signature,
353✔
10
} from "./_base/mod.ts";
353✔
11

12
// -------------------- Schemas --------------------
13

14
/**
15
 * Create a sub-account.
16
 * @see null
17
 */
18
export const CreateSubAccountRequest = /* @__PURE__ */ (() => {
353✔
19
  return v.pipe(
598✔
20
    v.object({
598✔
21
      /** Action to perform. */
22
      action: v.pipe(
598✔
23
        v.object({
598✔
24
          /** Type of action. */
25
          type: v.pipe(
598✔
26
            v.literal("createSubAccount"),
598✔
27
            v.description("Type of action."),
598✔
28
          ),
29
          /** Sub-account name. */
30
          name: v.pipe(
598✔
31
            v.string(),
598✔
32
            v.minLength(1),
598✔
33
            v.description("Sub-account name."),
598✔
34
          ),
35
        }),
598✔
36
        v.description("Action to perform."),
598✔
37
      ),
38
      /** Unique request identifier (current timestamp in ms). */
39
      nonce: v.pipe(
598✔
40
        UnsignedInteger,
598✔
41
        v.description("Unique request identifier (current timestamp in ms)."),
598✔
42
      ),
43
      /** Cryptographic signature. */
44
      signature: v.pipe(
598✔
45
        Signature,
598✔
46
        v.description("Cryptographic signature."),
598✔
47
      ),
48
      /** Expiration time of the action. */
49
      expiresAfter: v.pipe(
598✔
50
        v.optional(UnsignedInteger),
598✔
51
        v.description("Expiration time of the action."),
598✔
52
      ),
53
    }),
598✔
54
    v.description("Create a sub-account."),
598✔
55
  );
56
})();
353✔
57
export type CreateSubAccountRequest = v.InferOutput<typeof CreateSubAccountRequest>;
58

59
/** Response for creating a sub-account. */
60
export const CreateSubAccountResponse = /* @__PURE__ */ (() => {
353✔
61
  return v.pipe(
598✔
62
    v.object({
598✔
63
      /** Successful status. */
64
      status: v.pipe(
598✔
65
        v.literal("ok"),
598✔
66
        v.description("Successful status."),
598✔
67
      ),
68
      /** Response details. */
69
      response: v.pipe(
598✔
70
        v.object({
598✔
71
          /** Type of response. */
72
          type: v.pipe(
598✔
73
            v.literal("createSubAccount"),
598✔
74
            v.description("Type of response."),
598✔
75
          ),
76
          /** Sub-account address. */
77
          data: v.pipe(
598✔
78
            Address,
598✔
79
            v.description("Sub-account address."),
598✔
80
          ),
81
        }),
598✔
82
        v.description("Response details."),
598✔
83
      ),
84
    }),
598✔
85
    v.description("Response for creating a sub-account."),
598✔
86
  );
87
})();
353✔
88
export type CreateSubAccountResponse = v.InferOutput<typeof CreateSubAccountResponse>;
89

90
// -------------------- Function --------------------
91

92
/** Action parameters for the {@linkcode createSubAccount} function. */
93
export type CreateSubAccountParameters = ExtractRequestAction<v.InferInput<typeof CreateSubAccountRequest>>;
94
/** Request options for the {@linkcode createSubAccount} function. */
95
export type CreateSubAccountOptions = ExtractRequestOptions<v.InferInput<typeof CreateSubAccountRequest>>;
96

97
/**
98
 * Create a sub-account.
99
 * @param config - General configuration for Exchange API requests.
100
 * @param params - Parameters specific to the API request.
101
 * @param opts - Request execution options.
102
 * @returns Response for creating a sub-account.
103
 *
104
 * @throws {ApiRequestError} When the API returns an unsuccessful response.
105
 * @throws {TransportError} When the transport layer throws an error.
106
 *
107
 * @see null
108
 * @example
109
 * ```ts
110
 * import { HttpTransport } from "@nktkas/hyperliquid";
111
 * import { createSubAccount } from "@nktkas/hyperliquid/api/exchange";
112
 * import { privateKeyToAccount } from "npm:viem/accounts";
113
 *
114
 * const wallet = privateKeyToAccount("0x..."); // viem or ethers
115
 * const transport = new HttpTransport(); // or `WebSocketTransport`
116
 *
117
 * const data = await createSubAccount(
118
 *   { transport, wallet },
119
 *   { name: "..." },
120
 * );
121
 * ```
122
 */
123
export async function createSubAccount(
353✔
124
  config: ExchangeRequestConfig | MultiSignRequestConfig,
353✔
125
  params: DeepImmutable<CreateSubAccountParameters>,
353✔
126
  opts?: CreateSubAccountOptions,
353✔
127
): Promise<CreateSubAccountResponse> {
128
  const request = parser(CreateSubAccountRequest)({
356✔
129
    action: {
356✔
130
      type: "createSubAccount",
356✔
131
      ...params,
356✔
132
    },
356✔
133
    nonce: 0, // Placeholder; actual nonce generated in `executeL1Action`
356✔
134
    signature: { // Placeholder; actual signature generated in `executeL1Action`
356✔
135
      r: "0x0000000000000000000000000000000000000000000000000000000000000000",
356✔
136
      s: "0x0000000000000000000000000000000000000000000000000000000000000000",
356✔
137
      v: 27,
356✔
138
    },
356✔
139
    expiresAfter: typeof config.defaultExpiresAfter === "number"
×
140
      ? config.defaultExpiresAfter
×
141
      : await config.defaultExpiresAfter?.(),
×
142
  });
356✔
143
  return await executeL1Action(config, request, opts?.signal);
×
144
}
356✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc