use num_derive::FromPrimitive;
use thiserror::Error;
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum PerpetualsError {
#[error("Overflow in arithmetic operation")]
MathOverflow = 0x1770,
#[error("Unsupported price oracle")]
UnsupportedOracle = 0x1771,
#[error("Invalid oracle account")]
InvalidOracleAccount = 0x1772,
#[error("Stale oracle price")]
StaleOraclePrice = 0x1773,
#[error("Invalid oracle price")]
InvalidOraclePrice = 0x1774,
#[error("Instruction is not allowed in production")]
InvalidEnvironment = 0x1775,
#[error("Invalid collateral account")]
InvalidCollateralAccount = 0x1776,
#[error("Invalid collateral amount")]
InvalidCollateralAmount = 0x1777,
#[error("Collateral slippage")]
CollateralSlippage = 0x1778,
#[error("Invalid position state")]
InvalidPositionState = 0x1779,
#[error("Invalid perpetuals config")]
InvalidPerpetualsConfig = 0x177A,
#[error("Invalid pool config")]
InvalidPoolConfig = 0x177B,
#[error("Invalid instruction")]
InvalidInstruction = 0x177C,
#[error("Invalid custody config")]
InvalidCustodyConfig = 0x177D,
#[error("Invalid custody balance")]
InvalidCustodyBalance = 0x177E,
#[error("Invalid argument")]
InvalidArgument = 0x177F,
#[error("Invalid position request")]
InvalidPositionRequest = 0x1780,
#[error("Invalid position request input ata")]
InvalidPositionRequestInputAta = 0x1781,
#[error("Invalid mint")]
InvalidMint = 0x1782,
#[error("Insufficient token amount")]
InsufficientTokenAmount = 0x1783,
#[error("Insufficient token amount returned")]
InsufficientAmountReturned = 0x1784,
#[error("Price slippage limit exceeded")]
MaxPriceSlippage = 0x1785,
#[error("Position leverage limit exceeded")]
MaxLeverage = 0x1786,
#[error("Custody amount limit exceeded")]
CustodyAmountLimit = 0x1787,
#[error("Pool amount limit exceeded")]
PoolAmountLimit = 0x1788,
#[error("Personal pool amount limit exceeded")]
PersonalPoolAmountLimit = 0x1789,
#[error("Token is not supported")]
UnsupportedToken = 0x178A,
#[error("Instruction is not allowed at this time")]
InstructionNotAllowed = 0x178B,
#[error("Jupiter Program ID mismatch")]
JupiterProgramMismatch = 0x178C,
#[error("Program ID mismatch")]
ProgramMismatch = 0x178D,
#[error("Address mismatch")]
AddressMismatch = 0x178E,
#[error("Missing keeper ATA")]
KeeperATAMissing = 0x178F,
#[error("Swap amount mismatch")]
SwapAmountMismatch = 0x1790,
#[error("CPI not allowed")]
CPINotAllowed = 0x1791,
#[error("Invalid Keeper")]
InvalidKeeper = 0x1792,
#[error("Exceed execution period")]
ExceedExecutionPeriod = 0x1793,
#[error("Invalid Request Type")]
InvalidRequestType = 0x1794,
#[error("Invalid Trigger Price")]
InvalidTriggerPrice = 0x1795,
#[error("Trigger Price Slippage")]
TriggerPriceSlippage = 0x1796,
#[error("Missing Trigger Price")]
MissingTriggerPrice = 0x1797,
#[error("Missing Price Slippage")]
MissingPriceSlippage = 0x1798,
#[error("Invalid Price Calc Mode")]
InvalidPriceCalcMode = 0x1799,
#[error("Request Updated Too Recent")]
RequestUpdatedTooRecent = 0x179A,
#[error("Exceed Token Weightage")]
ExceedTokenWeightage = 0x179B,
#[error("Oracle Publish Time Too Early")]
OraclePublishTimeTooEarly = 0x179C,
#[error("Pull Oracle Publish Time Too Early")]
PullOraclePublishTimeTooEarly = 0x179D,
#[error("Stale Pull Oracle Price")]
StalePullOraclePrice = 0x179E,
#[error("Invalid Pull Oracle Price")]
InvalidPullOraclePrice = 0x179F,
#[error("Pull Oracle Not Verified")]
PullOracleNotVerified = 0x17A0,
#[error("Price Diff Between Pull and Push Oracle is Too Large")]
PriceDiffTooLarge = 0x17A1,
#[error("Invalid Doves Oracle Price")]
InvalidDovesOraclePrice = 0x17A2,
#[error("Invalid Request Time")]
InvalidRequestTime = 0x17A3,
#[error("Position Updated Too Recent")]
PositionUpdatedTooRecent = 0x17A4,
#[error("Ledger token account does not match")]
LedgerTokenAccountDoesNotMatch = 0x17A5,
#[error("Invalid token ledger")]
InvalidTokenLedger = 0x17A6,
#[error("Oracle Price Difference Too Large")]
OraclePriceDifferenceTooLarge = 0x17A7,
#[error("Invalid Oracle Signer")]
InvalidOracleSigner = 0x17A8,
#[error("Invalid Oracle Timestamp")]
InvalidOracleTimestamp = 0x17A9,
#[error("New Max Global Long Size Too Low")]
InvalidMaxGlobalLongSize = 0x17AA,
#[error("New Max Global Short Size Too Low")]
InvalidMaxGlobalShortSize = 0x17AB,
#[error("Borrows disabled for this custody")]
BorrowsDisabled = 0x17AC,
#[error("Borrows limit exceeded for this custody")]
BorrowLimitsExceeded = 0x17AD,
#[error("Withdraw exceeds margin of the custody")]
WithdrawExceedsMarginLimits = 0x17AE,
#[error("Cannot liquidate")]
CannotLiquidate = 0x17AF,
#[error("Cannot delegate stake to deactivated account")]
CannotDelegateStake = 0x17B0,
#[error("Max total staked amount exceeded")]
ExceededMaxTotalStakedAmount = 0x17B1,
#[error("LP token price change exceeds limit")]
LpTokenPriceChangeLimitExceeded = 0x17B2,
}
impl From<PerpetualsError> for solana_program::program_error::ProgramError {
fn from(e: PerpetualsError) -> Self {
solana_program::program_error::ProgramError::Custom(e as u32)
}
}