@dydxprotocol/v4-client-js 0.38.6 → 0.39.1

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.
Files changed (41) hide show
  1. package/__native__/__ios__/v4-native-client.js +76424 -47231
  2. package/build/examples/native_examples.js +3 -3
  3. package/build/examples/transfer_example_deposit.js +2 -3
  4. package/build/examples/transfer_example_send.js +5 -6
  5. package/build/examples/transfer_example_subaccount_transfer.js +2 -3
  6. package/build/examples/transfer_example_withdraw.js +2 -3
  7. package/build/examples/transfer_example_withdraw_other.js +2 -3
  8. package/build/examples/validator_post_example.js +2 -3
  9. package/build/src/clients/composite-client.d.ts +8 -8
  10. package/build/src/clients/composite-client.js +49 -13
  11. package/build/src/clients/constants.d.ts +3 -2
  12. package/build/src/clients/constants.js +25 -9
  13. package/build/src/clients/modules/composer.d.ts +1 -1
  14. package/build/src/clients/modules/composer.js +2 -6
  15. package/build/src/clients/modules/post.d.ts +6 -3
  16. package/build/src/clients/modules/post.js +22 -13
  17. package/build/src/clients/native.d.ts +2 -2
  18. package/build/src/clients/native.js +14 -6
  19. package/build/src/clients/types.d.ts +8 -0
  20. package/build/src/clients/types.js +1 -1
  21. package/build/src/clients/validator-client.js +2 -2
  22. package/build/src/lib/constants.d.ts +1 -5
  23. package/build/src/lib/constants.js +2 -10
  24. package/build/src/network_optimizer.js +7 -2
  25. package/examples/native_examples.ts +2 -2
  26. package/examples/transfer_example_deposit.ts +2 -6
  27. package/examples/transfer_example_send.ts +7 -17
  28. package/examples/transfer_example_subaccount_transfer.ts +2 -6
  29. package/examples/transfer_example_withdraw.ts +2 -6
  30. package/examples/transfer_example_withdraw_other.ts +2 -6
  31. package/examples/validator_post_example.ts +3 -6
  32. package/package.json +2 -1
  33. package/src/clients/composite-client.ts +64 -22
  34. package/src/clients/constants.ts +30 -8
  35. package/src/clients/modules/composer.ts +2 -7
  36. package/src/clients/modules/post.ts +27 -13
  37. package/src/clients/native.ts +18 -7
  38. package/src/clients/types.ts +10 -0
  39. package/src/clients/validator-client.ts +1 -1
  40. package/src/lib/constants.ts +1 -9
  41. package/src/network_optimizer.ts +6 -1
@@ -8,7 +8,7 @@ import { Order_Side, Order_TimeInForce } from '@dydxprotocol/v4-proto/src/codege
8
8
  import * as AuthModule from 'cosmjs-types/cosmos/auth/v1beta1/query';
9
9
  import Long from 'long';
10
10
 
11
- import { BECH32_PREFIX, GAS_PRICE_DYDX_DENOM, USDC_DENOM } from '../lib/constants';
11
+ import { BECH32_PREFIX } from '../lib/constants';
12
12
  import { UserError } from '../lib/errors';
13
13
  import { encodeJson } from '../lib/helpers';
14
14
  import { deriveHDKeyFromEthereumSignature } from '../lib/onboarding';
