Files
tycho-execution/src/encoding/strategy_selector.rs
Diana Carvalho 3e609c75ae feat: Support encoding only the pool swap
Create StraightToPoolStrategyEncoder
2025-01-16 17:18:11 +00:00

26 lines
883 B
Rust

use crate::encoding::models::Order;
use crate::encoding::strategy_encoder::{
SequentialExactInStrategyEncoder, SingleSwapStrategyEncoder, SlipSwapStrategyEncoder,
StraightToPoolStrategyEncoder, StrategyEncoder,
};
pub trait StrategySelector {
fn select_strategy(&self, order: &Order) -> Box<dyn StrategyEncoder>;
}
pub struct DefaultStrategySelector;
impl StrategySelector for DefaultStrategySelector {
fn select_strategy(&self, order: &Order) -> Box<dyn StrategyEncoder> {
if order.straight_to_pool {
Box::new(StraightToPoolStrategyEncoder {})
} else if order.swaps.len() == 1 {
Box::new(SingleSwapStrategyEncoder {})
} else if order.swaps.iter().all(|s| s.split == 0.0) {
Box::new(SequentialExactInStrategyEncoder {})
} else {
Box::new(SlipSwapStrategyEncoder {})
}
}
}