@dydxprotocol/v4-client-js 0.34.0 → 0.36.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.
Files changed (34) hide show
  1. package/__native__/__ios__/v4-native-client.js +1032 -3969
  2. package/__native__/__ios__/v4-native-client.js.map +1 -1
  3. package/__tests__/modules/client/MarketsEndpoints.test.ts +1 -15
  4. package/__tests__/modules/client/UtilityEndpoints.test.ts +29 -0
  5. package/build/__tests__/modules/client/MarketsEndpoints.test.js +2 -14
  6. package/build/__tests__/modules/client/UtilityEndpoints.test.d.ts +1 -0
  7. package/build/__tests__/modules/client/UtilityEndpoints.test.js +28 -0
  8. package/build/examples/markets_endpoints.d.ts +1 -1
  9. package/build/examples/markets_endpoints.js +2 -28
  10. package/build/examples/utility_endpoints.d.ts +4 -0
  11. package/build/examples/utility_endpoints.js +41 -0
  12. package/build/src/clients/constants.d.ts +5 -5
  13. package/build/src/clients/constants.js +6 -6
  14. package/build/src/clients/indexer-client.d.ts +6 -0
  15. package/build/src/clients/indexer-client.js +9 -1
  16. package/build/src/clients/modules/markets.d.ts +0 -2
  17. package/build/src/clients/modules/markets.js +1 -9
  18. package/build/src/clients/modules/utility.d.ts +20 -0
  19. package/build/src/clients/modules/utility.js +35 -0
  20. package/build/src/clients/types.d.ts +11 -0
  21. package/build/src/clients/types.js +1 -1
  22. package/build/src/network_optimizer.js +1 -1
  23. package/build/src/types.d.ts +0 -11
  24. package/build/src/types.js +2 -10
  25. package/examples/markets_endpoints.ts +1 -27
  26. package/examples/utility_endpoints.ts +41 -0
  27. package/package.json +1 -1
  28. package/src/clients/constants.ts +5 -5
  29. package/src/clients/indexer-client.ts +10 -0
  30. package/src/clients/modules/markets.ts +0 -10
  31. package/src/clients/modules/utility.ts +32 -0
  32. package/src/clients/types.ts +15 -0
  33. package/src/network_optimizer.ts +1 -1
  34. package/src/types.ts +0 -14
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Simple JS example demostrating accessing public data with Indexer REST endpoints
3
+ */
4
+
5
+ import { Network } from '../src/clients/constants';
6
+ import { IndexerClient } from '../src/clients/indexer-client';
7
+
8
+ async function test(): Promise<void> {
9
+ const client = new IndexerClient(Network.staging().indexerConfig);
10
+
11
+ // Get indexer server time
12
+ try {
13
+ const response = await client.utility.getTime();
14
+ console.log(response);
15
+ const timeIso = response.iso;
16
+ const timeEpoch = response.epoch;
17
+ console.log('time');
18
+ console.log(timeIso);
19
+ console.log(timeEpoch);
20
+ } catch (error) {
21
+ console.log(error.message);
22
+ }
23
+
24
+ // Get indexer server height
25
+ try {
26
+ const response = await client.utility.getHeight();
27
+ console.log(response);
28
+ const height = response.height;
29
+ const heightTime = response.time;
30
+ console.log('height');
31
+ console.log(height);
32
+ console.log(heightTime);
33
+ } catch (error) {
34
+ console.log(error.message);
35
+ }
36
+ }
37
+
38
+ test().then(() => {
39
+ }).catch((error) => {
40
+ console.log(error.message);
41
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dydxprotocol/v4-client-js",
3
- "version": "0.34.0",
3
+ "version": "0.36.0",
4
4
  "description": "General client library for the new dYdX system (v4 decentralized)",
5
5
  "main": "build/src/index.js",
6
6
  "scripts": {
@@ -14,27 +14,27 @@ export const TESTNET_CHAIN_ID = 'dydx-testnet-2';
14
14
  export enum IndexerApiHost {
15
15
  DEV = 'https://indexer.v4dev.dydx.exchange',
16
16
  STAGING = 'https://indexer.v4staging.dydx.exchange',
17
- TESTNET = 'https://indexer.v4testnet2.dydx.exchange',
17
+ TESTNET = 'https://indexer.v4testnet.dydx.exchange',
18
18
  // TODO: Add MAINNET
19
19
  }
20
20
 
21
21
  export enum IndexerWSHost {
22
22
  DEV = 'wss://indexer.v4dev.dydx.exchange/v4/ws',
23
23
  STAGING = 'wss://indexer.v4staging.dydx.exchange/v4/ws',
24
- TESTNET = 'wss://indexer.v4testnet2.dydx.exchange/v4/ws',
24
+ TESTNET = 'wss://indexer.v4testnet.dydx.exchange/v4/ws',
25
25
  // TODO: Add MAINNET
26
26
  }
27
27
 
28
28
  export enum FaucetApiHost {
29
29
  DEV = 'https://faucet.v4dev.expotrading.com',
30
30
  STAGING = 'https://faucet.v4staging.dydx.exchange',
31
- TESTNET = 'https://faucet.v4testnet2.dydx.exchange',
31
+ TESTNET = 'https://faucet.v4testnet.dydx.exchange',
32
32
  }
33
33
 
34
34
  export enum ValidatorApiHost {
35
35
  DEV = 'https://validator.v4dev.dydx.exchange',
36
36
  STAGING = 'https://validator.v4staging.dydx.exchange',
37
- TESTNET = 'https://validator.v4testnet2.dydx.exchange',
37
+ TESTNET = 'https://validator.v4testnet.dydx.exchange',
38
38
  // TODO: Add MAINNET
39
39
  }
40
40
 
@@ -43,7 +43,7 @@ export enum ValidatorApiHost {
43
43
  export enum NetworkId {
44
44
  DEV = 'dydxprotocol-testnet',
45
45
  STAGING = 'dydxprotocol-testnet',
46
- TESTNET = 'dydx-testnet-2',
46
+ TESTNET = 'dydx-testnet-3',
47
47
  // TODO: Add MAINNET
48
48
  }
49
49
  export const NETWORK_ID_MAINNET: string | null = null;
@@ -1,6 +1,7 @@
1
1
  import { IndexerConfig, DEFAULT_API_TIMEOUT } from './constants';
2
2
  import AccountClient from './modules/account';
3
3
  import MarketsClient from './modules/markets';
4
+ import UtilityClient from './modules/utility';
4
5
 
5
6
  /**
6
7
  * @description Client for Indexer
@@ -10,6 +11,7 @@ export class IndexerClient {
10
11
  readonly apiTimeout: number;
11
12
  readonly _markets: MarketsClient;
12
13
  readonly _account: AccountClient;
14
+ readonly _utility: UtilityClient;
13
15
 
14
16
  constructor(config: IndexerConfig, apiTimeout?: number) {
15
17
  this.config = config;
@@ -17,6 +19,7 @@ export class IndexerClient {
17
19
 
18
20
  this._markets = new MarketsClient(config.restEndpoint);
19
21
  this._account = new AccountClient(config.restEndpoint);
22
+ this._utility = new UtilityClient(config.restEndpoint);
20
23
  }
21
24
 
22
25
  /**
@@ -36,4 +39,11 @@ export class IndexerClient {
36
39
  get account(): AccountClient {
37
40
  return this._account;
38
41
  }
42
+
43
+ /**
44
+ * @description Get the utility module, used for interacting with non-market public endpoints.
45
+ */
46
+ get utility(): UtilityClient {
47
+ return this._utility;
48
+ }
39
49
  }
@@ -64,14 +64,4 @@ export default class MarketsClient extends RestClient {
64
64
  timePeriod: period,
65
65
  });
66
66
  }
67
-
68
- async getTime(): Promise<Data> {
69
- const uri = '/v4/time';
70
- return this.get(uri);
71
- }
72
-
73
- async getHeight(): Promise<Data> {
74
- const uri = '/v4/height';
75
- return this.get(uri);
76
- }
77
67
  }
