tycho_execution/encoding/strategy_encoder.rs
1use crate::encoding::{
2 errors::EncodingError,
3 models::{EncodedSolution, Solution},
4 swap_encoder::SwapEncoder,
5};
6
7/// A trait that defines how to encode a `Solution` for execution.
8pub trait StrategyEncoder {
9 /// `encode_strategy` takes a `Solution`, which contains all the necessary information about
10 /// the swaps to be performed, and encodes it into a format that can be executed by the router
11 /// or executor contracts.
12 ///
13 /// # Arguments
14 /// * `solution` - The `Solution` to encode, containing swap details, amounts, and execution
15 /// path
16 ///
17 /// # Returns
18 /// * `Result<EncodedSwaps, EncodingError>`
19 fn encode_strategy(&self, solution: &Solution) -> Result<EncodedSolution, EncodingError>;
20
21 /// Retrieves the swap encoder for a specific protocol system.
22 ///
23 /// # Arguments
24 /// * `protocol_system` - The identifier of the protocol system (e.g., "uniswap_v2")
25 ///
26 /// # Returns
27 /// * `Option<&Box<dyn SwapEncoder>>` - The swap encoder for the protocol if available
28 #[allow(clippy::borrowed_box)]
29 fn get_swap_encoder(&self, protocol_system: &str) -> Option<&Box<dyn SwapEncoder>>;
30
31 /// Creates a cloned instance of the strategy encoder.
32 fn clone_box(&self) -> Box<dyn StrategyEncoder>;
33}