feat: Refactor Registries

Interface changes:
- Rename StrategySelector to StrategyEncoderRegistry
- Implement clone for SwapEncoder

The StrategyEncoderRegistry needs to be initialised at the highest level and the passed to the TychoEncoder.
The TychoEncoder doesn't hold the chain nor the signer_pk as attributes anymore
The StrategyEncoderRegistry does:
- Initialises the SwapEncoderRegistry
- Initialises all the strategies and saves them in a HashMap
- Later, the TychoEncoder only reads from this hashmap

The StrategyEncoder now each holds a SwapEncoderRegistry as an attribute and they use this to get the correct SwapEncoder instead of reading from the global SWAP_ENCODER_REGISTRY

Simplified the SwapEncoderRegistry to not need a Config (everything is done inside itself)
All SwapEncoders implement clone

Took 2 hours 29 minutes

Took 11 seconds

Took 2 minutes
This commit is contained in:
Diana Carvalho
2025-02-04 13:30:01 +00:00
parent a92ba96d86
commit 23875b8b02
15 changed files with 206 additions and 148 deletions

View File

@@ -12,6 +12,7 @@ use crate::encoding::{
swap_encoder::SwapEncoder,
};
#[derive(Clone)]
pub struct UniswapV2SwapEncoder {
executor_address: String,
executor_selector: String,
@@ -59,8 +60,13 @@ impl SwapEncoder for UniswapV2SwapEncoder {
fn executor_selector(&self) -> &str {
&self.executor_selector
}
fn clone_box(&self) -> Box<dyn SwapEncoder> {
Box::new(self.clone())
}
}
#[derive(Clone)]
pub struct UniswapV3SwapEncoder {
executor_address: String,
executor_selector: String,
@@ -129,8 +135,12 @@ impl SwapEncoder for UniswapV3SwapEncoder {
fn executor_selector(&self) -> &str {
&self.executor_selector
}
fn clone_box(&self) -> Box<dyn SwapEncoder> {
Box::new(self.clone())
}
}
#[derive(Clone)]
pub struct BalancerV2SwapEncoder {
executor_address: String,
executor_selector: String,
@@ -179,6 +189,9 @@ impl SwapEncoder for BalancerV2SwapEncoder {
fn executor_selector(&self) -> &str {
&self.executor_selector
}
fn clone_box(&self) -> Box<dyn SwapEncoder> {
Box::new(self.clone())
}
}
#[cfg(test)]