dexter_vault/
error.rs

1use cosmwasm_std::{OverflowError, StdError, Uint128};
2use thiserror::Error;
3use dexter::asset::AssetInfo;
4
5#[derive(Error, Debug, PartialEq)]
6pub enum ContractError {
7    #[error("{0}")]
8    Std(#[from] StdError),
9
10    #[error("Unauthorized")]
11    Unauthorized {},
12
13    #[error("CodeId cannot be 0")]
14    InvalidCodeId {},
15
16    #[error("InvalidSubMsgId")]
17    InvalidSubMsgId {},
18
19    #[error("Invalid lp token name")]
20    InvalidLpTokenName {},
21
22    #[error("Invalid lp token symbol")]
23    InvalidLpTokenSymbol {},
24
25    #[error("Invalid PoolId")]
26    InvalidPoolId {},
27
28    #[error("LP Token address not found")]
29    LpTokenNotFound {},
30
31    #[error("Swap in / out amount cannot be 0")]
32    SwapAmountZero {},
33
34    #[error("Number of LP tokens to burn when withdrawing liquidity cannot be 0")]
35    BurnAmountZero {},
36
37    #[error("MaxSpendError - offer amount {offer_amount} is more than maximum allowed spent amount {max_spend}")]
38    MaxSpendError {
39        max_spend: Uint128,
40        offer_amount: Uint128,
41    },
42
43    #[error("MinReceiveError - return amount {ask_amount} is less than minimum requested amount {min_receive}")]
44    MinReceiveError {
45        min_receive: Uint128,
46        ask_amount: Uint128,
47    },
48
49    #[error("Pool Type already exists")]
50    PoolTypeAlreadyExists {},
51
52    #[error("Insufficient number of {denom} tokens sent. Tokens sent = {sent}. Tokens needed = {needed}")]
53    InsufficientNativeTokensSent {
54        denom: String,
55        sent: Uint128,
56        needed: Uint128,
57    },
58
59    #[error("ReceivedUnexpectedLpTokens - expected: {expected}, received: {received}")]
60    ReceivedUnexpectedLpTokens {
61        expected: Uint128,
62        received: Uint128,
63    },
64
65    #[error("PoolExitTransitionLpToBurnMismatch - expected_to_burn: {expected_to_burn}, actual_burn: {actual_burn}")]
66    PoolExitTransitionLpToBurnMismatch {
67        expected_to_burn: Uint128,
68        actual_burn: Uint128,
69    },
70
71    #[error("PoolExitTransitionAssetsOutMismatch - expected_assets_out: {expected_assets_out}, actual_assets_out: {actual_assets_out}")]
72    PoolExitTransitionAssetsOutMismatch {
73        expected_assets_out: String,
74        actual_assets_out: String,
75    },
76
77    #[error("MinAssetOutError - return amount {return_amount} is less than minimum requested amount {min_receive} for asset {asset_info}")]
78    MinAssetOutError {
79        return_amount: Uint128,
80        min_receive: Uint128,
81        asset_info: AssetInfo,
82    },
83
84    #[error("MaxLpToBurnError - burn amount {burn_amount} is more than maximum LP to burn {max_lp_to_burn} allowed by the user")]
85    MaxLpToBurnError {
86        burn_amount: Uint128,
87        max_lp_to_burn: Uint128,
88    },
89
90    #[error("Cannot burn more LP tokens than what's been sent by the users")]
91    InsufficientLpTokensToExit {},
92
93    #[error("Invalid number of assets")]
94    InvalidNumberOfAssets {},
95
96    #[error("Pool logic not satisfied. Reason : {error}")]
97    PoolQueryFailed { error: String },
98
99    #[error("Mismatched assets")]
100    MismatchedAssets {},
101
102    #[error("Invalid sequence of assets")]
103    InvalidSequenceOfAssets {},
104
105    #[error("Time limit for trade exceeded")]
106    DeadlineExpired {},
107
108    #[error("Amount cannot be 0")]
109    AmountCannotBeZero {},
110
111    #[error("Cannot swap same tokens")]
112    SameTokenError {},
113
114    #[error("Insufficient number of native tokens sent to the Vault")]
115    InsufficientTokensSent {},
116
117    #[error("Swap limit exceeded")]
118    SwapLimit {},
119
120    #[error("Duplicate of Pool Configs")]
121    PoolTypeConfigDuplicate {},
122
123    #[error("Invalid FeeInfo params")]
124    InvalidFeeInfo {},
125
126    #[error("Config for pool type not found")]
127    PoolTypeConfigNotFound {},
128
129    #[error("Pool is currently disabled. No new pool instances can be created")]
130    PoolConfigDisabled {},
131
132    #[error("Repeated assets in asset infos")]
133    RepeatedAssets {},
134
135    #[error("Address already whitelisted")]
136    AddressAlreadyWhitelisted,
137
138    #[error("Address is not whitelisted currently")]
139    AddressNotWhitelisted,
140
141    #[error("Creation of this pool type is disabled")]
142    PoolTypeCreationDisabled,
143
144    #[error("Cannot add admin to whitelist. Admin is always whitelisted by default")]
145    CannotAddOwnerToWhitelist,
146
147    #[error("Pool creation fee must be non-zero if enabled")]
148    InvalidPoolCreationFee,
149
150    #[error("Auto staking is disabled for vault")]
151    AutoStakeDisabled,
152
153    #[error("Deposits are paused")]
154    PausedDeposit,
155
156    #[error("Swaps are paused")]
157    PausedSwap,
158
159    #[error("LP Token ID is not configured")]
160    LpTokenCodeIdNotSet,
161
162    #[error("Fee collector address is not configured")]
163    FeeCollectorNotSet,
164
165    #[error("Invalid native asset precision list provided. It should only and exactly contain all native assets of the pool")]
166    InvalidNativeAssetPrecisionList,
167
168    #[error("Non zero precision value upto 18 is supported")]
169    UnsupportedPrecision,
170
171    #[error("Imbalanced exit is paused. Normal exit for a pool is always allowed")]
172    ImbalancedExitPaused,
173
174    #[error("Invalid contract version for upgrade {upgrade_version}. Expected: {expected}, Actual: {actual}")]
175    InvalidContractVersionForUpgrade {
176        upgrade_version: String,
177        expected: String,
178        actual: String,
179    },
180
181    #[error("Invalid contract name for migration. Expected: {expected}, Actual: {actual}")]
182    InvalidContractNameForMigration { expected: String, actual: String },
183}
184
185impl From<OverflowError> for ContractError {
186    fn from(o: OverflowError) -> Self {
187        StdError::from(o).into()
188    }
189}