1use astroport::{asset::MINIMUM_LIQUIDITY_AMOUNT, pair::MAX_FEE_SHARE_BPS};
2use cosmwasm_std::{OverflowError, StdError, Uint128};
3use cw_utils::{ParseReplyError, PaymentError};
4use thiserror::Error;
5
6#[derive(Error, Debug, PartialEq)]
8pub enum ContractError {
9 #[error("{0}")]
10 Std(#[from] StdError),
11
12 #[error("{0}")]
13 PaymentError(#[from] PaymentError),
14
15 #[error("{0}")]
16 ParseReplyError(#[from] ParseReplyError),
17
18 #[error("Unauthorized")]
19 Unauthorized {},
20
21 #[error("CW20 tokens can be swapped via Cw20::Send message only")]
22 Cw20DirectSwap {},
23
24 #[error("Operation non supported")]
25 NonSupported {},
26
27 #[error("Event of zero transfer")]
28 InvalidZeroAmount {},
29
30 #[error("Operation exceeds max spread limit")]
31 MaxSpreadAssertion {},
32
33 #[error("Provided spread amount exceeds allowed limit")]
34 AllowedSpreadAssertion {},
35
36 #[error("Operation exceeds max splippage tolerance")]
37 MaxSlippageAssertion {},
38
39 #[error("Slippage is more than expected: received {0}, expected {1} LP tokens")]
40 ProvideSlippageViolation(Uint128, Uint128),
41
42 #[error("Received {received} {asset_name} but expected {expected}")]
43 WithdrawSlippageViolation {
44 asset_name: String,
45 received: Uint128,
46 expected: Uint128,
47 },
48
49 #[error("Wrong asset length: expected {expected}, actual {actual}")]
50 WrongAssetLength { expected: usize, actual: usize },
51
52 #[error("Doubling assets in asset infos")]
53 DoublingAssets {},
54
55 #[error("Asset mismatch between the requested and the stored asset in contract")]
56 AssetMismatch {},
57
58 #[error("Pair type mismatch. Check factory pair configs")]
59 PairTypeMismatch {},
60
61 #[error("Incentives address is not set in factory. Cannot auto-stake")]
62 AutoStakeError {},
63
64 #[error("Initial liquidity must be more than {}", MINIMUM_LIQUIDITY_AMOUNT)]
65 MinimumLiquidityAmountError {},
66
67 #[error("Failed to migrate the contract")]
68 MigrationError {},
69
70 #[error("Failed to parse or process reply message")]
71 FailedToParseReply {},
72
73 #[error(
74 "Fee share is 0 or exceeds maximum allowed value of {} bps",
75 MAX_FEE_SHARE_BPS
76 )]
77 FeeShareOutOfBounds {},
78}
79
80impl From<OverflowError> for ContractError {
81 fn from(o: OverflowError) -> Self {
82 StdError::from(o).into()
83 }
84}