@dydxprotocol/v4-client-js 1.1.12 → 1.1.14
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/.eslintrc.js +3 -5
- package/.prettierignore +3 -0
- package/.prettierrc.json +6 -0
- package/.telescope.json +2 -4
- package/.vscode/launch.json +10 -10
- package/README.md +3 -1
- package/__native__/__ios__/v4-native-client.js +2648 -806
- package/__tests__/helpers/constants.ts +10 -8
- package/__tests__/lib/helpers.test.ts +22 -23
- package/__tests__/lib/util.test.ts +2 -8
- package/__tests__/lib/validation.test.ts +23 -26
- package/__tests__/modules/client/Transfers.test.ts +4 -19
- package/__tests__/modules/client/ValidatorPostEndpoints.test.ts +2 -5
- package/__tests__/modules/client/constants.ts +4 -2
- package/__tests__/modules/onboarding.test.ts +9 -7
- package/build/__tests__/helpers/constants.js +7 -7
- package/build/__tests__/lib/helpers.test.js +2 -6
- package/build/__tests__/lib/util.test.js +1 -1
- package/build/__tests__/lib/validation.test.js +3 -11
- package/build/__tests__/modules/client/Transfers.test.js +1 -1
- package/build/__tests__/modules/client/ValidatorPostEndpoints.test.js +2 -2
- package/build/__tests__/modules/client/constants.js +1 -1
- package/build/__tests__/modules/onboarding.test.js +2 -3
- package/build/examples/account_endpoints.js +4 -3
- package/build/examples/composite_example.js +5 -4
- package/build/examples/constants.js +1 -1
- package/build/examples/faucet_endpoint.js +4 -3
- package/build/examples/long_term_order_cancel_example.js +4 -3
- package/build/examples/markets_endpoints.js +4 -3
- package/build/examples/native_examples.js +4 -3
- package/build/examples/noble_example.js +1 -1
- package/build/examples/optimal_node.js +4 -12
- package/build/examples/short_term_order_cancel_example.js +4 -3
- package/build/examples/short_term_order_composite_example.js +4 -3
- package/build/examples/test.js +5 -4
- package/build/examples/transfer_example_deposit.js +4 -3
- package/build/examples/transfer_example_send.js +1 -1
- package/build/examples/transfer_example_subaccount_transfer.js +4 -3
- package/build/examples/transfer_example_withdraw.js +4 -3
- package/build/examples/transfer_example_withdraw_other.js +1 -1
- package/build/examples/utility_endpoints.js +4 -3
- package/build/examples/validator_get_example.js +15 -9
- package/build/examples/validator_post_example.js +4 -3
- package/build/examples/wallet_address.js +5 -4
- package/build/examples/websocket_example.js +1 -1
- package/build/src/clients/composite-client.d.ts +225 -224
- package/build/src/clients/composite-client.js +242 -237
- package/build/src/clients/constants.d.ts +3 -0
- package/build/src/clients/constants.js +6 -2
- package/build/src/clients/faucet-client.d.ts +4 -4
- package/build/src/clients/faucet-client.js +5 -5
- package/build/src/clients/helpers/chain-helpers.js +1 -1
- package/build/src/clients/helpers/request-helpers.js +5 -4
- package/build/src/clients/indexer-client.js +1 -1
- package/build/src/clients/lib/axios/axiosRequest.js +1 -1
- package/build/src/clients/lib/axios/errors.js +1 -1
- package/build/src/clients/lib/cctpProto.d.ts +2 -2
- package/build/src/clients/lib/cctpProto.js +287 -237
- package/build/src/clients/lib/errors.js +1 -1
- package/build/src/clients/modules/account.js +1 -1
- package/build/src/clients/modules/composer.d.ts +4 -0
- package/build/src/clients/modules/composer.js +39 -3
- package/build/src/clients/modules/get.d.ts +10 -3
- package/build/src/clients/modules/get.js +41 -54
- package/build/src/clients/modules/local-wallet.js +1 -1
- package/build/src/clients/modules/post.d.ts +3 -0
- package/build/src/clients/modules/post.js +34 -18
- package/build/src/clients/modules/proto-includes.d.ts +1 -0
- package/build/src/clients/modules/proto-includes.js +3 -2
- package/build/src/clients/modules/rest.js +1 -1
- package/build/src/clients/modules/signer.js +1 -1
- package/build/src/clients/modules/tendermintClient.d.ts +5 -5
- package/build/src/clients/modules/tendermintClient.js +6 -6
- package/build/src/clients/native.js +4 -7
- package/build/src/clients/noble-client.js +1 -1
- package/build/src/clients/socket-client.js +1 -1
- package/build/src/clients/subaccount.js +1 -1
- package/build/src/clients/types.d.ts +1 -1
- package/build/src/clients/types.js +1 -1
- package/build/src/clients/validator-client.d.ts +12 -12
- package/build/src/clients/validator-client.js +13 -13
- package/build/src/lib/errors.js +1 -1
- package/build/src/lib/onboarding.js +1 -1
- package/build/src/lib/utils.js +3 -3
- package/build/src/lib/validation.js +5 -4
- package/build/src/network_optimizer.js +10 -11
- package/build/src/types.d.ts +1 -1
- package/build/src/types.js +1 -1
- package/examples/account_endpoints.ts +5 -4
- package/examples/composite_example.ts +12 -7
- package/examples/constants.ts +10 -4
- package/examples/faucet_endpoint.ts +5 -4
- package/examples/human_readable_orders.json +85 -85
- package/examples/human_readable_short_term_orders.json +41 -41
- package/examples/long_term_order_cancel_example.ts +11 -6
- package/examples/markets_endpoints.ts +5 -4
- package/examples/native_examples.ts +8 -7
- package/examples/noble_example.ts +11 -23
- package/examples/optimal_node.ts +4 -14
- package/examples/raw_orders.json +128 -128
- package/examples/short_term_order_cancel_example.ts +7 -8
- package/examples/short_term_order_composite_example.ts +7 -8
- package/examples/test.ts +12 -7
- package/examples/transfer_example_deposit.ts +6 -9
- package/examples/transfer_example_send.ts +2 -10
- package/examples/transfer_example_subaccount_transfer.ts +6 -11
- package/examples/transfer_example_withdraw.ts +6 -9
- package/examples/transfer_example_withdraw_other.ts +1 -5
- package/examples/utility_endpoints.ts +5 -4
- package/examples/validator_get_example.ts +19 -10
- package/examples/validator_post_example.ts +7 -9
- package/examples/wallet_address.ts +6 -5
- package/examples/websocket_example.ts +5 -1
- package/package.json +4 -1
- package/src/clients/composite-client.ts +279 -330
- package/src/clients/constants.ts +38 -26
- package/src/clients/faucet-client.ts +5 -8
- package/src/clients/helpers/chain-helpers.ts +10 -6
- package/src/clients/helpers/request-helpers.ts +6 -5
- package/src/clients/indexer-client.ts +34 -34
- package/src/clients/lib/axios/axiosRequest.ts +4 -7
- package/src/clients/lib/axios/errors.ts +16 -21
- package/src/clients/lib/cctpProto.ts +655 -387
- package/src/clients/lib/errors.ts +8 -17
- package/src/clients/modules/account.ts +4 -12
- package/src/clients/modules/composer.ts +61 -20
- package/src/clients/modules/get.ts +71 -89
- package/src/clients/modules/local-wallet.ts +41 -56
- package/src/clients/modules/post.ts +664 -634
- package/src/clients/modules/proto-includes.ts +1 -0
- package/src/clients/modules/rest.ts +23 -26
- package/src/clients/modules/signer.ts +8 -22
- package/src/clients/modules/tendermintClient.ts +13 -36
- package/src/clients/native.ts +73 -139
- package/src/clients/noble-client.ts +1 -5
- package/src/clients/socket-client.ts +216 -216
- package/src/clients/subaccount.ts +16 -16
- package/src/clients/types.ts +14 -10
- package/src/clients/validator-client.ts +14 -16
- package/src/codegen/helpers.ts +149 -150
- package/src/codegen/index.ts +4 -5
- package/src/lib/errors.ts +3 -9
- package/src/lib/onboarding.ts +7 -2
- package/src/lib/utils.ts +5 -12
- package/src/lib/validation.ts +21 -19
- package/src/network_optimizer.ts +78 -65
- package/src/types.ts +5 -6
- package/tasks.json +15 -15
- package/tsconfig.eslint.json +1 -4
- package/tsconfig.json +2 -6
package/src/clients/constants.ts
CHANGED
|
@@ -25,7 +25,7 @@ export enum IndexerApiHost {
|
|
|
25
25
|
TESTNET = 'https://dydx-testnet.imperator.co',
|
|
26
26
|
LOCAL = 'http://localhost:3002',
|
|
27
27
|
// For the deployment by DYDX token holders
|
|
28
|
-
MAINNET = 'https://indexer.dydx.trade'
|
|
28
|
+
MAINNET = 'https://indexer.dydx.trade',
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export enum IndexerWSHost {
|
|
@@ -43,7 +43,7 @@ export enum ValidatorApiHost {
|
|
|
43
43
|
TESTNET = 'https://test-dydx.kingnodes.com',
|
|
44
44
|
LOCAL = 'http://localhost:26657',
|
|
45
45
|
// For the deployment by DYDX token holders
|
|
46
|
-
MAINNET = 'https://dydx-ops-rpc.kingnodes.com:443'
|
|
46
|
+
MAINNET = 'https://dydx-ops-rpc.kingnodes.com:443',
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// ------------ Network IDs ------------
|
|
@@ -51,7 +51,7 @@ export enum ValidatorApiHost {
|
|
|
51
51
|
export enum NetworkId {
|
|
52
52
|
TESTNET = 'dydx-testnet-4',
|
|
53
53
|
// For the deployment by DYDX token holders
|
|
54
|
-
MAINNET = 'dydx-mainnet-1'
|
|
54
|
+
MAINNET = 'dydx-mainnet-1',
|
|
55
55
|
}
|
|
56
56
|
export const NETWORK_ID_TESTNET: string = 'dydxprotocol-testnet';
|
|
57
57
|
// For the deployment by DYDX token holders
|
|
@@ -89,9 +89,16 @@ export const TYPE_URL_MSG_CREATE_ORACLE_MARKET = '/dydxprotocol.prices.MsgCreate
|
|
|
89
89
|
|
|
90
90
|
// x/sending
|
|
91
91
|
export const TYPE_URL_MSG_CREATE_TRANSFER = '/dydxprotocol.sending.MsgCreateTransfer';
|
|
92
|
-
export const TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT =
|
|
92
|
+
export const TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT =
|
|
93
|
+
'/dydxprotocol.sending.MsgWithdrawFromSubaccount';
|
|
93
94
|
export const TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT = '/dydxprotocol.sending.MsgDepositToSubaccount';
|
|
94
95
|
|
|
96
|
+
// x/staking
|
|
97
|
+
export const TYPE_URL_MSG_DELEGATE = '/cosmos.staking.v1beta1.MsgDelegate';
|
|
98
|
+
export const TYPE_URL_MSG_UNDELEGATE = '/cosmos.staking.v1beta1.MsgUndelegate';
|
|
99
|
+
export const TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD =
|
|
100
|
+
'/cosmos.staking.v1beta1.MsgWithdrawDelegatorReward';
|
|
101
|
+
|
|
95
102
|
// ------------ Chain Constants ------------
|
|
96
103
|
// The following are same across different networks / deployments.
|
|
97
104
|
export const GOV_MODULE_ADDRESS = 'dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky';
|
|
@@ -150,7 +157,7 @@ export enum OrderStatus {
|
|
|
150
157
|
}
|
|
151
158
|
|
|
152
159
|
export enum TickerType {
|
|
153
|
-
PERPETUAL = 'PERPETUAL',
|
|
160
|
+
PERPETUAL = 'PERPETUAL', // Only PERPETUAL is supported right now
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
export enum PositionStatus {
|
|
@@ -188,8 +195,7 @@ export class IndexerConfig {
|
|
|
188
195
|
public restEndpoint: string;
|
|
189
196
|
public websocketEndpoint: string;
|
|
190
197
|
|
|
191
|
-
constructor(restEndpoint: string,
|
|
192
|
-
websocketEndpoint: string) {
|
|
198
|
+
constructor(restEndpoint: string, websocketEndpoint: string) {
|
|
193
199
|
this.restEndpoint = restEndpoint;
|
|
194
200
|
this.websocketEndpoint = websocketEndpoint;
|
|
195
201
|
}
|
|
@@ -223,54 +229,60 @@ export class Network {
|
|
|
223
229
|
public env: string,
|
|
224
230
|
public indexerConfig: IndexerConfig,
|
|
225
231
|
public validatorConfig: ValidatorConfig,
|
|
226
|
-
) {
|
|
232
|
+
) {}
|
|
227
233
|
|
|
228
234
|
static testnet(): Network {
|
|
229
|
-
const indexerConfig = new IndexerConfig(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const validatorConfig = new ValidatorConfig(ValidatorApiHost.TESTNET, TESTNET_CHAIN_ID,
|
|
235
|
+
const indexerConfig = new IndexerConfig(IndexerApiHost.TESTNET, IndexerWSHost.TESTNET);
|
|
236
|
+
const validatorConfig = new ValidatorConfig(
|
|
237
|
+
ValidatorApiHost.TESTNET,
|
|
238
|
+
TESTNET_CHAIN_ID,
|
|
234
239
|
{
|
|
235
240
|
CHAINTOKEN_DENOM: 'adv4tnt',
|
|
236
241
|
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
|
|
237
242
|
USDC_GAS_DENOM: 'uusdc',
|
|
238
243
|
USDC_DECIMALS: 6,
|
|
239
244
|
CHAINTOKEN_DECIMALS: 18,
|
|
240
|
-
},
|
|
245
|
+
},
|
|
246
|
+
undefined,
|
|
247
|
+
'Client Example',
|
|
248
|
+
);
|
|
241
249
|
return new Network('testnet', indexerConfig, validatorConfig);
|
|
242
250
|
}
|
|
243
251
|
|
|
244
252
|
static local(): Network {
|
|
245
|
-
const indexerConfig = new IndexerConfig(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const validatorConfig = new ValidatorConfig(ValidatorApiHost.LOCAL, LOCAL_CHAIN_ID,
|
|
253
|
+
const indexerConfig = new IndexerConfig(IndexerApiHost.LOCAL, IndexerWSHost.LOCAL);
|
|
254
|
+
const validatorConfig = new ValidatorConfig(
|
|
255
|
+
ValidatorApiHost.LOCAL,
|
|
256
|
+
LOCAL_CHAIN_ID,
|
|
250
257
|
{
|
|
251
258
|
CHAINTOKEN_DENOM: 'adv4tnt',
|
|
252
259
|
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
|
|
253
260
|
USDC_GAS_DENOM: 'uusdc',
|
|
254
261
|
USDC_DECIMALS: 6,
|
|
255
262
|
CHAINTOKEN_DECIMALS: 18,
|
|
256
|
-
},
|
|
263
|
+
},
|
|
264
|
+
undefined,
|
|
265
|
+
'Client Example',
|
|
266
|
+
);
|
|
257
267
|
return new Network('local', indexerConfig, validatorConfig);
|
|
258
268
|
}
|
|
259
269
|
|
|
260
270
|
// For the deployment by DYDX token holders.
|
|
261
271
|
static mainnet(): Network {
|
|
262
|
-
const indexerConfig = new IndexerConfig(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const validatorConfig = new ValidatorConfig(ValidatorApiHost.MAINNET, MAINNET_CHAIN_ID,
|
|
272
|
+
const indexerConfig = new IndexerConfig(IndexerApiHost.MAINNET, IndexerWSHost.MAINNET);
|
|
273
|
+
const validatorConfig = new ValidatorConfig(
|
|
274
|
+
ValidatorApiHost.MAINNET,
|
|
275
|
+
MAINNET_CHAIN_ID,
|
|
267
276
|
{
|
|
268
277
|
CHAINTOKEN_DENOM: 'adydx',
|
|
269
278
|
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
|
|
270
279
|
USDC_GAS_DENOM: 'uusdc',
|
|
271
280
|
USDC_DECIMALS: 6,
|
|
272
281
|
CHAINTOKEN_DECIMALS: 18,
|
|
273
|
-
},
|
|
282
|
+
},
|
|
283
|
+
undefined,
|
|
284
|
+
'Client Example',
|
|
285
|
+
);
|
|
274
286
|
return new Network('mainnet', indexerConfig, validatorConfig);
|
|
275
287
|
}
|
|
276
288
|
|
|
@@ -3,10 +3,10 @@ import RestClient from './modules/rest';
|
|
|
3
3
|
|
|
4
4
|
export class FaucetClient extends RestClient {
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
* @description For testnet only, add USDC to an subaccount
|
|
7
|
+
*
|
|
8
|
+
* @returns The HTTP response.
|
|
9
|
+
*/
|
|
10
10
|
public async fill(
|
|
11
11
|
address: string,
|
|
12
12
|
subaccountNumber: number,
|
|
@@ -33,10 +33,7 @@ export class FaucetClient extends RestClient {
|
|
|
33
33
|
* @param headers requestHeaders
|
|
34
34
|
* @returns The HTTP response.
|
|
35
35
|
*/
|
|
36
|
-
public async fillNative(
|
|
37
|
-
address: string,
|
|
38
|
-
headers?: {},
|
|
39
|
-
): Promise<Response> {
|
|
36
|
+
public async fillNative(address: string, headers?: {}): Promise<Response> {
|
|
40
37
|
const uri = '/faucet/native-token';
|
|
41
38
|
|
|
42
39
|
return this.post(
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import Long from 'long';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
OrderType, OrderSide, OrderTimeInForce, OrderExecution,
|
|
5
|
-
} from '../constants';
|
|
3
|
+
import { OrderType, OrderSide, OrderTimeInForce, OrderExecution } from '../constants';
|
|
6
4
|
import { Order_ConditionType, Order_Side, Order_TimeInForce } from '../modules/proto-includes';
|
|
7
5
|
import { OrderFlags } from '../types';
|
|
8
6
|
|
|
@@ -105,10 +103,14 @@ export function calculateTimeInForce(
|
|
|
105
103
|
}
|
|
106
104
|
switch (execution) {
|
|
107
105
|
case OrderExecution.DEFAULT:
|
|
108
|
-
throw new Error(
|
|
106
|
+
throw new Error(
|
|
107
|
+
'Execution value DEFAULT not supported for STOP_MARKET or TAKE_PROFIT_MARKET',
|
|
108
|
+
);
|
|
109
109
|
|
|
110
110
|
case OrderExecution.POST_ONLY:
|
|
111
|
-
throw new Error(
|
|
111
|
+
throw new Error(
|
|
112
|
+
'Execution value POST_ONLY not supported for STOP_MARKET or TAKE_PROFIT_MARKET',
|
|
113
|
+
);
|
|
112
114
|
|
|
113
115
|
case OrderExecution.FOK:
|
|
114
116
|
return Order_TimeInForce.TIME_IN_FORCE_FILL_OR_KILL;
|
|
@@ -201,7 +203,9 @@ export function calculateConditionalOrderTriggerSubticks(
|
|
|
201
203
|
case OrderType.TAKE_PROFIT_LIMIT:
|
|
202
204
|
case OrderType.TAKE_PROFIT_MARKET:
|
|
203
205
|
if (triggerPrice === undefined) {
|
|
204
|
-
throw new Error(
|
|
206
|
+
throw new Error(
|
|
207
|
+
'triggerPrice must be set if orderType is STOP_LIMIT, STOP_MARKET, TAKE_PROFIT_LIMIT, or TAKE_PROFIT_MARKET',
|
|
208
|
+
);
|
|
205
209
|
}
|
|
206
210
|
return calculateSubticks(
|
|
207
211
|
triggerPrice,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export function generateQueryPath(url: string, params: {}): string {
|
|
2
|
-
const definedEntries = Object.entries(params)
|
|
3
|
-
|
|
2
|
+
const definedEntries = Object.entries(params).filter(
|
|
3
|
+
([_key, value]: [string, unknown]) => value !== undefined,
|
|
4
|
+
);
|
|
4
5
|
|
|
5
6
|
if (!definedEntries.length) {
|
|
6
7
|
return url;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
const paramsString = definedEntries
|
|
10
|
-
([key, value]: [string, unknown]) => `${key}=${value}
|
|
11
|
-
|
|
10
|
+
const paramsString = definedEntries
|
|
11
|
+
.map(([key, value]: [string, unknown]) => `${key}=${value}`)
|
|
12
|
+
.join('&');
|
|
12
13
|
return `${url}?${paramsString}`;
|
|
13
14
|
}
|
|
@@ -7,43 +7,43 @@ import UtilityClient from './modules/utility';
|
|
|
7
7
|
* @description Client for Indexer
|
|
8
8
|
*/
|
|
9
9
|
export class IndexerClient {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
public readonly config: IndexerConfig;
|
|
11
|
+
readonly apiTimeout: number;
|
|
12
|
+
readonly _markets: MarketsClient;
|
|
13
|
+
readonly _account: AccountClient;
|
|
14
|
+
readonly _utility: UtilityClient;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
constructor(config: IndexerConfig, apiTimeout?: number) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
this.apiTimeout = apiTimeout ?? DEFAULT_API_TIMEOUT;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
this._markets = new MarketsClient(config.restEndpoint);
|
|
21
|
+
this._account = new AccountClient(config.restEndpoint);
|
|
22
|
+
this._utility = new UtilityClient(config.restEndpoint);
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @description Get the public module, used for interacting with public endpoints.
|
|
27
|
+
*
|
|
28
|
+
* @returns The public module
|
|
29
|
+
*/
|
|
30
|
+
get markets(): MarketsClient {
|
|
31
|
+
return this._markets;
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
/**
|
|
35
|
+
* @description Get the private module, used for interacting with private endpoints.
|
|
36
|
+
*
|
|
37
|
+
* @returns The private module
|
|
38
|
+
*/
|
|
39
|
+
get account(): AccountClient {
|
|
40
|
+
return this._account;
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
}
|
|
49
49
|
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import axios, { AxiosRequestConfig } from 'axios';
|
|
2
2
|
|
|
3
3
|
import { Data } from '../../types';
|
|
4
|
-
import {
|
|
5
|
-
AxiosServerError,
|
|
6
|
-
AxiosError,
|
|
7
|
-
} from './errors';
|
|
4
|
+
import { AxiosServerError, AxiosError } from './errors';
|
|
8
5
|
import { RequestMethod } from './types';
|
|
9
6
|
|
|
10
7
|
export interface Response {
|
|
11
|
-
status: number
|
|
12
|
-
data: Data
|
|
13
|
-
headers: {}
|
|
8
|
+
status: number;
|
|
9
|
+
data: Data;
|
|
10
|
+
headers: {};
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
async function axiosRequest(options: AxiosRequestConfig): Promise<Response> {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WrappedError,
|
|
3
|
-
} from '../errors';
|
|
1
|
+
import { WrappedError } from '../errors';
|
|
4
2
|
|
|
5
3
|
interface AxiosOriginalError extends Error {
|
|
6
4
|
isAxiosError: true;
|
|
@@ -8,9 +6,9 @@ interface AxiosOriginalError extends Error {
|
|
|
8
6
|
}
|
|
9
7
|
|
|
10
8
|
interface AxiosErrorResponse {
|
|
11
|
-
status: number
|
|
12
|
-
statusText: string
|
|
13
|
-
data: {}
|
|
9
|
+
status: number;
|
|
10
|
+
statusText: string;
|
|
11
|
+
data: {};
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
/**
|
|
@@ -27,20 +25,17 @@ export class AxiosError extends WrappedError {}
|
|
|
27
25
|
* @description Axios error with response error fields.
|
|
28
26
|
*/
|
|
29
27
|
export class AxiosServerError extends AxiosError {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
public readonly status: number;
|
|
29
|
+
public readonly statusText: string;
|
|
30
|
+
public readonly data: {};
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.statusText = response.statusText;
|
|
44
|
-
this.data = response.data;
|
|
45
|
-
}
|
|
32
|
+
constructor(response: AxiosErrorResponse, originalError: AxiosOriginalError) {
|
|
33
|
+
super(
|
|
34
|
+
`${response.status}: ${response.statusText} - ${JSON.stringify(response.data, null, 2)}`,
|
|
35
|
+
originalError,
|
|
36
|
+
);
|
|
37
|
+
this.status = response.status;
|
|
38
|
+
this.statusText = response.statusText;
|
|
39
|
+
this.data = response.data;
|
|
40
|
+
}
|
|
46
41
|
}
|