@dydxprotocol/v4-client-js 1.1.31 → 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.
- package/README.md +36 -1
- package/__native__/__ios__/v4-native-client.js +59 -6
- package/build/examples/batch_cancel_orders_example.d.ts +1 -0
- package/build/examples/batch_cancel_orders_example.js +93 -0
- package/build/src/clients/composite-client.d.ts +24 -1
- package/build/src/clients/composite-client.js +27 -1
- package/build/src/clients/constants.d.ts +1 -0
- package/build/src/clients/constants.js +3 -2
- package/build/src/clients/lib/registry.js +2 -1
- package/build/src/clients/modules/composer.d.ts +2 -0
- package/build/src/clients/modules/composer.js +16 -1
- package/build/src/clients/modules/post.d.ts +3 -1
- package/build/src/clients/modules/post.js +11 -1
- package/examples/batch_cancel_orders_example.ts +130 -0
- package/package.json +1 -1
- package/src/clients/composite-client.ts +56 -1
- package/src/clients/constants.ts +2 -1
- package/src/clients/lib/registry.ts +3 -0
- package/src/clients/modules/composer.ts +26 -0
- package/src/clients/modules/post.ts +40 -0
|
@@ -40,7 +40,7 @@ import { UserError } from './lib/errors';
|
|
|
40
40
|
import { generateRegistry } from './lib/registry';
|
|
41
41
|
import LocalWallet from './modules/local-wallet';
|
|
42
42
|
import { SubaccountInfo } from './subaccount';
|
|
43
|
-
import { BroadcastMode } from './types';
|
|
43
|
+
import { BroadcastMode, OrderBatch } from './types';
|
|
44
44
|
import { ValidatorClient } from './validator-client';
|
|
45
45
|
|
|
46
46
|
// Required for encoding and decoding queries that are of type Long.
|
|
@@ -58,6 +58,12 @@ export interface MarketInfo {
|
|
|
58
58
|
subticksPerTick: number;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
export interface OrderBatchWithMarketId {
|
|
62
|
+
marketId: string;
|
|
63
|
+
clobPairId?: number;
|
|
64
|
+
clientIds: number[];
|
|
65
|
+
}
|
|
66
|
+
|
|
61
67
|
export class CompositeClient {
|
|
62
68
|
public readonly network: Network;
|
|
63
69
|
public gasDenom: SelectedGasDenom = SelectedGasDenom.USDC;
|
|
@@ -696,6 +702,55 @@ export class CompositeClient {
|
|
|
696
702
|
);
|
|
697
703
|
}
|
|
698
704
|
|
|
705
|
+
/**
|
|
706
|
+
* @description Batch cancel short term orders using marketId to clobPairId translation.
|
|
707
|
+
*
|
|
708
|
+
* @param subaccount The subaccount to cancel the order from
|
|
709
|
+
* @param shortTermOrders The list of short term order batches to cancel with marketId
|
|
710
|
+
* @param goodTilBlock The goodTilBlock of the order to cancel
|
|
711
|
+
* @returns The transaction hash.
|
|
712
|
+
*/
|
|
713
|
+
async batchCancelShortTermOrdersWithMarketId(
|
|
714
|
+
subaccount: SubaccountInfo,
|
|
715
|
+
shortTermOrders: OrderBatchWithMarketId[],
|
|
716
|
+
goodTilBlock: number,
|
|
717
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
718
|
+
const orderBatches = await Promise.all(
|
|
719
|
+
shortTermOrders.map(async ({ marketId, clobPairId, clientIds }) => ({
|
|
720
|
+
clobPairId: (
|
|
721
|
+
clobPairId ??
|
|
722
|
+
(await this.indexerClient.markets.getPerpetualMarkets(marketId)).markets[marketId]
|
|
723
|
+
).clobPairId,
|
|
724
|
+
clientIds }))
|
|
725
|
+
);
|
|
726
|
+
|
|
727
|
+
return this.validatorClient.post.batchCancelShortTermOrders(
|
|
728
|
+
subaccount,
|
|
729
|
+
orderBatches,
|
|
730
|
+
goodTilBlock,
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* @description Batch cancel short term orders using clobPairId.
|
|
736
|
+
*
|
|
737
|
+
* @param subaccount The subaccount to cancel the order from
|
|
738
|
+
* @param shortTermOrders The list of short term order batches to cancel with clobPairId
|
|
739
|
+
* @param goodTilBlock The goodTilBlock of the order to cancel
|
|
740
|
+
* @returns The transaction hash.
|
|
741
|
+
*/
|
|
742
|
+
async batchCancelShortTermOrdersWithClobPairId(
|
|
743
|
+
subaccount: SubaccountInfo,
|
|
744
|
+
shortTermOrders: OrderBatch[],
|
|
745
|
+
goodTilBlock: number,
|
|
746
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
747
|
+
return this.validatorClient.post.batchCancelShortTermOrders(
|
|
748
|
+
subaccount,
|
|
749
|
+
shortTermOrders,
|
|
750
|
+
goodTilBlock,
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
|
|
699
754
|
/**
|
|
700
755
|
* @description Transfer from a subaccount to another subaccount
|
|
701
756
|
*
|
package/src/clients/constants.ts
CHANGED
|
@@ -75,6 +75,7 @@ export const TYPE_URL_MSG_SUBMIT_PROPOSAL = '/cosmos.gov.v1.MsgSubmitProposal';
|
|
|
75
75
|
// x/clob
|
|
76
76
|
export const TYPE_URL_MSG_PLACE_ORDER = '/dydxprotocol.clob.MsgPlaceOrder';
|
|
77
77
|
export const TYPE_URL_MSG_CANCEL_ORDER = '/dydxprotocol.clob.MsgCancelOrder';
|
|
78
|
+
export const TYPE_URL_BATCH_CANCEL = '/dydxprotocol.clob.MsgBatchCancel';
|
|
78
79
|
export const TYPE_URL_MSG_CREATE_CLOB_PAIR = '/dydxprotocol.clob.MsgCreateClobPair';
|
|
79
80
|
export const TYPE_URL_MSG_UPDATE_CLOB_PAIR = '/dydxprotocol.clob.MsgUpdateClobPair';
|
|
80
81
|
|
|
@@ -101,7 +102,7 @@ export const TYPE_URL_MSG_UNDELEGATE = '/cosmos.staking.v1beta1.MsgUndelegate';
|
|
|
101
102
|
export const TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD =
|
|
102
103
|
'/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward';
|
|
103
104
|
|
|
104
|
-
|
|
105
|
+
// ------------ Chain Constants ------------
|
|
105
106
|
// The following are same across different networks / deployments.
|
|
106
107
|
export const GOV_MODULE_ADDRESS = 'dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky';
|
|
107
108
|
export const DELAYMSG_MODULE_ADDRESS = 'dydx1mkkvp26dngu6n8rmalaxyp3gwkjuzztq5zx6tr';
|
|
@@ -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
|
|
|
@@ -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,
|