feat: Bring back TransferType and simplify encoding logic
Took 1 hour 53 minutes
This commit is contained in:
@@ -6,14 +6,14 @@ use tycho_common::Bytes;
|
||||
use crate::encoding::{
|
||||
errors::EncodingError,
|
||||
evm::{
|
||||
constants::GROUPABLE_PROTOCOLS,
|
||||
constants::{GROUPABLE_PROTOCOLS, IN_TRANSFER_REQUIRED_PROTOCOLS},
|
||||
group_swaps::group_swaps,
|
||||
strategy_encoder::strategy_encoders::{
|
||||
SequentialSwapStrategyEncoder, SingleSwapStrategyEncoder, SplitSwapStrategyEncoder,
|
||||
},
|
||||
swap_encoder::swap_encoder_registry::SwapEncoderRegistry,
|
||||
},
|
||||
models::{Chain, EncodingContext, NativeAction, Solution, Transaction},
|
||||
models::{Chain, EncodingContext, NativeAction, Solution, Transaction, TransferType},
|
||||
strategy_encoder::StrategyEncoder,
|
||||
tycho_encoder::TychoEncoder,
|
||||
};
|
||||
@@ -273,14 +273,20 @@ impl TychoExecutorEncoder {
|
||||
|
||||
let mut grouped_protocol_data: Vec<u8> = vec![];
|
||||
for swap in grouped_swap.swaps.iter() {
|
||||
let transfer = if IN_TRANSFER_REQUIRED_PROTOCOLS
|
||||
.contains(&swap.component.protocol_system.as_str())
|
||||
{
|
||||
TransferType::Transfer
|
||||
} else {
|
||||
TransferType::None
|
||||
};
|
||||
let encoding_context = EncodingContext {
|
||||
receiver: receiver.clone(),
|
||||
exact_out: solution.exact_out,
|
||||
router_address: None,
|
||||
group_token_in: grouped_swap.token_in.clone(),
|
||||
group_token_out: grouped_swap.token_out.clone(),
|
||||
transfer_needed: true,
|
||||
transfer_from_needed: false,
|
||||
transfer,
|
||||
};
|
||||
let protocol_data = swap_encoder.encode_swap(swap.clone(), encoding_context.clone())?;
|
||||
grouped_protocol_data.extend(protocol_data);
|
||||
@@ -462,7 +468,7 @@ mod tests {
|
||||
Bytes::from_str("0x3ede3eca2a72b3aecc820e955b36f38437d01395").unwrap()
|
||||
);
|
||||
// single swap selector
|
||||
assert_eq!(&hex::encode(transactions[0].clone().data)[..8], "cc60c623");
|
||||
assert_eq!(&hex::encode(transactions[0].clone().data)[..8], "20144a07");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -487,7 +493,7 @@ mod tests {
|
||||
let transactions = transactions.unwrap();
|
||||
assert_eq!(transactions.len(), 1);
|
||||
// single swap selector
|
||||
assert_eq!(&hex::encode(transactions[0].clone().data)[..8], "cc60c623");
|
||||
assert_eq!(&hex::encode(transactions[0].clone().data)[..8], "20144a07");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -534,7 +540,7 @@ mod tests {
|
||||
assert_eq!(transactions.len(), 1);
|
||||
assert_eq!(transactions[0].value, eth_amount_in);
|
||||
// sequential swap selector
|
||||
assert_eq!(&hex::encode(transactions[0].clone().data)[..8], "59e3efbb");
|
||||
assert_eq!(&hex::encode(transactions[0].clone().data)[..8], "e8a980d7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1148,9 +1154,7 @@ mod tests {
|
||||
"6982508145454ce325ddbe47a25d4ec3d2311933",
|
||||
// zero for one
|
||||
"00",
|
||||
// transfer from false
|
||||
"00",
|
||||
// transfer true
|
||||
// transfer type Transfer
|
||||
"01",
|
||||
// receiver
|
||||
"cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2",
|
||||
|
||||
Reference in New Issue
Block a user