@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
27 lines (26 loc) • 1.22 kB
TypeScript
/**
* Nonce manager for generating unique, monotonically increasing nonces.
* @module
*/
/// <amd-module name="file:///home/runner/work/hyperliquid/hyperliquid/src/api/exchange/_methods/_base/_nonce.ts" />
/** Nonce manager interface. */
export interface NonceManager {
/** Returns a unique nonce for the given key, monotonically increasing per key. */
getNonce(key: string): number;
}
/**
* Creates a nonce manager that issues unique, monotonically increasing nonces per key.
*
* Uses `Date.now()` in ms; if the previous nonce for the key is greater than or equal to
* `Date.now()`, increments by 1 to maintain monotonicity.
*
* To bound memory under high-cardinality workloads (e.g., a server proxying many wallets),
* stale entries are pruned when the internal map grows beyond `maxEntries`. An entry is
* considered stale if `Date.now()` has advanced past its last issued nonce.
*
* @param maxEntries Upper bound on map size before stale entries are pruned. Default: `10000`.
* @return A {@linkcode NonceManager}.
*/
export declare function createNonceManager(maxEntries?: number): NonceManager;
/** Default global nonce manager instance. */
export declare const globalNonceManager: NonceManager;