feat: The execution structs should receiver tycho_core Chain

and convert it later to an execution model Chain

--- don't change below this line ---
ENG-4088 Took 8 minutes
This commit is contained in:
Diana Carvalho
2025-02-07 11:35:38 +00:00
parent 0c9050cf79
commit cad9f394cd
4 changed files with 15 additions and 20 deletions

View File

@@ -10,7 +10,7 @@ use tycho_execution::encoding::{
strategy_encoder::strategy_encoder_registry::EVMStrategyEncoderRegistry, strategy_encoder::strategy_encoder_registry::EVMStrategyEncoderRegistry,
tycho_encoder::EVMTychoEncoder, tycho_encoder::EVMTychoEncoder,
}, },
models::{Chain, Solution, Swap}, models::{Solution, Swap},
strategy_encoder::StrategyEncoderRegistry, strategy_encoder::StrategyEncoderRegistry,
tycho_encoder::TychoEncoder, tycho_encoder::TychoEncoder,
}; };
@@ -23,13 +23,13 @@ fn main() {
let user_address = Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2") let user_address = Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2")
.expect("Failed to create user address"); .expect("Failed to create user address");
let eth_chain = Chain::from(TychoCoreChain::Ethereum);
// Initialize the encoder // Initialize the encoder
let strategy_encoder_registry = let strategy_encoder_registry =
EVMStrategyEncoderRegistry::new(eth_chain.clone(), None, signer_pk.clone()) EVMStrategyEncoderRegistry::new(TychoCoreChain::Ethereum, None, signer_pk.clone())
.expect("Failed to create strategy encoder registry"); .expect("Failed to create strategy encoder registry");
let encoder = EVMTychoEncoder::new(strategy_encoder_registry, router_address, eth_chain) let encoder =
.expect("Failed to create encoder"); EVMTychoEncoder::new(strategy_encoder_registry, router_address, TychoCoreChain::Ethereum)
.expect("Failed to create encoder");
// ------------------- Encode a simple swap ------------------- // ------------------- Encode a simple swap -------------------

View File

@@ -21,10 +21,11 @@ pub struct EVMStrategyEncoderRegistry {
impl StrategyEncoderRegistry for EVMStrategyEncoderRegistry { impl StrategyEncoderRegistry for EVMStrategyEncoderRegistry {
fn new( fn new(
chain: Chain, chain: tycho_core::dto::Chain,
executors_file_path: Option<&str>, executors_file_path: Option<&str>,
signer_pk: Option<String>, signer_pk: Option<String>,
) -> Result<Self, EncodingError> { ) -> Result<Self, EncodingError> {
let chain = Chain::from(chain);
let swap_encoder_registry = SwapEncoderRegistry::new(executors_file_path, chain.clone())?; let swap_encoder_registry = SwapEncoderRegistry::new(executors_file_path, chain.clone())?;
let mut strategies: HashMap<String, Box<dyn StrategyEncoder>> = HashMap::new(); let mut strategies: HashMap<String, Box<dyn StrategyEncoder>> = HashMap::new();

View File

@@ -31,10 +31,11 @@ impl<S: StrategyEncoderRegistry> EVMTychoEncoder<S> {
pub fn new( pub fn new(
strategy_registry: S, strategy_registry: S,
router_address: String, router_address: String,
chain: Chain, chain: tycho_core::dto::Chain,
) -> Result<Self, EncodingError> { ) -> Result<Self, EncodingError> {
let router_address = Bytes::from_str(&router_address) let router_address = Bytes::from_str(&router_address)
.map_err(|_| EncodingError::FatalError("Invalid router address".to_string()))?; .map_err(|_| EncodingError::FatalError("Invalid router address".to_string()))?;
let chain: Chain = Chain::from(chain);
if chain.name != *"ethereum" { if chain.name != *"ethereum" {
return Err(EncodingError::InvalidInput( return Err(EncodingError::InvalidInput(
"Currently only Ethereum is supported".to_string(), "Currently only Ethereum is supported".to_string(),
@@ -151,10 +152,6 @@ mod tests {
strategy: Box<dyn StrategyEncoder>, strategy: Box<dyn StrategyEncoder>,
} }
fn eth_chain() -> Chain {
TychoCoreChain::Ethereum.into()
}
fn dai() -> Bytes { fn dai() -> Bytes {
Bytes::from_str("0x6b175474e89094c44da98b954eedeac495271d0f").unwrap() Bytes::from_str("0x6b175474e89094c44da98b954eedeac495271d0f").unwrap()
} }
@@ -169,7 +166,7 @@ mod tests {
impl StrategyEncoderRegistry for MockStrategyRegistry { impl StrategyEncoderRegistry for MockStrategyRegistry {
fn new( fn new(
_chain: Chain, _chain: tycho_core::dto::Chain,
_executors_file_path: Option<&str>, _executors_file_path: Option<&str>,
_signer_pk: Option<String>, _signer_pk: Option<String>,
) -> Result<MockStrategyRegistry, EncodingError> { ) -> Result<MockStrategyRegistry, EncodingError> {
@@ -210,11 +207,12 @@ mod tests {
} }
fn get_mocked_tycho_encoder() -> EVMTychoEncoder<MockStrategyRegistry> { fn get_mocked_tycho_encoder() -> EVMTychoEncoder<MockStrategyRegistry> {
let strategy_registry = MockStrategyRegistry::new(eth_chain(), None, None).unwrap(); let strategy_registry =
MockStrategyRegistry::new(TychoCoreChain::Ethereum, None, None).unwrap();
EVMTychoEncoder::new( EVMTychoEncoder::new(
strategy_registry, strategy_registry,
"0x1234567890abcdef1234567890abcdef12345678".to_string(), "0x1234567890abcdef1234567890abcdef12345678".to_string(),
eth_chain(), TychoCoreChain::Ethereum,
) )
.unwrap() .unwrap()
} }

View File

@@ -1,10 +1,6 @@
use tycho_core::Bytes; use tycho_core::{dto::Chain, Bytes};
use crate::encoding::{ use crate::encoding::{errors::EncodingError, models::Solution, swap_encoder::SwapEncoder};
errors::EncodingError,
models::{Chain, Solution},
swap_encoder::SwapEncoder,
};
/// Encodes a solution using a specific strategy. /// Encodes a solution using a specific strategy.
pub trait StrategyEncoder { pub trait StrategyEncoder {