@dydxprotocol/v4-client-js 0.38.6 → 0.39.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/__native__/__ios__/v4-native-client.js +75 -51
- package/build/examples/transfer_example_deposit.js +2 -3
- package/build/examples/transfer_example_send.js +5 -6
- package/build/examples/transfer_example_subaccount_transfer.js +2 -3
- package/build/examples/transfer_example_withdraw.js +2 -3
- package/build/examples/transfer_example_withdraw_other.js +2 -3
- package/build/examples/validator_post_example.js +2 -3
- package/build/src/clients/composite-client.d.ts +1 -1
- package/build/src/clients/composite-client.js +11 -6
- package/build/src/clients/constants.d.ts +3 -2
- package/build/src/clients/constants.js +18 -5
- package/build/src/clients/modules/composer.js +1 -5
- package/build/src/clients/modules/post.d.ts +5 -2
- package/build/src/clients/modules/post.js +22 -13
- package/build/src/clients/native.d.ts +1 -1
- package/build/src/clients/native.js +12 -6
- package/build/src/clients/types.d.ts +6 -0
- package/build/src/clients/types.js +1 -1
- package/build/src/clients/validator-client.js +2 -2
- package/build/src/lib/constants.d.ts +1 -5
- package/build/src/lib/constants.js +2 -10
- package/build/src/network_optimizer.js +5 -2
- package/examples/transfer_example_deposit.ts +2 -6
- package/examples/transfer_example_send.ts +5 -15
- package/examples/transfer_example_subaccount_transfer.ts +2 -6
- package/examples/transfer_example_withdraw.ts +2 -6
- package/examples/transfer_example_withdraw_other.ts +2 -6
- package/examples/validator_post_example.ts +3 -6
- package/package.json +1 -1
- package/src/clients/composite-client.ts +9 -7
- package/src/clients/constants.ts +22 -4
- package/src/clients/modules/composer.ts +0 -5
- package/src/clients/modules/post.ts +26 -12
- package/src/clients/native.ts +13 -6
- package/src/clients/types.ts +8 -0
- package/src/clients/validator-client.ts +1 -1
- package/src/lib/constants.ts +1 -9
- package/src/network_optimizer.ts +4 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Long from 'long';
|
|
2
2
|
|
|
3
3
|
import { BECH32_PREFIX } from '../src';
|
|
4
|
-
import {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
-
|
|
36
|
-
|
|
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
|
@@ -10,8 +10,6 @@ import protobuf from 'protobufjs';
|
|
|
10
10
|
import { isStatefulOrder, verifyOrderFlags } from '../lib/validation';
|
|
11
11
|
import { OrderFlags } from '../types';
|
|
12
12
|
import {
|
|
13
|
-
DYDX_DENOM,
|
|
14
|
-
GAS_PRICE,
|
|
15
13
|
Network,
|
|
16
14
|
OrderExecution,
|
|
17
15
|
OrderSide,
|
|
@@ -103,7 +101,7 @@ export class CompositeClient {
|
|
|
103
101
|
wallet: LocalWallet,
|
|
104
102
|
messaging: () => Promise<EncodeObject[]>,
|
|
105
103
|
zeroFee: boolean,
|
|
106
|
-
gasPrice
|
|
104
|
+
gasPrice?: GasPrice,
|
|
107
105
|
memo?: string,
|
|
108
106
|
account?: () => Promise<Account>,
|
|
109
107
|
): Promise<Uint8Array> {
|
|
@@ -129,7 +127,7 @@ export class CompositeClient {
|
|
|
129
127
|
wallet: LocalWallet,
|
|
130
128
|
messaging: () => Promise<EncodeObject[]>,
|
|
131
129
|
zeroFee: boolean,
|
|
132
|
-
gasPrice
|
|
130
|
+
gasPrice?: GasPrice,
|
|
133
131
|
memo?: string,
|
|
134
132
|
account?: () => Promise<Account>,
|
|
135
133
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
@@ -175,7 +173,7 @@ export class CompositeClient {
|
|
|
175
173
|
async simulate(
|
|
176
174
|
wallet: LocalWallet,
|
|
177
175
|
messaging: () => Promise<EncodeObject[]>,
|
|
178
|
-
gasPrice
|
|
176
|
+
gasPrice?: GasPrice,
|
|
179
177
|
memo?: string,
|
|
180
178
|
account?: () => Promise<Account>,
|
|
181
179
|
): Promise<StdFee> {
|
|
@@ -825,7 +823,7 @@ export class CompositeClient {
|
|
|
825
823
|
}
|
|
826
824
|
|
|
827
825
|
/**
|
|
828
|
-
* @description Create message to send
|
|
826
|
+
* @description Create message to send chain token from subaccount to wallet
|
|
829
827
|
* with human readable input.
|
|
830
828
|
*
|
|
831
829
|
* @param subaccount The subaccount to withdraw from
|
|
@@ -841,11 +839,15 @@ export class CompositeClient {
|
|
|
841
839
|
amount: number,
|
|
842
840
|
recipient: string,
|
|
843
841
|
): EncodeObject {
|
|
842
|
+
const chainTokenDenom = this._validatorClient?.config.denoms.CHAINTOKEN_DENOM;
|
|
843
|
+
if (chainTokenDenom === undefined) {
|
|
844
|
+
throw new Error('Chain token denom not set in validator config');
|
|
845
|
+
}
|
|
844
846
|
const quantums: Long = Long.fromNumber(amount * (10 ** 6));
|
|
845
847
|
return this.validatorClient.post.composer.composeMsgSendToken(
|
|
846
848
|
subaccount.address,
|
|
847
849
|
recipient,
|
|
848
|
-
|
|
850
|
+
chainTokenDenom,
|
|
849
851
|
quantums,
|
|
850
852
|
);
|
|
851
853
|
}
|
package/src/clients/constants.ts
CHANGED
|
@@ -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,11 +150,13 @@ 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
162
|
if ((restEndpoint?.endsWith('/'))) {
|
|
@@ -162,6 +164,7 @@ export class ValidatorConfig {
|
|
|
162
164
|
}
|
|
163
165
|
this.restEndpoint = restEndpoint;
|
|
164
166
|
this.chainId = chainId;
|
|
167
|
+
this.denoms = denoms;
|
|
165
168
|
this.broadcastOptions = broadcastOptions;
|
|
166
169
|
}
|
|
167
170
|
}
|
|
@@ -178,7 +181,12 @@ export class Network {
|
|
|
178
181
|
IndexerApiHost.DEV,
|
|
179
182
|
IndexerWSHost.DEV,
|
|
180
183
|
);
|
|
181
|
-
const validatorConfig = new ValidatorConfig(ValidatorApiHost.DEV, DEV_CHAIN_ID
|
|
184
|
+
const validatorConfig = new ValidatorConfig(ValidatorApiHost.DEV, DEV_CHAIN_ID,
|
|
185
|
+
{
|
|
186
|
+
CHAINTOKEN_DENOM: 'adv4tnt',
|
|
187
|
+
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
|
|
188
|
+
USDC_GAS_DENOM: 'uusdc',
|
|
189
|
+
});
|
|
182
190
|
return new Network('dev', indexerConfig, validatorConfig);
|
|
183
191
|
}
|
|
184
192
|
|
|
@@ -187,7 +195,12 @@ 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
|
+
});
|
|
191
204
|
return new Network('staging', indexerConfig, validatorConfig);
|
|
192
205
|
}
|
|
193
206
|
|
|
@@ -196,7 +209,12 @@ export class Network {
|
|
|
196
209
|
IndexerApiHost.TESTNET,
|
|
197
210
|
IndexerWSHost.TESTNET,
|
|
198
211
|
);
|
|
199
|
-
const validatorConfig = new ValidatorConfig(ValidatorApiHost.TESTNET, TESTNET_CHAIN_ID
|
|
212
|
+
const validatorConfig = new ValidatorConfig(ValidatorApiHost.TESTNET, TESTNET_CHAIN_ID,
|
|
213
|
+
{
|
|
214
|
+
CHAINTOKEN_DENOM: 'adv4tnt',
|
|
215
|
+
USDC_DENOM: 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
|
|
216
|
+
USDC_GAS_DENOM: 'uusdc',
|
|
217
|
+
});
|
|
200
218
|
return new Network('testnet', indexerConfig, validatorConfig);
|
|
201
219
|
}
|
|
202
220
|
|
|
@@ -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,
|
|
@@ -200,10 +199,6 @@ export class Composer {
|
|
|
200
199
|
coinDenom: string,
|
|
201
200
|
quantums: Long,
|
|
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
204
|
amount: quantums.toString(),
|
|
@@ -22,10 +22,7 @@ import _ from 'lodash';
|
|
|
22
22
|
import Long from 'long';
|
|
23
23
|
import protobuf from 'protobufjs';
|
|
24
24
|
|
|
25
|
-
import {
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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;
|
|
@@ -542,6 +550,10 @@ export class Post {
|
|
|
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 ===
|
|
570
|
+
coinDenom === this.denoms.CHAINTOKEN_DENOM
|
|
571
|
+
? this.defaultDydxGasPrice
|
|
572
|
+
: this.defaultGasPrice,
|
|
559
573
|
undefined,
|
|
560
574
|
broadcastMode,
|
|
561
575
|
);
|
package/src/clients/native.ts
CHANGED
|
@@ -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
|
|
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,19 @@ export async function connectNetwork(
|
|
|
68
68
|
indexerUrl: string,
|
|
69
69
|
indexerSocketUrl: string,
|
|
70
70
|
faucetUrl?: string,
|
|
71
|
+
usdcDenom?: string,
|
|
72
|
+
usdcGasDenom?: string,
|
|
73
|
+
chainTokenDenom?: string,
|
|
74
|
+
chainTokenGasDenom?: string,
|
|
71
75
|
): Promise<string> {
|
|
72
76
|
try {
|
|
73
77
|
const indexerConfig = new IndexerConfig(indexerUrl, indexerSocketUrl);
|
|
74
|
-
const validatorConfig = new ValidatorConfig(validatorUrl, chainId
|
|
78
|
+
const validatorConfig = new ValidatorConfig(validatorUrl, chainId, {
|
|
79
|
+
USDC_DENOM: usdcDenom ?? 'ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5',
|
|
80
|
+
CHAINTOKEN_DENOM: chainTokenDenom ?? 'adv4tnt',
|
|
81
|
+
USDC_GAS_DENOM: usdcGasDenom ?? 'uusdc',
|
|
82
|
+
CHAINTOKEN_GAS_DENOM: chainTokenGasDenom,
|
|
83
|
+
});
|
|
75
84
|
const config = new Network('native', indexerConfig, validatorConfig);
|
|
76
85
|
globalThis.client = await CompositeClient.connect(config);
|
|
77
86
|
if (faucetUrl !== undefined) {
|
|
@@ -488,8 +497,6 @@ export async function transferNativeToken(
|
|
|
488
497
|
return encodeObjects;
|
|
489
498
|
},
|
|
490
499
|
false,
|
|
491
|
-
GAS_PRICE_DYDX_DENOM,
|
|
492
|
-
undefined,
|
|
493
500
|
);
|
|
494
501
|
return encodeJson(tx);
|
|
495
502
|
} catch (error) {
|
|
@@ -509,7 +516,8 @@ export async function getAccountBalance(): Promise<String> {
|
|
|
509
516
|
}
|
|
510
517
|
const address = globalThis.wallet.address!;
|
|
511
518
|
|
|
512
|
-
const tx = await client.validatorClient.get
|
|
519
|
+
const tx = await client.validatorClient.get
|
|
520
|
+
.getAccountBalance(address, client.validatorClient.config.denoms.USDC_DENOM);
|
|
513
521
|
return encodeJson(tx);
|
|
514
522
|
} catch (error) {
|
|
515
523
|
return wrappedError(error);
|
|
@@ -681,7 +689,6 @@ export async function simulateTransferNativeToken(
|
|
|
681
689
|
() => {
|
|
682
690
|
return encodeObjects;
|
|
683
691
|
},
|
|
684
|
-
GAS_PRICE_DYDX_DENOM,
|
|
685
692
|
);
|
|
686
693
|
return encodeJson(stdFee);
|
|
687
694
|
} catch (error) {
|
package/src/clients/types.ts
CHANGED
|
@@ -61,6 +61,14 @@ export interface BroadcastOptions {
|
|
|
61
61
|
broadcastTimeoutMs: number;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
export interface DenomConfig {
|
|
65
|
+
USDC_DENOM: string;
|
|
66
|
+
CHAINTOKEN_DENOM: string;
|
|
67
|
+
|
|
68
|
+
USDC_GAS_DENOM?: string;
|
|
69
|
+
CHAINTOKEN_GAS_DENOM?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
64
72
|
// Specify when a broadcast should return:
|
|
65
73
|
// 1. Immediately
|
|
66
74
|
// 2. Once the transaction is added to the memPool
|
package/src/lib/constants.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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: [],
|
package/src/network_optimizer.ts
CHANGED
|
@@ -25,7 +25,10 @@ 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
|
+
USDC_DENOM: '',
|
|
31
|
+
}))
|
|
29
32
|
.catch((_) => undefined),
|
|
30
33
|
),
|
|
31
34
|
)).filter(isTruthy);
|