@dydxprotocol/v4-client-js 1.1.13 → 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 +2640 -797
- 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 +222 -222
- package/build/src/clients/composite-client.js +234 -228
- 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 +272 -329
- 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
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BroadcastTxSyncResponse,
|
|
3
|
-
} from '@cosmjs/tendermint-rpc/build/tendermint37';
|
|
1
|
+
import { BroadcastTxSyncResponse } from '@cosmjs/tendermint-rpc/build/tendermint37';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* An edge-case was hit in the client that should never have been reached.
|
|
7
5
|
*/
|
|
8
6
|
export class UnexpectedClientError extends Error {
|
|
9
|
-
constructor(
|
|
10
|
-
) {
|
|
7
|
+
constructor() {
|
|
11
8
|
super('An unexpected error occurred on the client');
|
|
12
9
|
this.name = 'UnexpectedClientError';
|
|
13
10
|
}
|
|
@@ -21,10 +18,7 @@ export class BroadcastErrorObject extends Error {
|
|
|
21
18
|
code: number;
|
|
22
19
|
codespace?: string;
|
|
23
20
|
|
|
24
|
-
constructor(
|
|
25
|
-
message: string,
|
|
26
|
-
result: BroadcastTxSyncResponse,
|
|
27
|
-
) {
|
|
21
|
+
constructor(message: string, result: BroadcastTxSyncResponse) {
|
|
28
22
|
super(message);
|
|
29
23
|
this.name = 'BroadcastError';
|
|
30
24
|
this.result = result;
|
|
@@ -58,13 +52,10 @@ export class CustomError extends Error {
|
|
|
58
52
|
* @description Base class for a custom error which wraps another error.
|
|
59
53
|
*/
|
|
60
54
|
export class WrappedError extends CustomError {
|
|
61
|
-
|
|
55
|
+
public readonly originalError: Error;
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
super(message);
|
|
68
|
-
this.originalError = originalError;
|
|
69
|
-
}
|
|
57
|
+
constructor(message: string, originalError: Error) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.originalError = originalError;
|
|
60
|
+
}
|
|
70
61
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OrderSide, OrderStatus, OrderType, PositionStatus, TickerType,
|
|
3
|
-
} from '../constants';
|
|
1
|
+
import { OrderSide, OrderStatus, OrderType, PositionStatus, TickerType } from '../constants';
|
|
4
2
|
import { Data } from '../types';
|
|
5
3
|
import RestClient from './rest';
|
|
6
4
|
|
|
@@ -8,18 +6,12 @@ import RestClient from './rest';
|
|
|
8
6
|
* @description REST endpoints for data related to a particular address.
|
|
9
7
|
*/
|
|
10
8
|
export default class AccountClient extends RestClient {
|
|
11
|
-
async getSubaccounts(
|
|
12
|
-
address: string,
|
|
13
|
-
limit?: number,
|
|
14
|
-
): Promise<Data> {
|
|
9
|
+
async getSubaccounts(address: string, limit?: number): Promise<Data> {
|
|
15
10
|
const uri = `/v4/addresses/${address}`;
|
|
16
11
|
return this.get(uri, { limit });
|
|
17
12
|
}
|
|
18
13
|
|
|
19
|
-
async getSubaccount(
|
|
20
|
-
address: string,
|
|
21
|
-
subaccountNumber: number,
|
|
22
|
-
): Promise<Data> {
|
|
14
|
+
async getSubaccount(address: string, subaccountNumber: number): Promise<Data> {
|
|
23
15
|
const uri = `/v4/addresses/${address}/subaccountNumber/${subaccountNumber}`;
|
|
24
16
|
return this.get(uri);
|
|
25
17
|
}
|
|
@@ -108,7 +100,7 @@ export default class AccountClient extends RestClient {
|
|
|
108
100
|
});
|
|
109
101
|
}
|
|
110
102
|
|
|
111
|
-
async getOrder(orderId: string)
|
|
103
|
+
async getOrder(orderId: string): Promise<Data> {
|
|
112
104
|
const uri = `/v4/orders/${orderId}`;
|
|
113
105
|
return this.get(uri);
|
|
114
106
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
/* eslint-disable comma-dangle */
|
|
2
|
+
/* eslint-disable @typescript-eslint/quotes */
|
|
1
3
|
import { EncodeObject, Registry } from '@cosmjs/proto-signing';
|
|
4
|
+
import { MsgWithdrawDelegatorReward } from '@dydxprotocol/v4-proto/src/codegen/cosmos/distribution/v1beta1/tx';
|
|
5
|
+
import { MsgSubmitProposal } from '@dydxprotocol/v4-proto/src/codegen/cosmos/gov/v1/tx';
|
|
2
6
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/clob_pair';
|
|
7
|
+
MsgDelegate,
|
|
8
|
+
MsgUndelegate,
|
|
9
|
+
} from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/tx';
|
|
10
|
+
import { ClobPair_Status } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/clob_pair';
|
|
8
11
|
import {
|
|
9
12
|
MsgCreateClobPair,
|
|
10
13
|
MsgUpdateClobPair,
|
|
@@ -34,6 +37,9 @@ import {
|
|
|
34
37
|
TYPE_URL_MSG_CREATE_TRANSFER,
|
|
35
38
|
TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT,
|
|
36
39
|
TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT,
|
|
40
|
+
TYPE_URL_MSG_DELEGATE,
|
|
41
|
+
TYPE_URL_MSG_UNDELEGATE,
|
|
42
|
+
TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD,
|
|
37
43
|
} from '../constants';
|
|
38
44
|
import { DenomConfig } from '../types';
|
|
39
45
|
import {
|
|
@@ -55,7 +61,6 @@ protobuf.util.Long = Long;
|
|
|
55
61
|
protobuf.configure();
|
|
56
62
|
|
|
57
63
|
export class Composer {
|
|
58
|
-
|
|
59
64
|
// ------------ x/clob ------------
|
|
60
65
|
public composeMsgPlaceOrder(
|
|
61
66
|
address: string,
|
|
@@ -366,10 +371,7 @@ export class Composer {
|
|
|
366
371
|
}
|
|
367
372
|
|
|
368
373
|
// ------------ x/delaymsg ------------
|
|
369
|
-
public composeMsgDelayMessage(
|
|
370
|
-
embeddedMsg: EncodeObject,
|
|
371
|
-
delayBlocks: number,
|
|
372
|
-
): EncodeObject {
|
|
374
|
+
public composeMsgDelayMessage(embeddedMsg: EncodeObject, delayBlocks: number): EncodeObject {
|
|
373
375
|
const msg: MsgDelayMessage = {
|
|
374
376
|
// all msgs sent to x/delay must be from x/gov module account.
|
|
375
377
|
authority: GOV_MODULE_ADDRESS,
|
|
@@ -394,10 +396,12 @@ export class Composer {
|
|
|
394
396
|
metadata: string = '',
|
|
395
397
|
expedited: boolean = false,
|
|
396
398
|
): EncodeObject {
|
|
397
|
-
const initialDeposit: Coin[] = [
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
399
|
+
const initialDeposit: Coin[] = [
|
|
400
|
+
{
|
|
401
|
+
amount: initialDepositAmount,
|
|
402
|
+
denom: initialDepositDenomConfig.CHAINTOKEN_DENOM,
|
|
403
|
+
},
|
|
404
|
+
];
|
|
401
405
|
|
|
402
406
|
const msg: MsgSubmitProposal = {
|
|
403
407
|
title,
|
|
@@ -415,6 +419,46 @@ export class Composer {
|
|
|
415
419
|
};
|
|
416
420
|
}
|
|
417
421
|
|
|
422
|
+
// ------------ x/staking ------------
|
|
423
|
+
public composeMsgDelegate(delegator: string, validator: string, amount: Coin): EncodeObject {
|
|
424
|
+
const msg: MsgDelegate = {
|
|
425
|
+
delegatorAddress: delegator,
|
|
426
|
+
validatorAddress: validator,
|
|
427
|
+
amount,
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
return {
|
|
431
|
+
typeUrl: TYPE_URL_MSG_DELEGATE,
|
|
432
|
+
value: msg,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
public composeMsgUndelegate(delegator: string, validator: string, amount: Coin): EncodeObject {
|
|
437
|
+
const msg: MsgUndelegate = {
|
|
438
|
+
delegatorAddress: delegator,
|
|
439
|
+
validatorAddress: validator,
|
|
440
|
+
amount,
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
return {
|
|
444
|
+
typeUrl: TYPE_URL_MSG_UNDELEGATE,
|
|
445
|
+
value: msg,
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// ------------ x/distribution ------------
|
|
450
|
+
public composeMsgWithdrawDelegatorReward(delegator: string, validator: string): EncodeObject {
|
|
451
|
+
const msg: MsgWithdrawDelegatorReward = {
|
|
452
|
+
delegatorAddress: delegator,
|
|
453
|
+
validatorAddress: validator,
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
return {
|
|
457
|
+
typeUrl: TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD,
|
|
458
|
+
value: msg,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
418
462
|
// ------------ util ------------
|
|
419
463
|
public validateGoodTilBlockAndTime(
|
|
420
464
|
orderFlags: number,
|
|
@@ -432,12 +476,9 @@ export class Composer {
|
|
|
432
476
|
return registry.encodeAsAny(message);
|
|
433
477
|
}
|
|
434
478
|
|
|
435
|
-
public wrapMessageArrAsAny(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
): Any[] {
|
|
439
|
-
const encodedMessages: Any[] = messages.map(
|
|
440
|
-
(message: EncodeObject) => this.wrapMessageAsAny(registry, message),
|
|
479
|
+
public wrapMessageArrAsAny(registry: Registry, messages: EncodeObject[]): Any[] {
|
|
480
|
+
const encodedMessages: Any[] = messages.map((message: EncodeObject) =>
|
|
481
|
+
this.wrapMessageAsAny(registry, message),
|
|
441
482
|
);
|
|
442
483
|
return encodedMessages;
|
|
443
484
|
}
|
|
@@ -18,6 +18,7 @@ import { UnexpectedClientError } from '../lib/errors';
|
|
|
18
18
|
import {
|
|
19
19
|
BridgeModule,
|
|
20
20
|
ClobModule,
|
|
21
|
+
DistributionModule,
|
|
21
22
|
FeeTierModule,
|
|
22
23
|
GovV1Module,
|
|
23
24
|
PerpetualsModule,
|
|
@@ -40,11 +41,11 @@ protobuf.configure();
|
|
|
40
41
|
|
|
41
42
|
export class Get {
|
|
42
43
|
readonly tendermintClient: TendermintClient;
|
|
43
|
-
readonly stargateQueryClient:
|
|
44
|
+
readonly stargateQueryClient: StargateQueryClient & TxExtension;
|
|
44
45
|
|
|
45
46
|
constructor(
|
|
46
47
|
tendermintClient: TendermintClient,
|
|
47
|
-
stargateQueryClient:
|
|
48
|
+
stargateQueryClient: StargateQueryClient & TxExtension,
|
|
48
49
|
) {
|
|
49
50
|
this.tendermintClient = tendermintClient;
|
|
50
51
|
this.stargateQueryClient = stargateQueryClient;
|
|
@@ -76,8 +77,7 @@ export class Get {
|
|
|
76
77
|
*/
|
|
77
78
|
async getFeeTiers(): Promise<FeeTierModule.QueryPerpetualFeeParamsResponse> {
|
|
78
79
|
const requestData = Uint8Array.from(
|
|
79
|
-
FeeTierModule.QueryPerpetualFeeParamsRequest.encode({})
|
|
80
|
-
.finish(),
|
|
80
|
+
FeeTierModule.QueryPerpetualFeeParamsRequest.encode({}).finish(),
|
|
81
81
|
);
|
|
82
82
|
|
|
83
83
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -94,8 +94,7 @@ export class Get {
|
|
|
94
94
|
*/
|
|
95
95
|
async getUserFeeTier(address: string): Promise<FeeTierModule.QueryUserFeeTierResponse> {
|
|
96
96
|
const requestData = Uint8Array.from(
|
|
97
|
-
FeeTierModule.QueryUserFeeTierRequest.encode({ user: address })
|
|
98
|
-
.finish(),
|
|
97
|
+
FeeTierModule.QueryUserFeeTierRequest.encode({ user: address }).finish(),
|
|
99
98
|
);
|
|
100
99
|
|
|
101
100
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -112,10 +111,9 @@ export class Get {
|
|
|
112
111
|
*/
|
|
113
112
|
async getUserStats(
|
|
114
113
|
address: string,
|
|
115
|
-
): Promise<{ takerNotional: Long
|
|
114
|
+
): Promise<{ takerNotional: Long; makerNotional: Long } | undefined> {
|
|
116
115
|
const requestData = Uint8Array.from(
|
|
117
|
-
StatsModule.QueryUserStatsRequest.encode({ user: address })
|
|
118
|
-
.finish(),
|
|
116
|
+
StatsModule.QueryUserStatsRequest.encode({ user: address }).finish(),
|
|
119
117
|
);
|
|
120
118
|
|
|
121
119
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -132,8 +130,7 @@ export class Get {
|
|
|
132
130
|
*/
|
|
133
131
|
async getAccountBalances(address: string): Promise<Coin[]> {
|
|
134
132
|
const requestData: Uint8Array = Uint8Array.from(
|
|
135
|
-
BankModule.QueryAllBalancesRequest.encode({ address })
|
|
136
|
-
.finish(),
|
|
133
|
+
BankModule.QueryAllBalancesRequest.encode({ address }).finish(),
|
|
137
134
|
);
|
|
138
135
|
|
|
139
136
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -153,8 +150,7 @@ export class Get {
|
|
|
153
150
|
BankModule.QueryBalanceRequest.encode({
|
|
154
151
|
address,
|
|
155
152
|
denom,
|
|
156
|
-
})
|
|
157
|
-
.finish(),
|
|
153
|
+
}).finish(),
|
|
158
154
|
);
|
|
159
155
|
|
|
160
156
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -172,8 +168,7 @@ export class Get {
|
|
|
172
168
|
*/
|
|
173
169
|
async getSubaccounts(): Promise<SubaccountsModule.QuerySubaccountAllResponse> {
|
|
174
170
|
const requestData: Uint8Array = Uint8Array.from(
|
|
175
|
-
SubaccountsModule.QueryAllSubaccountRequest.encode({})
|
|
176
|
-
.finish(),
|
|
171
|
+
SubaccountsModule.QueryAllSubaccountRequest.encode({}).finish(),
|
|
177
172
|
);
|
|
178
173
|
|
|
179
174
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -196,8 +191,7 @@ export class Get {
|
|
|
196
191
|
SubaccountsModule.QueryGetSubaccountRequest.encode({
|
|
197
192
|
owner: address,
|
|
198
193
|
number: accountNumber,
|
|
199
|
-
})
|
|
200
|
-
.finish(),
|
|
194
|
+
}).finish(),
|
|
201
195
|
);
|
|
202
196
|
|
|
203
197
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -213,10 +207,7 @@ export class Get {
|
|
|
213
207
|
* @returns Params for the rewards module.
|
|
214
208
|
*/
|
|
215
209
|
async getRewardsParams(): Promise<RewardsModule.QueryParamsResponse> {
|
|
216
|
-
const requestData = Uint8Array.from(
|
|
217
|
-
RewardsModule.QueryParamsRequest.encode({})
|
|
218
|
-
.finish(),
|
|
219
|
-
);
|
|
210
|
+
const requestData = Uint8Array.from(RewardsModule.QueryParamsRequest.encode({}).finish());
|
|
220
211
|
|
|
221
212
|
const data: Uint8Array = await this.sendQuery(
|
|
222
213
|
'/dydxprotocol.rewards.Query/Params',
|
|
@@ -232,8 +223,7 @@ export class Get {
|
|
|
232
223
|
*/
|
|
233
224
|
async getAllClobPairs(): Promise<ClobModule.QueryClobPairAllResponse> {
|
|
234
225
|
const requestData: Uint8Array = Uint8Array.from(
|
|
235
|
-
ClobModule.QueryAllClobPairRequest.encode({ pagination: PAGE_REQUEST })
|
|
236
|
-
.finish(),
|
|
226
|
+
ClobModule.QueryAllClobPairRequest.encode({ pagination: PAGE_REQUEST }).finish(),
|
|
237
227
|
);
|
|
238
228
|
|
|
239
229
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -250,14 +240,10 @@ export class Get {
|
|
|
250
240
|
*/
|
|
251
241
|
async getClobPair(pairId: number): Promise<ClobModule.QueryClobPairResponse> {
|
|
252
242
|
const requestData: Uint8Array = Uint8Array.from(
|
|
253
|
-
ClobModule.QueryGetClobPairRequest.encode({ id: pairId })
|
|
254
|
-
.finish(),
|
|
243
|
+
ClobModule.QueryGetClobPairRequest.encode({ id: pairId }).finish(),
|
|
255
244
|
);
|
|
256
245
|
|
|
257
|
-
const data: Uint8Array = await this.sendQuery(
|
|
258
|
-
'/dydxprotocol.clob.Query/ClobPair',
|
|
259
|
-
requestData,
|
|
260
|
-
);
|
|
246
|
+
const data: Uint8Array = await this.sendQuery('/dydxprotocol.clob.Query/ClobPair', requestData);
|
|
261
247
|
return ClobModule.QueryClobPairResponse.decode(data);
|
|
262
248
|
}
|
|
263
249
|
|
|
@@ -268,8 +254,7 @@ export class Get {
|
|
|
268
254
|
*/
|
|
269
255
|
async getAllPrices(): Promise<PricesModule.QueryAllMarketPricesResponse> {
|
|
270
256
|
const requestData: Uint8Array = Uint8Array.from(
|
|
271
|
-
PricesModule.QueryAllMarketPricesRequest.encode({ pagination: PAGE_REQUEST })
|
|
272
|
-
.finish(),
|
|
257
|
+
PricesModule.QueryAllMarketPricesRequest.encode({ pagination: PAGE_REQUEST }).finish(),
|
|
273
258
|
);
|
|
274
259
|
|
|
275
260
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -286,8 +271,7 @@ export class Get {
|
|
|
286
271
|
*/
|
|
287
272
|
async getPrice(marketId: number): Promise<PricesModule.QueryMarketPriceResponse> {
|
|
288
273
|
const requestData: Uint8Array = Uint8Array.from(
|
|
289
|
-
PricesModule.QueryMarketPriceRequest.encode({ id: marketId })
|
|
290
|
-
.finish(),
|
|
274
|
+
PricesModule.QueryMarketPriceRequest.encode({ id: marketId }).finish(),
|
|
291
275
|
);
|
|
292
276
|
|
|
293
277
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -304,8 +288,7 @@ export class Get {
|
|
|
304
288
|
*/
|
|
305
289
|
async getAllPerpetuals(): Promise<PerpetualsModule.QueryAllPerpetualsResponse> {
|
|
306
290
|
const requestData: Uint8Array = Uint8Array.from(
|
|
307
|
-
PerpetualsModule.QueryAllPerpetualsRequest.encode({ pagination: PAGE_REQUEST })
|
|
308
|
-
.finish(),
|
|
291
|
+
PerpetualsModule.QueryAllPerpetualsRequest.encode({ pagination: PAGE_REQUEST }).finish(),
|
|
309
292
|
);
|
|
310
293
|
|
|
311
294
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -320,12 +303,9 @@ export class Get {
|
|
|
320
303
|
*
|
|
321
304
|
* @returns The Perpetual for a given Perpetual Id.
|
|
322
305
|
*/
|
|
323
|
-
async getPerpetual(
|
|
324
|
-
perpetualId: number,
|
|
325
|
-
): Promise<PerpetualsModule.QueryPerpetualResponse> {
|
|
306
|
+
async getPerpetual(perpetualId: number): Promise<PerpetualsModule.QueryPerpetualResponse> {
|
|
326
307
|
const requestData: Uint8Array = Uint8Array.from(
|
|
327
|
-
PerpetualsModule.QueryPerpetualRequest.encode({ id: perpetualId })
|
|
328
|
-
.finish(),
|
|
308
|
+
PerpetualsModule.QueryPerpetualRequest.encode({ id: perpetualId }).finish(),
|
|
329
309
|
);
|
|
330
310
|
|
|
331
311
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -344,8 +324,7 @@ export class Get {
|
|
|
344
324
|
*/
|
|
345
325
|
async getAccount(address: string): Promise<Account> {
|
|
346
326
|
const requestData: Uint8Array = Uint8Array.from(
|
|
347
|
-
AuthModule.QueryAccountRequest.encode({ address })
|
|
348
|
-
.finish(),
|
|
327
|
+
AuthModule.QueryAccountRequest.encode({ address }).finish(),
|
|
349
328
|
);
|
|
350
329
|
|
|
351
330
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -366,12 +345,9 @@ export class Get {
|
|
|
366
345
|
*
|
|
367
346
|
* @returns Information on all equity tiers that are configured.
|
|
368
347
|
*/
|
|
369
|
-
async getEquityTierLimitConfiguration(): Promise<
|
|
370
|
-
ClobModule.QueryEquityTierLimitConfigurationResponse
|
|
371
|
-
> {
|
|
348
|
+
async getEquityTierLimitConfiguration(): Promise<ClobModule.QueryEquityTierLimitConfigurationResponse> {
|
|
372
349
|
const requestData: Uint8Array = Uint8Array.from(
|
|
373
|
-
ClobModule.QueryEquityTierLimitConfigurationRequest.encode({})
|
|
374
|
-
.finish(),
|
|
350
|
+
ClobModule.QueryEquityTierLimitConfigurationRequest.encode({}).finish(),
|
|
375
351
|
);
|
|
376
352
|
|
|
377
353
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -394,8 +370,7 @@ export class Get {
|
|
|
394
370
|
StakingModule.QueryDelegatorDelegationsRequest.encode({
|
|
395
371
|
delegatorAddr,
|
|
396
372
|
pagination: PAGE_REQUEST,
|
|
397
|
-
})
|
|
398
|
-
.finish(),
|
|
373
|
+
}).finish(),
|
|
399
374
|
);
|
|
400
375
|
|
|
401
376
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -418,8 +393,7 @@ export class Get {
|
|
|
418
393
|
StakingModule.QueryDelegatorUnbondingDelegationsRequest.encode({
|
|
419
394
|
delegatorAddr,
|
|
420
395
|
pagination: PAGE_REQUEST,
|
|
421
|
-
})
|
|
422
|
-
.finish(),
|
|
396
|
+
}).finish(),
|
|
423
397
|
);
|
|
424
398
|
|
|
425
399
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -429,6 +403,29 @@ export class Get {
|
|
|
429
403
|
return StakingModule.QueryDelegatorUnbondingDelegationsResponse.decode(data);
|
|
430
404
|
}
|
|
431
405
|
|
|
406
|
+
/**
|
|
407
|
+
*
|
|
408
|
+
* @description Get all unbonding delegations from a delegator.
|
|
409
|
+
*
|
|
410
|
+
* @returns All unbonding delegations from a delegator.
|
|
411
|
+
*/
|
|
412
|
+
async getDelegationTotalRewards(
|
|
413
|
+
delegatorAddress: string,
|
|
414
|
+
): Promise<DistributionModule.QueryDelegationTotalRewardsResponse> {
|
|
415
|
+
const requestData = Uint8Array.from(
|
|
416
|
+
DistributionModule.QueryDelegationTotalRewardsRequest.encode({
|
|
417
|
+
delegatorAddress,
|
|
418
|
+
})
|
|
419
|
+
.finish(),
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
const data: Uint8Array = await this.sendQuery(
|
|
423
|
+
'/cosmos.distribution.v1beta1.Query/DelegationTotalRewards',
|
|
424
|
+
requestData,
|
|
425
|
+
);
|
|
426
|
+
return DistributionModule.QueryDelegationTotalRewardsResponse.decode(data);
|
|
427
|
+
}
|
|
428
|
+
|
|
432
429
|
/**
|
|
433
430
|
* @description Get all delayed complete bridge messages, optionally filtered by address.
|
|
434
431
|
*
|
|
@@ -438,8 +435,7 @@ export class Get {
|
|
|
438
435
|
address: string = '',
|
|
439
436
|
): Promise<BridgeModule.QueryDelayedCompleteBridgeMessagesResponse> {
|
|
440
437
|
const requestData: Uint8Array = Uint8Array.from(
|
|
441
|
-
BridgeModule.QueryDelayedCompleteBridgeMessagesRequest.encode({ address })
|
|
442
|
-
.finish(),
|
|
438
|
+
BridgeModule.QueryDelayedCompleteBridgeMessagesRequest.encode({ address }).finish(),
|
|
443
439
|
);
|
|
444
440
|
|
|
445
441
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -454,16 +450,12 @@ export class Get {
|
|
|
454
450
|
*
|
|
455
451
|
* @returns all validators of a status.
|
|
456
452
|
*/
|
|
457
|
-
async getAllValidators(
|
|
458
|
-
status: string = '',
|
|
459
|
-
): Promise<StakingModule.QueryValidatorsResponse> {
|
|
453
|
+
async getAllValidators(status: string = ''): Promise<StakingModule.QueryValidatorsResponse> {
|
|
460
454
|
const requestData = Uint8Array.from(
|
|
461
|
-
StakingModule.QueryValidatorsRequest
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
})
|
|
466
|
-
.finish(),
|
|
455
|
+
StakingModule.QueryValidatorsRequest.encode({
|
|
456
|
+
status,
|
|
457
|
+
pagination: PAGE_REQUEST,
|
|
458
|
+
}).finish(),
|
|
467
459
|
);
|
|
468
460
|
|
|
469
461
|
const data: Uint8Array = await this.sendQuery(
|
|
@@ -488,28 +480,20 @@ export class Get {
|
|
|
488
480
|
depositor: string = '',
|
|
489
481
|
): Promise<GovV1Module.QueryProposalsResponse> {
|
|
490
482
|
const requestData = Uint8Array.from(
|
|
491
|
-
GovV1Module.QueryProposalsRequest
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
})
|
|
498
|
-
.finish(),
|
|
499
|
-
);
|
|
500
|
-
const data: Uint8Array = await this.sendQuery(
|
|
501
|
-
'/cosmos.gov.v1.Query/Proposals',
|
|
502
|
-
requestData,
|
|
483
|
+
GovV1Module.QueryProposalsRequest.encode({
|
|
484
|
+
proposalStatus,
|
|
485
|
+
voter,
|
|
486
|
+
depositor,
|
|
487
|
+
pagination: PAGE_REQUEST,
|
|
488
|
+
}).finish(),
|
|
503
489
|
);
|
|
490
|
+
const data: Uint8Array = await this.sendQuery('/cosmos.gov.v1.Query/Proposals', requestData);
|
|
504
491
|
return GovV1Module.QueryProposalsResponse.decode(data);
|
|
505
492
|
}
|
|
506
493
|
|
|
507
|
-
async getWithdrawalAndTransferGatingStatus(
|
|
508
|
-
): Promise<SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoResponse> {
|
|
494
|
+
async getWithdrawalAndTransferGatingStatus(): Promise<SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoResponse> {
|
|
509
495
|
const requestData = Uint8Array.from(
|
|
510
|
-
SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoRequest
|
|
511
|
-
.encode({})
|
|
512
|
-
.finish(),
|
|
496
|
+
SubaccountsModule.QueryGetWithdrawalAndTransfersBlockedInfoRequest.encode({}).finish(),
|
|
513
497
|
);
|
|
514
498
|
|
|
515
499
|
const data = await this.sendQuery(
|
|
@@ -524,24 +508,22 @@ export class Get {
|
|
|
524
508
|
denom: string,
|
|
525
509
|
): Promise<RateLimitModule.QueryCapacityByDenomResponse> {
|
|
526
510
|
const requestData = Uint8Array.from(
|
|
527
|
-
RateLimitModule.QueryCapacityByDenomRequest
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
})
|
|
531
|
-
.finish(),
|
|
511
|
+
RateLimitModule.QueryCapacityByDenomRequest.encode({
|
|
512
|
+
denom,
|
|
513
|
+
}).finish(),
|
|
532
514
|
);
|
|
533
515
|
|
|
534
|
-
const data = await this.sendQuery(
|
|
535
|
-
'/dydxprotocol.ratelimit.Query/CapacityByDenom',
|
|
536
|
-
requestData,
|
|
537
|
-
);
|
|
516
|
+
const data = await this.sendQuery('/dydxprotocol.ratelimit.Query/CapacityByDenom', requestData);
|
|
538
517
|
|
|
539
518
|
return RateLimitModule.QueryCapacityByDenomResponse.decode(data);
|
|
540
519
|
}
|
|
541
520
|
|
|
542
521
|
private async sendQuery(requestUrl: string, requestData: Uint8Array): Promise<Uint8Array> {
|
|
543
522
|
// eslint-disable-next-line max-len
|
|
544
|
-
const resp: QueryAbciResponse = await this.stargateQueryClient.queryAbci(
|
|
523
|
+
const resp: QueryAbciResponse = await this.stargateQueryClient.queryAbci(
|
|
524
|
+
requestUrl,
|
|
525
|
+
requestData,
|
|
526
|
+
);
|
|
545
527
|
return resp.value;
|
|
546
528
|
}
|
|
547
529
|
}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Secp256k1Pubkey,
|
|
3
|
-
StdFee,
|
|
4
|
-
encodeSecp256k1Pubkey,
|
|
5
|
-
} from '@cosmjs/amino';
|
|
1
|
+
import { Secp256k1Pubkey, StdFee, encodeSecp256k1Pubkey } from '@cosmjs/amino';
|
|
6
2
|
import {
|
|
7
3
|
AccountData,
|
|
8
4
|
DirectSecp256k1HdWallet,
|
|
9
5
|
EncodeObject,
|
|
10
6
|
OfflineSigner,
|
|
11
7
|
} from '@cosmjs/proto-signing';
|
|
12
|
-
import {
|
|
13
|
-
SigningStargateClient,
|
|
14
|
-
} from '@cosmjs/stargate';
|
|
8
|
+
import { SigningStargateClient } from '@cosmjs/stargate';
|
|
15
9
|
import Long from 'long';
|
|
16
10
|
import protobuf from 'protobufjs';
|
|
17
11
|
|
|
@@ -24,57 +18,48 @@ protobuf.util.Long = Long;
|
|
|
24
18
|
protobuf.configure();
|
|
25
19
|
|
|
26
20
|
export default class LocalWallet {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
accounts?: AccountData[];
|
|
22
|
+
address?: string;
|
|
23
|
+
pubKey?: Secp256k1Pubkey;
|
|
24
|
+
signer?: TransactionSigner;
|
|
25
|
+
offlineSigner?: OfflineSigner;
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
static async fromOfflineSigner(signer: OfflineSigner): Promise<LocalWallet> {
|
|
28
|
+
const wallet = new LocalWallet();
|
|
29
|
+
await wallet.setSigner(signer);
|
|
30
|
+
return wallet;
|
|
31
|
+
}
|
|
38
32
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
static async fromMnemonic(mnemonic: string, prefix?: string): Promise<LocalWallet> {
|
|
34
|
+
const wallet = new LocalWallet();
|
|
35
|
+
await wallet.setMnemonic(mnemonic, prefix);
|
|
36
|
+
return wallet;
|
|
37
|
+
}
|
|
44
38
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.pubKey = encodeSecp256k1Pubkey(firstAccount.pubkey);
|
|
58
|
-
this.signer = new TransactionSigner(
|
|
59
|
-
this.address,
|
|
60
|
-
stargateClient,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
39
|
+
async setSigner(signer: OfflineSigner): Promise<void> {
|
|
40
|
+
this.offlineSigner = signer;
|
|
41
|
+
const stargateClient = await SigningStargateClient.offline(signer, {
|
|
42
|
+
registry: generateRegistry(),
|
|
43
|
+
});
|
|
44
|
+
const accountData = await signer.getAccounts();
|
|
45
|
+
const firstAccount = accountData[0];
|
|
46
|
+
this.accounts = [...accountData];
|
|
47
|
+
this.address = firstAccount.address;
|
|
48
|
+
this.pubKey = encodeSecp256k1Pubkey(firstAccount.pubkey);
|
|
49
|
+
this.signer = new TransactionSigner(this.address, stargateClient);
|
|
50
|
+
}
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
69
|
-
return this.setSigner(signer);
|
|
70
|
-
}
|
|
52
|
+
async setMnemonic(mnemonic: string, prefix?: string): Promise<void> {
|
|
53
|
+
const signer = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix });
|
|
54
|
+
return this.setSigner(signer);
|
|
55
|
+
}
|
|
71
56
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
57
|
+
public async signTransaction(
|
|
58
|
+
messages: EncodeObject[],
|
|
59
|
+
transactionOptions: TransactionOptions,
|
|
60
|
+
fee?: StdFee,
|
|
61
|
+
memo: string = '',
|
|
62
|
+
): Promise<Uint8Array> {
|
|
63
|
+
return this.signer!.signTransaction(messages, transactionOptions, fee, memo);
|
|
64
|
+
}
|
|
80
65
|
}
|