1use crate::{
2 position::{InsolventCloseStep, LiquidatableReason},
3 ClockKind, PnlFactorKind, PoolKind,
4};
5
6#[derive(Debug, thiserror::Error)]
8pub enum Error {
9 #[error("unimplemented")]
11 Unimplemented,
12 #[error("invalid argument: {0}")]
14 InvalidArgument(&'static str),
15 #[error("empty deposit")]
17 EmptyDeposit,
18 #[error("empty withdrawal")]
20 EmptyWithdrawal,
21 #[error("empty swap")]
23 EmptySwap,
24 #[error("invalid prices")]
26 InvalidPrices,
27 #[error("unknown computation error: {0}")]
29 Computation(&'static str),
30 #[error("computation in `{0:?}` pool error: {1}")]
32 PoolComputation(PoolKind, &'static str),
33 #[error("pow computation error")]
35 PowComputation,
36 #[error("overflow")]
38 Overflow,
39 #[error("divided by zero")]
41 DividedByZero,
42 #[error("invalid pool value {0}")]
44 InvalidPoolValue(&'static str),
45 #[error("convert value error")]
47 Convert,
48 #[cfg(feature = "solana")]
50 #[error(transparent)]
51 Solana(#[from] anchor_lang::prelude::Error),
52 #[error("build params: {0}")]
54 BuildParams(&'static str),
55 #[error("missing pool of kind: {0:?}")]
57 MissingPoolKind(PoolKind),
58 #[error("missing clock of kind: {0:?}")]
60 MissingClockKind(ClockKind),
61 #[error("mint receiver not set")]
63 MintReceiverNotSet,
64 #[error("withdrawal vault not set")]
66 WithdrawalVaultNotSet,
67 #[error("insufficient funds to pay for costs: {0:?}")]
69 InsufficientFundsToPayForCosts(InsolventCloseStep),
70 #[error("invalid position state: {0}")]
72 InvalidPosition(&'static str),
73 #[error("liquidatable position: {0}")]
75 Liquidatable(LiquidatableReason),
76 #[error("not liquidatable")]
78 NotLiquidatable,
79 #[error("unable to get borrowing factor for empty pool value")]
81 UnableToGetBorrowingFactorEmptyPoolValue,
82 #[error("insufficient reserve, requried={0}, max={1}")]
84 InsufficientReserve(String, String),
85 #[error("insufficient reserve for open interest, required={0}, max={1}")]
87 InsufficientReserveForOpenInterest(String, String),
88 #[error("pnl factor ({0:?}) exceeded {1}")]
90 PnlFactorExceeded(PnlFactorKind, &'static str),
91 #[error("max pool amount exceeded: {0}")]
93 MaxPoolAmountExceeded(&'static str),
94 #[error("max pool value exceeded: {0}")]
96 MaxPoolValueExceeded(&'static str),
97 #[error("max open interest exceeded")]
99 MaxOpenInterestExceeded,
100 #[error("invalid token balance: {0}, expected={1}, balance={2}")]
102 InvalidTokenBalance(&'static str, String, String),
103 #[error("unable to get funding factor when the open interest is empty")]
105 UnableToGetFundingFactorEmptyOpenInterest,
106}