signet_orders/traits.rs
1#[cfg(doc)]
2use crate::Filler;
3use crate::OrdersAndFills;
4#[cfg(doc)]
5use alloy::providers::fillers::FillProvider;
6use alloy::{
7 network::{Ethereum, Network},
8 providers::{fillers::FillerControlFlow, Provider, SendableTx},
9 transports::TransportResult,
10};
11use core::future::Future;
12use futures_util::Stream;
13use signet_bundle::SignetEthBundle;
14#[cfg(doc)]
15use signet_types::SignedFill;
16use signet_types::SignedOrder;
17
18/// A trait for submitting signed orders to a backend.
19///
20/// Implementors of this trait are responsible for forwarding signed orders to a transaction cache
21/// or other order submission endpoint.
22pub trait OrderSubmitter {
23 /// The error type returned by submission operations.
24 type Error: core::error::Error + Send + Sync + 'static;
25
26 /// Submit a signed order to the backend.
27 fn submit_order(
28 &self,
29 order: SignedOrder,
30 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
31}
32
33/// A trait for fetching orders from a source.
34///
35/// Implementors of this trait provide access to signed orders, typically from a transaction cache.
36pub trait OrderSource {
37 /// The error type returned by the stream.
38 type Error: core::error::Error + Send + Sync + 'static;
39
40 /// Fetch orders from the source as a stream.
41 ///
42 /// Returns a stream of orders that automatically handles pagination. The stream yields
43 /// `Result<SignedOrder, Self::Error>` to allow for error propagation during iteration.
44 fn get_orders(&self) -> impl Stream<Item = Result<SignedOrder, Self::Error>> + Send;
45}
46
47/// A trait for submitting bundles to a backend.
48///
49/// Implementors of this trait are responsible for forwarding bundles to a transaction cache or
50/// builder endpoint.
51pub trait BundleSubmitter {
52 /// The response type returned on successful submission.
53 type Response;
54 /// The error type returned by submission operations.
55 type Error: core::error::Error + Send + Sync + 'static;
56
57 /// Submit a bundle to the backend.
58 fn submit_bundle(
59 &self,
60 bundle: SignetEthBundle,
61 ) -> impl Future<Output = Result<Self::Response, Self::Error>> + Send;
62}
63
64/// A provider that can fill transactions.
65///
66/// This trait abstracts over [`FillProvider`] to allow filling transaction requests.
67pub trait TxBuilder<N: Network = Ethereum>: Provider<N> + Send + Sync {
68 /// Fill a transaction request, returning a sendable transaction.
69 fn fill(
70 &self,
71 tx: N::TransactionRequest,
72 ) -> impl Future<Output = TransportResult<SendableTx<N>>> + Send;
73
74 /// Return the filler's status for the given transaction request.
75 fn status(&self, tx: &N::TransactionRequest) -> FillerControlFlow;
76}
77
78/// A trait for submitting signed fills to a backend.
79///
80/// Implementors handle transaction construction, gas pricing, and target block determination.
81/// This decouples the [`Filler`] from provider and fee concerns.
82pub trait FillSubmitter {
83 /// The response type returned on successful submission.
84 type Response;
85 /// The error type returned by submission operations.
86 type Error: core::error::Error + Send + Sync + 'static;
87
88 /// Submit signed fills to the backend.
89 ///
90 /// The fills map contains one [`SignedFill`] per destination chain ID.
91 fn submit_fills(
92 &self,
93 orders_and_fills: OrdersAndFills,
94 ) -> impl Future<Output = Result<Self::Response, Self::Error>> + Send;
95}