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:
@@ -10,7 +10,7 @@ use tycho_execution::encoding::{
|
||||
strategy_encoder::strategy_encoder_registry::EVMStrategyEncoderRegistry,
|
||||
tycho_encoder::EVMTychoEncoder,
|
||||
},
|
||||
models::{Chain, Solution, Swap},
|
||||
models::{Solution, Swap},
|
||||
strategy_encoder::StrategyEncoderRegistry,
|
||||
tycho_encoder::TychoEncoder,
|
||||
};
|
||||
@@ -23,13 +23,13 @@ fn main() {
|
||||
let user_address = Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2")
|
||||
.expect("Failed to create user address");
|
||||
|
||||
let eth_chain = Chain::from(TychoCoreChain::Ethereum);
|
||||
// Initialize the encoder
|
||||
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");
|
||||
let encoder = EVMTychoEncoder::new(strategy_encoder_registry, router_address, eth_chain)
|
||||
.expect("Failed to create encoder");
|
||||
let encoder =
|
||||
EVMTychoEncoder::new(strategy_encoder_registry, router_address, TychoCoreChain::Ethereum)
|
||||
.expect("Failed to create encoder");
|
||||
|
||||
// ------------------- Encode a simple swap -------------------
|
||||
|
||||
|
||||
@@ -21,10 +21,11 @@ pub struct EVMStrategyEncoderRegistry {
|
||||
|
||||
impl StrategyEncoderRegistry for EVMStrategyEncoderRegistry {
|
||||
fn new(
|
||||
chain: Chain,
|
||||
chain: tycho_core::dto::Chain,
|
||||
executors_file_path: Option<&str>,
|
||||
signer_pk: Option<String>,
|
||||
) -> Result<Self, EncodingError> {
|
||||
let chain = Chain::from(chain);
|
||||
let swap_encoder_registry = SwapEncoderRegistry::new(executors_file_path, chain.clone())?;
|
||||
|
||||
let mut strategies: HashMap<String, Box<dyn StrategyEncoder>> = HashMap::new();
|
||||
|
||||
@@ -31,10 +31,11 @@ impl<S: StrategyEncoderRegistry> EVMTychoEncoder<S> {
|
||||
pub fn new(
|
||||
strategy_registry: S,
|
||||
router_address: String,
|
||||
chain: Chain,
|
||||
chain: tycho_core::dto::Chain,
|
||||
) -> Result<Self, EncodingError> {
|
||||
let router_address = Bytes::from_str(&router_address)
|
||||
.map_err(|_| EncodingError::FatalError("Invalid router address".to_string()))?;
|
||||
let chain: Chain = Chain::from(chain);
|
||||
if chain.name != *"ethereum" {
|
||||
return Err(EncodingError::InvalidInput(
|
||||
"Currently only Ethereum is supported".to_string(),
|
||||
@@ -151,10 +152,6 @@ mod tests {
|
||||
strategy: Box<dyn StrategyEncoder>,
|
||||
}
|
||||
|
||||
fn eth_chain() -> Chain {
|
||||
TychoCoreChain::Ethereum.into()
|
||||
}
|
||||
|
||||
fn dai() -> Bytes {
|
||||
Bytes::from_str("0x6b175474e89094c44da98b954eedeac495271d0f").unwrap()
|
||||
}
|
||||
@@ -169,7 +166,7 @@ mod tests {
|
||||
|
||||
impl StrategyEncoderRegistry for MockStrategyRegistry {
|
||||
fn new(
|
||||
_chain: Chain,
|
||||
_chain: tycho_core::dto::Chain,
|
||||
_executors_file_path: Option<&str>,
|
||||
_signer_pk: Option<String>,
|
||||
) -> Result<MockStrategyRegistry, EncodingError> {
|
||||
@@ -210,11 +207,12 @@ mod tests {
|
||||
}
|
||||
|
||||
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(
|
||||
strategy_registry,
|
||||
"0x1234567890abcdef1234567890abcdef12345678".to_string(),
|
||||
eth_chain(),
|
||||
TychoCoreChain::Ethereum,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
use tycho_core::Bytes;
|
||||
use tycho_core::{dto::Chain, Bytes};
|
||||
|
||||
use crate::encoding::{
|
||||
errors::EncodingError,
|
||||
models::{Chain, Solution},
|
||||
swap_encoder::SwapEncoder,
|
||||
};
|
||||
use crate::encoding::{errors::EncodingError, models::Solution, swap_encoder::SwapEncoder};
|
||||
|
||||
/// Encodes a solution using a specific strategy.
|
||||
pub trait StrategyEncoder {
|
||||
|
||||
Reference in New Issue
Block a user