gmsol_model/
error.rs

1use crate::{
2    position::{InsolventCloseStep, LiquidatableReason},
3    ClockKind, PnlFactorKind, PoolKind,
4};
5
6/// Error type.
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9    /// Anchor error.
10    #[cfg(feature = "solana")]
11    #[error(transparent)]
12    Solana(#[from] anchor_lang::prelude::Error),
13    /// Market errors from [`gmsol-utils`].
14    #[cfg(feature = "gmsol-utils")]
15    #[error(transparent)]
16    Market(#[from] gmsol_utils::market::MarketError),
17    /// Unimplemented.
18    #[error("unimplemented")]
19    Unimplemented,
20    /// Invalid Argument.
21    #[error("invalid argument: {0}")]
22    InvalidArgument(&'static str),
23    /// Empty deposit.
24    #[error("empty deposit")]
25    EmptyDeposit,
26    /// Empty withdrawal.
27    #[error("empty withdrawal")]
28    EmptyWithdrawal,
29    /// Empty swap.
30    #[error("empty swap")]
31    EmptySwap,
32    /// Invalid prices.
33    #[error("invalid prices")]
34    InvalidPrices,
35    /// Unknown computation error.
36    #[error("unknown computation error: {0}")]
37    Computation(&'static str),
38    ///  Computation error in pool
39    #[error("computation in `{0:?}` pool error: {1}")]
40    PoolComputation(PoolKind, &'static str),
41    /// Power computation error.
42    #[error("pow computation error")]
43    PowComputation,
44    /// Overflow.
45    #[error("overflow")]
46    Overflow,
47    /// Divided by zero.
48    #[error("divided by zero")]
49    DividedByZero,
50    /// Invalid pool value.
51    #[error("invalid pool value {0}")]
52    InvalidPoolValue(&'static str),
53    /// Convert error.
54    #[error("convert value error")]
55    Convert,
56    /// Build params error.
57    #[error("build params: {0}")]
58    BuildParams(&'static str),
59    /// Missing pool of kind.
60    #[error("missing pool of kind: {0:?}")]
61    MissingPoolKind(PoolKind),
62    /// Missing clock of kind.
63    #[error("missing clock of kind: {0:?}")]
64    MissingClockKind(ClockKind),
65    /// Mint receiver not set.
66    #[error("mint receiver not set")]
67    MintReceiverNotSet,
68    /// Withdrawal vault not set.
69    #[error("withdrawal vault not set")]
70    WithdrawalVaultNotSet,
71    /// Insufficient funds to pay for cost.
72    #[error("insufficient funds to pay for costs: {0:?}")]
73    InsufficientFundsToPayForCosts(InsolventCloseStep),
74    /// Invalid position state.
75    #[error("invalid position state: {0}")]
76    InvalidPosition(&'static str),
77    /// Liquidatable Position.
78    #[error("liquidatable position: {0}")]
79    Liquidatable(LiquidatableReason),
80    /// Not liquidatable.
81    #[error("not liquidatable")]
82    NotLiquidatable,
83    /// Unable to get borrowing factor for empty pool value.
84    #[error("unable to get borrowing factor for empty pool value")]
85    UnableToGetBorrowingFactorEmptyPoolValue,
86    /// Insufficient reserve.
87    #[error("insufficient reserve, requried={0}, max={1}")]
88    InsufficientReserve(String, String),
89    /// Insufficient reserve for open interest.
90    #[error("insufficient reserve for open interest, required={0}, max={1}")]
91    InsufficientReserveForOpenInterest(String, String),
92    /// Pnl Factor Exceeded.
93    #[error("pnl factor ({0:?}) exceeded {1}")]
94    PnlFactorExceeded(PnlFactorKind, &'static str),
95    /// Max pool amount exceeded.
96    #[error("max pool amount exceeded: {0}")]
97    MaxPoolAmountExceeded(&'static str),
98    /// Max pool value for deposit exceeded.
99    #[error("max pool value exceeded: {0}")]
100    MaxPoolValueExceeded(&'static str),
101    /// Max open interest exceeded.
102    #[error("max open interest exceeded")]
103    MaxOpenInterestExceeded,
104    /// Invalid token balance.
105    #[error("invalid token balance: {0}, expected={1}, balance={2}")]
106    InvalidTokenBalance(&'static str, String, String),
107    /// Unable to get funding factor when the open interest is empty.
108    #[error("unable to get funding factor when the open interest is empty")]
109    UnableToGetFundingFactorEmptyOpenInterest,
110}