@dydxprotocol/v4-client-js 2.1.1 → 2.3.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/CHANGELOG.md +9 -2
- package/build/esm/src/clients/composite-client.d.ts +32 -0
- package/build/esm/src/clients/composite-client.d.ts.map +1 -1
- package/build/esm/src/clients/composite-client.js +38 -4
- package/build/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/clients/composite-client.ts +139 -2
package/package.json
CHANGED
|
@@ -76,6 +76,40 @@ export interface PermissionedKeysAccountAuth {
|
|
|
76
76
|
accountForOrder: SubaccountInfo;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
export type PlaceOrderPayload = {
|
|
80
|
+
subaccountNumber: number;
|
|
81
|
+
marketId: string;
|
|
82
|
+
type: OrderType;
|
|
83
|
+
side: OrderSide;
|
|
84
|
+
price: number;
|
|
85
|
+
size: number;
|
|
86
|
+
clientId: number;
|
|
87
|
+
timeInForce?: OrderTimeInForce;
|
|
88
|
+
goodTilTimeInSeconds?: number;
|
|
89
|
+
execution?: OrderExecution;
|
|
90
|
+
postOnly?: boolean;
|
|
91
|
+
reduceOnly?: boolean;
|
|
92
|
+
triggerPrice?: number;
|
|
93
|
+
marketInfo?: MarketInfo;
|
|
94
|
+
currentHeight?: number;
|
|
95
|
+
goodTilBlock?: number;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type CancelRawOrderPayload = {
|
|
99
|
+
subaccountNumber: number;
|
|
100
|
+
clientId: number;
|
|
101
|
+
orderFlags: OrderFlags;
|
|
102
|
+
clobPairId: number;
|
|
103
|
+
goodTilBlock?: number;
|
|
104
|
+
goodTilBlockTime?: number;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type TransferToSubaccountPayload = {
|
|
108
|
+
sourceSubaccountNumber: number;
|
|
109
|
+
recipientSubaccountNumber: number;
|
|
110
|
+
transferAmount: string;
|
|
111
|
+
};
|
|
112
|
+
|
|
79
113
|
export class CompositeClient {
|
|
80
114
|
public readonly network: Network;
|
|
81
115
|
public gasDenom: SelectedGasDenom = SelectedGasDenom.USDC;
|
|
@@ -476,7 +510,6 @@ export class CompositeClient {
|
|
|
476
510
|
type: OrderType,
|
|
477
511
|
side: OrderSide,
|
|
478
512
|
price: number,
|
|
479
|
-
// trigger_price: number, // not used for MARKET and LIMIT
|
|
480
513
|
size: number,
|
|
481
514
|
clientId: number,
|
|
482
515
|
timeInForce?: OrderTimeInForce,
|
|
@@ -1081,6 +1114,110 @@ export class CompositeClient {
|
|
|
1081
1114
|
return Buffer.from(signature).toString('base64');
|
|
1082
1115
|
}
|
|
1083
1116
|
|
|
1117
|
+
async bulkCancelAndTransferAndPlaceStatefulOrders(
|
|
1118
|
+
subaccount: SubaccountInfo,
|
|
1119
|
+
// these are executed in this order, all in one block, and all succeed or all fail
|
|
1120
|
+
cancelOrderPayloads: CancelRawOrderPayload[],
|
|
1121
|
+
transferToSubaccountPayload: TransferToSubaccountPayload | undefined,
|
|
1122
|
+
placeOrderPayloads: PlaceOrderPayload[],
|
|
1123
|
+
memo?: string,
|
|
1124
|
+
broadcastMode?: BroadcastMode,
|
|
1125
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
1126
|
+
if (cancelOrderPayloads.some((c) => c.orderFlags === OrderFlags.SHORT_TERM)) {
|
|
1127
|
+
throw new Error('SHORT_TERM cancels cannot be batched');
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
if (
|
|
1131
|
+
placeOrderPayloads.some(
|
|
1132
|
+
(placePayload) =>
|
|
1133
|
+
calculateOrderFlags(placePayload.type, placePayload.timeInForce) ===
|
|
1134
|
+
OrderFlags.SHORT_TERM,
|
|
1135
|
+
)
|
|
1136
|
+
) {
|
|
1137
|
+
throw new Error('SHORT_TERM orders cannot be batched');
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
const account: Promise<Account> = this.validatorClient.post.account(
|
|
1141
|
+
subaccount.address,
|
|
1142
|
+
undefined,
|
|
1143
|
+
);
|
|
1144
|
+
|
|
1145
|
+
const msgs: Promise<EncodeObject[]> = (async () => {
|
|
1146
|
+
const cancelMsgPromises = cancelOrderPayloads.map(async (cancelPayload) => {
|
|
1147
|
+
const cancelSubaccount = new SubaccountInfo(
|
|
1148
|
+
subaccount.wallet,
|
|
1149
|
+
cancelPayload.subaccountNumber,
|
|
1150
|
+
);
|
|
1151
|
+
return this.validatorClient.post.cancelOrderMsg(
|
|
1152
|
+
cancelSubaccount.address,
|
|
1153
|
+
cancelSubaccount.subaccountNumber,
|
|
1154
|
+
cancelPayload.clientId,
|
|
1155
|
+
cancelPayload.orderFlags,
|
|
1156
|
+
cancelPayload.clobPairId,
|
|
1157
|
+
cancelPayload.goodTilBlock,
|
|
1158
|
+
cancelPayload.goodTilBlockTime,
|
|
1159
|
+
);
|
|
1160
|
+
});
|
|
1161
|
+
|
|
1162
|
+
const transferMsg = (() => {
|
|
1163
|
+
if (transferToSubaccountPayload == null) {
|
|
1164
|
+
return undefined;
|
|
1165
|
+
}
|
|
1166
|
+
const transferSubaccount = new SubaccountInfo(
|
|
1167
|
+
subaccount.wallet,
|
|
1168
|
+
transferToSubaccountPayload?.sourceSubaccountNumber,
|
|
1169
|
+
);
|
|
1170
|
+
return this.transferToSubaccountMessage(
|
|
1171
|
+
transferSubaccount,
|
|
1172
|
+
transferSubaccount.address,
|
|
1173
|
+
transferToSubaccountPayload.recipientSubaccountNumber,
|
|
1174
|
+
transferToSubaccountPayload.transferAmount,
|
|
1175
|
+
);
|
|
1176
|
+
})();
|
|
1177
|
+
|
|
1178
|
+
const placeOrderMsgPromises = placeOrderPayloads.map((placePayload) => {
|
|
1179
|
+
const placeSubaccount = new SubaccountInfo(
|
|
1180
|
+
subaccount.wallet,
|
|
1181
|
+
placePayload.subaccountNumber,
|
|
1182
|
+
);
|
|
1183
|
+
return this.placeOrderMessage(
|
|
1184
|
+
placeSubaccount,
|
|
1185
|
+
placePayload.marketId,
|
|
1186
|
+
placePayload.type,
|
|
1187
|
+
placePayload.side,
|
|
1188
|
+
placePayload.price,
|
|
1189
|
+
placePayload.size,
|
|
1190
|
+
placePayload.clientId,
|
|
1191
|
+
placePayload.timeInForce,
|
|
1192
|
+
placePayload.goodTilTimeInSeconds,
|
|
1193
|
+
placePayload.execution,
|
|
1194
|
+
placePayload.postOnly,
|
|
1195
|
+
placePayload.reduceOnly,
|
|
1196
|
+
placePayload.triggerPrice,
|
|
1197
|
+
placePayload.marketInfo,
|
|
1198
|
+
placePayload.currentHeight,
|
|
1199
|
+
placePayload.goodTilBlock,
|
|
1200
|
+
);
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
return Promise.all([
|
|
1204
|
+
...cancelMsgPromises,
|
|
1205
|
+
...(transferMsg != null ? [transferMsg] : []),
|
|
1206
|
+
...placeOrderMsgPromises,
|
|
1207
|
+
]);
|
|
1208
|
+
})();
|
|
1209
|
+
|
|
1210
|
+
return this.send(
|
|
1211
|
+
subaccount.wallet,
|
|
1212
|
+
() => msgs,
|
|
1213
|
+
true,
|
|
1214
|
+
undefined,
|
|
1215
|
+
memo,
|
|
1216
|
+
broadcastMode ?? Method.BroadcastTxCommit,
|
|
1217
|
+
() => account,
|
|
1218
|
+
);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1084
1221
|
// vaults
|
|
1085
1222
|
|
|
1086
1223
|
async depositToMegavault(
|
|
@@ -1302,7 +1439,7 @@ export class CompositeClient {
|
|
|
1302
1439
|
|
|
1303
1440
|
// The top-level authenticator must pass validation
|
|
1304
1441
|
if (!checkAuthenticator(authenticator)) {
|
|
1305
|
-
return false
|
|
1442
|
+
return false;
|
|
1306
1443
|
}
|
|
1307
1444
|
|
|
1308
1445
|
return true;
|