1use crate::{
2 position::{InsolventCloseStep, LiquidatableReason},
3 ClockKind, PnlFactorKind, PoolKind,
4};
5
6#[derive(Debug, thiserror::Error)]
8pub enum Error {
9 #[cfg(feature = "solana")]
11 #[error(transparent)]
12 Solana(#[from] anchor_lang::prelude::Error),
13 #[cfg(feature = "gmsol-utils")]
15 #[error(transparent)]
16 Market(#[from] gmsol_utils::market::MarketError),
17 #[error("unimplemented")]
19 Unimplemented,
20 #[error("invalid argument: {0}")]
22 InvalidArgument(&'static str),
23 #[error("empty deposit")]
25 EmptyDeposit,
26 #[error("empty withdrawal")]
28 EmptyWithdrawal,
29 #[error("empty swap")]
31 EmptySwap,
32 #[error("invalid prices")]
34 InvalidPrices,
35 #[error("unknown computation error: {0}")]
37 Computation(&'static str),
38 #[error("computation in `{0:?}` pool error: {1}")]
40 PoolComputation(PoolKind, &'static str),
41 #[error("pow computation error")]
43 PowComputation,
44 #[error("overflow")]
46 Overflow,
47 #[error("divided by zero")]
49 DividedByZero,
50 #[error("invalid pool value {0}")]
52 InvalidPoolValue(&'static str),
53 #[error("convert value error")]
55 Convert,
56 #[error("build params: {0}")]
58 BuildParams(&'static str),
59 #[error("missing pool of kind: {0:?}")]
61 MissingPoolKind(PoolKind),
62 #[error("missing clock of kind: {0:?}")]
64 MissingClockKind(ClockKind),
65 #[error("mint receiver not set")]
67 MintReceiverNotSet,
68 #[error("withdrawal vault not set")]
70 WithdrawalVaultNotSet,
71 #[error("insufficient funds to pay for costs: {0:?}")]
73 InsufficientFundsToPayForCosts(InsolventCloseStep),
74 #[error("invalid position state: {0}")]
76 InvalidPosition(&'static str),
77 #[error("liquidatable position: {0}")]
79 Liquidatable(LiquidatableReason),
80 #[error("not liquidatable")]
82 NotLiquidatable,
83 #[error("unable to get borrowing factor for empty pool value")]
85 UnableToGetBorrowingFactorEmptyPoolValue,
86 #[error("insufficient reserve, requried={0}, max={1}")]
88 InsufficientReserve(String, String),
89 #[error("insufficient reserve for open interest, required={0}, max={1}")]
91 InsufficientReserveForOpenInterest(String, String),
92 #[error("pnl factor ({0:?}) exceeded {1}")]
94 PnlFactorExceeded(PnlFactorKind, &'static str),
95 #[error("max pool amount exceeded: {0}")]
97 MaxPoolAmountExceeded(&'static str),
98 #[error("max pool value exceeded: {0}")]
100 MaxPoolValueExceeded(&'static str),
101 #[error("max open interest exceeded")]
103 MaxOpenInterestExceeded,
104 #[error("invalid token balance: {0}, expected={1}, balance={2}")]
106 InvalidTokenBalance(&'static str, String, String),
107 #[error("unable to get funding factor when the open interest is empty")]
109 UnableToGetFundingFactorEmptyOpenInterest,
110}