fix: Use max instead of min to get the min_amount_out
between slippaged amount and checked amount Save router's address as Bytes and not String --- don't change below this line --- ENG-4081 Took 7 minutes
This commit is contained in:
@@ -15,7 +15,7 @@ pub struct EVMRouterEncoder<S: StrategySelector> {
|
||||
strategy_selector: S,
|
||||
signer: Option<String>,
|
||||
chain: Chain,
|
||||
router_address: String,
|
||||
router_address: Bytes,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -26,6 +26,8 @@ impl<S: StrategySelector> EVMRouterEncoder<S> {
|
||||
signer: Option<String>,
|
||||
chain: Chain,
|
||||
) -> Result<Self, EncodingError> {
|
||||
let router_address = Bytes::from_str(&router_address)
|
||||
.map_err(|_| EncodingError::FatalError("Invalid router address".to_string()))?;
|
||||
Ok(EVMRouterEncoder { strategy_selector, signer, chain, router_address })
|
||||
}
|
||||
}
|
||||
@@ -45,16 +47,14 @@ impl<S: StrategySelector> RouterEncoder<S> for EVMRouterEncoder<S> {
|
||||
let router_address = solution
|
||||
.router_address
|
||||
.clone()
|
||||
.unwrap_or(Bytes::from_str(&self.router_address).map_err(|_| {
|
||||
EncodingError::FatalError("Invalid router address".to_string())
|
||||
})?);
|
||||
.unwrap_or(self.router_address.clone());
|
||||
let strategy = self.strategy_selector.select_strategy(
|
||||
solution,
|
||||
self.signer.clone(),
|
||||
self.chain,
|
||||
)?;
|
||||
|
||||
let (contract_interaction,target_address) =
|
||||
let (contract_interaction, target_address) =
|
||||
strategy.encode_strategy(solution.clone(), router_address)?;
|
||||
|
||||
let value = if solution.native_action.clone().unwrap() == NativeAction::Wrap {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{cmp::min, str::FromStr};
|
||||
use std::{cmp::max, str::FromStr};
|
||||
|
||||
use alloy_primitives::{aliases::U24, map::HashSet, FixedBytes, U256, U8};
|
||||
use alloy_sol_types::SolValue;
|
||||
@@ -76,7 +76,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
||||
let multiplier = &one_hundred - slippage_percent;
|
||||
let expected_amount_with_slippage =
|
||||
(&solution.expected_amount * multiplier) / one_hundred;
|
||||
min_amount_out = min(min_amount_out, expected_amount_with_slippage);
|
||||
min_amount_out = max(min_amount_out, expected_amount_with_slippage);
|
||||
}
|
||||
min_amount_out
|
||||
} else {
|
||||
@@ -115,7 +115,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
||||
.position(|t| *t == swap.token_in)
|
||||
.ok_or_else(|| {
|
||||
EncodingError::InvalidInput(
|
||||
"Token in not found in tokens array".to_string(),
|
||||
"In token not found in tokens array".to_string(),
|
||||
)
|
||||
})?,
|
||||
),
|
||||
@@ -125,7 +125,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
||||
.position(|t| *t == swap.token_out)
|
||||
.ok_or_else(|| {
|
||||
EncodingError::InvalidInput(
|
||||
"Token out not found in tokens array".to_string(),
|
||||
"Out token not found in tokens array".to_string(),
|
||||
)
|
||||
})?,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user