@@ -0,0 +1,32 @@
1
+ import type { ComplianceResponse, HeightResponse, TimeResponse } from '../types';
2
+ import RestClient from './rest';
3
+
4
+ export default class UtilityClient extends RestClient {
5
+ /**
6
+ * @description Get the current time of the Indexer
7
+ * @returns {TimeResponse} isoString and epoch
8
+ */
9
+ async getTime(): Promise<TimeResponse> {
10
+ const uri = '/v4/time';
11
+ return this.get(uri);
12
+ }
13
+
14
+ /**
15
+ * @description Get the block height of the most recent block processed by the Indexer
16
+ * @returns {HeightResponse} block height and time
17
+ */
18
+ async getHeight(): Promise<HeightResponse> {
19
+ const uri = '/v4/height';
20
+ return this.get(uri);
21
+ }
22
+
23
+ /**
24
+ * @description Screen an address to see if it is restricted
25
+ * @param {string} address evm or dydx address
26
+ * @returns {ComplianceResponse} whether the specified address is restricted
27
+ */
28
+ async screen(address: string): Promise<ComplianceResponse> {
29
+ const uri = '/v4/screen';
30
+ return this.get(uri, { address });
31
+ }
32
+ }
@@ -70,4 +70,19 @@ export type BroadcastMode = (
70
70
  Method.BroadcastTxAsync | Method.BroadcastTxSync | Method.BroadcastTxCommit
71
71
  );
72
72
 
73
+ // ------ Utility Endpoint Responses ------ //
74
+ export interface TimeResponse {
75
+ iso: string;
76
+ epoch: number;
77
+ }
78
+
79
+ export interface HeightResponse {
80
+ height: number;
81
+ time: string;
82
+ }
83
+
84
+ export interface ComplianceResponse {
85
+ restricted: boolean;
86
+ }
87
+
73
88
  export * from './modules/proto-includes';
@@ -89,7 +89,7 @@ export class NetworkOptimizer {
89
89
  const responses = (await Promise.all(
90
90
  clients
91
91
  .map(async (client) => {
92
- const block = await client.markets.getHeight();
92
+ const block = await client.utility.getHeight();
93
93
  const response = new PingResponse(+block.height);
94
94
  return {
95
95
  endpoint: client.config.restEndpoint,
package/src/types.ts CHANGED
@@ -42,17 +42,3 @@ export interface Options {
42
42
  export enum ClobPairId {
43
43
  PERPETUAL_PAIR_BTC_USD = 0,
44
44
  }
45
-
46
- export enum MarketId {
47
- PERPETUAL_PRICE_BTC_USD = 0,
48
- }
49
-
50
- export enum PerpetualId {
51
- PERPETUAL_BTC_USD = 0,
52
- }
53
-
54
- export interface FaucetRequest {
55
- address: string;
56
- subaccountNumber: number;
57
- amount: number;
58
- }