@dydxprotocol/v4-client-js 1.13.0 → 1.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dydxprotocol/v4-client-js",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "General client library for the new dYdX system (v4 decentralized)",
5
5
  "main": "build/src/index.js",
6
6
  "scripts": {
@@ -86,7 +86,8 @@ export const TYPE_URL_MSG_UPDATE_CLOB_PAIR = '/dydxprotocol.clob.MsgUpdateClobPa
86
86
  export const TYPE_URL_MSG_DELAY_MESSAGE = '/dydxprotocol.delaymsg.MsgDelayMessage';
87
87
 
88
88
  // x/listing
89
- export const TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS = '/dydxprotocol.listing.MsgCreateMarketPermissionless';
89
+ export const TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS =
90
+ '/dydxprotocol.listing.MsgCreateMarketPermissionless';
90
91
 
91
92
  // x/perpetuals
92
93
  export const TYPE_URL_MSG_CREATE_PERPETUAL = '/dydxprotocol.perpetuals.MsgCreatePerpetual';
@@ -195,6 +196,12 @@ export enum PnlTickInterval {
195
196
  day = 'day',
196
197
  }
197
198
 
199
+ export enum TradingRewardAggregationPeriod {
200
+ DAILY = 'DAILY',
201
+ WEEKLY = 'WEEKLY',
202
+ MONTHLY = 'MONTHLY',
203
+ }
204
+
198
205
  // ------------ API Defaults ------------
199
206
  export const DEFAULT_API_TIMEOUT: number = 3_000;
200
207
 
@@ -1,4 +1,11 @@
1
- import { OrderSide, OrderStatus, OrderType, PositionStatus, TickerType } from '../constants';
1
+ import {
2
+ OrderSide,
3
+ OrderStatus,
4
+ OrderType,
5
+ PositionStatus,
6
+ TickerType,
7
+ TradingRewardAggregationPeriod,
8
+ } from '../constants';
2
9
  import { Data } from '../types';
3
10
  import RestClient from './rest';
4
11
 
@@ -6,6 +13,8 @@ import RestClient from './rest';
6
13
  * @description REST endpoints for data related to a particular address.
7
14
  */
8
15
  export default class AccountClient extends RestClient {
16
+ // ------ Subaccount ------ //
17
+
9
18
  async getSubaccounts(address: string, limit?: number): Promise<Data> {
10
19
  const uri = `/v4/addresses/${address}`;
11
20
  return this.get(uri, { limit });
@@ -16,6 +25,13 @@ export default class AccountClient extends RestClient {
16
25
  return this.get(uri);
17
26
  }
18
27
 
28
+ async getParentSubaccount(address: string, parentSubaccountNumber: number): Promise<Data> {
29
+ const uri = `/v4/addresses/${address}/subaccountNumber/${parentSubaccountNumber}`;
30
+ return this.get(uri);
31
+ }
32
+
33
+ // ------ Positions ------ //
34
+
19
35
  async getSubaccountPerpetualPositions(
20
36
  address: string,
21
37
  subaccountNumber: number,
@@ -54,6 +70,27 @@ export default class AccountClient extends RestClient {
54
70
  });
55
71
  }
56
72
 
73
+ // ------ Transfers ------ //
74
+
75
+ async getTransfersBetween(
76
+ sourceAddress: string,
77
+ sourceSubaccountNumber: string,
78
+ recipientAddress: string,
79
+ recipientSubaccountNumber: string,
80
+ createdBeforeOrAtHeight?: number | null,
81
+ createdBeforeOrAt?: string | null,
82
+ ): Promise<Data> {
83
+ const uri = '/v4/transfers/between';
84
+ return this.get(uri, {
85
+ sourceAddress,
86
+ sourceSubaccountNumber,
87
+ recipientAddress,
88
+ recipientSubaccountNumber,
89
+ createdBeforeOrAtHeight,
90
+ createdBeforeOrAt,
91
+ });
92
+ }
93
+
57
94
  async getSubaccountTransfers(
58
95
  address: string,
59
96
  subaccountNumber: number,
@@ -92,6 +129,8 @@ export default class AccountClient extends RestClient {
92
129
  });
93
130
  }
94
131
 
132
+ // ------ Orders ------ //
133
+
95
134
  async getSubaccountOrders(
96
135
  address: string,
97
136
  subaccountNumber: number,
@@ -121,11 +160,40 @@ export default class AccountClient extends RestClient {
121
160
  });
122
161
  }
123
162
 
