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:
@@ -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.
|
/// 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>> =
|
pub static IN_TRANSFER_OPTIMIZABLE_PROTOCOLS: LazyLock<HashSet<&'static str>> =
|
||||||
LazyLock::new(|| {
|
LazyLock::new(|| {
|
||||||
let mut set = HashSet::new();
|
let mut set = HashSet::new();
|
||||||
@@ -31,10 +32,12 @@ pub static IN_TRANSFER_OPTIMIZABLE_PROTOCOLS: LazyLock<HashSet<&'static str>> =
|
|||||||
set
|
set
|
||||||
});
|
});
|
||||||
|
|
||||||
// These protocols do not support chained swaps from the same protocol. This is the case for uniswap
|
// These protocols do not support chained swaps. The tokens can not be sent directly from the
|
||||||
// v3 because of the callback logic. The only way for this to work it would be to call the second
|
// previous pool into a pool of this protocol. The tokens need to be sent to the router and only
|
||||||
// swap during the callback of the first swap. This is currently not supported.
|
// then transferred into the pool. This is the case for uniswap v3 because of the callback logic.
|
||||||
pub static PROTOCOLS_NOT_OPTIMIZED_CHAINED_SWAPS: LazyLock<HashSet<&'static str>> =
|
// 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(|| {
|
LazyLock::new(|| {
|
||||||
let mut set = HashSet::new();
|
let mut set = HashSet::new();
|
||||||
set.insert("uniswap_v3");
|
set.insert("uniswap_v3");
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::encoding::{
|
|||||||
errors::EncodingError,
|
errors::EncodingError,
|
||||||
evm::{
|
evm::{
|
||||||
approvals::permit2::Permit2,
|
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,
|
group_swaps::group_swaps,
|
||||||
strategy_encoder::{
|
strategy_encoder::{
|
||||||
strategy_validators::{SequentialSwapValidator, SplitSwapValidator, SwapValidator},
|
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 IN_TRANSFER_OPTIMIZABLE_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 PROTOCOLS_NOT_OPTIMIZED_CHAINED_SWAPS
|
if UNSUPPORTED_PROTOCOLS_FOR_CHAINED_SWAPS
|
||||||
.contains(&next.protocol_system.as_str()) &&
|
.contains(&next.protocol_system.as_str())
|
||||||
PROTOCOLS_NOT_OPTIMIZED_CHAINED_SWAPS.contains(protocol.as_str())
|
|
||||||
{
|
{
|
||||||
next_in_between_swap_optimization = false;
|
next_in_between_swap_optimization = false;
|
||||||
self.router_address.clone()
|
self.router_address.clone()
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ pub trait TransferOptimization {
|
|||||||
} else if (swap.token_in == wrapped_token) && wrap {
|
} else if (swap.token_in == wrapped_token) && wrap {
|
||||||
// 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
|
||||||
// first swap
|
|
||||||
} else if is_first_swap {
|
} else if is_first_swap {
|
||||||
if in_transfer_optimizable {
|
if in_transfer_optimizable {
|
||||||
if permit2 {
|
if permit2 {
|
||||||
|
|||||||
Reference in New Issue
Block a user