The transfer from the user into the router is supposed to happen in the router (we only support this in the executors for callback constrained protocols). This is necessary because of some security concerns that were found in the audit. This way we reduce the space of attack. - Refactored TransferOptimization not to handle TransferTypes anymore but just return bools. - Split get_transfer_type into get_transfers and get_in_between_transfer. Updates tests - Updated the strategies to use this - Updated function signatures to pass transfer_from and funds_receiver - Updated SwapEncoders to handle this - SplitSwapStrategy just assumes all tokens are sent to and from the router at all times Took 2 hours 46 minutes
51 lines
2.3 KiB
Rust
51 lines
2.3 KiB
Rust
use std::{collections::HashSet, sync::LazyLock};
|
|
|
|
pub const DEFAULT_EXECUTORS_JSON: &str = include_str!("../../../config/executor_addresses.json");
|
|
pub const DEFAULT_ROUTERS_JSON: &str = include_str!("../../../config/router_addresses.json");
|
|
pub const PROTOCOL_SPECIFIC_CONFIG: &str =
|
|
include_str!("../../../config/protocol_specific_addresses.json");
|
|
|
|
/// These protocols support the optimization of grouping swaps.
|
|
///
|
|
/// This requires special encoding to send call data of multiple swaps to a single executor,
|
|
/// as if it were a single swap. The protocol likely uses flash accounting to save gas on token
|
|
/// transfers.
|
|
pub static GROUPABLE_PROTOCOLS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
|
|
let mut set = HashSet::new();
|
|
set.insert("uniswap_v4");
|
|
set.insert("vm:balancer_v3");
|
|
set.insert("ekubo_v2");
|
|
set
|
|
});
|
|
|
|
/// These protocols need an external in transfer to the pool. This transfer can be from the router,
|
|
/// from the user or from the previous pool. Any protocols that are not defined here expect funds to
|
|
/// be in the router at the time of swap and do the transfer themselves from `msg.sender`
|
|
pub static IN_TRANSFER_REQUIRED_PROTOCOLS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
|
|
let mut set = HashSet::new();
|
|
set.insert("uniswap_v2");
|
|
set.insert("sushiswap_v2");
|
|
set.insert("pancakeswap_v2");
|
|
set.insert("uniswap_v3");
|
|
set.insert("pancakeswap_v3");
|
|
set.insert("uniswap_v4");
|
|
set.insert("ekubo_v2");
|
|
set.insert("vm:maverick_v2");
|
|
set
|
|
});
|
|
|
|
// The protocols here are a subset of the ones defined in IN_TRANSFER_REQUIRED_PROTOCOLS. The in
|
|
// transfer needs to be performed inside the callback logic. This means, 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 CALLBACK_CONSTRAINED_PROTOCOLS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
|
|
let mut set = HashSet::new();
|
|
set.insert("uniswap_v3");
|
|
set.insert("pancakeswap_v3");
|
|
set.insert("uniswap_v4");
|
|
set.insert("ekubo_v2");
|
|
set
|
|
});
|