kabu_core_components/
traits.rs

1use crate::{BuilderContext, Component};
2use eyre::Result;
3use std::future::Future;
4
5/// Builder for pool/mempool components
6pub trait PoolBuilder<State>: Send {
7    /// The pool component type
8    type Pool: Component;
9
10    /// Build the pool component
11    fn build_pool(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Pool>> + Send;
12}
13
14/// Builder for network components
15pub trait NetworkBuilder<State>: Send {
16    /// The network component type
17    type Network: Component;
18
19    /// Build the network component
20    fn build_network(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Network>> + Send;
21}
22
23/// Builder for executor components
24pub trait ExecutorBuilder<State>: Send {
25    /// The executor component type
26    type Executor: Component;
27
28    /// Build the executor component
29    fn build_executor(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Executor>> + Send;
30}
31
32/// Builder for strategy components (MEV strategies like arbitrage, liquidation)
33pub trait StrategyBuilder<State>: Send {
34    /// The strategy component type
35    type Strategy: Component;
36
37    /// Build the strategy component
38    fn build_strategy(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Strategy>> + Send;
39}
40
41/// Builder for transaction signing components
42pub trait SignerBuilder<State>: Send {
43    /// The signer component type
44    type Signer: Component;
45
46    /// Build the signer component
47    fn build_signer(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Signer>> + Send;
48}
49
50/// Builder for market data components (pools, tokens, prices)
51pub trait MarketBuilder<State>: Send {
52    /// The market component type
53    type Market: Component;
54
55    /// Build the market component
56    fn build_market(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Market>> + Send;
57}
58
59/// Builder for broadcaster components (flashbots, mempool, etc.)
60pub trait BroadcasterBuilder<State>: Send {
61    /// The broadcaster component type
62    type Broadcaster: Component;
63
64    /// Build the broadcaster component
65    fn build_broadcaster(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Broadcaster>> + Send;
66}
67
68/// Builder for estimator components (gas, profit estimation)
69pub trait EstimatorBuilder<State>: Send {
70    /// The estimator component type
71    type Estimator: Component;
72
73    /// Build the estimator component
74    fn build_estimator(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Estimator>> + Send;
75}
76
77/// Builder for health monitoring components
78pub trait HealthMonitorBuilder<State>: Send {
79    /// The health monitor component type
80    type HealthMonitor: Component;
81
82    /// Build the health monitor component
83    fn build_health_monitor(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::HealthMonitor>> + Send;
84}
85
86/// Builder for consensus components (for blockchain compatibility)
87pub trait ConsensusBuilder<State>: Send {
88    /// The consensus component type
89    type Consensus: Component;
90
91    /// Build the consensus component
92    fn build_consensus(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Consensus>> + Send;
93}
94
95/// Builder for payload/block building components
96pub trait PayloadBuilder<State>: Send {
97    /// The payload builder component type
98    type PayloadBuilder: Component;
99
100    /// Build the payload builder component
101    fn build_payload(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::PayloadBuilder>> + Send;
102}
103
104/// Combined builder trait for all MEV node components
105pub trait MevNodeComponentsBuilder<State>: Send {
106    /// Pool component builder
107    type Pool: PoolBuilder<State>;
108    /// Network component builder
109    type Network: NetworkBuilder<State>;
110    /// Executor component builder
111    type Executor: ExecutorBuilder<State>;
112    /// Strategy component builder
113    type Strategy: StrategyBuilder<State>;
114    /// Signer component builder
115    type Signer: SignerBuilder<State>;
116    /// Market component builder
117    type Market: MarketBuilder<State>;
118    /// Broadcaster component builder
119    type Broadcaster: BroadcasterBuilder<State>;
120    /// Estimator component builder
121    type Estimator: EstimatorBuilder<State>;
122    /// Health monitor component builder
123    type HealthMonitor: HealthMonitorBuilder<State>;
124
125    /// Get the pool builder
126    fn pool_builder(&self) -> Self::Pool;
127    /// Get the network builder
128    fn network_builder(&self) -> Self::Network;
129    /// Get the executor builder
130    fn executor_builder(&self) -> Self::Executor;
131    /// Get the strategy builder
132    fn strategy_builder(&self) -> Self::Strategy;
133    /// Get the signer builder
134    fn signer_builder(&self) -> Self::Signer;
135    /// Get the market builder
136    fn market_builder(&self) -> Self::Market;
137    /// Get the broadcaster builder
138    fn broadcaster_builder(&self) -> Self::Broadcaster;
139    /// Get the estimator builder
140    fn estimator_builder(&self) -> Self::Estimator;
141    /// Get the health monitor builder
142    fn health_monitor_builder(&self) -> Self::HealthMonitor;
143}
144
145/// Builder for initialization components (one-shot actors that set up initial state)
146pub trait InitializerBuilder<State>: Send {
147    /// The initializer component type
148    type Initializer: Component;
149
150    /// Build the initializer component
151    fn build_initializer(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Initializer>> + Send;
152}
153
154/// Builder for merger components (combines multiple strategies or paths)
155pub trait MergerBuilder<State>: Send {
156    /// The merger component type
157    type Merger: Component;
158
159    /// Build the merger component
160    fn build_merger(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Merger>> + Send;
161}
162
163/// Builder for web server components
164pub trait WebServerBuilder<State>: Send {
165    /// The web server component type
166    type WebServer: Component;
167
168    /// Build the web server component
169    fn build_web_server(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::WebServer>> + Send;
170}
171
172/// Builder for monitoring components (influxdb, metrics)
173pub trait MonitoringBuilder<State>: Send {
174    /// The monitoring component type
175    type Monitoring: Component;
176
177    /// Build the monitoring component
178    fn build_monitoring(self, ctx: &BuilderContext<State>) -> impl Future<Output = Result<Self::Monitoring>> + Send;
179}
180
181/// Combined builder trait for basic node components (for simpler nodes)
182pub trait NodeComponentsBuilder<State>: Send {
183    /// Pool component builder
184    type Pool: PoolBuilder<State>;
185    /// Network component builder
186    type Network: NetworkBuilder<State>;
187    /// Executor component builder
188    type Executor: ExecutorBuilder<State>;
189    /// Strategy component builder
190    type Strategy: StrategyBuilder<State>;
191
192    /// Get the pool builder
193    fn pool_builder(&self) -> Self::Pool;
194    /// Get the network builder
195    fn network_builder(&self) -> Self::Network;
196    /// Get the executor builder
197    fn executor_builder(&self) -> Self::Executor;
198    /// Get the strategy builder
199    fn strategy_builder(&self) -> Self::Strategy;
200}