diff --git a/src/encoding/evm/approvals/permit2.rs b/src/encoding/evm/approvals/permit2.rs index c118358..37686a2 100644 --- a/src/encoding/evm/approvals/permit2.rs +++ b/src/encoding/evm/approvals/permit2.rs @@ -25,10 +25,11 @@ use crate::encoding::{ /// Struct for managing Permit2 operations, including encoding approvals and fetching allowance /// data. +#[derive(Clone)] pub struct Permit2 { address: Address, client: Arc>, - runtime: Runtime, + runtime: Arc, signer: PrivateKeySigner, chain_id: ChainId, } @@ -73,7 +74,7 @@ impl Permit2 { address: Address::from_str("0x000000000022D473030F116dDEE9F6B43aC78BA3") .map_err(|_| EncodingError::FatalError("Permit2 address not valid".to_string()))?, client, - runtime, + runtime: Arc::new(runtime), signer, chain_id: chain.id, }) diff --git a/src/encoding/evm/models.rs b/src/encoding/evm/models.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs b/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs index ba4f99e..0109aa1 100644 --- a/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs +++ b/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs @@ -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(), + } + } +} diff --git a/src/encoding/evm/strategy_encoder/strategy_encoders.rs b/src/encoding/evm/strategy_encoder/strategy_encoders.rs index af032a7..73e0f71 100644 --- a/src/encoding/evm/strategy_encoder/strategy_encoders.rs +++ b/src/encoding/evm/strategy_encoder/strategy_encoders.rs @@ -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 { + 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> { self.swap_encoder_registry .get_encoder(protocol_system) } + + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } } #[cfg(test)] diff --git a/src/encoding/evm/tycho_encoder.rs b/src/encoding/evm/tycho_encoder.rs index db80d0a..baa4f0f 100644 --- a/src/encoding/evm/tycho_encoder.rs +++ b/src/encoding/evm/tycho_encoder.rs @@ -19,6 +19,7 @@ use crate::encoding::{ /// * `router_address`: Bytes, the address of the router to use to execute the swaps. /// * `native_address`: Address of the chain's native token /// * `wrapped_address`: Address of the chain's wrapped native token +#[derive(Clone)] pub struct EVMTychoEncoder { strategy_registry: S, router_address: Bytes, @@ -183,6 +184,7 @@ mod tests { } } + #[derive(Clone)] struct MockStrategy; impl StrategyEncoder for MockStrategy { @@ -202,6 +204,9 @@ mod tests { fn get_swap_encoder(&self, _protocol_system: &str) -> Option<&Box> { None } + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } } fn get_mocked_tycho_encoder() -> EVMTychoEncoder { diff --git a/src/encoding/strategy_encoder.rs b/src/encoding/strategy_encoder.rs index cedb96c..101eaa4 100644 --- a/src/encoding/strategy_encoder.rs +++ b/src/encoding/strategy_encoder.rs @@ -16,6 +16,7 @@ pub trait StrategyEncoder { #[allow(clippy::borrowed_box)] fn get_swap_encoder(&self, protocol_system: &str) -> Option<&Box>; + fn clone_box(&self) -> Box; } /// Contains the supported strategies to encode a solution, and chooses the best strategy to encode