cw_dex/
error.rs

1//! This crate contains the enum CwDexError with variants for contract errors,
2//! and related functions
3
4use std::num::TryFromIntError;
5
6use apollo_cw_asset::Asset;
7use cosmwasm_std::{DivideByZeroError, OverflowError, StdError, Uint128};
8use thiserror::Error;
9
10#[cfg(feature = "backtraces")]
11use std::backtrace::Backtrace;
12
13/// ## Description
14/// This enum describes router-test contract errors!
15#[derive(Error, Debug, PartialEq)]
16
17pub enum CwDexError {
18    /// Converts from `cosmwasm_std::StdError`
19    #[error("{0}")]
20    Std(#[from] StdError),
21
22    /// Converts from `std::num::TryFromIntError`
23    #[error("{0}")]
24    TryFromIntError(#[from] TryFromIntError),
25
26    /// Converts from `cosmwasm_std::OverflowError`
27    #[error("{0}")]
28    Overflow(#[from] OverflowError),
29
30    /// Converts from `cosmwasm_std::DivideByZeroError`
31    #[error("{0}")]
32    DivideByZero(#[from] DivideByZeroError),
33
34    /// Converts from `std::convert::Infallible`
35    #[error("Infallible")]
36    Infallible(#[from] std::convert::Infallible),
37
38    /// Invalid Reply ID Error
39    #[error("Invalid output asset")]
40    InvalidOutAsset {},
41
42    /// Invalid input asset
43    #[error("Invalid input asset: {a}")]
44    InvalidInAsset {
45        /// The asset in question
46        a: Asset,
47    },
48
49    /// Invalid LP token
50    #[error("Invalid LP token")]
51    InvalidLpToken {},
52
53    /// Overflow when converting to from BigInt to Uint128
54    #[error("Overflow when converting to from BigInt to Uint128")]
55    BigIntOverflow {},
56
57    /// Zero funds transfer
58    #[error("Event of zero transfer")]
59    InvalidZeroAmount {},
60
61    /// Insufficient amount of liquidity
62    #[error("Insufficient amount of liquidity")]
63    LiquidityAmountTooSmall {},
64
65    /// Results from single-sided entry into empty pool
66    #[error("It is not possible to provide liquidity with one token for an empty pool")]
67    InvalidProvideLPsWithSingleToken {},
68
69    /// Asset is not an LP token
70    #[error("Asset is not an LP token")]
71    NotLpToken {},
72
73    /// When unstaking/unbonding is expected to be instant
74    #[error("Expected no unbonding period")]
75    UnstakingDurationNotSupported {},
76
77    /// The minimum amount of tokens requested was not returned from the action
78    #[error(
79        "Did not receive expected amount of tokens. Expected: {min_out}, received: {received}"
80    )]
81    MinOutNotReceived {
82        /// The minimum amount of tokens the user requested
83        min_out: Uint128,
84        /// The actual amount of tokens received
85        received: Uint128,
86    },
87
88    /// For when the token_denom can't be parsed
89    #[error("Could not parse address: {token_denom}")]
90    AddressParsingErrors {
91        /// The token_denom that couldn't be parsed
92        token_denom: String,
93    },
94
95    /// For when min_out is set for concentrated liquidity pools, as they do not
96    /// support min_out
97    #[error("Unsupported arguments. Reason: {reason}")]
98    UnsupportedArguments {
99        /// The reason that explains why the arguments are unsupported
100        reason: String,
101    },
102}
103
104impl From<CwDexError> for StdError {
105    fn from(x: CwDexError) -> Self {
106        Self::generic_err(String::from("CwDexError: ") + &x.to_string())
107    }
108}