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

nktkas / hyperliquid / 19514753888

19 Nov 2025 08:02PM UTC coverage: 94.811% (+0.1%) from 94.685%
19514753888

push

github

nktkas
ci: remove environment for test job

364 of 583 branches covered (62.44%)

Branch coverage included in aggregate %.

12208 of 12677 relevant lines covered (96.3%)

964.38 hits per line

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

91.36
/src/api/exchange/createSubAccount.ts
1
import * as v from "valibot";
357✔
2

3
// ============================================================
4
// API Schemas
5
// ============================================================
6

7
import { Address, UnsignedInteger } from "../_base.ts";
357✔
8
import { ErrorResponse, Signature } from "./_base/mod.ts";
357✔
9

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

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

89
// ============================================================
90
// Execution Logic
91
// ============================================================
92

93
import { type DeepImmutable, parser } from "../_base.ts";
357✔
94
import {
357✔
95
  type ExchangeRequestConfig,
96
  type ExcludeErrorResponse,
97
  executeL1Action,
357✔
98
  type ExtractRequestAction,
99
  type ExtractRequestOptions,
100
  type MultiSignRequestConfig,
101
} from "./_base/mod.ts";
357✔
102

103
/** Action parameters for the {@linkcode createSubAccount} function. */
104
export type CreateSubAccountParameters = ExtractRequestAction<v.InferInput<typeof CreateSubAccountRequest>>;
105

106
/** Request options for the {@linkcode createSubAccount} function. */
107
export type CreateSubAccountOptions = ExtractRequestOptions<v.InferInput<typeof CreateSubAccountRequest>>;
108

109
/** Successful variant of {@linkcode CreateSubAccountResponse} without errors. */
110
export type CreateSubAccountSuccessResponse = ExcludeErrorResponse<CreateSubAccountResponse>;
111

112
/**
113
 * Create a sub-account.
114
 * @param config - General configuration for Exchange API requests.
115
 * @param params - Parameters specific to the API request.
116
 * @param opts - Request execution options.
117
 * @returns Response for creating a sub-account.
118
 *
119
 * @throws {ApiRequestError} When the API returns an unsuccessful response.
120
 * @throws {TransportError} When the transport layer throws an error.
121
 *
122
 * @example
123
 * ```ts
124
 * import { HttpTransport } from "@nktkas/hyperliquid";
125
 * import { createSubAccount } from "@nktkas/hyperliquid/api/exchange";
126
 * import { privateKeyToAccount } from "viem/accounts";
127
 *
128
 * const wallet = privateKeyToAccount("0x..."); // viem or ethers
129
 * const transport = new HttpTransport(); // or `WebSocketTransport`
130
 *
131
 * const data = await createSubAccount(
132
 *   { transport, wallet },
133
 *   { name: "..." },
134
 * );
135
 * ```
136
 */
137
export async function createSubAccount(
357✔
138
  config: ExchangeRequestConfig | MultiSignRequestConfig,
357✔
139
  params: DeepImmutable<CreateSubAccountParameters>,
357✔
140
  opts?: CreateSubAccountOptions,
357✔
141
): Promise<CreateSubAccountSuccessResponse> {
142
  const request = parser(CreateSubAccountRequest)({
360✔
143
    action: {
360✔
144
      type: "createSubAccount",
360✔
145
      ...params,
360✔
146
    },
360✔
147
    nonce: 0, // Placeholder; actual nonce generated in `executeL1Action`
360✔
148
    signature: { // Placeholder; actual signature generated in `executeL1Action`
360✔
149
      r: "0x0000000000000000000000000000000000000000000000000000000000000000",
360✔
150
      s: "0x0000000000000000000000000000000000000000000000000000000000000000",
360✔
151
      v: 27,
360✔
152
    },
360✔
153
    expiresAfter: typeof config.defaultExpiresAfter === "number"
×
154
      ? config.defaultExpiresAfter
×
155
      : await config.defaultExpiresAfter?.(),
×
156
  });
360✔
157
  return await executeL1Action(config, request, opts?.signal);
×
158
}
360✔
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