• 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

89.55
/src/api/exchange/vaultModify.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, SuccessResponse } from "./_base/mod.ts";
357✔
9

10
/** Modify a vault's configuration. */
11
export const VaultModifyRequest = /* @__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("vaultModify"),
605✔
20
            v.description("Type of action."),
605✔
21
          ),
22
          /** Vault address. */
23
          vaultAddress: v.pipe(
605✔
24
            Address,
605✔
25
            v.description("Vault address."),
605✔
26
          ),
27
          /** Allow deposits from followers (default: null). */
28
          allowDeposits: v.pipe(
605✔
29
            v.optional(v.nullable(v.boolean()), null),
605✔
30
            v.description("Allow deposits from followers."),
605✔
31
          ),
32
          /** Always close positions on withdrawal (default: null). */
33
          alwaysCloseOnWithdraw: v.pipe(
605✔
34
            v.optional(v.nullable(v.boolean()), null),
605✔
35
            v.description("Always close positions on withdrawal."),
605✔
36
          ),
37
        }),
605✔
38
        v.description("Action to perform."),
605✔
39
      ),
40
      /** Unique request identifier (current timestamp in ms). */
41
      nonce: v.pipe(
605✔
42
        UnsignedInteger,
605✔
43
        v.description("Unique request identifier (current timestamp in ms)."),
605✔
44
      ),
45
      /** Cryptographic signature. */
46
      signature: v.pipe(
605✔
47
        Signature,
605✔
48
        v.description("Cryptographic signature."),
605✔
49
      ),
50
      /** Expiration time of the action. */
51
      expiresAfter: v.pipe(
605✔
52
        v.optional(UnsignedInteger),
605✔
53
        v.description("Expiration time of the action."),
605✔
54
      ),
55
    }),
605✔
56
    v.description("Modify a vault's configuration."),
605✔
57
  );
58
})();
357✔
59
export type VaultModifyRequest = v.InferOutput<typeof VaultModifyRequest>;
60

61
/** Successful response without specific data or error response. */
62
export const VaultModifyResponse = /* @__PURE__ */ (() => {
357✔
63
  return v.pipe(
605✔
64
    v.union([SuccessResponse, ErrorResponse]),
2,420✔
65
    v.description("Successful response without specific data or error response."),
605✔
66
  );
67
})();
357✔
68
export type VaultModifyResponse = v.InferOutput<typeof VaultModifyResponse>;
69

70
// ============================================================
71
// Execution Logic
72
// ============================================================
73

74
import { type DeepImmutable, parser } from "../_base.ts";
357✔
75
import {
357✔
76
  type ExchangeRequestConfig,
77
  type ExcludeErrorResponse,
78
  executeL1Action,
357✔
79
  type ExtractRequestAction,
80
  type ExtractRequestOptions,
81
  type MultiSignRequestConfig,
82
} from "./_base/mod.ts";
357✔
83

84
/** Action parameters for the {@linkcode vaultModify} function. */
85
export type VaultModifyParameters = ExtractRequestAction<v.InferInput<typeof VaultModifyRequest>>;
86

87
/** Request options for the {@linkcode vaultModify} function. */
88
export type VaultModifyOptions = ExtractRequestOptions<v.InferInput<typeof VaultModifyRequest>>;
89

90
/** Successful variant of {@linkcode VaultModifyResponse} without errors. */
91
export type VaultModifySuccessResponse = ExcludeErrorResponse<VaultModifyResponse>;
92

93
/**
94
 * Modify a vault's configuration.
95
 * @param config - General configuration for Exchange API requests.
96
 * @param params - Parameters specific to the API request.
97
 * @param opts - Request execution options.
98
 * @returns Successful response without specific data.
99
 *
100
 * @throws {ApiRequestError} When the API returns an unsuccessful response.
101
 * @throws {TransportError} When the transport layer throws an error.
102
 *
103
 * @example
104
 * ```ts
105
 * import { HttpTransport } from "@nktkas/hyperliquid";
106
 * import { vaultModify } from "@nktkas/hyperliquid/api/exchange";
107
 * import { privateKeyToAccount } from "viem/accounts";
108
 *
109
 * const wallet = privateKeyToAccount("0x..."); // viem or ethers
110
 * const transport = new HttpTransport(); // or `WebSocketTransport`
111
 *
112
 * await vaultModify(
113
 *   { transport, wallet },
114
 *   {
115
 *     vaultAddress: "0x...",
116
 *     allowDeposits: true,
117
 *     alwaysCloseOnWithdraw: false,
118
 *   },
119
 * );
120
 * ```
121
 */
122
export async function vaultModify(
357✔
123
  config: ExchangeRequestConfig | MultiSignRequestConfig,
357✔
124
  params: DeepImmutable<VaultModifyParameters>,
357✔
125
  opts?: VaultModifyOptions,
357✔
126
): Promise<VaultModifySuccessResponse> {
127
  const request = parser(VaultModifyRequest)({
360✔
128
    action: {
360✔
129
      type: "vaultModify",
360✔
130
      ...params,
360✔
131
    },
360✔
132
    nonce: 0, // Placeholder; actual nonce generated in `executeL1Action`
360✔
133
    signature: { // Placeholder; actual signature generated in `executeL1Action`
360✔
134
      r: "0x0000000000000000000000000000000000000000000000000000000000000000",
360✔
135
      s: "0x0000000000000000000000000000000000000000000000000000000000000000",
360✔
136
      v: 27,
360✔
137
    },
360✔
138
    expiresAfter: typeof config.defaultExpiresAfter === "number"
×
139
      ? config.defaultExpiresAfter
×
140
      : await config.defaultExpiresAfter?.(),
×
141
  });
360✔
142
  return await executeL1Action(config, request, opts?.signal);
×
143
}
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