feat: Add encode_full_calldata to TychoEncoder trait
This is so that people can easily use it without downcasting the encoder Took 32 minutes
This commit is contained in:
@@ -39,7 +39,6 @@ pub struct TychoRouterEncoder {
|
||||
native_address: Bytes,
|
||||
wrapped_address: Bytes,
|
||||
router_address: Bytes,
|
||||
#[allow(dead_code)]
|
||||
token_in_already_in_router: bool,
|
||||
permit2: Option<Permit2>,
|
||||
}
|
||||
@@ -130,22 +129,21 @@ impl TychoRouterEncoder {
|
||||
}
|
||||
Ok(encoded_solution)
|
||||
}
|
||||
}
|
||||
|
||||
impl TychoEncoder for TychoRouterEncoder {
|
||||
fn encode_solutions(
|
||||
&self,
|
||||
solutions: Vec<Solution>,
|
||||
) -> Result<Vec<EncodedSolution>, EncodingError> {
|
||||
let mut result: Vec<EncodedSolution> = Vec::new();
|
||||
for solution in solutions.iter() {
|
||||
let encoded_solution = self.encode_solution(solution)?;
|
||||
result.push(encoded_solution);
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Encodes a list of [`Solution`]s directly into executable transactions for the Tycho router.
|
||||
///
|
||||
/// This method wraps around Tycho’s example encoding logic (see [`encode_tycho_router_call`])
|
||||
/// and should only be used for **prototyping or development**.
|
||||
///
|
||||
/// # Warning
|
||||
/// This implementation uses default logic to construct the outer calldata (e.g., for setting
|
||||
/// `minAmountOut`). This might not be optimal or safe for production use.
|
||||
///
|
||||
/// To ensure correctness, **users should implement their own encoding pipeline** using
|
||||
/// [`encode_solutions`].
|
||||
///
|
||||
/// # Returns
|
||||
/// A vector of fully constructed [`Transaction`]s that can be submitted to a node or bundler.
|
||||
#[allow(dead_code)]
|
||||
fn encode_full_calldata(
|
||||
&self,
|
||||
solutions: Vec<Solution>,
|
||||
@@ -165,20 +163,6 @@ impl TychoRouterEncoder {
|
||||
}
|
||||
Ok(transactions)
|
||||
}
|
||||
}
|
||||
|
||||
impl TychoEncoder for TychoRouterEncoder {
|
||||
fn encode_solutions(
|
||||
&self,
|
||||
solutions: Vec<Solution>,
|
||||
) -> Result<Vec<EncodedSolution>, EncodingError> {
|
||||
let mut result: Vec<EncodedSolution> = Vec::new();
|
||||
for solution in solutions.iter() {
|
||||
let encoded_solution = self.encode_solution(solution)?;
|
||||
result.push(encoded_solution);
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Raises an `EncodingError` if the solution is not considered valid.
|
||||
///
|
||||
@@ -375,6 +359,15 @@ impl TychoEncoder for TychoExecutorEncoder {
|
||||
Ok(vec![encoded_solution])
|
||||
}
|
||||
|
||||
fn encode_full_calldata(
|
||||
&self,
|
||||
_solutions: Vec<Solution>,
|
||||
) -> Result<Vec<Transaction>, EncodingError> {
|
||||
Err(EncodingError::NotImplementedError(
|
||||
"Full calldata encoding is not supported for TychoExecutorEncoder".to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Raises an `EncodingError` if the solution is not considered valid.
|
||||
///
|
||||
/// A solution is considered valid if all the following conditions are met:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::encoding::{
|
||||
errors::EncodingError,
|
||||
models::{EncodedSolution, Solution},
|
||||
models::{EncodedSolution, Solution, Transaction},
|
||||
};
|
||||
|
||||
/// A high-level interface for encoding solutions into Tycho-compatible transactions or raw call
|
||||
@@ -47,6 +47,25 @@ pub trait TychoEncoder {
|
||||
solutions: Vec<Solution>,
|
||||
) -> Result<Vec<EncodedSolution>, EncodingError>;
|
||||
|
||||
/// Encodes a list of [`Solution`]s directly into executable transactions for the Tycho router.
|
||||
///
|
||||
/// This method wraps around Tycho’s example encoding logic (see [`encode_tycho_router_call`])
|
||||
/// and should only be used for **prototyping or development**.
|
||||
///
|
||||
/// # Warning
|
||||
/// This implementation uses default logic to construct the outer calldata (e.g., for setting
|
||||
/// `minAmountOut`). This might not be optimal or safe for production use.
|
||||
///
|
||||
/// To ensure correctness, **users should implement their own encoding pipeline** using
|
||||
/// [`encode_solutions`].
|
||||
///
|
||||
/// # Returns
|
||||
/// A vector of fully constructed [`Transaction`]s that can be submitted to a node or bundler.
|
||||
fn encode_full_calldata(
|
||||
&self,
|
||||
solutions: Vec<Solution>,
|
||||
) -> Result<Vec<Transaction>, EncodingError>;
|
||||
|
||||
/// Performs solution-level validation and sanity checks.
|
||||
///
|
||||
/// This function can be used to verify whether a proposed solution is structurally sound and
|
||||
|
||||
Reference in New Issue
Block a user