@ritbit/v4-client-js 2.4.0 → 2.4.2
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/build/cjs/src/clients/composite-client.js +10 -9
- package/build/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/build/esm/src/clients/composite-client.d.ts +3 -3
- package/build/esm/src/clients/composite-client.d.ts.map +1 -1
- package/build/esm/src/clients/composite-client.js +10 -9
- package/build/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +11 -3
- package/.env +0 -1
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -15
- package/.gitleaks.toml +0 -24
- package/.gitleaksignore +0 -1
- package/.nvmrc +0 -1
- package/.prettierignore +0 -3
- package/.prettierrc.json +0 -6
- package/.releaserc +0 -10
- package/.vscode/launch.json +0 -11
- package/__native__/__ios__/v4-native-client.js +0 -251395
- package/__native__/__ios__/v4-native-client.js.map +0 -1
- package/__tests__/clients/composite-client.test.ts +0 -140
- package/__tests__/helpers/baseClients.ts +0 -23
- package/__tests__/helpers/constants.ts +0 -131
- package/__tests__/lib/helpers.test.ts +0 -55
- package/__tests__/lib/util.test.ts +0 -77
- package/__tests__/lib/validation.test.ts +0 -289
- package/__tests__/modules/client/AccountEndpoints.test.ts +0 -236
- package/__tests__/modules/client/FaucetEndpoint.test.ts +0 -14
- package/__tests__/modules/client/MarketsEndpoints.test.ts +0 -84
- package/__tests__/modules/client/Transfers.test.ts +0 -44
- package/__tests__/modules/client/UtilityEndpoints.test.ts +0 -29
- package/__tests__/modules/client/ValidatorGetEndpoints.test.ts +0 -50
- package/__tests__/modules/client/ValidatorPostEndpoints.test.ts +0 -52
- package/__tests__/modules/client/constants.ts +0 -5
- package/__tests__/modules/onboarding.test.ts +0 -66
- package/build/cjs/__tests__/clients/composite-client.test.js +0 -130
- package/build/cjs/__tests__/helpers/baseClients.js +0 -29
- package/build/cjs/__tests__/helpers/constants.js +0 -110
- package/build/cjs/__tests__/lib/helpers.test.js +0 -46
- package/build/cjs/__tests__/lib/util.test.js +0 -67
- package/build/cjs/__tests__/lib/validation.test.js +0 -254
- package/build/cjs/__tests__/modules/client/AccountEndpoints.test.js +0 -171
- package/build/cjs/__tests__/modules/client/FaucetEndpoint.test.js +0 -15
- package/build/cjs/__tests__/modules/client/MarketsEndpoints.test.js +0 -69
- package/build/cjs/__tests__/modules/client/Transfers.test.js +0 -44
- package/build/cjs/__tests__/modules/client/UtilityEndpoints.test.js +0 -28
- package/build/cjs/__tests__/modules/client/ValidatorGetEndpoints.test.js +0 -46
- package/build/cjs/__tests__/modules/client/ValidatorPostEndpoints.test.js +0 -53
- package/build/cjs/__tests__/modules/client/constants.js +0 -7
- package/build/cjs/__tests__/modules/onboarding.test.js +0 -50
- package/build/cjs/examples/account_endpoints.js +0 -129
- package/build/cjs/examples/batch_cancel_orders_example.js +0 -93
- package/build/cjs/examples/composite_example.js +0 -50
- package/build/cjs/examples/constants.js +0 -35
- package/build/cjs/examples/faucet_endpoint.js +0 -23
- package/build/cjs/examples/gov_add_new_market.js +0 -77
- package/build/cjs/examples/human_readable_orders.json +0 -86
- package/build/cjs/examples/human_readable_short_term_orders.json +0 -42
- package/build/cjs/examples/json-encoding.js +0 -32
- package/build/cjs/examples/long_term_order_cancel_example.js +0 -63
- package/build/cjs/examples/markets_endpoints.js +0 -134
- package/build/cjs/examples/native_examples.js +0 -112
- package/build/cjs/examples/noble_example.js +0 -88
- package/build/cjs/examples/optimal_node.js +0 -70
- package/build/cjs/examples/permissioned_keys_example.js +0 -104
- package/build/cjs/examples/raw_orders.json +0 -130
- package/build/cjs/examples/short_term_order_cancel_example.js +0 -54
- package/build/cjs/examples/short_term_order_composite_example.js +0 -68
- package/build/cjs/examples/test.js +0 -50
- package/build/cjs/examples/transfer_example_deposit.js +0 -29
- package/build/cjs/examples/transfer_example_send.js +0 -42
- package/build/cjs/examples/transfer_example_subaccount_transfer.js +0 -29
- package/build/cjs/examples/transfer_example_withdraw.js +0 -30
- package/build/cjs/examples/transfer_example_withdraw_other.js +0 -42
- package/build/cjs/examples/utility_endpoints.js +0 -42
- package/build/cjs/examples/validator_get_example.js +0 -158
- package/build/cjs/examples/validator_post_example.js +0 -76
- package/build/cjs/examples/wallet_address.js +0 -22
- package/build/cjs/examples/websocket_example.js +0 -36
- package/build/cjs/examples/websocket_orderbook_example.js +0 -196
- package/build/esm/__tests__/clients/composite-client.test.d.ts +0 -2
- package/build/esm/__tests__/clients/composite-client.test.d.ts.map +0 -1
- package/build/esm/__tests__/clients/composite-client.test.js +0 -128
- package/build/esm/__tests__/helpers/baseClients.d.ts +0 -19
- package/build/esm/__tests__/helpers/baseClients.d.ts.map +0 -1
- package/build/esm/__tests__/helpers/baseClients.js +0 -22
- package/build/esm/__tests__/helpers/constants.d.ts +0 -19
- package/build/esm/__tests__/helpers/constants.d.ts.map +0 -1
- package/build/esm/__tests__/helpers/constants.js +0 -104
- package/build/esm/__tests__/lib/helpers.test.d.ts +0 -2
- package/build/esm/__tests__/lib/helpers.test.d.ts.map +0 -1
- package/build/esm/__tests__/lib/helpers.test.js +0 -41
- package/build/esm/__tests__/lib/util.test.d.ts +0 -2
- package/build/esm/__tests__/lib/util.test.d.ts.map +0 -1
- package/build/esm/__tests__/lib/util.test.js +0 -65
- package/build/esm/__tests__/lib/validation.test.d.ts +0 -2
- package/build/esm/__tests__/lib/validation.test.d.ts.map +0 -1
- package/build/esm/__tests__/lib/validation.test.js +0 -249
- package/build/esm/__tests__/modules/client/AccountEndpoints.test.d.ts +0 -2
- package/build/esm/__tests__/modules/client/AccountEndpoints.test.d.ts.map +0 -1
- package/build/esm/__tests__/modules/client/AccountEndpoints.test.js +0 -169
- package/build/esm/__tests__/modules/client/FaucetEndpoint.test.d.ts +0 -2
- package/build/esm/__tests__/modules/client/FaucetEndpoint.test.d.ts.map +0 -1
- package/build/esm/__tests__/modules/client/FaucetEndpoint.test.js +0 -13
- package/build/esm/__tests__/modules/client/MarketsEndpoints.test.d.ts +0 -2
- package/build/esm/__tests__/modules/client/MarketsEndpoints.test.d.ts.map +0 -1
- package/build/esm/__tests__/modules/client/MarketsEndpoints.test.js +0 -66
- package/build/esm/__tests__/modules/client/Transfers.test.d.ts +0 -2
- package/build/esm/__tests__/modules/client/Transfers.test.d.ts.map +0 -1
- package/build/esm/__tests__/modules/client/Transfers.test.js +0 -39
- package/build/esm/__tests__/modules/client/UtilityEndpoints.test.d.ts +0 -2
- package/build/esm/__tests__/modules/client/UtilityEndpoints.test.d.ts.map +0 -1
- package/build/esm/__tests__/modules/client/UtilityEndpoints.test.js +0 -26
- package/build/esm/__tests__/modules/client/ValidatorGetEndpoints.test.d.ts +0 -2
- package/build/esm/__tests__/modules/client/ValidatorGetEndpoints.test.d.ts.map +0 -1
- package/build/esm/__tests__/modules/client/ValidatorGetEndpoints.test.js +0 -44
- package/build/esm/__tests__/modules/client/ValidatorPostEndpoints.test.d.ts +0 -2
- package/build/esm/__tests__/modules/client/ValidatorPostEndpoints.test.d.ts.map +0 -1
- package/build/esm/__tests__/modules/client/ValidatorPostEndpoints.test.js +0 -48
- package/build/esm/__tests__/modules/client/constants.d.ts +0 -4
- package/build/esm/__tests__/modules/client/constants.d.ts.map +0 -1
- package/build/esm/__tests__/modules/client/constants.js +0 -4
- package/build/esm/__tests__/modules/onboarding.test.d.ts +0 -2
- package/build/esm/__tests__/modules/onboarding.test.d.ts.map +0 -1
- package/build/esm/__tests__/modules/onboarding.test.js +0 -48
- package/build/esm/examples/account_endpoints.d.ts +0 -5
- package/build/esm/examples/account_endpoints.d.ts.map +0 -1
- package/build/esm/examples/account_endpoints.js +0 -127
- package/build/esm/examples/batch_cancel_orders_example.d.ts +0 -2
- package/build/esm/examples/batch_cancel_orders_example.d.ts.map +0 -1
- package/build/esm/examples/batch_cancel_orders_example.js +0 -88
- package/build/esm/examples/composite_example.d.ts +0 -2
- package/build/esm/examples/composite_example.d.ts.map +0 -1
- package/build/esm/examples/composite_example.js +0 -45
- package/build/esm/examples/constants.d.ts +0 -13
- package/build/esm/examples/constants.d.ts.map +0 -1
- package/build/esm/examples/constants.js +0 -29
- package/build/esm/examples/faucet_endpoint.d.ts +0 -5
- package/build/esm/examples/faucet_endpoint.d.ts.map +0 -1
- package/build/esm/examples/faucet_endpoint.js +0 -21
- package/build/esm/examples/gov_add_new_market.d.ts +0 -2
- package/build/esm/examples/gov_add_new_market.d.ts.map +0 -1
- package/build/esm/examples/gov_add_new_market.js +0 -72
- package/build/esm/examples/human_readable_orders.json +0 -86
- package/build/esm/examples/human_readable_short_term_orders.json +0 -42
- package/build/esm/examples/json-encoding.d.ts +0 -2
- package/build/esm/examples/json-encoding.d.ts.map +0 -1
- package/build/esm/examples/json-encoding.js +0 -27
- package/build/esm/examples/long_term_order_cancel_example.d.ts +0 -2
- package/build/esm/examples/long_term_order_cancel_example.d.ts.map +0 -1
- package/build/esm/examples/long_term_order_cancel_example.js +0 -58
- package/build/esm/examples/markets_endpoints.d.ts +0 -5
- package/build/esm/examples/markets_endpoints.d.ts.map +0 -1
- package/build/esm/examples/markets_endpoints.js +0 -131
- package/build/esm/examples/native_examples.d.ts +0 -2
- package/build/esm/examples/native_examples.d.ts.map +0 -1
- package/build/esm/examples/native_examples.js +0 -110
- package/build/esm/examples/noble_example.d.ts +0 -2
- package/build/esm/examples/noble_example.d.ts.map +0 -1
- package/build/esm/examples/noble_example.js +0 -83
- package/build/esm/examples/optimal_node.d.ts +0 -2
- package/build/esm/examples/optimal_node.d.ts.map +0 -1
- package/build/esm/examples/optimal_node.js +0 -68
- package/build/esm/examples/permissioned_keys_example.d.ts +0 -2
- package/build/esm/examples/permissioned_keys_example.d.ts.map +0 -1
- package/build/esm/examples/permissioned_keys_example.js +0 -99
- package/build/esm/examples/raw_orders.json +0 -130
- package/build/esm/examples/short_term_order_cancel_example.d.ts +0 -2
- package/build/esm/examples/short_term_order_cancel_example.d.ts.map +0 -1
- package/build/esm/examples/short_term_order_cancel_example.js +0 -49
- package/build/esm/examples/short_term_order_composite_example.d.ts +0 -2
- package/build/esm/examples/short_term_order_composite_example.d.ts.map +0 -1
- package/build/esm/examples/short_term_order_composite_example.js +0 -63
- package/build/esm/examples/test.d.ts +0 -2
- package/build/esm/examples/test.d.ts.map +0 -1
- package/build/esm/examples/test.js +0 -45
- package/build/esm/examples/transfer_example_deposit.d.ts +0 -2
- package/build/esm/examples/transfer_example_deposit.d.ts.map +0 -1
- package/build/esm/examples/transfer_example_deposit.js +0 -24
- package/build/esm/examples/transfer_example_send.d.ts +0 -2
- package/build/esm/examples/transfer_example_send.d.ts.map +0 -1
- package/build/esm/examples/transfer_example_send.js +0 -37
- package/build/esm/examples/transfer_example_subaccount_transfer.d.ts +0 -2
- package/build/esm/examples/transfer_example_subaccount_transfer.d.ts.map +0 -1
- package/build/esm/examples/transfer_example_subaccount_transfer.js +0 -24
- package/build/esm/examples/transfer_example_withdraw.d.ts +0 -2
- package/build/esm/examples/transfer_example_withdraw.d.ts.map +0 -1
- package/build/esm/examples/transfer_example_withdraw.js +0 -25
- package/build/esm/examples/transfer_example_withdraw_other.d.ts +0 -2
- package/build/esm/examples/transfer_example_withdraw_other.d.ts.map +0 -1
- package/build/esm/examples/transfer_example_withdraw_other.js +0 -37
- package/build/esm/examples/utility_endpoints.d.ts +0 -5
- package/build/esm/examples/utility_endpoints.d.ts.map +0 -1
- package/build/esm/examples/utility_endpoints.js +0 -40
- package/build/esm/examples/validator_get_example.d.ts +0 -2
- package/build/esm/examples/validator_get_example.d.ts.map +0 -1
- package/build/esm/examples/validator_get_example.js +0 -156
- package/build/esm/examples/validator_post_example.d.ts +0 -2
- package/build/esm/examples/validator_post_example.d.ts.map +0 -1
- package/build/esm/examples/validator_post_example.js +0 -71
- package/build/esm/examples/wallet_address.d.ts +0 -2
- package/build/esm/examples/wallet_address.d.ts.map +0 -1
- package/build/esm/examples/wallet_address.js +0 -17
- package/build/esm/examples/websocket_example.d.ts +0 -2
- package/build/esm/examples/websocket_example.d.ts.map +0 -1
- package/build/esm/examples/websocket_example.js +0 -34
- package/build/esm/examples/websocket_orderbook_example.d.ts +0 -2
- package/build/esm/examples/websocket_orderbook_example.d.ts.map +0 -1
- package/build/esm/examples/websocket_orderbook_example.js +0 -194
- package/commitlint.config.js +0 -8
- package/examples/account_endpoints.ts +0 -129
- package/examples/batch_cancel_orders_example.ts +0 -130
- package/examples/composite_example.ts +0 -65
- package/examples/constants.ts +0 -42
- package/examples/faucet_endpoint.ts +0 -24
- package/examples/gov_add_new_market.json +0 -64
- package/examples/gov_add_new_market.ts +0 -95
- package/examples/human_readable_orders.json +0 -86
- package/examples/human_readable_short_term_orders.json +0 -42
- package/examples/json-encoding.ts +0 -33
- package/examples/long_term_order_cancel_example.ts +0 -87
- package/examples/markets_endpoints.ts +0 -134
- package/examples/native_examples.ts +0 -151
- package/examples/noble_example.ts +0 -107
- package/examples/optimal_node.ts +0 -70
- package/examples/permissioned_keys_example.ts +0 -162
- package/examples/raw_orders.json +0 -130
- package/examples/short_term_order_cancel_example.ts +0 -68
- package/examples/short_term_order_composite_example.ts +0 -80
- package/examples/test.ts +0 -65
- package/examples/transfer_example_deposit.ts +0 -28
- package/examples/transfer_example_send.ts +0 -60
- package/examples/transfer_example_subaccount_transfer.ts +0 -29
- package/examples/transfer_example_withdraw.ts +0 -31
- package/examples/transfer_example_withdraw_other.ts +0 -60
- package/examples/utility_endpoints.ts +0 -42
- package/examples/validator_get_example.ts +0 -160
- package/examples/validator_post_example.ts +0 -81
- package/examples/wallet_address.ts +0 -18
- package/examples/websocket_example.ts +0 -44
- package/examples/websocket_orderbook_example.ts +0 -239
- package/jest.config.js +0 -12
- package/jest.globalSetup.js +0 -5
- package/jest.setup.js +0 -1
- package/ritbit-v4-client-js-2.2.6.tgz +0 -0
- package/scripts/bump_version.sh +0 -16
- package/scripts/generate-cctp-protos.sh +0 -41
- package/scripts/mobile_build_pack.sh +0 -5
- package/scripts/publish-if-not-exists.sh +0 -21
- package/src/clients/composite-client.ts +0 -1469
- package/src/clients/constants.ts +0 -361
- package/src/clients/faucet-client.ts +0 -48
- package/src/clients/helpers/chain-helpers.ts +0 -231
- package/src/clients/helpers/request-helpers.ts +0 -71
- package/src/clients/indexer-client.ts +0 -61
- package/src/clients/lib/axios/axiosRequest.ts +0 -41
- package/src/clients/lib/axios/errors.ts +0 -41
- package/src/clients/lib/axios/index.ts +0 -7
- package/src/clients/lib/axios/types.ts +0 -6
- package/src/clients/lib/cctpProto.ts +0 -4197
- package/src/clients/lib/errors.ts +0 -63
- package/src/clients/lib/registry.ts +0 -93
- package/src/clients/modules/account.ts +0 -438
- package/src/clients/modules/composer.ts +0 -669
- package/src/clients/modules/get.ts +0 -791
- package/src/clients/modules/local-wallet.ts +0 -79
- package/src/clients/modules/markets.ts +0 -76
- package/src/clients/modules/post.ts +0 -1043
- package/src/clients/modules/proto-includes.ts +0 -34
- package/src/clients/modules/rest.ts +0 -40
- package/src/clients/modules/signer.ts +0 -139
- package/src/clients/modules/tendermintClient.ts +0 -168
- package/src/clients/modules/utility.ts +0 -47
- package/src/clients/modules/vault.ts +0 -23
- package/src/clients/native.ts +0 -1689
- package/src/clients/noble-client.ts +0 -108
- package/src/clients/socket-client.ts +0 -331
- package/src/clients/subaccount.ts +0 -57
- package/src/clients/types.ts +0 -191
- package/src/clients/validator-client.ts +0 -106
- package/src/index.ts +0 -19
- package/src/lib/constants.ts +0 -28
- package/src/lib/errors.ts +0 -38
- package/src/lib/helpers.ts +0 -99
- package/src/lib/onboarding.ts +0 -96
- package/src/lib/trading-key-utils.ts +0 -136
- package/src/lib/utils.ts +0 -84
- package/src/lib/validation.ts +0 -197
- package/src/network_optimizer.ts +0 -132
- package/src/types.ts +0 -44
- package/tasks.json +0 -16
- package/tsconfig.base.json +0 -21
- package/tsconfig.cjs.json +0 -10
- package/tsconfig.eslint.json +0 -14
- package/tsconfig.esm.json +0 -11
- package/tsconfig.json +0 -6
- package/webpack.config.js +0 -56
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClobPairId,
|
|
3
|
-
IBatchCancelOrder,
|
|
4
|
-
ICancelOrder,
|
|
5
|
-
IPlaceOrder,
|
|
6
|
-
OrderFlags,
|
|
7
|
-
MsgTransfer,
|
|
8
|
-
} from '../../src/types';
|
|
9
|
-
import { MAX_SUBACCOUNT_NUMBER, MAX_UINT_32 } from '../../src/lib/constants';
|
|
10
|
-
import { UserError } from '../../src/lib/errors';
|
|
11
|
-
import {
|
|
12
|
-
isValidAddress,
|
|
13
|
-
validateBatchCancelOrderMessage,
|
|
14
|
-
validateCancelOrderMessage,
|
|
15
|
-
validatePlaceOrderMessage,
|
|
16
|
-
validateTransferMessage,
|
|
17
|
-
} from '../../src/lib/validation';
|
|
18
|
-
import {
|
|
19
|
-
TEST_ADDRESS,
|
|
20
|
-
defaultCancelOrder,
|
|
21
|
-
defaultBatchCancelOrder,
|
|
22
|
-
defaultOrder,
|
|
23
|
-
defaultTransfer,
|
|
24
|
-
} from '../helpers/constants';
|
|
25
|
-
import Long from 'long';
|
|
26
|
-
|
|
27
|
-
const MAX_UINT_32_PLUS_1: number = MAX_UINT_32 + 1;
|
|
28
|
-
const MAX_SUBACCOUNT_NUMBER_PLUS_1: number = MAX_SUBACCOUNT_NUMBER + 1;
|
|
29
|
-
|
|
30
|
-
describe('Validations', () => {
|
|
31
|
-
it.each([
|
|
32
|
-
['valid', defaultOrder, undefined],
|
|
33
|
-
['0 value clientId', { ...defaultOrder, clientId: 0 }, undefined],
|
|
34
|
-
[
|
|
35
|
-
'underflow clientId',
|
|
36
|
-
{ ...defaultOrder, clientId: -1 },
|
|
37
|
-
new UserError(`clientId: ${-1} is not a valid uint32`),
|
|
38
|
-
],
|
|
39
|
-
[
|
|
40
|
-
'overflow clientId',
|
|
41
|
-
{ ...defaultOrder, clientId: MAX_UINT_32_PLUS_1 },
|
|
42
|
-
new UserError(`clientId: ${MAX_UINT_32_PLUS_1} is not a valid uint32`),
|
|
43
|
-
],
|
|
44
|
-
[
|
|
45
|
-
'underflow quantums',
|
|
46
|
-
{ ...defaultOrder, quantums: Long.NEG_ONE },
|
|
47
|
-
new UserError(`quantums: ${-1} cannot be <= 0`),
|
|
48
|
-
],
|
|
49
|
-
[
|
|
50
|
-
'underflow goodTilBlock',
|
|
51
|
-
{ ...defaultOrder, goodTilBlock: -1 },
|
|
52
|
-
new UserError(`goodTilBlock: ${-1} is not a valid uint32 or is 0`),
|
|
53
|
-
],
|
|
54
|
-
[
|
|
55
|
-
'overflow goodTilBlock',
|
|
56
|
-
{ ...defaultOrder, goodTilBlock: MAX_UINT_32_PLUS_1 },
|
|
57
|
-
new UserError(`goodTilBlock: ${MAX_UINT_32_PLUS_1} is not a valid uint32 or is 0`),
|
|
58
|
-
],
|
|
59
|
-
[
|
|
60
|
-
'0 goodTilBlock',
|
|
61
|
-
{ ...defaultOrder, goodTilBlock: 0 },
|
|
62
|
-
new UserError(`goodTilBlock: ${0} is not a valid uint32 or is 0`),
|
|
63
|
-
],
|
|
64
|
-
[
|
|
65
|
-
'underflow subticks',
|
|
66
|
-
{ ...defaultOrder, subticks: Long.NEG_ONE },
|
|
67
|
-
new UserError(`subticks: ${-1} cannot be <= 0`),
|
|
68
|
-
],
|
|
69
|
-
])(
|
|
70
|
-
'Validate order: %s',
|
|
71
|
-
(_name: string, order: IPlaceOrder, expectedError: UserError | undefined) => {
|
|
72
|
-
const validationError: UserError | void = validatePlaceOrderMessage(0, order);
|
|
73
|
-
expect(validationError).toEqual(expectedError);
|
|
74
|
-
},
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
it.each([
|
|
78
|
-
['valid', defaultCancelOrder, undefined],
|
|
79
|
-
['0 value clientId', { ...defaultCancelOrder, clientId: 0 }, undefined],
|
|
80
|
-
[
|
|
81
|
-
'underflow clientId',
|
|
82
|
-
{ ...defaultCancelOrder, clientId: -1 },
|
|
83
|
-
new UserError(`clientId: ${-1} is not a valid uint32`),
|
|
84
|
-
],
|
|
85
|
-
[
|
|
86
|
-
'overflow clientId',
|
|
87
|
-
{ ...defaultCancelOrder, clientId: MAX_UINT_32_PLUS_1 },
|
|
88
|
-
new UserError(`clientId: ${MAX_UINT_32_PLUS_1} is not a valid uint32`),
|
|
89
|
-
],
|
|
90
|
-
[
|
|
91
|
-
'underflow goodTilBlock',
|
|
92
|
-
{ ...defaultCancelOrder, goodTilBlock: -1 },
|
|
93
|
-
new UserError(`goodTilBlock: ${-1} is not a valid uint32 or is 0`),
|
|
94
|
-
],
|
|
95
|
-
[
|
|
96
|
-
'overflow goodTilBlock',
|
|
97
|
-
{ ...defaultCancelOrder, goodTilBlock: MAX_UINT_32_PLUS_1 },
|
|
98
|
-
new UserError(`goodTilBlock: ${MAX_UINT_32_PLUS_1} is not a valid uint32 or is 0`),
|
|
99
|
-
],
|
|
100
|
-
[
|
|
101
|
-
'0 goodTilBlock',
|
|
102
|
-
{ ...defaultCancelOrder, goodTilBlock: 0 },
|
|
103
|
-
new UserError(`goodTilBlock: ${0} is not a valid uint32 or is 0`),
|
|
104
|
-
],
|
|
105
|
-
[
|
|
106
|
-
'contains GoodTilBlockTime',
|
|
107
|
-
{ ...defaultCancelOrder, goodTilBlockTime: 10 },
|
|
108
|
-
new UserError('goodTilBlockTime is 10, but should not be set for non-stateful orders'),
|
|
109
|
-
],
|
|
110
|
-
[
|
|
111
|
-
'stateful order - valid',
|
|
112
|
-
{
|
|
113
|
-
...defaultCancelOrder,
|
|
114
|
-
orderFlags: OrderFlags.LONG_TERM,
|
|
115
|
-
goodTilBlock: undefined,
|
|
116
|
-
goodTilBlockTime: 10,
|
|
117
|
-
},
|
|
118
|
-
undefined,
|
|
119
|
-
],
|
|
120
|
-
[
|
|
121
|
-
'stateful order - undefined goodTilBlockTime',
|
|
122
|
-
{ ...defaultCancelOrder, orderFlags: OrderFlags.LONG_TERM },
|
|
123
|
-
new UserError(`goodTilBlockTime: ${undefined} is not a valid uint32 or is 0`),
|
|
124
|
-
],
|
|
125
|
-
[
|
|
126
|
-
'stateful order - zero goodTilBlockTime',
|
|
127
|
-
{ ...defaultCancelOrder, orderFlags: OrderFlags.LONG_TERM, goodTilBlockTime: 0 },
|
|
128
|
-
new UserError(`goodTilBlockTime: ${0} is not a valid uint32 or is 0`),
|
|
129
|
-
],
|
|
130
|
-
[
|
|
131
|
-
'stateful order - underflow goodTilBlockTime',
|
|
132
|
-
{ ...defaultCancelOrder, orderFlags: OrderFlags.LONG_TERM, goodTilBlockTime: -1 },
|
|
133
|
-
new UserError(`goodTilBlockTime: ${-1} is not a valid uint32 or is 0`),
|
|
134
|
-
],
|
|
135
|
-
[
|
|
136
|
-
'stateful order - overflow goodTilBlockTime',
|
|
137
|
-
{
|
|
138
|
-
...defaultCancelOrder,
|
|
139
|
-
orderFlags: OrderFlags.LONG_TERM,
|
|
140
|
-
goodTilBlockTime: MAX_UINT_32_PLUS_1,
|
|
141
|
-
},
|
|
142
|
-
new UserError(`goodTilBlockTime: ${MAX_UINT_32_PLUS_1} is not a valid uint32 or is 0`),
|
|
143
|
-
],
|
|
144
|
-
[
|
|
145
|
-
'stateful order - has GoodTilBlock',
|
|
146
|
-
{
|
|
147
|
-
...defaultCancelOrder,
|
|
148
|
-
orderFlags: OrderFlags.LONG_TERM,
|
|
149
|
-
goodTilBlock: 10,
|
|
150
|
-
goodTilBlockTime: 10,
|
|
151
|
-
},
|
|
152
|
-
new UserError('goodTilBlock is 10, but should not be set for stateful orders'),
|
|
153
|
-
],
|
|
154
|
-
])(
|
|
155
|
-
'Validate cancel order: %s',
|
|
156
|
-
(_name: string, order: ICancelOrder, expectedError: UserError | undefined) => {
|
|
157
|
-
const validationError: UserError | void = validateCancelOrderMessage(0, order);
|
|
158
|
-
expect(validationError).toEqual(expectedError);
|
|
159
|
-
},
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
it.each([
|
|
163
|
-
['valid', defaultBatchCancelOrder, undefined],
|
|
164
|
-
[
|
|
165
|
-
'overflow clientId',
|
|
166
|
-
{
|
|
167
|
-
...defaultBatchCancelOrder,
|
|
168
|
-
shortTermOrders: [
|
|
169
|
-
...defaultBatchCancelOrder.shortTermOrders,
|
|
170
|
-
{
|
|
171
|
-
clobPairId: ClobPairId.PERPETUAL_PAIR_ETH_USD,
|
|
172
|
-
clientIds: [MAX_UINT_32_PLUS_1],
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
},
|
|
176
|
-
new UserError(`clientId: ${MAX_UINT_32_PLUS_1} is not a valid uint32`),
|
|
177
|
-
],
|
|
178
|
-
[
|
|
179
|
-
'underflow goodTilBlock',
|
|
180
|
-
{ ...defaultBatchCancelOrder, goodTilBlock: -1 },
|
|
181
|
-
new UserError(`goodTilBlock: ${-1} is not a valid uint32 or is 0`),
|
|
182
|
-
],
|
|
183
|
-
[
|
|
184
|
-
'overflow goodTilBlock',
|
|
185
|
-
{ ...defaultBatchCancelOrder, goodTilBlock: MAX_UINT_32_PLUS_1 },
|
|
186
|
-
new UserError(`goodTilBlock: ${MAX_UINT_32_PLUS_1} is not a valid uint32 or is 0`),
|
|
187
|
-
],
|
|
188
|
-
[
|
|
189
|
-
'0 goodTilBlock',
|
|
190
|
-
{ ...defaultBatchCancelOrder, goodTilBlock: 0 },
|
|
191
|
-
new UserError(`goodTilBlock: ${0} is not a valid uint32 or is 0`),
|
|
192
|
-
],
|
|
193
|
-
])(
|
|
194
|
-
'Validate batch cancel orders: %s',
|
|
195
|
-
(_name: string, orders: IBatchCancelOrder, expectedError: UserError | undefined) => {
|
|
196
|
-
const validationError: UserError | void = validateBatchCancelOrderMessage(0, orders);
|
|
197
|
-
expect(validationError).toEqual(expectedError);
|
|
198
|
-
},
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
it.each([
|
|
202
|
-
['valid', defaultTransfer, undefined],
|
|
203
|
-
[
|
|
204
|
-
'underflow senderSubaccountNumber',
|
|
205
|
-
{ ...defaultTransfer, sender: { owner: TEST_ADDRESS, number: -1 } },
|
|
206
|
-
new UserError(`senderSubaccountNumber: ${-1} cannot be < 0 or > ${MAX_SUBACCOUNT_NUMBER}`),
|
|
207
|
-
],
|
|
208
|
-
[
|
|
209
|
-
'exceeds max subaccount number - senderSubaccountNumber',
|
|
210
|
-
{ ...defaultTransfer, sender: { owner: TEST_ADDRESS, number: MAX_SUBACCOUNT_NUMBER_PLUS_1 } },
|
|
211
|
-
new UserError(
|
|
212
|
-
`senderSubaccountNumber: ${MAX_SUBACCOUNT_NUMBER_PLUS_1} cannot be < 0 or > ${MAX_SUBACCOUNT_NUMBER}`,
|
|
213
|
-
),
|
|
214
|
-
],
|
|
215
|
-
[
|
|
216
|
-
'0 senderSubaccountNumber',
|
|
217
|
-
{ ...defaultTransfer, sender: { owner: TEST_ADDRESS, number: 0 } },
|
|
218
|
-
undefined,
|
|
219
|
-
],
|
|
220
|
-
[
|
|
221
|
-
'underflow recipientSubaccountNumber',
|
|
222
|
-
{ ...defaultTransfer, recipient: { owner: TEST_ADDRESS, number: -1 } },
|
|
223
|
-
new UserError(`recipientSubaccountNumber: ${-1} cannot be < 0 or > ${MAX_SUBACCOUNT_NUMBER}`),
|
|
224
|
-
],
|
|
225
|
-
[
|
|
226
|
-
'exceeds max subaccount number - recipient.subaccountNumber',
|
|
227
|
-
{
|
|
228
|
-
...defaultTransfer,
|
|
229
|
-
recipient: { owner: TEST_ADDRESS, number: MAX_SUBACCOUNT_NUMBER_PLUS_1 },
|
|
230
|
-
},
|
|
231
|
-
new UserError(
|
|
232
|
-
`recipientSubaccountNumber: ${MAX_SUBACCOUNT_NUMBER_PLUS_1} cannot be < 0 or > ${MAX_SUBACCOUNT_NUMBER}`,
|
|
233
|
-
),
|
|
234
|
-
],
|
|
235
|
-
[
|
|
236
|
-
'0 recipientSubaccountNumber',
|
|
237
|
-
{ ...defaultTransfer, recipient: { owner: TEST_ADDRESS, number: 0 } },
|
|
238
|
-
undefined,
|
|
239
|
-
],
|
|
240
|
-
[
|
|
241
|
-
'non-zero asset id',
|
|
242
|
-
{ ...defaultTransfer, assetId: 1 },
|
|
243
|
-
new UserError(`asset id: ${1} not supported`),
|
|
244
|
-
],
|
|
245
|
-
[
|
|
246
|
-
'0 amount',
|
|
247
|
-
{ ...defaultTransfer, amount: Long.ZERO },
|
|
248
|
-
new UserError(`amount: ${0} cannot be <= 0`),
|
|
249
|
-
],
|
|
250
|
-
[
|
|
251
|
-
'too short recipientAddress',
|
|
252
|
-
{
|
|
253
|
-
...defaultTransfer,
|
|
254
|
-
recipient: {
|
|
255
|
-
owner: 'dydx14063jves4u9zhm7eja5ltf3t8zspxd92qnk23',
|
|
256
|
-
number: 0,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
new UserError('Error: Invalid checksum for dydx14063jves4u9zhm7eja5ltf3t8zspxd92qnk23'),
|
|
260
|
-
],
|
|
261
|
-
[
|
|
262
|
-
'invalid recipientAddress',
|
|
263
|
-
{
|
|
264
|
-
...defaultTransfer,
|
|
265
|
-
recipient: {
|
|
266
|
-
owner: 'fakeAddress1234',
|
|
267
|
-
number: 0,
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
new UserError('Error: Mixed-case string fakeAddress1234'),
|
|
271
|
-
],
|
|
272
|
-
])(
|
|
273
|
-
'Validate transfer: %s',
|
|
274
|
-
(_name: string, transfer: MsgTransfer, expectedError: UserError | undefined) => {
|
|
275
|
-
const validationError: UserError | void = validateTransferMessage(transfer);
|
|
276
|
-
expect(validationError).toEqual(expectedError);
|
|
277
|
-
},
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
it.each([
|
|
281
|
-
['valid', 'dydx17xpfvakm2amg962yls6f84z3kell8c5leqdyt2', true],
|
|
282
|
-
['invalid: does not start with dydx1', 'dydx27xpfvakm2amg962yls6f84z3kell8c5leqdyt2', false],
|
|
283
|
-
['invalid: too short', 'dydx17xpfvakm2amg962yls6f84z3kell8c5leqdyt', false],
|
|
284
|
-
['invalid: too long', 'dydx17xpfvakm2amg962yls6f84z3kell8c5leqdyt2s', false],
|
|
285
|
-
])('Validate address: %s', (_name: string, address: string, expectedResult: boolean) => {
|
|
286
|
-
const validationResult: boolean = isValidAddress(address);
|
|
287
|
-
expect(validationResult).toEqual(expectedResult);
|
|
288
|
-
});
|
|
289
|
-
});
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { Network } from '../../../src/clients/constants';
|
|
2
|
-
import { IndexerClient } from '../../../src/clients/indexer-client';
|
|
3
|
-
import { TEST_ADDRESS } from './constants';
|
|
4
|
-
|
|
5
|
-
describe('IndexerClient', () => {
|
|
6
|
-
const client = new IndexerClient(Network.testnet().indexerConfig);
|
|
7
|
-
|
|
8
|
-
describe('Private Endpoints', () => {
|
|
9
|
-
it('Subaccounts', async () => {
|
|
10
|
-
const response = await client.account.getSubaccounts(TEST_ADDRESS);
|
|
11
|
-
const subaccounts = response.subaccounts;
|
|
12
|
-
expect(subaccounts.size).not.toBeNull();
|
|
13
|
-
const subaccount0 = subaccounts[0];
|
|
14
|
-
const subaccountNumber = subaccount0.subaccountNumber;
|
|
15
|
-
expect(subaccountNumber).not.toBeNull();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('Subaccount 0', async () => {
|
|
19
|
-
const response = await client.account.getSubaccount(TEST_ADDRESS, 0);
|
|
20
|
-
const subaccount = response.subaccount;
|
|
21
|
-
expect(subaccount).not.toBeNull();
|
|
22
|
-
const subaccountNumber = subaccount.subaccountNumber;
|
|
23
|
-
expect(subaccountNumber).not.toBeNull();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('Asset Positions', async () => {
|
|
27
|
-
const response = await client.account.getSubaccountAssetPositions(TEST_ADDRESS, 0);
|
|
28
|
-
expect(response).not.toBeNull();
|
|
29
|
-
const positions = response.positions;
|
|
30
|
-
expect(positions).not.toBeNull();
|
|
31
|
-
if (positions.length > 0) {
|
|
32
|
-
const position = positions[0];
|
|
33
|
-
expect(position).not.toBeNull();
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('Perpetual Positions', async () => {
|
|
38
|
-
const response = await client.account.getSubaccountPerpetualPositions(TEST_ADDRESS, 0);
|
|
39
|
-
expect(response).not.toBeNull();
|
|
40
|
-
const positions = response.positions;
|
|
41
|
-
expect(positions).not.toBeNull();
|
|
42
|
-
if (positions.length > 0) {
|
|
43
|
-
const position = positions[0];
|
|
44
|
-
expect(position).not.toBeNull();
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('Transfers', async () => {
|
|
49
|
-
const response = await client.account.getSubaccountTransfers(TEST_ADDRESS, 0);
|
|
50
|
-
expect(response).not.toBeNull();
|
|
51
|
-
const transfers = response.transfers;
|
|
52
|
-
expect(transfers).not.toBeNull();
|
|
53
|
-
if (transfers.length > 0) {
|
|
54
|
-
const transfer = transfers[0];
|
|
55
|
-
expect(transfer).not.toBeNull();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('Transfers ParentSubaccountNumber', async () => {
|
|
60
|
-
const response = await client.account.getParentSubaccountNumberTransfers(TEST_ADDRESS, 0);
|
|
61
|
-
expect(response).not.toBeNull();
|
|
62
|
-
const transfers = response.transfers;
|
|
63
|
-
expect(transfers).not.toBeNull();
|
|
64
|
-
if (transfers.length > 0) {
|
|
65
|
-
const transfer = transfers[0];
|
|
66
|
-
expect(transfer).not.toBeNull();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('Transfers Pagination', async () => {
|
|
71
|
-
const response = await client.account.getSubaccountTransfers(
|
|
72
|
-
TEST_ADDRESS,
|
|
73
|
-
0,
|
|
74
|
-
1,
|
|
75
|
-
undefined,
|
|
76
|
-
undefined,
|
|
77
|
-
1,
|
|
78
|
-
);
|
|
79
|
-
expect(response).not.toBeNull();
|
|
80
|
-
const transfers = response.transfers;
|
|
81
|
-
|
|
82
|
-
expect(transfers).not.toBeNull();
|
|
83
|
-
if (transfers.length > 0) {
|
|
84
|
-
const transfer = transfers[0];
|
|
85
|
-
expect(transfer).not.toBeNull();
|
|
86
|
-
|
|
87
|
-
expect(response.totalResults).toBeGreaterThanOrEqual(1);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
expect(response.pageSize).toStrictEqual(1);
|
|
91
|
-
expect(response.offset).toStrictEqual(0);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('Transfers ParentSubaccountNumber Pagination', async () => {
|
|
95
|
-
const response = await client.account.getParentSubaccountNumberTransfers(
|
|
96
|
-
TEST_ADDRESS,
|
|
97
|
-
0,
|
|
98
|
-
1,
|
|
99
|
-
undefined,
|
|
100
|
-
undefined,
|
|
101
|
-
1,
|
|
102
|
-
);
|
|
103
|
-
expect(response).not.toBeNull();
|
|
104
|
-
const transfers = response.transfers;
|
|
105
|
-
|
|
106
|
-
expect(transfers).not.toBeNull();
|
|
107
|
-
if (transfers.length > 0) {
|
|
108
|
-
const transfer = transfers[0];
|
|
109
|
-
expect(transfer).not.toBeNull();
|
|
110
|
-
|
|
111
|
-
expect(response.totalResults).toBeGreaterThanOrEqual(1);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
expect(response.pageSize).toStrictEqual(1);
|
|
115
|
-
expect(response.offset).toStrictEqual(0);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('Orders', async () => {
|
|
119
|
-
const response = await client.account.getSubaccountOrders(TEST_ADDRESS, 0);
|
|
120
|
-
expect(response).not.toBeNull();
|
|
121
|
-
const orders = response;
|
|
122
|
-
expect(orders).not.toBeNull();
|
|
123
|
-
if (orders.length > 0) {
|
|
124
|
-
const order = orders[0];
|
|
125
|
-
expect(order).not.toBeNull();
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('Fills', async () => {
|
|
130
|
-
const response = await client.account.getSubaccountFills(TEST_ADDRESS, 0);
|
|
131
|
-
expect(response).not.toBeNull();
|
|
132
|
-
const fills = response.fills;
|
|
133
|
-
expect(fills).not.toBeNull();
|
|
134
|
-
if (fills.length > 0) {
|
|
135
|
-
const fill = fills[0];
|
|
136
|
-
expect(fill).not.toBeNull();
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('Fills ParentSubaccountNumber', async () => {
|
|
141
|
-
const response = await client.account.getParentSubaccountNumberFills(TEST_ADDRESS, 0);
|
|
142
|
-
expect(response).not.toBeNull();
|
|
143
|
-
const fills = response.fills;
|
|
144
|
-
expect(fills).not.toBeNull();
|
|
145
|
-
if (fills.length > 0) {
|
|
146
|
-
const fill = fills[0];
|
|
147
|
-
expect(fill).not.toBeNull();
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('Fills Pagination', async () => {
|
|
152
|
-
const response = await client.account.getSubaccountFills(
|
|
153
|
-
TEST_ADDRESS,
|
|
154
|
-
0,
|
|
155
|
-
undefined,
|
|
156
|
-
undefined,
|
|
157
|
-
1,
|
|
158
|
-
undefined,
|
|
159
|
-
undefined,
|
|
160
|
-
1,
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
expect(response).not.toBeNull();
|
|
164
|
-
const fills = response.fills;
|
|
165
|
-
expect(fills).not.toBeNull();
|
|
166
|
-
if (fills.length > 0) {
|
|
167
|
-
const fill = fills[0];
|
|
168
|
-
expect(fill).not.toBeNull();
|
|
169
|
-
expect(response.totalResults).toBeGreaterThanOrEqual(1);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
expect(response.pageSize).toStrictEqual(1);
|
|
173
|
-
expect(response.offset).toStrictEqual(0);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('Fills ParentSubaccountNumber Pagination', async () => {
|
|
177
|
-
const response = await client.account.getParentSubaccountNumberFills(
|
|
178
|
-
TEST_ADDRESS,
|
|
179
|
-
0,
|
|
180
|
-
undefined,
|
|
181
|
-
undefined,
|
|
182
|
-
1,
|
|
183
|
-
undefined,
|
|
184
|
-
undefined,
|
|
185
|
-
1,
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
expect(response).not.toBeNull();
|
|
189
|
-
const fills = response.fills;
|
|
190
|
-
expect(fills).not.toBeNull();
|
|
191
|
-
if (fills.length > 0) {
|
|
192
|
-
const fill = fills[0];
|
|
193
|
-
expect(fill).not.toBeNull();
|
|
194
|
-
expect(response.totalResults).toBeGreaterThanOrEqual(1);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
expect(response.pageSize).toStrictEqual(1);
|
|
198
|
-
expect(response.offset).toStrictEqual(0);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('Historical PNL', async () => {
|
|
202
|
-
const response = await client.account.getSubaccountHistoricalPNLs(TEST_ADDRESS, 0);
|
|
203
|
-
expect(response).not.toBeNull();
|
|
204
|
-
const historicalPnl = response.historicalPnl;
|
|
205
|
-
expect(historicalPnl).not.toBeNull();
|
|
206
|
-
if (historicalPnl.length > 0) {
|
|
207
|
-
const historicalPnl0 = historicalPnl[0];
|
|
208
|
-
expect(historicalPnl0).not.toBeNull();
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('Historical PNL Pagination', async () => {
|
|
213
|
-
const response = await client.account.getSubaccountHistoricalPNLs(
|
|
214
|
-
TEST_ADDRESS,
|
|
215
|
-
0,
|
|
216
|
-
undefined,
|
|
217
|
-
undefined,
|
|
218
|
-
undefined,
|
|
219
|
-
undefined,
|
|
220
|
-
1,
|
|
221
|
-
1,
|
|
222
|
-
);
|
|
223
|
-
expect(response).not.toBeNull();
|
|
224
|
-
const historicalPnl = response.historicalPnl;
|
|
225
|
-
expect(historicalPnl).not.toBeNull();
|
|
226
|
-
if (historicalPnl.length > 0) {
|
|
227
|
-
const historicalPnl0 = historicalPnl[0];
|
|
228
|
-
expect(historicalPnl0).not.toBeNull();
|
|
229
|
-
expect(response.totalResults).toBeGreaterThanOrEqual(1);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
expect(response.pageSize).toStrictEqual(1);
|
|
233
|
-
expect(response.offset).toStrictEqual(0);
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FaucetApiHost } from '../../../src/clients/constants';
|
|
2
|
-
import { FaucetClient } from '../../../src/clients/faucet-client';
|
|
3
|
-
import { TEST_ADDRESS } from './constants';
|
|
4
|
-
|
|
5
|
-
describe('FaucetClient', () => {
|
|
6
|
-
const client = new FaucetClient(FaucetApiHost.TESTNET);
|
|
7
|
-
|
|
8
|
-
describe('Faucet Endpoints', () => {
|
|
9
|
-
it('Fill', async () => {
|
|
10
|
-
const response = await client.fill(TEST_ADDRESS, 0, 2000);
|
|
11
|
-
expect(response?.status).toBe(202);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Network } from '../../../src/clients/constants';
|
|
2
|
-
import { IndexerClient } from '../../../src/clients/indexer-client';
|
|
3
|
-
|
|
4
|
-
// ------------ Markets ------------
|
|
5
|
-
export const MARKET_BTC_USD: string = 'BTC-USD';
|
|
6
|
-
|
|
7
|
-
describe('IndexerClient', () => {
|
|
8
|
-
const client = new IndexerClient(Network.testnet().indexerConfig);
|
|
9
|
-
|
|
10
|
-
describe('Market Endpoints', () => {
|
|
11
|
-
it('Markets', async () => {
|
|
12
|
-
const response = await client.markets.getPerpetualMarkets();
|
|
13
|
-
const btc = response.markets[MARKET_BTC_USD];
|
|
14
|
-
const status = btc.status;
|
|
15
|
-
expect(status).toBe('ACTIVE');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('BTC Market', async () => {
|
|
19
|
-
const response = await client.markets.getPerpetualMarkets(MARKET_BTC_USD);
|
|
20
|
-
const btc = response.markets[MARKET_BTC_USD];
|
|
21
|
-
const status = btc.status;
|
|
22
|
-
expect(status).toBe('ACTIVE');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('BTC Trades', async () => {
|
|
26
|
-
const response = await client.markets.getPerpetualMarketTrades(MARKET_BTC_USD);
|
|
27
|
-
const trades = response.trades;
|
|
28
|
-
expect(trades).not.toBeUndefined();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('BTC Trades Pagination', async () => {
|
|
32
|
-
const response = await client.markets.getPerpetualMarketTrades(
|
|
33
|
-
MARKET_BTC_USD,
|
|
34
|
-
undefined,
|
|
35
|
-
undefined,
|
|
36
|
-
1,
|
|
37
|
-
1,
|
|
38
|
-
);
|
|
39
|
-
const trades = response.trades;
|
|
40
|
-
expect(trades).not.toBeUndefined();
|
|
41
|
-
|
|
42
|
-
if (trades.length > 0) {
|
|
43
|
-
const trade = trades[0];
|
|
44
|
-
expect(trade).not.toBeNull();
|
|
45
|
-
|
|
46
|
-
expect(response.totalResults).toBeGreaterThanOrEqual(1);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
expect(response.pageSize).toStrictEqual(1);
|
|
50
|
-
expect(response.offset).toStrictEqual(0);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('BTC Orderbook', async () => {
|
|
54
|
-
const response = await client.markets.getPerpetualMarketOrderbook(MARKET_BTC_USD);
|
|
55
|
-
const asks = response.asks;
|
|
56
|
-
const bids = response.bids;
|
|
57
|
-
expect(asks).not.toBeUndefined();
|
|
58
|
-
expect(bids).not.toBeUndefined();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('BTC Candles', async () => {
|
|
62
|
-
const response = await client.markets.getPerpetualMarketCandles(MARKET_BTC_USD, '1MIN');
|
|
63
|
-
const candles = response.candles;
|
|
64
|
-
expect(candles).not.toBeUndefined();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('BTC Historical Funding', async () => {
|
|
68
|
-
const response = await client.markets.getPerpetualMarketHistoricalFunding(MARKET_BTC_USD);
|
|
69
|
-
expect(response).not.toBeNull();
|
|
70
|
-
const historicalFunding = response.historicalFunding;
|
|
71
|
-
expect(historicalFunding).not.toBeNull();
|
|
72
|
-
if (historicalFunding.length > 0) {
|
|
73
|
-
const historicalFunding0 = historicalFunding[0];
|
|
74
|
-
expect(historicalFunding0).not.toBeNull();
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('Sparklines', async () => {
|
|
79
|
-
const response = await client.markets.getPerpetualMarketSparklines();
|
|
80
|
-
const btcSparklines = response[MARKET_BTC_USD];
|
|
81
|
-
expect(btcSparklines).not.toBeUndefined();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Network } from '../../../src/clients/constants';
|
|
2
|
-
import LocalWallet from '../../../src/clients/modules/local-wallet';
|
|
3
|
-
import { SubaccountInfo } from '../../../src/clients/subaccount';
|
|
4
|
-
import { ValidatorClient } from '../../../src/clients/validator-client';
|
|
5
|
-
import { TEST_MNEMONIC } from '../../../examples/constants';
|
|
6
|
-
import Long from 'long';
|
|
7
|
-
import { BECH32_PREFIX } from '../../../src';
|
|
8
|
-
|
|
9
|
-
async function sleep(ms: number): Promise<void> {
|
|
10
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe('Validator Client', () => {
|
|
14
|
-
let wallet: LocalWallet;
|
|
15
|
-
let subaccount: SubaccountInfo;
|
|
16
|
-
let client: ValidatorClient;
|
|
17
|
-
|
|
18
|
-
describe('Transfers', () => {
|
|
19
|
-
beforeEach(async () => {
|
|
20
|
-
wallet = await LocalWallet.fromMnemonic(TEST_MNEMONIC, BECH32_PREFIX);
|
|
21
|
-
subaccount = SubaccountInfo.forLocalWallet(wallet, 0);
|
|
22
|
-
client = await ValidatorClient.connect(Network.testnet().validatorConfig);
|
|
23
|
-
await sleep(5000); // wait for withdraw to complete
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('Withdraw', async () => {
|
|
27
|
-
const tx = await client.post.withdraw(subaccount, 0, new Long(1_00_000_000), undefined);
|
|
28
|
-
console.log('**Withdraw Tx**');
|
|
29
|
-
console.log(tx);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('Deposit', async () => {
|
|
33
|
-
const tx = await client.post.deposit(subaccount, 0, new Long(1_000_000));
|
|
34
|
-
console.log('**Deposit Tx**');
|
|
35
|
-
console.log(tx);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('Transfer', async () => {
|
|
39
|
-
const tx = await client.post.transfer(subaccount, subaccount.address, 1, 0, new Long(1_000));
|
|
40
|
-
console.log('**Transfer Tx**');
|
|
41
|
-
console.log(tx);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { IndexerClient } from '../../../src';
|
|
2
|
-
import { Network } from '../../../src/clients/constants';
|
|
3
|
-
import { TEST_ADDRESS } from './constants';
|
|
4
|
-
|
|
5
|
-
describe('IndexerClient', () => {
|
|
6
|
-
const client = new IndexerClient(Network.testnet().indexerConfig);
|
|
7
|
-
|
|
8
|
-
describe('Utility Endpoints', () => {
|
|
9
|
-
it('getTime', async () => {
|
|
10
|
-
const response = await client.utility.getTime();
|
|
11
|
-
const iso = response.iso;
|
|
12
|
-
expect(iso).not.toBeUndefined();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('getHeight', async () => {
|
|
16
|
-
const response = await client.utility.getHeight();
|
|
17
|
-
const height = response.height;
|
|
18
|
-
const time = response.time;
|
|
19
|
-
expect(height).not.toBeUndefined();
|
|
20
|
-
expect(time).not.toBeUndefined();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('Screen Address', async () => {
|
|
24
|
-
const response = await client.utility.screen(TEST_ADDRESS);
|
|
25
|
-
const { restricted } = response ?? {};
|
|
26
|
-
expect(restricted).toBeDefined();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
});
|