nautilus_lighter/common/consts.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Venue identifiers and tuning constants for the Lighter adapter.
17
18use std::{sync::LazyLock, time::Duration};
19
20use nautilus_model::identifiers::Venue;
21use ustr::Ustr;
22
23/// Venue name string for Lighter.
24pub const LIGHTER: &str = "LIGHTER";
25
26/// Lighter venue identifier.
27pub static LIGHTER_VENUE: LazyLock<Venue> = LazyLock::new(|| Venue::new(Ustr::from(LIGHTER)));
28
29/// L2 chain id for Lighter mainnet.
30///
31/// Mirrors the upstream `lighter-go` constant. Used as the first element of
32/// the L2 transaction hash preimage.
33pub const LIGHTER_MAINNET_CHAIN_ID: u32 = 304;
34
35/// L2 chain id for Lighter testnet.
36///
37/// Mirrors `lighter-go`'s testnet chain id and matches the value the oracle
38/// generator emits.
39pub const LIGHTER_TESTNET_CHAIN_ID: u32 = 300;
40
41/// Nautilus integrator account index on Lighter.
42pub const LIGHTER_NAUTILUS_INTEGRATOR_ACCOUNT_INDEX: u64 = 723_813;
43
44/// Venue error code for missing integrator approval.
45pub const LIGHTER_ERROR_CODE_INTEGRATOR_NOT_APPROVED: u64 = 21_149;
46
47/// Venue error code for an invalid (non-contiguous) transaction nonce.
48pub const LIGHTER_ERROR_CODE_INVALID_NONCE: i64 = 21_104;
49
50/// Venue error-code range for L2 transaction failures.
51///
52/// Observed codes follow a domain split: `20xxx` request validation, `21xxx`
53/// transaction processing (21104 invalid nonce, 21149 integrator not
54/// approved), `30xxx` WebSocket subscription state (30003 "Already
55/// Subscribed"). Bare error frames are attributed to in-flight `sendTx`
56/// requests only when the code falls in this range.
57pub const LIGHTER_ERROR_CODE_TX_RANGE: std::ops::Range<u64> = 21_000..22_000;
58
59/// Public docs anchor for integrator approval.
60pub const LIGHTER_INTEGRATOR_APPROVAL_DOCS_URL: &str =
61 "https://nautilustrader.io/docs/nightly/integrations/lighter.html#integrator-attribution";
62
63/// Maximum batch size for `sendTxBatch` on the WebSocket transport.
64pub const LIGHTER_MAX_BATCH_TX: usize = 15;
65
66/// Maximum auth-token expiry permitted by the venue (8 hours).
67pub const LIGHTER_AUTH_TOKEN_MAX_TTL: Duration = Duration::from_secs(8 * 60 * 60);
68
69/// Default refresh window before an auth token expires.
70///
71/// The adapter rotates the auth token this far ahead of expiry to avoid races
72/// during long-running WebSocket sessions.
73pub const LIGHTER_AUTH_TOKEN_REFRESH_LEAD: Duration = Duration::from_secs(15 * 60);
74
75/// Default WebSocket heartbeat interval.
76///
77/// Lighter requires a frame at least every 2 minutes; we send well below that.
78pub const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(30);
79
80/// Base reconnect backoff for the WebSocket client.
81pub const RECONNECT_BASE_BACKOFF: Duration = Duration::from_millis(250);
82
83/// Maximum reconnect backoff for the WebSocket client.
84pub const RECONNECT_MAX_BACKOFF: Duration = Duration::from_secs(30);
85
86/// Default HTTP request timeout.
87pub const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
88
89/// Maximum subscribe messages awaiting venue acknowledgement at once.
90///
91/// Held below Lighter's 50-per-IP inflight cap; see the WebSocket rate-limit
92/// strategy in [`crate::common::rate_limit`].
93pub const SUBSCRIBE_INFLIGHT_MAX: usize = 35;
94
95/// Outbound command queue depth before backpressure kicks in.
96pub const QUEUE_MAX: usize = 1000;