feat: Add clone to EVMTychoEncoder

--- don't change below this line ---
ENG-4088 Took 4 minutes

Took 8 seconds

Took 48 seconds
This commit is contained in:
Diana Carvalho
2025-02-06 11:49:11 +00:00
parent 4680a4be24
commit b333d60d69
6 changed files with 32 additions and 2 deletions

View File

@@ -58,3 +58,15 @@ impl StrategyEncoderRegistry for EVMStrategyEncoderRegistry {
}
}
}
impl Clone for EVMStrategyEncoderRegistry {
fn clone(&self) -> Self {
Self {
strategies: self
.strategies
.iter()
.map(|(k, v)| (k.clone(), v.clone_box()))
.collect(),
}
}
}

View File

@@ -73,6 +73,7 @@ pub trait EVMStrategyEncoder: StrategyEncoder {
/// * `permit2`: Permit2, responsible for managing permit2 operations and providing necessary
/// signatures and permit2 objects for calling the router
/// * `selector`: String, the selector for the swap function in the router contract
#[derive(Clone)]
pub struct SplitSwapStrategyEncoder {
swap_encoder_registry: SwapEncoderRegistry,
permit2: Permit2,
@@ -405,6 +406,10 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
self.swap_encoder_registry
.get_encoder(protocol_system)
}
fn clone_box(&self) -> Box<dyn StrategyEncoder> {
Box::new(self.clone())
}
}
/// This strategy encoder is used for solutions that are sent directly to the executor, bypassing
@@ -412,6 +417,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
///
/// # Fields
/// * `swap_encoder_registry`: SwapEncoderRegistry, containing all possible swap encoders
#[derive(Clone)]
pub struct ExecutorStrategyEncoder {
swap_encoder_registry: SwapEncoderRegistry,
}
@@ -459,10 +465,15 @@ impl StrategyEncoder for ExecutorStrategyEncoder {
.map_err(|_| EncodingError::FatalError("Invalid executor address".to_string()))?;
Ok((protocol_data, executor_address))
}
fn get_swap_encoder(&self, protocol_system: &str) -> Option<&Box<dyn SwapEncoder>> {
self.swap_encoder_registry
.get_encoder(protocol_system)
}
fn clone_box(&self) -> Box<dyn StrategyEncoder> {
Box::new(self.clone())
}
}
#[cfg(test)]