feat: upgrade tycho deps in protocol-testing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use alloy::{primitives::Keccak256, sol_types::SolValue};
|
||||
use miette::{miette, IntoDiagnostic, WrapErr};
|
||||
use num_bigint::BigUint;
|
||||
use tycho_common::{dto::Chain, Bytes};
|
||||
use tycho_simulation::{
|
||||
@@ -17,35 +18,36 @@ use tycho_simulation::{
|
||||
|
||||
/// Encodes swap data for the Tycho router.
|
||||
///
|
||||
/// Assumes a single swap solution and encodes the data ready to be used by the Tycho router directly.
|
||||
/// Assumes a single swap solution and encodes the data ready to be used by the Tycho router
|
||||
/// directly.
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `component`: The protocol component to swap through
|
||||
/// - `token_in`: Input token address
|
||||
/// - `token_in`: Input token address
|
||||
/// - `token_out`: Output token address
|
||||
/// - `amount_in`: Amount of input token to swap
|
||||
/// - `amount_out`: Expected amount of output token
|
||||
///
|
||||
/// # Returns
|
||||
/// A `Result<Transaction, EncodingError>` containing the encoded transaction data for the Tycho router,
|
||||
/// or an error if encoding fails.
|
||||
/// A `Result<Transaction>` containing the encoded transaction data for the Tycho
|
||||
/// router, or an error if encoding fails.
|
||||
pub fn encode_swap(
|
||||
component: ProtocolComponent,
|
||||
token_in: Bytes,
|
||||
token_out: Bytes,
|
||||
amount_in: BigUint,
|
||||
amount_out: BigUint,
|
||||
) -> Result<Transaction, EncodingError> {
|
||||
) -> miette::Result<Transaction> {
|
||||
let chain: tycho_common::models::Chain = Chain::Ethereum.into();
|
||||
let alice_address =
|
||||
Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2").map_err(|_| {
|
||||
EncodingError::FatalError("Alice's address can't be converted to Bytes".to_string())
|
||||
})?;
|
||||
let alice_address = Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2")
|
||||
.into_diagnostic()
|
||||
.wrap_err(miette!("Failed to parse Alice's address for Tycho router encoding"))?;
|
||||
let encoder = TychoRouterEncoderBuilder::new()
|
||||
.chain(chain)
|
||||
.user_transfer_type(UserTransferType::TransferFrom)
|
||||
.build()
|
||||
.expect("Failed to build encoder");
|
||||
.into_diagnostic()
|
||||
.wrap_err(miette!("Failed to build encoder"))?;
|
||||
|
||||
let swap = SwapBuilder::new(component, token_in.clone(), token_out.clone()).build();
|
||||
|
||||
@@ -69,10 +71,12 @@ pub fn encode_swap(
|
||||
|
||||
let encoded_solution = encoder
|
||||
.encode_solutions(vec![solution.clone()])
|
||||
.expect("Failed to encode router calldata")[0]
|
||||
.into_diagnostic()
|
||||
.wrap_err(miette!("Failed to encode router calldata"))?[0]
|
||||
.clone();
|
||||
|
||||
encode_tycho_router_call(encoded_solution, &solution, &chain.wrapped_native_token().address)
|
||||
.into_diagnostic()
|
||||
}
|
||||
|
||||
/// Encodes a transaction for the Tycho Router using `singleSwap` method and regular token
|
||||
|
||||
@@ -533,13 +533,13 @@ fn validate_state(
|
||||
|
||||
let protocol_component = block_msg.new_pairs.get(id);
|
||||
if let Some(pc) = protocol_component {
|
||||
let calldata = encode_swap(
|
||||
encode_swap(
|
||||
pc.clone(),
|
||||
token_in.address.clone(),
|
||||
token_out.address.clone(),
|
||||
amount_in,
|
||||
amount_out_result.amount,
|
||||
);
|
||||
)?;
|
||||
info!("Encoded swap successfully");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user