@dydxprotocol/v4-client-js 1.9.1 → 1.11.0

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.9.1",
3
+ "version": "1.11.0",
4
4
  "description": "General client library for the new dYdX system (v4 decentralized)",
5
5
  "main": "build/src/index.js",
6
6
  "scripts": {
@@ -1207,4 +1207,14 @@ export class CompositeClient {
1207
1207
 
1208
1208
  return this.send(wallet, () => msg, false, undefined, memo);
1209
1209
  }
1210
+
1211
+ async createMarketPermissionless(
1212
+ subaccount: SubaccountInfo,
1213
+ ticker: string,
1214
+ broadcastMode?: BroadcastMode,
1215
+ gasAdjustment?: number,
1216
+ memo?: string,
1217
+ ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
1218
+ return this.validatorClient.post.createMarketPermissionless(ticker, subaccount, broadcastMode, gasAdjustment, memo);
1219
+ }
1210
1220
  }
@@ -85,6 +85,9 @@ export const TYPE_URL_MSG_UPDATE_CLOB_PAIR = '/dydxprotocol.clob.MsgUpdateClobPa
85
85
  // x/delaymsg
86
86
  export const TYPE_URL_MSG_DELAY_MESSAGE = '/dydxprotocol.delaymsg.MsgDelayMessage';
87
87
 
88
+ // x/listing
89
+ export const TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS = '/dydxprotocol.listing.MsgCreateMarketPermissionless';
90
+
88
91
  // x/perpetuals
89
92
  export const TYPE_URL_MSG_CREATE_PERPETUAL = '/dydxprotocol.perpetuals.MsgCreatePerpetual';
90
93
 
@@ -97,6 +100,9 @@ export const TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT =
97
100
  '/dydxprotocol.sending.MsgWithdrawFromSubaccount';
98
101
  export const TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT = '/dydxprotocol.sending.MsgDepositToSubaccount';
99
102
 
103
+ // x/affiliates
104
+ export const TYPE_URL_MSG_REGISTER_AFFILIATE = '/dydxprotocol.affiliates.MsgRegisterAffiliate';
105
+
100
106
  // x/vault
101
107
  export const TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT = '/dydxprotocol.vault.MsgDepositToMegavault';
102
108
  export const TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT = '/dydxprotocol.vault.MsgWithdrawFromMegavault';
@@ -1,5 +1,6 @@
1
1
  import { GeneratedType, Registry } from '@cosmjs/proto-signing';
2
2
  import { defaultRegistryTypes } from '@cosmjs/stargate';
3
+ import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
3
4
  import {
4
5
  MsgPlaceOrder,
5
6
  MsgCancelOrder,
@@ -34,6 +35,7 @@ import {
34
35
  TYPE_URL_BATCH_CANCEL,
35
36
  TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT,
36
37
  TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
38
+ TYPE_URL_MSG_REGISTER_AFFILIATE,
37
39
  } from '../constants';
38
40
 
39
41
  export const registry: ReadonlyArray<[string, GeneratedType]> = [];
@@ -58,11 +60,15 @@ export function generateRegistry(): Registry {
58
60
  // vaults
59
61
  [TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT, MsgDepositToMegavault as GeneratedType],
60
62
  [TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT, MsgWithdrawFromMegavault as GeneratedType],
63
+
61
64
  // sending
62
65
  [TYPE_URL_MSG_CREATE_TRANSFER, MsgCreateTransfer as GeneratedType],
63
66
  [TYPE_URL_MSG_WITHDRAW_FROM_SUBACCOUNT, MsgWithdrawFromSubaccount as GeneratedType],
64
67
  [TYPE_URL_MSG_DEPOSIT_TO_SUBACCOUNT, MsgDepositToSubaccount as GeneratedType],
65
68
 
69
+ // affiliates
70
+ [TYPE_URL_MSG_REGISTER_AFFILIATE, MsgRegisterAffiliate as GeneratedType],
71
+
66
72
  // default types
67
73
  ...defaultRegistryTypes,
68
74
  ]);
@@ -7,6 +7,7 @@ import {
7
7
  MsgDelegate,
8
8
  MsgUndelegate,
9
9
  } from '@dydxprotocol/v4-proto/src/codegen/cosmos/staking/v1beta1/tx';
