feat: Add TokenTransfer class to Curve

- This needed to be in Curve so that the executor can also take care of transfers from the user into the tycho router, to avoid having transfer actions mixed between the router and executors
This commit is contained in:
TAMARA LIPOWSKI
2025-04-14 16:52:52 -04:00
committed by Diana Carvalho
parent dbc9042a2f
commit 462be5463b
7 changed files with 61 additions and 37 deletions

View File

@@ -31,7 +31,7 @@ pub static IN_TRANSFER_OPTIMIZABLE_PROTOCOLS: LazyLock<HashSet<&'static str>> =
pub static PROTOCOLS_EXPECTING_FUNDS_IN_ROUTER: LazyLock<HashSet<&'static str>> =
LazyLock::new(|| {
let mut set = HashSet::new();
set.insert("curve");
set.insert("vm:curve");
set.insert("balancer_v2");
// TODO remove uniswap_v4 when we add callback support for transfer optimizations
set.insert("uniswap_v4");

View File

@@ -27,11 +27,11 @@ pub trait TransferOptimization {
let is_first_swap =
(swap.token_in == given_token) || ((swap.token_in == wrapped_token) && wrap);
if is_first_swap && send_funds_to_pool {
if swap.token_in == native_token {
// Funds are already in router. Protocol takes care of native transfer.
TransferType::None
} else if permit2 {
if swap.token_in == native_token {
// Funds are already in router. All protocols currently take care of native transfers.
TransferType::None
} else if is_first_swap && send_funds_to_pool {
if permit2 {
// Transfer from swapper to pool using permit2.
TransferType::Permit2Transfer
} else {
@@ -39,10 +39,7 @@ pub trait TransferOptimization {
TransferType::TransferFrom
}
} else if is_first_swap && funds_expected_in_router {
if swap.token_in == native_token {
// Funds already in router. Do nothing.
TransferType::None
} else if permit2 {
if permit2 {
// Transfer from swapper to router using permit2.
TransferType::Permit2TransferToRouter
} else {

View File

@@ -545,6 +545,7 @@ impl SwapEncoder for CurveSwapEncoder {
i.to_be_bytes::<1>(),
j.to_be_bytes::<1>(),
approval_needed,
(encoding_context.transfer_type as u8).to_be_bytes(),
);
Ok(args.abi_encode_packed())
@@ -1263,6 +1264,8 @@ mod tests {
"01",
// approval needed
"01",
// transfer type
"05",
))
);
}
@@ -1329,6 +1332,8 @@ mod tests {
"00",
// approval needed
"01",
// transfer type
"05",
))
);
}
@@ -1405,6 +1410,8 @@ mod tests {
"01",
// approval needed
"01",
// transfer type
"05",
))
);
}