@dydxprotocol/v4-client-js 3.3.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/.nvmrc +1 -1
  2. package/__native__/__ios__/v4-native-client.js +109 -29
  3. package/__tests__/modules/client/AccountEndpoints.test.ts +68 -0
  4. package/build/cjs/__tests__/modules/client/AccountEndpoints.test.js +47 -1
  5. package/build/cjs/examples/account_endpoints.js +15 -1
  6. package/build/cjs/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/affiliates.js +1 -1
  7. package/build/cjs/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.js +11 -3
  8. package/build/cjs/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/transfer.js +62 -2
  9. package/build/cjs/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx.js +28 -2
  10. package/build/cjs/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx.rpc.msg.js +7 -1
  11. package/build/cjs/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.js +73 -2
  12. package/build/cjs/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.lcd.js +7 -1
  13. package/build/cjs/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.rpc.Query.js +10 -1
  14. package/build/cjs/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/stats.js +124 -15
  15. package/build/cjs/src/clients/composite-client.js +18 -11
  16. package/build/cjs/src/clients/constants.js +3 -1
  17. package/build/cjs/src/clients/helpers/chain-helpers.js +8 -1
  18. package/build/cjs/src/clients/modules/account.js +10 -1
  19. package/build/cjs/src/clients/types.js +3 -1
  20. package/build/cjs/src/lib/validation.js +5 -3
  21. package/build/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  22. package/build/esm/__tests__/modules/client/AccountEndpoints.test.js +47 -1
  23. package/build/esm/examples/account_endpoints.js +15 -1
  24. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/affiliates.d.ts +6 -1
  25. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/affiliates.d.ts.map +1 -1
  26. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/affiliates.js +1 -1
  27. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.d.ts +3 -0
  28. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.d.ts.map +1 -1
  29. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query.js +11 -3
  30. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.d.ts +35 -4
  31. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bundle.d.ts.map +1 -1
  32. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.query.d.ts +1 -0
  33. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rpc.query.d.ts.map +1 -1
  34. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/transfer.d.ts +30 -0
  35. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/transfer.d.ts.map +1 -1
  36. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/transfer.js +61 -1
  37. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx.d.ts +17 -0
  38. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx.d.ts.map +1 -1
  39. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx.js +27 -1
  40. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx.rpc.msg.d.ts +8 -2
  41. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx.rpc.msg.d.ts.map +1 -1
  42. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx.rpc.msg.js +9 -3
  43. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.d.ts +29 -1
  44. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.d.ts.map +1 -1
  45. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.js +73 -2
  46. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.lcd.d.ts +2 -1
  47. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.lcd.d.ts.map +1 -1
  48. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.lcd.js +7 -1
  49. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.rpc.Query.d.ts +5 -1
  50. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.rpc.Query.d.ts.map +1 -1
  51. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query.rpc.Query.js +11 -2
  52. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/stats.d.ts +54 -12
  53. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/stats.d.ts.map +1 -1
  54. package/build/esm/node_modules/@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/stats.js +121 -14
  55. package/build/esm/src/clients/composite-client.d.ts +14 -5
  56. package/build/esm/src/clients/composite-client.d.ts.map +1 -1
  57. package/build/esm/src/clients/composite-client.js +18 -11
  58. package/build/esm/src/clients/constants.d.ts +3 -1
  59. package/build/esm/src/clients/constants.d.ts.map +1 -1
  60. package/build/esm/src/clients/constants.js +3 -1
  61. package/build/esm/src/clients/helpers/chain-helpers.d.ts.map +1 -1
  62. package/build/esm/src/clients/helpers/chain-helpers.js +8 -1
  63. package/build/esm/src/clients/modules/account.d.ts +2 -0
  64. package/build/esm/src/clients/modules/account.d.ts.map +1 -1
  65. package/build/esm/src/clients/modules/account.js +10 -1
  66. package/build/esm/src/clients/types.d.ts +3 -1
  67. package/build/esm/src/clients/types.d.ts.map +1 -1
  68. package/build/esm/src/clients/types.js +3 -1
  69. package/build/esm/src/lib/validation.d.ts.map +1 -1
  70. package/build/esm/src/lib/validation.js +5 -3
  71. package/build/esm/tsconfig.esm.tsbuildinfo +1 -1
  72. package/examples/account_endpoints.ts +14 -0
  73. package/package.json +2 -2
  74. package/scripts/publish-if-not-exists.sh +33 -14
  75. package/src/clients/composite-client.ts +33 -3
  76. package/src/clients/constants.ts +2 -0
  77. package/src/clients/helpers/chain-helpers.ts +11 -0
  78. package/src/clients/modules/account.ts +26 -0
  79. package/src/clients/types.ts +2 -0
  80. package/src/lib/validation.ts +4 -2
  81. package/CHANGELOG.md +0 -12
