@pear-protocol/types 2.17.0 → 2.19.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.
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.js +1 -0
- package/dist/common/refinement.d.ts +0 -1
- package/dist/common/refinement.js +1 -9
- package/dist/instrument/entities.d.ts +1 -0
- package/dist/instrument/responses.d.ts +1 -0
- package/dist/instrument-precision/index.d.ts +1 -0
- package/dist/instrument-precision/index.js +6 -1
- package/dist/realtime/channels.d.ts +19 -0
- package/dist/realtime/channels.js +16 -0
- package/dist/realtime/frames.d.ts +923 -0
- package/dist/realtime/frames.js +140 -0
- package/dist/realtime/index.d.ts +6 -0
- package/dist/realtime/index.js +6 -0
- package/dist/realtime/messages.d.ts +243 -0
- package/dist/realtime/messages.js +118 -0
- package/dist/realtime/public-events.d.ts +342 -0
- package/dist/realtime/public-events.js +92 -0
- package/dist/realtime/user-events.d.ts +32 -0
- package/dist/realtime/user-events.js +32 -0
- package/dist/realtime/vault-events.d.ts +71 -0
- package/dist/realtime/vault-events.js +42 -0
- package/dist/schedule/entities.d.ts +53 -163
- package/dist/schedule/entities.js +62 -3
- package/dist/schedule/queries.d.ts +7 -0
- package/dist/schedule/queries.js +15 -1
- package/dist/schedule/responses.d.ts +150 -115
- package/dist/schedule/responses.js +6 -2
- package/dist/statistics/entities.d.ts +0 -1
- package/dist/statistics/entities.js +0 -2
- package/dist/statistics/responses.d.ts +0 -1
- package/dist/sync/payloads.d.ts +0 -162
- package/dist/sync/payloads.js +1 -35
- package/dist/trade-accounts/entities.d.ts +0 -16
- package/dist/trade-accounts/entities.js +0 -2
- package/dist/trade-accounts/payloads.d.ts +0 -12
- package/dist/trade-accounts/payloads.js +1 -7
- package/dist/trade-accounts/response.d.ts +0 -120
- package/dist/traders/public.d.ts +0 -1
- package/dist/traders/public.js +0 -1
- package/dist/vaults/responses.d.ts +1 -0
- package/dist/vaults/responses.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { EthereumAddress } from '../common/address';
|
|
3
|
+
import { WebsocketChannel } from './channels';
|
|
4
|
+
import { PriceUpdatedData, FundingUpdatedData, TradeExecutedData, TriggerTriggeredPublicData } from './public-events';
|
|
5
|
+
import { UserEventData, UserEventTopic } from './user-events';
|
|
6
|
+
import { PublicVaultInvalidatedData, ManagementVaultInvalidatedData } from './vault-events';
|
|
7
|
+
|
|
8
|
+
const FrameRequestId = z.string().optional();
|
|
9
|
+
const WebsocketWelcomeFrame = z.object({
|
|
10
|
+
type: z.literal("welcome"),
|
|
11
|
+
connectionId: z.string(),
|
|
12
|
+
heartbeatIntervalMs: z.number(),
|
|
13
|
+
resubscribeRequired: z.literal(true)
|
|
14
|
+
});
|
|
15
|
+
const AuthAckFrame = z.object({
|
|
16
|
+
id: FrameRequestId,
|
|
17
|
+
type: z.literal("ack"),
|
|
18
|
+
method: z.literal("auth"),
|
|
19
|
+
ok: z.literal(true)
|
|
20
|
+
});
|
|
21
|
+
const SubscriptionAckFrame = z.object({
|
|
22
|
+
id: FrameRequestId,
|
|
23
|
+
type: z.literal("ack"),
|
|
24
|
+
method: z.enum([
|
|
25
|
+
"subscribe",
|
|
26
|
+
"unsubscribe"
|
|
27
|
+
]),
|
|
28
|
+
channel: WebsocketChannel,
|
|
29
|
+
ok: z.literal(true)
|
|
30
|
+
});
|
|
31
|
+
const WebsocketAckFrame = z.discriminatedUnion("method", [
|
|
32
|
+
AuthAckFrame,
|
|
33
|
+
SubscriptionAckFrame
|
|
34
|
+
]);
|
|
35
|
+
const WebsocketVaultErrorCode = z.enum([
|
|
36
|
+
"FORBIDDEN",
|
|
37
|
+
"SUBSCRIPTION_REVOKED"
|
|
38
|
+
]);
|
|
39
|
+
const WebsocketRequestErrorCode = z.enum([
|
|
40
|
+
"AUTH_EXPIRED",
|
|
41
|
+
"CAPACITY_UNAVAILABLE",
|
|
42
|
+
"INTERNAL_ERROR",
|
|
43
|
+
"INVALID_FRAME",
|
|
44
|
+
"INVALID_JSON",
|
|
45
|
+
"INVALID_MESSAGE",
|
|
46
|
+
"INVALID_SUBSCRIPTION",
|
|
47
|
+
"RATE_LIMITED",
|
|
48
|
+
"TOO_MANY_SUBSCRIPTIONS",
|
|
49
|
+
"UNAUTHENTICATED"
|
|
50
|
+
]);
|
|
51
|
+
const WebsocketErrorCode = z.enum([
|
|
52
|
+
...WebsocketRequestErrorCode.options,
|
|
53
|
+
...WebsocketVaultErrorCode.options
|
|
54
|
+
]);
|
|
55
|
+
const RequestErrorFrame = z.object({
|
|
56
|
+
id: FrameRequestId,
|
|
57
|
+
type: z.literal("error"),
|
|
58
|
+
code: WebsocketRequestErrorCode,
|
|
59
|
+
message: z.string()
|
|
60
|
+
});
|
|
61
|
+
const VaultErrorFrame = z.object({
|
|
62
|
+
id: FrameRequestId,
|
|
63
|
+
type: z.literal("error"),
|
|
64
|
+
code: WebsocketVaultErrorCode,
|
|
65
|
+
message: z.string(),
|
|
66
|
+
// Vaults a FORBIDDEN refusal or SUBSCRIPTION_REVOKED notice applies to.
|
|
67
|
+
vaults: z.array(EthereumAddress)
|
|
68
|
+
});
|
|
69
|
+
const WebsocketErrorFrame = z.discriminatedUnion("code", [
|
|
70
|
+
RequestErrorFrame,
|
|
71
|
+
VaultErrorFrame
|
|
72
|
+
]);
|
|
73
|
+
const PriceUpdatedFrame = z.object({
|
|
74
|
+
type: z.literal("event"),
|
|
75
|
+
channel: z.literal("prices"),
|
|
76
|
+
topic: z.literal("price.updated"),
|
|
77
|
+
data: PriceUpdatedData
|
|
78
|
+
});
|
|
79
|
+
const FundingUpdatedFrame = z.object({
|
|
80
|
+
type: z.literal("event"),
|
|
81
|
+
channel: z.literal("funding"),
|
|
82
|
+
topic: z.literal("funding.updated"),
|
|
83
|
+
data: FundingUpdatedData
|
|
84
|
+
});
|
|
85
|
+
const TradeExecutedFrame = z.object({
|
|
86
|
+
type: z.literal("event"),
|
|
87
|
+
channel: z.literal("trades"),
|
|
88
|
+
topic: z.literal("trade.executed"),
|
|
89
|
+
data: TradeExecutedData
|
|
90
|
+
});
|
|
91
|
+
const TriggerTriggeredPublicFrame = z.object({
|
|
92
|
+
type: z.literal("event"),
|
|
93
|
+
channel: z.literal("trigger_events"),
|
|
94
|
+
topic: z.literal("trigger.triggered.public"),
|
|
95
|
+
data: TriggerTriggeredPublicData
|
|
96
|
+
});
|
|
97
|
+
const UserEventFrame = z.object({
|
|
98
|
+
type: z.literal("event"),
|
|
99
|
+
channel: z.literal("user_events"),
|
|
100
|
+
topic: UserEventTopic,
|
|
101
|
+
data: UserEventData
|
|
102
|
+
});
|
|
103
|
+
const VaultEventsInvalidatedFrame = z.object({
|
|
104
|
+
type: z.literal("event"),
|
|
105
|
+
channel: z.literal("vault_events"),
|
|
106
|
+
topic: z.literal("vault.invalidated"),
|
|
107
|
+
data: PublicVaultInvalidatedData
|
|
108
|
+
});
|
|
109
|
+
const VaultManagementInvalidatedFrame = z.object({
|
|
110
|
+
type: z.literal("event"),
|
|
111
|
+
channel: z.literal("vault_management"),
|
|
112
|
+
topic: z.literal("vault.invalidated"),
|
|
113
|
+
data: ManagementVaultInvalidatedData
|
|
114
|
+
});
|
|
115
|
+
const VaultInvalidatedFrame = z.discriminatedUnion("channel", [
|
|
116
|
+
VaultEventsInvalidatedFrame,
|
|
117
|
+
VaultManagementInvalidatedFrame
|
|
118
|
+
]);
|
|
119
|
+
const WebsocketEventFrame = z.discriminatedUnion("topic", [
|
|
120
|
+
PriceUpdatedFrame,
|
|
121
|
+
FundingUpdatedFrame,
|
|
122
|
+
TradeExecutedFrame,
|
|
123
|
+
TriggerTriggeredPublicFrame,
|
|
124
|
+
UserEventFrame,
|
|
125
|
+
VaultInvalidatedFrame
|
|
126
|
+
]);
|
|
127
|
+
const WebsocketPongFrame = z.object({
|
|
128
|
+
id: FrameRequestId,
|
|
129
|
+
type: z.literal("pong"),
|
|
130
|
+
timestamp: z.iso.datetime()
|
|
131
|
+
});
|
|
132
|
+
const WebsocketFrame = z.discriminatedUnion("type", [
|
|
133
|
+
WebsocketWelcomeFrame,
|
|
134
|
+
WebsocketAckFrame,
|
|
135
|
+
WebsocketErrorFrame,
|
|
136
|
+
WebsocketEventFrame,
|
|
137
|
+
WebsocketPongFrame
|
|
138
|
+
]);
|
|
139
|
+
|
|
140
|
+
export { WebsocketAckFrame, WebsocketErrorCode, WebsocketErrorFrame, WebsocketEventFrame, WebsocketFrame, WebsocketPongFrame, WebsocketRequestErrorCode, WebsocketVaultErrorCode, WebsocketWelcomeFrame };
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { EthereumAddress } from '../common/address';
|
|
3
|
+
/** Most vaults one socket may watch per vault channel (vault_events, vault_management). */
|
|
4
|
+
export declare const MAX_VAULTS_PER_CONNECTION = 20;
|
|
5
|
+
/** Client correlation id: a string or number, echoed back as a string on the matching ack or error. */
|
|
6
|
+
export declare const WebsocketRequestId: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
7
|
+
export declare const WebsocketPublicParams: z.ZodObject<{
|
|
8
|
+
connectors: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
9
|
+
hyperliquid: "hyperliquid";
|
|
10
|
+
binance: "binance";
|
|
11
|
+
bybit: "bybit";
|
|
12
|
+
okx: "okx";
|
|
13
|
+
lighter: "lighter";
|
|
14
|
+
lighter_rhc: "lighter_rhc";
|
|
15
|
+
}>>>;
|
|
16
|
+
instrumentIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
17
|
+
}, z.core.$strict>;
|
|
18
|
+
export type WebsocketPublicParams = z.output<typeof WebsocketPublicParams>;
|
|
19
|
+
export declare const WebsocketUserEventsParams: z.ZodObject<{
|
|
20
|
+
topics: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
21
|
+
"execution.failed": "execution.failed";
|
|
22
|
+
"execution.completed": "execution.completed";
|
|
23
|
+
"position.created": "position.created";
|
|
24
|
+
"position.updated": "position.updated";
|
|
25
|
+
"position.closed": "position.closed";
|
|
26
|
+
"schedule.created": "schedule.created";
|
|
27
|
+
"schedule.completed": "schedule.completed";
|
|
28
|
+
"schedule.failed": "schedule.failed";
|
|
29
|
+
"schedule.cancelled": "schedule.cancelled";
|
|
30
|
+
"ladder.created": "ladder.created";
|
|
31
|
+
"ladder.updated": "ladder.updated";
|
|
32
|
+
"ladder.cancelled": "ladder.cancelled";
|
|
33
|
+
"trigger.created": "trigger.created";
|
|
34
|
+
"trigger.triggered": "trigger.triggered";
|
|
35
|
+
"trigger.cancelled": "trigger.cancelled";
|
|
36
|
+
"trigger.converted": "trigger.converted";
|
|
37
|
+
"rebalance.created": "rebalance.created";
|
|
38
|
+
"rebalance.updated": "rebalance.updated";
|
|
39
|
+
"rebalance.executed": "rebalance.executed";
|
|
40
|
+
"rebalance.paused": "rebalance.paused";
|
|
41
|
+
"rebalance.cancelled": "rebalance.cancelled";
|
|
42
|
+
"notification.created": "notification.created";
|
|
43
|
+
}>>>;
|
|
44
|
+
}, z.core.$strict>;
|
|
45
|
+
export type WebsocketUserEventsParams = z.output<typeof WebsocketUserEventsParams>;
|
|
46
|
+
export declare const WebsocketTriggerEventsParams: z.ZodObject<{
|
|
47
|
+
connectors: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
48
|
+
hyperliquid: "hyperliquid";
|
|
49
|
+
binance: "binance";
|
|
50
|
+
bybit: "bybit";
|
|
51
|
+
okx: "okx";
|
|
52
|
+
lighter: "lighter";
|
|
53
|
+
lighter_rhc: "lighter_rhc";
|
|
54
|
+
}>>>;
|
|
55
|
+
accountIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
export type WebsocketTriggerEventsParams = z.output<typeof WebsocketTriggerEventsParams>;
|
|
58
|
+
/** Public vault invalidations are addressed by lowercased vault contract address. */
|
|
59
|
+
export declare const WebsocketVaultEventsParams: z.ZodObject<{
|
|
60
|
+
vaults: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<EthereumAddress, string>>>;
|
|
61
|
+
}, z.core.$strict>;
|
|
62
|
+
export type WebsocketVaultEventsParams = z.output<typeof WebsocketVaultEventsParams>;
|
|
63
|
+
/** Every frame a client may send to the realtime websocket. */
|
|
64
|
+
export declare const WebsocketControlMessage: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
65
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
66
|
+
method: z.ZodLiteral<"auth">;
|
|
67
|
+
params: z.ZodObject<{
|
|
68
|
+
accessToken: z.ZodString;
|
|
69
|
+
}, z.core.$strict>;
|
|
70
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
71
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
72
|
+
method: z.ZodLiteral<"ping">;
|
|
73
|
+
}, z.core.$strip>, z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
74
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
75
|
+
method: z.ZodLiteral<"subscribe">;
|
|
76
|
+
channel: z.ZodEnum<{
|
|
77
|
+
funding: "funding";
|
|
78
|
+
prices: "prices";
|
|
79
|
+
trades: "trades";
|
|
80
|
+
}>;
|
|
81
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
82
|
+
connectors: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
83
|
+
hyperliquid: "hyperliquid";
|
|
84
|
+
binance: "binance";
|
|
85
|
+
bybit: "bybit";
|
|
86
|
+
okx: "okx";
|
|
87
|
+
lighter: "lighter";
|
|
88
|
+
lighter_rhc: "lighter_rhc";
|
|
89
|
+
}>>>;
|
|
90
|
+
instrumentIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
91
|
+
}, z.core.$strict>>;
|
|
92
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
93
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
94
|
+
method: z.ZodLiteral<"subscribe">;
|
|
95
|
+
channel: z.ZodLiteral<"user_events">;
|
|
96
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
97
|
+
topics: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
98
|
+
"execution.failed": "execution.failed";
|
|
99
|
+
"execution.completed": "execution.completed";
|
|
100
|
+
"position.created": "position.created";
|
|
101
|
+
"position.updated": "position.updated";
|
|
102
|
+
"position.closed": "position.closed";
|
|
103
|
+
"schedule.created": "schedule.created";
|
|
104
|
+
"schedule.completed": "schedule.completed";
|
|
105
|
+
"schedule.failed": "schedule.failed";
|
|
106
|
+
"schedule.cancelled": "schedule.cancelled";
|
|
107
|
+
"ladder.created": "ladder.created";
|
|
108
|
+
"ladder.updated": "ladder.updated";
|
|
109
|
+
"ladder.cancelled": "ladder.cancelled";
|
|
110
|
+
"trigger.created": "trigger.created";
|
|
111
|
+
"trigger.triggered": "trigger.triggered";
|
|
112
|
+
"trigger.cancelled": "trigger.cancelled";
|
|
113
|
+
"trigger.converted": "trigger.converted";
|
|
114
|
+
"rebalance.created": "rebalance.created";
|
|
115
|
+
"rebalance.updated": "rebalance.updated";
|
|
116
|
+
"rebalance.executed": "rebalance.executed";
|
|
117
|
+
"rebalance.paused": "rebalance.paused";
|
|
118
|
+
"rebalance.cancelled": "rebalance.cancelled";
|
|
119
|
+
"notification.created": "notification.created";
|
|
120
|
+
}>>>;
|
|
121
|
+
}, z.core.$strict>>;
|
|
122
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
123
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
124
|
+
method: z.ZodLiteral<"subscribe">;
|
|
125
|
+
channel: z.ZodLiteral<"trigger_events">;
|
|
126
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
127
|
+
connectors: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
128
|
+
hyperliquid: "hyperliquid";
|
|
129
|
+
binance: "binance";
|
|
130
|
+
bybit: "bybit";
|
|
131
|
+
okx: "okx";
|
|
132
|
+
lighter: "lighter";
|
|
133
|
+
lighter_rhc: "lighter_rhc";
|
|
134
|
+
}>>>;
|
|
135
|
+
accountIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
136
|
+
}, z.core.$strict>>;
|
|
137
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
139
|
+
method: z.ZodLiteral<"subscribe">;
|
|
140
|
+
channel: z.ZodLiteral<"vault_events">;
|
|
141
|
+
params: z.ZodObject<{
|
|
142
|
+
vaults: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<EthereumAddress, string>>>;
|
|
143
|
+
}, z.core.$strict>;
|
|
144
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
145
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
146
|
+
method: z.ZodLiteral<"subscribe">;
|
|
147
|
+
channel: z.ZodLiteral<"vault_management">;
|
|
148
|
+
params: z.ZodObject<{
|
|
149
|
+
vaults: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<EthereumAddress, string>>>;
|
|
150
|
+
}, z.core.$strict>;
|
|
151
|
+
}, z.core.$strip>], "channel">, z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
152
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
153
|
+
method: z.ZodLiteral<"unsubscribe">;
|
|
154
|
+
channel: z.ZodEnum<{
|
|
155
|
+
funding: "funding";
|
|
156
|
+
prices: "prices";
|
|
157
|
+
trades: "trades";
|
|
158
|
+
}>;
|
|
159
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
160
|
+
connectors: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
161
|
+
hyperliquid: "hyperliquid";
|
|
162
|
+
binance: "binance";
|
|
163
|
+
bybit: "bybit";
|
|
164
|
+
okx: "okx";
|
|
165
|
+
lighter: "lighter";
|
|
166
|
+
lighter_rhc: "lighter_rhc";
|
|
167
|
+
}>>>;
|
|
168
|
+
instrumentIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
169
|
+
}, z.core.$strict>>;
|
|
170
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
171
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
172
|
+
method: z.ZodLiteral<"unsubscribe">;
|
|
173
|
+
channel: z.ZodLiteral<"user_events">;
|
|
174
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
175
|
+
topics: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
176
|
+
"execution.failed": "execution.failed";
|
|
177
|
+
"execution.completed": "execution.completed";
|
|
178
|
+
"position.created": "position.created";
|
|
179
|
+
"position.updated": "position.updated";
|
|
180
|
+
"position.closed": "position.closed";
|
|
181
|
+
"schedule.created": "schedule.created";
|
|
182
|
+
"schedule.completed": "schedule.completed";
|
|
183
|
+
"schedule.failed": "schedule.failed";
|
|
184
|
+
"schedule.cancelled": "schedule.cancelled";
|
|
185
|
+
"ladder.created": "ladder.created";
|
|
186
|
+
"ladder.updated": "ladder.updated";
|
|
187
|
+
"ladder.cancelled": "ladder.cancelled";
|
|
188
|
+
"trigger.created": "trigger.created";
|
|
189
|
+
"trigger.triggered": "trigger.triggered";
|
|
190
|
+
"trigger.cancelled": "trigger.cancelled";
|
|
191
|
+
"trigger.converted": "trigger.converted";
|
|
192
|
+
"rebalance.created": "rebalance.created";
|
|
193
|
+
"rebalance.updated": "rebalance.updated";
|
|
194
|
+
"rebalance.executed": "rebalance.executed";
|
|
195
|
+
"rebalance.paused": "rebalance.paused";
|
|
196
|
+
"rebalance.cancelled": "rebalance.cancelled";
|
|
197
|
+
"notification.created": "notification.created";
|
|
198
|
+
}>>>;
|
|
199
|
+
}, z.core.$strict>>;
|
|
200
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
201
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
202
|
+
method: z.ZodLiteral<"unsubscribe">;
|
|
203
|
+
channel: z.ZodLiteral<"trigger_events">;
|
|
204
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
205
|
+
connectors: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
206
|
+
hyperliquid: "hyperliquid";
|
|
207
|
+
binance: "binance";
|
|
208
|
+
bybit: "bybit";
|
|
209
|
+
okx: "okx";
|
|
210
|
+
lighter: "lighter";
|
|
211
|
+
lighter_rhc: "lighter_rhc";
|
|
212
|
+
}>>>;
|
|
213
|
+
accountIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
214
|
+
}, z.core.$strict>>;
|
|
215
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
216
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
217
|
+
method: z.ZodLiteral<"unsubscribe">;
|
|
218
|
+
channel: z.ZodLiteral<"vault_events">;
|
|
219
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
220
|
+
vaults: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<EthereumAddress, string>>>;
|
|
221
|
+
}, z.core.$strict>>;
|
|
222
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
223
|
+
id: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>;
|
|
224
|
+
method: z.ZodLiteral<"unsubscribe">;
|
|
225
|
+
channel: z.ZodLiteral<"vault_management">;
|
|
226
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
227
|
+
vaults: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<EthereumAddress, string>>>;
|
|
228
|
+
}, z.core.$strict>>;
|
|
229
|
+
}, z.core.$strip>], "channel">], "method">;
|
|
230
|
+
export type WebsocketControlMessage = z.output<typeof WebsocketControlMessage>;
|
|
231
|
+
export type WebsocketControlMessageInput = z.input<typeof WebsocketControlMessage>;
|
|
232
|
+
export type WebsocketAuthMessage = Extract<WebsocketControlMessage, {
|
|
233
|
+
method: 'auth';
|
|
234
|
+
}>;
|
|
235
|
+
export type WebsocketPingMessage = Extract<WebsocketControlMessage, {
|
|
236
|
+
method: 'ping';
|
|
237
|
+
}>;
|
|
238
|
+
export type WebsocketSubscribeMessage = Extract<WebsocketControlMessage, {
|
|
239
|
+
method: 'subscribe';
|
|
240
|
+
}>;
|
|
241
|
+
export type WebsocketUnsubscribeMessage = Extract<WebsocketControlMessage, {
|
|
242
|
+
method: 'unsubscribe';
|
|
243
|
+
}>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { EthereumAddress } from '../common/address';
|
|
3
|
+
import { Connector } from '../connector';
|
|
4
|
+
import { WebsocketPublicChannel } from './channels';
|
|
5
|
+
import { UserEventTopic } from './user-events';
|
|
6
|
+
|
|
7
|
+
const MAX_VAULTS_PER_CONNECTION = 20;
|
|
8
|
+
const WebsocketRequestId = z.union([
|
|
9
|
+
z.string(),
|
|
10
|
+
z.number()
|
|
11
|
+
]).transform(String).optional();
|
|
12
|
+
const WebsocketPublicParams = z.object({
|
|
13
|
+
connectors: z.array(Connector).optional(),
|
|
14
|
+
instrumentIds: z.array(z.string()).optional()
|
|
15
|
+
}).strict();
|
|
16
|
+
const WebsocketUserEventsParams = z.object({
|
|
17
|
+
topics: z.array(UserEventTopic).optional()
|
|
18
|
+
}).strict();
|
|
19
|
+
const WebsocketTriggerEventsParams = z.object({
|
|
20
|
+
connectors: z.array(Connector).optional(),
|
|
21
|
+
accountIds: z.array(z.string()).optional()
|
|
22
|
+
}).strict();
|
|
23
|
+
const WebsocketVaultEventsParams = z.object({
|
|
24
|
+
vaults: z.array(EthereumAddress).min(1)
|
|
25
|
+
}).strict();
|
|
26
|
+
const PingMessage = z.object({
|
|
27
|
+
id: WebsocketRequestId,
|
|
28
|
+
method: z.literal("ping")
|
|
29
|
+
});
|
|
30
|
+
const AuthMessage = z.object({
|
|
31
|
+
id: WebsocketRequestId,
|
|
32
|
+
method: z.literal("auth"),
|
|
33
|
+
params: z.object({
|
|
34
|
+
accessToken: z.string().min(1)
|
|
35
|
+
}).strict()
|
|
36
|
+
});
|
|
37
|
+
const SubscribePublicMessage = z.object({
|
|
38
|
+
id: WebsocketRequestId,
|
|
39
|
+
method: z.literal("subscribe"),
|
|
40
|
+
channel: WebsocketPublicChannel,
|
|
41
|
+
params: WebsocketPublicParams.optional()
|
|
42
|
+
});
|
|
43
|
+
const SubscribeUserEventsMessage = z.object({
|
|
44
|
+
id: WebsocketRequestId,
|
|
45
|
+
method: z.literal("subscribe"),
|
|
46
|
+
channel: z.literal("user_events"),
|
|
47
|
+
params: WebsocketUserEventsParams.optional()
|
|
48
|
+
});
|
|
49
|
+
const SubscribeTriggerEventsMessage = z.object({
|
|
50
|
+
id: WebsocketRequestId,
|
|
51
|
+
method: z.literal("subscribe"),
|
|
52
|
+
channel: z.literal("trigger_events"),
|
|
53
|
+
params: WebsocketTriggerEventsParams.optional()
|
|
54
|
+
});
|
|
55
|
+
const SubscribeVaultEventsMessage = z.object({
|
|
56
|
+
id: WebsocketRequestId,
|
|
57
|
+
method: z.literal("subscribe"),
|
|
58
|
+
channel: z.literal("vault_events"),
|
|
59
|
+
params: WebsocketVaultEventsParams
|
|
60
|
+
});
|
|
61
|
+
const SubscribeVaultManagementMessage = z.object({
|
|
62
|
+
id: WebsocketRequestId,
|
|
63
|
+
method: z.literal("subscribe"),
|
|
64
|
+
channel: z.literal("vault_management"),
|
|
65
|
+
params: WebsocketVaultEventsParams
|
|
66
|
+
});
|
|
67
|
+
const UnsubscribePublicMessage = z.object({
|
|
68
|
+
id: WebsocketRequestId,
|
|
69
|
+
method: z.literal("unsubscribe"),
|
|
70
|
+
channel: WebsocketPublicChannel,
|
|
71
|
+
params: WebsocketPublicParams.optional()
|
|
72
|
+
});
|
|
73
|
+
const UnsubscribeUserEventsMessage = z.object({
|
|
74
|
+
id: WebsocketRequestId,
|
|
75
|
+
method: z.literal("unsubscribe"),
|
|
76
|
+
channel: z.literal("user_events"),
|
|
77
|
+
params: WebsocketUserEventsParams.optional()
|
|
78
|
+
});
|
|
79
|
+
const UnsubscribeTriggerEventsMessage = z.object({
|
|
80
|
+
id: WebsocketRequestId,
|
|
81
|
+
method: z.literal("unsubscribe"),
|
|
82
|
+
channel: z.literal("trigger_events"),
|
|
83
|
+
params: WebsocketTriggerEventsParams.optional()
|
|
84
|
+
});
|
|
85
|
+
const UnsubscribeVaultEventsMessage = z.object({
|
|
86
|
+
id: WebsocketRequestId,
|
|
87
|
+
method: z.literal("unsubscribe"),
|
|
88
|
+
channel: z.literal("vault_events"),
|
|
89
|
+
params: WebsocketVaultEventsParams.optional()
|
|
90
|
+
});
|
|
91
|
+
const UnsubscribeVaultManagementMessage = z.object({
|
|
92
|
+
id: WebsocketRequestId,
|
|
93
|
+
method: z.literal("unsubscribe"),
|
|
94
|
+
channel: z.literal("vault_management"),
|
|
95
|
+
params: WebsocketVaultEventsParams.optional()
|
|
96
|
+
});
|
|
97
|
+
const SubscribeMessage = z.discriminatedUnion("channel", [
|
|
98
|
+
SubscribePublicMessage,
|
|
99
|
+
SubscribeUserEventsMessage,
|
|
100
|
+
SubscribeTriggerEventsMessage,
|
|
101
|
+
SubscribeVaultEventsMessage,
|
|
102
|
+
SubscribeVaultManagementMessage
|
|
103
|
+
]);
|
|
104
|
+
const UnsubscribeMessage = z.discriminatedUnion("channel", [
|
|
105
|
+
UnsubscribePublicMessage,
|
|
106
|
+
UnsubscribeUserEventsMessage,
|
|
107
|
+
UnsubscribeTriggerEventsMessage,
|
|
108
|
+
UnsubscribeVaultEventsMessage,
|
|
109
|
+
UnsubscribeVaultManagementMessage
|
|
110
|
+
]);
|
|
111
|
+
const WebsocketControlMessage = z.discriminatedUnion("method", [
|
|
112
|
+
AuthMessage,
|
|
113
|
+
PingMessage,
|
|
114
|
+
SubscribeMessage,
|
|
115
|
+
UnsubscribeMessage
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
export { MAX_VAULTS_PER_CONNECTION, WebsocketControlMessage, WebsocketPublicParams, WebsocketRequestId, WebsocketTriggerEventsParams, WebsocketUserEventsParams, WebsocketVaultEventsParams };
|