diff --git a/src/encoding/strategy_encoder.rs b/src/encoding/strategy_encoder.rs index 63d3ef4..aa2ffd8 100644 --- a/src/encoding/strategy_encoder.rs +++ b/src/encoding/strategy_encoder.rs @@ -1,4 +1,4 @@ -use std::cmp::min; +use std::{cmp::min, str::FromStr}; use alloy_primitives::Address; use alloy_sol_types::SolValue; @@ -97,7 +97,13 @@ impl StrategyEncoder for SequentialStrategyEncoder { }; let protocol_data = swap_encoder.encode_swap(swap.clone(), encoding_context)?; let executor_address = swap_encoder.executor_address(); - let swap_data = self.encode_protocol_header(protocol_data, executor_address, 0, 0, 0); + let swap_data = self.encode_protocol_header( + protocol_data, + Address::from_str(executor_address).expect("Couldn't convert executor address"), + 0, + 0, + 0, + ); swaps.push(swap_data); } diff --git a/src/encoding/swap_encoder/builder.rs b/src/encoding/swap_encoder/builder.rs index 492962d..5f6ffd1 100644 --- a/src/encoding/swap_encoder/builder.rs +++ b/src/encoding/swap_encoder/builder.rs @@ -1,22 +1,17 @@ -use std::str::FromStr; - -use alloy_primitives::Address; - use crate::encoding::swap_encoder::swap_struct_encoder::{ BalancerV2SwapEncoder, SwapEncoder, UniswapV2SwapEncoder, }; pub struct SwapEncoderBuilder { protocol_system: String, - executor_address: Address, + executor_address: String, } impl SwapEncoderBuilder { pub fn new(protocol_system: &str, executor_address: &str) -> Self { SwapEncoderBuilder { protocol_system: protocol_system.to_string(), - executor_address: Address::from_str(executor_address) - .unwrap_or_else(|_| panic!("Invalid address: {}", executor_address)), + executor_address: executor_address.to_string(), } } diff --git a/src/encoding/swap_encoder/swap_struct_encoder.rs b/src/encoding/swap_encoder/swap_struct_encoder.rs index e8d8d19..51168c0 100644 --- a/src/encoding/swap_encoder/swap_struct_encoder.rs +++ b/src/encoding/swap_encoder/swap_struct_encoder.rs @@ -11,20 +11,20 @@ use crate::encoding::{ }; pub trait SwapEncoder: Sync + Send { - fn new(executor_address: Address) -> Self + fn new(executor_address: String) -> Self where Self: Sized; fn encode_swap(&self, swap: Swap, encoding_context: EncodingContext) -> Result, Error>; - fn executor_address(&self) -> Address; + fn executor_address(&self) -> &str; } pub struct UniswapV2SwapEncoder { - executor_address: Address, + executor_address: String, } impl UniswapV2SwapEncoder {} impl SwapEncoder for UniswapV2SwapEncoder { - fn new(executor_address: Address) -> Self { + fn new(executor_address: String) -> Self { Self { executor_address } } fn encode_swap( @@ -35,18 +35,18 @@ impl SwapEncoder for UniswapV2SwapEncoder { todo!() } - fn executor_address(&self) -> Address { - self.executor_address + fn executor_address(&self) -> &str { + &self.executor_address } } pub struct BalancerV2SwapEncoder { - executor_address: Address, + executor_address: String, vault_address: Address, } impl SwapEncoder for BalancerV2SwapEncoder { - fn new(executor_address: Address) -> Self { + fn new(executor_address: String) -> Self { Self { executor_address, vault_address: Address::from_str("0xba12222222228d8ba445958a75a0704d566bf2c8") @@ -79,8 +79,8 @@ impl SwapEncoder for BalancerV2SwapEncoder { Ok(args.abi_encode()) } - fn executor_address(&self) -> Address { - self.executor_address + fn executor_address(&self) -> &str { + &self.executor_address } }