@@ -120,6 +120,20 @@ async function test(): Promise<void> {
120
120
  } catch (error) {
121
121
  console.log(error.message);
122
122
  }
123
+
124
+ // Get trade history
125
+ try {
126
+ const response = await client.account.getSubaccountTradeHistory(address, 0);
127
+ console.log(response);
128
+ const trades = response.tradeHistory;
129
+ console.log(trades);
130
+ if (trades.length > 0) {
131
+ const trade0 = trades[0];
132
+ console.log(trade0);
133
+ }
134
+ } catch (error) {
135
+ console.log(error.message);
136
+ }
123
137
  }
124
138
 
125
139
  test()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dydxprotocol/v4-client-js",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "General client library for the new dYdX system (v4 decentralized)",
5
5
  "main": "build/cjs/src/index.js",
6
6
  "module": "build/esm/src/index.js",
@@ -52,7 +52,7 @@
52
52
  "@cosmjs/stargate": "^0.32.1",
53
53
  "@cosmjs/tendermint-rpc": "^0.32.1",
54
54
  "@cosmjs/utils": "^0.32.1",
55
- "@dydxprotocol/v4-proto": "9.4.0-rc.0",
55
+ "@dydxprotocol/v4-proto": "9.5.0",
56
56
  "@osmonauts/lcd": "^0.6.0",
57
57
  "@scure/bip32": "^1.1.5",
58
58
  "@scure/bip39": "^1.1.1",
@@ -1,21 +1,40 @@
1
- #!/bin/bash
2
- set -euxo pipefail
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
3
 
4
- VERSION=$(cat package.json | jq -r '.version')
5
- NAME=$(cat package.json | jq -r '.name')
4
+ VERSION=$(jq -r '.version' package.json)
5
+ NAME=$(jq -r '.name' package.json)
6
+ TAG="v${VERSION}"
6
7
 
7
- test -z "$(npm info $NAME@$VERSION)"
8
- if [ $? -eq 0 ]; then
9
- set -e
8
+ echo "Checking npm registry for ${NAME}@${VERSION}..."
10
9
 
11
- git config --global user.email "ci@dydx.exchange"
12
- git config --global user.name "github_actions"
10
+ set +e
11
+ VIEW_OUTPUT=$(npm view "${NAME}@${VERSION}" 2>&1)
12
+ VIEW_EXIT=$?
13
+ set -e
13
14
 
14
- # Get version and tag
15
- git tag v4-client-js@${VERSION}
16
- git push --tags
15
+ if [ $VIEW_EXIT -eq 0 ]; then
16
+ echo "Skipping publish: ${NAME}@${VERSION} already exists"
17
+ exit 0
18
+ fi
19
+
20
+ if ! echo "$VIEW_OUTPUT" | grep -qiE 'E404|not found|No matching version'; then
21
+ echo "Registry check failed unexpectedly:"
22
+ echo "$VIEW_OUTPUT"
23
+ exit 1
24
+ fi
17
25
 
18
- npm publish
26
+ echo "Version not found. Proceeding with release."
27
+
28
+ git fetch --tags --quiet
29
+ git config user.email "ci@dydx.exchange"
30
+ git config user.name "github_actions"
31
+
32
+ if git show-ref --tags --verify --quiet "refs/tags/$TAG"; then
33
+ echo "Tag $TAG already exists"
19
34
  else
