fix: Rename constants and update docstrings for clarity

--- don't change below this line ---
ENG-4314 Took 44 minutes


Took 9 seconds
This commit is contained in:
Diana Carvalho
2025-04-17 15:51:01 +01:00
parent 8aa5b08b41
commit 244b7d3482
3 changed files with 32 additions and 35 deletions

View File

@@ -18,29 +18,28 @@ pub static GROUPABLE_PROTOCOLS: LazyLock<HashSet<&'static str>> = LazyLock::new(
set set
}); });
/// These protocols support the optimization of transferring straight from the user. /// These protocols need an external in transfer to the pool. This transfer can be from the router,
/// Any protocols that are not defined here expect funds to be in the router at the time of swap. /// from the user or from the previous pool. Any protocols that are not defined here expect funds to
pub static IN_TRANSFER_OPTIMIZABLE_PROTOCOLS: LazyLock<HashSet<&'static str>> = /// be in the router at the time of swap and do the transfer themselves from msg.sender
LazyLock::new(|| { pub static IN_TRANSFER_REQUIRED_PROTOCOLS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
let mut set = HashSet::new(); let mut set = HashSet::new();
set.insert("uniswap_v2"); set.insert("uniswap_v2");
set.insert("sushiswap_v2"); set.insert("sushiswap_v2");
set.insert("pancakeswap_v2"); set.insert("pancakeswap_v2");
set.insert("uniswap_v3"); set.insert("uniswap_v3");
set.insert("pancakeswap_v3"); set.insert("pancakeswap_v3");
set.insert("ekubo_v2"); set.insert("ekubo_v2");
set set
}); });
// These protocols do not support chained swaps. The tokens can not be sent directly from the // The protocols here are a subset of the ones defined in IN_TRANSFER_REQUIRED_PROTOCOLS. The tokens
// previous pool into a pool of this protocol. The tokens need to be sent to the router and only // can not be sent directly from the previous pool into a pool of this protocol. The tokens need to
// then transferred into the pool. This is the case for uniswap v3 because of the callback logic. // be sent to the router and only then transferred into the pool. This is the case for uniswap v3
// The only way for this to work it would be to call the second swap during the callback of the // because of the callback logic. The only way for this to work it would be to call the second swap
// first swap. This is currently not supported. // during the callback of the first swap. This is currently not supported.
pub static UNSUPPORTED_PROTOCOLS_FOR_CHAINED_SWAPS: LazyLock<HashSet<&'static str>> = pub static CALLBACK_CONSTRAINED_PROTOCOLS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
LazyLock::new(|| { let mut set = HashSet::new();
let mut set = HashSet::new(); set.insert("uniswap_v3");
set.insert("uniswap_v3"); set.insert("pancakeswap_v3");
set.insert("pancakeswap_v3"); set
set });
});

View File

@@ -8,7 +8,7 @@ use crate::encoding::{
errors::EncodingError, errors::EncodingError,
evm::{ evm::{
approvals::permit2::Permit2, approvals::permit2::Permit2,
constants::{IN_TRANSFER_OPTIMIZABLE_PROTOCOLS, UNSUPPORTED_PROTOCOLS_FOR_CHAINED_SWAPS}, constants::{CALLBACK_CONSTRAINED_PROTOCOLS, IN_TRANSFER_REQUIRED_PROTOCOLS},
group_swaps::group_swaps, group_swaps::group_swaps,
strategy_encoder::{ strategy_encoder::{
strategy_validators::{SequentialSwapValidator, SplitSwapValidator, SwapValidator}, strategy_validators::{SequentialSwapValidator, SplitSwapValidator, SwapValidator},
@@ -308,12 +308,10 @@ impl StrategyEncoder for SequentialSwapStrategyEncoder {
// if there is a next swap // if there is a next swap
let swap_receiver = if let Some(next) = next_swap { let swap_receiver = if let Some(next) = next_swap {
// if the protocol of the next swap supports transfer in optimization // if the protocol of the next swap supports transfer in optimization
if IN_TRANSFER_OPTIMIZABLE_PROTOCOLS.contains(&next.protocol_system.as_str()) { if IN_TRANSFER_REQUIRED_PROTOCOLS.contains(&next.protocol_system.as_str()) {
// if the protocol does not allow for chained swaps, we can't optimize the // 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 // receiver of this swap nor the transfer in of the next swap
if UNSUPPORTED_PROTOCOLS_FOR_CHAINED_SWAPS if CALLBACK_CONSTRAINED_PROTOCOLS.contains(&next.protocol_system.as_str()) {
.contains(&next.protocol_system.as_str())
{
next_in_between_swap_optimization = false; next_in_between_swap_optimization = false;
self.router_address.clone() self.router_address.clone()
} else { } else {

View File

@@ -1,7 +1,7 @@
use tycho_common::Bytes; use tycho_common::Bytes;
use crate::encoding::{ use crate::encoding::{
evm::constants::IN_TRANSFER_OPTIMIZABLE_PROTOCOLS, evm::constants::IN_TRANSFER_REQUIRED_PROTOCOLS,
models::{Swap, TransferType}, models::{Swap, TransferType},
}; };
@@ -19,8 +19,8 @@ pub trait TransferOptimization {
wrap: bool, wrap: bool,
in_between_swap_optimization: bool, in_between_swap_optimization: bool,
) -> TransferType { ) -> TransferType {
let in_transfer_optimizable: bool = let in_transfer_required: bool =
IN_TRANSFER_OPTIMIZABLE_PROTOCOLS.contains(&swap.component.protocol_system.as_str()); IN_TRANSFER_REQUIRED_PROTOCOLS.contains(&swap.component.protocol_system.as_str());
let is_first_swap = swap.token_in == given_token; let is_first_swap = swap.token_in == given_token;
@@ -31,7 +31,7 @@ pub trait TransferOptimization {
// Wrapping already happened in the router so we can just use a normal transfer. // Wrapping already happened in the router so we can just use a normal transfer.
TransferType::TransferToProtocol TransferType::TransferToProtocol
} else if is_first_swap { } else if is_first_swap {
if in_transfer_optimizable { if in_transfer_required {
if permit2 { if permit2 {
// Transfer from swapper to pool using permit2. // Transfer from swapper to pool using permit2.
TransferType::TransferPermit2ToProtocol TransferType::TransferPermit2ToProtocol
@@ -47,7 +47,7 @@ pub trait TransferOptimization {
TransferType::TransferFromToRouter TransferType::TransferFromToRouter
} }
// all other swaps // all other swaps
} else if !in_transfer_optimizable || in_between_swap_optimization { } else if !in_transfer_required || in_between_swap_optimization {
// funds should already be in the router or in the next pool // funds should already be in the router or in the next pool
TransferType::None TransferType::None
} else { } else {