Files
tycho-execution/src/encoding/errors.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

44 lines
1.4 KiB
Rust

use std::{io, str::Utf8Error};
use thiserror::Error;
/// Represents the outer-level, user-facing errors of the tycho-execution encoding package.
///
/// `EncodingError` encompasses all possible errors that can occur in the package,
/// wrapping lower-level errors in a user-friendly way for easier handling and display.
/// Variants:
/// - `InvalidInput`: Indicates that the encoding has failed due to bad input parameters.
/// - `FatalError`: There is problem with the application setup.
/// - `RecoverableError`: Indicates that the encoding has failed with a recoverable error. Retrying
/// at a later time may succeed. It may have failed due to a temporary issue, such as a network
/// problem.
#[derive(Error, Debug, PartialEq)]
pub enum EncodingError {
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Fatal error: {0}")]
FatalError(String),
#[error("Recoverable error: {0}")]
RecoverableError(String),
#[error("Not implemented: {0}")]
NotImplementedError(String),
}
impl From<io::Error> for EncodingError {
fn from(err: io::Error) -> Self {
EncodingError::FatalError(err.to_string())
}
}
impl From<serde_json::Error> for EncodingError {
fn from(err: serde_json::Error) -> Self {
EncodingError::FatalError(err.to_string())
}
}
impl From<Utf8Error> for EncodingError {
fn from(err: Utf8Error) -> Self {
EncodingError::FatalError(err.to_string())
}
}