Merge branch 'refs/heads/main' into hooks/dc/ENG-4624-pass-hook-data

# Conflicts:
#	foundry/test/assets/calldata.txt

Took 9 minutes
This commit is contained in:
Diana Carvalho
2025-07-31 17:50:45 +01:00
53 changed files with 5302 additions and 643 deletions

View File

@@ -1,7 +1,7 @@
use std::{collections::HashSet, str::FromStr};
use alloy::signers::local::PrivateKeySigner;
use tycho_common::Bytes;
use tycho_common::{models::Chain, Bytes};
use crate::encoding::{
errors::EncodingError,
@@ -17,7 +17,7 @@ use crate::encoding::{
utils::ple_encode,
},
models::{
Chain, EncodedSolution, EncodingContext, NativeAction, Solution, Transaction, TransferType,
EncodedSolution, EncodingContext, NativeAction, Solution, Transaction, TransferType,
UserTransferType,
},
strategy_encoder::StrategyEncoder,
@@ -62,19 +62,19 @@ impl TychoRouterEncoder {
};
Ok(TychoRouterEncoder {
single_swap_strategy: SingleSwapStrategyEncoder::new(
chain.clone(),
chain,
swap_encoder_registry.clone(),
user_transfer_type.clone(),
router_address.clone(),
)?,
sequential_swap_strategy: SequentialSwapStrategyEncoder::new(
chain.clone(),
chain,
swap_encoder_registry.clone(),
user_transfer_type.clone(),
router_address.clone(),
)?,
split_swap_strategy: SplitSwapStrategyEncoder::new(
chain.clone(),
chain,
swap_encoder_registry,
user_transfer_type.clone(),
router_address.clone(),
@@ -154,11 +154,11 @@ impl TychoEncoder for TychoRouterEncoder {
let encoded_solution = self.encode_solution(solution)?;
let transaction = encode_tycho_router_call(
self.chain.id,
self.chain.id(),
encoded_solution,
solution,
&self.user_transfer_type,
&self.chain.native_token()?,
&self.chain.native_token().address,
self.signer.clone(),
)?;
@@ -187,8 +187,11 @@ impl TychoEncoder for TychoRouterEncoder {
if solution.swaps.is_empty() {
return Err(EncodingError::FatalError("No swaps found in solution".to_string()));
}
let native_address = self.chain.native_token()?;
let wrapped_address = self.chain.wrapped_token()?;
let native_address = self.chain.native_token().address;
let wrapped_address = self
.chain
.wrapped_native_token()
.address;
if let Some(native_action) = &solution.native_action {
if native_action == &NativeAction::Wrap {
if solution.given_token != native_address {
@@ -400,7 +403,7 @@ mod tests {
use std::{collections::HashMap, str::FromStr};
use num_bigint::{BigInt, BigUint};
use tycho_common::models::{protocol::ProtocolComponent, Chain as TychoCommonChain};
use tycho_common::models::{protocol::ProtocolComponent, Chain};
use super::*;
use crate::encoding::models::Swap;
@@ -432,7 +435,7 @@ mod tests {
// Fee and tick spacing information for this test is obtained by querying the
// USV4 Position Manager contract: 0xbd216513d74c8cf14cf4747e6aaa6420ff64ee9e
// Using the poolKeys function with the first 25 bytes of the pool id
fn swap_usdc_eth_univ4() -> Swap {
fn swap_usdc_eth_univ4() -> Swap<'static> {
let pool_fee_usdc_eth = Bytes::from(BigInt::from(3000).to_signed_bytes_be());
let tick_spacing_usdc_eth = Bytes::from(BigInt::from(60).to_signed_bytes_be());
let mut static_attributes_usdc_eth: HashMap<String, Bytes> = HashMap::new();
@@ -450,10 +453,11 @@ mod tests {
token_out: eth().clone(),
split: 0f64,
user_data: None,
protocol_state: None,
}
}
fn swap_eth_pepe_univ4() -> Swap {
fn swap_eth_pepe_univ4() -> Swap<'static> {
let pool_fee_eth_pepe = Bytes::from(BigInt::from(25000).to_signed_bytes_be());
let tick_spacing_eth_pepe = Bytes::from(BigInt::from(500).to_signed_bytes_be());
let mut static_attributes_eth_pepe: HashMap<String, Bytes> = HashMap::new();
@@ -471,6 +475,7 @@ mod tests {
token_out: pepe().clone(),
split: 0f64,
user_data: None,
protocol_state: None,
}
}
@@ -479,7 +484,7 @@ mod tests {
}
fn eth_chain() -> Chain {
TychoCommonChain::Ethereum.into()
Chain::Ethereum
}
fn get_swap_encoder_registry() -> SwapEncoderRegistry {
@@ -519,6 +524,7 @@ mod tests {
token_out: dai(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {
@@ -584,6 +590,7 @@ mod tests {
token_out: dai(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let swap_dai_usdc = Swap {
@@ -596,6 +603,7 @@ mod tests {
token_out: usdc(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {
@@ -676,6 +684,7 @@ mod tests {
token_out: dai(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {
@@ -705,6 +714,7 @@ mod tests {
token_out: dai(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {
@@ -739,6 +749,7 @@ mod tests {
token_out: dai(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {
@@ -793,6 +804,7 @@ mod tests {
token_out: weth(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {
@@ -821,6 +833,7 @@ mod tests {
token_out: weth(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {
@@ -856,6 +869,7 @@ mod tests {
token_out: eth(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {
@@ -896,6 +910,7 @@ mod tests {
token_out: weth(),
split: 0.5f64,
user_data: None,
protocol_state: None,
},
Swap {
component: ProtocolComponent {
@@ -907,6 +922,7 @@ mod tests {
token_out: weth(),
split: 0f64,
user_data: None,
protocol_state: None,
},
Swap {
component: ProtocolComponent {
@@ -918,6 +934,7 @@ mod tests {
token_out: dai(),
split: 0f64,
user_data: None,
protocol_state: None,
},
];
@@ -951,6 +968,7 @@ mod tests {
token_out: weth(),
split: 0f64,
user_data: None,
protocol_state: None,
},
Swap {
component: ProtocolComponent {
@@ -962,6 +980,7 @@ mod tests {
token_out: usdc(),
split: 0f64,
user_data: None,
protocol_state: None,
},
Swap {
component: ProtocolComponent {
@@ -973,6 +992,7 @@ mod tests {
token_out: dai(),
split: 0f64,
user_data: None,
protocol_state: None,
},
Swap {
component: ProtocolComponent {
@@ -984,6 +1004,7 @@ mod tests {
token_out: wbtc(),
split: 0f64,
user_data: None,
protocol_state: None,
},
];
@@ -1024,6 +1045,7 @@ mod tests {
token_out: dai(),
split: 0f64,
user_data: None,
protocol_state: None,
},
Swap {
component: ProtocolComponent {
@@ -1035,6 +1057,7 @@ mod tests {
token_out: weth(),
split: 0.5f64,
user_data: None,
protocol_state: None,
},
Swap {
component: ProtocolComponent {
@@ -1046,6 +1069,7 @@ mod tests {
token_out: weth(),
split: 0f64,
user_data: None,
protocol_state: None,
},
];
@@ -1079,6 +1103,7 @@ mod tests {
token_out: dai(),
split: 0f64,
user_data: None,
protocol_state: None,
},
Swap {
component: ProtocolComponent {
@@ -1090,6 +1115,7 @@ mod tests {
token_out: weth(),
split: 0f64,
user_data: None,
protocol_state: None,
},
];
@@ -1144,6 +1170,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {
@@ -1204,6 +1231,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let solution = Solution {