From 4680a4be2429ab90bcb440fb1f57105f4f244360 Mon Sep 17 00:00:00 2001 From: Diana Carvalho Date: Thu, 6 Feb 2025 10:48:58 +0000 Subject: [PATCH] feat: Make executors_file_path optional and use a default value if None --- don't change below this line --- ENG-4088 Took 4 minutes Took 59 seconds --- examples/quickstart/main.rs | 3 +-- src/encoding/evm/constants.rs | 1 + .../evm/strategy_encoder/strategy_encoder_registry.rs | 8 ++++++-- src/encoding/evm/tycho_encoder.rs | 4 ++-- src/encoding/strategy_encoder.rs | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 src/encoding/evm/constants.rs diff --git a/examples/quickstart/main.rs b/examples/quickstart/main.rs index f63cd19..77a18c9 100644 --- a/examples/quickstart/main.rs +++ b/examples/quickstart/main.rs @@ -22,12 +22,11 @@ fn main() { Some("0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234".to_string()); let user_address = Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2") .expect("Failed to create user address"); - let executors_file_path = "src/encoding/config/executor_addresses.json"; let eth_chain = Chain::from(TychoCoreChain::Ethereum); // Initialize the encoder let strategy_encoder_registry = - EVMStrategyEncoderRegistry::new(eth_chain.clone(), executors_file_path, signer_pk.clone()) + EVMStrategyEncoderRegistry::new(eth_chain.clone(), None, signer_pk.clone()) .expect("Failed to create strategy encoder registry"); let encoder = EVMTychoEncoder::new(strategy_encoder_registry, router_address, eth_chain) .expect("Failed to create encoder"); diff --git a/src/encoding/evm/constants.rs b/src/encoding/evm/constants.rs new file mode 100644 index 0000000..177b7d9 --- /dev/null +++ b/src/encoding/evm/constants.rs @@ -0,0 +1 @@ +pub const DEFAULT_EXECUTORS_FILE_PATH: &str = "src/encoding/config/executor_addresses.json"; diff --git a/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs b/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs index 8ca10ce..ba4f99e 100644 --- a/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs +++ b/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use crate::encoding::{ errors::EncodingError, evm::{ + constants::DEFAULT_EXECUTORS_FILE_PATH, strategy_encoder::strategy_encoders::{ExecutorStrategyEncoder, SplitSwapStrategyEncoder}, swap_encoder::swap_encoder_registry::SwapEncoderRegistry, }, @@ -22,10 +23,13 @@ pub struct EVMStrategyEncoderRegistry { impl StrategyEncoderRegistry for EVMStrategyEncoderRegistry { fn new( chain: Chain, - executors_file_path: &str, + executors_file_path: Option<&str>, signer_pk: Option, ) -> Result { - let swap_encoder_registry = SwapEncoderRegistry::new(executors_file_path, chain.clone())?; + let swap_encoder_registry = SwapEncoderRegistry::new( + executors_file_path.unwrap_or(DEFAULT_EXECUTORS_FILE_PATH), + chain.clone(), + )?; let mut strategies: HashMap> = HashMap::new(); strategies.insert( diff --git a/src/encoding/evm/tycho_encoder.rs b/src/encoding/evm/tycho_encoder.rs index a022d18..db80d0a 100644 --- a/src/encoding/evm/tycho_encoder.rs +++ b/src/encoding/evm/tycho_encoder.rs @@ -169,7 +169,7 @@ mod tests { impl StrategyEncoderRegistry for MockStrategyRegistry { fn new( _chain: Chain, - _executors_file_path: &str, + _executors_file_path: Option<&str>, _signer_pk: Option, ) -> Result { Ok(Self { strategy: Box::new(MockStrategy) }) @@ -205,7 +205,7 @@ mod tests { } fn get_mocked_tycho_encoder() -> EVMTychoEncoder { - let strategy_registry = MockStrategyRegistry::new(eth_chain(), "", None).unwrap(); + let strategy_registry = MockStrategyRegistry::new(eth_chain(), None, None).unwrap(); EVMTychoEncoder::new( strategy_registry, "0x1234567890abcdef1234567890abcdef12345678".to_string(), diff --git a/src/encoding/strategy_encoder.rs b/src/encoding/strategy_encoder.rs index bb7ecf4..cedb96c 100644 --- a/src/encoding/strategy_encoder.rs +++ b/src/encoding/strategy_encoder.rs @@ -23,7 +23,7 @@ pub trait StrategyEncoder { pub trait StrategyEncoderRegistry { fn new( chain: Chain, - executors_file_path: &str, + executors_file_path: Option<&str>, signer_pk: Option, ) -> Result where