diff --git a/src/bin/tycho-encode.rs b/src/bin/tycho-encode.rs index 8a619a6..c613cc5 100644 --- a/src/bin/tycho-encode.rs +++ b/src/bin/tycho-encode.rs @@ -8,7 +8,7 @@ use hex; use num_bigint::BigUint; use serde_json::Value; use tycho_core::{ - dto::{Chain as DtoChain, ProtocolComponent}, + dto::{Chain, ProtocolComponent}, Bytes, }; use tycho_execution::encoding::{ @@ -22,6 +22,7 @@ use tycho_execution::encoding::{ }; const DEFAULT_ROUTER_ADDRESS: &str = "0x1234567890123456789012345678901234567890"; +const DEFAULT_EXECUTORS_FILE_PATH: &str = "src/encoding/config/executor_addresses.json"; const HELP_TEXT: &str = "\ USAGE: tycho-encode [ROUTER_ADDRESS] @@ -232,13 +233,13 @@ fn parse_protocol_component(obj: &Value) -> Result DtoChain::Ethereum, - "starknet" => DtoChain::Starknet, - "zksync" => DtoChain::ZkSync, - "arbitrum" => DtoChain::Arbitrum, - _ => DtoChain::Ethereum, // Default to Ethereum + "ethereum" => Chain::Ethereum, + "starknet" => Chain::Starknet, + "zksync" => Chain::ZkSync, + "arbitrum" => Chain::Arbitrum, + _ => Chain::Ethereum, // Default to Ethereum }) - .unwrap_or(DtoChain::Ethereum), + .unwrap_or(Chain::Ethereum), tokens: obj .get("tokens") .and_then(|v| v.as_array()) @@ -306,41 +307,17 @@ fn parse_protocol_component(obj: &Value) -> Result Result> { // Parse the input JSON let input_json: Value = serde_json::from_str(input)?; + let solution = parse_solution(input_json)?; - // Extract the chain from the input JSON - let chain = input_json - .get("chain") - .and_then(|v| v.as_str()) - .map(|s| match s.to_lowercase().as_str() { - "ethereum" => DtoChain::Ethereum, - "starknet" => DtoChain::Starknet, - "zksync" => DtoChain::ZkSync, - "arbitrum" => DtoChain::Arbitrum, - _ => DtoChain::Ethereum, // Default to Ethereum - }) - .unwrap_or(DtoChain::Ethereum); + // Create encoder and encode the solution + let strategy_selector = + EVMStrategyEncoderRegistry::new(Chain::Ethereum, DEFAULT_EXECUTORS_FILE_PATH, None)?; + let encoder = EVMTychoEncoder::new(strategy_selector, router_address.to_string())?; + let transactions = encoder.encode_router_calldata(vec![solution])?; - // Parse the solution from the input JSON - let mut solution = parse_solution(input_json)?; - solution.direct_execution = true; - - // Create the strategy encoder based on the chain - let strategy_encoder: Value = match chain { - DtoChain::Ethereum => { - // Create encoder and encode the solution with empty executors file path - let strategy_selector = EVMStrategyEncoderRegistry::new(DtoChain::Ethereum, "", None)?; - let encoder = EVMTychoEncoder::new(strategy_selector, router_address.to_string())?; - let transactions = encoder.encode_router_calldata(vec![solution])?; - - let result: Result> = Ok(serde_json::json!({ - "to": format!("0x{}", hex::encode(&transactions[0].to)), - "value": format!("0x{}", hex::encode(transactions[0].value.to_bytes_be())), - "data": format!("0x{}", hex::encode(&transactions[0].data)), - })); - result - } - _ => Err(format!("Unsupported chain: {:?}", chain).into()), - }?; - - Ok(strategy_encoder) + Ok(serde_json::json!({ + "to": format!("0x{}", hex::encode(&transactions[0].to)), + "value": format!("0x{}", hex::encode(transactions[0].value.to_bytes_be())), + "data": format!("0x{}", hex::encode(&transactions[0].data)), + })) } diff --git a/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs b/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs index 6e9712d..94a8253 100644 --- a/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs +++ b/src/encoding/evm/strategy_encoder/strategy_encoder_registry.rs @@ -22,11 +22,7 @@ impl StrategyEncoderRegistry for EVMStrategyEncoderRegistry { executors_file_path: &str, signer_pk: Option, ) -> Result { - let swap_encoder_registry = if executors_file_path.is_empty() { - SwapEncoderRegistry::new_direct_execution() - } else { - SwapEncoderRegistry::new(executors_file_path, Chain::Ethereum)? - }; + let swap_encoder_registry = SwapEncoderRegistry::new(executors_file_path, Chain::Ethereum)?; let mut strategies: HashMap> = HashMap::new(); strategies.insert( diff --git a/src/encoding/evm/swap_encoder/swap_encoder_registry.rs b/src/encoding/evm/swap_encoder/swap_encoder_registry.rs index 7ac2207..b04e580 100644 --- a/src/encoding/evm/swap_encoder/swap_encoder_registry.rs +++ b/src/encoding/evm/swap_encoder/swap_encoder_registry.rs @@ -29,25 +29,6 @@ impl SwapEncoderRegistry { Ok(Self { encoders }) } - pub fn new_direct_execution() -> Self { - let mut encoders = HashMap::new(); - - // Add default encoders with their respective executor addresses - let default_encoders = [ - ("uniswap_v2", "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"), - ("vm:balancer_v2", "0xBA12222222228d8Ba445958a75a0704d566BF2C8"), - ]; - - for (protocol, executor_address) in default_encoders { - let builder = SwapEncoderBuilder::new(protocol, executor_address); - if let Ok(encoder) = builder.build() { - encoders.insert(protocol.to_string(), encoder); - } - } - - Self { encoders } - } - #[allow(clippy::borrowed_box)] pub fn get_encoder(&self, protocol_system: &str) -> Option<&Box> { self.encoders.get(protocol_system)