• 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

93.18
/src/api/_base.ts
1
// deno-lint-ignore-file no-explicit-any ban-types
2
import * as v from "valibot";
359✔
3
import { HyperliquidError } from "../_base.ts";
359✔
4

5
// ============================================================
6
// Types
7
// ============================================================
8

9
export type MaybePromise<T> = T | Promise<T>;
10

11
export type Prettify<T> =
12
  & { [K in keyof T]: T[K] }
13
  & {};
14

15
export type DeepImmutable<T> = {
16
  readonly [K in keyof T]: DeepImmutable<T[K]>;
17
};
18

19
export type OmitFirst<T extends readonly any[]> = T extends readonly [any, ...infer R] ? R : [];
20

21
export type OverloadedParameters<T> = T extends {
22
  (...args: infer A1): unknown;
23
  (...args: infer A2): unknown;
24
  (...args: infer A3): unknown;
25
  (...args: infer A4): unknown;
26
} ? A1 | A2 | A3 | A4
27
  : T extends {
28
    (...args: infer A1): unknown;
29
    (...args: infer A2): unknown;
30
    (...args: infer A3): unknown;
31
  } ? A1 | A2 | A3
32
  : T extends {
33
    (...args: infer A1): unknown;
34
    (...args: infer A2): unknown;
35
  } ? A1 | A2
36
  : T extends (...args: infer A) => unknown ? A
37
  : never;
38

39
// ============================================================
40
// API Schemas
41
// ============================================================
42

43
export const UnsignedDecimal = /* @__PURE__ */ (() => {
359✔
44
  return v.pipe(
609✔
45
    v.union([v.string(), v.number()]),
2,436✔
46
    v.transform(String),
609✔
47
    v.string(),
609✔
48
    v.trim(),
609✔
49
    v.regex(/^[0-9]+(\.[0-9]+)?$/),
609✔
50
    v.transform((value) => formatDecimal(value)),
609✔
51
  );
52
})();
359✔
53
export type UnsignedDecimal = v.InferOutput<typeof UnsignedDecimal>;
54

55
export const Decimal = /* @__PURE__ */ (() => {
359✔
56
  return v.pipe(
609✔
57
    v.union([v.string(), v.number()]),
2,436✔
58
    v.transform(String),
609✔
59
    v.string(),
609✔
60
    v.trim(),
609✔
61
    v.regex(/^-?[0-9]+(\.[0-9]+)?$/),
609✔
62
    v.transform((value) => formatDecimal(value)),
609✔
63
  );
64
})();
359✔
65
export type Decimal = v.InferOutput<typeof Decimal>;
66

67
export const Integer = /* @__PURE__ */ (() => {
359✔
68
  return v.pipe(
609✔
69
    v.union([v.string(), v.number()]),
2,436✔
70
    v.transform(Number),
609✔
71
    v.number(),
609✔
72
    v.integer(),
609✔
73
    v.safeInteger(),
609✔
74
  );
75
})();
359✔
76
export type Integer = v.InferOutput<typeof Integer>;
77

78
export const UnsignedInteger = /* @__PURE__ */ (() => {
359✔
79
  return v.pipe(
609✔
80
    v.union([v.string(), v.number()]),
2,436✔
81
    v.transform(Number),
609✔
82
    v.number(),
609✔
83
    v.integer(),
609✔
84
    v.safeInteger(),
609✔
85
    v.minValue(0),
609✔
86
  );
87
})();
359✔
88
export type UnsignedInteger = v.InferOutput<typeof UnsignedInteger>;
89

90
export const Hex = /* @__PURE__ */ (() => {
359✔
91
  return v.pipe(
609✔
92
    v.string(),
609✔
93
    v.regex(/^0[xX][0-9a-fA-F]+$/),
609✔
94
    v.transform((value) => value.toLowerCase() as `0x${string}`),
609✔
95
  );
96
})();
359✔
97
export type Hex = v.InferOutput<typeof Hex>;
98

99
export const Address = /* @__PURE__ */ (() => {
359✔
100
  return v.pipe(Hex, v.length(42));
609✔
101
})();
359✔
102
export type Address = v.InferOutput<typeof Address>;
103

104
export const TokenId = /* @__PURE__ */ (() => {
359✔
105
  return v.pipe(
609✔
106
    v.string(),
609✔
107
    v.regex(/^[^:]+:0x[0-9a-fA-F]+$/),
609✔
108
    v.transform((value) => value as `${string}:${Hex}`),
609✔
109
  );
110
})();
359✔
111
export type TokenId = v.InferOutput<typeof TokenId>;
112

113
export const Percent = /* @__PURE__ */ (() => {
359✔
114
  return v.pipe(
609✔
115
    v.string(),
609✔
116
    v.regex(/^[0-9]+(\.[0-9]+)?%$/),
609✔
117
    v.transform((value) => value as `${string}%`),
609✔
118
  );
119
})();
359✔
120
export type Percent = v.InferOutput<typeof Percent>;
121

122
export const ISO8601WithoutTimezone = /* @__PURE__ */ (() => {
359✔
123
  return v.pipe(
609✔
124
    v.string(),
609✔
125
    v.regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])[T ](?:0\d|1\d|2[0-3])(?::[0-5]\d){2}(?:\.\d{1,9})?$/),
609✔
126
  );
127
})();
359✔
128
export type ISO8601WithoutTimezone = v.InferOutput<typeof ISO8601WithoutTimezone>;
129

130
/** Removes leading/trailing zeros from decimal string without precision loss. */
131
function formatDecimal(numStr: string): string {
359✔
132
  return numStr
585,402✔
133
    .trim()
585,402✔
134
    .replace(/^(-?)0+(?=\d)/, "$1") // Remove leading zeros, keep sign
585,402✔
135
    .replace(/(\.\d*?)0+$/, "$1") // Remove trailing zeros after decimal
585,402✔
136
    .replace(/\.$/, ""); // Remove lone decimal point
585,402✔
137
}
585,402✔
138

139
/** Thrown when validating invalid data.  */
140
export class SchemaError extends HyperliquidError {
359✔
141
  constructor(message: string) {
×
142
    super(message);
×
143
    this.name = "SchemaError";
×
144
  }
×
145
}
359✔
146

147
/**
148
 * Creates a valibot parser with summarized error messages.
149
 * Used for validating, formatting, and sorting object keys for correct signature generation.
150
 * @param schema - The valibot schema to validate against.
151
 * @returns A parser function that validates input against the schema.
152
 */
153
export function parser<TSchema extends v.GenericSchema>(schema: TSchema): v.Parser<TSchema, undefined> {
359✔
154
  const safeParser = v.safeParser(schema);
1,872✔
155
  const parser = (input: unknown) => {
1,872✔
156
    const result = safeParser(input);
3,385✔
157
    if (result.issues) throw new SchemaError("\n" + v.summarize(result.issues));
×
158
    return result.output;
3,385✔
159
  };
1,872✔
160
  parser.schema = schema;
1,872✔
161
  parser.config = undefined;
1,872✔
162
  return parser;
1,872✔
163
}
1,872✔
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