@dydxprotocol/v4-client-js 1.0.15 → 1.0.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dydxprotocol/v4-client-js",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "General client library for the new dYdX system (v4 decentralized)",
5
5
  "main": "build/src/index.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@ import Long from 'long';
9
9
  import protobuf from 'protobufjs';
10
10
 
11
11
  import { isStatefulOrder, verifyOrderFlags } from '../lib/validation';
12
- import { OrderFlags } from '../types';
12
+ import { GovAddNewMarketParams, OrderFlags } from '../types';
13
13
  import {
14
14
  Network,
15
15
  OrderExecution,
@@ -31,6 +31,7 @@ import {
31
31
  } from './helpers/chain-helpers';
32
32
  import { IndexerClient } from './indexer-client';
33
33
  import { UserError } from './lib/errors';
34
+ import { generateRegistry } from './lib/registry';
34
35
  import LocalWallet from './modules/local-wallet';
35
36
  import { SubaccountInfo } from './subaccount';
36
37
  import { ValidatorClient } from './validator-client';
@@ -498,7 +499,7 @@ export class CompositeClient {
498
499
  );
499
500
  }
500
501
 
501
- private async retrieveMarketInfo(marketId: string, marketInfo?:MarketInfo): Promise<MarketInfo> {
502
+ private async retrieveMarketInfo(marketId: string, marketInfo?: MarketInfo): Promise<MarketInfo> {
502
503
  if (marketInfo) {
503
504
  return Promise.resolve(marketInfo);
504
505
  } else {
@@ -1000,4 +1001,98 @@ export class CompositeClient {
1000
1001
 
1001
1002
  return Buffer.from(signature).toString('base64');
1002
1003
  }
1004
+
1005
+ /**
1006
+ * @description Submit a governance proposal to add a new market.
1007
+ *
1008
+ * @param params Parameters neeeded to create a new market.
1009
+ * @param title Title of the gov proposal.
1010
+ * @param summary Summary of the gov proposal.
1011
+ * @param initialDepositAmount Initial deposit amount of the gov proposal.
1012
+ * @param proposer proposer of the gov proposal.
1013
+ *
1014
+ * @returns the transaction hash.
1015
+ */
1016
+ async submitGovAddNewMarketProposal(
1017
+ wallet: LocalWallet,
1018
+ params: GovAddNewMarketParams,
1019
+ title: string,
1020
+ summary: string,
1021
+ initialDepositAmount: number,
1022
+ ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
1023
+ const msg: Promise<EncodeObject[]> = new Promise((resolve) => {
1024
+ const composer = this.validatorClient.post.composer;
1025
+ const registry = generateRegistry();
1026
+ const msgs: EncodeObject[] = [];
1027
+
1028
+ // x/prices.MsgCreateOracleMarket
1029
+ const createOracleMarket = composer.composeMsgCreateOracleMarket(
1030
+ params.id,
1031
+ params.ticker,
1032
+ params.priceExponent,
1033
+ params.minExchanges,
1034
+ params.minPriceChange,
1035
+ params.exchangeConfigJson,
1036
+ );
1037
+
1038
+ // x/perpetuals.MsgCreatePerpetual
1039
+ const createPerpetual = composer.composeMsgCreatePerpetual(
1040
+ params.id,
1041
+ params.id,
1042
+ params.ticker,
1043
+ params.atomicResolution,
1044
+ params.liquidityTier,
1045
+ );
1046
+
1047
+ // x/clob.MsgCreateClobPair
1048
+ const createClobPair = composer.composeMsgCreateClobPair(
1049
+ params.id,
1050
+ params.id,
1051
+ params.quantumConversionExponent,
1052
+ params.stepBaseQuantums,
1053
+ params.subticksPerTick,
1054
+ );
1055
+
1056
+ // x/clob.MsgUpdateClobPair
1057
+ const updateClobPair = composer.composeMsgUpdateClobPair(
1058
+ params.id,
1059
+ params.id,
1060
+ params.quantumConversionExponent,
1061
+ params.stepBaseQuantums,
1062
+ params.subticksPerTick,
1063
+ );
1064
+
1065
+ // x/delaymsg.MsgDelayMessage
1066
+ const delayMessage = composer.composeMsgDelayMessage(
1067
+ // IMPORTANT: must wrap messages in Any type to fit into delaymsg.
1068
+ composer.wrapMessageAsAny(registry, updateClobPair),
1069
+ params.delayBlocks,
1070
+ );
1071
+
1072
+ // The order matters.
1073
+ msgs.push(createOracleMarket);
1074
+ msgs.push(createPerpetual);
1075
+ msgs.push(createClobPair);
1076
+ msgs.push(delayMessage);
1077
+
1078
+ // x/gov.v1.MsgSubmitProposal
1079
+ const submitProposal = composer.composeMsgSubmitProposal(
1080
+ title,
1081
+ initialDepositAmount,
1082
+ this.validatorClient.config.denoms, // use the client denom.
1083
+ summary,
1084
+ // IMPORTANT: must wrap messages in Any type for gov's submit proposal.
1085
+ composer.wrapMessageArrAsAny(registry, msgs),
1086
+ wallet.address!, // proposer
1087
+ );
1088
+
1089
+ resolve([submitProposal]);
1090
+ });
1091
+
1092
+ return this.send(
1093
+ wallet,
1094
+ () => msg,
1095
+ false,
1096
+ );
1097
+ }
1003
1098
  }
@@ -43,6 +43,40 @@ export enum NetworkId {
43
43
  export const NETWORK_ID_MAINNET: string | null = null;
44
44
  export const NETWORK_ID_TESTNET: string = 'dydxprotocol-testnet';
45
45
 
46
+ // ------------ MsgType URLs ------------
47
+ // Default CosmosSDK
48
+ // x/bank
49
+ export const TYPE_URL_MSG_SEND = '/cosmos.bank.v1beta1.MsgSend';
50
+
51
+ // x/gov
52
+ export const TYPE_URL_MSG_SUBMIT_PROPOSAL = '/cosmos.gov.v1.MsgSubmitProposal';
53
+
54
+ // dYdX Specific
55
+ // x/clob
56
+ export const TYPE_URL_MSG_PLACE_ORDER = '/dydxprotocol.clob.MsgPlaceOrder';
57
+ export const TYPE_URL_MSG_CANCEL_ORDER = '/dydxprotocol.clob.MsgCancelOrder';
58
+ export const TYPE_URL_MSG_CREATE_CLOB_PAIR = '/dydxprotocol.clob.MsgCreateClobPair';
59
+ export const TYPE_URL_MSG_UPDATE_CLOB_PAIR = '/dydxprotocol.clob.MsgUpdateClobPair';
60
+
61
+ // x/delaymsg
62
+ export const TYPE_URL_MSG_DELAY_MESSAGE = '/dydxprotocol.delaymsg.MsgDelayMessage';
63
+
64
+ // x/perpetuals
65
+ export const TYPE_URL_MSG_CREATE_PERPETUAL = '/dydxprotocol.perpetuals.MsgCreatePerpetual';
66
+
67
+ // x/prices
68
+ export const TYPE_URL_MSG_CREATE_ORACLE_MARKET = '/dydxprotocol.prices.MsgCreateOracleMarket';
69
+
70
+ // x/sending
71
+ export const TYPE_URL_MSG_CREATE_TRANSFER = '/dydxprotocol.sending.MsgCreateTransfer';
72
+ export const TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT = '/dydxprotocol.sending.MsgWithdrawFromSubaccount';
73
+ export const TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT = '/dydxprotocol.sending.MsgDepositToSubaccount';
74
+
75
+ // ------------ Chain Constants ------------
76
+ // The following are same across different networks / deployments.
77
+ export const GOV_MODULE_ADDRESS = 'dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky';
78
+ export const DELAYMSG_MODULE_ADDRESS = 'dydx1mkkvp26dngu6n8rmalaxyp3gwkjuzztq5zx6tr';
79
+
46
80
  // ------------ Market Statistic Day Types ------------
47
81
  export enum MarketStatisticDay {
48
82
  ONE = '1',
@@ -131,14 +165,14 @@ export const PAGE_REQUEST: PageRequest = {
131
165
  };
132
166
 
133
167
  export class IndexerConfig {
134
- public restEndpoint: string;
135
- public websocketEndpoint: string;
168
+ public restEndpoint: string;
169
+ public websocketEndpoint: string;
136
170
 
137
- constructor(restEndpoint: string,
138
- websocketEndpoint: string) {
139
- this.restEndpoint = restEndpoint;
140
- this.websocketEndpoint = websocketEndpoint;
141
- }
171
+ constructor(restEndpoint: string,
172
+ websocketEndpoint: string) {
173
+ this.restEndpoint = restEndpoint;
174
+ this.websocketEndpoint = websocketEndpoint;
175
+ }
142
176
  }
143
177
 
144
178
  export class ValidatorConfig {
@@ -166,7 +200,7 @@ export class Network {
166
200
  public env: string,
167
201
  public indexerConfig: IndexerConfig,
168
202
  public validatorConfig: ValidatorConfig,
169
- ) {}
203
+ ) { }
170
204
 
171
205
  static testnet(): Network {
172
206
  const indexerConfig = new IndexerConfig(
@@ -3,26 +3,53 @@ import { defaultRegistryTypes } from '@cosmjs/stargate';
3
3
  import {
4
4
  MsgPlaceOrder,
5
5
  MsgCancelOrder,
6
+ MsgCreateClobPair,
7
+ MsgUpdateClobPair,
6
8
  } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/tx';
9
+ import { MsgDelayMessage } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/delaymsg/tx';
10
+ import { MsgCreatePerpetual } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/tx';
11
+ import { MsgCreateOracleMarket } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/tx';
7
12
  import {
8
13
  MsgWithdrawFromSubaccount,
9
14
  MsgDepositToSubaccount,
10
15
  } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/transfer';
16
+ import { MsgCreateTransfer } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx';
17
+
11
18
  import {
12
- MsgCreateTransfer,
13
- } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx';
19
+ TYPE_URL_MSG_PLACE_ORDER,
20
+ TYPE_URL_MSG_CANCEL_ORDER,
21
+ TYPE_URL_MSG_CREATE_CLOB_PAIR,
22
+ TYPE_URL_MSG_UPDATE_CLOB_PAIR,
23
+ TYPE_URL_MSG_DELAY_MESSAGE,
24
+ TYPE_URL_MSG_CREATE_PERPETUAL,
25
+ TYPE_URL_MSG_CREATE_ORACLE_MARKET,
26
+ TYPE_URL_MSG_CREATE_TRANSFER,
27
+ TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT,
28
+ TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT,
29
+ } from '../constants';
14
30
 
15
31
  export const registry: ReadonlyArray<[string, GeneratedType]> = [];
16
32
  export function generateRegistry(): Registry {
17
33
  return new Registry([
18
34
  // clob
19
- ['/dydxprotocol.clob.MsgPlaceOrder', MsgPlaceOrder as GeneratedType],
20
- ['/dydxprotocol.clob.MsgCancelOrder', MsgCancelOrder as GeneratedType],
35
+ [TYPE_URL_MSG_PLACE_ORDER, MsgPlaceOrder as GeneratedType],
36
+ [TYPE_URL_MSG_CANCEL_ORDER, MsgCancelOrder as GeneratedType],
37
+ [TYPE_URL_MSG_CREATE_CLOB_PAIR, MsgCreateClobPair as GeneratedType],
38
+ [TYPE_URL_MSG_UPDATE_CLOB_PAIR, MsgUpdateClobPair as GeneratedType],
39
+
40
+ // delaymsg
41
+ [TYPE_URL_MSG_DELAY_MESSAGE, MsgDelayMessage as GeneratedType],
42
+
43
+ // perpetuals
44
+ [TYPE_URL_MSG_CREATE_PERPETUAL, MsgCreatePerpetual as GeneratedType],
45
+
46
+ // prices
47
+ [TYPE_URL_MSG_CREATE_ORACLE_MARKET, MsgCreateOracleMarket as GeneratedType],
21
48
 
22
49
  // sending
23
- ['/dydxprotocol.sending.MsgCreateTransfer', MsgCreateTransfer as GeneratedType],
24
- ['/dydxprotocol.sending.MsgWithdrawFromSubaccount', MsgWithdrawFromSubaccount as GeneratedType],
25
- ['/dydxprotocol.sending.MsgDepositToSubaccount', MsgDepositToSubaccount as GeneratedType],
50
+ [TYPE_URL_MSG_CREATE_TRANSFER, MsgCreateTransfer as GeneratedType],
51
+ [TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT, MsgWithdrawFromSubaccount as GeneratedType],
52
+ [TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT, MsgDepositToSubaccount as GeneratedType],
26
53
 
27
54
  // default types
28
55
  ...defaultRegistryTypes,
@@ -1,9 +1,40 @@
1
- import { EncodeObject } from '@cosmjs/proto-signing';
1
+ import { EncodeObject, Registry } from '@cosmjs/proto-signing';
2
+ import {
3
+ MsgSubmitProposal,
4
+ } from '@dydxprotocol/v4-proto/src/codegen/cosmos/gov/v1/tx';
5
+ import {
6
+ ClobPair_Status,
7
+ } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/clob_pair';
8
+ import {
9
+ MsgCreateClobPair,
10
+ MsgUpdateClobPair,
11
+ } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/tx';
12
+ import { MsgDelayMessage } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/delaymsg/tx';
13
+ import { MsgCreatePerpetual } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/tx';
14
+ import { MsgCreateOracleMarket } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/tx';
2
15
  import { MsgSend } from 'cosmjs-types/cosmos/bank/v1beta1/tx';
3
16
  import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin';
17
+ import { Any } from 'cosmjs-types/google/protobuf/any';
4
18
  import Long from 'long';
5
19
  import protobuf from 'protobufjs';
6
20
 
21
+ import {
22
+ GOV_MODULE_ADDRESS,
23
+ DELAYMSG_MODULE_ADDRESS,
24
+ TYPE_URL_MSG_SEND,
25
+ TYPE_URL_MSG_SUBMIT_PROPOSAL,
26
+ TYPE_URL_MSG_PLACE_ORDER,
27
+ TYPE_URL_MSG_CANCEL_ORDER,
28
+ TYPE_URL_MSG_CREATE_CLOB_PAIR,
29
+ TYPE_URL_MSG_UPDATE_CLOB_PAIR,
30
+ TYPE_URL_MSG_DELAY_MESSAGE,
31
+ TYPE_URL_MSG_CREATE_PERPETUAL,
32
+ TYPE_URL_MSG_CREATE_ORACLE_MARKET,
33
+ TYPE_URL_MSG_CREATE_TRANSFER,
34
+ TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT,
35
+ TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT,
36
+ } from '../constants';
37
+ import { DenomConfig } from '../types';
7
38
  import {
8
39
  OrderId,
9
40
  Order,
@@ -23,6 +54,8 @@ protobuf.util.Long = Long;
23
54
  protobuf.configure();
24
55
 
25
56
  export class Composer {
57
+
58
+ // ------------ x/clob ------------
26
59
  public composeMsgPlaceOrder(
27
60
  address: string,
28
61
  subaccountNumber: number,
@@ -70,7 +103,7 @@ export class Composer {
70
103
  order,
71
104
  };
72
105
  return {
73
- typeUrl: '/dydxprotocol.clob.MsgPlaceOrder',
106
+ typeUrl: TYPE_URL_MSG_PLACE_ORDER,
74
107
  value: msg,
75
108
  };
76
109
  }
@@ -105,11 +138,68 @@ export class Composer {
105
138
  };
106
139
 
107
140
  return {
108
- typeUrl: '/dydxprotocol.clob.MsgCancelOrder',
141
+ typeUrl: TYPE_URL_MSG_CANCEL_ORDER,
109
142
  value: msg,
110
143
  };
111
144
  }
112
145
 
146
+ public composeMsgCreateClobPair(
147
+ clobId: number,
148
+ perpetualId: number,
149
+ quantumConversionExponent: number,
150
+ stepBaseQuantums: Long,
151
+ subticksPerTick: number,
152
+ ): EncodeObject {
153
+ const msg: MsgCreateClobPair = {
154
+ // uses x/gov module account since creating the clob pair is a governance action.
155
+ authority: GOV_MODULE_ADDRESS,
156
+ clobPair: {
157
+ id: clobId,
158
+ perpetualClobMetadata: {
159
+ perpetualId,
160
+ },
161
+ quantumConversionExponent,
162
+ stepBaseQuantums,
163
+ subticksPerTick,
164
+ status: ClobPair_Status.STATUS_INITIALIZING,
165
+ },
166
+ };
167
+
168
+ return {
169
+ typeUrl: TYPE_URL_MSG_CREATE_CLOB_PAIR,
170
+ value: msg,
171
+ };
172
+ }
173
+
174
+ public composeMsgUpdateClobPair(
175
+ clobId: number,
176
+ perpetualId: number,
177
+ quantumConversionExponent: number,
178
+ stepBaseQuantums: Long,
179
+ subticksPerTick: number,
180
+ ): EncodeObject {
181
+ const msg: MsgUpdateClobPair = {
182
+ // uses x/delaymsg module account since updating the clob pair is a delayedmsg action.
183
+ authority: DELAYMSG_MODULE_ADDRESS,
184
+ clobPair: {
185
+ id: clobId,
186
+ perpetualClobMetadata: {
187
+ perpetualId,
188
+ },
189
+ quantumConversionExponent,
190
+ stepBaseQuantums,
191
+ subticksPerTick,
192
+ status: ClobPair_Status.STATUS_ACTIVE,
193
+ },
194
+ };
195
+
196
+ return {
197
+ typeUrl: TYPE_URL_MSG_UPDATE_CLOB_PAIR,
198
+ value: msg,
199
+ };
200
+ }
201
+
202
+ // ------------ x/sending ------------
113
203
  public composeMsgTransfer(
114
204
  address: string,
115
205
  subaccountNumber: number,
@@ -139,7 +229,7 @@ export class Composer {
139
229
  };
140
230
 
141
231
  return {
142
- typeUrl: '/dydxprotocol.sending.MsgCreateTransfer',
232
+ typeUrl: TYPE_URL_MSG_CREATE_TRANSFER,
143
233
  value: msg,
144
234
  };
145
235
  }
@@ -163,7 +253,7 @@ export class Composer {
163
253
  };
164
254
 
165
255
  return {
166
- typeUrl: '/dydxprotocol.sending.MsgDepositToSubaccount',
256
+ typeUrl: TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT,
167
257
  value: msg,
168
258
  };
169
259
  }
@@ -188,11 +278,12 @@ export class Composer {
188
278
  };
189
279
 
190
280
  return {
191
- typeUrl: '/dydxprotocol.sending.MsgWithdrawFromSubaccount',
281
+ typeUrl: TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT,
192
282
  value: msg,
193
283
  };
194
284
  }
195
285
 
286
+ // ------------ x/bank ------------
196
287
  public composeMsgSendToken(
197
288
  address: string,
198
289
  recipient: string,
@@ -211,11 +302,117 @@ export class Composer {
211
302
  };
212
303
 
213
304
  return {
214
- typeUrl: '/cosmos.bank.v1beta1.MsgSend',
305
+ typeUrl: TYPE_URL_MSG_SEND,
306
+ value: msg,
307
+ };
308
+ }
309
+
310
+ // ------------ x/prices ------------
311
+ public composeMsgCreateOracleMarket(
312
+ marketId: number,
313
+ pair: string,
314
+ exponent: number,
315
+ minExchanges: number,
316
+ minPriceChangePpm: number,
317
+ exchangeConfigJson: string,
318
+ ): EncodeObject {
319
+ const msg: MsgCreateOracleMarket = {
320
+ // uses x/gov module account since creating the oracle market is a governance action.
321
+ authority: GOV_MODULE_ADDRESS,
322
+ params: {
323
+ id: marketId,
324
+ pair,
325
+ exponent,
326
+ minExchanges,
327
+ minPriceChangePpm,
328
+ exchangeConfigJson,
329
+ },
330
+ };
331
+
332
+ return {
333
+ typeUrl: TYPE_URL_MSG_CREATE_ORACLE_MARKET,
215
334
  value: msg,
216
335
  };
217
336
  }
218
337
 
338
+ // ------------ x/perpetuals ------------
339
+ public composeMsgCreatePerpetual(
340
+ perpetualId: number,
341
+ marketId: number,
342
+ ticker: string,
343
+ atomicResolution: number,
344
+ liquidityTier: number,
345
+ ): EncodeObject {
346
+ const msg: MsgCreatePerpetual = {
347
+ // uses x/gov module account since creating the perpetual is a governance action.
348
+ authority: GOV_MODULE_ADDRESS,
349
+ params: {
350
+ id: perpetualId,
351
+ marketId,
352
+ ticker,
353
+ atomicResolution,
354
+ defaultFundingPpm: 0, // default funding should be 0 to start.
355
+ liquidityTier,
356
+ },
357
+ };
358
+
359
+ return {
360
+ typeUrl: TYPE_URL_MSG_CREATE_PERPETUAL,
361
+ value: msg,
362
+ };
363
+ }
364
+
365
+ // ------------ x/delaymsg ------------
366
+ public composeMsgDelayMessage(
367
+ embeddedMsg: EncodeObject,
368
+ delayBlocks: number,
369
+ ): EncodeObject {
370
+ const msg: MsgDelayMessage = {
371
+ // all msgs sent to x/delay must be from x/gov module account.
372
+ authority: GOV_MODULE_ADDRESS,
373
+ msg: embeddedMsg,
374
+ delayBlocks,
375
+ };
376
+
377
+ return {
378
+ typeUrl: TYPE_URL_MSG_DELAY_MESSAGE,
379
+ value: msg,
380
+ };
381
+ }
382
+
383
+ // ------------ x/gov ------------
384
+ public composeMsgSubmitProposal(
385
+ title: string,
386
+ initialDepositAmount: number,
387
+ initialDepositDenomConfig: DenomConfig,
388
+ summary: string,
389
+ messages: EncodeObject[],
390
+ proposer: string,
391
+ metadata: string = '',
392
+ expedited: boolean = false,
393
+ ): EncodeObject {
394
+ const initialDeposit: Coin[] = [{
395
+ amount: initialDepositAmount.toString(),
396
+ denom: initialDepositDenomConfig.CHAINTOKEN_DENOM,
397
+ }];
398
+
399
+ const msg: MsgSubmitProposal = {
400
+ title,
401
+ initialDeposit,
402
+ summary,
403
+ messages,
404
+ proposer,
405
+ metadata,
406
+ expedited,
407
+ };
408
+
409
+ return {
410
+ typeUrl: TYPE_URL_MSG_SUBMIT_PROPOSAL,
411
+ value: msg,
412
+ };
413
+ }
414
+
415
+ // ------------ util ------------
219
416
  public validateGoodTilBlockAndTime(
220
417
  orderFlags: number,
221
418
  goodTilBlock: number,
@@ -227,4 +424,18 @@ export class Composer {
227
424
  throw new Error('goodTilBlockTime must be set if orderFlags is not 0');
228
425
  }
229
426
  }
427
+
428
+ public wrapMessageAsAny(registry: Registry, message: EncodeObject): Any {
429
+ return registry.encodeAsAny(message);
430
+ }
431
+
432
+ public wrapMessageArrAsAny(
433
+ registry: Registry,
434
+ messages: EncodeObject[],
435
+ ): Any[] {
436
+ const encodedMessages: Any[] = messages.map(
437
+ (message: EncodeObject) => this.wrapMessageAsAny(registry, message),
438
+ );
439
+ return encodedMessages;
440
+ }
230
441
  }
@@ -19,8 +19,10 @@ import {
19
19
  BridgeModule,
20
20
  ClobModule,
21
21
  FeeTierModule,
22
+ GovV1Module,
22
23
  PerpetualsModule,
23
24
  PricesModule,
25
+ ProposalStatus,
24
26
  RewardsModule,
25
27
  StakingModule,
26
28
  StatsModule,
@@ -365,7 +367,7 @@ export class Get {
365
367
  */
366
368
  async getEquityTierLimitConfiguration(): Promise<
367
369
  ClobModule.QueryEquityTierLimitConfigurationResponse
368
- > {
370
+ > {
369
371
  const requestData: Uint8Array = Uint8Array.from(
370
372
  ClobModule.QueryEquityTierLimitConfigurationRequest.encode({})
371
373
  .finish(),
@@ -470,9 +472,40 @@ export class Get {
470
472
  return StakingModule.QueryValidatorsResponse.decode(data);
471
473
  }
472
474
 
475
+ /**
476
+ * @description Get all gov proposals.
477
+ *
478
+ * @param proposalStatus Status of the proposal to filter by.
479
+ * @param voter Voter to filter by.
480
+ * @param depositor Depositor to filter by.
481
+ *
482
+ * @returns All gov proposals that match the filters above.
483
+ */
484
+ async getAllGovProposals(
485
+ proposalStatus: ProposalStatus = ProposalStatus.PROPOSAL_STATUS_VOTING_PERIOD,
486
+ voter: string = '',
487
+ depositor: string = '',
488
+ ): Promise<GovV1Module.QueryProposalsResponse> {
489
+ const requestData = Uint8Array.from(
490
+ GovV1Module.QueryProposalsRequest
491
+ .encode({
492
+ proposalStatus,
493
+ voter,
494
+ depositor,
495
+ pagination: PAGE_REQUEST,
496
+ })
497
+ .finish(),
498
+ );
499
+ const data: Uint8Array = await this.sendQuery(
500
+ '/cosmos.gov.v1.Query/Proposals',
501
+ requestData,
502
+ );
503
+ return GovV1Module.QueryProposalsResponse.decode(data);
504
+ }
505
+
473
506
  private async sendQuery(requestUrl: string, requestData: Uint8Array): Promise<Uint8Array> {
474
- const resp: QueryAbciResponse = await
475
- this.stargateQueryClient.queryAbci(requestUrl, requestData);
507
+ // eslint-disable-next-line max-len
508
+ const resp: QueryAbciResponse = await this.stargateQueryClient.queryAbci(requestUrl, requestData);
476
509
  return resp.value;
477
510
  }
478
511
  }
@@ -1,17 +1,22 @@
1
+ export * as GovV1Module from '@dydxprotocol/v4-proto/src/codegen/cosmos/gov/v1/query';
2
+ export * as StatsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query';
3
+
1
4
  export * as ClobModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/query';
2
5
  export * as PerpetualsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/query';
3
6
  export * as PricesModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/query';
4
- export * as SubaccountsModule
5
- from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/query';
7
+ export * as SubaccountsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/query';
6
8
  export * as FeeTierModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/feetiers/query';
7
- export * as StatsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/stats/query';
8
9
  export * as RewardsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/rewards/query';
9
10
  export * as StakingModule from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/query';
10
11
  export * as BridgeModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/bridge/query';
11
12
 
12
13
  export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/base/abci/v1beta1/abci';
14
+ export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/gov/v1/gov';
13
15
  export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order';
14
16
  export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/tx';
17
+ export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/delaymsg/tx';
18
+ export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/perpetuals/tx';
19
+ export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/prices/tx';
15
20
  export * from '@dydxprotocol/v4-proto/src/codegen/google/protobuf/any';
16
21
  export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/subaccounts/subaccount';
17
22
  export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx';
@@ -96,6 +96,7 @@ export interface ComplianceResponse {
96
96
  restricted: boolean;
97
97
  }
98
98
 
99
+ // ------------ Squid ------------ //
99
100
  export type SquidIBCPayload = {
100
101
  msgTypeUrl: '/ibc.applications.transfer.v1.MsgTransfer';
101
102
  msg: Partial<{
@@ -109,4 +110,29 @@ export type SquidIBCPayload = {
109
110
  }>;
110
111
  };
111
112
 
113
+ // ------------ x/gov: Add New Market ------------ //
114
+ export type GovAddNewMarketParams = {
115
+ // common
116
+ id: number;
117
+ ticker: string;
118
+
119
+ // x/prices
120
+ priceExponent: number;
121
+ minPriceChange: number;
122
+ minExchanges: number;
123
+ exchangeConfigJson: string;
124
+
125
+ // x/perpetuals
126
+ liquidityTier: number;
127
+ atomicResolution: number;
128
+
129
+ // x/clob
130
+ quantumConversionExponent: number;
131
+ stepBaseQuantums: Long;
132
+ subticksPerTick: number;
133
+
134
+ // x/delaymsg
135
+ delayBlocks: number;
136
+ };
137
+
112
138
  export * from './modules/proto-includes';