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

@@ -5,7 +5,7 @@ use alloy::{
sol_types::SolValue,
};
use serde_json::from_str;
use tycho_common::Bytes;
use tycho_common::{models::Chain, Bytes};
use crate::encoding::{
errors::EncodingError,
@@ -13,7 +13,7 @@ use crate::encoding::{
approvals::protocol_approvals_manager::ProtocolApprovalsManager,
utils::{bytes_to_address, get_static_attribute, pad_to_fixed_size},
},
models::{Chain, EncodingContext, Swap},
models::{EncodingContext, Swap},
swap_encoder::SwapEncoder,
};
@@ -428,7 +428,10 @@ impl CurveSwapEncoder {
// Some curve pools support both ETH and WETH as tokens.
// They do the wrapping/unwrapping inside the pool
fn normalize_token(&self, token: Address, coins: &[Address]) -> Result<Address, EncodingError> {
let native_token_address = bytes_to_address(&self.native_token_address)?;
let native_token_address =
Address::from_str(&self.native_token_curve_address).map_err(|_| {
EncodingError::FatalError("Invalid native token curve address".to_string())
})?;
let wrapped_native_token_address = bytes_to_address(&self.wrapped_native_token_address)?;
if token == native_token_address && !coins.contains(&token) {
Ok(wrapped_native_token_address)
@@ -461,7 +464,7 @@ impl CurveSwapEncoder {
.iter()
.position(|&addr| addr == token_out)
.ok_or(EncodingError::FatalError(format!(
"Token in address {token_in} not found in curve pool coins"
"Token in address {token_out} not found in curve pool coins"
)))?;
Ok((U8::from(i), U8::from(j)))
}
@@ -484,9 +487,9 @@ impl SwapEncoder for CurveSwapEncoder {
.to_string();
Ok(Self {
executor_address,
native_token_address: chain.native_token()?,
native_token_address: chain.native_token().address,
native_token_curve_address,
wrapped_native_token_address: chain.wrapped_token()?,
wrapped_native_token_address: chain.wrapped_native_token().address,
})
}
@@ -664,7 +667,7 @@ mod tests {
use alloy::hex::encode;
use num_bigint::BigInt;
use tycho_common::{
models::{protocol::ProtocolComponent, Chain as TychoCoreChain},
models::{protocol::ProtocolComponent, Chain},
Bytes,
};
@@ -688,6 +691,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
receiver: Bytes::from("0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e"), // BOB
@@ -699,7 +703,7 @@ mod tests {
};
let encoder = UniswapV2SwapEncoder::new(
String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
None,
)
.unwrap();
@@ -748,6 +752,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
receiver: Bytes::from("0x0000000000000000000000000000000000000001"),
@@ -759,7 +764,7 @@ mod tests {
};
let encoder = UniswapV3SwapEncoder::new(
String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
None,
)
.unwrap();
@@ -809,6 +814,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
// The receiver was generated with `makeAddr("bob") using forge`
@@ -821,7 +827,7 @@ mod tests {
};
let encoder = BalancerV2SwapEncoder::new(
String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
Some(HashMap::from([(
"vault_address".to_string(),
"0xba12222222228d8ba445958a75a0704d566bf2c8".to_string(),
@@ -882,6 +888,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
// The receiver is ALICE to match the solidity tests
@@ -896,7 +903,7 @@ mod tests {
};
let encoder = UniswapV4SwapEncoder::new(
String::from("0xF62849F9A0B5Bf2913b396098F7c7019b51A820a"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
None,
)
.unwrap();
@@ -957,6 +964,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
@@ -971,7 +979,7 @@ mod tests {
let encoder = UniswapV4SwapEncoder::new(
String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
None,
)
.unwrap();
@@ -1054,6 +1062,7 @@ mod tests {
token_out: usdt_address.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let second_swap = Swap {
@@ -1062,11 +1071,12 @@ mod tests {
token_out: wbtc_address.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoder = UniswapV4SwapEncoder::new(
String::from("0xF62849F9A0B5Bf2913b396098F7c7019b51A820a"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
None,
)
.unwrap();
@@ -1147,6 +1157,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
@@ -1158,9 +1169,7 @@ mod tests {
transfer_type: TransferType::Transfer,
};
let encoder =
EkuboSwapEncoder::new(String::default(), TychoCoreChain::Ethereum.into(), None)
.unwrap();
let encoder = EkuboSwapEncoder::new(String::default(), Chain::Ethereum, None).unwrap();
let encoded_swap = encoder
.encode_swap(&swap, &encoding_context)
@@ -1191,9 +1200,7 @@ mod tests {
let group_token_out = Bytes::from("0xdAC17F958D2ee523a2206206994597C13D831ec7"); // USDT
let intermediary_token = Bytes::from("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"); // USDC
let encoder =
EkuboSwapEncoder::new(String::default(), TychoCoreChain::Ethereum.into(), None)
.unwrap();
let encoder = EkuboSwapEncoder::new(String::default(), Chain::Ethereum, None).unwrap();
let encoding_context = EncodingContext {
receiver: RECEIVER.into(),
@@ -1220,6 +1227,7 @@ mod tests {
token_out: intermediary_token.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let second_swap = Swap {
@@ -1236,6 +1244,7 @@ mod tests {
token_out: group_token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let first_encoded_swap = encoder
@@ -1356,13 +1365,10 @@ mod tests {
token_out: Bytes::from(token_out),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoder = CurveSwapEncoder::new(
String::default(),
TychoCoreChain::Ethereum.into(),
curve_config(),
)
.unwrap();
let encoder =
CurveSwapEncoder::new(String::default(), Chain::Ethereum, curve_config()).unwrap();
let (i, j) = encoder
.get_coin_indexes(
&swap,
@@ -1400,6 +1406,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
// The receiver was generated with `makeAddr("bob") using forge`
@@ -1412,7 +1419,7 @@ mod tests {
};
let encoder = CurveSwapEncoder::new(
String::from("0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
curve_config(),
)
.unwrap();
@@ -1472,6 +1479,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
// The receiver was generated with `makeAddr("bob") using forge`
@@ -1484,7 +1492,7 @@ mod tests {
};
let encoder = CurveSwapEncoder::new(
String::from("0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
curve_config(),
)
.unwrap();
@@ -1545,6 +1553,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
// The receiver was generated with `makeAddr("bob") using forge`
@@ -1557,7 +1566,7 @@ mod tests {
};
let encoder = CurveSwapEncoder::new(
String::from("0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
Some(HashMap::from([
(
"native_token_address".to_string(),
@@ -1619,6 +1628,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
// The receiver was generated with `makeAddr("bob") using forge`
@@ -1631,7 +1641,7 @@ mod tests {
};
let encoder = BalancerV3SwapEncoder::new(
String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
None,
)
.unwrap();
@@ -1677,6 +1687,7 @@ mod tests {
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
};
let encoding_context = EncodingContext {
// The receiver was generated with `makeAddr("bob") using forge`
@@ -1689,7 +1700,7 @@ mod tests {
};
let encoder = MaverickV2SwapEncoder::new(
String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"),
TychoCoreChain::Ethereum.into(),
Chain::Ethereum,
None,
)
.unwrap();