Files
tycho-execution/src/encoding/strategy_encoder.rs
Diana Carvalho 4e8c6ddc8c feat: Separate encoding swaps from encoding txs
This way the user is responsible for encoding the Tycho Router method inputs that are used as guardrails in execution.

Interface changes:
- Create EncodedSolution
- StrategyEncoder
  - don't need to know have permit2 or token_in_already_in_router as attributes anymore
  - encode_strategy returns EncodedSolution now (no method encoding done here now)
- TychoEncoder
  - add encode_solution() method. This is the recommended method for users
  - needs to have permit2, token_in_already_in_router and router_address as attributes
  - permit creation is made in the router now

Also:
- create encoding_utils.rs
- update all tests

Took 2 hours 42 minutes


Took 3 minutes

Took 13 minutes
2025-05-22 14:43:12 +01:00

34 lines
1.3 KiB
Rust

use crate::encoding::{
errors::EncodingError,
models::{EncodedSolution, Solution},
swap_encoder::SwapEncoder,
};
/// A trait that defines how to encode a `Solution` for execution.
pub trait StrategyEncoder {
/// `encode_strategy` takes a `Solution`, which contains all the necessary information about
/// the swaps to be performed, and encodes it into a format that can be executed by the router
/// or executor contracts.
///
/// # Arguments
/// * `solution` - The `Solution` to encode, containing swap details, amounts, and execution
/// path
///
/// # Returns
/// * `Result<EncodedSwaps, EncodingError>`
fn encode_strategy(&self, solution: Solution) -> Result<EncodedSolution, EncodingError>;
/// Retrieves the swap encoder for a specific protocol system.
///
/// # Arguments
/// * `protocol_system` - The identifier of the protocol system (e.g., "uniswap_v2")
///
/// # Returns
/// * `Option<&Box<dyn SwapEncoder>>` - The swap encoder for the protocol if available
#[allow(clippy::borrowed_box)]
fn get_swap_encoder(&self, protocol_system: &str) -> Option<&Box<dyn SwapEncoder>>;
/// Creates a cloned instance of the strategy encoder.
fn clone_box(&self) -> Box<dyn StrategyEncoder>;
}