@dydxprotocol/v4-client-js 1.21.0 → 1.21.2
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 +4 -9
- package/build/src/clients/constants.d.ts +2 -1
- package/build/src/clients/constants.js +3 -2
- package/build/src/clients/modules/post.d.ts +2 -1
- package/build/src/clients/modules/post.js +9 -4
- package/build/src/clients/validator-client.js +2 -2
- package/build/src/lib/utils.d.ts +1 -0
- package/build/src/lib/utils.js +10 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/clients/constants.ts +5 -2
- package/src/clients/modules/post.ts +14 -3
- package/src/clients/validator-client.ts +1 -1
- package/src/lib/utils.ts +14 -0
package/package.json
CHANGED
package/src/clients/constants.ts
CHANGED
|
@@ -117,8 +117,8 @@ export const TYPE_URL_MSG_WITHDRAW_DELEGATOR_REWARD =
|
|
|
117
117
|
'/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward';
|
|
118
118
|
|
|
119
119
|
// x/accountplus
|
|
120
|
-
export const TYPE_URL_MSG_ADD_AUTHENTICATOR = '/dydxprotocol.accountplus.MsgAddAuthenticator'
|
|
121
|
-
export const TYPE_URL_MSG_REMOVE_AUTHENTICATOR = '/dydxprotocol.accountplus.MsgRemoveAuthenticator'
|
|
120
|
+
export const TYPE_URL_MSG_ADD_AUTHENTICATOR = '/dydxprotocol.accountplus.MsgAddAuthenticator';
|
|
121
|
+
export const TYPE_URL_MSG_REMOVE_AUTHENTICATOR = '/dydxprotocol.accountplus.MsgRemoveAuthenticator';
|
|
122
122
|
|
|
123
123
|
// ------------ Chain Constants ------------
|
|
124
124
|
// The following are same across different networks / deployments.
|
|
@@ -257,6 +257,7 @@ export class ValidatorConfig {
|
|
|
257
257
|
public broadcastOptions?: BroadcastOptions;
|
|
258
258
|
public defaultClientMemo?: string;
|
|
259
259
|
public useTimestampNonce?: boolean;
|
|
260
|
+
public timestampNonceOffsetMs?: number;
|
|
260
261
|
|
|
261
262
|
constructor(
|
|
262
263
|
restEndpoint: string,
|
|
@@ -265,6 +266,7 @@ export class ValidatorConfig {
|
|
|
265
266
|
broadcastOptions?: BroadcastOptions,
|
|
266
267
|
defaultClientMemo?: string,
|
|
267
268
|
useTimestampNonce?: boolean,
|
|
269
|
+
timestampNonceOffsetMs?: number,
|
|
268
270
|
) {
|
|
269
271
|
this.restEndpoint = restEndpoint?.endsWith('/') ? restEndpoint.slice(0, -1) : restEndpoint;
|
|
270
272
|
this.chainId = chainId;
|
|
@@ -273,6 +275,7 @@ export class ValidatorConfig {
|
|
|
273
275
|
this.broadcastOptions = broadcastOptions;
|
|
274
276
|
this.defaultClientMemo = defaultClientMemo;
|
|
275
277
|
this.useTimestampNonce = useTimestampNonce;
|
|
278
|
+
this.timestampNonceOffsetMs = timestampNonceOffsetMs;
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
281
|
|
|
@@ -56,6 +56,7 @@ export class Post {
|
|
|
56
56
|
public readonly defaultDydxGasPrice: GasPrice;
|
|
57
57
|
|
|
58
58
|
public useTimestampNonce: boolean = false;
|
|
59
|
+
public timestampNonceOffsetMs: number = 0;
|
|
59
60
|
private accountNumberCache: Map<string, Account> = new Map();
|
|
60
61
|
|
|
61
62
|
constructor(
|
|
@@ -64,6 +65,7 @@ export class Post {
|
|
|
64
65
|
denoms: DenomConfig,
|
|
65
66
|
defaultClientMemo?: string,
|
|
66
67
|
useTimestampNonce?: boolean,
|
|
68
|
+
timestampNonceOffsetMs?: number,
|
|
67
69
|
) {
|
|
68
70
|
this.get = get;
|
|
69
71
|
this.chainId = chainId;
|
|
@@ -81,7 +83,10 @@ export class Post {
|
|
|
81
83
|
: denoms.CHAINTOKEN_DENOM
|
|
82
84
|
}`,
|
|
83
85
|
);
|
|
84
|
-
if (useTimestampNonce === true)
|
|
86
|
+
if (useTimestampNonce === true) {
|
|
87
|
+
this.useTimestampNonce = useTimestampNonce;
|
|
88
|
+
this.timestampNonceOffsetMs = timestampNonceOffsetMs ?? this.timestampNonceOffsetMs;
|
|
89
|
+
}
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
/**
|
|
@@ -243,7 +248,9 @@ export class Post {
|
|
|
243
248
|
authenticators?: Long[],
|
|
244
249
|
): Promise<Uint8Array> {
|
|
245
250
|
// protocol expects timestamp nonce in UTC milliseconds, which is the unit returned by Date.now()
|
|
246
|
-
const sequence = this.useTimestampNonce
|
|
251
|
+
const sequence = this.useTimestampNonce
|
|
252
|
+
? Date.now() + this.timestampNonceOffsetMs
|
|
253
|
+
: account.sequence;
|
|
247
254
|
// Simulate transaction if no fee is specified.
|
|
248
255
|
const fee: StdFee = zeroFee
|
|
249
256
|
? {
|
|
@@ -956,7 +963,11 @@ export class Post {
|
|
|
956
963
|
authenticatorType: AuthenticatorType,
|
|
957
964
|
data: Uint8Array,
|
|
958
965
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
959
|
-
const msg = this.composer.composeMsgAddAuthenticator(
|
|
966
|
+
const msg = this.composer.composeMsgAddAuthenticator(
|
|
967
|
+
subaccount.address,
|
|
968
|
+
authenticatorType,
|
|
969
|
+
data,
|
|
970
|
+
);
|
|
960
971
|
|
|
961
972
|
return this.send(
|
|
962
973
|
subaccount.wallet,
|
|
@@ -69,7 +69,6 @@ export class ValidatorClient {
|
|
|
69
69
|
this._post.setSelectedGasDenom(gasDenom);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
73
72
|
/**
|
|
74
73
|
* @description populate account number cache in the Post module for performance.
|
|
75
74
|
*/
|
|
@@ -98,6 +97,7 @@ export class ValidatorClient {
|
|
|
98
97
|
this.config.denoms,
|
|
99
98
|
this.config.defaultClientMemo,
|
|
100
99
|
this.config.useTimestampNonce,
|
|
100
|
+
this.config.timestampNonceOffsetMs,
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
}
|
package/src/lib/utils.ts
CHANGED
|
@@ -60,3 +60,17 @@ export function getGovAddNewMarketTitle(ticker: string): string {
|
|
|
60
60
|
export function getGovAddNewMarketSummary(ticker: string, delayBlocks: number): string {
|
|
61
61
|
return `Add the x/prices, x/perpetuals and x/clob parameters needed for a ${ticker} perpetual market. Create the market in INITIALIZING status and transition it to ACTIVE status after ${delayBlocks} blocks.`;
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
export function calculateClockOffsetFromFetchDateHeader(
|
|
65
|
+
clientRequestStartTime: number,
|
|
66
|
+
serverReportedTime: number,
|
|
67
|
+
clientRequestEndTime: number,
|
|
68
|
+
): number {
|
|
69
|
+
// use midpoint, so assume that time for request reach server === time for response to reach us
|
|
70
|
+
const estimatedLocalTimeAtServerArrival = (clientRequestStartTime + clientRequestEndTime) / 2;
|
|
71
|
+
|
|
72
|
+
// we need an offset such that estimatedLocalTimeAtServerArrival + offset = serverReportedTime
|
|
73
|
+
const offset = serverReportedTime - estimatedLocalTimeAtServerArrival;
|
|
74
|
+
|
|
75
|
+
return Math.floor(offset);
|
|
76
|
+
}
|