@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
|
@@ -10,6 +10,7 @@ export * as RateLimitModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotoco
|
|
|
10
10
|
export * as RewardsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rewards/query';
|
|
11
11
|
export * as StakingModule from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/query';
|
|
12
12
|
export * as BridgeModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bridge/query';
|
|
13
|
+
export * as DistributionModule from '@dydxprotocol/v4-proto/src/codegen/cosmos/distribution/v1beta1/query';
|
|
13
14
|
|
|
14
15
|
export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/base/abci/v1beta1/abci';
|
|
15
16
|
export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/gov/v1/gov';
|
|
@@ -4,34 +4,31 @@ import { RequestMethod, Response, request } from '../lib/axios';
|
|
|
4
4
|
import { Data } from '../types';
|
|
5
5
|
|
|
6
6
|
export default class RestClient {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
readonly host: string;
|
|
8
|
+
readonly apiTimeout: Number;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
this.apiTimeout = apiTimeout || DEFAULT_API_TIMEOUT;
|
|
10
|
+
constructor(host: string, apiTimeout?: Number | null) {
|
|
11
|
+
if (host.endsWith('/')) {
|
|
12
|
+
this.host = host.slice(0, -1);
|
|
13
|
+
} else {
|
|
14
|
+
this.host = host;
|
|
17
15
|
}
|
|
16
|
+
this.apiTimeout = apiTimeout || DEFAULT_API_TIMEOUT;
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const response = await request(url);
|
|
25
|
-
return response.data;
|
|
26
|
-
}
|
|
19
|
+
async get(requestPath: string, params: {} = {}): Promise<Data> {
|
|
20
|
+
const url = `${this.host}${generateQueryPath(requestPath, params)}`;
|
|
21
|
+
const response = await request(url);
|
|
22
|
+
return response.data;
|
|
23
|
+
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
async post(
|
|
26
|
+
requestPath: string,
|
|
27
|
+
params: {} = {},
|
|
28
|
+
body?: unknown | null,
|
|
29
|
+
headers: {} = {},
|
|
30
|
+
): Promise<Response> {
|
|
31
|
+
const url = `${this.host}${generateQueryPath(requestPath, params)}`;
|
|
32
|
+
return request(url, RequestMethod.POST, body, headers);
|
|
33
|
+
}
|
|
37
34
|
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { EncodeObject } from '@cosmjs/proto-signing';
|
|
2
|
-
import {
|
|
3
|
-
SigningStargateClient,
|
|
4
|
-
StdFee,
|
|
5
|
-
} from '@cosmjs/stargate';
|
|
2
|
+
import { SigningStargateClient, StdFee } from '@cosmjs/stargate';
|
|
6
3
|
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
7
4
|
import Long from 'long';
|
|
8
5
|
import protobuf from 'protobufjs';
|
|
9
6
|
|
|
10
7
|
import { UserError } from '../lib/errors';
|
|
11
|
-
import {
|
|
12
|
-
TransactionOptions,
|
|
13
|
-
} from '../types';
|
|
8
|
+
import { TransactionOptions } from '../types';
|
|
14
9
|
|
|
15
10
|
// Required for encoding and decoding queries that are of type Long.
|
|
16
11
|
// Must be done once but since the individal modules should be usable
|
|
@@ -23,10 +18,7 @@ export class TransactionSigner {
|
|
|
23
18
|
readonly address: string;
|
|
24
19
|
readonly stargateSigningClient: SigningStargateClient;
|
|
25
20
|
|
|
26
|
-
constructor(
|
|
27
|
-
address: string,
|
|
28
|
-
stargateSigningClient: SigningStargateClient,
|
|
29
|
-
) {
|
|
21
|
+
constructor(address: string, stargateSigningClient: SigningStargateClient) {
|
|
30
22
|
this.address = address;
|
|
31
23
|
this.stargateSigningClient = stargateSigningClient;
|
|
32
24
|
}
|
|
@@ -50,17 +42,11 @@ export class TransactionSigner {
|
|
|
50
42
|
}
|
|
51
43
|
|
|
52
44
|
// Sign, encode and return the transaction.
|
|
53
|
-
const rawTx: TxRaw = await this.stargateSigningClient.sign(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
accountNumber: transactionOptions.accountNumber,
|
|
60
|
-
sequence: transactionOptions.sequence,
|
|
61
|
-
chainId: transactionOptions.chainId,
|
|
62
|
-
},
|
|
63
|
-
);
|
|
45
|
+
const rawTx: TxRaw = await this.stargateSigningClient.sign(this.address, messages, fee, memo, {
|
|
46
|
+
accountNumber: transactionOptions.accountNumber,
|
|
47
|
+
sequence: transactionOptions.sequence,
|
|
48
|
+
chainId: transactionOptions.chainId,
|
|
49
|
+
});
|
|
64
50
|
return Uint8Array.from(TxRaw.encode(rawTx).finish());
|
|
65
51
|
}
|
|
66
52
|
}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { toHex } from '@cosmjs/encoding';
|
|
2
2
|
import { Uint53 } from '@cosmjs/math';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
TimeoutError,
|
|
6
|
-
IndexedTx,
|
|
7
|
-
} from '@cosmjs/stargate';
|
|
8
|
-
import {
|
|
9
|
-
Method,
|
|
10
|
-
Tendermint37Client,
|
|
11
|
-
toRfc3339WithNanoseconds,
|
|
12
|
-
} from '@cosmjs/tendermint-rpc';
|
|
3
|
+
import { Block, TimeoutError, IndexedTx } from '@cosmjs/stargate';
|
|
4
|
+
import { Method, Tendermint37Client, toRfc3339WithNanoseconds } from '@cosmjs/tendermint-rpc';
|
|
13
5
|
import {
|
|
14
6
|
Attribute,
|
|
15
7
|
BlockResponse,
|
|
@@ -27,10 +19,7 @@ export class TendermintClient {
|
|
|
27
19
|
readonly baseClient: Tendermint37Client;
|
|
28
20
|
broadcastOptions: BroadcastOptions;
|
|
29
21
|
|
|
30
|
-
constructor(
|
|
31
|
-
baseClient: Tendermint37Client,
|
|
32
|
-
broadcastOptions: BroadcastOptions,
|
|
33
|
-
) {
|
|
22
|
+
constructor(baseClient: Tendermint37Client, broadcastOptions: BroadcastOptions) {
|
|
34
23
|
this.baseClient = baseClient;
|
|
35
24
|
this.broadcastOptions = broadcastOptions;
|
|
36
25
|
}
|
|
@@ -58,11 +47,11 @@ export class TendermintClient {
|
|
|
58
47
|
}
|
|
59
48
|
|
|
60
49
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
50
|
+
* @description Broadcast a signed transaction with a specific mode.
|
|
51
|
+
* @throws BroadcastErrorObject when result code is not zero. TypeError when mode is invalid.
|
|
52
|
+
* @returns Differs depending on the BroadcastMode used.
|
|
53
|
+
* See https://docs.cosmos.network/master/run-node/txs.html for more information.
|
|
54
|
+
*/
|
|
66
55
|
async broadcastTransaction(
|
|
67
56
|
tx: Uint8Array,
|
|
68
57
|
mode: BroadcastMode,
|
|
@@ -83,9 +72,7 @@ export class TendermintClient {
|
|
|
83
72
|
* @description Broadcast a signed transaction.
|
|
84
73
|
* @returns The transaction hash.
|
|
85
74
|
*/
|
|
86
|
-
broadcastTransactionAsync(
|
|
87
|
-
tx: Uint8Array,
|
|
88
|
-
): Promise<BroadcastTxAsyncResponse> {
|
|
75
|
+
broadcastTransactionAsync(tx: Uint8Array): Promise<BroadcastTxAsyncResponse> {
|
|
89
76
|
return this.baseClient.broadcastTxAsync({ tx });
|
|
90
77
|
}
|
|
91
78
|
|
|
@@ -94,15 +81,10 @@ export class TendermintClient {
|
|
|
94
81
|
* @throws BroadcastErrorObject when result code is not zero.
|
|
95
82
|
* @returns The response from the node once the transaction is processed by `CheckTx`.
|
|
96
83
|
*/
|
|
97
|
-
async broadcastTransactionSync(
|
|
98
|
-
tx: Uint8Array,
|
|
99
|
-
): Promise<BroadcastTxSyncResponse> {
|
|
84
|
+
async broadcastTransactionSync(tx: Uint8Array): Promise<BroadcastTxSyncResponse> {
|
|
100
85
|
const result: BroadcastTxSyncResponse = await this.baseClient.broadcastTxSync({ tx });
|
|
101
86
|
if (result.code !== 0) {
|
|
102
|
-
throw new BroadcastErrorObject(
|
|
103
|
-
`Broadcasting transaction failed: ${result.log}`,
|
|
104
|
-
result,
|
|
105
|
-
);
|
|
87
|
+
throw new BroadcastErrorObject(`Broadcasting transaction failed: ${result.log}`, result);
|
|
106
88
|
}
|
|
107
89
|
return result;
|
|
108
90
|
}
|
|
@@ -112,9 +94,7 @@ export class TendermintClient {
|
|
|
112
94
|
* @throws BroadcastErrorObject when result code is not zero.
|
|
113
95
|
* @returns The result of the transaction once included in the blockchain.
|
|
114
96
|
*/
|
|
115
|
-
async broadcastTransactionCommit(
|
|
116
|
-
tx: Uint8Array,
|
|
117
|
-
): Promise<IndexedTx> {
|
|
97
|
+
async broadcastTransactionCommit(tx: Uint8Array): Promise<IndexedTx> {
|
|
118
98
|
const result: BroadcastTxSyncResponse = await this.broadcastTransactionSync(tx);
|
|
119
99
|
return this.queryHash(result.hash);
|
|
120
100
|
}
|
|
@@ -126,10 +106,7 @@ export class TendermintClient {
|
|
|
126
106
|
* @throws TimeoutError if the transaction is not committed on-chain within the timeout limit.
|
|
127
107
|
* @returns An indexed transaction containing information about the transaction when committed.
|
|
128
108
|
*/
|
|
129
|
-
async queryHash(
|
|
130
|
-
hash: Uint8Array,
|
|
131
|
-
time: number = 0,
|
|
132
|
-
): Promise<IndexedTx> {
|
|
109
|
+
async queryHash(hash: Uint8Array, time: number = 0): Promise<IndexedTx> {
|
|
133
110
|
const now: number = Date.now();
|
|
134
111
|
const transactionId: string = toHex(hash).toUpperCase();
|
|
135
112
|
|