@pear-protocol/types 1.3.0 → 1.5.0

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.
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ import { Connector } from '../connector';
3
+ import { Trigger } from '../trigger';
4
+ import { LadderConfig } from './payloads';
5
+
6
+ const LadderStatus = z.enum(["ACTIVE", "COMPLETED", "CANCELLED"]);
7
+ const Ladder = z.object({
8
+ id: z.uuid(),
9
+ connector: Connector,
10
+ positionKey: z.string(),
11
+ config: LadderConfig,
12
+ status: LadderStatus,
13
+ triggers: z.array(Trigger),
14
+ createdAt: z.string(),
15
+ updatedAt: z.string()
16
+ });
17
+
18
+ export { Ladder, LadderStatus };
@@ -0,0 +1,4 @@
1
+ export * from './entities';
2
+ export * from './payloads';
3
+ export * from './queries';
4
+ export * from './responses';
@@ -0,0 +1,4 @@
1
+ export * from './entities';
2
+ export * from './payloads';
3
+ export * from './queries';
4
+ export * from './responses';
@@ -0,0 +1,229 @@
1
+ import { z } from 'zod';
2
+ export declare const LadderConfig: z.ZodObject<{
3
+ thresholdStart: z.ZodNumber;
4
+ thresholdEnd: z.ZodNumber;
5
+ levels: z.ZodInt;
6
+ weighting: z.ZodDefault<z.ZodLiteral<"EQUAL">>;
7
+ }, z.core.$strip>;
8
+ export declare const LadderConditionOpen: z.ZodDiscriminatedUnion<[z.ZodObject<{
9
+ type: z.ZodLiteral<"ratio">;
10
+ data: z.ZodObject<{
11
+ priceSource: z.ZodEnum<{
12
+ mid: "mid";
13
+ mark: "mark";
14
+ }>;
15
+ symbol_a: z.ZodString;
16
+ symbol_b: z.ZodString;
17
+ track: z.ZodEnum<{
18
+ PEAK: "PEAK";
19
+ TROUGH: "TROUGH";
20
+ }>;
21
+ }, z.core.$strip>;
22
+ }, z.core.$strip>, z.ZodObject<{
23
+ type: z.ZodLiteral<"price">;
24
+ data: z.ZodObject<{
25
+ priceSource: z.ZodEnum<{
26
+ mid: "mid";
27
+ mark: "mark";
28
+ }>;
29
+ symbol: z.ZodString;
30
+ track: z.ZodEnum<{
31
+ PEAK: "PEAK";
32
+ TROUGH: "TROUGH";
33
+ }>;
34
+ }, z.core.$strip>;
35
+ }, z.core.$strip>, z.ZodObject<{
36
+ type: z.ZodLiteral<"weighted_ratio">;
37
+ data: z.ZodObject<{
38
+ priceSource: z.ZodEnum<{
39
+ mid: "mid";
40
+ mark: "mark";
41
+ }>;
42
+ basket: z.ZodArray<z.ZodObject<{
43
+ symbol: z.ZodString;
44
+ side: z.ZodEnum<{
45
+ BUY: "BUY";
46
+ SELL: "SELL";
47
+ }>;
48
+ weight: z.ZodNumber;
49
+ }, z.core.$strip>>;
50
+ track: z.ZodEnum<{
51
+ PEAK: "PEAK";
52
+ TROUGH: "TROUGH";
53
+ }>;
54
+ }, z.core.$strip>;
55
+ }, z.core.$strip>], "type">;
56
+ export declare const CreateLadderMarketOpen: z.ZodObject<{
57
+ type: z.ZodLiteral<"MARKET">;
58
+ intent: z.ZodLiteral<"OPEN">;
59
+ clientId: z.ZodOptional<z.ZodString>;
60
+ condition: z.ZodDiscriminatedUnion<[z.ZodObject<{
61
+ type: z.ZodLiteral<"ratio">;
62
+ data: z.ZodObject<{
63
+ priceSource: z.ZodEnum<{
64
+ mid: "mid";
65
+ mark: "mark";
66
+ }>;
67
+ symbol_a: z.ZodString;
68
+ symbol_b: z.ZodString;
69
+ track: z.ZodEnum<{
70
+ PEAK: "PEAK";
71
+ TROUGH: "TROUGH";
72
+ }>;
73
+ }, z.core.$strip>;
74
+ }, z.core.$strip>, z.ZodObject<{
75
+ type: z.ZodLiteral<"price">;
76
+ data: z.ZodObject<{
77
+ priceSource: z.ZodEnum<{
78
+ mid: "mid";
79
+ mark: "mark";
80
+ }>;
81
+ symbol: z.ZodString;
82
+ track: z.ZodEnum<{
83
+ PEAK: "PEAK";
84
+ TROUGH: "TROUGH";
85
+ }>;
86
+ }, z.core.$strip>;
87
+ }, z.core.$strip>, z.ZodObject<{
88
+ type: z.ZodLiteral<"weighted_ratio">;
89
+ data: z.ZodObject<{
90
+ priceSource: z.ZodEnum<{
91
+ mid: "mid";
92
+ mark: "mark";
93
+ }>;
94
+ basket: z.ZodArray<z.ZodObject<{
95
+ symbol: z.ZodString;
96
+ side: z.ZodEnum<{
97
+ BUY: "BUY";
98
+ SELL: "SELL";
99
+ }>;
100
+ weight: z.ZodNumber;
101
+ }, z.core.$strip>>;
102
+ track: z.ZodEnum<{
103
+ PEAK: "PEAK";
104
+ TROUGH: "TROUGH";
105
+ }>;
106
+ }, z.core.$strip>;
107
+ }, z.core.$strip>], "type">;
108
+ config: z.ZodObject<{
109
+ thresholdStart: z.ZodNumber;
110
+ thresholdEnd: z.ZodNumber;
111
+ levels: z.ZodInt;
112
+ weighting: z.ZodDefault<z.ZodLiteral<"EQUAL">>;
113
+ }, z.core.$strip>;
114
+ payload: z.ZodObject<{
115
+ type: z.ZodLiteral<"MARKET">;
116
+ legs: z.ZodTuple<[z.ZodObject<{
117
+ symbol: z.ZodString;
118
+ side: z.ZodEnum<{
119
+ BUY: "BUY";
120
+ SELL: "SELL";
121
+ }>;
122
+ mode: z.ZodEnum<{
123
+ QUANTITY: "QUANTITY";
124
+ USD: "USD";
125
+ }>;
126
+ amount: z.ZodString;
127
+ }, z.core.$strip>], z.ZodObject<{
128
+ symbol: z.ZodString;
129
+ side: z.ZodEnum<{
130
+ BUY: "BUY";
131
+ SELL: "SELL";
132
+ }>;
133
+ mode: z.ZodEnum<{
134
+ QUANTITY: "QUANTITY";
135
+ USD: "USD";
136
+ }>;
137
+ amount: z.ZodString;
138
+ }, z.core.$strip>>;
139
+ }, z.core.$strip>;
140
+ }, z.core.$strip>;
141
+ export declare const CreateLadder: z.ZodDiscriminatedUnion<[z.ZodObject<{
142
+ type: z.ZodLiteral<"MARKET">;
143
+ intent: z.ZodLiteral<"OPEN">;
144
+ clientId: z.ZodOptional<z.ZodString>;
145
+ condition: z.ZodDiscriminatedUnion<[z.ZodObject<{
146
+ type: z.ZodLiteral<"ratio">;
147
+ data: z.ZodObject<{
148
+ priceSource: z.ZodEnum<{
149
+ mid: "mid";
150
+ mark: "mark";
151
+ }>;
152
+ symbol_a: z.ZodString;
153
+ symbol_b: z.ZodString;
154
+ track: z.ZodEnum<{
155
+ PEAK: "PEAK";
156
+ TROUGH: "TROUGH";
157
+ }>;
158
+ }, z.core.$strip>;
159
+ }, z.core.$strip>, z.ZodObject<{
160
+ type: z.ZodLiteral<"price">;
161
+ data: z.ZodObject<{
162
+ priceSource: z.ZodEnum<{
163
+ mid: "mid";
164
+ mark: "mark";
165
+ }>;
166
+ symbol: z.ZodString;
167
+ track: z.ZodEnum<{
168
+ PEAK: "PEAK";
169
+ TROUGH: "TROUGH";
170
+ }>;
171
+ }, z.core.$strip>;
172
+ }, z.core.$strip>, z.ZodObject<{
173
+ type: z.ZodLiteral<"weighted_ratio">;
174
+ data: z.ZodObject<{
175
+ priceSource: z.ZodEnum<{
176
+ mid: "mid";
177
+ mark: "mark";
178
+ }>;
179
+ basket: z.ZodArray<z.ZodObject<{
180
+ symbol: z.ZodString;
181
+ side: z.ZodEnum<{
182
+ BUY: "BUY";
183
+ SELL: "SELL";
184
+ }>;
185
+ weight: z.ZodNumber;
186
+ }, z.core.$strip>>;
187
+ track: z.ZodEnum<{
188
+ PEAK: "PEAK";
189
+ TROUGH: "TROUGH";
190
+ }>;
191
+ }, z.core.$strip>;
192
+ }, z.core.$strip>], "type">;
193
+ config: z.ZodObject<{
194
+ thresholdStart: z.ZodNumber;
195
+ thresholdEnd: z.ZodNumber;
196
+ levels: z.ZodInt;
197
+ weighting: z.ZodDefault<z.ZodLiteral<"EQUAL">>;
198
+ }, z.core.$strip>;
199
+ payload: z.ZodObject<{
200
+ type: z.ZodLiteral<"MARKET">;
201
+ legs: z.ZodTuple<[z.ZodObject<{
202
+ symbol: z.ZodString;
203
+ side: z.ZodEnum<{
204
+ BUY: "BUY";
205
+ SELL: "SELL";
206
+ }>;
207
+ mode: z.ZodEnum<{
208
+ QUANTITY: "QUANTITY";
209
+ USD: "USD";
210
+ }>;
211
+ amount: z.ZodString;
212
+ }, z.core.$strip>], z.ZodObject<{
213
+ symbol: z.ZodString;
214
+ side: z.ZodEnum<{
215
+ BUY: "BUY";
216
+ SELL: "SELL";
217
+ }>;
218
+ mode: z.ZodEnum<{
219
+ QUANTITY: "QUANTITY";
220
+ USD: "USD";
221
+ }>;
222
+ amount: z.ZodString;
223
+ }, z.core.$strip>>;
224
+ }, z.core.$strip>;
225
+ }, z.core.$strip>], "type">;
226
+ export type LadderConfig = z.output<typeof LadderConfig>;
227
+ export type LadderConditionOpen = z.output<typeof LadderConditionOpen>;
228
+ export type CreateLadderMarketOpen = z.output<typeof CreateLadderMarketOpen>;
229
+ export type CreateLadder = z.output<typeof CreateLadder>;
@@ -0,0 +1,73 @@
1
+ import { z } from 'zod';
2
+ import { ClientIdCode } from '../common/client-id';
3
+ import { RefineMinimumTwoSymbols, RefineUniqueSymbols, RefineWeightingSum, RefineMinimumOneBuyOneSell, RefineTwoUniqueSymbols, RefineMinimumOneSymbol } from '../common/refinement';
4
+ import { Side } from '../common/schema';
5
+ import { TradeLegPostOnly } from '../common/trade-legs';
6
+ import { InstrumentId } from '../instrument';
7
+ import { MetricTrack } from '../trigger/common';
8
+
9
+ const LadderThreshold = z.number().positive({
10
+ message: "Threshold must be greater than 0"
11
+ });
12
+ const LadderConfig = z.object({
13
+ thresholdStart: LadderThreshold,
14
+ thresholdEnd: LadderThreshold,
15
+ levels: z.int().min(2).max(50),
16
+ weighting: z.literal("EQUAL").default("EQUAL")
17
+ }).refine((config) => config.thresholdStart !== config.thresholdEnd, {
18
+ message: "thresholds must differ"
19
+ });
20
+ const PriceSource = z.enum(["mid", "mark"], {
21
+ message: "Price source must be mid or mark"
22
+ });
23
+ const AssetWeight = z.number().positive({ message: "Weight must be greater than 0" }).max(1, { message: "Weight must be less than 1" });
24
+ const WeightedRatioBasketItem = z.object({
25
+ symbol: InstrumentId,
26
+ side: Side,
27
+ weight: AssetWeight
28
+ });
29
+ const WeightedRatioBasket = z.array(WeightedRatioBasketItem).superRefine(RefineMinimumTwoSymbols).superRefine(RefineUniqueSymbols).superRefine(RefineWeightingSum).superRefine(RefineMinimumOneBuyOneSell);
30
+ const LadderRatioOpen = z.object({
31
+ type: z.literal("ratio"),
32
+ data: z.object({
33
+ priceSource: PriceSource,
34
+ symbol_a: InstrumentId,
35
+ symbol_b: InstrumentId,
36
+ track: MetricTrack
37
+ }).superRefine(RefineTwoUniqueSymbols)
38
+ });
39
+ const LadderPriceOpen = z.object({
40
+ type: z.literal("price"),
41
+ data: z.object({
42
+ priceSource: PriceSource,
43
+ symbol: InstrumentId,
44
+ track: MetricTrack
45
+ })
46
+ });
47
+ const LadderWeightedRatioOpen = z.object({
48
+ type: z.literal("weighted_ratio"),
49
+ data: z.object({
50
+ priceSource: PriceSource,
51
+ basket: WeightedRatioBasket,
52
+ track: MetricTrack
53
+ })
54
+ });
55
+ const LadderConditionOpen = z.discriminatedUnion("type", [
56
+ LadderRatioOpen,
57
+ LadderPriceOpen,
58
+ LadderWeightedRatioOpen
59
+ ]);
60
+ const CreateLadderMarketOpen = z.object({
61
+ type: z.literal("MARKET"),
62
+ intent: z.literal("OPEN"),
63
+ clientId: ClientIdCode,
64
+ condition: LadderConditionOpen,
65
+ config: LadderConfig,
66
+ payload: z.object({
67
+ type: z.literal("MARKET"),
68
+ legs: z.tuple([TradeLegPostOnly]).rest(TradeLegPostOnly).superRefine(RefineMinimumOneSymbol).superRefine(RefineUniqueSymbols)
69
+ })
70
+ });
71
+ const CreateLadder = z.discriminatedUnion("type", [CreateLadderMarketOpen]);
72
+
73
+ export { CreateLadder, CreateLadderMarketOpen, LadderConditionOpen, LadderConfig };
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+ export declare const LadderListParams: z.ZodObject<{
3
+ limit: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<number>>>;
4
+ cursor: z.ZodOptional<z.ZodString>;
5
+ connector: z.ZodOptional<z.ZodEnum<{
6
+ hyperliquid: "hyperliquid";
7
+ binance: "binance";
8
+ bybit: "bybit";
9
+ okx: "okx";
10
+ lighter: "lighter";
11
+ }>>;
12
+ }, z.core.$strip>;
13
+ export type LadderListParamsInput = z.input<typeof LadderListParams>;
14
+ export type LadderListParams = z.output<typeof LadderListParams>;
@@ -0,0 +1,9 @@
1
+ import 'zod';
2
+ import { CursorFindParams } from '../common';
3
+ import { Connector } from '../connector';
4
+
5
+ const LadderListParams = CursorFindParams.extend({
6
+ connector: Connector.optional()
7
+ });
8
+
9
+ export { LadderListParams };