1use num_derive::FromPrimitive;
4use gemachain_program::{decode_error::DecodeError, program_error::ProgramError};
5use thiserror::Error;
6
7#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
9pub enum SwapError {
10 #[error("Swap account already in use")]
13 AlreadyInUse,
14 #[error("Invalid program address generated from bump seed and key")]
16 InvalidProgramAddress,
17 #[error("Input account owner is not the program address")]
19 InvalidOwner,
20 #[error("Output pool account owner cannot be the program address")]
22 InvalidOutputOwner,
23 #[error("Deserialized account is not an GPL Token mint")]
25 ExpectedMint,
26
27 #[error("Deserialized account is not an GPL Token account")]
30 ExpectedAccount,
31 #[error("Input token account empty")]
33 EmptySupply,
34 #[error("Pool token mint has a non-zero supply")]
36 InvalidSupply,
37 #[error("Token account has a delegate")]
39 InvalidDelegate,
40 #[error("InvalidInput")]
42 InvalidInput,
43
44 #[error("Address of the provided swap token account is incorrect")]
47 IncorrectSwapAccount,
48 #[error("Address of the provided pool token mint is incorrect")]
50 IncorrectPoolMint,
51 #[error("InvalidOutput")]
53 InvalidOutput,
54 #[error("General calculation failure due to overflow or underflow")]
56 CalculationFailure,
57 #[error("Invalid instruction")]
59 InvalidInstruction,
60
61 #[error("Swap input token accounts have the same mint")]
64 RepeatedMint,
65 #[error("Swap instruction exceeds desired slippage limit")]
67 ExceededSlippage,
68 #[error("Token account has a close authority")]
70 InvalidCloseAuthority,
71 #[error("Pool token mint has a freeze authority")]
73 InvalidFreezeAuthority,
74 #[error("Pool fee token account incorrect")]
76 IncorrectFeeAccount,
77
78 #[error("Given pool token amount results in zero trading tokens")]
81 ZeroTradingTokens,
82 #[error("Fee calculation failed due to overflow, underflow, or unexpected 0")]
84 FeeCalculationFailure,
85 #[error("Conversion to u64 failed with an overflow or underflow")]
87 ConversionFailure,
88 #[error("The provided fee does not match the program owner's constraints")]
90 InvalidFee,
91 #[error("The provided token program does not match the token program expected by the swap")]
93 IncorrectTokenProgramId,
94
95 #[error("The provided curve type is not supported by the program owner")]
98 UnsupportedCurveType,
99 #[error("The provided curve parameters are invalid")]
101 InvalidCurve,
102 #[error("The operation cannot be performed on the given curve")]
104 UnsupportedCurveOperation,
105}
106impl From<SwapError> for ProgramError {
107 fn from(e: SwapError) -> Self {
108 ProgramError::Custom(e as u32)
109 }
110}
111impl<T> DecodeError<T> for SwapError {
112 fn type_of() -> &'static str {
113 "Swap Error"
114 }
115}