feat: Add clone to EVMTychoEncoder
--- don't change below this line --- ENG-4088 Took 4 minutes Took 8 seconds Took 48 seconds
This commit is contained in:
@@ -25,10 +25,11 @@ use crate::encoding::{
|
|||||||
|
|
||||||
/// Struct for managing Permit2 operations, including encoding approvals and fetching allowance
|
/// Struct for managing Permit2 operations, including encoding approvals and fetching allowance
|
||||||
/// data.
|
/// data.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Permit2 {
|
pub struct Permit2 {
|
||||||
address: Address,
|
address: Address,
|
||||||
client: Arc<RootProvider<BoxTransport>>,
|
client: Arc<RootProvider<BoxTransport>>,
|
||||||
runtime: Runtime,
|
runtime: Arc<Runtime>,
|
||||||
signer: PrivateKeySigner,
|
signer: PrivateKeySigner,
|
||||||
chain_id: ChainId,
|
chain_id: ChainId,
|
||||||
}
|
}
|
||||||
@@ -73,7 +74,7 @@ impl Permit2 {
|
|||||||
address: Address::from_str("0x000000000022D473030F116dDEE9F6B43aC78BA3")
|
address: Address::from_str("0x000000000022D473030F116dDEE9F6B43aC78BA3")
|
||||||
.map_err(|_| EncodingError::FatalError("Permit2 address not valid".to_string()))?,
|
.map_err(|_| EncodingError::FatalError("Permit2 address not valid".to_string()))?,
|
||||||
client,
|
client,
|
||||||
runtime,
|
runtime: Arc::new(runtime),
|
||||||
signer,
|
signer,
|
||||||
chain_id: chain.id,
|
chain_id: chain.id,
|
||||||
})
|
})
|
||||||
|
|||||||
0
src/encoding/evm/models.rs
Normal file
0
src/encoding/evm/models.rs
Normal file
@@ -58,3 +58,15 @@ impl StrategyEncoderRegistry for EVMStrategyEncoderRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Clone for EVMStrategyEncoderRegistry {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
Self {
|
||||||
|
strategies: self
|
||||||
|
.strategies
|
||||||
|
.iter()
|
||||||
|
.map(|(k, v)| (k.clone(), v.clone_box()))
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ pub trait EVMStrategyEncoder: StrategyEncoder {
|
|||||||
/// * `permit2`: Permit2, responsible for managing permit2 operations and providing necessary
|
/// * `permit2`: Permit2, responsible for managing permit2 operations and providing necessary
|
||||||
/// signatures and permit2 objects for calling the router
|
/// signatures and permit2 objects for calling the router
|
||||||
/// * `selector`: String, the selector for the swap function in the router contract
|
/// * `selector`: String, the selector for the swap function in the router contract
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct SplitSwapStrategyEncoder {
|
pub struct SplitSwapStrategyEncoder {
|
||||||
swap_encoder_registry: SwapEncoderRegistry,
|
swap_encoder_registry: SwapEncoderRegistry,
|
||||||
permit2: Permit2,
|
permit2: Permit2,
|
||||||
@@ -405,6 +406,10 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
|||||||
self.swap_encoder_registry
|
self.swap_encoder_registry
|
||||||
.get_encoder(protocol_system)
|
.get_encoder(protocol_system)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn clone_box(&self) -> Box<dyn StrategyEncoder> {
|
||||||
|
Box::new(self.clone())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This strategy encoder is used for solutions that are sent directly to the executor, bypassing
|
/// This strategy encoder is used for solutions that are sent directly to the executor, bypassing
|
||||||
@@ -412,6 +417,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
|||||||
///
|
///
|
||||||
/// # Fields
|
/// # Fields
|
||||||
/// * `swap_encoder_registry`: SwapEncoderRegistry, containing all possible swap encoders
|
/// * `swap_encoder_registry`: SwapEncoderRegistry, containing all possible swap encoders
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct ExecutorStrategyEncoder {
|
pub struct ExecutorStrategyEncoder {
|
||||||
swap_encoder_registry: SwapEncoderRegistry,
|
swap_encoder_registry: SwapEncoderRegistry,
|
||||||
}
|
}
|
||||||
@@ -459,10 +465,15 @@ impl StrategyEncoder for ExecutorStrategyEncoder {
|
|||||||
.map_err(|_| EncodingError::FatalError("Invalid executor address".to_string()))?;
|
.map_err(|_| EncodingError::FatalError("Invalid executor address".to_string()))?;
|
||||||
Ok((protocol_data, executor_address))
|
Ok((protocol_data, executor_address))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_swap_encoder(&self, protocol_system: &str) -> Option<&Box<dyn SwapEncoder>> {
|
fn get_swap_encoder(&self, protocol_system: &str) -> Option<&Box<dyn SwapEncoder>> {
|
||||||
self.swap_encoder_registry
|
self.swap_encoder_registry
|
||||||
.get_encoder(protocol_system)
|
.get_encoder(protocol_system)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn clone_box(&self) -> Box<dyn StrategyEncoder> {
|
||||||
|
Box::new(self.clone())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use crate::encoding::{
|
|||||||
/// * `router_address`: Bytes, the address of the router to use to execute the swaps.
|
/// * `router_address`: Bytes, the address of the router to use to execute the swaps.
|
||||||
/// * `native_address`: Address of the chain's native token
|
/// * `native_address`: Address of the chain's native token
|
||||||
/// * `wrapped_address`: Address of the chain's wrapped native token
|
/// * `wrapped_address`: Address of the chain's wrapped native token
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct EVMTychoEncoder<S: StrategyEncoderRegistry> {
|
pub struct EVMTychoEncoder<S: StrategyEncoderRegistry> {
|
||||||
strategy_registry: S,
|
strategy_registry: S,
|
||||||
router_address: Bytes,
|
router_address: Bytes,
|
||||||
@@ -183,6 +184,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct MockStrategy;
|
struct MockStrategy;
|
||||||
|
|
||||||
impl StrategyEncoder for MockStrategy {
|
impl StrategyEncoder for MockStrategy {
|
||||||
@@ -202,6 +204,9 @@ mod tests {
|
|||||||
fn get_swap_encoder(&self, _protocol_system: &str) -> Option<&Box<dyn SwapEncoder>> {
|
fn get_swap_encoder(&self, _protocol_system: &str) -> Option<&Box<dyn SwapEncoder>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
fn clone_box(&self) -> Box<dyn StrategyEncoder> {
|
||||||
|
Box::new(self.clone())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_mocked_tycho_encoder() -> EVMTychoEncoder<MockStrategyRegistry> {
|
fn get_mocked_tycho_encoder() -> EVMTychoEncoder<MockStrategyRegistry> {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub trait StrategyEncoder {
|
|||||||
|
|
||||||
#[allow(clippy::borrowed_box)]
|
#[allow(clippy::borrowed_box)]
|
||||||
fn get_swap_encoder(&self, protocol_system: &str) -> Option<&Box<dyn SwapEncoder>>;
|
fn get_swap_encoder(&self, protocol_system: &str) -> Option<&Box<dyn SwapEncoder>>;
|
||||||
|
fn clone_box(&self) -> Box<dyn StrategyEncoder>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains the supported strategies to encode a solution, and chooses the best strategy to encode
|
/// Contains the supported strategies to encode a solution, and chooses the best strategy to encode
|
||||||
|
|||||||
Reference in New Issue
Block a user