163
+ async getParentSubaccountNumberOrders(
164
+ address: string,
165
+ parentSubaccountNumber: number,
166
+ ticker?: string | null,
167
+ side?: OrderSide | null,
168
+ status?: OrderStatus | null,
169
+ type?: OrderType | null,
170
+ limit?: number | null,
171
+ goodTilBlockBeforeOrAt?: number | null,
172
+ goodTilBlockTimeBeforeOrAt?: string | null,
173
+ returnLatestOrders?: boolean | null,
174
+ ): Promise<Data> {
175
+ const uri = '/v4/orders/parentSubaccountNumber';
176
+ return this.get(uri, {
177
+ address,
178
+ parentSubaccountNumber,
179
+ ticker,
180
+ side,
181
+ status,
182
+ type,
183
+ limit,
184
+ goodTilBlockBeforeOrAt,
185
+ goodTilBlockTimeBeforeOrAt,
186
+ returnLatestOrders,
187
+ });
188
+ }
189
+
124
190
  async getOrder(orderId: string): Promise<Data> {
125
191
  const uri = `/v4/orders/${orderId}`;
126
192
  return this.get(uri);
127
193
  }
128
194
 
195
+ // ------ Fills ------ //
196
+
129
197
  async getSubaccountFills(
130
198
  address: string,
131
199
  subaccountNumber: number,
@@ -172,6 +240,8 @@ export default class AccountClient extends RestClient {
172
240
  });
173
241
  }
174
242
 
243
+ // ------ Pnl ------ //
244
+
175
245
  async getSubaccountHistoricalPNLs(
176
246
  address: string,
177
247
  subaccountNumber: number,
@@ -195,22 +265,39 @@ export default class AccountClient extends RestClient {
195
265
  });
196
266
  }
197
267
 
198
- async getTransfersBetween(
199
- sourceAddress: string,
200
- sourceSubaccountNumber: string,
201
- recipientAddress: string,
202
- recipientSubaccountNumber: string,
268
+ async getParentSubaccountNumberHistoricalPNLs(
269
+ address: string,
270
+ parentSubaccountNumber: number,
203
271
  createdBeforeOrAtHeight?: number | null,
204
- createdBeforeOrAt?: string | null
205
- ): Promise<Data> {
206
- const uri = '/v4/transfers/between';
272
+ createdBeforeOrAt?: string | null,
273
+ createdOnOrAfterHeight?: number | null,
274
+ createdOnOrAfter?: string | null,
275
+ limit?: number | null,
276
+ page?: number | null,
277
+ ): Promise<Data> {
278
+ const uri = '/v4//historical-pnl/parentSubaccount';
207
279
  return this.get(uri, {
208
- sourceAddress,
209
- sourceSubaccountNumber,
210
- recipientAddress,
211
- recipientSubaccountNumber,
280
+ address,
281
+ parentSubaccountNumber,
212
282
  createdBeforeOrAtHeight,
213
283
  createdBeforeOrAt,
284
+ createdOnOrAfterHeight,
285
+ createdOnOrAfter,
286
+ limit,
287
+ page,
214
288
  });
215
289
  }
290
+
291
+ // ------ Rewards ------ //
292
+
293
+ async getHistoricalTradingRewardsAggregations(
294
+ address: string,
295
+ period: TradingRewardAggregationPeriod,
296
+ limit?: number,
297
+ startingBeforeOrAt?: string,
298
+ startingBeforeOrAtHeight?: string,
299
+ ): Promise<Data> {
300
+ const uri = `/v4/historicalTradingRewardAggregations/${address}`;
301
+ return this.get(uri, { period, limit, startingBeforeOrAt, startingBeforeOrAtHeight });
302
+ }
216
303
  }
@@ -220,12 +220,17 @@ export async function getFeeTiers(): Promise<string> {
220
220
  }
221
221
  }
222
222
 
223
- export async function getUserFeeTier(address: string): Promise<string> {
223
+ export async function getUserFeeTier(payload: string): Promise<string> {
224
224
  try {
225
225
  const client = globalThis.client;
226
226
  if (client === undefined) {
227
227
  throw new UserError('client is not connected. Call connectClient() first');
228
228
  }
229
+ const json = JSON.parse(payload);
230
+ const address = json.address;
231
+ if (address === undefined) {
232
+ throw new UserError('address is not set');
233
+ }
229
234
  const feeTiers = await globalThis.client?.validatorClient.get.getUserFeeTier(address);
230
235
  return encodeJson(feeTiers);
231
236
  } catch (e) {