@pear-protocol/types 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { Connector } from '../connector';
|
|
3
3
|
import { InstrumentPrecision } from '../instrument-precision';
|
|
4
4
|
|
|
5
|
-
const InstrumentId = z.string();
|
|
5
|
+
const InstrumentId = z.string().trim().min(1, "Instrument ID is required").max(64, "Instrument ID must be at most 64 characters").regex(/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/, "Instrument ID contains invalid characters");
|
|
6
6
|
const InstrumentType = z.enum(["spot", "perp", "hip3"]);
|
|
7
7
|
const Instrument = z.object({
|
|
8
8
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
declare const CreateTWAPOpen: z.ZodObject<{
|
|
3
|
-
startAt: z.
|
|
4
|
-
endAt: z.
|
|
3
|
+
startAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
|
|
4
|
+
endAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
|
|
5
5
|
strategy: z.ZodLiteral<"TWAP">;
|
|
6
6
|
intent: z.ZodLiteral<"OPEN">;
|
|
7
7
|
executionType: z.ZodLiteral<"MARKET">;
|
|
@@ -21,8 +21,8 @@ declare const CreateTWAPOpen: z.ZodObject<{
|
|
|
21
21
|
sliceIntervalMs: z.ZodInt;
|
|
22
22
|
}, z.core.$strip>;
|
|
23
23
|
declare const CreateTWAPClose: z.ZodObject<{
|
|
24
|
-
startAt: z.
|
|
25
|
-
endAt: z.
|
|
24
|
+
startAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
|
|
25
|
+
endAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
|
|
26
26
|
strategy: z.ZodLiteral<"TWAP">;
|
|
27
27
|
intent: z.ZodLiteral<"CLOSE">;
|
|
28
28
|
executionType: z.ZodLiteral<"MARKET">;
|
|
@@ -34,8 +34,8 @@ declare const CreateTWAPClose: z.ZodObject<{
|
|
|
34
34
|
sliceIntervalMs: z.ZodInt;
|
|
35
35
|
}, z.core.$strip>;
|
|
36
36
|
export declare const CreateSchedule: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
37
|
-
startAt: z.
|
|
38
|
-
endAt: z.
|
|
37
|
+
startAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
|
|
38
|
+
endAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
|
|
39
39
|
strategy: z.ZodLiteral<"TWAP">;
|
|
40
40
|
intent: z.ZodLiteral<"OPEN">;
|
|
41
41
|
executionType: z.ZodLiteral<"MARKET">;
|
|
@@ -54,8 +54,8 @@ export declare const CreateSchedule: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
54
54
|
targetNotional: z.ZodString;
|
|
55
55
|
sliceIntervalMs: z.ZodInt;
|
|
56
56
|
}, z.core.$strip>, z.ZodObject<{
|
|
57
|
-
startAt: z.
|
|
58
|
-
endAt: z.
|
|
57
|
+
startAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
|
|
58
|
+
endAt: z.ZodPipe<z.ZodOptional<z.ZodCoercedDate<unknown>>, z.ZodTransform<Date, Date | undefined>>;
|
|
59
59
|
strategy: z.ZodLiteral<"TWAP">;
|
|
60
60
|
intent: z.ZodLiteral<"CLOSE">;
|
|
61
61
|
executionType: z.ZodLiteral<"MARKET">;
|
|
@@ -4,6 +4,9 @@ import { InstrumentId } from '../instrument';
|
|
|
4
4
|
import { ScheduleSliceMode } from './entities';
|
|
5
5
|
|
|
6
6
|
const SliceInterval = z.int().min(6e4).max(26784e5);
|
|
7
|
+
const THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
8
|
+
const DefaultStartAt = z.coerce.date().optional().transform((value) => value ?? /* @__PURE__ */ new Date());
|
|
9
|
+
const DefaultEndAt = z.coerce.date().optional().transform((value) => value ?? new Date(Date.now() + THIRTY_DAYS_MS));
|
|
7
10
|
const TWAPSliceOpenLeg = z.object({
|
|
8
11
|
/**
|
|
9
12
|
* Instrument ID
|
|
@@ -38,14 +41,15 @@ const BaseSchedule = z.object({
|
|
|
38
41
|
/**
|
|
39
42
|
* Start at date
|
|
40
43
|
*/
|
|
41
|
-
startAt:
|
|
44
|
+
startAt: DefaultStartAt,
|
|
42
45
|
/**
|
|
43
46
|
* End at date
|
|
44
47
|
*/
|
|
45
|
-
endAt:
|
|
46
|
-
|
|
48
|
+
endAt: DefaultEndAt
|
|
49
|
+
}).refine((data) => data.startAt && data.endAt && data.startAt < data.endAt, {
|
|
50
|
+
message: "Start at date must be before end at date"
|
|
47
51
|
});
|
|
48
|
-
const CreateTWAPOpen = BaseSchedule.
|
|
52
|
+
const CreateTWAPOpen = BaseSchedule.safeExtend({
|
|
49
53
|
/**
|
|
50
54
|
* Strategy
|
|
51
55
|
*/
|
|
@@ -71,7 +75,7 @@ const CreateTWAPOpen = BaseSchedule.extend({
|
|
|
71
75
|
*/
|
|
72
76
|
sliceIntervalMs: SliceInterval
|
|
73
77
|
});
|
|
74
|
-
const CreateTWAPClose = BaseSchedule.
|
|
78
|
+
const CreateTWAPClose = BaseSchedule.safeExtend({
|
|
75
79
|
/**
|
|
76
80
|
* Strategy
|
|
77
81
|
*/
|
package/dist/users/payloads.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export declare const UpdateUserPreferences: z.ZodObject<{
|
|
|
4
4
|
}, z.core.$strip>;
|
|
5
5
|
export type UpdateUserPreferences = z.infer<typeof UpdateUserPreferences>;
|
|
6
6
|
export declare const UpdateUserDisplayName: z.ZodObject<{
|
|
7
|
-
displayName: z.ZodString
|
|
7
|
+
displayName: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodString>;
|
|
8
8
|
}, z.core.$strip>;
|
|
9
9
|
export type UpdateUserDisplayName = z.infer<typeof UpdateUserDisplayName>;
|
package/dist/users/payloads.js
CHANGED
|
@@ -3,8 +3,24 @@ import { z } from 'zod';
|
|
|
3
3
|
const UpdateUserPreferences = z.object({
|
|
4
4
|
slippageToleranceBps: z.int().min(1).max(1e4).optional().describe("User slippage preference in basis points")
|
|
5
5
|
}).describe("Payload to update user preferences");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const DISPLAY_NAME_REGEX = /^[\p{L}\p{N} .'-]+$/u;
|
|
7
|
+
const DisplayNameSchema = z.preprocess(
|
|
8
|
+
(value) => {
|
|
9
|
+
if (typeof value !== "string") return value;
|
|
10
|
+
return value.normalize("NFKC").trim().replace(/\s+/g, " ");
|
|
11
|
+
},
|
|
12
|
+
z.string().min(1, "Display name must be at least 1 character").max(40, "Display name must be at most 40 characters").refine((value) => !/[\u200B-\u200D\uFEFF]/.test(value), {
|
|
13
|
+
message: "Display name contains invisible characters"
|
|
14
|
+
}).refine((value) => DISPLAY_NAME_REGEX.test(value), {
|
|
15
|
+
message: "Display name may only contain letters, numbers, spaces, apostrophes, hyphens, and periods"
|
|
16
|
+
}).refine((value) => /[\p{L}\p{N}]/u.test(value), {
|
|
17
|
+
message: "Display name must contain at least one letter or number"
|
|
18
|
+
}).refine((value) => !/^[ .'-]|[ .'-]$/.test(value), {
|
|
19
|
+
message: "Display name cannot start or end with punctuation"
|
|
20
|
+
}).refine((value) => !/[ .'-]{2,}/.test(value), {
|
|
21
|
+
message: "Display name cannot contain repeated separators"
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
const UpdateUserDisplayName = z.object({ displayName: DisplayNameSchema }).describe("Payload to update user display name");
|
|
9
25
|
|
|
10
26
|
export { UpdateUserDisplayName, UpdateUserPreferences };
|