@dydxprotocol/v4-client-js 1.1.9 → 1.1.11

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.
@@ -22,7 +22,7 @@ import _ from 'lodash';
22
22
  import Long from 'long';
23
23
  import protobuf from 'protobufjs';
24
24
 
25
- import { GAS_MULTIPLIER } from '../constants';
25
+ import { GAS_MULTIPLIER, SelectedGasDenom } from '../constants';
26
26
  import { UnexpectedClientError } from '../lib/errors';
27
27
  import { generateRegistry } from '../lib/registry';
28
28
  import { SubaccountInfo } from '../subaccount';
@@ -56,6 +56,7 @@ export class Post {
56
56
  public readonly denoms: DenomConfig;
57
57
  public readonly defaultClientMemo?: string;
58
58
 
59
+ public selectedGasDenom: SelectedGasDenom = SelectedGasDenom.USDC;
59
60
  public readonly defaultGasPrice: GasPrice;
60
61
  public readonly defaultDydxGasPrice: GasPrice;
61
62
 
@@ -79,6 +80,16 @@ export class Post {
79
80
  .fromString(`25000000000${denoms.CHAINTOKEN_GAS_DENOM !== undefined ? denoms.CHAINTOKEN_GAS_DENOM : denoms.CHAINTOKEN_DENOM}`);
80
81
  }
81
82
 
83
+ setSelectedGasDenom(selectedGasDenom: SelectedGasDenom): void {
84
+ this.selectedGasDenom = selectedGasDenom;
85
+ }
86
+
87
+ getGasPrice(): GasPrice {
88
+ return this.selectedGasDenom === SelectedGasDenom.USDC
89
+ ? this.defaultGasPrice
90
+ : this.defaultDydxGasPrice;
91
+ }
92
+
82
93
  /**
83
94
  * @description Simulate a transaction
84
95
  * the calling function is responsible for creating the messages.
@@ -90,7 +101,7 @@ export class Post {
90
101
  async simulate(
91
102
  wallet: LocalWallet,
92
103
  messaging: () => Promise<EncodeObject[]>,
93
- gasPrice: GasPrice = this.defaultGasPrice,
104
+ gasPrice: GasPrice = this.getGasPrice(),
94
105
  memo?: string,
95
106
  account?: () => Promise<Account>,
96
107
  ): Promise<StdFee> {
@@ -120,7 +131,7 @@ export class Post {
120
131
  wallet: LocalWallet,
121
132
  messaging: () => Promise<EncodeObject[]>,
122
133
  zeroFee: boolean,
123
- gasPrice: GasPrice = this.defaultGasPrice,
134
+ gasPrice: GasPrice = this.getGasPrice(),
124
135
  memo?: string,
125
136
  account?: () => Promise<Account>,
126
137
  ): Promise<Uint8Array> {
@@ -143,7 +154,7 @@ export class Post {
143
154
  wallet: LocalWallet,
144
155
  messaging: () => Promise<EncodeObject[]>,
145
156
  zeroFee: boolean,
146
- gasPrice: GasPrice = this.defaultGasPrice,
157
+ gasPrice: GasPrice = this.getGasPrice(),
147
158
  memo?: string,
148
159
  broadcastMode?: BroadcastMode,
149
160
  account?: () => Promise<Account>,
@@ -202,7 +213,7 @@ export class Post {
202
213
  messages: EncodeObject[],
203
214
  account: Account,
204
215
  zeroFee: boolean,
205
- gasPrice: GasPrice = this.defaultGasPrice,
216
+ gasPrice: GasPrice = this.getGasPrice(),
206
217
  memo?: string,
207
218
  ): Promise<Uint8Array> {
208
219
  // Simulate transaction if no fee is specified.
@@ -258,7 +269,7 @@ export class Post {
258
269
  account: Account,
259
270
  messages: EncodeObject[],
260
271
  zeroFee: boolean,
261
- gasPrice: GasPrice = this.defaultGasPrice,
272
+ gasPrice: GasPrice = this.getGasPrice(),
262
273
  memo?: string,
263
274
  broadcastMode?: BroadcastMode,
264
275
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
@@ -301,7 +312,7 @@ export class Post {
301
312
  pubKey: Secp256k1Pubkey,
302
313
  sequence: number,
303
314
  messages: readonly EncodeObject[],
304
- gasPrice: GasPrice = this.defaultGasPrice,
315
+ gasPrice: GasPrice = this.getGasPrice(),
305
316
  memo?: string,
306
317
  ): Promise<StdFee> {
307
318
  // Get simulated response.
@@ -1,3 +1,4 @@
1
+ import { MAX_SUBACCOUNT_NUMBER } from './constants';
1
2
  import LocalWallet from './modules/local-wallet';
2
3
 
3
4
  export class SubaccountInfo {
@@ -6,8 +7,8 @@ export class SubaccountInfo {
6
7
  readonly subaccountNumber: number;
7
8
 
8
9
  constructor(wallet: LocalWallet, subaccountNumber: number = 0) {
9
- if (subaccountNumber < 0 || subaccountNumber > 127) {
10
- throw new Error('Subaccount number must be between 0 and 127');
10
+ if (subaccountNumber < 0 || subaccountNumber > MAX_SUBACCOUNT_NUMBER) {
11
+ throw new Error(`Subaccount number must be between 0 and ${MAX_SUBACCOUNT_NUMBER}`);
11
12
  }
12
13
  this.wallet = wallet;
13
14
  this.subaccountNumber = subaccountNumber;
@@ -3,7 +3,12 @@ import { Tendermint37Client } from '@cosmjs/tendermint-rpc';
3
3
  import Long from 'long';
4
4
  import protobuf from 'protobufjs';
5
5
 
6
- import { ValidatorConfig, BROADCAST_POLL_INTERVAL_MS, BROADCAST_TIMEOUT_MS } from './constants';
6
+ import {
7
+ ValidatorConfig,
8
+ BROADCAST_POLL_INTERVAL_MS,
9
+ BROADCAST_TIMEOUT_MS,
10
+ SelectedGasDenom,
11
+ } from './constants';
7
12
  import { Get } from './modules/get';
8
13
  import { Post } from './modules/post';
9
14
  import { TendermintClient } from './modules/tendermintClient';
@@ -55,6 +60,17 @@ export class ValidatorClient {
55
60
  return this._post!;
56
61
  }
57
62
 
63
+ get selectedGasDenom(): SelectedGasDenom | undefined {
64
+ if (!this._post) return undefined;
65
+ return this._post.selectedGasDenom;
66
+ }
67
+
68
+ setSelectedGasDenom(gasDenom: SelectedGasDenom): void {
69
+ if (!this._post) throw new Error('Post module not initialized');
70
+
71
+ this._post.setSelectedGasDenom(gasDenom);
72
+ }
73
+
58
74
  private async initialize(): Promise<void> {
59
75
  const tendermint37Client: Tendermint37Client = await Tendermint37Client.connect(
60
76
  this.config.restEndpoint,
@@ -21,7 +21,7 @@ export const ZERO_FEE: StdFee = {
21
21
 
22
22
  // Validation
23
23
  export const MAX_UINT_32 = 4_294_967_295;
24
- export const MAX_SUBACCOUNT_NUMBER = 127;
24
+ export const MAX_SUBACCOUNT_NUMBER = 128_000;
25
25
 
26
26
  export const DEFAULT_SEQUENCE: number = 0;
27
27