use crate::{
position::{InsolventCloseStep, LiquidatableReason},
ClockKind, PnlFactorKind, PoolKind,
};
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[cfg(feature = "solana")]
#[error(transparent)]
Solana(#[from] anchor_lang::prelude::Error),
#[cfg(feature = "gmsol-utils")]
#[error(transparent)]
Market(#[from] gmsol_utils::market::MarketError),
#[error("unimplemented")]
Unimplemented,
#[error("invalid argument: {0}")]
InvalidArgument(&'static str),
#[error("empty deposit")]
EmptyDeposit,
#[error("empty withdrawal")]
EmptyWithdrawal,
#[error("empty swap")]
EmptySwap,
#[error("invalid prices")]
InvalidPrices,
#[error("unknown computation error: {0}")]
Computation(&'static str),
#[error("computation in `{0:?}` pool error: {1}")]
PoolComputation(PoolKind, &'static str),
#[error("pow computation error")]
PowComputation,
#[error("overflow")]
Overflow,
#[error("divided by zero")]
DividedByZero,
#[error("invalid pool value {0}")]
InvalidPoolValue(&'static str),
#[error("convert value error")]
Convert,
#[error("build params: {0}")]
BuildParams(&'static str),
#[error("missing pool of kind: {0:?}")]
MissingPoolKind(PoolKind),
#[error("missing clock of kind: {0:?}")]
MissingClockKind(ClockKind),
#[error("mint receiver not set")]
MintReceiverNotSet,
#[error("withdrawal vault not set")]
WithdrawalVaultNotSet,
#[error("insufficient funds to pay for costs: {0:?}")]
InsufficientFundsToPayForCosts(InsolventCloseStep),
#[error("invalid position state: {0}")]
InvalidPosition(&'static str),
#[error("liquidatable position: {0}")]
Liquidatable(LiquidatableReason),
#[error("not liquidatable")]
NotLiquidatable,
#[error("unable to get borrowing factor for empty pool value")]
UnableToGetBorrowingFactorEmptyPoolValue,
#[error("insufficient reserve, required={0}, max={1}")]
InsufficientReserve(String, String),
#[error("insufficient reserve for open interest, required={0}, max={1}")]
InsufficientReserveForOpenInterest(String, String),
#[error("pnl factor ({0:?}) exceeded {1}")]
PnlFactorExceeded(PnlFactorKind, &'static str),
#[error("max pool amount exceeded: {0}")]
MaxPoolAmountExceeded(&'static str),
#[error("max pool value exceeded: {0}")]
MaxPoolValueExceeded(&'static str),
#[error("max open interest exceeded")]
MaxOpenInterestExceeded,
#[error("invalid token balance: {0}, expected={1}, balance={2}")]
InvalidTokenBalance(&'static str, String, String),
#[error("unable to get funding factor when the open interest is empty")]
UnableToGetFundingFactorEmptyOpenInterest,
}
pub const GLV_PRICING_NEGATIVE_POOL_VALUE_ERROR: &str = "negative pool value during GLV pricing";
pub const GLV_PRICING_MARKET_TOKEN_TO_GLV_VALUE_ERROR: &str =
"failed to convert market token amount to GLV value";
pub const GLV_PRICING_GLV_VALUE_TO_MARKET_TOKEN_ERROR: &str =
"failed to convert GLV value to market token amount";