@dydxprotocol/v4-client-js 2.2.0 → 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 -12
- package/build/esm/src/clients/composite-client.d.ts +6 -2
- package/build/esm/src/clients/composite-client.d.ts.map +1 -1
- package/build/esm/src/clients/composite-client.js +19 -18
- package/build/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/clients/composite-client.ts +75 -107
package/package.json
CHANGED
|
@@ -104,6 +104,12 @@ export type CancelRawOrderPayload = {
|
|
|
104
104
|
goodTilBlockTime?: number;
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
+
export type TransferToSubaccountPayload = {
|
|
108
|
+
sourceSubaccountNumber: number;
|
|
109
|
+
recipientSubaccountNumber: number;
|
|
110
|
+
transferAmount: string;
|
|
111
|
+
};
|
|
112
|
+
|
|
107
113
|
export class CompositeClient {
|
|
108
114
|
public readonly network: Network;
|
|
109
115
|
public gasDenom: SelectedGasDenom = SelectedGasDenom.USDC;
|
|
@@ -1108,71 +1114,11 @@ export class CompositeClient {
|
|
|
1108
1114
|
return Buffer.from(signature).toString('base64');
|
|
1109
1115
|
}
|
|
1110
1116
|
|
|
1111
|
-
async
|
|
1112
|
-
sourceSubaccount: SubaccountInfo,
|
|
1113
|
-
recipientSubaccountNumber: number,
|
|
1114
|
-
transferAmount: string,
|
|
1115
|
-
placeOrderPayload: Omit<PlaceOrderPayload, 'subaccountNumber'>,
|
|
1116
|
-
memo?: string,
|
|
1117
|
-
broadcastMode?: BroadcastMode,
|
|
1118
|
-
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
1119
|
-
const orderFlags = calculateOrderFlags(placeOrderPayload.type, placeOrderPayload.timeInForce);
|
|
1120
|
-
if (orderFlags === OrderFlags.SHORT_TERM) {
|
|
1121
|
-
throw new Error('SHORT_TERM orders cannot be batched with transfers');
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
const recipientSubaccount = new SubaccountInfo(
|
|
1125
|
-
sourceSubaccount.wallet,
|
|
1126
|
-
recipientSubaccountNumber,
|
|
1127
|
-
);
|
|
1128
|
-
|
|
1129
|
-
const account: Promise<Account> = this.validatorClient.post.account(
|
|
1130
|
-
recipientSubaccount.address,
|
|
1131
|
-
orderFlags,
|
|
1132
|
-
);
|
|
1133
|
-
|
|
1134
|
-
return this.send(
|
|
1135
|
-
sourceSubaccount.wallet,
|
|
1136
|
-
async () => {
|
|
1137
|
-
const transferMsg = this.transferToSubaccountMessage(
|
|
1138
|
-
sourceSubaccount,
|
|
1139
|
-
recipientSubaccount.address,
|
|
1140
|
-
recipientSubaccountNumber,
|
|
1141
|
-
transferAmount,
|
|
1142
|
-
);
|
|
1143
|
-
|
|
1144
|
-
const placeOrderMsg = await this.placeOrderMessage(
|
|
1145
|
-
recipientSubaccount,
|
|
1146
|
-
placeOrderPayload.marketId,
|
|
1147
|
-
placeOrderPayload.type,
|
|
1148
|
-
placeOrderPayload.side,
|
|
1149
|
-
placeOrderPayload.price,
|
|
1150
|
-
placeOrderPayload.size,
|
|
1151
|
-
placeOrderPayload.clientId,
|
|
1152
|
-
placeOrderPayload.timeInForce,
|
|
1153
|
-
placeOrderPayload.goodTilTimeInSeconds,
|
|
1154
|
-
placeOrderPayload.execution,
|
|
1155
|
-
placeOrderPayload.postOnly,
|
|
1156
|
-
placeOrderPayload.reduceOnly,
|
|
1157
|
-
placeOrderPayload.triggerPrice,
|
|
1158
|
-
placeOrderPayload.marketInfo,
|
|
1159
|
-
placeOrderPayload.currentHeight,
|
|
1160
|
-
placeOrderPayload.goodTilBlock,
|
|
1161
|
-
);
|
|
1162
|
-
|
|
1163
|
-
return [transferMsg, placeOrderMsg];
|
|
1164
|
-
},
|
|
1165
|
-
true,
|
|
1166
|
-
undefined,
|
|
1167
|
-
memo,
|
|
1168
|
-
broadcastMode ?? Method.BroadcastTxCommit,
|
|
1169
|
-
() => account,
|
|
1170
|
-
);
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
async bulkCancelAndPlaceStatefulOrders(
|
|
1117
|
+
async bulkCancelAndTransferAndPlaceStatefulOrders(
|
|
1174
1118
|
subaccount: SubaccountInfo,
|
|
1119
|
+
// these are executed in this order, all in one block, and all succeed or all fail
|
|
1175
1120
|
cancelOrderPayloads: CancelRawOrderPayload[],
|
|
1121
|
+
transferToSubaccountPayload: TransferToSubaccountPayload | undefined,
|
|
1176
1122
|
placeOrderPayloads: PlaceOrderPayload[],
|
|
1177
1123
|
memo?: string,
|
|
1178
1124
|
broadcastMode?: BroadcastMode,
|
|
@@ -1196,52 +1142,74 @@ export class CompositeClient {
|
|
|
1196
1142
|
undefined,
|
|
1197
1143
|
);
|
|
1198
1144
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
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
|
+
})();
|
|
1217
1177
|
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
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
|
+
})();
|
|
1242
1209
|
|
|
1243
|
-
|
|
1244
|
-
|
|
1210
|
+
return this.send(
|
|
1211
|
+
subaccount.wallet,
|
|
1212
|
+
() => msgs,
|
|
1245
1213
|
true,
|
|
1246
1214
|
undefined,
|
|
1247
1215
|
memo,
|