@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
@@ -31,7 +31,7 @@ async function test(): Promise<void> {
31
31
 
32
32
  const sendTokenPayload = {
33
33
  subaccountNumber: 0,
34
- amount: 10, // Dydx Token
34
+ amount: '10', // Dydx Token
35
35
  recipient: 'dydx15ndn9c895f8ntck25qughtuck9spv2d9svw5qx',
36
36
  };
37
37
  const fees = await simulateTransferNativeToken(JSON.stringify(sendTokenPayload));
@@ -99,7 +99,7 @@ async function test(): Promise<void> {
99
99
  const encode = (str: string):string => Buffer.from(str, 'binary').toString('base64');
100
100
  const encoded = encode(squidPayload);
101
101
 
102
- tx = await withdrawToIBC(0, 13, encoded);
102
+ tx = await withdrawToIBC(0, '13', encoded);
103
103
  console.log(tx);
104
104
 
105
105
  const connected = await connectNetwork(
@@ -1,7 +1,7 @@
1
1
  import Long from 'long';
2
2
 
3
3
  import { BECH32_PREFIX } from '../src';
4
- import { STAGING_CHAIN_ID, Network, ValidatorConfig } from '../src/clients/constants';
4
+ import { Network } from '../src/clients/constants';
5
5
  import LocalWallet from '../src/clients/modules/local-wallet';
6
6
  import { Subaccount } from '../src/clients/subaccount';
7
7
  import { ValidatorClient } from '../src/clients/validator-client';
@@ -13,11 +13,7 @@ async function test(): Promise<void> {
13
13
  const wallet = await LocalWallet.fromMnemonic(DYDX_TEST_MNEMONIC, BECH32_PREFIX);
14
14
  console.log(wallet);
15
15
 
16
- const config = new ValidatorConfig(
17
- Network.staging().validatorConfig.restEndpoint,
18
- STAGING_CHAIN_ID,
19
- );
20
- const client = await ValidatorClient.connect(config);
16
+ const client = await ValidatorClient.connect(Network.staging().validatorConfig);
21
17
  console.log('**Client**');
22
18
  console.log(client);
23
19
 
@@ -4,13 +4,7 @@ import Long from 'long';
4
4
 
5
5
  import { TEST_RECIPIENT_ADDRESS } from '../__tests__/helpers/constants';
6
6
  import { BECH32_PREFIX } from '../src';
7
- import {
8
- STAGING_CHAIN_ID,
9
- Network,
10
- ValidatorConfig,
11
- DYDX_DENOM,
12
- GAS_PRICE_DYDX_DENOM,
13
- } from '../src/clients/constants';
7
+ import { Network } from '../src/clients/constants';
14
8
  import LocalWallet from '../src/clients/modules/local-wallet';
15
9
  import { Subaccount } from '../src/clients/subaccount';
16
10
  import { ValidatorClient } from '../src/clients/validator-client';
@@ -25,11 +19,7 @@ async function test(): Promise<void> {
25
19
  );
26
20
  console.log(wallet);
27
21
 
28
- const config = new ValidatorConfig(
29
- Network.staging().validatorConfig.restEndpoint,
30
- STAGING_CHAIN_ID,
31
- );
32
- const client = await ValidatorClient.connect(config);
22
+ const client = await ValidatorClient.connect(Network.staging().validatorConfig);
33
23
  console.log('**Client**');
34
24
  console.log(client);
35
25
 
@@ -41,8 +31,8 @@ async function test(): Promise<void> {
41
31
  const msg = client.post.composer.composeMsgSendToken(
42
32
  subaccount.address,
43
33
  TEST_RECIPIENT_ADDRESS,
44
- DYDX_DENOM,
45
- amount,
34
+ client.config.denoms.CHAINTOKEN_DENOM,
35
+ amount.toString(),
46
36
  );
47
37
 
48
38
  resolve([msg]);
@@ -51,7 +41,7 @@ async function test(): Promise<void> {
51
41
  const totalFee = await client.post.simulate(
52
42
  subaccount.wallet,
53
43
  () => msgs,
54
- GAS_PRICE_DYDX_DENOM,
44
+ undefined,
55
45
  undefined,
56
46
  );
57
47
  console.log('**Total Fee**');
@@ -64,8 +54,8 @@ async function test(): Promise<void> {
64
54
  const tx = await client.post.sendToken(
65
55
  subaccount,
66
56
  TEST_RECIPIENT_ADDRESS,
67
- DYDX_DENOM,
68
- amountAfterFee,
57
+ client.config.denoms.CHAINTOKEN_DENOM,
58
+ amountAfterFee.toString(),
69
59
  false,
70
60
  Method.BroadcastTxCommit,
71
61
  );
@@ -1,7 +1,7 @@
1
1
  import Long from 'long';
2
2
 
3
3
  import { BECH32_PREFIX } from '../src';
4
- import { STAGING_CHAIN_ID, Network, ValidatorConfig } from '../src/clients/constants';
4
+ import { Network } from '../src/clients/constants';
5
5
  import LocalWallet from '../src/clients/modules/local-wallet';
6
6
  import { Subaccount } from '../src/clients/subaccount';
7
7
  import { ValidatorClient } from '../src/clients/validator-client';
@@ -13,11 +13,7 @@ async function test(): Promise<void> {
13
13
  const wallet = await LocalWallet.fromMnemonic(DYDX_TEST_MNEMONIC, BECH32_PREFIX);
14
14
  console.log(wallet);
15
15
 
16
- const config = new ValidatorConfig(
17
- Network.staging().validatorConfig.restEndpoint,
18
- STAGING_CHAIN_ID,
19
- );
20
- const client = await ValidatorClient.connect(config);
16
+ const client = await ValidatorClient.connect(Network.staging().validatorConfig);
21
17
  console.log('**Client**');
22
18
  console.log(client);
23
19
 
@@ -1,7 +1,7 @@
1
1
  import Long from 'long';
2
2
 
3
3
  import { BECH32_PREFIX } from '../src';
4
- import { STAGING_CHAIN_ID, Network, ValidatorConfig } from '../src/clients/constants';
4
+ import { Network } from '../src/clients/constants';
5
5
  import LocalWallet from '../src/clients/modules/local-wallet';
6
6
  import { Subaccount } from '../src/clients/subaccount';
7
7
  import { ValidatorClient } from '../src/clients/validator-client';
@@ -13,11 +13,7 @@ async function test(): Promise<void> {
13
13
  const wallet = await LocalWallet.fromMnemonic(DYDX_TEST_MNEMONIC, BECH32_PREFIX);
14
14
  console.log(wallet);
15
15
 
16
- const config = new ValidatorConfig(
17
- Network.staging().validatorConfig.restEndpoint,
18
- STAGING_CHAIN_ID,
19
- );
20
- const client = await ValidatorClient.connect(config);
16
+ const client = await ValidatorClient.connect(Network.staging().validatorConfig);
21
17
  console.log('**Client**');
22
18
  console.log(client);
23
19
 
@@ -4,7 +4,7 @@ import Long from 'long';
4
4
 
5
5
  import { TEST_RECIPIENT_ADDRESS } from '../__tests__/helpers/constants';
6
6
  import { BECH32_PREFIX } from '../src';
7
- import { STAGING_CHAIN_ID, Network, ValidatorConfig } from '../src/clients/constants';
7
+ import { Network } from '../src/clients/constants';
8
8
  import LocalWallet from '../src/clients/modules/local-wallet';
9
9
  import { Subaccount } from '../src/clients/subaccount';
10
10
  import { ValidatorClient } from '../src/clients/validator-client';
@@ -16,11 +16,7 @@ async function test(): Promise<void> {
16
16
  const wallet = await LocalWallet.fromMnemonic(DYDX_TEST_MNEMONIC, BECH32_PREFIX);
17
17
  console.log(wallet);
18
18
 
19
- const config = new ValidatorConfig(
20
- Network.staging().validatorConfig.restEndpoint,
21
- STAGING_CHAIN_ID,
22
- );
23
- const client = await ValidatorClient.connect(config);
19
+ const client = await ValidatorClient.connect(Network.staging().validatorConfig);
24
20
  console.log('**Client**');
25
21
  console.log(client);
26
22
 
@@ -2,7 +2,7 @@ import Long from 'long';
2
2
  import protobuf from 'protobufjs';
3
3
 
4
4
  import { BECH32_PREFIX } from '../src';
5
- import { STAGING_CHAIN_ID, Network, ValidatorConfig } from '../src/clients/constants';
5
+ import { Network } from '../src/clients/constants';
6
6
  import LocalWallet from '../src/clients/modules/local-wallet';
7
7
  import { Subaccount } from '../src/clients/subaccount';
8
8
  import { IPlaceOrder } from '../src/clients/types';
@@ -32,11 +32,8 @@ async function sleep(ms: number): Promise<void> {
32
32
  async function test(): Promise<void> {
33
33
  const wallet = await LocalWallet.fromMnemonic(DYDX_TEST_MNEMONIC, BECH32_PREFIX);
34
34
  console.log(wallet);
35
- const config = new ValidatorConfig(
36
- Network.staging().validatorConfig.restEndpoint,
37
- STAGING_CHAIN_ID,
38
- );
39
- const client = await ValidatorClient.connect(config);
35
+
36
+ const client = await ValidatorClient.connect(Network.staging().validatorConfig);
40
37
  console.log('**Client**');
41
38
  console.log(client);
42
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dydxprotocol/v4-client-js",
3
- "version": "0.38.6",
3
+ "version": "0.39.1",
4
4
  "description": "General client library for the new dYdX system (v4 decentralized)",
5
5
  "main": "build/src/index.js",
6
6
  "scripts": {
@@ -44,6 +44,7 @@
44
44
  "bech32": "^1.1.4",
45
45
  "bignumber.js": "^9.1.1",
46
46
  "ethereum-cryptography": "^2.0.0",
47
+ "ethers": "^6.6.1",
47
48
  "long": "^4.0.0",
48
49
  "protobufjs": ">=6.11.4",
49
50
  "ws": "^8.13.0"
@@ -4,14 +4,13 @@ import {
4
4
  } from '@cosmjs/stargate';
5
5
  import { BroadcastTxAsyncResponse, BroadcastTxSyncResponse } from '@cosmjs/tendermint-rpc/build/tendermint37';
6
6
  import { Order_ConditionType, Order_TimeInForce } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order';
7
+ import { parseUnits } from 'ethers';
7
8
  import Long from 'long';
8
9
  import protobuf from 'protobufjs';
9
10
 
10
11
  import { isStatefulOrder, verifyOrderFlags } from '../lib/validation';
11
12
  import { OrderFlags } from '../types';
12
13
  import {
13
- DYDX_DENOM,
14
- GAS_PRICE,
15
14
  Network,
16
15
  OrderExecution,
17
16
  OrderSide,
@@ -103,7 +102,7 @@ export class CompositeClient {
103
102
  wallet: LocalWallet,
104
103
  messaging: () => Promise<EncodeObject[]>,
105
104
  zeroFee: boolean,
106
- gasPrice: GasPrice = GAS_PRICE,
105
+ gasPrice?: GasPrice,
107
106
  memo?: string,
108
107
  account?: () => Promise<Account>,
109
108
  ): Promise<Uint8Array> {
@@ -129,7 +128,7 @@ export class CompositeClient {
129
128
  wallet: LocalWallet,
130
129
  messaging: () => Promise<EncodeObject[]>,
131
130
  zeroFee: boolean,
132
- gasPrice: GasPrice = GAS_PRICE,
131
+ gasPrice?: GasPrice,
133
132
  memo?: string,
134
133
  account?: () => Promise<Account>,
135
134
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
@@ -175,7 +174,7 @@ export class CompositeClient {
175
174
  async simulate(
176
175
  wallet: LocalWallet,
177
176
  messaging: () => Promise<EncodeObject[]>,
178
- gasPrice: GasPrice = GAS_PRICE,
177
+ gasPrice?: GasPrice,
179
178
  memo?: string,
180
179
  account?: () => Promise<Account>,
181
180
  ): Promise<StdFee> {
@@ -671,7 +670,7 @@ export class CompositeClient {
671
670
  subaccount: Subaccount,
672
671
  recipientAddress: string,
673
672
  recipientSubaccountNumber: number,
674
- amount: number,
673
+ amount: string,
675
674
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
676
675
  const msgs: Promise<EncodeObject[]> = new Promise((resolve) => {
677
676
  const msg = this.transferToSubaccountMessage(
@@ -705,16 +704,27 @@ export class CompositeClient {
705
704
  subaccount: Subaccount,
706
705
  recipientAddress: string,
707
706
  recipientSubaccountNumber: number,
708
- amount: number,
707
+ amount: string,
709
708
  ): EncodeObject {
710
- const quantums: Long = Long.fromNumber(amount * (10 ** 6));
709
+ const validatorClient = this._validatorClient;
710
+ if (validatorClient === undefined) {
711
+ throw new Error('validatorClient not set');
712
+ }
713
+ const quantums = parseUnits(amount, validatorClient.config.denoms.USDC_DECIMALS);
714
+ if (quantums > BigInt(Long.MAX_VALUE.toString())) {
715
+ throw new Error('amount to large');
716
+ }
717
+ if (quantums < 0) {
718
+ throw new Error('amount must be positive');
719
+ }
720
+
711
721
  return this.validatorClient.post.composer.composeMsgTransfer(
712
722
  subaccount.address,
713
723
  subaccount.subaccountNumber,
714
724
  recipientAddress,
715
725
  recipientSubaccountNumber,
716
726
  0,
717
- quantums,
727
+ Long.fromString(quantums.toString()),
718
728
  );
719
729
  }
720
730
 
@@ -730,7 +740,7 @@ export class CompositeClient {
730
740
  */
731
741
  async depositToSubaccount(
732
742
  subaccount: Subaccount,
733
- amount: number,
743
+ amount: string,
734
744
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
735
745
  const msgs: Promise<EncodeObject[]> = new Promise((resolve) => {
736
746
  const msg = this.depositToSubaccountMessage(
@@ -756,14 +766,25 @@ export class CompositeClient {
756
766
  */
757
767
  depositToSubaccountMessage(
758
768
  subaccount: Subaccount,
759
- amount: number,
769
+ amount: string,
760
770
  ): EncodeObject {
761
- const quantums: Long = Long.fromNumber(amount * (10 ** 6));
771
+ const validatorClient = this._validatorClient;
772
+ if (validatorClient === undefined) {
773
+ throw new Error('validatorClient not set');
774
+ }
775
+ const quantums = parseUnits(amount, validatorClient.config.denoms.USDC_DECIMALS);
776
+ if (quantums > BigInt(Long.MAX_VALUE.toString())) {
777
+ throw new Error('amount to large');
778
+ }
779
+ if (quantums < 0) {
780
+ throw new Error('amount must be positive');
781
+ }
782
+
762
783
  return this.validatorClient.post.composer.composeMsgDepositToSubaccount(
763
784
  subaccount.address,
764
785
  subaccount.subaccountNumber,
765
786
  0,
766
- quantums,
787
+ Long.fromString(quantums.toString()),
767
788
  );
768
789
  }
769
790
 
@@ -780,7 +801,7 @@ export class CompositeClient {
780
801
  */
781
802
  async withdrawFromSubaccount(
782
803
  subaccount: Subaccount,
783
- amount: number,
804
+ amount: string,
784
805
  recipient?: string,
785
806
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
786
807
  const msgs: Promise<EncodeObject[]> = new Promise((resolve) => {
@@ -811,21 +832,32 @@ export class CompositeClient {
811
832
  */
812
833
  withdrawFromSubaccountMessage(
813
834
  subaccount: Subaccount,
814
- amount: number,
835
+ amount: string,
815
836
  recipient?: string,
816
837
  ): EncodeObject {
817
- const quantums: Long = Long.fromNumber(amount * (10 ** 6));
838
+ const validatorClient = this._validatorClient;
839
+ if (validatorClient === undefined) {
840
+ throw new Error('validatorClient not set');
841
+ }
842
+ const quantums = parseUnits(amount, validatorClient.config.denoms.USDC_DECIMALS);
843
+ if (quantums > BigInt(Long.MAX_VALUE.toString())) {
844
+ throw new Error('amount to large');
845
+ }
846
+ if (quantums < 0) {
847
+ throw new Error('amount must be positive');
848
+ }
849
+
818
850
  return this.validatorClient.post.composer.composeMsgWithdrawFromSubaccount(
819
851
  subaccount.address,
820
852
  subaccount.subaccountNumber,
821
853
  0,
822
- quantums,
854
+ Long.fromString(quantums.toString()),
823
855
  recipient,
824
856
  );
825
857
  }
826
858
 
827
859
  /**
828
- * @description Create message to send dydx token from subaccount to wallet
860
+ * @description Create message to send chain token from subaccount to wallet
829
861
  * with human readable input.
830
862
  *
831
863
  * @param subaccount The subaccount to withdraw from
@@ -838,15 +870,25 @@ export class CompositeClient {
838
870
  */
839
871
  sendTokenMessage(
840
872
  subaccount: Subaccount,
841
- amount: number,
873
+ amount: string,
842
874
  recipient: string,
843
875
  ): EncodeObject {
844
- const quantums: Long = Long.fromNumber(amount * (10 ** 6));
876
+ const {
877
+ CHAINTOKEN_DENOM: chainTokenDenom,
878
+ CHAINTOKEN_DECIMALS: chainTokenDecimals,
879
+ } = this._validatorClient?.config.denoms || {};
880
+
881
+ if (chainTokenDenom === undefined || chainTokenDecimals === undefined) {
882
+ throw new Error('Chain token denom not set in validator config');
883
+ }
884
+
885
+ const quantums = parseUnits(amount, chainTokenDecimals);
886
+
845
887
  return this.validatorClient.post.composer.composeMsgSendToken(
846
888
  subaccount.address,
847
889
  recipient,
848
- DYDX_DENOM,
849
- quantums,
890
+ chainTokenDenom,
891
+ quantums.toString(),
850
892
  );
851
893
  }
852
894
 
@@ -1,7 +1,7 @@
1
1
  import { PageRequest } from '@dydxprotocol/v4-proto/src/codegen/cosmos/base/query/v1beta1/pagination';
2
2
  import Long from 'long';
3
3
 
4
- import { BroadcastOptions } from './types';
4
+ import { BroadcastOptions, DenomConfig } from './types';
5
5
 
6
6
  export * from '../lib/constants';
7
7
 
@@ -150,18 +150,19 @@ export class IndexerConfig {
150
150
  export class ValidatorConfig {
151
151
  public restEndpoint: string;
152
152
  public chainId: string;
153
+ public denoms: DenomConfig;
153
154
  public broadcastOptions?: BroadcastOptions;
154
155
 
155
156
  constructor(
156
157
  restEndpoint: string,
157
158
  chainId: string,
159
+ denoms: DenomConfig,
158
160
  broadcastOptions?: BroadcastOptions,
159
161
  ) {
160
- if ((restEndpoint?.endsWith('/'))) {
161
- this.restEndpoint = restEndpoint.slice(0, -1);
162
- }
163
- this.restEndpoint = restEndpoint;
162
+ this.restEndpoint = restEndpoint?.endsWith('/') ? restEndpoint.slice(0, -1) : restEndpoint;
164
163
  this.chainId = chainId;
164
+
165
+ this.denoms = denoms;
165
166
  this.broadcastOptions = broadcastOptions;
166
167
  }
167
168
  }
@@ -178,7 +179,14 @@ export class Network {
178
179
  IndexerApiHost.DEV,
179
180
  IndexerWSHost.DEV,
180
181
  );
181
- const validatorConfig = new ValidatorConfig(ValidatorApiHost.DEV, DEV_CHAIN_ID);
182
+ const validatorConfig = new ValidatorConfig(ValidatorApiHost.DEV, DEV_CHAIN_ID,
183
+ {
184
+ CHAINTOKEN_DENOM: 'adv4tnt',
185
+ USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
186
+ USDC_GAS_DENOM: 'uusdc',
187
+ USDC_DECIMALS: 6,
188
+ CHAINTOKEN_DECIMALS: 18,
189
+ });
182
190
  return new Network('dev', indexerConfig, validatorConfig);
183
191
  }
184
192
 
@@ -187,7 +195,14 @@ export class Network {
187
195
  IndexerApiHost.STAGING,
188
196
  IndexerWSHost.STAGING,
189
197
  );
190
- const validatorConfig = new ValidatorConfig(ValidatorApiHost.STAGING, STAGING_CHAIN_ID);
198
+ const validatorConfig = new ValidatorConfig(ValidatorApiHost.STAGING, STAGING_CHAIN_ID,
199
+ {
200
+ CHAINTOKEN_DENOM: 'adv4tnt',
201
+ USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
202
+ USDC_GAS_DENOM: 'uusdc',
203
+ USDC_DECIMALS: 6,
204
+ CHAINTOKEN_DECIMALS: 18,
205
+ });
191
206
  return new Network('staging', indexerConfig, validatorConfig);
192
207
  }
193
208
 
@@ -196,7 +211,14 @@ export class Network {
196
211
  IndexerApiHost.TESTNET,
197
212
  IndexerWSHost.TESTNET,
198
213
  );
199
- const validatorConfig = new ValidatorConfig(ValidatorApiHost.TESTNET, TESTNET_CHAIN_ID);
214
+ const validatorConfig = new ValidatorConfig(ValidatorApiHost.TESTNET, TESTNET_CHAIN_ID,
215
+ {
216
+ CHAINTOKEN_DENOM: 'adv4tnt',
217
+ USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
218
+ USDC_GAS_DENOM: 'uusdc',
219
+ USDC_DECIMALS: 6,
220
+ CHAINTOKEN_DECIMALS: 18,
221
+ });
200
222
  return new Network('testnet', indexerConfig, validatorConfig);
201
223
  }
202
224
 
@@ -4,7 +4,6 @@ import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin';
4
4
  import Long from 'long';
5
5
  import protobuf from 'protobufjs';
6
6
 
7
- import { USDC_DENOM, DYDX_DENOM } from '../../lib/constants';
8
7
  import {
9
8
  OrderId,
10
9
  Order,
@@ -198,15 +197,11 @@ export class Composer {
198
197
  address: string,
199
198
  recipient: string,
200
199
  coinDenom: string,
201
- quantums: Long,
200
+ quantums: string,
202
201
  ): EncodeObject {
203
- if (coinDenom !== USDC_DENOM && coinDenom !== DYDX_DENOM) {
204
- throw new Error('Unsupported coinDenom');
205
- }
206
-
207
202
  const coin: Coin = {
208
203
  denom: coinDenom,
209
- amount: quantums.toString(),
204
+ amount: quantums,
210
205
  };
211
206
 
212
207
  const msg: MsgSend = {
@@ -22,10 +22,7 @@ import _ from 'lodash';
22
22
  import Long from 'long';
23
23
  import protobuf from 'protobufjs';
24
24
 
25
- import { DYDX_DENOM, GAS_PRICE_DYDX_DENOM, USDC_DENOM } from '../../lib/constants';
26
- import {
27
- GAS_MULTIPLIER, GAS_PRICE,
28
- } from '../constants';
25
+ import { GAS_MULTIPLIER } from '../constants';
29
26
  import { UnexpectedClientError } from '../lib/errors';
30
27
  import { generateRegistry } from '../lib/registry';
31
28
  import { Subaccount } from '../subaccount';
@@ -35,6 +32,7 @@ import {
35
32
  TransactionOptions,
36
33
  IPlaceOrder,
37
34
  ICancelOrder,
35
+ DenomConfig,
38
36
  } from '../types';
39
37
  import { Composer } from './composer';
40
38
  import { Get } from './get';
@@ -55,17 +53,27 @@ export class Post {
55
53
  private readonly registry: Registry;
56
54
  private readonly chainId: string;
57
55
  public readonly get: Get;
56
+ public readonly denoms: DenomConfig;
57
+
58
+ private readonly defaultGasPrice: GasPrice;
59
+ private readonly defaultDydxGasPrice: GasPrice;
58
60
 
59
61
  private accountNumberCache: Map<string, Account> = new Map();
60
62
 
61
63
  constructor(
62
64
  get: Get,
63
65
  chainId: string,
66
+ denoms: DenomConfig,
64
67
  ) {
65
68
  this.get = get;
66
69
  this.chainId = chainId;
67
70
  this.registry = generateRegistry();
68
71
  this.composer = new Composer();
72
+ this.denoms = denoms;
73
+ this.defaultGasPrice = GasPrice
74
+ .fromString(`0.025${denoms.USDC_GAS_DENOM !== undefined ? denoms.USDC_GAS_DENOM : denoms.USDC_DENOM}`);
75
+ this.defaultDydxGasPrice = GasPrice
76
+ .fromString(`25000000000${denoms.CHAINTOKEN_GAS_DENOM !== undefined ? denoms.CHAINTOKEN_GAS_DENOM : denoms.CHAINTOKEN_DENOM}`);
69
77
  }
70
78
 
71
79
  /**
@@ -79,7 +87,7 @@ export class Post {
79
87
  async simulate(
80
88
  wallet: LocalWallet,
81
89
  messaging: () => Promise<EncodeObject[]>,
82
- gasPrice: GasPrice = GAS_PRICE,
90
+ gasPrice: GasPrice = this.defaultGasPrice,
83
91
  memo?: string,
84
92
  account?: () => Promise<Account>,
85
93
  ): Promise<StdFee> {
@@ -109,7 +117,7 @@ export class Post {
109
117
  wallet: LocalWallet,
110
118
  messaging: () => Promise<EncodeObject[]>,
111
119
  zeroFee: boolean,
112
- gasPrice: GasPrice = GAS_PRICE,
120
+ gasPrice: GasPrice = this.defaultGasPrice,
113
121
  memo?: string,
114
122
  account?: () => Promise<Account>,
115
123
  ): Promise<Uint8Array> {
@@ -132,7 +140,7 @@ export class Post {
132
140
  wallet: LocalWallet,
133
141
  messaging: () => Promise<EncodeObject[]>,
134
142
  zeroFee: boolean,
135
- gasPrice: GasPrice = GAS_PRICE,
143
+ gasPrice: GasPrice = this.defaultGasPrice,
136
144
  memo?: string,
137
145
  broadcastMode?: BroadcastMode,
138
146
  account?: () => Promise<Account>,
@@ -184,7 +192,7 @@ export class Post {
184
192
  messages: EncodeObject[],
185
193
  account: Account,
186
194
  zeroFee: boolean,
187
- gasPrice: GasPrice = GAS_PRICE,
195
+ gasPrice: GasPrice = this.defaultGasPrice,
188
196
  memo?: string,
189
197
  ): Promise<Uint8Array> {
190
198
  // Simulate transaction if no fee is specified.
@@ -240,7 +248,7 @@ export class Post {
240
248
  account: Account,
241
249
  messages: EncodeObject[],
242
250
  zeroFee: boolean,
243
- gasPrice: GasPrice = GAS_PRICE,
251
+ gasPrice: GasPrice = this.defaultGasPrice,
244
252
  memo?: string,
245
253
  broadcastMode?: BroadcastMode,
246
254
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
@@ -283,7 +291,7 @@ export class Post {
283
291
  pubKey: Secp256k1Pubkey,
284
292
  sequence: number,
285
293
  messages: readonly EncodeObject[],
286
- gasPrice: GasPrice = GAS_PRICE,
294
+ gasPrice: GasPrice = this.defaultGasPrice,
287
295
  memo?: string,
288
296
  ): Promise<StdFee> {
289
297
  // Get simulated response.
@@ -320,7 +328,7 @@ export class Post {
320
328
  if (coin.denom === 'uusdc') {
321
329
  return {
322
330
  amount: coin.amount,
323
- denom: USDC_DENOM,
331
+ denom: this.denoms.USDC_DENOM,
324
332
  };
325
333
  }
326
334
  return coin;
@@ -538,10 +546,14 @@ export class Post {
538
546
  subaccount: Subaccount,
539
547
  recipient: string,
540
548
  coinDenom: string,
541
- quantums: Long,
549
+ quantums: string,
542
550
  zeroFee: boolean = true,
543
551
  broadcastMode?: BroadcastMode,
544
552
  ): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
553
+ if (coinDenom !== this.denoms.CHAINTOKEN_DENOM && coinDenom !== this.denoms.USDC_DENOM) {
554
+ throw new Error('Unsupported coinDenom');
555
+ }
556
+
545
557
  const msgs: Promise<EncodeObject[]> = new Promise((resolve) => {
546
558
  const msg = this.composer.composeMsgSendToken(
547
559
  subaccount.address,
@@ -555,7 +567,9 @@ export class Post {
555
567
  subaccount.wallet,
556
568
  () => msgs,
557
569
  zeroFee,
558
- coinDenom === DYDX_DENOM ? GAS_PRICE_DYDX_DENOM : GAS_PRICE,
570
+ coinDenom === this.denoms.CHAINTOKEN_DENOM
571
+ ? this.defaultDydxGasPrice
572
+ : this.defaultGasPrice,
559
573
  undefined,
560
574
  broadcastMode,
561
575
  );