1use cosmwasm_std::{Decimal, StdError};
2use thiserror::Error;
3
4#[derive(Error, Debug, PartialEq)]
5pub enum ContractError {
6 #[error("{0}")]
7 Std(#[from] StdError),
8
9 #[error("Unauthorized")]
10 Unauthorized {},
11
12 #[error("Semver parsing error: {0}")]
13 SemVer(String),
14
15 #[error("Insufficient funds sent")]
16 InsufficientFundsSend {},
17
18 #[error("Unexpected Error")]
19 UnexpectedError {},
20
21 #[error("Insufficient collateral")]
22 InsufficientCollateral {},
23
24 #[error("Premature liquidation")]
25 PrematureLiquidation {},
26
27 #[error("Duplicated liquidation")]
28 DuplicatedLiquidation {},
29
30 #[error("Failed liquidation")]
31 FailedLiquidation {},
32
33 #[error("Failed to serialize")]
34 FailedToSerialize { err_msg: String },
35
36 #[error("Failed to convert to binary")]
37 FailedToBinary { err_msg: String },
38
39 #[error("Failed to get equity and total market value")]
40 FailedToGetEquityAndTotalMarketValue { err_msg: String },
41
42 #[error("Failed to get insurance fund from storage")]
43 FailedToGetInsuranceFund {},
44
45 #[error("Failed to get order with order id")]
46 FailedToGetOrder { order_id: String },
47
48 #[error("Failed to fetch all balances")]
49 FailedToFetchBalances { err_msg: String },
50
51 #[error("Insufficient balance")]
52 InsufficientBalance {},
53
54 #[error("Insufficient balance for funding payment")]
55 InsufficientBalanceForFundingPayment {},
56
57 #[error("Invalid coin type")]
58 InvalidCoinType {},
59
60 #[error("Invalid position effect")]
61 InvalidPositionEffect {},
62
63 #[error("Invalid position direction")]
64 InvalidPositionDirection {},
65
66 #[error("Invalid cw20 token")]
67 Invalidcw20token {},
68
69 #[error("Invalid order data")]
70 InvalidOrderData {},
71
72 #[error("Insufficient open amount to close")]
73 InsufficientOpenPositionToClose {
74 intended_close_amount: Decimal,
75 can_be_closed: Decimal,
76 },
77
78 #[error("Unsupported Denom")]
79 InvalidDenom { unsupported_denom: String },
80
81 #[error("Twap does not exist")]
82 TwapNotExist {},
83
84 #[error("Order not found")]
85 OrderNotFound {},
86
87 #[error("User not whitelisted for this feature")]
88 UnwhitelistedUser {},
89
90 #[error("Pool does not have enough liquidity")]
91 InsufficientLiquidity {},
92 }
95
96impl From<semver::Error> for ContractError {
97 fn from(err: semver::Error) -> Self {
98 Self::SemVer(err.to_string())
99 }
100}