fix: unsupported protocols for chained swaps are always unsupported

not only when the previous swap if of the same protocol!
Improve docs and naming

--- don't change below this line ---
ENG-4314 Took 15 minutes
This commit is contained in:
Diana Carvalho
2025-04-17 09:33:52 +01:00
parent efe12cfcd6
commit 8aa5b08b41
3 changed files with 10 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ pub static GROUPABLE_PROTOCOLS: LazyLock<HashSet<&'static str>> = LazyLock::new(
});
/// These protocols support the optimization of transferring straight from the user.
/// Any protocols that are not defined here expect funds to be in the router at the time of swap.
pub static IN_TRANSFER_OPTIMIZABLE_PROTOCOLS: LazyLock<HashSet<&'static str>> =
LazyLock::new(|| {
let mut set = HashSet::new();
@@ -31,10 +32,12 @@ pub static IN_TRANSFER_OPTIMIZABLE_PROTOCOLS: LazyLock<HashSet<&'static str>> =
set
});
// These protocols do not support chained swaps from the same protocol. This is the case for uniswap
// v3 because of the callback logic. The only way for this to work it would be to call the second
// swap during the callback of the first swap. This is currently not supported.
pub static PROTOCOLS_NOT_OPTIMIZED_CHAINED_SWAPS: LazyLock<HashSet<&'static str>> =
// These protocols do not support chained swaps. The tokens can not be sent directly from the
// previous pool into a pool of this protocol. The tokens need to be sent to the router and only
// then transferred into the pool. This is the case for uniswap v3 because of the callback logic.
// The only way for this to work it would be to call the second swap during the callback of the
// first swap. This is currently not supported.
pub static UNSUPPORTED_PROTOCOLS_FOR_CHAINED_SWAPS: LazyLock<HashSet<&'static str>> =
LazyLock::new(|| {
let mut set = HashSet::new();
set.insert("uniswap_v3");

View File

@@ -8,7 +8,7 @@ use crate::encoding::{
errors::EncodingError,
evm::{
approvals::permit2::Permit2,
constants::{IN_TRANSFER_OPTIMIZABLE_PROTOCOLS, PROTOCOLS_NOT_OPTIMIZED_CHAINED_SWAPS},
constants::{IN_TRANSFER_OPTIMIZABLE_PROTOCOLS, UNSUPPORTED_PROTOCOLS_FOR_CHAINED_SWAPS},
group_swaps::group_swaps,
strategy_encoder::{
strategy_validators::{SequentialSwapValidator, SplitSwapValidator, SwapValidator},
@@ -311,9 +311,8 @@ impl StrategyEncoder for SequentialSwapStrategyEncoder {
if IN_TRANSFER_OPTIMIZABLE_PROTOCOLS.contains(&next.protocol_system.as_str()) {
// if the protocol does not allow for chained swaps, we can't optimize the
// receiver of this swap nor the transfer in of the next swap
if PROTOCOLS_NOT_OPTIMIZED_CHAINED_SWAPS
.contains(&next.protocol_system.as_str()) &&
PROTOCOLS_NOT_OPTIMIZED_CHAINED_SWAPS.contains(protocol.as_str())
if UNSUPPORTED_PROTOCOLS_FOR_CHAINED_SWAPS
.contains(&next.protocol_system.as_str())
{
next_in_between_swap_optimization = false;
self.router_address.clone()

View File

@@ -30,7 +30,6 @@ pub trait TransferOptimization {
} else if (swap.token_in == wrapped_token) && wrap {
// Wrapping already happened in the router so we can just use a normal transfer.
TransferType::TransferToProtocol
// first swap
} else if is_first_swap {
if in_transfer_optimizable {
if permit2 {