nautilus_lighter/common/urls.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//! Base URL resolution for Lighter REST and WebSocket endpoints.
17
18use super::{
19 deployment,
20 enums::{LighterDeployment, LighterEnvironment},
21};
22
23/// Returns the REST base URL for the given environment.
24#[must_use]
25pub const fn lighter_http_base_url(environment: LighterEnvironment) -> &'static str {
26 deployment::http_base_url(LighterDeployment::Lighter, environment)
27}
28
29/// Returns the WebSocket URL for the given environment.
30#[must_use]
31pub const fn lighter_ws_url(environment: LighterEnvironment) -> &'static str {
32 deployment::ws_url(LighterDeployment::Lighter, environment)
33}
34
35/// Returns the L2 chain id for the given environment.
36///
37/// The chain id is the first element of every signed transaction's hash
38/// preimage and must match the value the sequencer expects, otherwise
39/// signatures verify against a different message and are rejected.
40#[must_use]
41pub const fn lighter_chain_id(environment: LighterEnvironment) -> u32 {
42 deployment::chain_id(LighterDeployment::Lighter, environment)
43}
44
45#[cfg(test)]
46mod tests {
47 use rstest::rstest;
48
49 use super::*;
50
51 #[rstest]
52 fn test_http_base_url() {
53 assert_eq!(
54 lighter_http_base_url(LighterEnvironment::Mainnet),
55 "https://mainnet.zklighter.elliot.ai",
56 );
57 assert_eq!(
58 lighter_http_base_url(LighterEnvironment::Testnet),
59 "https://testnet.zklighter.elliot.ai",
60 );
61 }
62
63 #[rstest]
64 fn test_ws_url() {
65 assert_eq!(
66 lighter_ws_url(LighterEnvironment::Mainnet),
67 "wss://mainnet.zklighter.elliot.ai/stream",
68 );
69 assert_eq!(
70 lighter_ws_url(LighterEnvironment::Testnet),
71 "wss://testnet.zklighter.elliot.ai/stream",
72 );
73 }
74
75 #[rstest]
76 fn test_chain_id() {
77 assert_eq!(lighter_chain_id(LighterEnvironment::Mainnet), 304);
78 assert_eq!(lighter_chain_id(LighterEnvironment::Testnet), 300);
79 }
80}