@dydxprotocol/v4-client-js 1.1.12 → 1.1.14
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/.eslintrc.js +3 -5
- package/.prettierignore +3 -0
- package/.prettierrc.json +6 -0
- package/.telescope.json +2 -4
- package/.vscode/launch.json +10 -10
- package/README.md +3 -1
- package/__native__/__ios__/v4-native-client.js +2648 -806
- package/__tests__/helpers/constants.ts +10 -8
- package/__tests__/lib/helpers.test.ts +22 -23
- package/__tests__/lib/util.test.ts +2 -8
- package/__tests__/lib/validation.test.ts +23 -26
- package/__tests__/modules/client/Transfers.test.ts +4 -19
- package/__tests__/modules/client/ValidatorPostEndpoints.test.ts +2 -5
- package/__tests__/modules/client/constants.ts +4 -2
- package/__tests__/modules/onboarding.test.ts +9 -7
- package/build/__tests__/helpers/constants.js +7 -7
- package/build/__tests__/lib/helpers.test.js +2 -6
- package/build/__tests__/lib/util.test.js +1 -1
- package/build/__tests__/lib/validation.test.js +3 -11
- package/build/__tests__/modules/client/Transfers.test.js +1 -1
- package/build/__tests__/modules/client/ValidatorPostEndpoints.test.js +2 -2
- package/build/__tests__/modules/client/constants.js +1 -1
- package/build/__tests__/modules/onboarding.test.js +2 -3
- package/build/examples/account_endpoints.js +4 -3
- package/build/examples/composite_example.js +5 -4
- package/build/examples/constants.js +1 -1
- package/build/examples/faucet_endpoint.js +4 -3
- package/build/examples/long_term_order_cancel_example.js +4 -3
- package/build/examples/markets_endpoints.js +4 -3
- package/build/examples/native_examples.js +4 -3
- package/build/examples/noble_example.js +1 -1
- package/build/examples/optimal_node.js +4 -12
- package/build/examples/short_term_order_cancel_example.js +4 -3
- package/build/examples/short_term_order_composite_example.js +4 -3
- package/build/examples/test.js +5 -4
- package/build/examples/transfer_example_deposit.js +4 -3
- package/build/examples/transfer_example_send.js +1 -1
- package/build/examples/transfer_example_subaccount_transfer.js +4 -3
- package/build/examples/transfer_example_withdraw.js +4 -3
- package/build/examples/transfer_example_withdraw_other.js +1 -1
- package/build/examples/utility_endpoints.js +4 -3
- package/build/examples/validator_get_example.js +15 -9
- package/build/examples/validator_post_example.js +4 -3
- package/build/examples/wallet_address.js +5 -4
- package/build/examples/websocket_example.js +1 -1
- package/build/src/clients/composite-client.d.ts +225 -224
- package/build/src/clients/composite-client.js +242 -237
- package/build/src/clients/constants.d.ts +3 -0
- package/build/src/clients/constants.js +6 -2
- package/build/src/clients/faucet-client.d.ts +4 -4
- package/build/src/clients/faucet-client.js +5 -5
- package/build/src/clients/helpers/chain-helpers.js +1 -1
- package/build/src/clients/helpers/request-helpers.js +5 -4
- package/build/src/clients/indexer-client.js +1 -1
- package/build/src/clients/lib/axios/axiosRequest.js +1 -1
- package/build/src/clients/lib/axios/errors.js +1 -1
- package/build/src/clients/lib/cctpProto.d.ts +2 -2
- package/build/src/clients/lib/cctpProto.js +287 -237
- package/build/src/clients/lib/errors.js +1 -1
- package/build/src/clients/modules/account.js +1 -1
- package/build/src/clients/modules/composer.d.ts +4 -0
- package/build/src/clients/modules/composer.js +39 -3
- package/build/src/clients/modules/get.d.ts +10 -3
- package/build/src/clients/modules/get.js +41 -54
- package/build/src/clients/modules/local-wallet.js +1 -1
- package/build/src/clients/modules/post.d.ts +3 -0
- package/build/src/clients/modules/post.js +34 -18
- package/build/src/clients/modules/proto-includes.d.ts +1 -0
- package/build/src/clients/modules/proto-includes.js +3 -2
- package/build/src/clients/modules/rest.js +1 -1
- package/build/src/clients/modules/signer.js +1 -1
- package/build/src/clients/modules/tendermintClient.d.ts +5 -5
- package/build/src/clients/modules/tendermintClient.js +6 -6
- package/build/src/clients/native.js +4 -7
- package/build/src/clients/noble-client.js +1 -1
- package/build/src/clients/socket-client.js +1 -1
- package/build/src/clients/subaccount.js +1 -1
- package/build/src/clients/types.d.ts +1 -1
- package/build/src/clients/types.js +1 -1
- package/build/src/clients/validator-client.d.ts +12 -12
- package/build/src/clients/validator-client.js +13 -13
- package/build/src/lib/errors.js +1 -1
- package/build/src/lib/onboarding.js +1 -1
- package/build/src/lib/utils.js +3 -3
- package/build/src/lib/validation.js +5 -4
- package/build/src/network_optimizer.js +10 -11
- package/build/src/types.d.ts +1 -1
- package/build/src/types.js +1 -1
- package/examples/account_endpoints.ts +5 -4
- package/examples/composite_example.ts +12 -7
- package/examples/constants.ts +10 -4
- package/examples/faucet_endpoint.ts +5 -4
- package/examples/human_readable_orders.json +85 -85
- package/examples/human_readable_short_term_orders.json +41 -41
- package/examples/long_term_order_cancel_example.ts +11 -6
- package/examples/markets_endpoints.ts +5 -4
- package/examples/native_examples.ts +8 -7
- package/examples/noble_example.ts +11 -23
- package/examples/optimal_node.ts +4 -14
- package/examples/raw_orders.json +128 -128
- package/examples/short_term_order_cancel_example.ts +7 -8
- package/examples/short_term_order_composite_example.ts +7 -8
- package/examples/test.ts +12 -7
- package/examples/transfer_example_deposit.ts +6 -9
- package/examples/transfer_example_send.ts +2 -10
- package/examples/transfer_example_subaccount_transfer.ts +6 -11
- package/examples/transfer_example_withdraw.ts +6 -9
- package/examples/transfer_example_withdraw_other.ts +1 -5
- package/examples/utility_endpoints.ts +5 -4
- package/examples/validator_get_example.ts +19 -10
- package/examples/validator_post_example.ts +7 -9
- package/examples/wallet_address.ts +6 -5
- package/examples/websocket_example.ts +5 -1
- package/package.json +4 -1
- package/src/clients/composite-client.ts +279 -330
- package/src/clients/constants.ts +38 -26
- package/src/clients/faucet-client.ts +5 -8
- package/src/clients/helpers/chain-helpers.ts +10 -6
- package/src/clients/helpers/request-helpers.ts +6 -5
- package/src/clients/indexer-client.ts +34 -34
- package/src/clients/lib/axios/axiosRequest.ts +4 -7
- package/src/clients/lib/axios/errors.ts +16 -21
- package/src/clients/lib/cctpProto.ts +655 -387
- package/src/clients/lib/errors.ts +8 -17
- package/src/clients/modules/account.ts +4 -12
- package/src/clients/modules/composer.ts +61 -20
- package/src/clients/modules/get.ts +71 -89
- package/src/clients/modules/local-wallet.ts +41 -56
- package/src/clients/modules/post.ts +664 -634
- package/src/clients/modules/proto-includes.ts +1 -0
- package/src/clients/modules/rest.ts +23 -26
- package/src/clients/modules/signer.ts +8 -22
- package/src/clients/modules/tendermintClient.ts +13 -36
- package/src/clients/native.ts +73 -139
- package/src/clients/noble-client.ts +1 -5
- package/src/clients/socket-client.ts +216 -216
- package/src/clients/subaccount.ts +16 -16
- package/src/clients/types.ts +14 -10
- package/src/clients/validator-client.ts +14 -16
- package/src/codegen/helpers.ts +149 -150
- package/src/codegen/index.ts +4 -5
- package/src/lib/errors.ts +3 -9
- package/src/lib/onboarding.ts +7 -2
- package/src/lib/utils.ts +5 -12
- package/src/lib/validation.ts +21 -19
- package/src/network_optimizer.ts +78 -65
- package/src/types.ts +5 -6
- package/tasks.json +15 -15
- package/tsconfig.eslint.json +1 -4
- package/tsconfig.json +2 -6
|
@@ -35,246 +35,246 @@ export enum CandlesResolution {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export class SocketClient {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
private url: string;
|
|
39
|
+
private ws?: WebSocket;
|
|
40
|
+
private onOpenCallback?: () => void;
|
|
41
|
+
private onCloseCallback?: () => void;
|
|
42
|
+
private onMessageCallback?: (event: MessageEvent) => void;
|
|
43
|
+
private lastMessageTime: number = Date.now();
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
constructor(
|
|
46
|
+
config: IndexerConfig,
|
|
47
|
+
onOpenCallback: () => void,
|
|
48
|
+
onCloseCallback: () => void,
|
|
49
|
+
onMessageCallback: (event: MessageEvent) => void,
|
|
50
|
+
) {
|
|
51
|
+
this.url = config.websocketEndpoint;
|
|
52
|
+
this.onOpenCallback = onOpenCallback;
|
|
53
|
+
this.onCloseCallback = onCloseCallback;
|
|
54
|
+
this.onMessageCallback = onMessageCallback;
|
|
55
|
+
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
connect(): void {
|
|
58
|
+
this.ws = new WebSocket(this.url);
|
|
59
|
+
this.ws.addEventListener('open', this.handleOpen.bind(this));
|
|
60
|
+
this.ws.addEventListener('close', this.handleClose.bind(this));
|
|
61
|
+
this.ws.addEventListener('message', this.handleMessage.bind(this));
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
/**
|
|
65
|
+
* @description Close the websocket connection.
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
close(): void {
|
|
69
|
+
this.ws?.close();
|
|
70
|
+
this.ws = undefined;
|
|
71
|
+
}
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @description Send data to the websocket connection.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
send(data: string): void {
|
|
78
|
+
this.ws?.send(data);
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
81
|
+
private handleOpen(): void {
|
|
82
|
+
if (this.onOpenCallback) {
|
|
83
|
+
this.onOpenCallback();
|
|
85
84
|
}
|
|
85
|
+
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
87
|
+
private handleClose(): void {
|
|
88
|
+
if (this.onCloseCallback) {
|
|
89
|
+
this.onCloseCallback();
|
|
91
90
|
}
|
|
91
|
+
}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
93
|
+
private handleMessage(event: MessageEvent): void {
|
|
94
|
+
if (event.data === 'PING') {
|
|
95
|
+
this.send('PONG');
|
|
96
|
+
} else {
|
|
97
|
+
this.lastMessageTime = Date.now();
|
|
98
|
+
if (this.onMessageCallback) {
|
|
99
|
+
this.onMessageCallback(event);
|
|
101
100
|
}
|
|
102
101
|
}
|
|
102
|
+
}
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
/**
|
|
105
|
+
* @description Set callback when the socket is opened.
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
set onOpen(callback: () => void) {
|
|
109
|
+
this.onOpenCallback = callback;
|
|
110
|
+
}
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
/**
|
|
113
|
+
* @description Set callback when the socket is closed.
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
set onClose(callback: () => void) {
|
|
117
|
+
this.onCloseCallback = callback;
|
|
118
|
+
}
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
/**
|
|
121
|
+
* @description Set callback when the socket receives a message.
|
|
122
|
+
*
|
|
123
|
+
*/
|
|
124
|
+
set onMessage(callback: (event: MessageEvent) => void) {
|
|
125
|
+
this.onMessageCallback = callback;
|
|
126
|
+
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
/**
|
|
129
|
+
* @description Send a subscribe message to the websocket connection.
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
subscribe(channel: string, params?: object): void {
|
|
133
|
+
const message = {
|
|
134
|
+
type: OutgoingMessageTypes.SUBSCRIBE,
|
|
135
|
+
channel,
|
|
136
|
+
...params,
|
|
137
|
+
};
|
|
138
|
+
this.send(JSON.stringify(message));
|
|
139
|
+
}
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
141
|
+
/**
|
|
142
|
+
* @description Send an unsubscribe message to the websocket connection.
|
|
143
|
+
*
|
|
144
|
+
*/
|
|
145
|
+
unsubscribe(channel: string, params?: object): void {
|
|
146
|
+
const message = {
|
|
147
|
+
type: OutgoingMessageTypes.UNSUBSCRIBE,
|
|
148
|
+
channel,
|
|
149
|
+
...params,
|
|
150
|
+
};
|
|
151
|
+
this.send(JSON.stringify(message));
|
|
152
|
+
}
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
154
|
+
/**
|
|
155
|
+
* @description Subscribe to markets channel.
|
|
156
|
+
*
|
|
157
|
+
*/
|
|
158
|
+
subscribeToMarkets(): void {
|
|
159
|
+
const channel = SocketChannels.MARKETS;
|
|
160
|
+
const params = {
|
|
161
|
+
batched: true,
|
|
162
|
+
};
|
|
163
|
+
this.subscribe(channel, params);
|
|
164
|
+
}
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
166
|
+
/**
|
|
167
|
+
* @description Unsubscribe from markets channel
|
|
168
|
+
*
|
|
169
|
+
*/
|
|
170
|
+
unsubscribeFromMarkets(): void {
|
|
171
|
+
const channel = SocketChannels.MARKETS;
|
|
172
|
+
this.unsubscribe(channel);
|
|
173
|
+
}
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
175
|
+
/**
|
|
176
|
+
* @description Subscribe to trade channel
|
|
177
|
+
* for a specific market.
|
|
178
|
+
*
|
|
179
|
+
*/
|
|
180
|
+
subscribeToTrades(market: string): void {
|
|
181
|
+
const channel = SocketChannels.TRADES;
|
|
182
|
+
const params = {
|
|
183
|
+
id: market,
|
|
184
|
+
batched: true,
|
|
185
|
+
};
|
|
186
|
+
this.subscribe(channel, params);
|
|
187
|
+
}
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
189
|
+
/**
|
|
190
|
+
* @description Unscribed from trade channel
|
|
191
|
+
* for a specific market.
|
|
192
|
+
*
|
|
193
|
+
*/
|
|
194
|
+
unsubscribeFromTrades(market: string): void {
|
|
195
|
+
const channel = SocketChannels.TRADES;
|
|
196
|
+
const params = {
|
|
197
|
+
id: market,
|
|
198
|
+
};
|
|
199
|
+
this.unsubscribe(channel, params);
|
|
200
|
+
}
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
202
|
+
/**
|
|
203
|
+
* @description Subscribe to orderbook channel
|
|
204
|
+
* for a specific market.
|
|
205
|
+
*
|
|
206
|
+
*/
|
|
207
|
+
subscribeToOrderbook(market: string): void {
|
|
208
|
+
const channel = SocketChannels.ORDERBOOK;
|
|
209
|
+
const params = {
|
|
210
|
+
id: market,
|
|
211
|
+
batched: true,
|
|
212
|
+
};
|
|
213
|
+
this.subscribe(channel, params);
|
|
214
|
+
}
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
216
|
+
/**
|
|
217
|
+
* @description Unsubscribe from orderbook channel
|
|
218
|
+
* for a specific market.
|
|
219
|
+
*/
|
|
220
|
+
unsubscribeFromOrderbook(market: string): void {
|
|
221
|
+
const channel = SocketChannels.ORDERBOOK;
|
|
222
|
+
const params = {
|
|
223
|
+
id: market,
|
|
224
|
+
};
|
|
225
|
+
this.unsubscribe(channel, params);
|
|
226
|
+
}
|
|
227
227
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
228
|
+
/**
|
|
229
|
+
* @description Subscribe to candles channel
|
|
230
|
+
* for a specific market and resolution.
|
|
231
|
+
*
|
|
232
|
+
*/
|
|
233
|
+
subscribeToCandles(market: string, resolution: CandlesResolution): void {
|
|
234
|
+
const channel = SocketChannels.CANDLES;
|
|
235
|
+
const params = {
|
|
236
|
+
id: `${market}/${resolution}`,
|
|
237
|
+
batched: true,
|
|
238
|
+
};
|
|
239
|
+
this.subscribe(channel, params);
|
|
240
|
+
}
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
242
|
+
/**
|
|
243
|
+
* @description Unsubscribe from candles channel
|
|
244
|
+
* for a specific market and resolution.
|
|
245
|
+
*/
|
|
246
|
+
unsubscribeFromCandles(market: string, resolution: CandlesResolution): void {
|
|
247
|
+
const channel = SocketChannels.CANDLES;
|
|
248
|
+
const params = {
|
|
249
|
+
id: `${market}/${resolution}`,
|
|
250
|
+
};
|
|
251
|
+
this.unsubscribe(channel, params);
|
|
252
|
+
}
|
|
253
253
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
254
|
+
/**
|
|
255
|
+
* @description Subscribe to subaccount channel
|
|
256
|
+
* for a specific address and subaccount number.
|
|
257
|
+
*/
|
|
258
|
+
subscribeToSubaccount(address: string, subaccountNumber: number): void {
|
|
259
|
+
const channel = SocketChannels.SUBACCOUNTS;
|
|
260
|
+
const subaccountId = `${address}/${subaccountNumber}`;
|
|
261
|
+
const params = {
|
|
262
|
+
id: subaccountId,
|
|
263
|
+
};
|
|
264
|
+
this.subscribe(channel, params);
|
|
265
|
+
}
|
|
266
266
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
267
|
+
/**
|
|
268
|
+
* @description Unsubscribe from subaccount channel
|
|
269
|
+
* for a specific address and subaccount number.
|
|
270
|
+
*
|
|
271
|
+
*/
|
|
272
|
+
unsubscribeFromSubaccount(address: string, subaccountNumber: number): void {
|
|
273
|
+
const channel = SocketChannels.SUBACCOUNTS;
|
|
274
|
+
const subaccountId = `${address}/${subaccountNumber}`;
|
|
275
|
+
const params = {
|
|
276
|
+
id: subaccountId,
|
|
277
|
+
};
|
|
278
|
+
this.unsubscribe(channel, params);
|
|
279
|
+
}
|
|
280
280
|
}
|
|
@@ -2,24 +2,24 @@ import { MAX_SUBACCOUNT_NUMBER } from './constants';
|
|
|
2
2
|
import LocalWallet from './modules/local-wallet';
|
|
3
3
|
|
|
4
4
|
export class SubaccountInfo {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
readonly wallet: LocalWallet;
|
|
6
|
+
// TODO, change address to Wallet object when implementing validator functions
|
|
7
|
+
readonly subaccountNumber: number;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
this.wallet = wallet;
|
|
14
|
-
this.subaccountNumber = subaccountNumber;
|
|
9
|
+
constructor(wallet: LocalWallet, subaccountNumber: number = 0) {
|
|
10
|
+
if (subaccountNumber < 0 || subaccountNumber > MAX_SUBACCOUNT_NUMBER) {
|
|
11
|
+
throw new Error(`Subaccount number must be between 0 and ${MAX_SUBACCOUNT_NUMBER}`);
|
|
15
12
|
}
|
|
13
|
+
this.wallet = wallet;
|
|
14
|
+
this.subaccountNumber = subaccountNumber;
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
17
|
+
get address(): string {
|
|
18
|
+
const address = this.wallet.address;
|
|
19
|
+
if (address !== undefined) {
|
|
20
|
+
return address;
|
|
21
|
+
} else {
|
|
22
|
+
throw new Error('Address not set');
|
|
24
23
|
}
|
|
24
|
+
}
|
|
25
25
|
}
|
package/src/clients/types.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Coin } from '@cosmjs/proto-signing';
|
|
2
2
|
import { Method } from '@cosmjs/tendermint-rpc';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Order_ConditionType,
|
|
5
|
+
Order_Side,
|
|
6
|
+
Order_TimeInForce,
|
|
7
|
+
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order';
|
|
4
8
|
import { PerpetualMarketType } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/perpetual';
|
|
5
9
|
import BigNumber from 'bignumber.js';
|
|
6
10
|
import Long from 'long';
|
|
@@ -36,7 +40,7 @@ export enum OrderFlags {
|
|
|
36
40
|
|
|
37
41
|
export interface IBasicOrder {
|
|
38
42
|
clientId: number;
|
|
39
|
-
orderFlags: OrderFlags
|
|
43
|
+
orderFlags: OrderFlags;
|
|
40
44
|
clobPairId: number;
|
|
41
45
|
goodTilBlock?: number;
|
|
42
46
|
goodTilBlockTime?: number;
|
|
@@ -46,15 +50,14 @@ export interface IPlaceOrder extends IBasicOrder {
|
|
|
46
50
|
side: Order_Side;
|
|
47
51
|
quantums: Long;
|
|
48
52
|
subticks: Long;
|
|
49
|
-
timeInForce: Order_TimeInForce
|
|
53
|
+
timeInForce: Order_TimeInForce;
|
|
50
54
|
reduceOnly: boolean;
|
|
51
55
|
clientMetadata: number;
|
|
52
|
-
conditionType?: Order_ConditionType
|
|
53
|
-
conditionalOrderTriggerSubticks?: Long
|
|
56
|
+
conditionType?: Order_ConditionType;
|
|
57
|
+
conditionalOrderTriggerSubticks?: Long;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
export interface ICancelOrder extends IBasicOrder {
|
|
57
|
-
}
|
|
60
|
+
export interface ICancelOrder extends IBasicOrder {}
|
|
58
61
|
|
|
59
62
|
// How long to wait and how often to check when calling Broadcast with
|
|
60
63
|
// Method.BroadcastTxCommit
|
|
@@ -78,9 +81,10 @@ export interface DenomConfig {
|
|
|
78
81
|
// 2. Once the transaction is added to the memPool
|
|
79
82
|
// 3. Once the transaction is committed to a block
|
|
80
83
|
// See https://docs.cosmos.network/master/run-node/txs.html for more information
|
|
81
|
-
export type BroadcastMode =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
export type BroadcastMode =
|
|
85
|
+
| Method.BroadcastTxAsync
|
|
86
|
+
| Method.BroadcastTxSync
|
|
87
|
+
| Method.BroadcastTxCommit;
|
|
84
88
|
|
|
85
89
|
// ------ Utility Endpoint Responses ------ //
|
|
86
90
|
export interface TimeResponse {
|
|
@@ -26,36 +26,34 @@ export class ValidatorClient {
|
|
|
26
26
|
private _post?: Post;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
* @description Connect to a validator client
|
|
30
|
+
*
|
|
31
|
+
* @returns The validator client
|
|
32
|
+
*/
|
|
33
33
|
static async connect(config: ValidatorConfig): Promise<ValidatorClient> {
|
|
34
34
|
const client = new ValidatorClient(config);
|
|
35
35
|
await client.initialize();
|
|
36
36
|
return client;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
private constructor(
|
|
40
|
-
config: ValidatorConfig,
|
|
41
|
-
) {
|
|
39
|
+
private constructor(config: ValidatorConfig) {
|
|
42
40
|
this.config = config;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
* @description Get the query module, used for retrieving on-chain data.
|
|
45
|
+
*
|
|
46
|
+
* @returns The query module
|
|
47
|
+
*/
|
|
50
48
|
get get(): Get {
|
|
51
49
|
return this._get!;
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
* @description transaction module, used for sending transactions.
|
|
54
|
+
*
|
|
55
|
+
* @returns The transaction module
|
|
56
|
+
*/
|
|
59
57
|
get post(): Post {
|
|
60
58
|
return this._post!;
|
|
61
59
|
}
|
|
@@ -80,7 +78,7 @@ export class ValidatorClient {
|
|
|
80
78
|
broadcastPollIntervalMs: BROADCAST_POLL_INTERVAL_MS,
|
|
81
79
|
broadcastTimeoutMs: BROADCAST_TIMEOUT_MS,
|
|
82
80
|
});
|
|
83
|
-
const queryClient:
|
|
81
|
+
const queryClient: QueryClient & TxExtension = QueryClient.withExtensions(
|
|
84
82
|
tendermint37Client,
|
|
85
83
|
setupTxExtension,
|
|
86
84
|
);
|