Skip to main content

nautilus_lighter/signing/tx/
mod.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//! Lighter L2 transaction encoding.
17//!
18//! Each L2 transaction body is reduced to a sequence of Goldilocks field
19//! elements in a fixed order, hashed with Poseidon2 to a single `Fp5` digest,
20//! optionally aggregated with a hash of the per-tx [`L2TxAttributes`], and
21//! emitted as 40 canonical little-endian bytes. The resulting hash is what
22//! [`super::schnorr::PrivateKey::sign`] consumes; the venue's sequencer
23//! recomputes the same hash and rejects the transaction on mismatch.
24//!
25//! The wire-format `tx_info` is a JSON object with field order matching the
26//! upstream `lighter-go` `txtypes.L2*TxInfo` Go structs. The signature is
27//! base64-encoded after `s_le || e_le` byte assembly. See [`sign_tx`] for
28//! the full pipeline.
29//!
30//! Phase E covers the trading critical path: [`CreateOrderTxInfo`],
31//! [`CancelOrderTxInfo`], [`ModifyOrderTxInfo`], plus
32//! [`ApproveIntegratorTxInfo`] off the hot path. Subsequent tx types follow
33//! the same template once a use case lands.
34
35mod encode;
36mod types;
37
38pub use encode::{SignedTx, TX_HASH_BYTES, TxInfoJson, compute_tx_hash, sign_tx};
39pub use types::{
40    ApproveIntegratorTxInfo, CancelAllOrdersTxInfo, CancelOrderTxInfo, CreateOrderTxInfo,
41    L2TxAttributes, LighterTx, ModifyOrderTxInfo, OrderInfo, TxContext, UpdateLeverageTxInfo,
42};