@dydxprotocol/v4-client-js 0.35.0 → 0.36.1
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/__native__/__ios__/v4-native-client.js +1026 -3963
- package/__native__/__ios__/v4-native-client.js.map +1 -0
- package/__tests__/modules/client/MarketsEndpoints.test.ts +1 -15
- package/__tests__/modules/client/UtilityEndpoints.test.ts +29 -0
- package/build/__tests__/modules/client/MarketsEndpoints.test.js +2 -14
- package/build/__tests__/modules/client/UtilityEndpoints.test.d.ts +1 -0
- package/build/__tests__/modules/client/UtilityEndpoints.test.js +28 -0
- package/build/examples/markets_endpoints.d.ts +1 -1
- package/build/examples/markets_endpoints.js +2 -28
- package/build/examples/utility_endpoints.d.ts +4 -0
- package/build/examples/utility_endpoints.js +41 -0
- package/build/src/clients/constants.d.ts +4 -4
- package/build/src/clients/constants.js +5 -5
- package/build/src/clients/indexer-client.d.ts +6 -0
- package/build/src/clients/indexer-client.js +9 -1
- package/build/src/clients/modules/markets.d.ts +0 -2
- package/build/src/clients/modules/markets.js +1 -9
- package/build/src/clients/modules/utility.d.ts +20 -0
- package/build/src/clients/modules/utility.js +35 -0
- package/build/src/clients/types.d.ts +11 -0
- package/build/src/clients/types.js +1 -1
- package/build/src/network_optimizer.js +1 -1
- package/build/src/types.d.ts +0 -11
- package/build/src/types.js +2 -10
- package/examples/markets_endpoints.ts +1 -27
- package/examples/utility_endpoints.ts +41 -0
- package/package.json +1 -1
- package/src/clients/constants.ts +4 -4
- package/src/clients/indexer-client.ts +10 -0
- package/src/clients/modules/markets.ts +0 -10
- package/src/clients/modules/utility.ts +32 -0
- package/src/clients/types.ts +15 -0
- package/src/network_optimizer.ts +1 -1
- 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
package/src/clients/constants.ts
CHANGED
|
@@ -8,20 +8,20 @@ export * from '../lib/constants';
|
|
|
8
8
|
// Chain ID
|
|
9
9
|
export const DEV_CHAIN_ID = 'dydxprotocol-testnet';
|
|
10
10
|
export const STAGING_CHAIN_ID = 'dydxprotocol-testnet';
|
|
11
|
-
export const TESTNET_CHAIN_ID = 'dydx-testnet-
|
|
11
|
+
export const TESTNET_CHAIN_ID = 'dydx-testnet-3';
|
|
12
12
|
|
|
13
13
|
// ------------ API URLs ------------
|
|
14
14
|
export enum IndexerApiHost {
|
|
15
15
|
DEV = 'https://indexer.v4dev.dydx.exchange',
|
|
16
16
|
STAGING = 'https://indexer.v4staging.dydx.exchange',
|
|
17
|
-
TESTNET = 'https://
|
|
17
|
+
TESTNET = 'https://dydx-testnet.imperator.co',
|
|
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://
|
|
24
|
+
TESTNET = 'wss://dydx-testnet.imperator.co/v4/ws',
|
|
25
25
|
// TODO: Add MAINNET
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -34,7 +34,7 @@ export enum FaucetApiHost {
|
|
|
34
34
|
export enum ValidatorApiHost {
|
|
35
35
|
DEV = 'https://validator.v4dev.dydx.exchange',
|
|
36
36
|
STAGING = 'https://validator.v4staging.dydx.exchange',
|
|
37
|
-
TESTNET = 'https://
|
|
37
|
+
TESTNET = 'https://dydx-testnet-archive.allthatnode.com',
|
|
38
38
|
// TODO: Add MAINNET
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -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
|
+
}
|
package/src/clients/types.ts
CHANGED
|
@@ -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';
|
package/src/network_optimizer.ts
CHANGED
|
@@ -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.
|
|
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
|
-
}
|