@dydxprotocol/v4-client-js 3.1.1 → 3.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dydxprotocol/v4-client-js",
3
- "version": "3.1.1",
3
+ "version": "3.2.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",
@@ -82,6 +82,7 @@ export const TYPE_URL_MSG_CANCEL_ORDER = '/dydxprotocol.clob.MsgCancelOrder';
82
82
  export const TYPE_URL_BATCH_CANCEL = '/dydxprotocol.clob.MsgBatchCancel';
83
83
  export const TYPE_URL_MSG_CREATE_CLOB_PAIR = '/dydxprotocol.clob.MsgCreateClobPair';
84
84
  export const TYPE_URL_MSG_UPDATE_CLOB_PAIR = '/dydxprotocol.clob.MsgUpdateClobPair';
85
+ export const TYPE_URL_MSG_UPDATE_LEVERAGE = '/dydxprotocol.clob.MsgUpdateLeverage';
85
86
 
86
87
  // x/delaymsg
87
88
  export const TYPE_URL_MSG_DELAY_MESSAGE = '/dydxprotocol.delaymsg.MsgDelayMessage';
@@ -1,6 +1,9 @@
1
1
  import { GeneratedType, Registry } from '@cosmjs/proto-signing';
2
2
  import { defaultRegistryTypes } from '@cosmjs/stargate';
3
- import { MsgAddAuthenticator, MsgRemoveAuthenticator } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
3
+ import {
4
+ MsgAddAuthenticator,
5
+ MsgRemoveAuthenticator,
6
+ } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
4
7
  import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
5
8
  import {
6
9
  MsgPlaceOrder,
@@ -8,6 +11,7 @@ import {
8
11
  MsgCreateClobPair,
9
12
  MsgUpdateClobPair,
10
13
  MsgBatchCancel,
14
+ MsgUpdateLeverage,
11
15
  } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/tx';
12
16
  import { MsgDelayMessage } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/delaymsg/tx';
13
17
  import { MsgCreateMarketPermissionless } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx';
@@ -41,6 +45,7 @@ import {
41
45
  TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS,
42
46
  TYPE_URL_MSG_ADD_AUTHENTICATOR,
43
47
  TYPE_URL_MSG_REMOVE_AUTHENTICATOR,
48
+ TYPE_URL_MSG_UPDATE_LEVERAGE,
44
49
  } from '../constants';
45
50
 
46
51
  export const registry: ReadonlyArray<[string, GeneratedType]> = [];
@@ -52,6 +57,7 @@ export function generateRegistry(): Registry {
52
57
  [TYPE_URL_BATCH_CANCEL, MsgBatchCancel as GeneratedType],
53
58
  [TYPE_URL_MSG_CREATE_CLOB_PAIR, MsgCreateClobPair as GeneratedType],
54
59
  [TYPE_URL_MSG_UPDATE_CLOB_PAIR, MsgUpdateClobPair as GeneratedType],
60
+ [TYPE_URL_MSG_UPDATE_LEVERAGE, MsgUpdateLeverage as GeneratedType],
55
61
 
56
62
  // delaymsg
57
63
  [TYPE_URL_MSG_DELAY_MESSAGE, MsgDelayMessage as GeneratedType],
@@ -77,7 +83,6 @@ export function generateRegistry(): Registry {
77
83
  // affiliates
78
84
  [TYPE_URL_MSG_REGISTER_AFFILIATE, MsgRegisterAffiliate as GeneratedType],
79
85
 
80
-
81
86
  // authentication
82
87
  [TYPE_URL_MSG_ADD_AUTHENTICATOR, MsgAddAuthenticator as GeneratedType],
83
88
  [TYPE_URL_MSG_REMOVE_AUTHENTICATOR, MsgRemoveAuthenticator as GeneratedType],
@@ -7,13 +7,18 @@ import {
7
7
  MsgDelegate,
8
8
  MsgUndelegate,
9
9
  } from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/tx';
10
- import { MsgAddAuthenticator, MsgRemoveAuthenticator } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
10
+ import {
11
+ MsgAddAuthenticator,
12
+ MsgRemoveAuthenticator,
13
+ } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
11
14
  import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
12
15
  import { ClobPair_Status } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/clob_pair';
13
16
  import {
17
+ LeverageEntry,
14
18
  MsgBatchCancel,
15
19
  MsgCreateClobPair,
16
20
  MsgUpdateClobPair,
21
+ MsgUpdateLeverage,
17
22
  OrderBatch,
18
23
  } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/tx';
19
24
  import { MsgDelayMessage } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/delaymsg/tx';
@@ -56,6 +61,7 @@ import {
56
61
  TYPE_URL_MSG_ADD_AUTHENTICATOR,
57
62
  TYPE_URL_MSG_REMOVE_AUTHENTICATOR,
58
63
  AuthenticatorType,
64
+ TYPE_URL_MSG_UPDATE_LEVERAGE,
59
65
  } from '../constants';
60
66
  import { DenomConfig, ITwapParameters, IBuilderCodeParameters } from '../types';
61
67
  import {
@@ -97,7 +103,7 @@ export class Composer {
97
103
  conditionalOrderTriggerSubticks: Long = Long.fromInt(0),
98
104
  twapParameters?: ITwapParameters,
99
105
  builderCodeParameters?: IBuilderCodeParameters,
100
- orderRouterAddress: string = "",
106
+ orderRouterAddress: string = '',
101
107
  ): EncodeObject {
102
108
  this.validateGoodTilBlockAndTime(orderFlags, goodTilBlock, goodTilBlockTime);
103
109
 
@@ -252,6 +258,27 @@ export class Composer {
252
258
  };
253
259
  }
254
260
 
261
+ public composeMsgUpdateLeverage(
262
+ address: string,
263
+ subaccountNumber: number,
264
+ entries: LeverageEntry[],
265
+ ): EncodeObject {
266
+ const subaccountId: SubaccountId = {
267
+ owner: address,
268
+ number: subaccountNumber,
269
+ };
270
+
271
+ const msg: MsgUpdateLeverage = {
272
+ subaccountId,
273
+ clobPairLeverage: entries,
274
+ };
275
+
276
+ return {
277
+ typeUrl: TYPE_URL_MSG_UPDATE_LEVERAGE,
278
+ value: msg,
279
+ };
280
+ }
281
+
255
282
  // ------------ x/sending ------------
256
283
  public composeMsgTransfer(
257
284
  address: string,
@@ -577,13 +604,13 @@ export class Composer {
577
604
 
578
605
  const msg: MsgCreateMarketPermissionless = {
579
606
  ticker,
580
- subaccountId
607
+ subaccountId,
581
608
  };
582
609
 
583
610
  return {
584
611
  typeUrl: TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS,
585
612
  value: msg,
586
- }
613
+ };
587
614
  }
588
615
 
589
616
  // ----------- x/accountplus --------
@@ -597,27 +624,24 @@ export class Composer {
597
624
  sender: address,
598
625
  authenticatorType,
599
626
  data,
600
- }
627
+ };
601
628
 
602
629
  return {
603
630
  typeUrl: TYPE_URL_MSG_ADD_AUTHENTICATOR,
604
631
  value: msg,
605
- }
632
+ };
606
633
  }
607
634
 
608
- public composeMsgRemoveAuthenticator(
609
- address: string,
610
- id: Long,
611
- ): EncodeObject {
635
+ public composeMsgRemoveAuthenticator(address: string, id: Long): EncodeObject {
612
636
  const msg: MsgRemoveAuthenticator = {
613
637
  sender: address,
614
638
  id,
615
- }
639
+ };
616
640
 
617
641
  return {
618
642
  typeUrl: TYPE_URL_MSG_REMOVE_AUTHENTICATOR,
619
643
  value: msg,
620
- }
644
+ };
621
645
  }
