@pear-protocol/types 1.20.0 → 1.22.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.
@@ -152,6 +152,78 @@ export declare const AttachTriggerMarketClose: z.ZodUnion<readonly [z.ZodObject<
152
152
  activationValue: z.ZodOptional<z.ZodNumber>;
153
153
  }, z.core.$strip>;
154
154
  }, z.core.$strip>]>;
155
+ export declare const AttachTriggerMarketCloseList: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
156
+ intent: z.ZodLiteral<"CLOSE">;
157
+ type: z.ZodLiteral<"MARKET">;
158
+ bracketType: z.ZodEnum<{
159
+ STOP_LOSS: "STOP_LOSS";
160
+ TAKE_PROFIT: "TAKE_PROFIT";
161
+ }>;
162
+ condition: z.ZodDiscriminatedUnion<[z.ZodObject<{
163
+ type: z.ZodLiteral<"notional">;
164
+ data: z.ZodObject<{
165
+ priceSource: z.ZodEnum<{
166
+ mid: "mid";
167
+ mark: "mark";
168
+ }>;
169
+ threshold: z.ZodNumber;
170
+ }, z.core.$strip>;
171
+ }, z.core.$strip>, z.ZodObject<{
172
+ type: z.ZodLiteral<"upnl">;
173
+ data: z.ZodObject<{
174
+ priceSource: z.ZodEnum<{
175
+ mid: "mid";
176
+ mark: "mark";
177
+ }>;
178
+ threshold: z.ZodNumber;
179
+ }, z.core.$strip>;
180
+ }, z.core.$strip>, z.ZodObject<{
181
+ type: z.ZodLiteral<"upnl_bps">;
182
+ data: z.ZodObject<{
183
+ priceSource: z.ZodEnum<{
184
+ mid: "mid";
185
+ mark: "mark";
186
+ }>;
187
+ threshold: z.ZodNumber;
188
+ }, z.core.$strip>;
189
+ }, z.core.$strip>], "type">;
190
+ }, z.core.$strip>, z.ZodObject<{
191
+ intent: z.ZodLiteral<"CLOSE">;
192
+ type: z.ZodLiteral<"MARKET">;
193
+ condition: z.ZodDiscriminatedUnion<[z.ZodObject<{
194
+ type: z.ZodLiteral<"notional_trailing">;
195
+ data: z.ZodObject<{
196
+ priceSource: z.ZodEnum<{
197
+ mid: "mid";
198
+ mark: "mark";
199
+ }>;
200
+ }, z.core.$strip>;
201
+ }, z.core.$strip>, z.ZodObject<{
202
+ type: z.ZodLiteral<"upnl_trailing">;
203
+ data: z.ZodObject<{
204
+ priceSource: z.ZodEnum<{
205
+ mid: "mid";
206
+ mark: "mark";
207
+ }>;
208
+ }, z.core.$strip>;
209
+ }, z.core.$strip>, z.ZodObject<{
210
+ type: z.ZodLiteral<"upnl_bps_trailing">;
211
+ data: z.ZodObject<{
212
+ priceSource: z.ZodEnum<{
213
+ mid: "mid";
214
+ mark: "mark";
215
+ }>;
216
+ }, z.core.$strip>;
217
+ }, z.core.$strip>], "type">;
218
+ trailing: z.ZodObject<{
219
+ mode: z.ZodEnum<{
220
+ RELATIVE_BPS: "RELATIVE_BPS";
221
+ ABSOLUTE_POINTS: "ABSOLUTE_POINTS";
222
+ }>;
223
+ deltaValue: z.ZodNumber;
224
+ activationValue: z.ZodOptional<z.ZodNumber>;
225
+ }, z.core.$strip>;
226
+ }, z.core.$strip>]>>;
155
227
  export declare const CreateTriggerMarketOpen: z.ZodObject<{
156
228
  intent: z.ZodLiteral<"OPEN">;
157
229
  type: z.ZodLiteral<"MARKET">;
@@ -480,6 +552,10 @@ export declare const CreateTriggerMarketCloseStatic: z.ZodObject<{
480
552
  TAKE_PROFIT: "TAKE_PROFIT";
481
553
  NONE: "NONE";
482
554
  }>;
555
+ semanticBracketType: z.ZodOptional<z.ZodEnum<{
556
+ STOP_LOSS: "STOP_LOSS";
557
+ TAKE_PROFIT: "TAKE_PROFIT";
558
+ }>>;
483
559
  condition: z.ZodDiscriminatedUnion<[z.ZodObject<{
484
560
  type: z.ZodLiteral<"ratio">;
485
561
  data: z.ZodObject<{
@@ -631,6 +707,10 @@ export declare const CreateTriggerMarketClose: z.ZodUnion<readonly [z.ZodObject<
631
707
  TAKE_PROFIT: "TAKE_PROFIT";
632
708
  NONE: "NONE";
633
709
  }>;
710
+ semanticBracketType: z.ZodOptional<z.ZodEnum<{
711
+ STOP_LOSS: "STOP_LOSS";
712
+ TAKE_PROFIT: "TAKE_PROFIT";
713
+ }>>;
634
714
  condition: z.ZodDiscriminatedUnion<[z.ZodObject<{
635
715
  type: z.ZodLiteral<"ratio">;
636
716
  data: z.ZodObject<{
@@ -1099,6 +1179,10 @@ export declare const CreateTriggerClose: z.ZodUnion<readonly [z.ZodObject<{
1099
1179
  TAKE_PROFIT: "TAKE_PROFIT";
1100
1180
  NONE: "NONE";
1101
1181
  }>;
1182
+ semanticBracketType: z.ZodOptional<z.ZodEnum<{
1183
+ STOP_LOSS: "STOP_LOSS";
1184
+ TAKE_PROFIT: "TAKE_PROFIT";
1185
+ }>>;
1102
1186
  condition: z.ZodDiscriminatedUnion<[z.ZodObject<{
1103
1187
  type: z.ZodLiteral<"ratio">;
1104
1188
  data: z.ZodObject<{
@@ -1248,6 +1332,7 @@ export type CreateTriggerMarketClose = z.output<typeof CreateTriggerMarketClose>
1248
1332
  export type AttachTriggerMarketCloseStatic = z.output<typeof AttachTriggerMarketCloseStatic>;
1249
1333
  export type AttachTriggerMarketCloseTrailing = z.output<typeof AttachTriggerMarketCloseTrailing>;
1250
1334
  export type AttachTriggerMarketClose = z.output<typeof AttachTriggerMarketClose>;
1335
+ export type AttachTriggerMarketCloseList = z.output<typeof AttachTriggerMarketCloseList>;
1251
1336
  export type CreateTriggerOpen = z.output<typeof CreateTriggerOpen>;
1252
1337
  export type CreateTriggerClose = z.output<typeof CreateTriggerClose>;
1253
1338
  export type TrailingConfig = z.output<typeof TrailingConfig>;
@@ -30,19 +30,20 @@ const AttachTriggerMarketCloseTrailing = z.object({
30
30
  trailing: TrailingConfig
31
31
  }).superRefine(RefineTrailingLogicalRules);
32
32
  const AttachTriggerMarketClose = z.union([AttachTriggerMarketCloseStatic, AttachTriggerMarketCloseTrailing]);
33
+ const AttachTriggerMarketCloseList = z.array(AttachTriggerMarketClose).max(MAX_ATTACH_TRIGGERS, `At most ${MAX_ATTACH_TRIGGERS} close triggers can be attached.`).superRefine((attachTriggers, ctx) => {
34
+ const trailingCount = attachTriggers.filter(isAttachTriggerMarketCloseTrailing).length;
35
+ if (trailingCount > 1) {
36
+ ctx.addIssue({
37
+ code: "custom",
38
+ message: "At most one trailing close trigger can be attached."
39
+ });
40
+ }
41
+ });
33
42
  const CreateTriggerMarketOpen = z.object({
34
43
  intent: z.literal("OPEN"),
35
44
  type: z.literal("MARKET"),
36
45
  condition: CreateTriggerConditionOpen,
37
- attachTriggers: z.array(AttachTriggerMarketClose).max(MAX_ATTACH_TRIGGERS, `A market-open trigger can attach at most ${MAX_ATTACH_TRIGGERS} close triggers.`).superRefine((attachTriggers, ctx) => {
38
- const trailingCount = attachTriggers.filter(isAttachTriggerMarketCloseTrailing).length;
39
- if (trailingCount > 1) {
40
- ctx.addIssue({
41
- code: "custom",
42
- message: "A market-open trigger can attach at most one trailing close trigger."
43
- });
44
- }
45
- }).optional(),
46
+ attachTriggers: AttachTriggerMarketCloseList.optional(),
46
47
  payload: CreateTriggerMarketPayload,
47
48
  /**
48
49
  * Attribution route code (client_ids.code)
@@ -65,6 +66,9 @@ const CreateTriggerMarketCloseStatic = z.object({
65
66
  type: z.literal("MARKET"),
66
67
  positionId: z.uuid(),
67
68
  bracketType: BracketType,
69
+ // User intent when bracketType is a side-dependent price-crossing encoding.
70
+ // Optional so older clients remain wire-compatible during rollout.
71
+ semanticBracketType: TpSlBracketType.optional(),
68
72
  condition: CreateTriggerConditionCloseStatic,
69
73
  /**
70
74
  * Attribution route code (client_ids.code)
@@ -89,4 +93,4 @@ function isAttachTriggerMarketCloseTrailing(attachedTrigger) {
89
93
  return "trailing" in attachedTrigger && attachedTrigger.trailing !== void 0;
90
94
  }
91
95
 
92
- export { AttachTriggerMarketClose, AttachTriggerMarketCloseStatic, AttachTriggerMarketCloseTrailing, CreateTriggerClose, CreateTriggerMarketAdjust, CreateTriggerMarketClose, CreateTriggerMarketCloseStatic, CreateTriggerMarketCloseTrailing, CreateTriggerMarketOpen, CreateTriggerOpen, TrailingConfig, isAttachTriggerMarketCloseTrailing };
96
+ export { AttachTriggerMarketClose, AttachTriggerMarketCloseList, AttachTriggerMarketCloseStatic, AttachTriggerMarketCloseTrailing, CreateTriggerClose, CreateTriggerMarketAdjust, CreateTriggerMarketClose, CreateTriggerMarketCloseStatic, CreateTriggerMarketCloseTrailing, CreateTriggerMarketOpen, CreateTriggerOpen, TrailingConfig, isAttachTriggerMarketCloseTrailing };
@@ -1,17 +1,25 @@
1
1
  import type { z } from 'zod';
2
- import type { BracketType } from '../common';
3
2
  import type { CreateTriggerConditionCloseStatic } from '../payloads/conditions';
4
3
  type ValidationFieldIssue = {
5
4
  field: 'threshold';
6
5
  message: string;
7
6
  };
8
7
  type ConditionType = CreateTriggerConditionCloseStatic['type'];
8
+ /** Surface every logical threshold issue on a static close trigger as a zod issue. */
9
9
  export declare const RefineStaticLogicalRules: (value: {
10
- bracketType: BracketType;
11
10
  condition: CreateTriggerConditionCloseStatic;
12
11
  }, context: z.RefinementCtx) => void;
12
+ /**
13
+ * Validate a static close trigger's threshold against the rules its condition type implies.
14
+ *
15
+ * Deliberately blind to `bracketType`: it selects only the comparison direction (TAKE_PROFIT ->
16
+ * PEAK, STOP_LOSS -> TROUGH, NONE -> PEAK), and every sign pairs coherently with either direction. A positive
17
+ * STOP_LOSS is a profit floor ("close if my gain falls back to +10%") and a negative TAKE_PROFIT
18
+ * is a recovery exit ("close when my -30% loss recovers to -24%"); both are supported orders. A
19
+ * threshold that is already satisfied fires on the next evaluation pass, but catching that needs
20
+ * the position's current uPnL, which no pure function can see — it belongs in the usecase.
21
+ */
13
22
  export declare function getStaticLogicalIssues(input: {
14
- bracketType: BracketType;
15
23
  conditionType: ConditionType;
16
24
  threshold: number;
17
25
  }): ValidationFieldIssue[];
@@ -1,6 +1,5 @@
1
1
  const RefineStaticLogicalRules = (value, context) => {
2
2
  for (const issue of getStaticLogicalIssues({
3
- bracketType: value.bracketType,
4
3
  conditionType: value.condition.type,
5
4
  threshold: value.condition.data.threshold
6
5
  })) {
@@ -23,7 +22,15 @@ function getStaticLogicalIssues(input) {
23
22
  }
24
23
  break;
25
24
  }
26
- case "upnl":
25
+ case "upnl": {
26
+ if (threshold === 0) {
27
+ issues.push({
28
+ field: "threshold",
29
+ message: "threshold must not be 0 for uPnL static triggers"
30
+ });
31
+ }
32
+ break;
33
+ }
27
34
  case "upnl_bps": {
28
35
  if (threshold === 0) {
29
36
  issues.push({
@@ -71,6 +71,11 @@ export declare const TriggerListResponse: z.ZodObject<{
71
71
  TAKE_PROFIT: "TAKE_PROFIT";
72
72
  NONE: "NONE";
73
73
  }>;
74
+ semanticBracketType: z.ZodOptional<z.ZodEnum<{
75
+ STOP_LOSS: "STOP_LOSS";
76
+ TAKE_PROFIT: "TAKE_PROFIT";
77
+ NONE: "NONE";
78
+ }>>;
74
79
  createdAt: z.ZodString;
75
80
  updatedAt: z.ZodString;
76
81
  intent: z.ZodLiteral<"OPEN">;
@@ -272,6 +277,11 @@ export declare const TriggerListResponse: z.ZodObject<{
272
277
  TAKE_PROFIT: "TAKE_PROFIT";
273
278
  NONE: "NONE";
274
279
  }>;
280
+ semanticBracketType: z.ZodOptional<z.ZodEnum<{
281
+ STOP_LOSS: "STOP_LOSS";
282
+ TAKE_PROFIT: "TAKE_PROFIT";
283
+ NONE: "NONE";
284
+ }>>;
275
285
  createdAt: z.ZodString;
276
286
  updatedAt: z.ZodString;
277
287
  intent: z.ZodLiteral<"ADJUST">;
@@ -519,6 +529,11 @@ export declare const TriggerListResponse: z.ZodObject<{
519
529
  TAKE_PROFIT: "TAKE_PROFIT";
520
530
  NONE: "NONE";
521
531
  }>;
532
+ semanticBracketType: z.ZodOptional<z.ZodEnum<{
533
+ STOP_LOSS: "STOP_LOSS";
534
+ TAKE_PROFIT: "TAKE_PROFIT";
535
+ NONE: "NONE";
536
+ }>>;
522
537
  createdAt: z.ZodString;
523
538
  updatedAt: z.ZodString;
524
539
  intent: z.ZodLiteral<"CLOSE">;
@@ -804,6 +819,11 @@ export declare const CreateTriggerResponse: z.ZodObject<{
804
819
  TAKE_PROFIT: "TAKE_PROFIT";
805
820
  NONE: "NONE";
806
821
  }>;
822
+ semanticBracketType: z.ZodOptional<z.ZodEnum<{
823
+ STOP_LOSS: "STOP_LOSS";
824
+ TAKE_PROFIT: "TAKE_PROFIT";
825
+ NONE: "NONE";
826
+ }>>;
807
827
  createdAt: z.ZodString;
808
828
  updatedAt: z.ZodString;
809
829
  intent: z.ZodLiteral<"OPEN">;
@@ -1005,6 +1025,11 @@ export declare const CreateTriggerResponse: z.ZodObject<{
1005
1025
  TAKE_PROFIT: "TAKE_PROFIT";
1006
1026
  NONE: "NONE";
1007
1027
  }>;
1028
+ semanticBracketType: z.ZodOptional<z.ZodEnum<{
1029
+ STOP_LOSS: "STOP_LOSS";
1030
+ TAKE_PROFIT: "TAKE_PROFIT";
1031
+ NONE: "NONE";
1032
+ }>>;
1008
1033
  createdAt: z.ZodString;
1009
1034
  updatedAt: z.ZodString;
1010
1035
  intent: z.ZodLiteral<"ADJUST">;
@@ -1252,6 +1277,11 @@ export declare const CreateTriggerResponse: z.ZodObject<{
1252
1277
  TAKE_PROFIT: "TAKE_PROFIT";
1253
1278
  NONE: "NONE";
1254
1279
  }>;
1280
+ semanticBracketType: z.ZodOptional<z.ZodEnum<{
1281
+ STOP_LOSS: "STOP_LOSS";
1282
+ TAKE_PROFIT: "TAKE_PROFIT";
1283
+ NONE: "NONE";
1284
+ }>>;
1255
1285
  createdAt: z.ZodString;
1256
1286
  updatedAt: z.ZodString;
1257
1287
  intent: z.ZodLiteral<"CLOSE">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/types",
3
- "version": "1.20.0",
3
+ "version": "1.22.0",
4
4
  "description": "Pear Protocol Types definitions",
5
5
  "private": false,
6
6
  "type": "module",