1use 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#[derive(Error, Debug, PartialEq)]
16
17pub enum CwDexError {
18 #[error("{0}")]
20 Std(#[from] StdError),
21
22 #[error("{0}")]
24 TryFromIntError(#[from] TryFromIntError),
25
26 #[error("{0}")]
28 Overflow(#[from] OverflowError),
29
30 #[error("{0}")]
32 DivideByZero(#[from] DivideByZeroError),
33
34 #[error("Infallible")]
36 Infallible(#[from] std::convert::Infallible),
37
38 #[error("Invalid output asset")]
40 InvalidOutAsset {},
41
42 #[error("Invalid input asset: {a}")]
44 InvalidInAsset {
45 a: Asset,
47 },
48
49 #[error("Invalid LP token")]
51 InvalidLpToken {},
52
53 #[error("Overflow when converting to from BigInt to Uint128")]
55 BigIntOverflow {},
56
57 #[error("Event of zero transfer")]
59 InvalidZeroAmount {},
60
61 #[error("Insufficient amount of liquidity")]
63 LiquidityAmountTooSmall {},
64
65 #[error("It is not possible to provide liquidity with one token for an empty pool")]
67 InvalidProvideLPsWithSingleToken {},
68
69 #[error("Asset is not an LP token")]
71 NotLpToken {},
72
73 #[error("Expected no unbonding period")]
75 UnstakingDurationNotSupported {},
76
77 #[error(
79 "Did not receive expected amount of tokens. Expected: {min_out}, received: {received}"
80 )]
81 MinOutNotReceived {
82 min_out: Uint128,
84 received: Uint128,
86 },
87
88 #[error("Could not parse address: {token_denom}")]
90 AddressParsingErrors {
91 token_denom: String,
93 },
94
95 #[error("Unsupported arguments. Reason: {reason}")]
98 UnsupportedArguments {
99 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}