@dydxprotocol/v4-client-js 1.1.13 → 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.
Files changed (150) hide show
  1. package/.eslintrc.js +3 -5
  2. package/.prettierignore +3 -0
  3. package/.prettierrc.json +6 -0
  4. package/.telescope.json +2 -4
  5. package/.vscode/launch.json +10 -10
  6. package/README.md +3 -1
  7. package/__native__/__ios__/v4-native-client.js +2640 -797
  8. package/__tests__/helpers/constants.ts +10 -8
  9. package/__tests__/lib/helpers.test.ts +22 -23
  10. package/__tests__/lib/util.test.ts +2 -8
  11. package/__tests__/lib/validation.test.ts +23 -26
  12. package/__tests__/modules/client/Transfers.test.ts +4 -19
  13. package/__tests__/modules/client/ValidatorPostEndpoints.test.ts +2 -5
  14. package/__tests__/modules/client/constants.ts +4 -2
  15. package/__tests__/modules/onboarding.test.ts +9 -7
  16. package/build/__tests__/helpers/constants.js +7 -7
  17. package/build/__tests__/lib/helpers.test.js +2 -6
  18. package/build/__tests__/lib/util.test.js +1 -1
  19. package/build/__tests__/lib/validation.test.js +3 -11
  20. package/build/__tests__/modules/client/Transfers.test.js +1 -1
  21. package/build/__tests__/modules/client/ValidatorPostEndpoints.test.js +2 -2
  22. package/build/__tests__/modules/client/constants.js +1 -1
  23. package/build/__tests__/modules/onboarding.test.js +2 -3
  24. package/build/examples/account_endpoints.js +4 -3
  25. package/build/examples/composite_example.js +5 -4
  26. package/build/examples/constants.js +1 -1
  27. package/build/examples/faucet_endpoint.js +4 -3
  28. package/build/examples/long_term_order_cancel_example.js +4 -3
  29. package/build/examples/markets_endpoints.js +4 -3
  30. package/build/examples/native_examples.js +4 -3
  31. package/build/examples/noble_example.js +1 -1
  32. package/build/examples/optimal_node.js +4 -12
  33. package/build/examples/short_term_order_cancel_example.js +4 -3
  34. package/build/examples/short_term_order_composite_example.js +4 -3
  35. package/build/examples/test.js +5 -4
  36. package/build/examples/transfer_example_deposit.js +4 -3
  37. package/build/examples/transfer_example_send.js +1 -1
  38. package/build/examples/transfer_example_subaccount_transfer.js +4 -3
  39. package/build/examples/transfer_example_withdraw.js +4 -3
  40. package/build/examples/transfer_example_withdraw_other.js +1 -1
  41. package/build/examples/utility_endpoints.js +4 -3
  42. package/build/examples/validator_get_example.js +15 -9
  43. package/build/examples/validator_post_example.js +4 -3
  44. package/build/examples/wallet_address.js +5 -4
  45. package/build/examples/websocket_example.js +1 -1
  46. package/build/src/clients/composite-client.d.ts +222 -222
  47. package/build/src/clients/composite-client.js +234 -228
  48. package/build/src/clients/constants.d.ts +3 -0
  49. package/build/src/clients/constants.js +6 -2
  50. package/build/src/clients/faucet-client.d.ts +4 -4
  51. package/build/src/clients/faucet-client.js +5 -5
  52. package/build/src/clients/helpers/chain-helpers.js +1 -1
  53. package/build/src/clients/helpers/request-helpers.js +5 -4
  54. package/build/src/clients/indexer-client.js +1 -1
  55. package/build/src/clients/lib/axios/axiosRequest.js +1 -1
  56. package/build/src/clients/lib/axios/errors.js +1 -1
  57. package/build/src/clients/lib/cctpProto.d.ts +2 -2
  58. package/build/src/clients/lib/cctpProto.js +287 -237
  59. package/build/src/clients/lib/errors.js +1 -1
  60. package/build/src/clients/modules/account.js +1 -1
  61. package/build/src/clients/modules/composer.d.ts +4 -0
  62. package/build/src/clients/modules/composer.js +39 -3
  63. package/build/src/clients/modules/get.d.ts +10 -3
  64. package/build/src/clients/modules/get.js +41 -54
  65. package/build/src/clients/modules/local-wallet.js +1 -1
  66. package/build/src/clients/modules/post.d.ts +3 -0
  67. package/build/src/clients/modules/post.js +34 -18
  68. package/build/src/clients/modules/proto-includes.d.ts +1 -0
  69. package/build/src/clients/modules/proto-includes.js +3 -2
  70. package/build/src/clients/modules/rest.js +1 -1
  71. package/build/src/clients/modules/signer.js +1 -1
  72. package/build/src/clients/modules/tendermintClient.d.ts +5 -5
  73. package/build/src/clients/modules/tendermintClient.js +6 -6
  74. package/build/src/clients/native.js +4 -7
  75. package/build/src/clients/noble-client.js +1 -1
  76. package/build/src/clients/socket-client.js +1 -1
  77. package/build/src/clients/subaccount.js +1 -1
  78. package/build/src/clients/types.d.ts +1 -1
  79. package/build/src/clients/types.js +1 -1
  80. package/build/src/clients/validator-client.d.ts +12 -12
  81. package/build/src/clients/validator-client.js +13 -13
  82. package/build/src/lib/errors.js +1 -1
  83. package/build/src/lib/onboarding.js +1 -1
  84. package/build/src/lib/utils.js +3 -3
  85. package/build/src/lib/validation.js +5 -4
  86. package/build/src/network_optimizer.js +10 -11
  87. package/build/src/types.d.ts +1 -1
  88. package/build/src/types.js +1 -1
  89. package/examples/account_endpoints.ts +5 -4
  90. package/examples/composite_example.ts +12 -7
  91. package/examples/constants.ts +10 -4
  92. package/examples/faucet_endpoint.ts +5 -4
  93. package/examples/human_readable_orders.json +85 -85
  94. package/examples/human_readable_short_term_orders.json +41 -41
  95. package/examples/long_term_order_cancel_example.ts +11 -6
  96. package/examples/markets_endpoints.ts +5 -4
  97. package/examples/native_examples.ts +8 -7
  98. package/examples/noble_example.ts +11 -23
  99. package/examples/optimal_node.ts +4 -14
  100. package/examples/raw_orders.json +128 -128
  101. package/examples/short_term_order_cancel_example.ts +7 -8
  102. package/examples/short_term_order_composite_example.ts +7 -8
  103. package/examples/test.ts +12 -7
  104. package/examples/transfer_example_deposit.ts +6 -9
  105. package/examples/transfer_example_send.ts +2 -10
  106. package/examples/transfer_example_subaccount_transfer.ts +6 -11
  107. package/examples/transfer_example_withdraw.ts +6 -9
  108. package/examples/transfer_example_withdraw_other.ts +1 -5
  109. package/examples/utility_endpoints.ts +5 -4
  110. package/examples/validator_get_example.ts +19 -10
  111. package/examples/validator_post_example.ts +7 -9
  112. package/examples/wallet_address.ts +6 -5
  113. package/examples/websocket_example.ts +5 -1
  114. package/package.json +4 -1
  115. package/src/clients/composite-client.ts +272 -329
  116. package/src/clients/constants.ts +38 -26
  117. package/src/clients/faucet-client.ts +5 -8
  118. package/src/clients/helpers/chain-helpers.ts +10 -6
  119. package/src/clients/helpers/request-helpers.ts +6 -5
  120. package/src/clients/indexer-client.ts +34 -34
  121. package/src/clients/lib/axios/axiosRequest.ts +4 -7
  122. package/src/clients/lib/axios/errors.ts +16 -21
  123. package/src/clients/lib/cctpProto.ts +655 -387
  124. package/src/clients/lib/errors.ts +8 -17
  125. package/src/clients/modules/account.ts +4 -12
  126. package/src/clients/modules/composer.ts +61 -20
  127. package/src/clients/modules/get.ts +71 -89
  128. package/src/clients/modules/local-wallet.ts +41 -56
  129. package/src/clients/modules/post.ts +664 -634
  130. package/src/clients/modules/proto-includes.ts +1 -0
  131. package/src/clients/modules/rest.ts +23 -26
  132. package/src/clients/modules/signer.ts +8 -22
  133. package/src/clients/modules/tendermintClient.ts +13 -36
  134. package/src/clients/native.ts +73 -139
  135. package/src/clients/noble-client.ts +1 -5
  136. package/src/clients/socket-client.ts +216 -216
  137. package/src/clients/subaccount.ts +16 -16
  138. package/src/clients/types.ts +14 -10
  139. package/src/clients/validator-client.ts +14 -16
  140. package/src/codegen/helpers.ts +149 -150
  141. package/src/codegen/index.ts +4 -5
  142. package/src/lib/errors.ts +3 -9
  143. package/src/lib/onboarding.ts +7 -2
  144. package/src/lib/utils.ts +5 -12
  145. package/src/lib/validation.ts +21 -19
  146. package/src/network_optimizer.ts +78 -65
  147. package/src/types.ts +5 -6
  148. package/tasks.json +15 -15
  149. package/tsconfig.eslint.json +1 -4
  150. package/tsconfig.json +2 -6
