feat: Implement SplitSwapStrategyEncoder
The strategy works as follows: - Manage approvals needed - Compute min amount (if check amount is any): - if slippage is defined, apply slippage on the expected amount and take the min value between that and the check amount - if not, it's just the check amount - Iterate through the swaps - call the corresponding swap encoder to encode the swap - add swap header (tokens indexes and split) - ple encode the swaps - Add extra inputs (amounts, token addresses, min amount, (un)wrap, number of tokens and receiver) Misc: - Move executor address and selector encoding inside the SwapEncoder - Add default executor_selector to SwapEncoder - Pass router address inside the SplitSwapStrategyEncoder - Move Permit2 inside the SplitSwapStrategyEncoder. It is a responsibility and a specificity of the strategy to need permit2 approvals --- don't change below this line --- ENG-4081 Took 1 hour 21 minutes
This commit is contained in:
@@ -1,12 +1,25 @@
|
||||
use alloy::signers::local::PrivateKeySigner;
|
||||
use alloy_primitives::ChainId;
|
||||
use tycho_core::Bytes;
|
||||
|
||||
use crate::encoding::{errors::EncodingError, models::Solution};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait StrategyEncoder {
|
||||
fn encode_strategy(&self, to_encode: Solution) -> Result<Vec<u8>, EncodingError>;
|
||||
fn encode_strategy(
|
||||
&self,
|
||||
to_encode: Solution,
|
||||
router_address: Bytes,
|
||||
) -> Result<Vec<u8>, EncodingError>;
|
||||
fn selector(&self, exact_out: bool) -> &str;
|
||||
}
|
||||
|
||||
pub trait StrategySelector {
|
||||
#[allow(dead_code)]
|
||||
fn select_strategy(&self, solution: &Solution) -> Box<dyn StrategyEncoder>;
|
||||
fn select_strategy(
|
||||
&self,
|
||||
solution: &Solution,
|
||||
signer: Option<PrivateKeySigner>,
|
||||
chain_id: ChainId,
|
||||
) -> Result<Box<dyn StrategyEncoder>, EncodingError>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user