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
This commit is contained in:
Diana Carvalho
2025-05-21 13:33:46 +01:00
parent 6a6955d31d
commit 4e8c6ddc8c
12 changed files with 869 additions and 420 deletions

View File

@@ -1,6 +1,8 @@
use tycho_common::Bytes;
use crate::encoding::{errors::EncodingError, models::Solution, swap_encoder::SwapEncoder};
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 {
@@ -13,11 +15,8 @@ pub trait StrategyEncoder {
/// path
///
/// # Returns
/// * `Result<(Vec<u8>, Bytes, Option<String>), EncodingError>` - A tuple containing:
/// - The encoded data as bytes
/// - The address of the contract to call (router or executor)
/// - Optionally, the function selector to use when calling the contract
fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError>;
/// * `Result<EncodedSwaps, EncodingError>`
fn encode_strategy(&self, solution: Solution) -> Result<EncodedSolution, EncodingError>;
/// Retrieves the swap encoder for a specific protocol system.
///