@dydxprotocol/v4-client-js 2.1.0 → 2.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/CHANGELOG.md +12 -7
- package/build/esm/src/clients/composite-client.d.ts +28 -0
- package/build/esm/src/clients/composite-client.d.ts.map +1 -1
- package/build/esm/src/clients/composite-client.js +37 -4
- package/build/esm/src/clients/modules/account.js +2 -2
- package/build/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/clients/composite-client.ts +171 -2
- package/src/clients/modules/account.ts +1 -1
package/package.json
CHANGED
|
@@ -76,6 +76,34 @@ 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
|
+
|
|
79
107
|
export class CompositeClient {
|
|
80
108
|
public readonly network: Network;
|
|
81
109
|
public gasDenom: SelectedGasDenom = SelectedGasDenom.USDC;
|
|
@@ -476,7 +504,6 @@ export class CompositeClient {
|
|
|
476
504
|
type: OrderType,
|
|
477
505
|
side: OrderSide,
|
|
478
506
|
price: number,
|
|
479
|
-
// trigger_price: number, // not used for MARKET and LIMIT
|
|
480
507
|
size: number,
|
|
481
508
|
clientId: number,
|
|
482
509
|
timeInForce?: OrderTimeInForce,
|
|
@@ -1081,6 +1108,148 @@ export class CompositeClient {
|
|
|
1081
1108
|
return Buffer.from(signature).toString('base64');
|
|
1082
1109
|
}
|
|
1083
1110
|
|
|
1111
|
+
async transferToSubaccountAndPlaceStatefulOrder(
|
|
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(
|
|
1174
|
+
subaccount: SubaccountInfo,
|
|
1175
|
+
cancelOrderPayloads: CancelRawOrderPayload[],
|
|
1176
|
+
placeOrderPayloads: PlaceOrderPayload[],
|
|
1177
|
+
memo?: string,
|
|
1178
|
+
broadcastMode?: BroadcastMode,
|
|
1179
|
+
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
1180
|
+
if (cancelOrderPayloads.some((c) => c.orderFlags === OrderFlags.SHORT_TERM)) {
|
|
1181
|
+
throw new Error('SHORT_TERM cancels cannot be batched');
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
if (
|
|
1185
|
+
placeOrderPayloads.some(
|
|
1186
|
+
(placePayload) =>
|
|
1187
|
+
calculateOrderFlags(placePayload.type, placePayload.timeInForce) ===
|
|
1188
|
+
OrderFlags.SHORT_TERM,
|
|
1189
|
+
)
|
|
1190
|
+
) {
|
|
1191
|
+
throw new Error('SHORT_TERM orders cannot be batched');
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
const account: Promise<Account> = this.validatorClient.post.account(
|
|
1195
|
+
subaccount.address,
|
|
1196
|
+
undefined,
|
|
1197
|
+
);
|
|
1198
|
+
|
|
1199
|
+
return this.send(
|
|
1200
|
+
subaccount.wallet,
|
|
1201
|
+
async () => {
|
|
1202
|
+
const cancelMsgPromises = cancelOrderPayloads.map(async (cancelPayload) => {
|
|
1203
|
+
const cancelSubaccount = new SubaccountInfo(
|
|
1204
|
+
subaccount.wallet,
|
|
1205
|
+
cancelPayload.subaccountNumber,
|
|
1206
|
+
);
|
|
1207
|
+
return this.validatorClient.post.cancelOrderMsg(
|
|
1208
|
+
cancelSubaccount.address,
|
|
1209
|
+
cancelSubaccount.subaccountNumber,
|
|
1210
|
+
cancelPayload.clientId,
|
|
1211
|
+
cancelPayload.orderFlags,
|
|
1212
|
+
cancelPayload.clobPairId,
|
|
1213
|
+
cancelPayload.goodTilBlock,
|
|
1214
|
+
cancelPayload.goodTilBlockTime,
|
|
1215
|
+
);
|
|
1216
|
+
});
|
|
1217
|
+
|
|
1218
|
+
const placeOrderMsgPromises = placeOrderPayloads.map((placePayload) => {
|
|
1219
|
+
const placeSubaccount = new SubaccountInfo(
|
|
1220
|
+
subaccount.wallet,
|
|
1221
|
+
placePayload.subaccountNumber,
|
|
1222
|
+
);
|
|
1223
|
+
return this.placeOrderMessage(
|
|
1224
|
+
placeSubaccount,
|
|
1225
|
+
placePayload.marketId,
|
|
1226
|
+
placePayload.type,
|
|
1227
|
+
placePayload.side,
|
|
1228
|
+
placePayload.price,
|
|
1229
|
+
placePayload.size,
|
|
1230
|
+
placePayload.clientId,
|
|
1231
|
+
placePayload.timeInForce,
|
|
1232
|
+
placePayload.goodTilTimeInSeconds,
|
|
1233
|
+
placePayload.execution,
|
|
1234
|
+
placePayload.postOnly,
|
|
1235
|
+
placePayload.reduceOnly,
|
|
1236
|
+
placePayload.triggerPrice,
|
|
1237
|
+
placePayload.marketInfo,
|
|
1238
|
+
placePayload.currentHeight,
|
|
1239
|
+
placePayload.goodTilBlock,
|
|
1240
|
+
);
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
return Promise.all([...cancelMsgPromises, ...placeOrderMsgPromises]);
|
|
1244
|
+
},
|
|
1245
|
+
true,
|
|
1246
|
+
undefined,
|
|
1247
|
+
memo,
|
|
1248
|
+
broadcastMode ?? Method.BroadcastTxCommit,
|
|
1249
|
+
() => account,
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1084
1253
|
// vaults
|
|
1085
1254
|
|
|
1086
1255
|
async depositToMegavault(
|
|
@@ -1302,7 +1471,7 @@ export class CompositeClient {
|
|
|
1302
1471
|
|
|
1303
1472
|
// The top-level authenticator must pass validation
|
|
1304
1473
|
if (!checkAuthenticator(authenticator)) {
|
|
1305
|
-
return false
|
|
1474
|
+
return false;
|
|
1306
1475
|
}
|
|
1307
1476
|
|
|
1308
1477
|
return true;
|
|
@@ -334,7 +334,7 @@ export default class AccountClient extends RestClient {
|
|
|
334
334
|
afterOrAt?: string,
|
|
335
335
|
page?: number,
|
|
336
336
|
): Promise<Data> {
|
|
337
|
-
const uri = `/v4/fundingPayments/
|
|
337
|
+
const uri = `/v4/fundingPayments/parentSubaccount`;
|
|
338
338
|
return this.get(uri, { address, parentSubaccountNumber, limit, ticker, afterOrAt, page });
|
|
339
339
|
}
|
|
340
340
|
}
|