@@ -1,10 +1,14 @@
1
1
  import { EncodeObject } from '@cosmjs/proto-signing';
2
- import {
3
- Account, GasPrice, IndexedTx, StdFee,
4
- } from '@cosmjs/stargate';
2
+ import { Account, GasPrice, IndexedTx, StdFee } from '@cosmjs/stargate';
5
3
  import { Method } from '@cosmjs/tendermint-rpc';
6
- import { BroadcastTxAsyncResponse, BroadcastTxSyncResponse } from '@cosmjs/tendermint-rpc/build/tendermint37';
7
- import { Order_ConditionType, Order_TimeInForce } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order';
4
+ import {
5
+ BroadcastTxAsyncResponse,
6
+ BroadcastTxSyncResponse,
7
+ } from '@cosmjs/tendermint-rpc/build/tendermint37';
8
+ import {
9
+ Order_ConditionType,
10
+ Order_TimeInForce,
11
+ } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order';
8
12
  import { parseUnits } from 'ethers';
9
13
  import Long from 'long';
10
14
  import protobuf from 'protobufjs';
@@ -66,15 +70,9 @@ export class CompositeClient {
66
70
  return client;
67
71
  }
68
72
 
69
- private constructor(
70
- network: Network,
71
- apiTimeout?: number,
72
- ) {
73
+ private constructor(network: Network, apiTimeout?: number) {
73
74
  this.network = network;
74
- this._indexerClient = new IndexerClient(
75
- network.indexerConfig,
76
- apiTimeout,
77
- );
75
+ this._indexerClient = new IndexerClient(network.indexerConfig, apiTimeout);
78
76
  }
79
77
 
80
78
  private async initialize(): Promise<void> {
@@ -106,13 +104,13 @@ export class CompositeClient {
106
104
  }
107
105
 
108
106
  /**
109
- * @description Sign a list of messages with a wallet.
110
- * the calling function is responsible for creating the messages.
111
- *
112
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
113
- * at any point.
114
- * @returns The Signature.
115
- */
107
+ * @description Sign a list of messages with a wallet.
108
+ * the calling function is responsible for creating the messages.
109
+ *
110
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
111
+ * at any point.
112
+ * @returns The Signature.
113
+ */
116
114
  async sign(
117
115
  wallet: LocalWallet,
118
116
  messaging: () => Promise<EncodeObject[]>,
@@ -121,24 +119,17 @@ export class CompositeClient {
121
119
  memo?: string,
122
120
  account?: () => Promise<Account>,
123
121
  ): Promise<Uint8Array> {
124
- return this.validatorClient.post.sign(
125
- wallet,
126
- messaging,
127
- zeroFee,
128
- gasPrice,
129
- memo,
130
- account,
131
- );
122
+ return this.validatorClient.post.sign(wallet, messaging, zeroFee, gasPrice, memo, account);
132
123
  }
133
124
 
134
125
  /**
135
- * @description Send a list of messages with a wallet.
136
- * the calling function is responsible for creating the messages.
137
- *
138
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
139
- * at any point.
140
- * @returns The Transaction Hash.
141
- */
126
+ * @description Send a list of messages with a wallet.
127
+ * the calling function is responsible for creating the messages.
128
+ *
129
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
130
+ * at any point.
131
+ * @returns The Transaction Hash.
132
+ */
142
133
  async send(
143
134
  wallet: LocalWallet,
144
135
  messaging: () => Promise<EncodeObject[]>,
@@ -160,14 +151,14 @@ export class CompositeClient {
160
151
  }
161
152
 
162
153
  /**
163
- * @description Send a signed transaction.
164
- *
165
- * @param signedTransaction The signed transaction to send.
166
- *
167
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
168
- * at any point.
169
- * @returns The Transaction Hash.
170
- */
154
+ * @description Send a signed transaction.
155
+ *
156
+ * @param signedTransaction The signed transaction to send.
157
+ *
158
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
159
+ * at any point.
160
+ * @returns The Transaction Hash.
161
+ */
171
162
  async sendSignedTransaction(
172
163
  signedTransaction: Uint8Array,
173
164
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
@@ -175,18 +166,18 @@ export class CompositeClient {
175
166
  }
176
167
 
177
168
  /**
178
- * @description Simulate a list of messages with a wallet.
179
- * the calling function is responsible for creating the messages.
180
- *
181
- * To send multiple messages with gas estimate:
182
- * 1. Client is responsible for creating the messages.
183
- * 2. Call simulate() to get the gas estimate.
184
- * 3. Call send() to send the messages.
185
- *
186
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
187
- * at any point.
188
- * @returns The gas estimate.
189
- */
169
+ * @description Simulate a list of messages with a wallet.
170
+ * the calling function is responsible for creating the messages.
171
+ *
172
+ * To send multiple messages with gas estimate:
173
+ * 1. Client is responsible for creating the messages.
174
+ * 2. Call simulate() to get the gas estimate.
175
+ * 3. Call send() to send the messages.
176
+ *
177
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
178
+ * at any point.
179
+ * @returns The gas estimate.
180
+ */
190
181
  async simulate(
191
182
  wallet: LocalWallet,
192
183
  messaging: () => Promise<EncodeObject[]>,
@@ -194,22 +185,16 @@ export class CompositeClient {
194
185
  memo?: string,
195
186
  account?: () => Promise<Account>,
196
187
  ): Promise<StdFee> {
197
- return this.validatorClient.post.simulate(
198
- wallet,
199
- messaging,
200
- gasPrice,
201
- memo,
202
- account,
203
- );
188
+ return this.validatorClient.post.simulate(wallet, messaging, gasPrice, memo, account);
204
189
  }
205
190
 
206
191
  /**
207
- * @description Calculate the goodTilBlock value for a SHORT_TERM order
208
- *
209
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
210
- * at any point.
211
- * @returns The goodTilBlock value
212
- */
192
+ * @description Calculate the goodTilBlock value for a SHORT_TERM order
193
+ *
194
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
195
+ * at any point.
196
+ * @returns The goodTilBlock value
197
+ */
213
198
 
214
199
  private async calculateGoodTilBlock(
215
200
  orderFlags: OrderFlags,
@@ -220,7 +205,7 @@ export class CompositeClient {
220
205
  if (goodTilBlock !== undefined && goodTilBlock !== 0) {
221
206
  return Promise.resolve(goodTilBlock);
222
207
  } else {
223
- const height = currentHeight ?? await this.validatorClient.get.latestBlockHeight();
208
+ const height = currentHeight ?? (await this.validatorClient.get.latestBlockHeight());
224
209
  return height + SHORT_BLOCK_FORWARD;
225
210
  }
226
211
  } else {
@@ -250,15 +235,15 @@ export class CompositeClient {
250
235
  }
251
236
 
252
237
  /**
253
- * @description Calculate the goodTilBlockTime value for a LONG_TERM order
254
- * the calling function is responsible for creating the messages.
255
- *
256
- * @param goodTilTimeInSeconds The goodTilTimeInSeconds of the order to place.
257
- *
258
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
259
- * at any point.
260
- * @returns The goodTilBlockTime value
261
- */
238
+ * @description Calculate the goodTilBlockTime value for a LONG_TERM order
239
+ * the calling function is responsible for creating the messages.
240
+ *
241
+ * @param goodTilTimeInSeconds The goodTilTimeInSeconds of the order to place.
242
+ *
243
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
244
+ * at any point.
245
+ * @returns The goodTilBlockTime value
246
+ */
262
247
  private calculateGoodTilBlockTime(goodTilTimeInSeconds: number): number {
263
248
  const now = new Date();
264
249
  const millisecondsPerSecond = 1000;
@@ -312,10 +297,12 @@ export class CompositeClient {
312
297
  timeInForce,
313
298
  reduceOnly,
314
299
  );
315
- msg.then((it) => resolve([it])).catch((err) => {
316
- console.log(err);
317
- reject(err);
318
- });
300
+ msg
301
+ .then((it) => resolve([it]))
302
+ .catch((err) => {
303
+ console.log(err);
304
+ reject(err);
305
+ });
319
306
  });
320
307
  const account: Promise<Account> = this.validatorClient.post.account(
321
308
  subaccount.address,
@@ -333,36 +320,36 @@ export class CompositeClient {
333
320
  }
334
321
 
335
322
  /**
336
- * @description Place an order with human readable input.
337
- *
338
- * Only MARKET and LIMIT types are supported right now
339
- * Use human readable form of input, including price and size
340
- * The quantum and subticks are calculated and submitted
341
- *
342
- * @param subaccount The subaccount to place the order on.
343
- * @param marketId The market to place the order on.
344
- * @param type The type of order to place.
345
- * @param side The side of the order to place.
346
- * @param price The price of the order to place.
347
- * @param size The size of the order to place.
348
- * @param clientId The client id of the order to place.
349
- * @param timeInForce The time in force of the order to place.
350
- * @param goodTilTimeInSeconds The goodTilTimeInSeconds of the order to place.
351
- * @param execution The execution of the order to place.
352
- * @param postOnly The postOnly of the order to place.
353
- * @param reduceOnly The reduceOnly of the order to place.
354
- * @param triggerPrice The trigger price of conditional orders.
355
- * @param marketInfo optional market information for calculating quantums and subticks.
356
- * This can be constructed from Indexer API. If set to null, additional round
357
- * trip to Indexer API will be made.
358
- * @param currentHeight Current block height. This can be obtained from ValidatorClient.
359
- * If set to null, additional round trip to ValidatorClient will be made.
360
- *
361
- *
362
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
363
- * at any point.
364
- * @returns The transaction hash.
365
- */
323
+ * @description Place an order with human readable input.
324
+ *
325
+ * Only MARKET and LIMIT types are supported right now
326
+ * Use human readable form of input, including price and size
327
+ * The quantum and subticks are calculated and submitted
328
+ *
329
+ * @param subaccount The subaccount to place the order on.
330
+ * @param marketId The market to place the order on.
331
+ * @param type The type of order to place.
332
+ * @param side The side of the order to place.
333
+ * @param price The price of the order to place.
334
+ * @param size The size of the order to place.
335
+ * @param clientId The client id of the order to place.
336
+ * @param timeInForce The time in force of the order to place.
337
+ * @param goodTilTimeInSeconds The goodTilTimeInSeconds of the order to place.
338
+ * @param execution The execution of the order to place.
339
+ * @param postOnly The postOnly of the order to place.
340
+ * @param reduceOnly The reduceOnly of the order to place.
341
+ * @param triggerPrice The trigger price of conditional orders.
342
+ * @param marketInfo optional market information for calculating quantums and subticks.
343
+ * This can be constructed from Indexer API. If set to null, additional round
344
+ * trip to Indexer API will be made.
345
+ * @param currentHeight Current block height. This can be obtained from ValidatorClient.
346
+ * If set to null, additional round trip to ValidatorClient will be made.
347
+ *
348
+ *
349
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
350
+ * at any point.
351
+ * @returns The transaction hash.
352
+ */
366
353
  async placeOrder(
367
354
  subaccount: SubaccountInfo,
368
355
  marketId: string,
@@ -401,9 +388,11 @@ export class CompositeClient {
401
388
  currentHeight,
402
389
  goodTilBlock,
403
390
  );
404
- msg.then((it) => resolve([it])).catch((err) => {
405
- console.log(err);
406
- });
391
+ msg
392
+ .then((it) => resolve([it]))
393
+ .catch((err) => {
394
+ console.log(err);
395
+ });
407
396
  });
408
397
  const orderFlags = calculateOrderFlags(type, timeInForce);
409
398
  const account: Promise<Account> = this.validatorClient.post.account(
@@ -422,30 +411,30 @@ export class CompositeClient {
422
411
  }
423
412
 
424
413
  /**
425
- * @description Calculate and create the place order message
426
- *
427
- * Only MARKET and LIMIT types are supported right now
428
- * Use human readable form of input, including price and size
429
- * The quantum and subticks are calculated and submitted
430
- *
431
- * @param subaccount The subaccount to place the order under
432
- * @param marketId The market to place the order on
433
- * @param type The type of order to place
434
- * @param side The side of the order to place
435
- * @param price The price of the order to place
436
- * @param size The size of the order to place
437
- * @param clientId The client id of the order to place
438
- * @param timeInForce The time in force of the order to place
439
- * @param goodTilTimeInSeconds The goodTilTimeInSeconds of the order to place
440
- * @param execution The execution of the order to place
441
- * @param postOnly The postOnly of the order to place
442
- * @param reduceOnly The reduceOnly of the order to place
443
- *
444
- *
445
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
446
- * at any point.
447
- * @returns The message to be passed into the protocol
448
- */
414
+ * @description Calculate and create the place order message
415
+ *
416
+ * Only MARKET and LIMIT types are supported right now
417
+ * Use human readable form of input, including price and size
418
+ * The quantum and subticks are calculated and submitted
419
+ *
420
+ * @param subaccount The subaccount to place the order under
421
+ * @param marketId The market to place the order on
422
+ * @param type The type of order to place
423
+ * @param side The side of the order to place
424
+ * @param price The price of the order to place
425
+ * @param size The size of the order to place
426
+ * @param clientId The client id of the order to place
427
+ * @param timeInForce The time in force of the order to place
428
+ * @param goodTilTimeInSeconds The goodTilTimeInSeconds of the order to place
429
+ * @param execution The execution of the order to place
430
+ * @param postOnly The postOnly of the order to place
431
+ * @param reduceOnly The reduceOnly of the order to place
432
+ *
433
+ *
434
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
435
+ * at any point.
436
+ * @returns The message to be passed into the protocol
437
+ */
449
438
  private async placeOrderMessage(
450
439
  subaccount: SubaccountInfo,
451
440
  marketId: string,
@@ -470,8 +459,7 @@ export class CompositeClient {
470
459
  const result = await Promise.all([
471
460
  this.calculateGoodTilBlock(orderFlags, currentHeight, goodTilBlock),
472
461
  this.retrieveMarketInfo(marketId, marketInfo),
473
- ],
474
- );
462
+ ]);
475
463
  const desiredGoodTilBlock = result[0];
476
464
  const clobPairId = result[1].clobPairId;
477
465
  const atomicResolution = result[1].atomicResolution;
@@ -479,11 +467,7 @@ export class CompositeClient {
479
467
  const quantumConversionExponent = result[1].quantumConversionExponent;
480
468
  const subticksPerTick = result[1].subticksPerTick;
481
469
  const orderSide = calculateSide(side);
482
- const quantums = calculateQuantums(
483
- size,
484
- atomicResolution,
485
- stepBaseQuantums,
486
- );
470
+ const quantums = calculateQuantums(size, atomicResolution, stepBaseQuantums);
487
471
  const subticks = calculateSubticks(
488
472
  price,
489
473
  atomicResolution,
@@ -506,7 +490,8 @@ export class CompositeClient {
506
490
  atomicResolution,
507
491
  quantumConversionExponent,
508
492
  subticksPerTick,
509
- triggerPrice);
493
+ triggerPrice,
494
+ );
510
495
  return this.validatorClient.post.composer.composeMsgPlaceOrder(
511
496
  subaccount.address,
512
497
  subaccount.subaccountNumber,
@@ -548,26 +533,26 @@ export class CompositeClient {
548
533
  }
549
534
 
550
535
  /**
551
- * @description Calculate and create the short term place order message
552
- *
553
- * Use human readable form of input, including price and size
554
- * The quantum and subticks are calculated and submitted
555
- *
556
- * @param subaccount The subaccount to place the order under
557
- * @param marketId The market to place the order on
558
- * @param side The side of the order to place
559
- * @param price The price of the order to place
560
- * @param size The size of the order to place
561
- * @param clientId The client id of the order to place
562
- * @param timeInForce The time in force of the order to place
563
- * @param goodTilBlock The goodTilBlock of the order to place
564
- * @param reduceOnly The reduceOnly of the order to place
565
- *
566
- *
567
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
568
- * at any point.
569
- * @returns The message to be passed into the protocol
570
- */
536
+ * @description Calculate and create the short term place order message
537
+ *
538
+ * Use human readable form of input, including price and size
539
+ * The quantum and subticks are calculated and submitted
540
+ *
541
+ * @param subaccount The subaccount to place the order under
542
+ * @param marketId The market to place the order on
543
+ * @param side The side of the order to place
544
+ * @param price The price of the order to place
545
+ * @param size The size of the order to place
546
+ * @param clientId The client id of the order to place
547
+ * @param timeInForce The time in force of the order to place
548
+ * @param goodTilBlock The goodTilBlock of the order to place
549
+ * @param reduceOnly The reduceOnly of the order to place
550
+ *
551
+ *
552
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
553
+ * at any point.
554
+ * @returns The message to be passed into the protocol
555
+ */
571
556
  private async placeShortTermOrderMessage(
572
557
  subaccount: SubaccountInfo,
573
558
  marketId: string,
@@ -589,11 +574,7 @@ export class CompositeClient {
589
574
  const quantumConversionExponent = market.quantumConversionExponent;
590
575
  const subticksPerTick = market.subticksPerTick;
591
576
  const orderSide = calculateSide(side);
592
- const quantums = calculateQuantums(
593
- size,
594
- atomicResolution,
595
- stepBaseQuantums,
596
- );
577
+ const quantums = calculateQuantums(size, atomicResolution, stepBaseQuantums);
597
578
  const subticks = calculateSubticks(
598
579
  price,
599
580
  atomicResolution,
@@ -621,19 +602,19 @@ export class CompositeClient {
621
602
  }
622
603
 
623
604
  /**
624
- * @description Cancel an order with order information from web socket or REST.
625
- *
626
- * @param subaccount The subaccount to cancel the order from
627
- * @param clientId The client id of the order to cancel
628
- * @param orderFlags The order flags of the order to cancel
629
- * @param clobPairId The clob pair id of the order to cancel
630
- * @param goodTilBlock The goodTilBlock of the order to cancel
631
- * @param goodTilBlockTime The goodTilBlockTime of the order to cancel
632
- *
633
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
634
- * at any point.
635
- * @returns The transaction hash.
636
- */
605
+ * @description Cancel an order with order information from web socket or REST.
606
+ *
607
+ * @param subaccount The subaccount to cancel the order from
608
+ * @param clientId The client id of the order to cancel
609
+ * @param orderFlags The order flags of the order to cancel
610
+ * @param clobPairId The clob pair id of the order to cancel
611
+ * @param goodTilBlock The goodTilBlock of the order to cancel
612
+ * @param goodTilBlockTime The goodTilBlockTime of the order to cancel
613
+ *
614
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
615
+ * at any point.
616
+ * @returns The transaction hash.
617
+ */
637
618
  async cancelRawOrder(
638
619
  subaccount: SubaccountInfo,
639
620
  clientId: number,
@@ -653,19 +634,19 @@ export class CompositeClient {
653
634
  }
654
635
 
655
636
  /**
656
- * @description Cancel an order with human readable input.
657
- *
658
- * @param subaccount The subaccount to cancel the order from
659
- * @param clientId The client id of the order to cancel
660
- * @param orderFlags The order flags of the order to cancel
661
- * @param marketId The market to cancel the order on
662
- * @param goodTilBlock The goodTilBlock of the order to cancel
663
- * @param goodTilBlockTime The goodTilBlockTime of the order to cancel
664
- *
665
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
666
- * at any point.
667
- * @returns The transaction hash.
668
- */
637
+ * @description Cancel an order with human readable input.
638
+ *
639
+ * @param subaccount The subaccount to cancel the order from
640
+ * @param clientId The client id of the order to cancel
641
+ * @param orderFlags The order flags of the order to cancel
642
+ * @param marketId The market to cancel the order on
643
+ * @param goodTilBlock The goodTilBlock of the order to cancel
644
+ * @param goodTilBlockTime The goodTilBlockTime of the order to cancel
645
+ *
646
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
647
+ * at any point.
648
+ * @returns The transaction hash.
649
+ */
669
650
  async cancelOrder(
670
651
  subaccount: SubaccountInfo,
671
652
  clientId: number,
@@ -674,7 +655,6 @@ export class CompositeClient {
674
655
  goodTilBlock?: number,
675
656
  goodTilTimeInSeconds?: number,
676
657
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
677
-
678
658
  const marketsResponse = await this.indexerClient.markets.getPerpetualMarkets(marketId);
679
659
  const market = marketsResponse.markets[marketId];
680
660
  const clobPairId = market.clobPairId;
@@ -691,7 +671,7 @@ export class CompositeClient {
691
671
  if (goodTilBlock !== 0) {
692
672
  throw new Error(
693
673
  'goodTilBlock should be zero since LONG_TERM or CONDITIONAL orders ' +
694
- 'use goodTilTimeInSeconds instead of goodTilBlock.',
674
+ 'use goodTilTimeInSeconds instead of goodTilBlock.',
695
675
  );
696
676
  }
697
677
  goodTilBlockTime = this.calculateGoodTilBlockTime(goodTilTimeInSeconds);
@@ -700,7 +680,9 @@ export class CompositeClient {
700
680
  throw new Error('goodTilBlock must be non-zero for SHORT_TERM orders');
701
681
  }
702
682
  if (goodTilTimeInSeconds !== undefined && goodTilTimeInSeconds !== 0) {
703
- throw new Error('goodTilTimeInSeconds should be zero since SHORT_TERM orders use goodTilBlock instead of goodTilTimeInSeconds.');
683
+ throw new Error(
684
+ 'goodTilTimeInSeconds should be zero since SHORT_TERM orders use goodTilBlock instead of goodTilTimeInSeconds.',
685
+ );
704
686
  }
705
687
  }
706
688
 
@@ -715,17 +697,17 @@ export class CompositeClient {
715
697
  }
716
698
 
717
699
  /**
718
- * @description Transfer from a subaccount to another subaccount
719
- *
720
- * @param subaccount The subaccount to transfer from
721
- * @param recipientAddress The recipient address
722
- * @param recipientSubaccountNumber The recipient subaccount number
723
- * @param amount The amount to transfer
724
- *
725
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
726
- * at any point.
727
- * @returns The transaction hash.
728
- */
700
+ * @description Transfer from a subaccount to another subaccount
701
+ *
702
+ * @param subaccount The subaccount to transfer from
703
+ * @param recipientAddress The recipient address
704
+ * @param recipientSubaccountNumber The recipient subaccount number
705
+ * @param amount The amount to transfer
706
+ *
707
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
708
+ * at any point.
709
+ * @returns The transaction hash.
710
+ */
729
711
  async transferToSubaccount(
730
712
  subaccount: SubaccountInfo,
731
713
  recipientAddress: string,
@@ -754,18 +736,18 @@ export class CompositeClient {
754
736
  }
755
737
 
756
738
  /**
757
- * @description Create message to transfer from a subaccount to another subaccount
758
- *
759
- * @param subaccount The subaccount to transfer from
760
- * @param recipientAddress The recipient address
761
- * @param recipientSubaccountNumber The recipient subaccount number
762
- * @param amount The amount to transfer
763
- *
764
- *
765
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
766
- * at any point.
767
- * @returns The message
768
- */
739
+ * @description Create message to transfer from a subaccount to another subaccount
740
+ *
741
+ * @param subaccount The subaccount to transfer from
742
+ * @param recipientAddress The recipient address
743
+ * @param recipientSubaccountNumber The recipient subaccount number
744
+ * @param amount The amount to transfer
745
+ *
746
+ *
747
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
748
+ * at any point.
749
+ * @returns The message
750
+ */
769
751
  transferToSubaccountMessage(
770
752
  subaccount: SubaccountInfo,
771
753
  recipientAddress: string,
@@ -795,49 +777,38 @@ export class CompositeClient {
795
777
  }
796
778
 
797
779
  /**
798
- * @description Deposit from wallet to subaccount
799
- *
800
- * @param subaccount The subaccount to deposit to
801
- * @param amount The amount to deposit
802
- *
803
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
804
- * at any point.
805
- * @returns The transaction hash.
806
- */
780
+ * @description Deposit from wallet to subaccount
781
+ *
782
+ * @param subaccount The subaccount to deposit to
783
+ * @param amount The amount to deposit
784
+ *
785
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
786
+ * at any point.
787
+ * @returns The transaction hash.
788
+ */
807
789
  async depositToSubaccount(
808
790
  subaccount: SubaccountInfo,
809
791
  amount: string,
810
792
  memo?: string,
811
793
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
812
794
  const msgs: Promise<EncodeObject[]> = new Promise((resolve) => {
813
- const msg = this.depositToSubaccountMessage(
814
- subaccount,
815
- amount,
816
- );
795
+ const msg = this.depositToSubaccountMessage(subaccount, amount);
817
796
  resolve([msg]);
818
797
  });
819
- return this.validatorClient.post.send(subaccount.wallet,
820
- () => msgs,
821
- false,
822
- undefined,
823
- memo,
824
- );
798
+ return this.validatorClient.post.send(subaccount.wallet, () => msgs, false, undefined, memo);
825
799
  }
826
800
 
827
801
  /**
828
- * @description Create message to deposit from wallet to subaccount
829
- *
830
- * @param subaccount The subaccount to deposit to
831
- * @param amount The amount to deposit
832
- *
833
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
834
- * at any point.
835
- * @returns The message
836
- */
837
- depositToSubaccountMessage(
838
- subaccount: SubaccountInfo,
839
- amount: string,
840
- ): EncodeObject {
802
+ * @description Create message to deposit from wallet to subaccount
803
+ *
804
+ * @param subaccount The subaccount to deposit to
805
+ * @param amount The amount to deposit
806
+ *
807
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
808
+ * at any point.
809
+ * @returns The message
810
+ */
811
+ depositToSubaccountMessage(subaccount: SubaccountInfo, amount: string): EncodeObject {
841
812
  const validatorClient = this._validatorClient;
842
813
  if (validatorClient === undefined) {
843
814
  throw new Error('validatorClient not set');
@@ -859,16 +830,16 @@ export class CompositeClient {
859
830
  }
860
831
 
861
832
  /**
862
- * @description Withdraw from subaccount to wallet
863
- *
864
- * @param subaccount The subaccount to withdraw from
865
- * @param amount The amount to withdraw
866
- * @param recipient The recipient address, default to subaccount address
867
- *
868
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
869
- * at any point.
870
- * @returns The transaction hash
871
- */
833
+ * @description Withdraw from subaccount to wallet
834
+ *
835
+ * @param subaccount The subaccount to withdraw from
836
+ * @param amount The amount to withdraw
837
+ * @param recipient The recipient address, default to subaccount address
838
+ *
839
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
840
+ * at any point.
841
+ * @returns The transaction hash
842
+ */
872
843
  async withdrawFromSubaccount(
873
844
  subaccount: SubaccountInfo,
874
845
  amount: string,
@@ -876,34 +847,24 @@ export class CompositeClient {
876
847
  memo?: string,
877
848
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
878
849
  const msgs: Promise<EncodeObject[]> = new Promise((resolve) => {
879
- const msg = this.withdrawFromSubaccountMessage(
880
- subaccount,
881
- amount,
882
- recipient,
883
- );
850
+ const msg = this.withdrawFromSubaccountMessage(subaccount, amount, recipient);
884
851
  resolve([msg]);
885
852
  });
886
- return this.send(
887
- subaccount.wallet,
888
- () => msgs,
889
- false,
890
- undefined,
891
- memo,
892
- );
853
+ return this.send(subaccount.wallet, () => msgs, false, undefined, memo);
893
854
  }
894
855
 
895
856
  /**
896
- * @description Create message to withdraw from subaccount to wallet
897
- * with human readable input.
898
- *
899
- * @param subaccount The subaccount to withdraw from
900
- * @param amount The amount to withdraw
901
- * @param recipient The recipient address
902
- *
903
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
904
- * at any point.
905
- * @returns The message
906
- */
857
+ * @description Create message to withdraw from subaccount to wallet
858
+ * with human readable input.
859
+ *
860
+ * @param subaccount The subaccount to withdraw from
861
+ * @param amount The amount to withdraw
862
+ * @param recipient The recipient address
863
+ *
864
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
865
+ * at any point.
866
+ * @returns The message
867
+ */
907
868
  withdrawFromSubaccountMessage(
908
869
  subaccount: SubaccountInfo,
909
870
  amount: string,
@@ -931,30 +892,24 @@ export class CompositeClient {
931
892
  }
932
893
 
933
894
  /**
934
- * @description Create message to send chain token from subaccount to wallet
935
- * with human readable input.
936
- *
937
- * @param subaccount The subaccount to withdraw from
938
- * @param amount The amount to withdraw
939
- * @param recipient The recipient address
940
- *
941
- * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
942
- * at any point.
943
- * @returns The message
944
- */
945
- sendTokenMessage(
946
- wallet: LocalWallet,
947
- amount: string,
948
- recipient: string,
949
- ): EncodeObject {
895
+ * @description Create message to send chain token from subaccount to wallet
896
+ * with human readable input.
897
+ *
898
+ * @param subaccount The subaccount to withdraw from
899
+ * @param amount The amount to withdraw
900
+ * @param recipient The recipient address
901
+ *
902
+ * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
903
+ * at any point.
904
+ * @returns The message
905
+ */
906
+ sendTokenMessage(wallet: LocalWallet, amount: string, recipient: string): EncodeObject {
950
907
  const address = wallet.address;
951
908
  if (address === undefined) {
952
909
  throw new UserError('wallet address is not set. Call connectWallet() first');
953
910
  }
954
- const {
955
- CHAINTOKEN_DENOM: chainTokenDenom,
956
- CHAINTOKEN_DECIMALS: chainTokenDecimals,
957
- } = this._validatorClient?.config.denoms || {};
911
+ const { CHAINTOKEN_DENOM: chainTokenDenom, CHAINTOKEN_DECIMALS: chainTokenDecimals } =
912
+ this._validatorClient?.config.denoms || {};
958
913
 
959
914
  if (chainTokenDenom === undefined || chainTokenDecimals === undefined) {
960
915
  throw new Error('Chain token denom not set in validator config');
@@ -1001,15 +956,13 @@ export class CompositeClient {
1001
956
  postOnly,
1002
957
  reduceOnly,
1003
958
  );
1004
- msg.then((it) => resolve([it])).catch((err) => {
1005
- console.log(err);
1006
- });
959
+ msg
960
+ .then((it) => resolve([it]))
961
+ .catch((err) => {
962
+ console.log(err);
963
+ });
1007
964
  });
1008
- const signature = await this.sign(
1009
- wallet,
1010
- () => msgs,
1011
- true,
1012
- );
965
+ const signature = await this.sign(wallet, () => msgs, true);
1013
966
 
1014
967
  return Buffer.from(signature).toString('base64');
1015
968
  }
@@ -1034,11 +987,7 @@ export class CompositeClient {
1034
987
  );
1035
988
  resolve([msg]);
1036
989
  });
1037
- const signature = await this.sign(
1038
- subaccount.wallet,
1039
- () => msgs,
1040
- true,
1041
- );
990
+ const signature = await this.sign(subaccount.wallet, () => msgs, true);
1042
991
 
1043
992
  return Buffer.from(signature).toString('base64');
1044
993
  }
@@ -1136,12 +1085,6 @@ export class CompositeClient {
1136
1085
  resolve([submitProposal]);
1137
1086
  });
1138
1087
 
1139
- return this.send(
1140
- wallet,
1141
- () => msg,
1142
- false,
1143
- undefined,
1144
- memo,
1145
- );
1088
+ return this.send(wallet, () => msg, false, undefined, memo);
1146
1089
  }
1147
1090
  }