@dydxprotocol/v4-client-js 1.1.30 → 1.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.
@@ -5,6 +5,7 @@ import {
5
5
  MsgCancelOrder,
6
6
  MsgCreateClobPair,
7
7
  MsgUpdateClobPair,
8
+ MsgBatchCancel,
8
9
  } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/tx';
9
10
  import { MsgDelayMessage } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/delaymsg/tx';
10
11
  import { MsgCreatePerpetual } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/tx';
@@ -26,6 +27,7 @@ import {
26
27
  TYPE_URL_MSG_CREATE_TRANSFER,
27
28
  TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT,
28
29
  TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT,
30
+ TYPE_URL_BATCH_CANCEL,
29
31
  } from '../constants';
30
32
 
31
33
  export const registry: ReadonlyArray<[string, GeneratedType]> = [];
@@ -34,6 +36,7 @@ export function generateRegistry(): Registry {
34
36
  // clob
35
37
  [TYPE_URL_MSG_PLACE_ORDER, MsgPlaceOrder as GeneratedType],
36
38
  [TYPE_URL_MSG_CANCEL_ORDER, MsgCancelOrder as GeneratedType],
39
+ [TYPE_URL_BATCH_CANCEL, MsgBatchCancel as GeneratedType],
37
40
  [TYPE_URL_MSG_CREATE_CLOB_PAIR, MsgCreateClobPair as GeneratedType],
38
41
  [TYPE_URL_MSG_UPDATE_CLOB_PAIR, MsgUpdateClobPair as GeneratedType],
39
42
 
@@ -175,8 +175,10 @@ export default class AccountClient extends RestClient {
175
175
  async getSubaccountHistoricalPNLs(
176
176
  address: string,
177
177
  subaccountNumber: number,
178
- effectiveBeforeOrAt?: string | null,
179
- effectiveAtOrAfter?: string | null,
178
+ createdBeforeOrAtHeight?: number | null,
179
+ createdBeforeOrAt?: string | null,
180
+ createdOnOrAfterHeight?: number | null,
181
+ createdOnOrAfter?: string | null,
180
182
  limit?: number | null,
181
183
  page?: number | null,
182
184
  ): Promise<Data> {
@@ -184,8 +186,10 @@ export default class AccountClient extends RestClient {
184
186
  return this.get(uri, {
185
187
  address,
186
188
  subaccountNumber,
187
- effectiveBeforeOrAt,
188
- effectiveAtOrAfter,
189
+ createdBeforeOrAtHeight,
190
+ createdBeforeOrAt,
191
+ createdOnOrAfterHeight,
192
+ createdOnOrAfter,
189
193
  limit,
190
194
  page,
191
195
  });
@@ -9,8 +9,10 @@ import {
9
9
  } from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/tx';
10
10
  import { ClobPair_Status } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/clob_pair';
11
11
  import {
12
+ MsgBatchCancel,
12
13
  MsgCreateClobPair,
13
14
  MsgUpdateClobPair,
15
+ OrderBatch,
14
16
  } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/tx';
15
17
  import { MsgDelayMessage } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/delaymsg/tx';
16
18
  import { PerpetualMarketType } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/perpetual';
@@ -40,6 +42,7 @@ import {
40
42
  TYPE_URL_MSG_DELEGATE,
41
43
  TYPE_URL_MSG_UNDELEGATE,
42
44
  TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD,
45
+ TYPE_URL_BATCH_CANCEL,
43
46
  } from '../constants';
44
47
  import { DenomConfig } from '../types';
45
48
  import {
@@ -149,6 +152,29 @@ export class Composer {
149
152
  };
150
153
  }
151
154
 
155
+ public composeMsgBatchCancelShortTermOrders(
156
+ address: string,
157
+ subaccountNumber: number,
158
+ shortTermCancels: OrderBatch[],
159
+ goodTilBlock: number,
160
+ ): EncodeObject {
161
+ const subaccountId: SubaccountId = {
162
+ owner: address,
163
+ number: subaccountNumber,
164
+ };
165
+
166
+ const msg: MsgBatchCancel = {
167
+ subaccountId,
168
+ shortTermCancels,
169
+ goodTilBlock,
170
+ };
171
+
172
+ return {
173
+ typeUrl: TYPE_URL_BATCH_CANCEL,
174
+ value: msg,
175
+ };
176
+ }
177
+
152
178
  public composeMsgCreateClobPair(
153
179
  clobId: number,
154
180
  perpetualId: number,
@@ -33,6 +33,7 @@ import {
33
33
  MsgPlaceOrder,
34
34
  MsgCancelOrder,
35
35
  Order_ConditionType,
36
+ OrderBatch,
36
37
  } from './proto-includes';
37
38
 
38
39
  // Required for encoding and decoding queries that are of type Long.
@@ -520,6 +521,45 @@ export class Post {
520
521
  );
521
522
  }
522
523
 
524
+ async batchCancelShortTermOrders(
525
+ subaccount: SubaccountInfo,
526
+ shortTermOrders: OrderBatch[],
527
+ goodTilBlock: number,
528
+ broadcastMode?: BroadcastMode,
529
+ ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
530
+ const msg = await this.batchCancelShortTermOrdersMsg(
531
+ subaccount.address,
532
+ subaccount.subaccountNumber,
533
+ shortTermOrders,
534
+ goodTilBlock,
535
+ );
536
+ return this.send(
537
+ subaccount.wallet,
538
+ () => Promise.resolve([msg]),
539
+ true,
540
+ undefined,
541
+ undefined,
542
+ broadcastMode,
543
+ );
544
+ }
545
+
546
+ async batchCancelShortTermOrdersMsg(
547
+ address: string,
548
+ subaccountNumber: number,
549
+ shortTermOrders: OrderBatch[],
550
+ goodTilBlock: number,
551
+ ): Promise<EncodeObject> {
552
+ return new Promise((resolve) => {
553
+ const msg = this.composer.composeMsgBatchCancelShortTermOrders(
554
+ address,
555
+ subaccountNumber,
556
+ shortTermOrders,
557
+ goodTilBlock,
558
+ );
559
+ resolve(msg);
560
+ });
561
+ }
562
+
523
563
  async transfer(
524
564
  subaccount: SubaccountInfo,
525
565
  recipientAddress: string,
@@ -47,7 +47,7 @@ declare global {
47
47
  var hdKey: {
48
48
  privateKey: Uint8Array | null;
49
49
  publicKey: Uint8Array | null;
50
- }
50
+ };
51
51
 
52
52
  // eslint-disable-next-line vars-on-top, no-var
53
53
  var nobleClient: NobleClient | undefined;
@@ -174,8 +174,9 @@ export async function deriveMnemomicFromEthereumSignature(signature: string): Pr
174
174
  const { mnemonic, privateKey, publicKey } = deriveHDKeyFromEthereumSignature(signature);
175
175
  const wallet = await LocalWallet.fromMnemonic(mnemonic, BECH32_PREFIX);
176
176
  globalThis.hdKey = {
177
- privateKey, publicKey
178
- }
177
+ privateKey,
178
+ publicKey,
179
+ };
179
180
  const result = { mnemonic, address: wallet.address! };
180
181
  return new Promise((resolve) => {
181
182
  resolve(encodeJson(result));
@@ -293,15 +294,15 @@ export async function placeOrder(payload: string): Promise<string> {
293
294
  throw new UserError('clientId is not set');
294
295
  }
295
296
  const timeInForce = json.timeInForce;
296
- const goodTilTimeInSeconds = json.goodTilTimeInSeconds;
297
- const goodTilBlock = json.goodTilBlock;
297
+ const goodTilTimeInSeconds = json.goodTilTimeInSeconds ?? 0;
298
+ const goodTilBlock = json.goodTilBlock ?? undefined;
298
299
  const execution = json.execution;
299
300
  const postOnly = json.postOnly ?? false;
300
301
  const reduceOnly = json.reduceOnly ?? false;
301
- const triggerPrice = json.triggerPrice;
302
+ const triggerPrice = json.triggerPrice ?? undefined;
302
303
 
303
- const marketInfo = json.marketInfo as MarketInfo;
304
- const currentHeight = json.currentHeight as number;
304
+ const marketInfo = (json.marketInfo as MarketInfo) ?? undefined;
305
+ const currentHeight = (json.currentHeight as number) ?? undefined;
305
306
 
306
307
  const subaccount = new SubaccountInfo(wallet, subaccountNumber);
307
308
  const tx = await client.placeOrder(
@@ -1287,11 +1288,11 @@ export async function signCompliancePayload(payload: string): Promise<string> {
1287
1288
  if (!globalThis.hdKey?.privateKey || !globalThis.hdKey?.publicKey) {
1288
1289
  throw new Error('Missing hdKey');
1289
1290
  }
1290
-
1291
+
1291
1292
  const timestampInSeconds = Math.floor(Date.now() / 1000);
1292
1293
  const messageToSign: string = `${message}:${action}"${currentStatus ?? ''}:${timestampInSeconds}`;
1293
1294
  const messageHash = sha256(Buffer.from(messageToSign));
1294
-
1295
+
1295
1296
  const signed = await Secp256k1.createSignature(messageHash, globalThis.hdKey.privateKey);
1296
1297
  const signedMessage = signed.toFixedLength();
1297
1298
 
@@ -1316,4 +1317,4 @@ export async function setSelectedGasDenom(gasDenom: string): Promise<string> {
1316
1317
  } catch (error) {
1317
1318
  return wrappedError(error);
1318
1319
  }
1319
- }
1320
+ }