@dydxprotocol/v4-client-js 1.6.0 → 1.7.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/CHANGELOG.md +2 -2
- package/__native__/__ios__/v4-native-client.js +33 -17
- package/build/src/clients/constants.d.ts +2 -1
- package/build/src/clients/constants.js +3 -2
- package/build/src/clients/modules/composer.js +2 -2
- package/build/src/clients/modules/post.d.ts +3 -1
- package/build/src/clients/modules/post.js +26 -11
- package/build/src/clients/validator-client.js +2 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/clients/constants.ts +3 -0
- package/src/clients/modules/composer.ts +2 -1
- package/src/clients/modules/post.ts +24 -10
- package/src/clients/validator-client.ts +1 -0
package/package.json
CHANGED
package/src/clients/constants.ts
CHANGED
|
@@ -220,6 +220,7 @@ export class ValidatorConfig {
|
|
|
220
220
|
public denoms: DenomConfig;
|
|
221
221
|
public broadcastOptions?: BroadcastOptions;
|
|
222
222
|
public defaultClientMemo?: string;
|
|
223
|
+
public useTimestampNonce?: boolean;
|
|
223
224
|
|
|
224
225
|
constructor(
|
|
225
226
|
restEndpoint: string,
|
|
@@ -227,6 +228,7 @@ export class ValidatorConfig {
|
|
|
227
228
|
denoms: DenomConfig,
|
|
228
229
|
broadcastOptions?: BroadcastOptions,
|
|
229
230
|
defaultClientMemo?: string,
|
|
231
|
+
useTimestampNonce?: boolean,
|
|
230
232
|
) {
|
|
231
233
|
this.restEndpoint = restEndpoint?.endsWith('/') ? restEndpoint.slice(0, -1) : restEndpoint;
|
|
232
234
|
this.chainId = chainId;
|
|
@@ -234,6 +236,7 @@ export class ValidatorConfig {
|
|
|
234
236
|
this.denoms = denoms;
|
|
235
237
|
this.broadcastOptions = broadcastOptions;
|
|
236
238
|
this.defaultClientMemo = defaultClientMemo;
|
|
239
|
+
this.useTimestampNonce = useTimestampNonce;
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
|
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD,
|
|
49
49
|
TYPE_URL_BATCH_CANCEL,
|
|
50
50
|
TYPE_URL_MSG_DEPOSIT_TO_MEGAVAULT,
|
|
51
|
+
TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
|
|
51
52
|
} from '../constants';
|
|
52
53
|
import { DenomConfig } from '../types';
|
|
53
54
|
import {
|
|
@@ -490,7 +491,7 @@ export class Composer {
|
|
|
490
491
|
};
|
|
491
492
|
|
|
492
493
|
return {
|
|
493
|
-
typeUrl:
|
|
494
|
+
typeUrl: TYPE_URL_MSG_WITHDRAW_FROM_MEGAVAULT,
|
|
494
495
|
value: msg,
|
|
495
496
|
};
|
|
496
497
|
}
|
|
@@ -55,9 +55,10 @@ export class Post {
|
|
|
55
55
|
public readonly defaultGasPrice: GasPrice;
|
|
56
56
|
public readonly defaultDydxGasPrice: GasPrice;
|
|
57
57
|
|
|
58
|
+
public useTimestampNonce: boolean = false;
|
|
58
59
|
private accountNumberCache: Map<string, Account> = new Map();
|
|
59
60
|
|
|
60
|
-
constructor(get: Get, chainId: string, denoms: DenomConfig, defaultClientMemo?: string) {
|
|
61
|
+
constructor(get: Get, chainId: string, denoms: DenomConfig, defaultClientMemo?: string, useTimestampNonce?: boolean) {
|
|
61
62
|
this.get = get;
|
|
62
63
|
this.chainId = chainId;
|
|
63
64
|
this.registry = generateRegistry();
|
|
@@ -74,6 +75,7 @@ export class Post {
|
|
|
74
75
|
: denoms.CHAINTOKEN_DENOM
|
|
75
76
|
}`,
|
|
76
77
|
);
|
|
78
|
+
if (useTimestampNonce === true) this.useTimestampNonce = useTimestampNonce;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
/**
|
|
@@ -113,14 +115,23 @@ export class Post {
|
|
|
113
115
|
memo?: string,
|
|
114
116
|
account?: () => Promise<Account>,
|
|
115
117
|
): Promise<StdFee> {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
let msgs: EncodeObject[];
|
|
119
|
+
// protocol expects timestamp nonce in UTC milliseconds, which is the unit returned by Date.now()
|
|
120
|
+
let sequence = Date.now();
|
|
121
|
+
|
|
122
|
+
if (this.useTimestampNonce) {
|
|
123
|
+
msgs = await messaging();
|
|
124
|
+
} else {
|
|
125
|
+
const msgsPromise = messaging();
|
|
126
|
+
const accountPromise = account ? await account() : this.account(wallet.address!);
|
|
127
|
+
const msgsAndAccount = await Promise.all([msgsPromise, accountPromise]);
|
|
128
|
+
msgs = msgsAndAccount[0];
|
|
129
|
+
sequence = msgsAndAccount[1].sequence;
|
|
130
|
+
}
|
|
120
131
|
|
|
121
132
|
return this.simulateTransaction(
|
|
122
133
|
wallet.pubKey!,
|
|
123
|
-
|
|
134
|
+
sequence,
|
|
124
135
|
msgs,
|
|
125
136
|
gasPrice,
|
|
126
137
|
memo,
|
|
@@ -225,16 +236,18 @@ export class Post {
|
|
|
225
236
|
gasPrice: GasPrice = this.getGasPrice(),
|
|
226
237
|
memo?: string,
|
|
227
238
|
): Promise<Uint8Array> {
|
|
239
|
+
// protocol expects timestamp nonce in UTC milliseconds, which is the unit returned by Date.now()
|
|
240
|
+
const sequence = this.useTimestampNonce ? Date.now() : account.sequence;
|
|
228
241
|
// Simulate transaction if no fee is specified.
|
|
229
242
|
const fee: StdFee = zeroFee
|
|
230
243
|
? {
|
|
231
244
|
amount: [],
|
|
232
245
|
gas: '1000000',
|
|
233
246
|
}
|
|
234
|
-
: await this.simulateTransaction(wallet.pubKey!,
|
|
247
|
+
: await this.simulateTransaction(wallet.pubKey!, sequence, messages, gasPrice, memo);
|
|
235
248
|
|
|
236
249
|
const txOptions: TransactionOptions = {
|
|
237
|
-
sequence
|
|
250
|
+
sequence,
|
|
238
251
|
accountNumber: account.accountNumber,
|
|
239
252
|
chainId: this.chainId,
|
|
240
253
|
};
|
|
@@ -246,11 +259,12 @@ export class Post {
|
|
|
246
259
|
* @description Retrieve an account structure for transactions.
|
|
247
260
|
* For short term orders, the sequence doesn't matter. Use cached if available.
|
|
248
261
|
* For long term and conditional orders, a round trip to validator must be made.
|
|
262
|
+
* when timestamp nonce is supported, no need to fetch account sequence number
|
|
249
263
|
*/
|
|
250
264
|
public async account(address: string, orderFlags?: OrderFlags): Promise<Account> {
|
|
251
|
-
if (orderFlags === OrderFlags.SHORT_TERM) {
|
|
265
|
+
if (orderFlags === OrderFlags.SHORT_TERM || this.useTimestampNonce) {
|
|
252
266
|
if (this.accountNumberCache.has(address)) {
|
|
253
|
-
//
|
|
267
|
+
// If order is SHORT_TERM or if timestamp nonce is enabled, the sequence doesn't matter
|
|
254
268
|
return this.accountNumberCache.get(address)!;
|
|
255
269
|
}
|
|
256
270
|
}
|