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