622
646
 
623
647
  // ------------ util ------------
@@ -364,6 +364,22 @@ export class Get {
364
364
  return ClobModule.QueryEquityTierLimitConfigurationResponse.decode(data);
365
365
  }
366
366
 
367
+ /**
368
+ * @description Get user leverage settings for a given subaccount
369
+ * @returns User set leverage for all clob pairs
370
+ */
371
+ async getPerpetualMarketsLeverage(
372
+ address: string,
373
+ subaccountNumber: number,
374
+ ): Promise<ClobModule.QueryLeverageResponse> {
375
+ const requestData: Uint8Array = Uint8Array.from(
376
+ ClobModule.QueryLeverageRequest.encode({ owner: address, number: subaccountNumber }).finish(),
377
+ );
378
+
379
+ const data: Uint8Array = await this.sendQuery('/dydxprotocol.clob.Query/Leverage', requestData);
380
+ return ClobModule.QueryLeverageResponse.decode(data);
381
+ }
382
+
367
383
  /**
368
384
  *
369
385
  * @description Get all delegations from a delegator.
@@ -34,6 +34,7 @@ import {
34
34
  MsgCancelOrder,
35
35
  Order_ConditionType,
36
36
  OrderBatch,
37
+ LeverageEntry,
37
38
  } from './proto-includes';
38
39
 
39
40
  // Required for encoding and decoding queries that are of type Long.
@@ -628,6 +629,38 @@ export class Post {
628
629
  });
629
630
  }
630
631
 
632
+ async updatePerpetualMarketsLeverage(
633
+ subaccount: SubaccountInfo,
634
+ address: string,
635
+ entries: LeverageEntry[],
636
+ broadcastMode?: BroadcastMode,
637
+ ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
638
+ const msg = await this.updatePerpetualMarketsLeverageMsg(subaccount, address, entries);
639
+ return this.send(
640
+ subaccount,
641
+ () => Promise.resolve([msg]),
642
+ false,
643
+ undefined,
644
+ undefined,
645
+ broadcastMode,
646
+ );
647
+ }
648
+
649
+ async updatePerpetualMarketsLeverageMsg(
650
+ subaccount: SubaccountInfo,
651
+ address: string,
652
+ entries: LeverageEntry[],
653
+ ): Promise<EncodeObject> {
654
+ return new Promise((resolve) => {
655
+ const msg = this.composer.composeMsgUpdateLeverage(
656
+ address,
657
+ subaccount.subaccountNumber,
658
+ entries,
659
+ );
660
+ resolve(msg);
661
+ });
662
+ }
663
+
631
664
  async transfer(
632
665
  subaccount: SubaccountInfo,
633
666
  recipientAddress: string,