tycho_common/simulation/
errors.rs

1use thiserror::Error;
2
3use crate::simulation::protocol_sim::GetAmountOutResult;
4
5/// Represents the outer-level, user-facing errors of the tycho-simulation package.
6///
7/// `SimulationError` encompasses all possible errors that can occur in the package,
8/// wrapping lower-level errors in a user-friendly way for easier handling and display.
9/// Variants:
10/// - `RecoverableError`: Indicates that the simulation has failed with a recoverable error.
11///   Retrying at a later time may succeed. It may have failed due to a temporary issue, such as a
12///   network problem.
13/// - `InvalidInput`: Indicates that the simulation has failed due to bad input parameters.
14/// - `FatalError`: There is a bug with this pool or protocol - do not attempt simulation again.
15#[derive(Error, Debug)]
16pub enum SimulationError {
17    #[error("Fatal error: {0}")]
18    FatalError(String),
19    #[error("Invalid input: {0}")]
20    InvalidInput(String, Option<GetAmountOutResult>),
21    #[error("Recoverable error: {0}")]
22    RecoverableError(String),
23}
24
25#[derive(Debug)]
26pub enum TransitionError<T> {
27    OutOfOrder { state: T, event: T },
28    MissingAttribute(String),
29    DecodeError(String),
30    InvalidEventType(),
31    SimulationError(SimulationError),
32}
33
34impl<T> From<SimulationError> for TransitionError<T> {
35    fn from(error: SimulationError) -> Self {
36        TransitionError::SimulationError(error)
37    }
38}