20
- echo "skipping publish, package $NAME@$VERSION already published"
35
+ git tag -a "$TAG" -m "Release $TAG"
36
+ git push origin "$TAG"
21
37
  fi
38
+
39
+ unset NODE_AUTH_TOKEN
40
+ npm publish --provenance --access public
@@ -45,7 +45,7 @@ import { UserError } from './lib/errors';
45
45
  import { generateRegistry } from './lib/registry';
46
46
  import LocalWallet from './modules/local-wallet';
47
47
  import { SubaccountInfo } from './subaccount';
48
- import { BroadcastMode, OrderBatch } from './types';
48
+ import { BroadcastMode, IBuilderCodeParameters, ITwapParameters, OrderBatch } from './types';
49
49
  import { ValidatorClient } from './validator-client';
50
50
 
51
51
  // Required for encoding and decoding queries that are of type Long.
@@ -86,6 +86,9 @@ export type PlaceOrderPayload = {
86
86
  marketInfo?: MarketInfo;
87
87
  currentHeight?: number;
88
88
  goodTilBlock?: number;
89
+ twapParameters?: ITwapParameters;
90
+ builderCodeParameters?: IBuilderCodeParameters;
91
+ orderRouterAddress?: string;
89
92
  };
90
93
 
91
94
  export type CancelRawOrderPayload = {
@@ -318,6 +321,8 @@ export class CompositeClient {
318
321
  * @param timeInForce The time in force of the order to place
319
322
  * @param goodTilBlock The goodTilBlock of the order to place
320
323
  * @param reduceOnly The reduceOnly of the order to place
324
+ * @param builderCodeParameters The builder code parameters of the order to place.
325
+ * @param orderRouterAddress The order router address of the order to place.
321
326
  *
322
327
  *
323
328
  * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
@@ -335,6 +340,8 @@ export class CompositeClient {
335
340
  timeInForce: Order_TimeInForce,
336
341
  reduceOnly: boolean,
337
342
  memo?: string,
343
+ builderCodeParameters?: IBuilderCodeParameters,
344
+ orderRouterAddress?: string,
338
345
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
339
346
  const msgs: Promise<EncodeObject[]> = new Promise((resolve, reject) => {
340
347
  const msg = this.placeShortTermOrderMessage(
@@ -347,6 +354,8 @@ export class CompositeClient {
347
354
  goodTilBlock,
348
355
  timeInForce,
349
356
  reduceOnly,
357
+ builderCodeParameters,
358
+ orderRouterAddress,
350
359
  );
351
360
  msg
352
361
  .then((it) => {
@@ -397,7 +406,10 @@ export class CompositeClient {
397
406
  * trip to Indexer API will be made.
398
407
  * @param currentHeight Current block height. This can be obtained from ValidatorClient.
399
408
  * If set to null, additional round trip to ValidatorClient will be made.
400
- *
409
+ * @param goodTilBlock The goodTilBlock of the order to place.
410
+ * @param twapParameters The twap parameters of the order to place.
411
+ * @param builderCodeParameters The builder code parameters of the order to place.
412
+ * @param orderRouterAddress The order router address of the order to place.
401
413
  *
402
414
  * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
403
415
  * at any point.
@@ -422,6 +434,9 @@ export class CompositeClient {
422
434
  goodTilBlock?: number,
423
435
  memo?: string,
424
436
  broadcastMode?: BroadcastMode,
437
+ twapParameters?: ITwapParameters,
438
+ builderCodeParameters?: IBuilderCodeParameters,
439
+ orderRouterAddress?: string,
425
440
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
426
441
  const msgs: Promise<EncodeObject[]> = new Promise((resolve) => {
427
442
  const msg = this.placeOrderMessage(
@@ -441,6 +456,9 @@ export class CompositeClient {
441
456
  marketInfo,
442
457
  currentHeight,
443
458
  goodTilBlock,
459
+ twapParameters,
460
+ builderCodeParameters,
461
+ orderRouterAddress,
444
462
  );
445
463
  msg
446
464
  .then((it) => resolve([it]))
@@ -506,6 +524,9 @@ export class CompositeClient {
506
524
  marketInfo?: MarketInfo,
507
525
  currentHeight?: number,
508
526
  goodTilBlock?: number,
527
+ twapParameters?: ITwapParameters,
528
+ builderCodeParameters?: IBuilderCodeParameters,
529
+ orderRouterAddress?: string,
509
530
  ): Promise<EncodeObject> {
510
531
  const orderFlags = calculateOrderFlags(type, timeInForce);
511
532
 
@@ -561,6 +582,9 @@ export class CompositeClient {
561
582
  clientMetadata,
562
583
  conditionalType,
563
584
  conditionalOrderTriggerSubticks,
585
+ twapParameters,
586
+ builderCodeParameters,
587
+ orderRouterAddress,
564
588
  );
565
589
  }
566
590
 
@@ -600,7 +624,8 @@ export class CompositeClient {
600
624
  * @param timeInForce The time in force of the order to place
601
625
  * @param goodTilBlock The goodTilBlock of the order to place
602
626
  * @param reduceOnly The reduceOnly of the order to place
603
- *
627
+ * @param builderCodeParameters The builder code parameters of the order to place.
628
+ * @param orderRouterAddress The order router address of the order to place.
604
629
  *
605
630
  * @throws UnexpectedClientError if a malformed response is returned with no GRPC error
606
631
  * at any point.
@@ -616,6 +641,8 @@ export class CompositeClient {
616
641
  goodTilBlock: number,
617
642
  timeInForce: Order_TimeInForce,
618
643
  reduceOnly: boolean,
644
+ builderCodeParameters?: IBuilderCodeParameters,
645
+ orderRouterAddress?: string,
619
646
  ): Promise<EncodeObject> {
620
647
  await this.validateGoodTilBlock(goodTilBlock);
621
648
 
@@ -651,6 +678,9 @@ export class CompositeClient {
651
678
  0, // Client metadata is 0 for short term orders.
652
679
  Order_ConditionType.CONDITION_TYPE_UNSPECIFIED, // Short term orders cannot be conditional.
653
680
  Long.fromInt(0), // Short term orders cannot be conditional.
681
+ undefined,
682
+ builderCodeParameters,
683
+ orderRouterAddress,
654
684
  );
655
685
  }
656
686
 
@@ -144,6 +144,8 @@ export enum OrderType {
144
144
  TAKE_PROFIT_LIMIT = 'TAKE_PROFIT',
145
145
  STOP_MARKET = 'STOP_MARKET',
146
146
  TAKE_PROFIT_MARKET = 'TAKE_PROFIT_MARKET',
147
+ TWAP = 'TWAP',
148
+ TWAP_SUBORDER = 'TWAP_SUBORDER',
147
149
  }
148
150
 
149
151
  // ------------ Order Side ------------
@@ -45,6 +45,7 @@ export function calculateSubticks(
45
45
  return Long.fromNumber(result);
46
46
  }
47
47
 
48
+
48
49
  export function calculateSide(side: OrderSide): Order_Side {
49
50
  return side === OrderSide.BUY ? Order_Side.SIDE_BUY : Order_Side.SIDE_SELL;
50
51
  }
@@ -133,6 +134,10 @@ export function calculateTimeInForce(
133
134
  throw new Error('Unexpected code path: timeInForce');
134
135
  }
135
136
 
137
+ case OrderType.TWAP:
138
+ case OrderType.TWAP_SUBORDER:
139
+ return Order_TimeInForce.TIME_IN_FORCE_UNSPECIFIED;
140
+
136
141
  default:
137
142
  throw new Error('Unexpected code path: timeInForce');
138
143
  }
@@ -159,6 +164,12 @@ export function calculateOrderFlags(type: OrderType, timeInForce?: OrderTimeInFo
159
164
  case OrderType.TAKE_PROFIT_MARKET:
160
165
  return OrderFlags.CONDITIONAL;
161
166
 
167
+ case OrderType.TWAP:
168
+ return OrderFlags.TWAP;
169
+
170
+ case OrderType.TWAP_SUBORDER:
171
+ return OrderFlags.TWAP_SUBORDER;
172
+
162
173
  default:
163
174
  throw new Error('Unexpected code path: orderFlags');
164
175
  }
@@ -385,4 +385,30 @@ export default class AccountClient extends RestClient {
385
385
  const uri = `/v4/fundingPayments/parentSubaccount`;
386
386
  return this.get(uri, { address, parentSubaccountNumber, limit, ticker, afterOrAt, page });
387
387
  }
388
+
389
+ // ------ Trade History ------ //
390
+
391
+ async getSubaccountTradeHistory(
392
+ address: string,
393
+ subaccountNumber: number,
394
+ market?: string,
395
+ marketType?: string,
396
+ limit?: number,
397
+ page?: number,
398
+ ): Promise<Data> {
399
+ const uri = `/v4/tradeHistory`;
400
+ return this.get(uri, { address, subaccountNumber, market, marketType, limit, page });
401
+ }
402
+
403
+ async getParentSubaccountNumberTradeHistory(
404
+ address: string,
405
+ parentSubaccountNumber: number,
406
+ market?: string,
407
+ marketType?: string,
408
+ limit?: number,
409
+ page?: number,
410
+ ): Promise<Data> {
411
+ const uri = `/v4/tradeHistory/parentSubaccountNumber`;
412
+ return this.get(uri, { address, parentSubaccountNumber, market, marketType, limit, page });
413
+ }
388
414
  }
@@ -39,6 +39,8 @@ export enum OrderFlags {
39
39
  SHORT_TERM = 0,
40
40
  LONG_TERM = 64,
41
41
  CONDITIONAL = 32,
42
+ TWAP = 128,
43
+ TWAP_SUBORDER = 256,
42
44
  }
43
45
 
44
46
  // TWAP order parameters
@@ -173,12 +173,14 @@ export function verifyOrderFlags(orderFlags: OrderFlags): boolean {
173
173
  return (
174
174
  orderFlags === OrderFlags.SHORT_TERM ||
175
175
  orderFlags === OrderFlags.LONG_TERM ||
176
- orderFlags === OrderFlags.CONDITIONAL
176
+ orderFlags === OrderFlags.CONDITIONAL ||
177
+ orderFlags === OrderFlags.TWAP ||
178
+ orderFlags === OrderFlags.TWAP_SUBORDER
177
179
  );
178
180
  }
179
181
 
180
182
  export function isStatefulOrder(orderFlags: OrderFlags): boolean {
181
- return orderFlags === OrderFlags.LONG_TERM || orderFlags === OrderFlags.CONDITIONAL;
183
+ return orderFlags === OrderFlags.LONG_TERM || orderFlags === OrderFlags.CONDITIONAL || orderFlags === OrderFlags.TWAP || orderFlags === OrderFlags.TWAP_SUBORDER;
182
184
  }
183
185
 
184
186
  function verifyIsBech32(address: string): Error | undefined {
package/CHANGELOG.md DELETED
@@ -1,12 +0,0 @@
1
- # [3.3.0](https://github.com/dydxprotocol/v4-clients/compare/v4-client-js@3.2.0...v4-client-js@3.3.0) (2025-12-12)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * rust test failure ([#460](https://github.com/dydxprotocol/v4-clients/issues/460)) ([c0a6dfd](https://github.com/dydxprotocol/v4-clients/commit/c0a6dfd295975efaaea28e34f8d4a766921badae))
7
-
8
-
9
- ### Features
10
-
11
- * add examples for batch cancel, cancel, and long-term order using permissioned keys ([#462](https://github.com/dydxprotocol/v4-clients/issues/462)) ([5fc63f3](https://github.com/dydxprotocol/v4-clients/commit/5fc63f3677b851e9652125f2009e7046a53c2975))
12
- * Add getHeightWithHeaders to Utility Module ([#464](https://github.com/dydxprotocol/v4-clients/issues/464)) ([074c16e](https://github.com/dydxprotocol/v4-clients/commit/074c16e87c59d39923e78ef3d853641b0679da3b))