@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/network_optimizer.ts
CHANGED
|
@@ -4,16 +4,14 @@ import { encodeJson } from './lib/helpers';
|
|
|
4
4
|
import { IndexerConfig, ValidatorConfig } from './types';
|
|
5
5
|
|
|
6
6
|
class PingResponse {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
public readonly height: number;
|
|
8
|
+
public readonly responseTime: Date;
|
|
9
|
+
public endpoint?: string;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
this.responseTime = new Date();
|
|
16
|
-
}
|
|
11
|
+
constructor(height: number) {
|
|
12
|
+
this.height = height;
|
|
13
|
+
this.responseTime = new Date();
|
|
14
|
+
}
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export const isTruthy = <T>(n?: T | false | null | undefined | 0): n is T => Boolean(n);
|
|
@@ -23,26 +21,35 @@ export class NetworkOptimizer {
|
|
|
23
21
|
endpointUrls: string[],
|
|
24
22
|
chainId: string,
|
|
25
23
|
): Promise<ValidatorClient[]> {
|
|
26
|
-
return (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
return (
|
|
25
|
+
await Promise.all(
|
|
26
|
+
endpointUrls.map((endpointUrl) =>
|
|
27
|
+
ValidatorClient.connect(
|
|
28
|
+
new ValidatorConfig(endpointUrl, chainId, {
|
|
29
|
+
CHAINTOKEN_DENOM: 'placeholder',
|
|
30
|
+
CHAINTOKEN_DECIMALS: 18,
|
|
31
|
+
USDC_DENOM: 'uusdc',
|
|
32
|
+
USDC_DECIMALS: 6,
|
|
33
|
+
}),
|
|
34
|
+
).catch((_) => undefined),
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
).filter(isTruthy);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
private indexerClients(
|
|
40
|
-
endpointUrls
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
private indexerClients(endpointUrls: string[]): IndexerClient[] {
|
|
41
|
+
return endpointUrls
|
|
42
|
+
.map(
|
|
43
|
+
(endpointUrl) =>
|
|
44
|
+
new IndexerClient(
|
|
45
|
+
// socket is not used for finding optimal indexer, but required as a parameter to the config
|
|
46
|
+
new IndexerConfig(
|
|
47
|
+
endpointUrl,
|
|
48
|
+
endpointUrl.replace('https://', 'wss://').replace('http://', 'ws://'),
|
|
49
|
+
),
|
|
50
|
+
),
|
|
51
|
+
)
|
|
52
|
+
.filter(isTruthy);
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
async findOptimalNode(endpointUrls: string[], chainId: string): Promise<string> {
|
|
@@ -55,30 +62,33 @@ export class NetworkOptimizer {
|
|
|
55
62
|
return encodeJson(errorResponse);
|
|
56
63
|
}
|
|
57
64
|
const clients = await this.validatorClients(endpointUrls, chainId);
|
|
58
|
-
const responses = (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const responses = (
|
|
66
|
+
await Promise.all(
|
|
67
|
+
clients
|
|
68
|
+
.map(async (client) => {
|
|
69
|
+
const block = await client.get.latestBlock();
|
|
70
|
+
const response = new PingResponse(block.header.height);
|
|
71
|
+
return {
|
|
72
|
+
endpoint: client.config.restEndpoint,
|
|
73
|
+
height: response.height,
|
|
74
|
+
time: response.responseTime.getTime(),
|
|
75
|
+
};
|
|
76
|
+
})
|
|
77
|
+
.map((promise) => promise.catch((_) => undefined)),
|
|
78
|
+
)
|
|
79
|
+
).filter(isTruthy);
|
|
71
80
|
|
|
72
81
|
if (responses.length === 0) {
|
|
73
82
|
throw new Error('Could not connect to endpoints');
|
|
74
83
|
}
|
|
75
84
|
const maxHeight = Math.max(...responses.map(({ height }) => height));
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
return (
|
|
86
|
+
responses
|
|
87
|
+
// Only consider nodes at `maxHeight` or `maxHeight - 1`
|
|
88
|
+
.filter(({ height }) => height === maxHeight || height === maxHeight - 1)
|
|
89
|
+
// Return the endpoint with the fastest response time
|
|
90
|
+
.sort((a, b) => a.time - b.time)[0].endpoint
|
|
91
|
+
);
|
|
82
92
|
}
|
|
83
93
|
|
|
84
94
|
async findOptimalIndexer(endpointUrls: string[]): Promise<string> {
|
|
@@ -91,29 +101,32 @@ export class NetworkOptimizer {
|
|
|
91
101
|
return encodeJson(errorResponse);
|
|
92
102
|
}
|
|
93
103
|
const clients = this.indexerClients(endpointUrls);
|
|
94
|
-
const responses = (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
const responses = (
|
|
105
|
+
await Promise.all(
|
|
106
|
+
clients
|
|
107
|
+
.map(async (client) => {
|
|
108
|
+
const block = await client.utility.getHeight();
|
|
109
|
+
const response = new PingResponse(+block.height);
|
|
110
|
+
return {
|
|
111
|
+
endpoint: client.config.restEndpoint,
|
|
112
|
+
height: response.height,
|
|
113
|
+
time: response.responseTime.getTime(),
|
|
114
|
+
};
|
|
115
|
+
})
|
|
116
|
+
.map((promise) => promise.catch((_) => undefined)),
|
|
117
|
+
)
|
|
118
|
+
).filter(isTruthy);
|
|
107
119
|
|
|
108
120
|
if (responses.length === 0) {
|
|
109
121
|
throw new Error('Could not connect to endpoints');
|
|
110
122
|
}
|
|
111
123
|
const maxHeight = Math.max(...responses.map(({ height }) => height));
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
return (
|
|
125
|
+
responses
|
|
126
|
+
// Only consider nodes at `maxHeight` or `maxHeight - 1`
|
|
127
|
+
.filter(({ height }) => height === maxHeight || height === maxHeight - 1)
|
|
128
|
+
// Return the endpoint with the fastest response time
|
|
129
|
+
.sort((a, b) => a.time - b.time)[0].endpoint
|
|
130
|
+
);
|
|
118
131
|
}
|
|
119
132
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { StdFee } from '@cosmjs/amino';
|
|
2
|
-
import {
|
|
3
|
-
Method,
|
|
4
|
-
} from '@cosmjs/tendermint-rpc';
|
|
2
|
+
import { Method } from '@cosmjs/tendermint-rpc';
|
|
5
3
|
|
|
6
4
|
import { TransactionOptions } from './clients/types';
|
|
7
5
|
|
|
@@ -27,9 +25,10 @@ export interface ApiOptions {
|
|
|
27
25
|
// 2. Once the transaction is added to the memPool
|
|
28
26
|
// 3. Once the transaction is committed to a block
|
|
29
27
|
// See https://docs.cosmos.network/master/run-node/txs.html for more information
|
|
30
|
-
export type BroadcastMode =
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
export type BroadcastMode =
|
|
29
|
+
| Method.BroadcastTxAsync
|
|
30
|
+
| Method.BroadcastTxSync
|
|
31
|
+
| Method.BroadcastTxCommit;
|
|
33
32
|
|
|
34
33
|
// Defines the options for a transaction.
|
|
35
34
|
export interface Options {
|
package/tasks.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
2
|
+
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
3
|
+
// for the documentation about the tasks.json format
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"command": "npm",
|
|
6
|
+
"isShellCommand": true,
|
|
7
|
+
"showOutput": "always",
|
|
8
|
+
"suppressTaskName": true,
|
|
9
|
+
"tasks": [
|
|
10
|
+
{
|
|
11
|
+
"isBuildCommand": true,
|
|
12
|
+
"taskName": "build",
|
|
13
|
+
"args": ["run", "build"]
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
package/tsconfig.eslint.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "./node_modules/@dydxprotocol/node-service-base-dev/tsconfig.json",
|
|
3
|
-
"exclude": [
|
|
4
|
-
"src/codegen/**/*.ts",
|
|
5
|
-
"__native__/*.js",
|
|
6
|
-
"__native__/__ios__/*.js"
|
|
7
|
-
],
|
|
3
|
+
"exclude": ["src/codegen/**/*.ts", "__native__/*.js", "__native__/__ios__/*.js"],
|
|
8
4
|
"include": [
|
|
9
5
|
"__tests__",
|
|
10
6
|
"examples",
|
|
11
7
|
"scripts",
|
|
12
|
-
"src",
|
|
8
|
+
"src",
|
|
13
9
|
"codegen.js",
|
|
14
10
|
"node_modules/@dydxprotocol/v4-proto/**/**.ts"
|
|
15
11
|
],
|