10
+ import { MsgRegisterAffiliate } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/tx';
10
11
  import { ClobPair_Status } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/clob_pair';
11
12
  import {
12
13
  MsgBatchCancel,
@@ -47,8 +48,10 @@ import {
47
48
  TYPE_URL_MSG_UNDELEGATE,
48
49
  TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD,
49
50
  TYPE_URL_BATCH_CANCEL,
51
+ TYPE_URL_MSG_REGISTER_AFFILIATE,
50
52
  TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT,
51
53
  TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
54
+ TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS,
52
55
  } from '../constants';
53
56
  import { DenomConfig } from '../types';
54
57
  import {
@@ -60,6 +63,7 @@ import {
60
63
  MsgPlaceOrder,
61
64
  MsgCancelOrder,
62
65
  SubaccountId,
66
+ MsgCreateMarketPermissionless,
63
67
  MsgCreateTransfer,
64
68
  Transfer,
65
69
  MsgDepositToSubaccount,
@@ -536,6 +540,41 @@ export class Composer {
536
540
  };
537
541
  }
538
542
 
543
+ // ------------ x/affiliates ------------
544
+ public composeMsgRegisterAffiliate(referee: string, affiliate: string): EncodeObject {
545
+ const msg: MsgRegisterAffiliate = {
546
+ referee,
547
+ affiliate,
548
+ };
549
+
550
+ return {
551
+ typeUrl: TYPE_URL_MSG_REGISTER_AFFILIATE,
552
+ value: msg,
553
+ };
554
+ }
555
+
556
+ // ------------ x/listing ------------
557
+ public composeMsgCreateMarketPermissionless(
558
+ address: string,
559
+ ticker: string,
560
+ subaccountNumber: number,
561
+ ): EncodeObject {
562
+ const subaccountId: SubaccountId = {
563
+ owner: address,
564
+ number: subaccountNumber,
565
+ };
566
+
567
+ const msg: MsgCreateMarketPermissionless = {
568
+ ticker,
569
+ subaccountId
570
+ };
571
+
572
+ return {
573
+ typeUrl: TYPE_URL_MSG_CREATE_MARKET_PERMISSIONLESS,
574
+ value: msg,
575
+ }
576
+ }
577
+
539
578
  // ------------ util ------------
540
579
  public validateGoodTilBlockAndTime(
541
580
  orderFlags: number,
@@ -17,6 +17,7 @@ import { bigIntToBytes } from '../../lib/helpers';
17
17
  import { PAGE_REQUEST } from '../constants';
18
18
  import { UnexpectedClientError } from '../lib/errors';
19
19
  import {
20
+ AffiliateModule,
20
21
  BridgeModule,
21
22
  ClobModule,
22
23
  DistributionModule,
@@ -559,6 +560,56 @@ export class Get {
559
560
  return VaultModule.QueryMegavaultWithdrawalInfoResponse.decode(data);
560
561
  }
561
562
 
563
+ async getAffiliateInfo(address: string): Promise<AffiliateModule.AffiliateInfoResponse> {
564
+ const requestData = Uint8Array.from(
565
+ AffiliateModule.AffiliateInfoRequest.encode({
566
+ address,
567
+ }).finish(),
568
+ );
569
+
570
+ const data = await this.sendQuery('/dydxprotocol.affiliates.Query/AffiliateInfo', requestData);
571
+
572
+ return AffiliateModule.AffiliateInfoResponse.decode(data);
573
+ }
574
+
575
+ async getReferredBy(address: string): Promise<AffiliateModule.ReferredByResponse> {
576
+ const requestData = Uint8Array.from(
577
+ AffiliateModule.ReferredByRequest.encode({
578
+ address,
579
+ }).finish(),
580
+ );
581
+
582
+ const data = await this.sendQuery('/dydxprotocol.affiliates.Query/ReferredBy', requestData);
583
+
584
+ return AffiliateModule.ReferredByResponse.decode(data);
585
+ }
586
+
587
+ async getAllAffiliateTiers(): Promise<AffiliateModule.AllAffiliateTiersResponse> {
588
+ const requestData = Uint8Array.from(
589
+ AffiliateModule.AllAffiliateTiersRequest.encode({}).finish(),
590
+ );
591
+
592
+ const data = await this.sendQuery(
593
+ '/dydxprotocol.affiliates.Query/AllAffiliateTiers',
594
+ requestData,
595
+ );
596
+
597
+ return AffiliateModule.AllAffiliateTiersResponse.decode(data);
598
+ }
599
+
600
+ async getAffiliateWhitelist(): Promise<AffiliateModule.AffiliateWhitelistResponse> {
601
+ const requestData = Uint8Array.from(
602
+ AffiliateModule.AffiliateWhitelistRequest.encode({}).finish(),
603
+ );
604
+
605
+ const data = await this.sendQuery(
606
+ '/dydxprotocol.affiliates.Query/AffiliateWhitelist',
607
+ requestData,
608
+ );
609
+
610
+ return AffiliateModule.AffiliateWhitelistResponse.decode(data);
611
+ }
612
+
562
613
  private async sendQuery(requestUrl: string, requestData: Uint8Array): Promise<Uint8Array> {
563
614
  // eslint-disable-next-line max-len
564
615
  const resp: QueryAbciResponse = await this.stargateQueryClient.queryAbci(
@@ -58,7 +58,13 @@ export class Post {
58
58
  public useTimestampNonce: boolean = false;
59
59
  private accountNumberCache: Map<string, Account> = new Map();
60
60
 
61
- constructor(get: Get, chainId: string, denoms: DenomConfig, defaultClientMemo?: string, useTimestampNonce?: boolean) {
61
+ constructor(
62
+ get: Get,
63
+ chainId: string,
64
+ denoms: DenomConfig,
65
+ defaultClientMemo?: string,
66
+ useTimestampNonce?: boolean,
67
+ ) {
62
68
  this.get = get;
63
69
  this.chainId = chainId;
64
70
  this.registry = generateRegistry();
@@ -129,13 +135,7 @@ export class Post {
129
135
  sequence = msgsAndAccount[1].sequence;
130
136
  }
131
137
 
132
- return this.simulateTransaction(
133
- wallet.pubKey!,
134
- sequence,
135
- msgs,
136
- gasPrice,
137
- memo,
138
- );
138
+ return this.simulateTransaction(wallet.pubKey!, sequence, msgs, gasPrice, memo);
139
139
  }
140
140
 
141
141
  /**
@@ -177,6 +177,7 @@ export class Post {
177
177
  memo?: string,
178
178
  broadcastMode?: BroadcastMode,
179
179
  account?: () => Promise<Account>,
180
+ gasAdjustment: number = GAS_MULTIPLIER,
180
181
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
181
182
  const msgsPromise = messaging();
182
183
  const accountPromise = account ? await account() : this.account(wallet.address!);
@@ -191,6 +192,7 @@ export class Post {
191
192
  gasPrice,
192
193
  memo ?? this.defaultClientMemo,
193
194
  broadcastMode ?? this.defaultBroadcastMode(msgs),
195
+ gasAdjustment,
194
196
  );
195
197
  }
196
198
 
@@ -235,6 +237,7 @@ export class Post {
235
237
  zeroFee: boolean,
236
238
  gasPrice: GasPrice = this.getGasPrice(),
237
239
  memo?: string,
240
+ gasAdjustment: number = GAS_MULTIPLIER,
238
241
  ): Promise<Uint8Array> {
239
242
  // protocol expects timestamp nonce in UTC milliseconds, which is the unit returned by Date.now()
240
243
  const sequence = this.useTimestampNonce ? Date.now() : account.sequence;
@@ -244,7 +247,14 @@ export class Post {
244
247
  amount: [],
245
248
  gas: '1000000',
246
249
  }
247
- : await this.simulateTransaction(wallet.pubKey!, sequence, messages, gasPrice, memo);
250
+ : await this.simulateTransaction(
251
+ wallet.pubKey!,
252
+ sequence,
253
+ messages,
254
+ gasPrice,
255
+ memo,
256
+ gasAdjustment,
257
+ );
248
258
 
249
259
  const txOptions: TransactionOptions = {
250
260
  sequence,
@@ -286,6 +296,7 @@ export class Post {
286
296
  gasPrice: GasPrice = this.getGasPrice(),
287
297
  memo?: string,
288
298
  broadcastMode?: BroadcastMode,
299
+ gasAdjustment: number = GAS_MULTIPLIER,
289
300
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
290
301
  const signedTransaction = await this.signTransaction(
291
302
  wallet,
@@ -294,6 +305,7 @@ export class Post {
294
305
  zeroFee,
295
306
  gasPrice,
296
307
  memo,
308
+ gasAdjustment,
297
309
  );
298
310
  return this.sendSignedTransaction(signedTransaction, broadcastMode);
299
311
  }
@@ -326,6 +338,7 @@ export class Post {
326
338
  messages: readonly EncodeObject[],
327
339
  gasPrice: GasPrice = this.getGasPrice(),
328
340
  memo?: string,
341
+ gasAdjustment: number = GAS_MULTIPLIER,
329
342
  ): Promise<StdFee> {
330
343
  // Get simulated response.
331
344
  const encodedMessages: Any[] = messages.map((message: EncodeObject) =>
@@ -347,7 +360,7 @@ export class Post {
347
360
  const gasEstimate: number = Uint53.fromString(
348
361
  simulationResponse.gasInfo.gasUsed.toString(),
349
362
  ).toNumber();
350
- const fee = calculateFee(Math.floor(gasEstimate * GAS_MULTIPLIER), gasPrice);
363
+ const fee = calculateFee(Math.floor(gasEstimate * gasAdjustment), gasPrice);
351
364
 
352
365
  // TODO(TRCL-2550): Temporary workaround before IBC denom is supported in '@cosmjs/stargate'.
353
366
  // The '@cosmjs/stargate' does not support denom with '/', so currently GAS_PRICE is
@@ -881,4 +894,46 @@ export class Post {
881
894
  ): EncodeObject {
882
895
  return this.composer.composeMsgWithdrawFromMegavault(...args);
883
896
  }
897
+
898
+ async registerAffiliate(
899
+ subaccount: SubaccountInfo,
900
+ affiliate: string,
901
+ broadcastMode?: BroadcastMode,
902
+ ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
903
+ const msg = this.registerAffiliateMsg(subaccount.address, affiliate);
904
+ const gasAdjustment = 1.8;
905
+ return this.send(
906
+ subaccount.wallet,
907
+ () => Promise.resolve([msg]),
908
+ false,
909
+ undefined,
910
+ undefined,
911
+ broadcastMode,
912
+ undefined,
913
+ gasAdjustment,
914
+ );
915
+ }
916
+
917
+ registerAffiliateMsg(...args: Parameters<Composer['composeMsgRegisterAffiliate']>): EncodeObject {
918
+ return this.composer.composeMsgRegisterAffiliate(...args);
919
+ }
920
+
921
+ launchMarketMsg(...args: Parameters<Composer['composeMsgCreateMarketPermissionless']>): EncodeObject {
922
+ return this.composer.composeMsgCreateMarketPermissionless(...args);
923
+ }
924
+
925
+ async createMarketPermissionless(ticker: string, subaccount: SubaccountInfo, broadcastMode?: BroadcastMode, gasAdjustment?: number, memo?: string): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
926
+ const msg = this.launchMarketMsg(subaccount.address, ticker, subaccount.subaccountNumber);
927
+
928
+ return this.send(
929
+ subaccount.wallet,
930
+ () => Promise.resolve([msg]),
931
+ false,
932
+ undefined,
933
+ memo,
934
+ broadcastMode,
935
+ undefined,
936
+ gasAdjustment,
937
+ );
938
+ }
884
939
  }
@@ -11,7 +11,9 @@ export * as RewardsModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/
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
13
  export * as DistributionModule from '@dydxprotocol/v4-proto/src/codegen/cosmos/distribution/v1beta1/query';
14
+ export * as AffiliateModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/affiliates/query';
14
15
  export * as VaultModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/vault/query';
16
+ export * as ListingModule from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/query';
15
17
 
16
18
  export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/base/abci/v1beta1/abci';
17
19
  export * from '@dydxprotocol/v4-proto/src/codegen/cosmos/gov/v1/gov';
@@ -26,3 +28,4 @@ export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/tx';
26
28
  export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/sending/transfer';
27
29
  export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/assets/genesis';
28
30
  export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/assets/asset';
31
+ export * from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/listing/tx';