nautilus_derive/signing/modules/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//! Per-action `module_data` ABI encoders.
17//!
18//! Each Derive self-custodial action targets a dedicated module contract on
19//! the Derive Chain. The ABI-encoded module data is keccak-hashed and folded
20//! into the EIP-712 action hash assembled in [`super::eip712`].
21//!
22//! Initial scope: trade-module signing only. Withdraw / transfer / deposit /
23//! RFQ encoders land here as scope expands.
24
25pub mod trade;
26
27/// Boxed error returned by [`ModuleData::to_abi_encoded`].
28///
29/// Each per-module encoder defines its own typed error (e.g.
30/// [`trade::TradeEncodeError`]) and erases it through this alias so the
31/// trait stays type-erased without forcing every caller to enumerate
32/// every concrete module variant.
33pub type ModuleEncodeError = Box<dyn std::error::Error + Send + Sync + 'static>;
34
35/// Data encodable into a module-specific ABI payload that participates in
36/// the EIP-712 action hash.
37pub trait ModuleData {
38 /// ABI-encode this module payload using the field tuple defined in the
39 /// upstream Solidity action contract.
40 ///
41 /// # Errors
42 ///
43 /// Returns a [`ModuleEncodeError`] when the payload contains a value the
44 /// venue contract cannot accept (e.g. a negative `max_fee` for trades or
45 /// a decimal that overflows the 1e18-scaled signed/unsigned 256-bit
46 /// range).
47 fn to_abi_encoded(&self) -> Result<Vec<u8>, ModuleEncodeError>;
48}