@@ -68,10 +68,23 @@ export async function connectNetwork(
68
68
  indexerUrl: string,
69
69
  indexerSocketUrl: string,
70
70
  faucetUrl?: string,
71
+ usdcDenom?: string,
72
+ usdcDecimals?: string,
73
+ usdcGasDenom?: string,
74
+ chainTokenDenom?: string,
75
+ chainTokenDecimals?: string,
76
+ chainTokenGasDenom?: string,
71
77
  ): Promise<string> {
72
78
  try {
73
79
  const indexerConfig = new IndexerConfig(indexerUrl, indexerSocketUrl);
74
- const validatorConfig = new ValidatorConfig(validatorUrl, chainId);
80
+ const validatorConfig = new ValidatorConfig(validatorUrl, chainId, {
81
+ USDC_DENOM: usdcDenom ?? 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
82
+ USDC_DECIMALS: parseInt(usdcDecimals ?? '6', 10),
83
+ USDC_GAS_DENOM: usdcGasDenom ?? 'uusdc',
84
+ CHAINTOKEN_DENOM: chainTokenDenom ?? 'adv4tnt',
85
+ CHAINTOKEN_DECIMALS: parseInt(chainTokenDecimals ?? '18', 10),
86
+ CHAINTOKEN_GAS_DENOM: chainTokenGasDenom,
87
+ });
75
88
  const config = new Network('native', indexerConfig, validatorConfig);
76
89
  globalThis.client = await CompositeClient.connect(config);
77
90
  if (faucetUrl !== undefined) {
@@ -406,7 +419,7 @@ export async function faucet(
406
419
 
407
420
  export async function withdrawToIBC(
408
421
  subaccountNumber: number,
409
- amount: number,
422
+ amount: string,
410
423
  payload: string,
411
424
  ): Promise<string> {
412
425
  try {
@@ -488,8 +501,6 @@ export async function transferNativeToken(
488
501
  return encodeObjects;
489
502
  },
490
503
  false,
491
- GAS_PRICE_DYDX_DENOM,
492
- undefined,
493
504
  );
494
505
  return encodeJson(tx);
495
506
  } catch (error) {
@@ -509,7 +520,8 @@ export async function getAccountBalance(): Promise<String> {
509
520
  }
510
521
  const address = globalThis.wallet.address!;
511
522
 
512
- const tx = await client.validatorClient.get.getAccountBalance(address, USDC_DENOM);
523
+ const tx = await client.validatorClient.get
524
+ .getAccountBalance(address, client.validatorClient.config.denoms.USDC_DENOM);
513
525
  return encodeJson(tx);
514
526
  } catch (error) {
515
527
  return wrappedError(error);
@@ -681,7 +693,6 @@ export async function simulateTransferNativeToken(
681
693
  () => {
682
694
  return encodeObjects;
683
695
  },
684
- GAS_PRICE_DYDX_DENOM,
685
696
  );
686
697
  return encodeJson(stdFee);
687
698
  } catch (error) {
@@ -61,6 +61,16 @@ export interface BroadcastOptions {
61
61
  broadcastTimeoutMs: number;
62
62
  }
63
63
 
64
+ export interface DenomConfig {
65
+ USDC_DENOM: string;
66
+ USDC_DECIMALS: number;
67
+ USDC_GAS_DENOM?: string;
68
+
69
+ CHAINTOKEN_DENOM: string;
70
+ CHAINTOKEN_DECIMALS: number;
71
+ CHAINTOKEN_GAS_DENOM?: string;
72
+ }
73
+
64
74
  // Specify when a broadcast should return:
65
75
  // 1. Immediately
66
76
  // 2. Once the transaction is added to the memPool
@@ -69,6 +69,6 @@ export class ValidatorClient {
69
69
  setupTxExtension,
70
70
  );
71
71
  this._get = new Get(tendermintClient, queryClient);
72
- this._post = new Post(this._get!, this.config.chainId);
72
+ this._post = new Post(this._get!, this.config.chainId, this.config.denoms);
73
73
  }
74
74
  }
@@ -1,4 +1,4 @@
1
- import { GasPrice, StdFee } from '@cosmjs/stargate';
1
+ import { StdFee } from '@cosmjs/stargate';
2
2
 
3
3
  // Bech32 Prefix
4
4
  export const BECH32_PREFIX = 'dydx';
@@ -10,16 +10,8 @@ export const BROADCAST_TIMEOUT_MS: number = 8_000;
10
10
  // API Defaults
11
11
  export const API_TIMEOUT_DEFAULT_MS: number = 5_000;
12
12
 
13
- // Default placeholder USDC denom (same as protocol).
14
- // Precomputed USDC IBC denom.
15
- export const USDC_DENOM = 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5';
16
- export const DYDX_DENOM = 'dv4tnt';
17
-
18
13
  // Gas
19
14
  export const GAS_MULTIPLIER: number = 1.4;
20
- // TODO(TRCL-2550): Replace 'uusdc' with IBC denom.
21
- export const GAS_PRICE: GasPrice = GasPrice.fromString('0.025uusdc');
22
- export const GAS_PRICE_DYDX_DENOM: GasPrice = GasPrice.fromString('0.025dv4tnt');
23
15
 
24
16
  export const ZERO_FEE: StdFee = {
25
17
  amount: [],
@@ -25,7 +25,12 @@ export class NetworkOptimizer {
25
25
  ): Promise<ValidatorClient[]> {
26
26
  return (await Promise.all(
27
27
  endpointUrls.map((endpointUrl) => ValidatorClient.connect(
28
- new ValidatorConfig(endpointUrl, chainId))
28
+ new ValidatorConfig(endpointUrl, chainId, {
29
+ CHAINTOKEN_DENOM: '',
30
+ CHAINTOKEN_DECIMALS: 18,
31
+ USDC_DENOM: '',
32
+ USDC_DECIMALS: 6,
33
+ }))
29
34
  .catch((_) => undefined),
30
35
  ),
31
36
  )).filter(isTruthy);