@dydxprotocol/v4-client-js 1.3.16 → 1.5.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.3.16",
3
+ "version": "1.5.0",
4
4
  "description": "General client library for the new dYdX system (v4 decentralized)",
5
5
  "main": "build/src/index.js",
6
6
  "scripts": {
@@ -11,8 +11,8 @@
11
11
  "coverage": "npm run test -- --coverage",
12
12
  "fix": "npm run lint -- --fix",
13
13
  "lint": "eslint --ext .ts,.js .",
14
- "prepublishOnly": "npm run compile && ls build/node_modules/@dydxprotocol/v4-proto",
15
- "release": "semantic-release --no-ci",
14
+ "prepublishOnly": "npm run compile",
15
+ "release": "semantic-release",
16
16
  "start": "node build/src/index.js",
17
17
  "test": "NODE_ENV=test jest --testPathIgnorePatterns=__tests__/modules/client/*",
18
18
  "test:watch": "npm test -- --watch",
@@ -109,6 +109,11 @@ export class CompositeClient {
109
109
  this._validatorClient.setSelectedGasDenom(gasDenom);
110
110
  }
111
111
 
112
+ async populateAccountNumberCache(address: string): Promise<void> {
113
+ if (!this._validatorClient) throw new Error('Validator client not initialized');
114
+ await this._validatorClient.populateAccountNumberCache(address);
115
+ }
116
+
112
117
  /**
113
118
  * @description Sign a list of messages with a wallet.
114
119
  * the calling function is responsible for creating the messages.
@@ -176,6 +176,11 @@ export enum TimePeriod {
176
176
  SEVEN_DAYS = 'SEVEN_DAYS',
177
177
  }
178
178
 
179
+ export enum PnlTickInterval {
180
+ HOUR = "hour",
181
+ day = "day",
182
+ }
183
+
179
184
  // ------------ API Defaults ------------
180
185
  export const DEFAULT_API_TIMEOUT: number = 3_000;
181
186
 
@@ -2,6 +2,7 @@ import { IndexerConfig, DEFAULT_API_TIMEOUT } from './constants';
2
2
  import AccountClient from './modules/account';
3
3
  import MarketsClient from './modules/markets';
4
4
  import UtilityClient from './modules/utility';
5
+ import VaultClient from './modules/vault';
5
6
 
6
7
  /**
7
8
  * @description Client for Indexer
@@ -12,6 +13,7 @@ export class IndexerClient {
12
13
  readonly _markets: MarketsClient;
13
14
  readonly _account: AccountClient;
14
15
  readonly _utility: UtilityClient;
16
+ readonly _vault: VaultClient;
15
17
 
16
18
  constructor(config: IndexerConfig, apiTimeout?: number) {
17
19
  this.config = config;
@@ -20,6 +22,7 @@ export class IndexerClient {
20
22
  this._markets = new MarketsClient(config.restEndpoint);
21
23
  this._account = new AccountClient(config.restEndpoint);
22
24
  this._utility = new UtilityClient(config.restEndpoint);
25
+ this._vault = new VaultClient(config.restEndpoint);
23
26
  }
24
27
 
25
28
  /**
@@ -46,4 +49,13 @@ export class IndexerClient {
46
49
  get utility(): UtilityClient {
47
50
  return this._utility;
48
51
  }
52
+
53
+ /**
54
+ * @description Get the vault module, used for interacting with vault endpoints.
55
+ *
56
+ * @returns The vault module
57
+ */
58
+ get vault(): VaultClient {
59
+ return this._vault;
60
+ }
49
61
  }
@@ -194,4 +194,23 @@ export default class AccountClient extends RestClient {
194
194
  page,
195
195
  });
196
196
  }
197
+
198
+ async getTransfersBetween(
199
+ sourceAddress: string,
200
+ sourceSubaccountNumber: string,
201
+ recipientAddress: string,
202
+ recipientSubaccountNumber: string,
203
+ createdBeforeOrAtHeight?: number | null,
204
+ createdBeforeOrAt?: string | null
205
+ ): Promise<Data> {
206
+ const uri = '/v4/transfers/between';
207
+ return this.get(uri, {
208
+ sourceAddress,
209
+ sourceSubaccountNumber,
210
+ recipientAddress,
211
+ recipientSubaccountNumber,
212
+ createdBeforeOrAtHeight,
213
+ createdBeforeOrAt,
214
+ });
215
+ }
197
216
  }
@@ -76,6 +76,18 @@ export class Post {
76
76
  );
77
77
  }
78
78
 
79
+ /**
80
+ * @description Retrieves the account number for the given wallet address and populates the accountNumberCache.
81
+ * The account number is required for txOptions when signing a transaction.
82
+ * Pre-populating the cache avoids a round-trip request during the first transaction creation in the session, preventing it from being a performance blocker.
83
+ */
84
+ public async populateAccountNumberCache(address: string): Promise<void> {
85
+ if (this.accountNumberCache.has(address)) return;
86
+
87
+ const account = await this.get.getAccount(address);
88
+ this.accountNumberCache.set(address, account);
89
+ }
90
+
79
91
  setSelectedGasDenom(selectedGasDenom: SelectedGasDenom): void {
80
92
  this.selectedGasDenom = selectedGasDenom;
81
93
  }
@@ -0,0 +1,23 @@
1
+ import { PnlTickInterval } from '../constants';
2
+ import { Data } from '../types';
3
+ import RestClient from './rest';
4
+
5
+ /**
6
+ * @description REST endpoints for data unrelated to a particular address.
7
+ */
8
+ export default class VaultClient extends RestClient {
9
+ async getMegavaultHistoricalPnl(resolution?: PnlTickInterval | null): Promise<Data> {
10
+ const uri = '/v4/vault/v1/megavault/historicalPnl';
11
+ return this.get(uri, { resolution });
12
+ }
13
+
14
+ async getVaultsHistoricalPnl(resolution?: PnlTickInterval | null): Promise<Data> {
15
+ const uri = '/v4/vault/v1/vaults/historicalPnl';
16
+ return this.get(uri, { resolution });
17
+ }
18
+
19
+ async getMegavaultPositions(): Promise<Data> {
20
+ const uri = '/v4/vault/v1/megavault/positions';
21
+ return this.get(uri);
22
+ }
23
+ }
@@ -69,6 +69,15 @@ export class ValidatorClient {
69
69
  this._post.setSelectedGasDenom(gasDenom);
70
70
  }
71
71
 
72
+
73
+ /**
74
+ * @description populate account number cache in the Post module for performance.
75
+ */
76
+ async populateAccountNumberCache(address: string): Promise<void> {
77
+ if (!this._post) throw new Error('Post module not initialized');
78
+ await this._post.populateAccountNumberCache(address);
79
+ }
80
+
72
81
  private async initialize(): Promise<void> {
73
82
  const tendermint37Client: Tendermint37Client = await Tendermint37Client.connect(
74
83
  this.config.restEndpoint,